]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.3-201405071928.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.3-201405071928.patch
CommitLineData
5fc7802e
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..45602ea 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)
6811diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6812index 6ae540e..b7396dc 100644
6813--- a/arch/mips/kernel/process.c
6814+++ b/arch/mips/kernel/process.c
6815@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6816 out:
6817 return pc;
6818 }
6819-
6820-/*
6821- * Don't forget that the stack pointer must be aligned on a 8 bytes
6822- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6823- */
6824-unsigned long arch_align_stack(unsigned long sp)
6825-{
6826- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6827- sp -= get_random_int() & ~PAGE_MASK;
6828-
6829- return sp & ALMASK;
6830-}
6831diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6832index 7da9b76..21578be 100644
6833--- a/arch/mips/kernel/ptrace.c
6834+++ b/arch/mips/kernel/ptrace.c
6835@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6836 return ret;
6837 }
6838
6839+#ifdef CONFIG_GRKERNSEC_SETXID
6840+extern void gr_delayed_cred_worker(void);
6841+#endif
6842+
6843 /*
6844 * Notification of system call entry/exit
6845 * - triggered by current->work.syscall_trace
6846@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6847 tracehook_report_syscall_entry(regs))
6848 ret = -1;
6849
6850+#ifdef CONFIG_GRKERNSEC_SETXID
6851+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6852+ gr_delayed_cred_worker();
6853+#endif
6854+
6855 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6856 trace_sys_enter(regs, regs->regs[2]);
6857
6858diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6859index 07fc524..b9d7f28 100644
6860--- a/arch/mips/kernel/reset.c
6861+++ b/arch/mips/kernel/reset.c
6862@@ -13,6 +13,7 @@
6863 #include <linux/reboot.h>
6864
6865 #include <asm/reboot.h>
6866+#include <asm/bug.h>
6867
6868 /*
6869 * Urgs ... Too many MIPS machines to handle this in a generic way.
6870@@ -29,16 +30,19 @@ void machine_restart(char *command)
6871 {
6872 if (_machine_restart)
6873 _machine_restart(command);
6874+ BUG();
6875 }
6876
6877 void machine_halt(void)
6878 {
6879 if (_machine_halt)
6880 _machine_halt();
6881+ BUG();
6882 }
6883
6884 void machine_power_off(void)
6885 {
6886 if (pm_power_off)
6887 pm_power_off();
6888+ BUG();
6889 }
6890diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6891index c10aa84..9ec2e60 100644
6892--- a/arch/mips/kernel/smtc-proc.c
6893+++ b/arch/mips/kernel/smtc-proc.c
6894@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6895
6896 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6897
6898-atomic_t smtc_fpu_recoveries;
6899+atomic_unchecked_t smtc_fpu_recoveries;
6900
6901 static int smtc_proc_show(struct seq_file *m, void *v)
6902 {
6903@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6904 for(i = 0; i < NR_CPUS; i++)
6905 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6906 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6907- atomic_read(&smtc_fpu_recoveries));
6908+ atomic_read_unchecked(&smtc_fpu_recoveries));
6909 return 0;
6910 }
6911
6912@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6913 smtc_cpu_stats[i].selfipis = 0;
6914 }
6915
6916- atomic_set(&smtc_fpu_recoveries, 0);
6917+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6918
6919 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6920 }
6921diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6922index dfc1b91..11a2c07 100644
6923--- a/arch/mips/kernel/smtc.c
6924+++ b/arch/mips/kernel/smtc.c
6925@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6926 }
6927 smtc_ipi_qdump();
6928 printk("%d Recoveries of \"stolen\" FPU\n",
6929- atomic_read(&smtc_fpu_recoveries));
6930+ atomic_read_unchecked(&smtc_fpu_recoveries));
6931 }
6932
6933
6934diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6935index c24ad5f..9983ab2 100644
6936--- a/arch/mips/kernel/sync-r4k.c
6937+++ b/arch/mips/kernel/sync-r4k.c
6938@@ -20,8 +20,8 @@
6939 #include <asm/mipsregs.h>
6940
6941 static atomic_t count_start_flag = ATOMIC_INIT(0);
6942-static atomic_t count_count_start = ATOMIC_INIT(0);
6943-static atomic_t count_count_stop = ATOMIC_INIT(0);
6944+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6945+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6946 static atomic_t count_reference = ATOMIC_INIT(0);
6947
6948 #define COUNTON 100
6949@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6950
6951 for (i = 0; i < NR_LOOPS; i++) {
6952 /* slaves loop on '!= 2' */
6953- while (atomic_read(&count_count_start) != 1)
6954+ while (atomic_read_unchecked(&count_count_start) != 1)
6955 mb();
6956- atomic_set(&count_count_stop, 0);
6957+ atomic_set_unchecked(&count_count_stop, 0);
6958 smp_wmb();
6959
6960 /* this lets the slaves write their count register */
6961- atomic_inc(&count_count_start);
6962+ atomic_inc_unchecked(&count_count_start);
6963
6964 /*
6965 * Everyone initialises count in the last loop:
6966@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6967 /*
6968 * Wait for all slaves to leave the synchronization point:
6969 */
6970- while (atomic_read(&count_count_stop) != 1)
6971+ while (atomic_read_unchecked(&count_count_stop) != 1)
6972 mb();
6973- atomic_set(&count_count_start, 0);
6974+ atomic_set_unchecked(&count_count_start, 0);
6975 smp_wmb();
6976- atomic_inc(&count_count_stop);
6977+ atomic_inc_unchecked(&count_count_stop);
6978 }
6979 /* Arrange for an interrupt in a short while */
6980 write_c0_compare(read_c0_count() + COUNTON);
6981@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
6982 initcount = atomic_read(&count_reference);
6983
6984 for (i = 0; i < NR_LOOPS; i++) {
6985- atomic_inc(&count_count_start);
6986- while (atomic_read(&count_count_start) != 2)
6987+ atomic_inc_unchecked(&count_count_start);
6988+ while (atomic_read_unchecked(&count_count_start) != 2)
6989 mb();
6990
6991 /*
6992@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
6993 if (i == NR_LOOPS-1)
6994 write_c0_count(initcount);
6995
6996- atomic_inc(&count_count_stop);
6997- while (atomic_read(&count_count_stop) != 2)
6998+ atomic_inc_unchecked(&count_count_stop);
6999+ while (atomic_read_unchecked(&count_count_stop) != 2)
7000 mb();
7001 }
7002 /* Arrange for an interrupt in a short while */
7003diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7004index e0b4996..6b43ce7 100644
7005--- a/arch/mips/kernel/traps.c
7006+++ b/arch/mips/kernel/traps.c
7007@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7008 siginfo_t info;
7009
7010 prev_state = exception_enter();
7011- die_if_kernel("Integer overflow", regs);
7012+ if (unlikely(!user_mode(regs))) {
7013+
7014+#ifdef CONFIG_PAX_REFCOUNT
7015+ if (fixup_exception(regs)) {
7016+ pax_report_refcount_overflow(regs);
7017+ exception_exit(prev_state);
7018+ return;
7019+ }
7020+#endif
7021+
7022+ die("Integer overflow", regs);
7023+ }
7024
7025 info.si_code = FPE_INTOVF;
7026 info.si_signo = SIGFPE;
7027diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7028index becc42b..9e43d4b 100644
7029--- a/arch/mips/mm/fault.c
7030+++ b/arch/mips/mm/fault.c
7031@@ -28,6 +28,23 @@
7032 #include <asm/highmem.h> /* For VMALLOC_END */
7033 #include <linux/kdebug.h>
7034
7035+#ifdef CONFIG_PAX_PAGEEXEC
7036+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7037+{
7038+ unsigned long i;
7039+
7040+ printk(KERN_ERR "PAX: bytes at PC: ");
7041+ for (i = 0; i < 5; i++) {
7042+ unsigned int c;
7043+ if (get_user(c, (unsigned int *)pc+i))
7044+ printk(KERN_CONT "???????? ");
7045+ else
7046+ printk(KERN_CONT "%08x ", c);
7047+ }
7048+ printk("\n");
7049+}
7050+#endif
7051+
7052 /*
7053 * This routine handles page faults. It determines the address,
7054 * and the problem, and then passes it off to one of the appropriate
7055@@ -199,6 +216,14 @@ bad_area:
7056 bad_area_nosemaphore:
7057 /* User mode accesses just cause a SIGSEGV */
7058 if (user_mode(regs)) {
7059+
7060+#ifdef CONFIG_PAX_PAGEEXEC
7061+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7062+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7063+ do_group_exit(SIGKILL);
7064+ }
7065+#endif
7066+
7067 tsk->thread.cp0_badvaddr = address;
7068 tsk->thread.error_code = write;
7069 #if 0
7070diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7071index f1baadd..5472dca 100644
7072--- a/arch/mips/mm/mmap.c
7073+++ b/arch/mips/mm/mmap.c
7074@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7075 struct vm_area_struct *vma;
7076 unsigned long addr = addr0;
7077 int do_color_align;
7078+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7079 struct vm_unmapped_area_info info;
7080
7081 if (unlikely(len > TASK_SIZE))
7082@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7083 do_color_align = 1;
7084
7085 /* requesting a specific address */
7086+
7087+#ifdef CONFIG_PAX_RANDMMAP
7088+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7089+#endif
7090+
7091 if (addr) {
7092 if (do_color_align)
7093 addr = COLOUR_ALIGN(addr, pgoff);
7094@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7095 addr = PAGE_ALIGN(addr);
7096
7097 vma = find_vma(mm, addr);
7098- if (TASK_SIZE - len >= addr &&
7099- (!vma || addr + len <= vma->vm_start))
7100+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7101 return addr;
7102 }
7103
7104 info.length = len;
7105 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7106 info.align_offset = pgoff << PAGE_SHIFT;
7107+ info.threadstack_offset = offset;
7108
7109 if (dir == DOWN) {
7110 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7111@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7112 {
7113 unsigned long random_factor = 0UL;
7114
7115+#ifdef CONFIG_PAX_RANDMMAP
7116+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7117+#endif
7118+
7119 if (current->flags & PF_RANDOMIZE) {
7120 random_factor = get_random_int();
7121 random_factor = random_factor << PAGE_SHIFT;
7122@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7123
7124 if (mmap_is_legacy()) {
7125 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7126+
7127+#ifdef CONFIG_PAX_RANDMMAP
7128+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7129+ mm->mmap_base += mm->delta_mmap;
7130+#endif
7131+
7132 mm->get_unmapped_area = arch_get_unmapped_area;
7133 } else {
7134 mm->mmap_base = mmap_base(random_factor);
7135+
7136+#ifdef CONFIG_PAX_RANDMMAP
7137+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7138+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7139+#endif
7140+
7141 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7142 }
7143 }
7144
7145-static inline unsigned long brk_rnd(void)
7146-{
7147- unsigned long rnd = get_random_int();
7148-
7149- rnd = rnd << PAGE_SHIFT;
7150- /* 8MB for 32bit, 256MB for 64bit */
7151- if (TASK_IS_32BIT_ADDR)
7152- rnd = rnd & 0x7ffffful;
7153- else
7154- rnd = rnd & 0xffffffful;
7155-
7156- return rnd;
7157-}
7158-
7159-unsigned long arch_randomize_brk(struct mm_struct *mm)
7160-{
7161- unsigned long base = mm->brk;
7162- unsigned long ret;
7163-
7164- ret = PAGE_ALIGN(base + brk_rnd());
7165-
7166- if (ret < mm->brk)
7167- return mm->brk;
7168-
7169- return ret;
7170-}
7171-
7172 int __virt_addr_valid(const volatile void *kaddr)
7173 {
7174 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7175diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7176index 59cccd9..f39ac2f 100644
7177--- a/arch/mips/pci/pci-octeon.c
7178+++ b/arch/mips/pci/pci-octeon.c
7179@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7180
7181
7182 static struct pci_ops octeon_pci_ops = {
7183- octeon_read_config,
7184- octeon_write_config,
7185+ .read = octeon_read_config,
7186+ .write = octeon_write_config,
7187 };
7188
7189 static struct resource octeon_pci_mem_resource = {
7190diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7191index 5e36c33..eb4a17b 100644
7192--- a/arch/mips/pci/pcie-octeon.c
7193+++ b/arch/mips/pci/pcie-octeon.c
7194@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7195 }
7196
7197 static struct pci_ops octeon_pcie0_ops = {
7198- octeon_pcie0_read_config,
7199- octeon_pcie0_write_config,
7200+ .read = octeon_pcie0_read_config,
7201+ .write = octeon_pcie0_write_config,
7202 };
7203
7204 static struct resource octeon_pcie0_mem_resource = {
7205@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7206 };
7207
7208 static struct pci_ops octeon_pcie1_ops = {
7209- octeon_pcie1_read_config,
7210- octeon_pcie1_write_config,
7211+ .read = octeon_pcie1_read_config,
7212+ .write = octeon_pcie1_write_config,
7213 };
7214
7215 static struct resource octeon_pcie1_mem_resource = {
7216@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7217 };
7218
7219 static struct pci_ops octeon_dummy_ops = {
7220- octeon_dummy_read_config,
7221- octeon_dummy_write_config,
7222+ .read = octeon_dummy_read_config,
7223+ .write = octeon_dummy_write_config,
7224 };
7225
7226 static struct resource octeon_dummy_mem_resource = {
7227diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7228index a2358b4..7cead4f 100644
7229--- a/arch/mips/sgi-ip27/ip27-nmi.c
7230+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7231@@ -187,9 +187,9 @@ void
7232 cont_nmi_dump(void)
7233 {
7234 #ifndef REAL_NMI_SIGNAL
7235- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7236+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7237
7238- atomic_inc(&nmied_cpus);
7239+ atomic_inc_unchecked(&nmied_cpus);
7240 #endif
7241 /*
7242 * Only allow 1 cpu to proceed
7243@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7244 udelay(10000);
7245 }
7246 #else
7247- while (atomic_read(&nmied_cpus) != num_online_cpus());
7248+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7249 #endif
7250
7251 /*
7252diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7253index a046b30..6799527 100644
7254--- a/arch/mips/sni/rm200.c
7255+++ b/arch/mips/sni/rm200.c
7256@@ -270,7 +270,7 @@ spurious_8259A_irq:
7257 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7258 spurious_irq_mask |= irqmask;
7259 }
7260- atomic_inc(&irq_err_count);
7261+ atomic_inc_unchecked(&irq_err_count);
7262 /*
7263 * Theoretically we do not have to handle this IRQ,
7264 * but in Linux this does not cause problems and is
7265diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7266index 41e873b..34d33a7 100644
7267--- a/arch/mips/vr41xx/common/icu.c
7268+++ b/arch/mips/vr41xx/common/icu.c
7269@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7270
7271 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7272
7273- atomic_inc(&irq_err_count);
7274+ atomic_inc_unchecked(&irq_err_count);
7275
7276 return -1;
7277 }
7278diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7279index ae0e4ee..e8f0692 100644
7280--- a/arch/mips/vr41xx/common/irq.c
7281+++ b/arch/mips/vr41xx/common/irq.c
7282@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7283 irq_cascade_t *cascade;
7284
7285 if (irq >= NR_IRQS) {
7286- atomic_inc(&irq_err_count);
7287+ atomic_inc_unchecked(&irq_err_count);
7288 return;
7289 }
7290
7291@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7292 ret = cascade->get_irq(irq);
7293 irq = ret;
7294 if (ret < 0)
7295- atomic_inc(&irq_err_count);
7296+ atomic_inc_unchecked(&irq_err_count);
7297 else
7298 irq_dispatch(irq);
7299 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7300diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7301index 967d144..db12197 100644
7302--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7303+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7304@@ -11,12 +11,14 @@
7305 #ifndef _ASM_PROC_CACHE_H
7306 #define _ASM_PROC_CACHE_H
7307
7308+#include <linux/const.h>
7309+
7310 /* L1 cache */
7311
7312 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7313 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7314-#define L1_CACHE_BYTES 16 /* bytes per entry */
7315 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7316+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7317 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7318
7319 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7320diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7321index bcb5df2..84fabd2 100644
7322--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7323+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7324@@ -16,13 +16,15 @@
7325 #ifndef _ASM_PROC_CACHE_H
7326 #define _ASM_PROC_CACHE_H
7327
7328+#include <linux/const.h>
7329+
7330 /*
7331 * L1 cache
7332 */
7333 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7334 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7335-#define L1_CACHE_BYTES 32 /* bytes per entry */
7336 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7337+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7338 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7339
7340 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7341diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7342index 4ce7a01..449202a 100644
7343--- a/arch/openrisc/include/asm/cache.h
7344+++ b/arch/openrisc/include/asm/cache.h
7345@@ -19,11 +19,13 @@
7346 #ifndef __ASM_OPENRISC_CACHE_H
7347 #define __ASM_OPENRISC_CACHE_H
7348
7349+#include <linux/const.h>
7350+
7351 /* FIXME: How can we replace these with values from the CPU...
7352 * they shouldn't be hard-coded!
7353 */
7354
7355-#define L1_CACHE_BYTES 16
7356 #define L1_CACHE_SHIFT 4
7357+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7358
7359 #endif /* __ASM_OPENRISC_CACHE_H */
7360diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7361index 472886c..00e7df9 100644
7362--- a/arch/parisc/include/asm/atomic.h
7363+++ b/arch/parisc/include/asm/atomic.h
7364@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7365 return dec;
7366 }
7367
7368+#define atomic64_read_unchecked(v) atomic64_read(v)
7369+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7370+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7371+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7372+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7373+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7374+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7375+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7376+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7377+
7378 #endif /* !CONFIG_64BIT */
7379
7380
7381diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7382index 47f11c7..3420df2 100644
7383--- a/arch/parisc/include/asm/cache.h
7384+++ b/arch/parisc/include/asm/cache.h
7385@@ -5,6 +5,7 @@
7386 #ifndef __ARCH_PARISC_CACHE_H
7387 #define __ARCH_PARISC_CACHE_H
7388
7389+#include <linux/const.h>
7390
7391 /*
7392 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7393@@ -15,13 +16,13 @@
7394 * just ruin performance.
7395 */
7396 #ifdef CONFIG_PA20
7397-#define L1_CACHE_BYTES 64
7398 #define L1_CACHE_SHIFT 6
7399 #else
7400-#define L1_CACHE_BYTES 32
7401 #define L1_CACHE_SHIFT 5
7402 #endif
7403
7404+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7405+
7406 #ifndef __ASSEMBLY__
7407
7408 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7409diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7410index 3391d06..c23a2cc 100644
7411--- a/arch/parisc/include/asm/elf.h
7412+++ b/arch/parisc/include/asm/elf.h
7413@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7414
7415 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7416
7417+#ifdef CONFIG_PAX_ASLR
7418+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7419+
7420+#define PAX_DELTA_MMAP_LEN 16
7421+#define PAX_DELTA_STACK_LEN 16
7422+#endif
7423+
7424 /* This yields a mask that user programs can use to figure out what
7425 instruction set this CPU supports. This could be done in user space,
7426 but it's not easy, and we've already done it here. */
7427diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7428index f213f5b..0af3e8e 100644
7429--- a/arch/parisc/include/asm/pgalloc.h
7430+++ b/arch/parisc/include/asm/pgalloc.h
7431@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7432 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7433 }
7434
7435+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7436+{
7437+ pgd_populate(mm, pgd, pmd);
7438+}
7439+
7440 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7441 {
7442 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7443@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7444 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7445 #define pmd_free(mm, x) do { } while (0)
7446 #define pgd_populate(mm, pmd, pte) BUG()
7447+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7448
7449 #endif
7450
7451diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7452index 22b89d1..ce34230 100644
7453--- a/arch/parisc/include/asm/pgtable.h
7454+++ b/arch/parisc/include/asm/pgtable.h
7455@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7456 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7457 #define PAGE_COPY PAGE_EXECREAD
7458 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7459+
7460+#ifdef CONFIG_PAX_PAGEEXEC
7461+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7462+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7463+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7464+#else
7465+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7466+# define PAGE_COPY_NOEXEC PAGE_COPY
7467+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7468+#endif
7469+
7470 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7471 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7472 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7473diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7474index 4006964..fcb3cc2 100644
7475--- a/arch/parisc/include/asm/uaccess.h
7476+++ b/arch/parisc/include/asm/uaccess.h
7477@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7478 const void __user *from,
7479 unsigned long n)
7480 {
7481- int sz = __compiletime_object_size(to);
7482+ size_t sz = __compiletime_object_size(to);
7483 int ret = -EFAULT;
7484
7485- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7486+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7487 ret = __copy_from_user(to, from, n);
7488 else
7489 copy_from_user_overflow();
7490diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7491index 50dfafc..b9fc230 100644
7492--- a/arch/parisc/kernel/module.c
7493+++ b/arch/parisc/kernel/module.c
7494@@ -98,16 +98,38 @@
7495
7496 /* three functions to determine where in the module core
7497 * or init pieces the location is */
7498+static inline int in_init_rx(struct module *me, void *loc)
7499+{
7500+ return (loc >= me->module_init_rx &&
7501+ loc < (me->module_init_rx + me->init_size_rx));
7502+}
7503+
7504+static inline int in_init_rw(struct module *me, void *loc)
7505+{
7506+ return (loc >= me->module_init_rw &&
7507+ loc < (me->module_init_rw + me->init_size_rw));
7508+}
7509+
7510 static inline int in_init(struct module *me, void *loc)
7511 {
7512- return (loc >= me->module_init &&
7513- loc <= (me->module_init + me->init_size));
7514+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7515+}
7516+
7517+static inline int in_core_rx(struct module *me, void *loc)
7518+{
7519+ return (loc >= me->module_core_rx &&
7520+ loc < (me->module_core_rx + me->core_size_rx));
7521+}
7522+
7523+static inline int in_core_rw(struct module *me, void *loc)
7524+{
7525+ return (loc >= me->module_core_rw &&
7526+ loc < (me->module_core_rw + me->core_size_rw));
7527 }
7528
7529 static inline int in_core(struct module *me, void *loc)
7530 {
7531- return (loc >= me->module_core &&
7532- loc <= (me->module_core + me->core_size));
7533+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7534 }
7535
7536 static inline int in_local(struct module *me, void *loc)
7537@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7538 }
7539
7540 /* align things a bit */
7541- me->core_size = ALIGN(me->core_size, 16);
7542- me->arch.got_offset = me->core_size;
7543- me->core_size += gots * sizeof(struct got_entry);
7544+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7545+ me->arch.got_offset = me->core_size_rw;
7546+ me->core_size_rw += gots * sizeof(struct got_entry);
7547
7548- me->core_size = ALIGN(me->core_size, 16);
7549- me->arch.fdesc_offset = me->core_size;
7550- me->core_size += fdescs * sizeof(Elf_Fdesc);
7551+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7552+ me->arch.fdesc_offset = me->core_size_rw;
7553+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7554
7555 me->arch.got_max = gots;
7556 me->arch.fdesc_max = fdescs;
7557@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7558
7559 BUG_ON(value == 0);
7560
7561- got = me->module_core + me->arch.got_offset;
7562+ got = me->module_core_rw + me->arch.got_offset;
7563 for (i = 0; got[i].addr; i++)
7564 if (got[i].addr == value)
7565 goto out;
7566@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7567 #ifdef CONFIG_64BIT
7568 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7569 {
7570- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7571+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7572
7573 if (!value) {
7574 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7575@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7576
7577 /* Create new one */
7578 fdesc->addr = value;
7579- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7580+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7581 return (Elf_Addr)fdesc;
7582 }
7583 #endif /* CONFIG_64BIT */
7584@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7585
7586 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7587 end = table + sechdrs[me->arch.unwind_section].sh_size;
7588- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7589+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7590
7591 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7592 me->arch.unwind_section, table, end, gp);
7593diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7594index b7cadc4..bf4a32d 100644
7595--- a/arch/parisc/kernel/sys_parisc.c
7596+++ b/arch/parisc/kernel/sys_parisc.c
7597@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7598 unsigned long task_size = TASK_SIZE;
7599 int do_color_align, last_mmap;
7600 struct vm_unmapped_area_info info;
7601+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7602
7603 if (len > task_size)
7604 return -ENOMEM;
7605@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7606 goto found_addr;
7607 }
7608
7609+#ifdef CONFIG_PAX_RANDMMAP
7610+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7611+#endif
7612+
7613 if (addr) {
7614 if (do_color_align && last_mmap)
7615 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7616@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7617 info.high_limit = mmap_upper_limit();
7618 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7619 info.align_offset = shared_align_offset(last_mmap, pgoff);
7620+ info.threadstack_offset = offset;
7621 addr = vm_unmapped_area(&info);
7622
7623 found_addr:
7624@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7625 unsigned long addr = addr0;
7626 int do_color_align, last_mmap;
7627 struct vm_unmapped_area_info info;
7628+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7629
7630 #ifdef CONFIG_64BIT
7631 /* This should only ever run for 32-bit processes. */
7632@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7633 }
7634
7635 /* requesting a specific address */
7636+#ifdef CONFIG_PAX_RANDMMAP
7637+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7638+#endif
7639+
7640 if (addr) {
7641 if (do_color_align && last_mmap)
7642 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7643@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7644 info.high_limit = mm->mmap_base;
7645 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7646 info.align_offset = shared_align_offset(last_mmap, pgoff);
7647+ info.threadstack_offset = offset;
7648 addr = vm_unmapped_area(&info);
7649 if (!(addr & ~PAGE_MASK))
7650 goto found_addr;
7651@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7652 mm->mmap_legacy_base = mmap_legacy_base();
7653 mm->mmap_base = mmap_upper_limit();
7654
7655+#ifdef CONFIG_PAX_RANDMMAP
7656+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7657+ mm->mmap_legacy_base += mm->delta_mmap;
7658+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7659+ }
7660+#endif
7661+
7662 if (mmap_is_legacy()) {
7663 mm->mmap_base = mm->mmap_legacy_base;
7664 mm->get_unmapped_area = arch_get_unmapped_area;
7665diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7666index 1cd1d0c..44ec918 100644
7667--- a/arch/parisc/kernel/traps.c
7668+++ b/arch/parisc/kernel/traps.c
7669@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7670
7671 down_read(&current->mm->mmap_sem);
7672 vma = find_vma(current->mm,regs->iaoq[0]);
7673- if (vma && (regs->iaoq[0] >= vma->vm_start)
7674- && (vma->vm_flags & VM_EXEC)) {
7675-
7676+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7677 fault_address = regs->iaoq[0];
7678 fault_space = regs->iasq[0];
7679
7680diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7681index 9d08c71..e2b4d20 100644
7682--- a/arch/parisc/mm/fault.c
7683+++ b/arch/parisc/mm/fault.c
7684@@ -15,6 +15,7 @@
7685 #include <linux/sched.h>
7686 #include <linux/interrupt.h>
7687 #include <linux/module.h>
7688+#include <linux/unistd.h>
7689
7690 #include <asm/uaccess.h>
7691 #include <asm/traps.h>
7692@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7693 static unsigned long
7694 parisc_acctyp(unsigned long code, unsigned int inst)
7695 {
7696- if (code == 6 || code == 16)
7697+ if (code == 6 || code == 7 || code == 16)
7698 return VM_EXEC;
7699
7700 switch (inst & 0xf0000000) {
7701@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7702 }
7703 #endif
7704
7705+#ifdef CONFIG_PAX_PAGEEXEC
7706+/*
7707+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7708+ *
7709+ * returns 1 when task should be killed
7710+ * 2 when rt_sigreturn trampoline was detected
7711+ * 3 when unpatched PLT trampoline was detected
7712+ */
7713+static int pax_handle_fetch_fault(struct pt_regs *regs)
7714+{
7715+
7716+#ifdef CONFIG_PAX_EMUPLT
7717+ int err;
7718+
7719+ do { /* PaX: unpatched PLT emulation */
7720+ unsigned int bl, depwi;
7721+
7722+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7723+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7724+
7725+ if (err)
7726+ break;
7727+
7728+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7729+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7730+
7731+ err = get_user(ldw, (unsigned int *)addr);
7732+ err |= get_user(bv, (unsigned int *)(addr+4));
7733+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7734+
7735+ if (err)
7736+ break;
7737+
7738+ if (ldw == 0x0E801096U &&
7739+ bv == 0xEAC0C000U &&
7740+ ldw2 == 0x0E881095U)
7741+ {
7742+ unsigned int resolver, map;
7743+
7744+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7745+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7746+ if (err)
7747+ break;
7748+
7749+ regs->gr[20] = instruction_pointer(regs)+8;
7750+ regs->gr[21] = map;
7751+ regs->gr[22] = resolver;
7752+ regs->iaoq[0] = resolver | 3UL;
7753+ regs->iaoq[1] = regs->iaoq[0] + 4;
7754+ return 3;
7755+ }
7756+ }
7757+ } while (0);
7758+#endif
7759+
7760+#ifdef CONFIG_PAX_EMUTRAMP
7761+
7762+#ifndef CONFIG_PAX_EMUSIGRT
7763+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7764+ return 1;
7765+#endif
7766+
7767+ do { /* PaX: rt_sigreturn emulation */
7768+ unsigned int ldi1, ldi2, bel, nop;
7769+
7770+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7771+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7772+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7773+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7774+
7775+ if (err)
7776+ break;
7777+
7778+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7779+ ldi2 == 0x3414015AU &&
7780+ bel == 0xE4008200U &&
7781+ nop == 0x08000240U)
7782+ {
7783+ regs->gr[25] = (ldi1 & 2) >> 1;
7784+ regs->gr[20] = __NR_rt_sigreturn;
7785+ regs->gr[31] = regs->iaoq[1] + 16;
7786+ regs->sr[0] = regs->iasq[1];
7787+ regs->iaoq[0] = 0x100UL;
7788+ regs->iaoq[1] = regs->iaoq[0] + 4;
7789+ regs->iasq[0] = regs->sr[2];
7790+ regs->iasq[1] = regs->sr[2];
7791+ return 2;
7792+ }
7793+ } while (0);
7794+#endif
7795+
7796+ return 1;
7797+}
7798+
7799+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7800+{
7801+ unsigned long i;
7802+
7803+ printk(KERN_ERR "PAX: bytes at PC: ");
7804+ for (i = 0; i < 5; i++) {
7805+ unsigned int c;
7806+ if (get_user(c, (unsigned int *)pc+i))
7807+ printk(KERN_CONT "???????? ");
7808+ else
7809+ printk(KERN_CONT "%08x ", c);
7810+ }
7811+ printk("\n");
7812+}
7813+#endif
7814+
7815 int fixup_exception(struct pt_regs *regs)
7816 {
7817 const struct exception_table_entry *fix;
7818@@ -210,8 +321,33 @@ retry:
7819
7820 good_area:
7821
7822- if ((vma->vm_flags & acc_type) != acc_type)
7823+ if ((vma->vm_flags & acc_type) != acc_type) {
7824+
7825+#ifdef CONFIG_PAX_PAGEEXEC
7826+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7827+ (address & ~3UL) == instruction_pointer(regs))
7828+ {
7829+ up_read(&mm->mmap_sem);
7830+ switch (pax_handle_fetch_fault(regs)) {
7831+
7832+#ifdef CONFIG_PAX_EMUPLT
7833+ case 3:
7834+ return;
7835+#endif
7836+
7837+#ifdef CONFIG_PAX_EMUTRAMP
7838+ case 2:
7839+ return;
7840+#endif
7841+
7842+ }
7843+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7844+ do_group_exit(SIGKILL);
7845+ }
7846+#endif
7847+
7848 goto bad_area;
7849+ }
7850
7851 /*
7852 * If for any reason at all we couldn't handle the fault, make
7853diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7854index 957bf34..3430cc8 100644
7855--- a/arch/powerpc/Kconfig
7856+++ b/arch/powerpc/Kconfig
7857@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7858 config KEXEC
7859 bool "kexec system call"
7860 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7861+ depends on !GRKERNSEC_KMEM
7862 help
7863 kexec is a system call that implements the ability to shutdown your
7864 current kernel, and to start another kernel. It is like a reboot
7865diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7866index e3b1d41..8e81edf 100644
7867--- a/arch/powerpc/include/asm/atomic.h
7868+++ b/arch/powerpc/include/asm/atomic.h
7869@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7870 return t1;
7871 }
7872
7873+#define atomic64_read_unchecked(v) atomic64_read(v)
7874+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7875+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7876+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7877+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7878+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7879+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7880+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7881+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7882+
7883 #endif /* __powerpc64__ */
7884
7885 #endif /* __KERNEL__ */
7886diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7887index ed0afc1..0332825 100644
7888--- a/arch/powerpc/include/asm/cache.h
7889+++ b/arch/powerpc/include/asm/cache.h
7890@@ -3,6 +3,7 @@
7891
7892 #ifdef __KERNEL__
7893
7894+#include <linux/const.h>
7895
7896 /* bytes per L1 cache line */
7897 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7898@@ -22,7 +23,7 @@
7899 #define L1_CACHE_SHIFT 7
7900 #endif
7901
7902-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7903+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7904
7905 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7906
7907diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7908index 935b5e7..7001d2d 100644
7909--- a/arch/powerpc/include/asm/elf.h
7910+++ b/arch/powerpc/include/asm/elf.h
7911@@ -28,8 +28,19 @@
7912 the loader. We need to make sure that it is out of the way of the program
7913 that it will "exec", and that there is sufficient room for the brk. */
7914
7915-extern unsigned long randomize_et_dyn(unsigned long base);
7916-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7917+#define ELF_ET_DYN_BASE (0x20000000)
7918+
7919+#ifdef CONFIG_PAX_ASLR
7920+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7921+
7922+#ifdef __powerpc64__
7923+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7924+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7925+#else
7926+#define PAX_DELTA_MMAP_LEN 15
7927+#define PAX_DELTA_STACK_LEN 15
7928+#endif
7929+#endif
7930
7931 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7932
7933@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7934 (0x7ff >> (PAGE_SHIFT - 12)) : \
7935 (0x3ffff >> (PAGE_SHIFT - 12)))
7936
7937-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7938-#define arch_randomize_brk arch_randomize_brk
7939-
7940-
7941 #ifdef CONFIG_SPU_BASE
7942 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7943 #define NT_SPU 1
7944diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7945index 8196e9c..d83a9f3 100644
7946--- a/arch/powerpc/include/asm/exec.h
7947+++ b/arch/powerpc/include/asm/exec.h
7948@@ -4,6 +4,6 @@
7949 #ifndef _ASM_POWERPC_EXEC_H
7950 #define _ASM_POWERPC_EXEC_H
7951
7952-extern unsigned long arch_align_stack(unsigned long sp);
7953+#define arch_align_stack(x) ((x) & ~0xfUL)
7954
7955 #endif /* _ASM_POWERPC_EXEC_H */
7956diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7957index 5acabbd..7ea14fa 100644
7958--- a/arch/powerpc/include/asm/kmap_types.h
7959+++ b/arch/powerpc/include/asm/kmap_types.h
7960@@ -10,7 +10,7 @@
7961 * 2 of the License, or (at your option) any later version.
7962 */
7963
7964-#define KM_TYPE_NR 16
7965+#define KM_TYPE_NR 17
7966
7967 #endif /* __KERNEL__ */
7968 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7969diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
7970index b8da913..60b608a 100644
7971--- a/arch/powerpc/include/asm/local.h
7972+++ b/arch/powerpc/include/asm/local.h
7973@@ -9,15 +9,26 @@ typedef struct
7974 atomic_long_t a;
7975 } local_t;
7976
7977+typedef struct
7978+{
7979+ atomic_long_unchecked_t a;
7980+} local_unchecked_t;
7981+
7982 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7983
7984 #define local_read(l) atomic_long_read(&(l)->a)
7985+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7986 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
7987+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
7988
7989 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
7990+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
7991 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
7992+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
7993 #define local_inc(l) atomic_long_inc(&(l)->a)
7994+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7995 #define local_dec(l) atomic_long_dec(&(l)->a)
7996+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7997
7998 static __inline__ long local_add_return(long a, local_t *l)
7999 {
8000@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8001
8002 return t;
8003 }
8004+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8005
8006 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8007
8008@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8009
8010 return t;
8011 }
8012+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8013
8014 static __inline__ long local_inc_return(local_t *l)
8015 {
8016@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8017
8018 #define local_cmpxchg(l, o, n) \
8019 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8020+#define local_cmpxchg_unchecked(l, o, n) \
8021+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8022 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8023
8024 /**
8025diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8026index 8565c25..2865190 100644
8027--- a/arch/powerpc/include/asm/mman.h
8028+++ b/arch/powerpc/include/asm/mman.h
8029@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8030 }
8031 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8032
8033-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8034+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8035 {
8036 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8037 }
8038diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8039index 32e4e21..62afb12 100644
8040--- a/arch/powerpc/include/asm/page.h
8041+++ b/arch/powerpc/include/asm/page.h
8042@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8043 * and needs to be executable. This means the whole heap ends
8044 * up being executable.
8045 */
8046-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8047- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8048+#define VM_DATA_DEFAULT_FLAGS32 \
8049+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8050+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8051
8052 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8054@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8055 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8056 #endif
8057
8058+#define ktla_ktva(addr) (addr)
8059+#define ktva_ktla(addr) (addr)
8060+
8061 #ifndef CONFIG_PPC_BOOK3S_64
8062 /*
8063 * Use the top bit of the higher-level page table entries to indicate whether
8064diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8065index 88693ce..ac6f9ab 100644
8066--- a/arch/powerpc/include/asm/page_64.h
8067+++ b/arch/powerpc/include/asm/page_64.h
8068@@ -153,15 +153,18 @@ do { \
8069 * stack by default, so in the absence of a PT_GNU_STACK program header
8070 * we turn execute permission off.
8071 */
8072-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8073- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8074+#define VM_STACK_DEFAULT_FLAGS32 \
8075+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8076+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8077
8078 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8079 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8080
8081+#ifndef CONFIG_PAX_PAGEEXEC
8082 #define VM_STACK_DEFAULT_FLAGS \
8083 (is_32bit_task() ? \
8084 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8085+#endif
8086
8087 #include <asm-generic/getorder.h>
8088
8089diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8090index 4b0be20..c15a27d 100644
8091--- a/arch/powerpc/include/asm/pgalloc-64.h
8092+++ b/arch/powerpc/include/asm/pgalloc-64.h
8093@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8094 #ifndef CONFIG_PPC_64K_PAGES
8095
8096 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8097+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8098
8099 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8100 {
8101@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8102 pud_set(pud, (unsigned long)pmd);
8103 }
8104
8105+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8106+{
8107+ pud_populate(mm, pud, pmd);
8108+}
8109+
8110 #define pmd_populate(mm, pmd, pte_page) \
8111 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8112 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8113@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8114 #endif
8115
8116 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8117+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8118
8119 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8120 pte_t *pte)
8121diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8122index 3ebb188..e17dddf 100644
8123--- a/arch/powerpc/include/asm/pgtable.h
8124+++ b/arch/powerpc/include/asm/pgtable.h
8125@@ -2,6 +2,7 @@
8126 #define _ASM_POWERPC_PGTABLE_H
8127 #ifdef __KERNEL__
8128
8129+#include <linux/const.h>
8130 #ifndef __ASSEMBLY__
8131 #include <linux/mmdebug.h>
8132 #include <asm/processor.h> /* For TASK_SIZE */
8133diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8134index 4aad413..85d86bf 100644
8135--- a/arch/powerpc/include/asm/pte-hash32.h
8136+++ b/arch/powerpc/include/asm/pte-hash32.h
8137@@ -21,6 +21,7 @@
8138 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8139 #define _PAGE_USER 0x004 /* usermode access allowed */
8140 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8141+#define _PAGE_EXEC _PAGE_GUARDED
8142 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8143 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8144 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8145diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8146index 90c06ec..3517221 100644
8147--- a/arch/powerpc/include/asm/reg.h
8148+++ b/arch/powerpc/include/asm/reg.h
8149@@ -248,6 +248,7 @@
8150 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8151 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8152 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8153+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8154 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8155 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8156 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8157diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8158index 084e080..9415a3d 100644
8159--- a/arch/powerpc/include/asm/smp.h
8160+++ b/arch/powerpc/include/asm/smp.h
8161@@ -51,7 +51,7 @@ struct smp_ops_t {
8162 int (*cpu_disable)(void);
8163 void (*cpu_die)(unsigned int nr);
8164 int (*cpu_bootable)(unsigned int nr);
8165-};
8166+} __no_const;
8167
8168 extern void smp_send_debugger_break(void);
8169 extern void start_secondary_resume(void);
8170diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8171index b034ecd..af7e31f 100644
8172--- a/arch/powerpc/include/asm/thread_info.h
8173+++ b/arch/powerpc/include/asm/thread_info.h
8174@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8175 #if defined(CONFIG_PPC64)
8176 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8177 #endif
8178+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8179+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8180
8181 /* as above, but as bit values */
8182 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8183@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8184 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8185 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8186 #define _TIF_NOHZ (1<<TIF_NOHZ)
8187+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8188 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8189 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8190- _TIF_NOHZ)
8191+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8192
8193 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8194 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8195diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8196index 9485b43..3bd3c16 100644
8197--- a/arch/powerpc/include/asm/uaccess.h
8198+++ b/arch/powerpc/include/asm/uaccess.h
8199@@ -58,6 +58,7 @@
8200
8201 #endif
8202
8203+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8204 #define access_ok(type, addr, size) \
8205 (__chk_user_ptr(addr), \
8206 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8207@@ -318,52 +319,6 @@ do { \
8208 extern unsigned long __copy_tofrom_user(void __user *to,
8209 const void __user *from, unsigned long size);
8210
8211-#ifndef __powerpc64__
8212-
8213-static inline unsigned long copy_from_user(void *to,
8214- const void __user *from, unsigned long n)
8215-{
8216- unsigned long over;
8217-
8218- if (access_ok(VERIFY_READ, from, n))
8219- return __copy_tofrom_user((__force void __user *)to, from, n);
8220- if ((unsigned long)from < TASK_SIZE) {
8221- over = (unsigned long)from + n - TASK_SIZE;
8222- return __copy_tofrom_user((__force void __user *)to, from,
8223- n - over) + over;
8224- }
8225- return n;
8226-}
8227-
8228-static inline unsigned long copy_to_user(void __user *to,
8229- const void *from, unsigned long n)
8230-{
8231- unsigned long over;
8232-
8233- if (access_ok(VERIFY_WRITE, to, n))
8234- return __copy_tofrom_user(to, (__force void __user *)from, n);
8235- if ((unsigned long)to < TASK_SIZE) {
8236- over = (unsigned long)to + n - TASK_SIZE;
8237- return __copy_tofrom_user(to, (__force void __user *)from,
8238- n - over) + over;
8239- }
8240- return n;
8241-}
8242-
8243-#else /* __powerpc64__ */
8244-
8245-#define __copy_in_user(to, from, size) \
8246- __copy_tofrom_user((to), (from), (size))
8247-
8248-extern unsigned long copy_from_user(void *to, const void __user *from,
8249- unsigned long n);
8250-extern unsigned long copy_to_user(void __user *to, const void *from,
8251- unsigned long n);
8252-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8253- unsigned long n);
8254-
8255-#endif /* __powerpc64__ */
8256-
8257 static inline unsigned long __copy_from_user_inatomic(void *to,
8258 const void __user *from, unsigned long n)
8259 {
8260@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8261 if (ret == 0)
8262 return 0;
8263 }
8264+
8265+ if (!__builtin_constant_p(n))
8266+ check_object_size(to, n, false);
8267+
8268 return __copy_tofrom_user((__force void __user *)to, from, n);
8269 }
8270
8271@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8272 if (ret == 0)
8273 return 0;
8274 }
8275+
8276+ if (!__builtin_constant_p(n))
8277+ check_object_size(from, n, true);
8278+
8279 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8280 }
8281
8282@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8283 return __copy_to_user_inatomic(to, from, size);
8284 }
8285
8286+#ifndef __powerpc64__
8287+
8288+static inline unsigned long __must_check copy_from_user(void *to,
8289+ const void __user *from, unsigned long n)
8290+{
8291+ unsigned long over;
8292+
8293+ if ((long)n < 0)
8294+ return n;
8295+
8296+ if (access_ok(VERIFY_READ, from, n)) {
8297+ if (!__builtin_constant_p(n))
8298+ check_object_size(to, n, false);
8299+ return __copy_tofrom_user((__force void __user *)to, from, n);
8300+ }
8301+ if ((unsigned long)from < TASK_SIZE) {
8302+ over = (unsigned long)from + n - TASK_SIZE;
8303+ if (!__builtin_constant_p(n - over))
8304+ check_object_size(to, n - over, false);
8305+ return __copy_tofrom_user((__force void __user *)to, from,
8306+ n - over) + over;
8307+ }
8308+ return n;
8309+}
8310+
8311+static inline unsigned long __must_check copy_to_user(void __user *to,
8312+ const void *from, unsigned long n)
8313+{
8314+ unsigned long over;
8315+
8316+ if ((long)n < 0)
8317+ return n;
8318+
8319+ if (access_ok(VERIFY_WRITE, to, n)) {
8320+ if (!__builtin_constant_p(n))
8321+ check_object_size(from, n, true);
8322+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8323+ }
8324+ if ((unsigned long)to < TASK_SIZE) {
8325+ over = (unsigned long)to + n - TASK_SIZE;
8326+ if (!__builtin_constant_p(n))
8327+ check_object_size(from, n - over, true);
8328+ return __copy_tofrom_user(to, (__force void __user *)from,
8329+ n - over) + over;
8330+ }
8331+ return n;
8332+}
8333+
8334+#else /* __powerpc64__ */
8335+
8336+#define __copy_in_user(to, from, size) \
8337+ __copy_tofrom_user((to), (from), (size))
8338+
8339+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8340+{
8341+ if ((long)n < 0 || n > INT_MAX)
8342+ return n;
8343+
8344+ if (!__builtin_constant_p(n))
8345+ check_object_size(to, n, false);
8346+
8347+ if (likely(access_ok(VERIFY_READ, from, n)))
8348+ n = __copy_from_user(to, from, n);
8349+ else
8350+ memset(to, 0, n);
8351+ return n;
8352+}
8353+
8354+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8355+{
8356+ if ((long)n < 0 || n > INT_MAX)
8357+ return n;
8358+
8359+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8360+ if (!__builtin_constant_p(n))
8361+ check_object_size(from, n, true);
8362+ n = __copy_to_user(to, from, n);
8363+ }
8364+ return n;
8365+}
8366+
8367+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8368+ unsigned long n);
8369+
8370+#endif /* __powerpc64__ */
8371+
8372 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8373
8374 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8375diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8376index fcc9a89..07be2bb 100644
8377--- a/arch/powerpc/kernel/Makefile
8378+++ b/arch/powerpc/kernel/Makefile
8379@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8380 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8381 endif
8382
8383+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8384+
8385 obj-y := cputable.o ptrace.o syscalls.o \
8386 irq.o align.o signal_32.o pmc.o vdso.o \
8387 process.o systbl.o idle.o \
8388diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8389index 063b65d..7a26e9d 100644
8390--- a/arch/powerpc/kernel/exceptions-64e.S
8391+++ b/arch/powerpc/kernel/exceptions-64e.S
8392@@ -771,6 +771,7 @@ storage_fault_common:
8393 std r14,_DAR(r1)
8394 std r15,_DSISR(r1)
8395 addi r3,r1,STACK_FRAME_OVERHEAD
8396+ bl .save_nvgprs
8397 mr r4,r14
8398 mr r5,r15
8399 ld r14,PACA_EXGEN+EX_R14(r13)
8400@@ -779,8 +780,7 @@ storage_fault_common:
8401 cmpdi r3,0
8402 bne- 1f
8403 b .ret_from_except_lite
8404-1: bl .save_nvgprs
8405- mr r5,r3
8406+1: mr r5,r3
8407 addi r3,r1,STACK_FRAME_OVERHEAD
8408 ld r4,_DAR(r1)
8409 bl .bad_page_fault
8410diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8411index 38d5073..f00af8d 100644
8412--- a/arch/powerpc/kernel/exceptions-64s.S
8413+++ b/arch/powerpc/kernel/exceptions-64s.S
8414@@ -1584,10 +1584,10 @@ handle_page_fault:
8415 11: ld r4,_DAR(r1)
8416 ld r5,_DSISR(r1)
8417 addi r3,r1,STACK_FRAME_OVERHEAD
8418+ bl .save_nvgprs
8419 bl .do_page_fault
8420 cmpdi r3,0
8421 beq+ 12f
8422- bl .save_nvgprs
8423 mr r5,r3
8424 addi r3,r1,STACK_FRAME_OVERHEAD
8425 lwz r4,_DAR(r1)
8426diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8427index 6cff040..74ac5d1 100644
8428--- a/arch/powerpc/kernel/module_32.c
8429+++ b/arch/powerpc/kernel/module_32.c
8430@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8431 me->arch.core_plt_section = i;
8432 }
8433 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8434- printk("Module doesn't contain .plt or .init.plt sections.\n");
8435+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8436 return -ENOEXEC;
8437 }
8438
8439@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8440
8441 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8442 /* Init, or core PLT? */
8443- if (location >= mod->module_core
8444- && location < mod->module_core + mod->core_size)
8445+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8446+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8447 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8448- else
8449+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8450+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8451 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8452+ else {
8453+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8454+ return ~0UL;
8455+ }
8456
8457 /* Find this entry, or if that fails, the next avail. entry */
8458 while (entry->jump[0]) {
8459@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8460 }
8461 #ifdef CONFIG_DYNAMIC_FTRACE
8462 module->arch.tramp =
8463- do_plt_call(module->module_core,
8464+ do_plt_call(module->module_core_rx,
8465 (unsigned long)ftrace_caller,
8466 sechdrs, module);
8467 #endif
8468diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8469index af064d2..ce56147 100644
8470--- a/arch/powerpc/kernel/process.c
8471+++ b/arch/powerpc/kernel/process.c
8472@@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8473 * Lookup NIP late so we have the best change of getting the
8474 * above info out without failing
8475 */
8476- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8477- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8478+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8479+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8480 #endif
8481 show_stack(current, (unsigned long *) regs->gpr[1]);
8482 if (!user_mode(regs))
8483@@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8484 newsp = stack[0];
8485 ip = stack[STACK_FRAME_LR_SAVE];
8486 if (!firstframe || ip != lr) {
8487- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8488+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8489 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8490 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8491- printk(" (%pS)",
8492+ printk(" (%pA)",
8493 (void *)current->ret_stack[curr_frame].ret);
8494 curr_frame--;
8495 }
8496@@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8497 struct pt_regs *regs = (struct pt_regs *)
8498 (sp + STACK_FRAME_OVERHEAD);
8499 lr = regs->link;
8500- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8501+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8502 regs->trap, (void *)regs->nip, (void *)lr);
8503 firstframe = 1;
8504 }
8505@@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8506 mtspr(SPRN_CTRLT, ctrl);
8507 }
8508 #endif /* CONFIG_PPC64 */
8509-
8510-unsigned long arch_align_stack(unsigned long sp)
8511-{
8512- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8513- sp -= get_random_int() & ~PAGE_MASK;
8514- return sp & ~0xf;
8515-}
8516-
8517-static inline unsigned long brk_rnd(void)
8518-{
8519- unsigned long rnd = 0;
8520-
8521- /* 8MB for 32bit, 1GB for 64bit */
8522- if (is_32bit_task())
8523- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8524- else
8525- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8526-
8527- return rnd << PAGE_SHIFT;
8528-}
8529-
8530-unsigned long arch_randomize_brk(struct mm_struct *mm)
8531-{
8532- unsigned long base = mm->brk;
8533- unsigned long ret;
8534-
8535-#ifdef CONFIG_PPC_STD_MMU_64
8536- /*
8537- * If we are using 1TB segments and we are allowed to randomise
8538- * the heap, we can put it above 1TB so it is backed by a 1TB
8539- * segment. Otherwise the heap will be in the bottom 1TB
8540- * which always uses 256MB segments and this may result in a
8541- * performance penalty.
8542- */
8543- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8544- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8545-#endif
8546-
8547- ret = PAGE_ALIGN(base + brk_rnd());
8548-
8549- if (ret < mm->brk)
8550- return mm->brk;
8551-
8552- return ret;
8553-}
8554-
8555-unsigned long randomize_et_dyn(unsigned long base)
8556-{
8557- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8558-
8559- if (ret < base)
8560- return base;
8561-
8562- return ret;
8563-}
8564diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8565index 2e3d2bf..35df241 100644
8566--- a/arch/powerpc/kernel/ptrace.c
8567+++ b/arch/powerpc/kernel/ptrace.c
8568@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8569 return ret;
8570 }
8571
8572+#ifdef CONFIG_GRKERNSEC_SETXID
8573+extern void gr_delayed_cred_worker(void);
8574+#endif
8575+
8576 /*
8577 * We must return the syscall number to actually look up in the table.
8578 * This can be -1L to skip running any syscall at all.
8579@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8580
8581 secure_computing_strict(regs->gpr[0]);
8582
8583+#ifdef CONFIG_GRKERNSEC_SETXID
8584+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8585+ gr_delayed_cred_worker();
8586+#endif
8587+
8588 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8589 tracehook_report_syscall_entry(regs))
8590 /*
8591@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8592 {
8593 int step;
8594
8595+#ifdef CONFIG_GRKERNSEC_SETXID
8596+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8597+ gr_delayed_cred_worker();
8598+#endif
8599+
8600 audit_syscall_exit(regs);
8601
8602 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8603diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8604index a67e00a..f71d8c7 100644
8605--- a/arch/powerpc/kernel/signal_32.c
8606+++ b/arch/powerpc/kernel/signal_32.c
8607@@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8608 /* Save user registers on the stack */
8609 frame = &rt_sf->uc.uc_mcontext;
8610 addr = frame;
8611- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8612+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8613 sigret = 0;
8614 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8615 } else {
8616diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8617index 8d253c2..405b337 100644
8618--- a/arch/powerpc/kernel/signal_64.c
8619+++ b/arch/powerpc/kernel/signal_64.c
8620@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8621 current->thread.fp_state.fpscr = 0;
8622
8623 /* Set up to return from userspace. */
8624- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8625+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8626 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8627 } else {
8628 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8629diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8630index 33cd7a0..d615344 100644
8631--- a/arch/powerpc/kernel/traps.c
8632+++ b/arch/powerpc/kernel/traps.c
8633@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8634 return flags;
8635 }
8636
8637+extern void gr_handle_kernel_exploit(void);
8638+
8639 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8640 int signr)
8641 {
8642@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8643 panic("Fatal exception in interrupt");
8644 if (panic_on_oops)
8645 panic("Fatal exception");
8646+
8647+ gr_handle_kernel_exploit();
8648+
8649 do_exit(signr);
8650 }
8651
8652diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8653index 094e45c..d82b848 100644
8654--- a/arch/powerpc/kernel/vdso.c
8655+++ b/arch/powerpc/kernel/vdso.c
8656@@ -35,6 +35,7 @@
8657 #include <asm/vdso.h>
8658 #include <asm/vdso_datapage.h>
8659 #include <asm/setup.h>
8660+#include <asm/mman.h>
8661
8662 #undef DEBUG
8663
8664@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8665 vdso_base = VDSO32_MBASE;
8666 #endif
8667
8668- current->mm->context.vdso_base = 0;
8669+ current->mm->context.vdso_base = ~0UL;
8670
8671 /* vDSO has a problem and was disabled, just don't "enable" it for the
8672 * process
8673@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8674 vdso_base = get_unmapped_area(NULL, vdso_base,
8675 (vdso_pages << PAGE_SHIFT) +
8676 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8677- 0, 0);
8678+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8679 if (IS_ERR_VALUE(vdso_base)) {
8680 rc = vdso_base;
8681 goto fail_mmapsem;
8682diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8683index 3cf541a..ab2d825 100644
8684--- a/arch/powerpc/kvm/powerpc.c
8685+++ b/arch/powerpc/kvm/powerpc.c
8686@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8687 }
8688 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8689
8690-int kvm_arch_init(void *opaque)
8691+int kvm_arch_init(const void *opaque)
8692 {
8693 return 0;
8694 }
8695diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8696index 5eea6f3..5d10396 100644
8697--- a/arch/powerpc/lib/usercopy_64.c
8698+++ b/arch/powerpc/lib/usercopy_64.c
8699@@ -9,22 +9,6 @@
8700 #include <linux/module.h>
8701 #include <asm/uaccess.h>
8702
8703-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8704-{
8705- if (likely(access_ok(VERIFY_READ, from, n)))
8706- n = __copy_from_user(to, from, n);
8707- else
8708- memset(to, 0, n);
8709- return n;
8710-}
8711-
8712-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8713-{
8714- if (likely(access_ok(VERIFY_WRITE, to, n)))
8715- n = __copy_to_user(to, from, n);
8716- return n;
8717-}
8718-
8719 unsigned long copy_in_user(void __user *to, const void __user *from,
8720 unsigned long n)
8721 {
8722@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8723 return n;
8724 }
8725
8726-EXPORT_SYMBOL(copy_from_user);
8727-EXPORT_SYMBOL(copy_to_user);
8728 EXPORT_SYMBOL(copy_in_user);
8729
8730diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8731index 51ab9e7..7d3c78b 100644
8732--- a/arch/powerpc/mm/fault.c
8733+++ b/arch/powerpc/mm/fault.c
8734@@ -33,6 +33,10 @@
8735 #include <linux/magic.h>
8736 #include <linux/ratelimit.h>
8737 #include <linux/context_tracking.h>
8738+#include <linux/slab.h>
8739+#include <linux/pagemap.h>
8740+#include <linux/compiler.h>
8741+#include <linux/unistd.h>
8742
8743 #include <asm/firmware.h>
8744 #include <asm/page.h>
8745@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8746 }
8747 #endif
8748
8749+#ifdef CONFIG_PAX_PAGEEXEC
8750+/*
8751+ * PaX: decide what to do with offenders (regs->nip = fault address)
8752+ *
8753+ * returns 1 when task should be killed
8754+ */
8755+static int pax_handle_fetch_fault(struct pt_regs *regs)
8756+{
8757+ return 1;
8758+}
8759+
8760+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8761+{
8762+ unsigned long i;
8763+
8764+ printk(KERN_ERR "PAX: bytes at PC: ");
8765+ for (i = 0; i < 5; i++) {
8766+ unsigned int c;
8767+ if (get_user(c, (unsigned int __user *)pc+i))
8768+ printk(KERN_CONT "???????? ");
8769+ else
8770+ printk(KERN_CONT "%08x ", c);
8771+ }
8772+ printk("\n");
8773+}
8774+#endif
8775+
8776 /*
8777 * Check whether the instruction at regs->nip is a store using
8778 * an update addressing form which will update r1.
8779@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8780 * indicate errors in DSISR but can validly be set in SRR1.
8781 */
8782 if (trap == 0x400)
8783- error_code &= 0x48200000;
8784+ error_code &= 0x58200000;
8785 else
8786 is_write = error_code & DSISR_ISSTORE;
8787 #else
8788@@ -378,7 +409,7 @@ good_area:
8789 * "undefined". Of those that can be set, this is the only
8790 * one which seems bad.
8791 */
8792- if (error_code & 0x10000000)
8793+ if (error_code & DSISR_GUARDED)
8794 /* Guarded storage error. */
8795 goto bad_area;
8796 #endif /* CONFIG_8xx */
8797@@ -393,7 +424,7 @@ good_area:
8798 * processors use the same I/D cache coherency mechanism
8799 * as embedded.
8800 */
8801- if (error_code & DSISR_PROTFAULT)
8802+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8803 goto bad_area;
8804 #endif /* CONFIG_PPC_STD_MMU */
8805
8806@@ -483,6 +514,23 @@ bad_area:
8807 bad_area_nosemaphore:
8808 /* User mode accesses cause a SIGSEGV */
8809 if (user_mode(regs)) {
8810+
8811+#ifdef CONFIG_PAX_PAGEEXEC
8812+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8813+#ifdef CONFIG_PPC_STD_MMU
8814+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8815+#else
8816+ if (is_exec && regs->nip == address) {
8817+#endif
8818+ switch (pax_handle_fetch_fault(regs)) {
8819+ }
8820+
8821+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8822+ do_group_exit(SIGKILL);
8823+ }
8824+ }
8825+#endif
8826+
8827 _exception(SIGSEGV, regs, code, address);
8828 goto bail;
8829 }
8830diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8831index cb8bdbe..cde4bc7 100644
8832--- a/arch/powerpc/mm/mmap.c
8833+++ b/arch/powerpc/mm/mmap.c
8834@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8835 return sysctl_legacy_va_layout;
8836 }
8837
8838-static unsigned long mmap_rnd(void)
8839+static unsigned long mmap_rnd(struct mm_struct *mm)
8840 {
8841 unsigned long rnd = 0;
8842
8843+#ifdef CONFIG_PAX_RANDMMAP
8844+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8845+#endif
8846+
8847 if (current->flags & PF_RANDOMIZE) {
8848 /* 8MB for 32bit, 1GB for 64bit */
8849 if (is_32bit_task())
8850@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8851 return rnd << PAGE_SHIFT;
8852 }
8853
8854-static inline unsigned long mmap_base(void)
8855+static inline unsigned long mmap_base(struct mm_struct *mm)
8856 {
8857 unsigned long gap = rlimit(RLIMIT_STACK);
8858
8859@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8860 else if (gap > MAX_GAP)
8861 gap = MAX_GAP;
8862
8863- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8864+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8865 }
8866
8867 /*
8868@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8869 */
8870 if (mmap_is_legacy()) {
8871 mm->mmap_base = TASK_UNMAPPED_BASE;
8872+
8873+#ifdef CONFIG_PAX_RANDMMAP
8874+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8875+ mm->mmap_base += mm->delta_mmap;
8876+#endif
8877+
8878 mm->get_unmapped_area = arch_get_unmapped_area;
8879 } else {
8880- mm->mmap_base = mmap_base();
8881+ mm->mmap_base = mmap_base(mm);
8882+
8883+#ifdef CONFIG_PAX_RANDMMAP
8884+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8885+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8886+#endif
8887+
8888 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8889 }
8890 }
8891diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8892index b0c75cc..ef7fb93 100644
8893--- a/arch/powerpc/mm/slice.c
8894+++ b/arch/powerpc/mm/slice.c
8895@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8896 if ((mm->task_size - len) < addr)
8897 return 0;
8898 vma = find_vma(mm, addr);
8899- return (!vma || (addr + len) <= vma->vm_start);
8900+ return check_heap_stack_gap(vma, addr, len, 0);
8901 }
8902
8903 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8904@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8905 info.align_offset = 0;
8906
8907 addr = TASK_UNMAPPED_BASE;
8908+
8909+#ifdef CONFIG_PAX_RANDMMAP
8910+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8911+ addr += mm->delta_mmap;
8912+#endif
8913+
8914 while (addr < TASK_SIZE) {
8915 info.low_limit = addr;
8916 if (!slice_scan_available(addr, available, 1, &addr))
8917@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8918 if (fixed && addr > (mm->task_size - len))
8919 return -ENOMEM;
8920
8921+#ifdef CONFIG_PAX_RANDMMAP
8922+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8923+ addr = 0;
8924+#endif
8925+
8926 /* If hint, make sure it matches our alignment restrictions */
8927 if (!fixed && addr) {
8928 addr = _ALIGN_UP(addr, 1ul << pshift);
8929diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8930index 4278acf..67fd0e6 100644
8931--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8932+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8933@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8934 }
8935
8936 static struct pci_ops scc_pciex_pci_ops = {
8937- scc_pciex_read_config,
8938- scc_pciex_write_config,
8939+ .read = scc_pciex_read_config,
8940+ .write = scc_pciex_write_config,
8941 };
8942
8943 static void pciex_clear_intr_all(unsigned int __iomem *base)
8944diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8945index 9098692..3d54cd1 100644
8946--- a/arch/powerpc/platforms/cell/spufs/file.c
8947+++ b/arch/powerpc/platforms/cell/spufs/file.c
8948@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8949 return VM_FAULT_NOPAGE;
8950 }
8951
8952-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8953+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8954 unsigned long address,
8955- void *buf, int len, int write)
8956+ void *buf, size_t len, int write)
8957 {
8958 struct spu_context *ctx = vma->vm_file->private_data;
8959 unsigned long offset = address - vma->vm_start;
8960diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8961index 1d47061..0714963 100644
8962--- a/arch/s390/include/asm/atomic.h
8963+++ b/arch/s390/include/asm/atomic.h
8964@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8965 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8966 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8967
8968+#define atomic64_read_unchecked(v) atomic64_read(v)
8969+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8970+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8971+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8972+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8973+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8974+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8975+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8976+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8977+
8978 #define smp_mb__before_atomic_dec() smp_mb()
8979 #define smp_mb__after_atomic_dec() smp_mb()
8980 #define smp_mb__before_atomic_inc() smp_mb()
8981diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8982index 4d7ccac..d03d0ad 100644
8983--- a/arch/s390/include/asm/cache.h
8984+++ b/arch/s390/include/asm/cache.h
8985@@ -9,8 +9,10 @@
8986 #ifndef __ARCH_S390_CACHE_H
8987 #define __ARCH_S390_CACHE_H
8988
8989-#define L1_CACHE_BYTES 256
8990+#include <linux/const.h>
8991+
8992 #define L1_CACHE_SHIFT 8
8993+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8994 #define NET_SKB_PAD 32
8995
8996 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8997diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8998index 78f4f87..598ce39 100644
8999--- a/arch/s390/include/asm/elf.h
9000+++ b/arch/s390/include/asm/elf.h
9001@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9002 the loader. We need to make sure that it is out of the way of the program
9003 that it will "exec", and that there is sufficient room for the brk. */
9004
9005-extern unsigned long randomize_et_dyn(unsigned long base);
9006-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9007+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9008+
9009+#ifdef CONFIG_PAX_ASLR
9010+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9011+
9012+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9013+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9014+#endif
9015
9016 /* This yields a mask that user programs can use to figure out what
9017 instruction set this CPU supports. */
9018@@ -222,9 +228,6 @@ struct linux_binprm;
9019 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9020 int arch_setup_additional_pages(struct linux_binprm *, int);
9021
9022-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9023-#define arch_randomize_brk arch_randomize_brk
9024-
9025 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9026
9027 #endif
9028diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9029index c4a93d6..4d2a9b4 100644
9030--- a/arch/s390/include/asm/exec.h
9031+++ b/arch/s390/include/asm/exec.h
9032@@ -7,6 +7,6 @@
9033 #ifndef __ASM_EXEC_H
9034 #define __ASM_EXEC_H
9035
9036-extern unsigned long arch_align_stack(unsigned long sp);
9037+#define arch_align_stack(x) ((x) & ~0xfUL)
9038
9039 #endif /* __ASM_EXEC_H */
9040diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9041index 79330af..254cf37 100644
9042--- a/arch/s390/include/asm/uaccess.h
9043+++ b/arch/s390/include/asm/uaccess.h
9044@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9045 __range_ok((unsigned long)(addr), (size)); \
9046 })
9047
9048+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9049 #define access_ok(type, addr, size) __access_ok(addr, size)
9050
9051 /*
9052@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9053 copy_to_user(void __user *to, const void *from, unsigned long n)
9054 {
9055 might_fault();
9056+
9057+ if ((long)n < 0)
9058+ return n;
9059+
9060 return __copy_to_user(to, from, n);
9061 }
9062
9063@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9064 static inline unsigned long __must_check
9065 __copy_from_user(void *to, const void __user *from, unsigned long n)
9066 {
9067+ if ((long)n < 0)
9068+ return n;
9069+
9070 return uaccess.copy_from_user(n, from, to);
9071 }
9072
9073@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9074 static inline unsigned long __must_check
9075 copy_from_user(void *to, const void __user *from, unsigned long n)
9076 {
9077- unsigned int sz = __compiletime_object_size(to);
9078+ size_t sz = __compiletime_object_size(to);
9079
9080 might_fault();
9081- if (unlikely(sz != -1 && sz < n)) {
9082+
9083+ if ((long)n < 0)
9084+ return n;
9085+
9086+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9087 copy_from_user_overflow();
9088 return n;
9089 }
9090diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9091index b89b591..fd9609d 100644
9092--- a/arch/s390/kernel/module.c
9093+++ b/arch/s390/kernel/module.c
9094@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9095
9096 /* Increase core size by size of got & plt and set start
9097 offsets for got and plt. */
9098- me->core_size = ALIGN(me->core_size, 4);
9099- me->arch.got_offset = me->core_size;
9100- me->core_size += me->arch.got_size;
9101- me->arch.plt_offset = me->core_size;
9102- me->core_size += me->arch.plt_size;
9103+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9104+ me->arch.got_offset = me->core_size_rw;
9105+ me->core_size_rw += me->arch.got_size;
9106+ me->arch.plt_offset = me->core_size_rx;
9107+ me->core_size_rx += me->arch.plt_size;
9108 return 0;
9109 }
9110
9111@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9112 if (info->got_initialized == 0) {
9113 Elf_Addr *gotent;
9114
9115- gotent = me->module_core + me->arch.got_offset +
9116+ gotent = me->module_core_rw + me->arch.got_offset +
9117 info->got_offset;
9118 *gotent = val;
9119 info->got_initialized = 1;
9120@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9121 rc = apply_rela_bits(loc, val, 0, 64, 0);
9122 else if (r_type == R_390_GOTENT ||
9123 r_type == R_390_GOTPLTENT) {
9124- val += (Elf_Addr) me->module_core - loc;
9125+ val += (Elf_Addr) me->module_core_rw - loc;
9126 rc = apply_rela_bits(loc, val, 1, 32, 1);
9127 }
9128 break;
9129@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9130 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9131 if (info->plt_initialized == 0) {
9132 unsigned int *ip;
9133- ip = me->module_core + me->arch.plt_offset +
9134+ ip = me->module_core_rx + me->arch.plt_offset +
9135 info->plt_offset;
9136 #ifndef CONFIG_64BIT
9137 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9138@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9139 val - loc + 0xffffUL < 0x1ffffeUL) ||
9140 (r_type == R_390_PLT32DBL &&
9141 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9142- val = (Elf_Addr) me->module_core +
9143+ val = (Elf_Addr) me->module_core_rx +
9144 me->arch.plt_offset +
9145 info->plt_offset;
9146 val += rela->r_addend - loc;
9147@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9148 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9149 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9150 val = val + rela->r_addend -
9151- ((Elf_Addr) me->module_core + me->arch.got_offset);
9152+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9153 if (r_type == R_390_GOTOFF16)
9154 rc = apply_rela_bits(loc, val, 0, 16, 0);
9155 else if (r_type == R_390_GOTOFF32)
9156@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9157 break;
9158 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9159 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9160- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9161+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9162 rela->r_addend - loc;
9163 if (r_type == R_390_GOTPC)
9164 rc = apply_rela_bits(loc, val, 1, 32, 0);
9165diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9166index dd14532..1dfc145 100644
9167--- a/arch/s390/kernel/process.c
9168+++ b/arch/s390/kernel/process.c
9169@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9170 }
9171 return 0;
9172 }
9173-
9174-unsigned long arch_align_stack(unsigned long sp)
9175-{
9176- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9177- sp -= get_random_int() & ~PAGE_MASK;
9178- return sp & ~0xf;
9179-}
9180-
9181-static inline unsigned long brk_rnd(void)
9182-{
9183- /* 8MB for 32bit, 1GB for 64bit */
9184- if (is_32bit_task())
9185- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9186- else
9187- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9188-}
9189-
9190-unsigned long arch_randomize_brk(struct mm_struct *mm)
9191-{
9192- unsigned long ret;
9193-
9194- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9195- return (ret > mm->brk) ? ret : mm->brk;
9196-}
9197-
9198-unsigned long randomize_et_dyn(unsigned long base)
9199-{
9200- unsigned long ret;
9201-
9202- if (!(current->flags & PF_RANDOMIZE))
9203- return base;
9204- ret = PAGE_ALIGN(base + brk_rnd());
9205- return (ret > base) ? ret : base;
9206-}
9207diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9208index 9b436c2..54fbf0a 100644
9209--- a/arch/s390/mm/mmap.c
9210+++ b/arch/s390/mm/mmap.c
9211@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9212 */
9213 if (mmap_is_legacy()) {
9214 mm->mmap_base = mmap_base_legacy();
9215+
9216+#ifdef CONFIG_PAX_RANDMMAP
9217+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9218+ mm->mmap_base += mm->delta_mmap;
9219+#endif
9220+
9221 mm->get_unmapped_area = arch_get_unmapped_area;
9222 } else {
9223 mm->mmap_base = mmap_base();
9224+
9225+#ifdef CONFIG_PAX_RANDMMAP
9226+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9227+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9228+#endif
9229+
9230 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9231 }
9232 }
9233@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9234 */
9235 if (mmap_is_legacy()) {
9236 mm->mmap_base = mmap_base_legacy();
9237+
9238+#ifdef CONFIG_PAX_RANDMMAP
9239+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9240+ mm->mmap_base += mm->delta_mmap;
9241+#endif
9242+
9243 mm->get_unmapped_area = s390_get_unmapped_area;
9244 } else {
9245 mm->mmap_base = mmap_base();
9246+
9247+#ifdef CONFIG_PAX_RANDMMAP
9248+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9249+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9250+#endif
9251+
9252 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9253 }
9254 }
9255diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9256index ae3d59f..f65f075 100644
9257--- a/arch/score/include/asm/cache.h
9258+++ b/arch/score/include/asm/cache.h
9259@@ -1,7 +1,9 @@
9260 #ifndef _ASM_SCORE_CACHE_H
9261 #define _ASM_SCORE_CACHE_H
9262
9263+#include <linux/const.h>
9264+
9265 #define L1_CACHE_SHIFT 4
9266-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9267+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9268
9269 #endif /* _ASM_SCORE_CACHE_H */
9270diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9271index f9f3cd5..58ff438 100644
9272--- a/arch/score/include/asm/exec.h
9273+++ b/arch/score/include/asm/exec.h
9274@@ -1,6 +1,6 @@
9275 #ifndef _ASM_SCORE_EXEC_H
9276 #define _ASM_SCORE_EXEC_H
9277
9278-extern unsigned long arch_align_stack(unsigned long sp);
9279+#define arch_align_stack(x) (x)
9280
9281 #endif /* _ASM_SCORE_EXEC_H */
9282diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9283index a1519ad3..e8ac1ff 100644
9284--- a/arch/score/kernel/process.c
9285+++ b/arch/score/kernel/process.c
9286@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9287
9288 return task_pt_regs(task)->cp0_epc;
9289 }
9290-
9291-unsigned long arch_align_stack(unsigned long sp)
9292-{
9293- return sp;
9294-}
9295diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9296index ef9e555..331bd29 100644
9297--- a/arch/sh/include/asm/cache.h
9298+++ b/arch/sh/include/asm/cache.h
9299@@ -9,10 +9,11 @@
9300 #define __ASM_SH_CACHE_H
9301 #ifdef __KERNEL__
9302
9303+#include <linux/const.h>
9304 #include <linux/init.h>
9305 #include <cpu/cache.h>
9306
9307-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9308+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9309
9310 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9311
9312diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9313index 6777177..cb5e44f 100644
9314--- a/arch/sh/mm/mmap.c
9315+++ b/arch/sh/mm/mmap.c
9316@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9317 struct mm_struct *mm = current->mm;
9318 struct vm_area_struct *vma;
9319 int do_colour_align;
9320+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9321 struct vm_unmapped_area_info info;
9322
9323 if (flags & MAP_FIXED) {
9324@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9325 if (filp || (flags & MAP_SHARED))
9326 do_colour_align = 1;
9327
9328+#ifdef CONFIG_PAX_RANDMMAP
9329+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9330+#endif
9331+
9332 if (addr) {
9333 if (do_colour_align)
9334 addr = COLOUR_ALIGN(addr, pgoff);
9335@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9336 addr = PAGE_ALIGN(addr);
9337
9338 vma = find_vma(mm, addr);
9339- if (TASK_SIZE - len >= addr &&
9340- (!vma || addr + len <= vma->vm_start))
9341+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9342 return addr;
9343 }
9344
9345 info.flags = 0;
9346 info.length = len;
9347- info.low_limit = TASK_UNMAPPED_BASE;
9348+ info.low_limit = mm->mmap_base;
9349 info.high_limit = TASK_SIZE;
9350 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9351 info.align_offset = pgoff << PAGE_SHIFT;
9352@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9353 struct mm_struct *mm = current->mm;
9354 unsigned long addr = addr0;
9355 int do_colour_align;
9356+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9357 struct vm_unmapped_area_info info;
9358
9359 if (flags & MAP_FIXED) {
9360@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9361 if (filp || (flags & MAP_SHARED))
9362 do_colour_align = 1;
9363
9364+#ifdef CONFIG_PAX_RANDMMAP
9365+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9366+#endif
9367+
9368 /* requesting a specific address */
9369 if (addr) {
9370 if (do_colour_align)
9371@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9372 addr = PAGE_ALIGN(addr);
9373
9374 vma = find_vma(mm, addr);
9375- if (TASK_SIZE - len >= addr &&
9376- (!vma || addr + len <= vma->vm_start))
9377+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9378 return addr;
9379 }
9380
9381@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9382 VM_BUG_ON(addr != -ENOMEM);
9383 info.flags = 0;
9384 info.low_limit = TASK_UNMAPPED_BASE;
9385+
9386+#ifdef CONFIG_PAX_RANDMMAP
9387+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9388+ info.low_limit += mm->delta_mmap;
9389+#endif
9390+
9391 info.high_limit = TASK_SIZE;
9392 addr = vm_unmapped_area(&info);
9393 }
9394diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9395index be56a24..443328f 100644
9396--- a/arch/sparc/include/asm/atomic_64.h
9397+++ b/arch/sparc/include/asm/atomic_64.h
9398@@ -14,18 +14,40 @@
9399 #define ATOMIC64_INIT(i) { (i) }
9400
9401 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9402+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9403+{
9404+ return v->counter;
9405+}
9406 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9407+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9408+{
9409+ return v->counter;
9410+}
9411
9412 #define atomic_set(v, i) (((v)->counter) = i)
9413+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9414+{
9415+ v->counter = i;
9416+}
9417 #define atomic64_set(v, i) (((v)->counter) = i)
9418+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9419+{
9420+ v->counter = i;
9421+}
9422
9423 extern void atomic_add(int, atomic_t *);
9424+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9425 extern void atomic64_add(long, atomic64_t *);
9426+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9427 extern void atomic_sub(int, atomic_t *);
9428+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9429 extern void atomic64_sub(long, atomic64_t *);
9430+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9431
9432 extern int atomic_add_ret(int, atomic_t *);
9433+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9434 extern long atomic64_add_ret(long, atomic64_t *);
9435+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9436 extern int atomic_sub_ret(int, atomic_t *);
9437 extern long atomic64_sub_ret(long, atomic64_t *);
9438
9439@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9440 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9441
9442 #define atomic_inc_return(v) atomic_add_ret(1, v)
9443+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9444+{
9445+ return atomic_add_ret_unchecked(1, v);
9446+}
9447 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9448+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9449+{
9450+ return atomic64_add_ret_unchecked(1, v);
9451+}
9452
9453 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9454 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9455
9456 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9457+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9458+{
9459+ return atomic_add_ret_unchecked(i, v);
9460+}
9461 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9462+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9463+{
9464+ return atomic64_add_ret_unchecked(i, v);
9465+}
9466
9467 /*
9468 * atomic_inc_and_test - increment and test
9469@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9470 * other cases.
9471 */
9472 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9473+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9474+{
9475+ return atomic_inc_return_unchecked(v) == 0;
9476+}
9477 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9478
9479 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9480@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9481 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9482
9483 #define atomic_inc(v) atomic_add(1, v)
9484+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9485+{
9486+ atomic_add_unchecked(1, v);
9487+}
9488 #define atomic64_inc(v) atomic64_add(1, v)
9489+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9490+{
9491+ atomic64_add_unchecked(1, v);
9492+}
9493
9494 #define atomic_dec(v) atomic_sub(1, v)
9495+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9496+{
9497+ atomic_sub_unchecked(1, v);
9498+}
9499 #define atomic64_dec(v) atomic64_sub(1, v)
9500+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9501+{
9502+ atomic64_sub_unchecked(1, v);
9503+}
9504
9505 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9506 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9507
9508 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9509+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9510+{
9511+ return cmpxchg(&v->counter, old, new);
9512+}
9513 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9514+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9515+{
9516+ return xchg(&v->counter, new);
9517+}
9518
9519 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9520 {
9521- int c, old;
9522+ int c, old, new;
9523 c = atomic_read(v);
9524 for (;;) {
9525- if (unlikely(c == (u)))
9526+ if (unlikely(c == u))
9527 break;
9528- old = atomic_cmpxchg((v), c, c + (a));
9529+
9530+ asm volatile("addcc %2, %0, %0\n"
9531+
9532+#ifdef CONFIG_PAX_REFCOUNT
9533+ "tvs %%icc, 6\n"
9534+#endif
9535+
9536+ : "=r" (new)
9537+ : "0" (c), "ir" (a)
9538+ : "cc");
9539+
9540+ old = atomic_cmpxchg(v, c, new);
9541 if (likely(old == c))
9542 break;
9543 c = old;
9544@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9545 #define atomic64_cmpxchg(v, o, n) \
9546 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9547 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9548+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9549+{
9550+ return xchg(&v->counter, new);
9551+}
9552
9553 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9554 {
9555- long c, old;
9556+ long c, old, new;
9557 c = atomic64_read(v);
9558 for (;;) {
9559- if (unlikely(c == (u)))
9560+ if (unlikely(c == u))
9561 break;
9562- old = atomic64_cmpxchg((v), c, c + (a));
9563+
9564+ asm volatile("addcc %2, %0, %0\n"
9565+
9566+#ifdef CONFIG_PAX_REFCOUNT
9567+ "tvs %%xcc, 6\n"
9568+#endif
9569+
9570+ : "=r" (new)
9571+ : "0" (c), "ir" (a)
9572+ : "cc");
9573+
9574+ old = atomic64_cmpxchg(v, c, new);
9575 if (likely(old == c))
9576 break;
9577 c = old;
9578 }
9579- return c != (u);
9580+ return c != u;
9581 }
9582
9583 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9584diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9585index 5bb6991..5c2132e 100644
9586--- a/arch/sparc/include/asm/cache.h
9587+++ b/arch/sparc/include/asm/cache.h
9588@@ -7,10 +7,12 @@
9589 #ifndef _SPARC_CACHE_H
9590 #define _SPARC_CACHE_H
9591
9592+#include <linux/const.h>
9593+
9594 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9595
9596 #define L1_CACHE_SHIFT 5
9597-#define L1_CACHE_BYTES 32
9598+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9599
9600 #ifdef CONFIG_SPARC32
9601 #define SMP_CACHE_BYTES_SHIFT 5
9602diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9603index a24e41f..47677ff 100644
9604--- a/arch/sparc/include/asm/elf_32.h
9605+++ b/arch/sparc/include/asm/elf_32.h
9606@@ -114,6 +114,13 @@ typedef struct {
9607
9608 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9609
9610+#ifdef CONFIG_PAX_ASLR
9611+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9612+
9613+#define PAX_DELTA_MMAP_LEN 16
9614+#define PAX_DELTA_STACK_LEN 16
9615+#endif
9616+
9617 /* This yields a mask that user programs can use to figure out what
9618 instruction set this cpu supports. This can NOT be done in userspace
9619 on Sparc. */
9620diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9621index 370ca1e..d4f4a98 100644
9622--- a/arch/sparc/include/asm/elf_64.h
9623+++ b/arch/sparc/include/asm/elf_64.h
9624@@ -189,6 +189,13 @@ typedef struct {
9625 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9626 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9627
9628+#ifdef CONFIG_PAX_ASLR
9629+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9630+
9631+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9632+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9633+#endif
9634+
9635 extern unsigned long sparc64_elf_hwcap;
9636 #define ELF_HWCAP sparc64_elf_hwcap
9637
9638diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9639index 9b1c36d..209298b 100644
9640--- a/arch/sparc/include/asm/pgalloc_32.h
9641+++ b/arch/sparc/include/asm/pgalloc_32.h
9642@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9643 }
9644
9645 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9646+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9647
9648 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9649 unsigned long address)
9650diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9651index bcfe063..b333142 100644
9652--- a/arch/sparc/include/asm/pgalloc_64.h
9653+++ b/arch/sparc/include/asm/pgalloc_64.h
9654@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9655 }
9656
9657 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9658+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9659
9660 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9661 {
9662diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9663index 59ba6f6..4518128 100644
9664--- a/arch/sparc/include/asm/pgtable.h
9665+++ b/arch/sparc/include/asm/pgtable.h
9666@@ -5,4 +5,8 @@
9667 #else
9668 #include <asm/pgtable_32.h>
9669 #endif
9670+
9671+#define ktla_ktva(addr) (addr)
9672+#define ktva_ktla(addr) (addr)
9673+
9674 #endif
9675diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9676index 502f632..da1917f 100644
9677--- a/arch/sparc/include/asm/pgtable_32.h
9678+++ b/arch/sparc/include/asm/pgtable_32.h
9679@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9680 #define PAGE_SHARED SRMMU_PAGE_SHARED
9681 #define PAGE_COPY SRMMU_PAGE_COPY
9682 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9683+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9684+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9685+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9686 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9687
9688 /* Top-level page directory - dummy used by init-mm.
9689@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9690
9691 /* xwr */
9692 #define __P000 PAGE_NONE
9693-#define __P001 PAGE_READONLY
9694-#define __P010 PAGE_COPY
9695-#define __P011 PAGE_COPY
9696+#define __P001 PAGE_READONLY_NOEXEC
9697+#define __P010 PAGE_COPY_NOEXEC
9698+#define __P011 PAGE_COPY_NOEXEC
9699 #define __P100 PAGE_READONLY
9700 #define __P101 PAGE_READONLY
9701 #define __P110 PAGE_COPY
9702 #define __P111 PAGE_COPY
9703
9704 #define __S000 PAGE_NONE
9705-#define __S001 PAGE_READONLY
9706-#define __S010 PAGE_SHARED
9707-#define __S011 PAGE_SHARED
9708+#define __S001 PAGE_READONLY_NOEXEC
9709+#define __S010 PAGE_SHARED_NOEXEC
9710+#define __S011 PAGE_SHARED_NOEXEC
9711 #define __S100 PAGE_READONLY
9712 #define __S101 PAGE_READONLY
9713 #define __S110 PAGE_SHARED
9714diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9715index 79da178..c2eede8 100644
9716--- a/arch/sparc/include/asm/pgtsrmmu.h
9717+++ b/arch/sparc/include/asm/pgtsrmmu.h
9718@@ -115,6 +115,11 @@
9719 SRMMU_EXEC | SRMMU_REF)
9720 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9721 SRMMU_EXEC | SRMMU_REF)
9722+
9723+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9724+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9725+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9726+
9727 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9728 SRMMU_DIRTY | SRMMU_REF)
9729
9730diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9731index 9689176..63c18ea 100644
9732--- a/arch/sparc/include/asm/spinlock_64.h
9733+++ b/arch/sparc/include/asm/spinlock_64.h
9734@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9735
9736 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9737
9738-static void inline arch_read_lock(arch_rwlock_t *lock)
9739+static inline void arch_read_lock(arch_rwlock_t *lock)
9740 {
9741 unsigned long tmp1, tmp2;
9742
9743 __asm__ __volatile__ (
9744 "1: ldsw [%2], %0\n"
9745 " brlz,pn %0, 2f\n"
9746-"4: add %0, 1, %1\n"
9747+"4: addcc %0, 1, %1\n"
9748+
9749+#ifdef CONFIG_PAX_REFCOUNT
9750+" tvs %%icc, 6\n"
9751+#endif
9752+
9753 " cas [%2], %0, %1\n"
9754 " cmp %0, %1\n"
9755 " bne,pn %%icc, 1b\n"
9756@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9757 " .previous"
9758 : "=&r" (tmp1), "=&r" (tmp2)
9759 : "r" (lock)
9760- : "memory");
9761+ : "memory", "cc");
9762 }
9763
9764-static int inline arch_read_trylock(arch_rwlock_t *lock)
9765+static inline int arch_read_trylock(arch_rwlock_t *lock)
9766 {
9767 int tmp1, tmp2;
9768
9769@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9770 "1: ldsw [%2], %0\n"
9771 " brlz,a,pn %0, 2f\n"
9772 " mov 0, %0\n"
9773-" add %0, 1, %1\n"
9774+" addcc %0, 1, %1\n"
9775+
9776+#ifdef CONFIG_PAX_REFCOUNT
9777+" tvs %%icc, 6\n"
9778+#endif
9779+
9780 " cas [%2], %0, %1\n"
9781 " cmp %0, %1\n"
9782 " bne,pn %%icc, 1b\n"
9783@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9784 return tmp1;
9785 }
9786
9787-static void inline arch_read_unlock(arch_rwlock_t *lock)
9788+static inline void arch_read_unlock(arch_rwlock_t *lock)
9789 {
9790 unsigned long tmp1, tmp2;
9791
9792 __asm__ __volatile__(
9793 "1: lduw [%2], %0\n"
9794-" sub %0, 1, %1\n"
9795+" subcc %0, 1, %1\n"
9796+
9797+#ifdef CONFIG_PAX_REFCOUNT
9798+" tvs %%icc, 6\n"
9799+#endif
9800+
9801 " cas [%2], %0, %1\n"
9802 " cmp %0, %1\n"
9803 " bne,pn %%xcc, 1b\n"
9804@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9805 : "memory");
9806 }
9807
9808-static void inline arch_write_lock(arch_rwlock_t *lock)
9809+static inline void arch_write_lock(arch_rwlock_t *lock)
9810 {
9811 unsigned long mask, tmp1, tmp2;
9812
9813@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9814 : "memory");
9815 }
9816
9817-static void inline arch_write_unlock(arch_rwlock_t *lock)
9818+static inline void arch_write_unlock(arch_rwlock_t *lock)
9819 {
9820 __asm__ __volatile__(
9821 " stw %%g0, [%0]"
9822@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9823 : "memory");
9824 }
9825
9826-static int inline arch_write_trylock(arch_rwlock_t *lock)
9827+static inline int arch_write_trylock(arch_rwlock_t *lock)
9828 {
9829 unsigned long mask, tmp1, tmp2, result;
9830
9831diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9832index 96efa7a..16858bf 100644
9833--- a/arch/sparc/include/asm/thread_info_32.h
9834+++ b/arch/sparc/include/asm/thread_info_32.h
9835@@ -49,6 +49,8 @@ struct thread_info {
9836 unsigned long w_saved;
9837
9838 struct restart_block restart_block;
9839+
9840+ unsigned long lowest_stack;
9841 };
9842
9843 /*
9844diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9845index a5f01ac..703b554 100644
9846--- a/arch/sparc/include/asm/thread_info_64.h
9847+++ b/arch/sparc/include/asm/thread_info_64.h
9848@@ -63,6 +63,8 @@ struct thread_info {
9849 struct pt_regs *kern_una_regs;
9850 unsigned int kern_una_insn;
9851
9852+ unsigned long lowest_stack;
9853+
9854 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9855 };
9856
9857@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9858 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9859 /* flag bit 4 is available */
9860 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9861-/* flag bit 6 is available */
9862+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9863 #define TIF_32BIT 7 /* 32-bit binary */
9864 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9865 #define TIF_SECCOMP 9 /* secure computing */
9866 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9867 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9868+
9869 /* NOTE: Thread flags >= 12 should be ones we have no interest
9870 * in using in assembly, else we can't use the mask as
9871 * an immediate value in instructions such as andcc.
9872@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9873 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9874 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9875 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9876+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9877
9878 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9879 _TIF_DO_NOTIFY_RESUME_MASK | \
9880 _TIF_NEED_RESCHED)
9881 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9882
9883+#define _TIF_WORK_SYSCALL \
9884+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9885+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9886+
9887+
9888 /*
9889 * Thread-synchronous status.
9890 *
9891diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9892index 0167d26..767bb0c 100644
9893--- a/arch/sparc/include/asm/uaccess.h
9894+++ b/arch/sparc/include/asm/uaccess.h
9895@@ -1,5 +1,6 @@
9896 #ifndef ___ASM_SPARC_UACCESS_H
9897 #define ___ASM_SPARC_UACCESS_H
9898+
9899 #if defined(__sparc__) && defined(__arch64__)
9900 #include <asm/uaccess_64.h>
9901 #else
9902diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9903index 53a28dd..50c38c3 100644
9904--- a/arch/sparc/include/asm/uaccess_32.h
9905+++ b/arch/sparc/include/asm/uaccess_32.h
9906@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9907
9908 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9909 {
9910- if (n && __access_ok((unsigned long) to, n))
9911+ if ((long)n < 0)
9912+ return n;
9913+
9914+ if (n && __access_ok((unsigned long) to, n)) {
9915+ if (!__builtin_constant_p(n))
9916+ check_object_size(from, n, true);
9917 return __copy_user(to, (__force void __user *) from, n);
9918- else
9919+ } else
9920 return n;
9921 }
9922
9923 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9924 {
9925+ if ((long)n < 0)
9926+ return n;
9927+
9928+ if (!__builtin_constant_p(n))
9929+ check_object_size(from, n, true);
9930+
9931 return __copy_user(to, (__force void __user *) from, n);
9932 }
9933
9934 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9935 {
9936- if (n && __access_ok((unsigned long) from, n))
9937+ if ((long)n < 0)
9938+ return n;
9939+
9940+ if (n && __access_ok((unsigned long) from, n)) {
9941+ if (!__builtin_constant_p(n))
9942+ check_object_size(to, n, false);
9943 return __copy_user((__force void __user *) to, from, n);
9944- else
9945+ } else
9946 return n;
9947 }
9948
9949 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9950 {
9951+ if ((long)n < 0)
9952+ return n;
9953+
9954 return __copy_user((__force void __user *) to, from, n);
9955 }
9956
9957diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9958index ad7e178..c9e7423 100644
9959--- a/arch/sparc/include/asm/uaccess_64.h
9960+++ b/arch/sparc/include/asm/uaccess_64.h
9961@@ -10,6 +10,7 @@
9962 #include <linux/compiler.h>
9963 #include <linux/string.h>
9964 #include <linux/thread_info.h>
9965+#include <linux/kernel.h>
9966 #include <asm/asi.h>
9967 #include <asm/spitfire.h>
9968 #include <asm-generic/uaccess-unaligned.h>
9969@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9970 static inline unsigned long __must_check
9971 copy_from_user(void *to, const void __user *from, unsigned long size)
9972 {
9973- unsigned long ret = ___copy_from_user(to, from, size);
9974+ unsigned long ret;
9975
9976+ if ((long)size < 0 || size > INT_MAX)
9977+ return size;
9978+
9979+ if (!__builtin_constant_p(size))
9980+ check_object_size(to, size, false);
9981+
9982+ ret = ___copy_from_user(to, from, size);
9983 if (unlikely(ret))
9984 ret = copy_from_user_fixup(to, from, size);
9985
9986@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9987 static inline unsigned long __must_check
9988 copy_to_user(void __user *to, const void *from, unsigned long size)
9989 {
9990- unsigned long ret = ___copy_to_user(to, from, size);
9991+ unsigned long ret;
9992
9993+ if ((long)size < 0 || size > INT_MAX)
9994+ return size;
9995+
9996+ if (!__builtin_constant_p(size))
9997+ check_object_size(from, size, true);
9998+
9999+ ret = ___copy_to_user(to, from, size);
10000 if (unlikely(ret))
10001 ret = copy_to_user_fixup(to, from, size);
10002 return ret;
10003diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10004index d15cc17..d0ae796 100644
10005--- a/arch/sparc/kernel/Makefile
10006+++ b/arch/sparc/kernel/Makefile
10007@@ -4,7 +4,7 @@
10008 #
10009
10010 asflags-y := -ansi
10011-ccflags-y := -Werror
10012+#ccflags-y := -Werror
10013
10014 extra-y := head_$(BITS).o
10015
10016diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10017index 510baec..9ff2607 100644
10018--- a/arch/sparc/kernel/process_32.c
10019+++ b/arch/sparc/kernel/process_32.c
10020@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10021
10022 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10023 r->psr, r->pc, r->npc, r->y, print_tainted());
10024- printk("PC: <%pS>\n", (void *) r->pc);
10025+ printk("PC: <%pA>\n", (void *) r->pc);
10026 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10027 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10028 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10029 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10030 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10031 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10032- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10033+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10034
10035 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10036 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10037@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10038 rw = (struct reg_window32 *) fp;
10039 pc = rw->ins[7];
10040 printk("[%08lx : ", pc);
10041- printk("%pS ] ", (void *) pc);
10042+ printk("%pA ] ", (void *) pc);
10043 fp = rw->ins[6];
10044 } while (++count < 16);
10045 printk("\n");
10046diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10047index d7b4967..2edf827 100644
10048--- a/arch/sparc/kernel/process_64.c
10049+++ b/arch/sparc/kernel/process_64.c
10050@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10051 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10052 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10053 if (regs->tstate & TSTATE_PRIV)
10054- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10055+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10056 }
10057
10058 void show_regs(struct pt_regs *regs)
10059@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10060
10061 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10062 regs->tpc, regs->tnpc, regs->y, print_tainted());
10063- printk("TPC: <%pS>\n", (void *) regs->tpc);
10064+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10065 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10066 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10067 regs->u_regs[3]);
10068@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10069 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10070 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10071 regs->u_regs[15]);
10072- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10073+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10074 show_regwindow(regs);
10075 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10076 }
10077@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10078 ((tp && tp->task) ? tp->task->pid : -1));
10079
10080 if (gp->tstate & TSTATE_PRIV) {
10081- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10082+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10083 (void *) gp->tpc,
10084 (void *) gp->o7,
10085 (void *) gp->i7,
10086diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10087index 79cc0d1..ec62734 100644
10088--- a/arch/sparc/kernel/prom_common.c
10089+++ b/arch/sparc/kernel/prom_common.c
10090@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10091
10092 unsigned int prom_early_allocated __initdata;
10093
10094-static struct of_pdt_ops prom_sparc_ops __initdata = {
10095+static struct of_pdt_ops prom_sparc_ops __initconst = {
10096 .nextprop = prom_common_nextprop,
10097 .getproplen = prom_getproplen,
10098 .getproperty = prom_getproperty,
10099diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10100index c13c9f2..d572c34 100644
10101--- a/arch/sparc/kernel/ptrace_64.c
10102+++ b/arch/sparc/kernel/ptrace_64.c
10103@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10104 return ret;
10105 }
10106
10107+#ifdef CONFIG_GRKERNSEC_SETXID
10108+extern void gr_delayed_cred_worker(void);
10109+#endif
10110+
10111 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10112 {
10113 int ret = 0;
10114@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10115 if (test_thread_flag(TIF_NOHZ))
10116 user_exit();
10117
10118+#ifdef CONFIG_GRKERNSEC_SETXID
10119+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10120+ gr_delayed_cred_worker();
10121+#endif
10122+
10123 if (test_thread_flag(TIF_SYSCALL_TRACE))
10124 ret = tracehook_report_syscall_entry(regs);
10125
10126@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10127 if (test_thread_flag(TIF_NOHZ))
10128 user_exit();
10129
10130+#ifdef CONFIG_GRKERNSEC_SETXID
10131+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10132+ gr_delayed_cred_worker();
10133+#endif
10134+
10135 audit_syscall_exit(regs);
10136
10137 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10138diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10139index b085311..6f885f7 100644
10140--- a/arch/sparc/kernel/smp_64.c
10141+++ b/arch/sparc/kernel/smp_64.c
10142@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10143 extern unsigned long xcall_flush_dcache_page_spitfire;
10144
10145 #ifdef CONFIG_DEBUG_DCFLUSH
10146-extern atomic_t dcpage_flushes;
10147-extern atomic_t dcpage_flushes_xcall;
10148+extern atomic_unchecked_t dcpage_flushes;
10149+extern atomic_unchecked_t dcpage_flushes_xcall;
10150 #endif
10151
10152 static inline void __local_flush_dcache_page(struct page *page)
10153@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10154 return;
10155
10156 #ifdef CONFIG_DEBUG_DCFLUSH
10157- atomic_inc(&dcpage_flushes);
10158+ atomic_inc_unchecked(&dcpage_flushes);
10159 #endif
10160
10161 this_cpu = get_cpu();
10162@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10163 xcall_deliver(data0, __pa(pg_addr),
10164 (u64) pg_addr, cpumask_of(cpu));
10165 #ifdef CONFIG_DEBUG_DCFLUSH
10166- atomic_inc(&dcpage_flushes_xcall);
10167+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10168 #endif
10169 }
10170 }
10171@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10172 preempt_disable();
10173
10174 #ifdef CONFIG_DEBUG_DCFLUSH
10175- atomic_inc(&dcpage_flushes);
10176+ atomic_inc_unchecked(&dcpage_flushes);
10177 #endif
10178 data0 = 0;
10179 pg_addr = page_address(page);
10180@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10181 xcall_deliver(data0, __pa(pg_addr),
10182 (u64) pg_addr, cpu_online_mask);
10183 #ifdef CONFIG_DEBUG_DCFLUSH
10184- atomic_inc(&dcpage_flushes_xcall);
10185+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10186 #endif
10187 }
10188 __local_flush_dcache_page(page);
10189diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10190index 3a8d184..49498a8 100644
10191--- a/arch/sparc/kernel/sys_sparc_32.c
10192+++ b/arch/sparc/kernel/sys_sparc_32.c
10193@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10194 if (len > TASK_SIZE - PAGE_SIZE)
10195 return -ENOMEM;
10196 if (!addr)
10197- addr = TASK_UNMAPPED_BASE;
10198+ addr = current->mm->mmap_base;
10199
10200 info.flags = 0;
10201 info.length = len;
10202diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10203index beb0b5a..5a153f7 100644
10204--- a/arch/sparc/kernel/sys_sparc_64.c
10205+++ b/arch/sparc/kernel/sys_sparc_64.c
10206@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10207 struct vm_area_struct * vma;
10208 unsigned long task_size = TASK_SIZE;
10209 int do_color_align;
10210+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10211 struct vm_unmapped_area_info info;
10212
10213 if (flags & MAP_FIXED) {
10214 /* We do not accept a shared mapping if it would violate
10215 * cache aliasing constraints.
10216 */
10217- if ((flags & MAP_SHARED) &&
10218+ if ((filp || (flags & MAP_SHARED)) &&
10219 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10220 return -EINVAL;
10221 return addr;
10222@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10223 if (filp || (flags & MAP_SHARED))
10224 do_color_align = 1;
10225
10226+#ifdef CONFIG_PAX_RANDMMAP
10227+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10228+#endif
10229+
10230 if (addr) {
10231 if (do_color_align)
10232 addr = COLOR_ALIGN(addr, pgoff);
10233@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10234 addr = PAGE_ALIGN(addr);
10235
10236 vma = find_vma(mm, addr);
10237- if (task_size - len >= addr &&
10238- (!vma || addr + len <= vma->vm_start))
10239+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10240 return addr;
10241 }
10242
10243 info.flags = 0;
10244 info.length = len;
10245- info.low_limit = TASK_UNMAPPED_BASE;
10246+ info.low_limit = mm->mmap_base;
10247 info.high_limit = min(task_size, VA_EXCLUDE_START);
10248 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10249 info.align_offset = pgoff << PAGE_SHIFT;
10250+ info.threadstack_offset = offset;
10251 addr = vm_unmapped_area(&info);
10252
10253 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10254 VM_BUG_ON(addr != -ENOMEM);
10255 info.low_limit = VA_EXCLUDE_END;
10256+
10257+#ifdef CONFIG_PAX_RANDMMAP
10258+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10259+ info.low_limit += mm->delta_mmap;
10260+#endif
10261+
10262 info.high_limit = task_size;
10263 addr = vm_unmapped_area(&info);
10264 }
10265@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10266 unsigned long task_size = STACK_TOP32;
10267 unsigned long addr = addr0;
10268 int do_color_align;
10269+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10270 struct vm_unmapped_area_info info;
10271
10272 /* This should only ever run for 32-bit processes. */
10273@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10274 /* We do not accept a shared mapping if it would violate
10275 * cache aliasing constraints.
10276 */
10277- if ((flags & MAP_SHARED) &&
10278+ if ((filp || (flags & MAP_SHARED)) &&
10279 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10280 return -EINVAL;
10281 return addr;
10282@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10283 if (filp || (flags & MAP_SHARED))
10284 do_color_align = 1;
10285
10286+#ifdef CONFIG_PAX_RANDMMAP
10287+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10288+#endif
10289+
10290 /* requesting a specific address */
10291 if (addr) {
10292 if (do_color_align)
10293@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10294 addr = PAGE_ALIGN(addr);
10295
10296 vma = find_vma(mm, addr);
10297- if (task_size - len >= addr &&
10298- (!vma || addr + len <= vma->vm_start))
10299+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10300 return addr;
10301 }
10302
10303@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10304 info.high_limit = mm->mmap_base;
10305 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10306 info.align_offset = pgoff << PAGE_SHIFT;
10307+ info.threadstack_offset = offset;
10308 addr = vm_unmapped_area(&info);
10309
10310 /*
10311@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10312 VM_BUG_ON(addr != -ENOMEM);
10313 info.flags = 0;
10314 info.low_limit = TASK_UNMAPPED_BASE;
10315+
10316+#ifdef CONFIG_PAX_RANDMMAP
10317+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10318+ info.low_limit += mm->delta_mmap;
10319+#endif
10320+
10321 info.high_limit = STACK_TOP32;
10322 addr = vm_unmapped_area(&info);
10323 }
10324@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10325 EXPORT_SYMBOL(get_fb_unmapped_area);
10326
10327 /* Essentially the same as PowerPC. */
10328-static unsigned long mmap_rnd(void)
10329+static unsigned long mmap_rnd(struct mm_struct *mm)
10330 {
10331 unsigned long rnd = 0UL;
10332
10333+#ifdef CONFIG_PAX_RANDMMAP
10334+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10335+#endif
10336+
10337 if (current->flags & PF_RANDOMIZE) {
10338 unsigned long val = get_random_int();
10339 if (test_thread_flag(TIF_32BIT))
10340@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10341
10342 void arch_pick_mmap_layout(struct mm_struct *mm)
10343 {
10344- unsigned long random_factor = mmap_rnd();
10345+ unsigned long random_factor = mmap_rnd(mm);
10346 unsigned long gap;
10347
10348 /*
10349@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10350 gap == RLIM_INFINITY ||
10351 sysctl_legacy_va_layout) {
10352 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10353+
10354+#ifdef CONFIG_PAX_RANDMMAP
10355+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10356+ mm->mmap_base += mm->delta_mmap;
10357+#endif
10358+
10359 mm->get_unmapped_area = arch_get_unmapped_area;
10360 } else {
10361 /* We know it's 32-bit */
10362@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10363 gap = (task_size / 6 * 5);
10364
10365 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10366+
10367+#ifdef CONFIG_PAX_RANDMMAP
10368+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10369+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10370+#endif
10371+
10372 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10373 }
10374 }
10375diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10376index 33a17e7..d87fb1f 100644
10377--- a/arch/sparc/kernel/syscalls.S
10378+++ b/arch/sparc/kernel/syscalls.S
10379@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10380 #endif
10381 .align 32
10382 1: ldx [%g6 + TI_FLAGS], %l5
10383- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10384+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10385 be,pt %icc, rtrap
10386 nop
10387 call syscall_trace_leave
10388@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10389
10390 srl %i3, 0, %o3 ! IEU0
10391 srl %i2, 0, %o2 ! IEU0 Group
10392- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10393+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10394 bne,pn %icc, linux_syscall_trace32 ! CTI
10395 mov %i0, %l5 ! IEU1
10396 5: call %l7 ! CTI Group brk forced
10397@@ -208,7 +208,7 @@ linux_sparc_syscall:
10398
10399 mov %i3, %o3 ! IEU1
10400 mov %i4, %o4 ! IEU0 Group
10401- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10402+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10403 bne,pn %icc, linux_syscall_trace ! CTI Group
10404 mov %i0, %l5 ! IEU0
10405 2: call %l7 ! CTI Group brk forced
10406@@ -223,7 +223,7 @@ ret_sys_call:
10407
10408 cmp %o0, -ERESTART_RESTARTBLOCK
10409 bgeu,pn %xcc, 1f
10410- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10411+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10412 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10413
10414 2:
10415diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10416index 6629829..036032d 100644
10417--- a/arch/sparc/kernel/traps_32.c
10418+++ b/arch/sparc/kernel/traps_32.c
10419@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10420 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10421 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10422
10423+extern void gr_handle_kernel_exploit(void);
10424+
10425 void die_if_kernel(char *str, struct pt_regs *regs)
10426 {
10427 static int die_counter;
10428@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10429 count++ < 30 &&
10430 (((unsigned long) rw) >= PAGE_OFFSET) &&
10431 !(((unsigned long) rw) & 0x7)) {
10432- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10433+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10434 (void *) rw->ins[7]);
10435 rw = (struct reg_window32 *)rw->ins[6];
10436 }
10437 }
10438 printk("Instruction DUMP:");
10439 instruction_dump ((unsigned long *) regs->pc);
10440- if(regs->psr & PSR_PS)
10441+ if(regs->psr & PSR_PS) {
10442+ gr_handle_kernel_exploit();
10443 do_exit(SIGKILL);
10444+ }
10445 do_exit(SIGSEGV);
10446 }
10447
10448diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10449index 4ced92f..965eeed 100644
10450--- a/arch/sparc/kernel/traps_64.c
10451+++ b/arch/sparc/kernel/traps_64.c
10452@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10453 i + 1,
10454 p->trapstack[i].tstate, p->trapstack[i].tpc,
10455 p->trapstack[i].tnpc, p->trapstack[i].tt);
10456- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10457+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10458 }
10459 }
10460
10461@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10462
10463 lvl -= 0x100;
10464 if (regs->tstate & TSTATE_PRIV) {
10465+
10466+#ifdef CONFIG_PAX_REFCOUNT
10467+ if (lvl == 6)
10468+ pax_report_refcount_overflow(regs);
10469+#endif
10470+
10471 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10472 die_if_kernel(buffer, regs);
10473 }
10474@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10475 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10476 {
10477 char buffer[32];
10478-
10479+
10480 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10481 0, lvl, SIGTRAP) == NOTIFY_STOP)
10482 return;
10483
10484+#ifdef CONFIG_PAX_REFCOUNT
10485+ if (lvl == 6)
10486+ pax_report_refcount_overflow(regs);
10487+#endif
10488+
10489 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10490
10491 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10492@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10493 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10494 printk("%s" "ERROR(%d): ",
10495 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10496- printk("TPC<%pS>\n", (void *) regs->tpc);
10497+ printk("TPC<%pA>\n", (void *) regs->tpc);
10498 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10499 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10500 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10501@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10502 smp_processor_id(),
10503 (type & 0x1) ? 'I' : 'D',
10504 regs->tpc);
10505- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10506+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10507 panic("Irrecoverable Cheetah+ parity error.");
10508 }
10509
10510@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10511 smp_processor_id(),
10512 (type & 0x1) ? 'I' : 'D',
10513 regs->tpc);
10514- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10515+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10516 }
10517
10518 struct sun4v_error_entry {
10519@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10520 /*0x38*/u64 reserved_5;
10521 };
10522
10523-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10524-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10525+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10526+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10527
10528 static const char *sun4v_err_type_to_str(u8 type)
10529 {
10530@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10531 }
10532
10533 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10534- int cpu, const char *pfx, atomic_t *ocnt)
10535+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10536 {
10537 u64 *raw_ptr = (u64 *) ent;
10538 u32 attrs;
10539@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10540
10541 show_regs(regs);
10542
10543- if ((cnt = atomic_read(ocnt)) != 0) {
10544- atomic_set(ocnt, 0);
10545+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10546+ atomic_set_unchecked(ocnt, 0);
10547 wmb();
10548 printk("%s: Queue overflowed %d times.\n",
10549 pfx, cnt);
10550@@ -2046,7 +2057,7 @@ out:
10551 */
10552 void sun4v_resum_overflow(struct pt_regs *regs)
10553 {
10554- atomic_inc(&sun4v_resum_oflow_cnt);
10555+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10556 }
10557
10558 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10559@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10560 /* XXX Actually even this can make not that much sense. Perhaps
10561 * XXX we should just pull the plug and panic directly from here?
10562 */
10563- atomic_inc(&sun4v_nonresum_oflow_cnt);
10564+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10565 }
10566
10567 unsigned long sun4v_err_itlb_vaddr;
10568@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10569
10570 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10571 regs->tpc, tl);
10572- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10573+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10574 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10575- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10576+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10577 (void *) regs->u_regs[UREG_I7]);
10578 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10579 "pte[%lx] error[%lx]\n",
10580@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10581
10582 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10583 regs->tpc, tl);
10584- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10585+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10586 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10587- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10588+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10589 (void *) regs->u_regs[UREG_I7]);
10590 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10591 "pte[%lx] error[%lx]\n",
10592@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10593 fp = (unsigned long)sf->fp + STACK_BIAS;
10594 }
10595
10596- printk(" [%016lx] %pS\n", pc, (void *) pc);
10597+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10598 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10599 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10600 int index = tsk->curr_ret_stack;
10601 if (tsk->ret_stack && index >= graph) {
10602 pc = tsk->ret_stack[index - graph].ret;
10603- printk(" [%016lx] %pS\n", pc, (void *) pc);
10604+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10605 graph++;
10606 }
10607 }
10608@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10609 return (struct reg_window *) (fp + STACK_BIAS);
10610 }
10611
10612+extern void gr_handle_kernel_exploit(void);
10613+
10614 void die_if_kernel(char *str, struct pt_regs *regs)
10615 {
10616 static int die_counter;
10617@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10618 while (rw &&
10619 count++ < 30 &&
10620 kstack_valid(tp, (unsigned long) rw)) {
10621- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10622+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10623 (void *) rw->ins[7]);
10624
10625 rw = kernel_stack_up(rw);
10626@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10627 }
10628 user_instruction_dump ((unsigned int __user *) regs->tpc);
10629 }
10630- if (regs->tstate & TSTATE_PRIV)
10631+ if (regs->tstate & TSTATE_PRIV) {
10632+ gr_handle_kernel_exploit();
10633 do_exit(SIGKILL);
10634+ }
10635 do_exit(SIGSEGV);
10636 }
10637 EXPORT_SYMBOL(die_if_kernel);
10638diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10639index 3c1a7cb..73e1923 100644
10640--- a/arch/sparc/kernel/unaligned_64.c
10641+++ b/arch/sparc/kernel/unaligned_64.c
10642@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10643 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10644
10645 if (__ratelimit(&ratelimit)) {
10646- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10647+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10648 regs->tpc, (void *) regs->tpc);
10649 }
10650 }
10651diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10652index dbe119b..089c7c1 100644
10653--- a/arch/sparc/lib/Makefile
10654+++ b/arch/sparc/lib/Makefile
10655@@ -2,7 +2,7 @@
10656 #
10657
10658 asflags-y := -ansi -DST_DIV0=0x02
10659-ccflags-y := -Werror
10660+#ccflags-y := -Werror
10661
10662 lib-$(CONFIG_SPARC32) += ashrdi3.o
10663 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10664diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10665index 85c233d..68500e0 100644
10666--- a/arch/sparc/lib/atomic_64.S
10667+++ b/arch/sparc/lib/atomic_64.S
10668@@ -17,7 +17,12 @@
10669 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10670 BACKOFF_SETUP(%o2)
10671 1: lduw [%o1], %g1
10672- add %g1, %o0, %g7
10673+ addcc %g1, %o0, %g7
10674+
10675+#ifdef CONFIG_PAX_REFCOUNT
10676+ tvs %icc, 6
10677+#endif
10678+
10679 cas [%o1], %g1, %g7
10680 cmp %g1, %g7
10681 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10682@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10683 2: BACKOFF_SPIN(%o2, %o3, 1b)
10684 ENDPROC(atomic_add)
10685
10686+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10687+ BACKOFF_SETUP(%o2)
10688+1: lduw [%o1], %g1
10689+ add %g1, %o0, %g7
10690+ cas [%o1], %g1, %g7
10691+ cmp %g1, %g7
10692+ bne,pn %icc, 2f
10693+ nop
10694+ retl
10695+ nop
10696+2: BACKOFF_SPIN(%o2, %o3, 1b)
10697+ENDPROC(atomic_add_unchecked)
10698+
10699 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10700 BACKOFF_SETUP(%o2)
10701 1: lduw [%o1], %g1
10702- sub %g1, %o0, %g7
10703+ subcc %g1, %o0, %g7
10704+
10705+#ifdef CONFIG_PAX_REFCOUNT
10706+ tvs %icc, 6
10707+#endif
10708+
10709 cas [%o1], %g1, %g7
10710 cmp %g1, %g7
10711 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10712@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10713 2: BACKOFF_SPIN(%o2, %o3, 1b)
10714 ENDPROC(atomic_sub)
10715
10716+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10717+ BACKOFF_SETUP(%o2)
10718+1: lduw [%o1], %g1
10719+ sub %g1, %o0, %g7
10720+ cas [%o1], %g1, %g7
10721+ cmp %g1, %g7
10722+ bne,pn %icc, 2f
10723+ nop
10724+ retl
10725+ nop
10726+2: BACKOFF_SPIN(%o2, %o3, 1b)
10727+ENDPROC(atomic_sub_unchecked)
10728+
10729 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10730 BACKOFF_SETUP(%o2)
10731 1: lduw [%o1], %g1
10732- add %g1, %o0, %g7
10733+ addcc %g1, %o0, %g7
10734+
10735+#ifdef CONFIG_PAX_REFCOUNT
10736+ tvs %icc, 6
10737+#endif
10738+
10739 cas [%o1], %g1, %g7
10740 cmp %g1, %g7
10741 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10742@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10743 2: BACKOFF_SPIN(%o2, %o3, 1b)
10744 ENDPROC(atomic_add_ret)
10745
10746+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10747+ BACKOFF_SETUP(%o2)
10748+1: lduw [%o1], %g1
10749+ addcc %g1, %o0, %g7
10750+ cas [%o1], %g1, %g7
10751+ cmp %g1, %g7
10752+ bne,pn %icc, 2f
10753+ add %g7, %o0, %g7
10754+ sra %g7, 0, %o0
10755+ retl
10756+ nop
10757+2: BACKOFF_SPIN(%o2, %o3, 1b)
10758+ENDPROC(atomic_add_ret_unchecked)
10759+
10760 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10761 BACKOFF_SETUP(%o2)
10762 1: lduw [%o1], %g1
10763- sub %g1, %o0, %g7
10764+ subcc %g1, %o0, %g7
10765+
10766+#ifdef CONFIG_PAX_REFCOUNT
10767+ tvs %icc, 6
10768+#endif
10769+
10770 cas [%o1], %g1, %g7
10771 cmp %g1, %g7
10772 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10773@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10774 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10775 BACKOFF_SETUP(%o2)
10776 1: ldx [%o1], %g1
10777- add %g1, %o0, %g7
10778+ addcc %g1, %o0, %g7
10779+
10780+#ifdef CONFIG_PAX_REFCOUNT
10781+ tvs %xcc, 6
10782+#endif
10783+
10784 casx [%o1], %g1, %g7
10785 cmp %g1, %g7
10786 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10787@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10788 2: BACKOFF_SPIN(%o2, %o3, 1b)
10789 ENDPROC(atomic64_add)
10790
10791+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10792+ BACKOFF_SETUP(%o2)
10793+1: ldx [%o1], %g1
10794+ addcc %g1, %o0, %g7
10795+ casx [%o1], %g1, %g7
10796+ cmp %g1, %g7
10797+ bne,pn %xcc, 2f
10798+ nop
10799+ retl
10800+ nop
10801+2: BACKOFF_SPIN(%o2, %o3, 1b)
10802+ENDPROC(atomic64_add_unchecked)
10803+
10804 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10805 BACKOFF_SETUP(%o2)
10806 1: ldx [%o1], %g1
10807- sub %g1, %o0, %g7
10808+ subcc %g1, %o0, %g7
10809+
10810+#ifdef CONFIG_PAX_REFCOUNT
10811+ tvs %xcc, 6
10812+#endif
10813+
10814 casx [%o1], %g1, %g7
10815 cmp %g1, %g7
10816 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10817@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10818 2: BACKOFF_SPIN(%o2, %o3, 1b)
10819 ENDPROC(atomic64_sub)
10820
10821+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10822+ BACKOFF_SETUP(%o2)
10823+1: ldx [%o1], %g1
10824+ subcc %g1, %o0, %g7
10825+ casx [%o1], %g1, %g7
10826+ cmp %g1, %g7
10827+ bne,pn %xcc, 2f
10828+ nop
10829+ retl
10830+ nop
10831+2: BACKOFF_SPIN(%o2, %o3, 1b)
10832+ENDPROC(atomic64_sub_unchecked)
10833+
10834 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10835 BACKOFF_SETUP(%o2)
10836 1: ldx [%o1], %g1
10837- add %g1, %o0, %g7
10838+ addcc %g1, %o0, %g7
10839+
10840+#ifdef CONFIG_PAX_REFCOUNT
10841+ tvs %xcc, 6
10842+#endif
10843+
10844 casx [%o1], %g1, %g7
10845 cmp %g1, %g7
10846 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10847@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10848 2: BACKOFF_SPIN(%o2, %o3, 1b)
10849 ENDPROC(atomic64_add_ret)
10850
10851+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10852+ BACKOFF_SETUP(%o2)
10853+1: ldx [%o1], %g1
10854+ addcc %g1, %o0, %g7
10855+ casx [%o1], %g1, %g7
10856+ cmp %g1, %g7
10857+ bne,pn %xcc, 2f
10858+ add %g7, %o0, %g7
10859+ mov %g7, %o0
10860+ retl
10861+ nop
10862+2: BACKOFF_SPIN(%o2, %o3, 1b)
10863+ENDPROC(atomic64_add_ret_unchecked)
10864+
10865 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10866 BACKOFF_SETUP(%o2)
10867 1: ldx [%o1], %g1
10868- sub %g1, %o0, %g7
10869+ subcc %g1, %o0, %g7
10870+
10871+#ifdef CONFIG_PAX_REFCOUNT
10872+ tvs %xcc, 6
10873+#endif
10874+
10875 casx [%o1], %g1, %g7
10876 cmp %g1, %g7
10877 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10878diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10879index 323335b..ed85ea2 100644
10880--- a/arch/sparc/lib/ksyms.c
10881+++ b/arch/sparc/lib/ksyms.c
10882@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10883
10884 /* Atomic counter implementation. */
10885 EXPORT_SYMBOL(atomic_add);
10886+EXPORT_SYMBOL(atomic_add_unchecked);
10887 EXPORT_SYMBOL(atomic_add_ret);
10888+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10889 EXPORT_SYMBOL(atomic_sub);
10890+EXPORT_SYMBOL(atomic_sub_unchecked);
10891 EXPORT_SYMBOL(atomic_sub_ret);
10892 EXPORT_SYMBOL(atomic64_add);
10893+EXPORT_SYMBOL(atomic64_add_unchecked);
10894 EXPORT_SYMBOL(atomic64_add_ret);
10895+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10896 EXPORT_SYMBOL(atomic64_sub);
10897+EXPORT_SYMBOL(atomic64_sub_unchecked);
10898 EXPORT_SYMBOL(atomic64_sub_ret);
10899 EXPORT_SYMBOL(atomic64_dec_if_positive);
10900
10901diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10902index 30c3ecc..736f015 100644
10903--- a/arch/sparc/mm/Makefile
10904+++ b/arch/sparc/mm/Makefile
10905@@ -2,7 +2,7 @@
10906 #
10907
10908 asflags-y := -ansi
10909-ccflags-y := -Werror
10910+#ccflags-y := -Werror
10911
10912 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10913 obj-y += fault_$(BITS).o
10914diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10915index 59dbd46..1dd7f5e 100644
10916--- a/arch/sparc/mm/fault_32.c
10917+++ b/arch/sparc/mm/fault_32.c
10918@@ -21,6 +21,9 @@
10919 #include <linux/perf_event.h>
10920 #include <linux/interrupt.h>
10921 #include <linux/kdebug.h>
10922+#include <linux/slab.h>
10923+#include <linux/pagemap.h>
10924+#include <linux/compiler.h>
10925
10926 #include <asm/page.h>
10927 #include <asm/pgtable.h>
10928@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10929 return safe_compute_effective_address(regs, insn);
10930 }
10931
10932+#ifdef CONFIG_PAX_PAGEEXEC
10933+#ifdef CONFIG_PAX_DLRESOLVE
10934+static void pax_emuplt_close(struct vm_area_struct *vma)
10935+{
10936+ vma->vm_mm->call_dl_resolve = 0UL;
10937+}
10938+
10939+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10940+{
10941+ unsigned int *kaddr;
10942+
10943+ vmf->page = alloc_page(GFP_HIGHUSER);
10944+ if (!vmf->page)
10945+ return VM_FAULT_OOM;
10946+
10947+ kaddr = kmap(vmf->page);
10948+ memset(kaddr, 0, PAGE_SIZE);
10949+ kaddr[0] = 0x9DE3BFA8U; /* save */
10950+ flush_dcache_page(vmf->page);
10951+ kunmap(vmf->page);
10952+ return VM_FAULT_MAJOR;
10953+}
10954+
10955+static const struct vm_operations_struct pax_vm_ops = {
10956+ .close = pax_emuplt_close,
10957+ .fault = pax_emuplt_fault
10958+};
10959+
10960+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10961+{
10962+ int ret;
10963+
10964+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10965+ vma->vm_mm = current->mm;
10966+ vma->vm_start = addr;
10967+ vma->vm_end = addr + PAGE_SIZE;
10968+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10969+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10970+ vma->vm_ops = &pax_vm_ops;
10971+
10972+ ret = insert_vm_struct(current->mm, vma);
10973+ if (ret)
10974+ return ret;
10975+
10976+ ++current->mm->total_vm;
10977+ return 0;
10978+}
10979+#endif
10980+
10981+/*
10982+ * PaX: decide what to do with offenders (regs->pc = fault address)
10983+ *
10984+ * returns 1 when task should be killed
10985+ * 2 when patched PLT trampoline was detected
10986+ * 3 when unpatched PLT trampoline was detected
10987+ */
10988+static int pax_handle_fetch_fault(struct pt_regs *regs)
10989+{
10990+
10991+#ifdef CONFIG_PAX_EMUPLT
10992+ int err;
10993+
10994+ do { /* PaX: patched PLT emulation #1 */
10995+ unsigned int sethi1, sethi2, jmpl;
10996+
10997+ err = get_user(sethi1, (unsigned int *)regs->pc);
10998+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10999+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11000+
11001+ if (err)
11002+ break;
11003+
11004+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11005+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11006+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11007+ {
11008+ unsigned int addr;
11009+
11010+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11011+ addr = regs->u_regs[UREG_G1];
11012+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11013+ regs->pc = addr;
11014+ regs->npc = addr+4;
11015+ return 2;
11016+ }
11017+ } while (0);
11018+
11019+ do { /* PaX: patched PLT emulation #2 */
11020+ unsigned int ba;
11021+
11022+ err = get_user(ba, (unsigned int *)regs->pc);
11023+
11024+ if (err)
11025+ break;
11026+
11027+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11028+ unsigned int addr;
11029+
11030+ if ((ba & 0xFFC00000U) == 0x30800000U)
11031+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11032+ else
11033+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11034+ regs->pc = addr;
11035+ regs->npc = addr+4;
11036+ return 2;
11037+ }
11038+ } while (0);
11039+
11040+ do { /* PaX: patched PLT emulation #3 */
11041+ unsigned int sethi, bajmpl, nop;
11042+
11043+ err = get_user(sethi, (unsigned int *)regs->pc);
11044+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11045+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11046+
11047+ if (err)
11048+ break;
11049+
11050+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11051+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11052+ nop == 0x01000000U)
11053+ {
11054+ unsigned int addr;
11055+
11056+ addr = (sethi & 0x003FFFFFU) << 10;
11057+ regs->u_regs[UREG_G1] = addr;
11058+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11059+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11060+ else
11061+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11062+ regs->pc = addr;
11063+ regs->npc = addr+4;
11064+ return 2;
11065+ }
11066+ } while (0);
11067+
11068+ do { /* PaX: unpatched PLT emulation step 1 */
11069+ unsigned int sethi, ba, nop;
11070+
11071+ err = get_user(sethi, (unsigned int *)regs->pc);
11072+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11073+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11074+
11075+ if (err)
11076+ break;
11077+
11078+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11079+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11080+ nop == 0x01000000U)
11081+ {
11082+ unsigned int addr, save, call;
11083+
11084+ if ((ba & 0xFFC00000U) == 0x30800000U)
11085+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11086+ else
11087+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11088+
11089+ err = get_user(save, (unsigned int *)addr);
11090+ err |= get_user(call, (unsigned int *)(addr+4));
11091+ err |= get_user(nop, (unsigned int *)(addr+8));
11092+ if (err)
11093+ break;
11094+
11095+#ifdef CONFIG_PAX_DLRESOLVE
11096+ if (save == 0x9DE3BFA8U &&
11097+ (call & 0xC0000000U) == 0x40000000U &&
11098+ nop == 0x01000000U)
11099+ {
11100+ struct vm_area_struct *vma;
11101+ unsigned long call_dl_resolve;
11102+
11103+ down_read(&current->mm->mmap_sem);
11104+ call_dl_resolve = current->mm->call_dl_resolve;
11105+ up_read(&current->mm->mmap_sem);
11106+ if (likely(call_dl_resolve))
11107+ goto emulate;
11108+
11109+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11110+
11111+ down_write(&current->mm->mmap_sem);
11112+ if (current->mm->call_dl_resolve) {
11113+ call_dl_resolve = current->mm->call_dl_resolve;
11114+ up_write(&current->mm->mmap_sem);
11115+ if (vma)
11116+ kmem_cache_free(vm_area_cachep, vma);
11117+ goto emulate;
11118+ }
11119+
11120+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11121+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11122+ up_write(&current->mm->mmap_sem);
11123+ if (vma)
11124+ kmem_cache_free(vm_area_cachep, vma);
11125+ return 1;
11126+ }
11127+
11128+ if (pax_insert_vma(vma, call_dl_resolve)) {
11129+ up_write(&current->mm->mmap_sem);
11130+ kmem_cache_free(vm_area_cachep, vma);
11131+ return 1;
11132+ }
11133+
11134+ current->mm->call_dl_resolve = call_dl_resolve;
11135+ up_write(&current->mm->mmap_sem);
11136+
11137+emulate:
11138+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11139+ regs->pc = call_dl_resolve;
11140+ regs->npc = addr+4;
11141+ return 3;
11142+ }
11143+#endif
11144+
11145+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11146+ if ((save & 0xFFC00000U) == 0x05000000U &&
11147+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11148+ nop == 0x01000000U)
11149+ {
11150+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11151+ regs->u_regs[UREG_G2] = addr + 4;
11152+ addr = (save & 0x003FFFFFU) << 10;
11153+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11154+ regs->pc = addr;
11155+ regs->npc = addr+4;
11156+ return 3;
11157+ }
11158+ }
11159+ } while (0);
11160+
11161+ do { /* PaX: unpatched PLT emulation step 2 */
11162+ unsigned int save, call, nop;
11163+
11164+ err = get_user(save, (unsigned int *)(regs->pc-4));
11165+ err |= get_user(call, (unsigned int *)regs->pc);
11166+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11167+ if (err)
11168+ break;
11169+
11170+ if (save == 0x9DE3BFA8U &&
11171+ (call & 0xC0000000U) == 0x40000000U &&
11172+ nop == 0x01000000U)
11173+ {
11174+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11175+
11176+ regs->u_regs[UREG_RETPC] = regs->pc;
11177+ regs->pc = dl_resolve;
11178+ regs->npc = dl_resolve+4;
11179+ return 3;
11180+ }
11181+ } while (0);
11182+#endif
11183+
11184+ return 1;
11185+}
11186+
11187+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11188+{
11189+ unsigned long i;
11190+
11191+ printk(KERN_ERR "PAX: bytes at PC: ");
11192+ for (i = 0; i < 8; i++) {
11193+ unsigned int c;
11194+ if (get_user(c, (unsigned int *)pc+i))
11195+ printk(KERN_CONT "???????? ");
11196+ else
11197+ printk(KERN_CONT "%08x ", c);
11198+ }
11199+ printk("\n");
11200+}
11201+#endif
11202+
11203 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11204 int text_fault)
11205 {
11206@@ -229,6 +503,24 @@ good_area:
11207 if (!(vma->vm_flags & VM_WRITE))
11208 goto bad_area;
11209 } else {
11210+
11211+#ifdef CONFIG_PAX_PAGEEXEC
11212+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11213+ up_read(&mm->mmap_sem);
11214+ switch (pax_handle_fetch_fault(regs)) {
11215+
11216+#ifdef CONFIG_PAX_EMUPLT
11217+ case 2:
11218+ case 3:
11219+ return;
11220+#endif
11221+
11222+ }
11223+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11224+ do_group_exit(SIGKILL);
11225+ }
11226+#endif
11227+
11228 /* Allow reads even for write-only mappings */
11229 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11230 goto bad_area;
11231diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11232index 69bb818..6ca35c8 100644
11233--- a/arch/sparc/mm/fault_64.c
11234+++ b/arch/sparc/mm/fault_64.c
11235@@ -22,6 +22,9 @@
11236 #include <linux/kdebug.h>
11237 #include <linux/percpu.h>
11238 #include <linux/context_tracking.h>
11239+#include <linux/slab.h>
11240+#include <linux/pagemap.h>
11241+#include <linux/compiler.h>
11242
11243 #include <asm/page.h>
11244 #include <asm/pgtable.h>
11245@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11246 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11247 regs->tpc);
11248 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11249- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11250+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11251 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11252 dump_stack();
11253 unhandled_fault(regs->tpc, current, regs);
11254@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11255 show_regs(regs);
11256 }
11257
11258+#ifdef CONFIG_PAX_PAGEEXEC
11259+#ifdef CONFIG_PAX_DLRESOLVE
11260+static void pax_emuplt_close(struct vm_area_struct *vma)
11261+{
11262+ vma->vm_mm->call_dl_resolve = 0UL;
11263+}
11264+
11265+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11266+{
11267+ unsigned int *kaddr;
11268+
11269+ vmf->page = alloc_page(GFP_HIGHUSER);
11270+ if (!vmf->page)
11271+ return VM_FAULT_OOM;
11272+
11273+ kaddr = kmap(vmf->page);
11274+ memset(kaddr, 0, PAGE_SIZE);
11275+ kaddr[0] = 0x9DE3BFA8U; /* save */
11276+ flush_dcache_page(vmf->page);
11277+ kunmap(vmf->page);
11278+ return VM_FAULT_MAJOR;
11279+}
11280+
11281+static const struct vm_operations_struct pax_vm_ops = {
11282+ .close = pax_emuplt_close,
11283+ .fault = pax_emuplt_fault
11284+};
11285+
11286+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11287+{
11288+ int ret;
11289+
11290+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11291+ vma->vm_mm = current->mm;
11292+ vma->vm_start = addr;
11293+ vma->vm_end = addr + PAGE_SIZE;
11294+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11295+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11296+ vma->vm_ops = &pax_vm_ops;
11297+
11298+ ret = insert_vm_struct(current->mm, vma);
11299+ if (ret)
11300+ return ret;
11301+
11302+ ++current->mm->total_vm;
11303+ return 0;
11304+}
11305+#endif
11306+
11307+/*
11308+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11309+ *
11310+ * returns 1 when task should be killed
11311+ * 2 when patched PLT trampoline was detected
11312+ * 3 when unpatched PLT trampoline was detected
11313+ */
11314+static int pax_handle_fetch_fault(struct pt_regs *regs)
11315+{
11316+
11317+#ifdef CONFIG_PAX_EMUPLT
11318+ int err;
11319+
11320+ do { /* PaX: patched PLT emulation #1 */
11321+ unsigned int sethi1, sethi2, jmpl;
11322+
11323+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11324+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11325+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11326+
11327+ if (err)
11328+ break;
11329+
11330+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11331+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11332+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11333+ {
11334+ unsigned long addr;
11335+
11336+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11337+ addr = regs->u_regs[UREG_G1];
11338+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11339+
11340+ if (test_thread_flag(TIF_32BIT))
11341+ addr &= 0xFFFFFFFFUL;
11342+
11343+ regs->tpc = addr;
11344+ regs->tnpc = addr+4;
11345+ return 2;
11346+ }
11347+ } while (0);
11348+
11349+ do { /* PaX: patched PLT emulation #2 */
11350+ unsigned int ba;
11351+
11352+ err = get_user(ba, (unsigned int *)regs->tpc);
11353+
11354+ if (err)
11355+ break;
11356+
11357+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11358+ unsigned long addr;
11359+
11360+ if ((ba & 0xFFC00000U) == 0x30800000U)
11361+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11362+ else
11363+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11364+
11365+ if (test_thread_flag(TIF_32BIT))
11366+ addr &= 0xFFFFFFFFUL;
11367+
11368+ regs->tpc = addr;
11369+ regs->tnpc = addr+4;
11370+ return 2;
11371+ }
11372+ } while (0);
11373+
11374+ do { /* PaX: patched PLT emulation #3 */
11375+ unsigned int sethi, bajmpl, nop;
11376+
11377+ err = get_user(sethi, (unsigned int *)regs->tpc);
11378+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11379+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11380+
11381+ if (err)
11382+ break;
11383+
11384+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11385+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11386+ nop == 0x01000000U)
11387+ {
11388+ unsigned long addr;
11389+
11390+ addr = (sethi & 0x003FFFFFU) << 10;
11391+ regs->u_regs[UREG_G1] = addr;
11392+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11393+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11394+ else
11395+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11396+
11397+ if (test_thread_flag(TIF_32BIT))
11398+ addr &= 0xFFFFFFFFUL;
11399+
11400+ regs->tpc = addr;
11401+ regs->tnpc = addr+4;
11402+ return 2;
11403+ }
11404+ } while (0);
11405+
11406+ do { /* PaX: patched PLT emulation #4 */
11407+ unsigned int sethi, mov1, call, mov2;
11408+
11409+ err = get_user(sethi, (unsigned int *)regs->tpc);
11410+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11411+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11412+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11413+
11414+ if (err)
11415+ break;
11416+
11417+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11418+ mov1 == 0x8210000FU &&
11419+ (call & 0xC0000000U) == 0x40000000U &&
11420+ mov2 == 0x9E100001U)
11421+ {
11422+ unsigned long addr;
11423+
11424+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11425+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11426+
11427+ if (test_thread_flag(TIF_32BIT))
11428+ addr &= 0xFFFFFFFFUL;
11429+
11430+ regs->tpc = addr;
11431+ regs->tnpc = addr+4;
11432+ return 2;
11433+ }
11434+ } while (0);
11435+
11436+ do { /* PaX: patched PLT emulation #5 */
11437+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11438+
11439+ err = get_user(sethi, (unsigned int *)regs->tpc);
11440+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11441+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11442+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11443+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11444+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11445+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11446+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11447+
11448+ if (err)
11449+ break;
11450+
11451+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11452+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11453+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11454+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11455+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11456+ sllx == 0x83287020U &&
11457+ jmpl == 0x81C04005U &&
11458+ nop == 0x01000000U)
11459+ {
11460+ unsigned long addr;
11461+
11462+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11463+ regs->u_regs[UREG_G1] <<= 32;
11464+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11465+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11466+ regs->tpc = addr;
11467+ regs->tnpc = addr+4;
11468+ return 2;
11469+ }
11470+ } while (0);
11471+
11472+ do { /* PaX: patched PLT emulation #6 */
11473+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11474+
11475+ err = get_user(sethi, (unsigned int *)regs->tpc);
11476+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11477+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11478+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11479+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11480+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11481+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11482+
11483+ if (err)
11484+ break;
11485+
11486+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11487+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11488+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11489+ sllx == 0x83287020U &&
11490+ (or & 0xFFFFE000U) == 0x8A116000U &&
11491+ jmpl == 0x81C04005U &&
11492+ nop == 0x01000000U)
11493+ {
11494+ unsigned long addr;
11495+
11496+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11497+ regs->u_regs[UREG_G1] <<= 32;
11498+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11499+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11500+ regs->tpc = addr;
11501+ regs->tnpc = addr+4;
11502+ return 2;
11503+ }
11504+ } while (0);
11505+
11506+ do { /* PaX: unpatched PLT emulation step 1 */
11507+ unsigned int sethi, ba, nop;
11508+
11509+ err = get_user(sethi, (unsigned int *)regs->tpc);
11510+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11511+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11512+
11513+ if (err)
11514+ break;
11515+
11516+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11517+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11518+ nop == 0x01000000U)
11519+ {
11520+ unsigned long addr;
11521+ unsigned int save, call;
11522+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11523+
11524+ if ((ba & 0xFFC00000U) == 0x30800000U)
11525+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11526+ else
11527+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11528+
11529+ if (test_thread_flag(TIF_32BIT))
11530+ addr &= 0xFFFFFFFFUL;
11531+
11532+ err = get_user(save, (unsigned int *)addr);
11533+ err |= get_user(call, (unsigned int *)(addr+4));
11534+ err |= get_user(nop, (unsigned int *)(addr+8));
11535+ if (err)
11536+ break;
11537+
11538+#ifdef CONFIG_PAX_DLRESOLVE
11539+ if (save == 0x9DE3BFA8U &&
11540+ (call & 0xC0000000U) == 0x40000000U &&
11541+ nop == 0x01000000U)
11542+ {
11543+ struct vm_area_struct *vma;
11544+ unsigned long call_dl_resolve;
11545+
11546+ down_read(&current->mm->mmap_sem);
11547+ call_dl_resolve = current->mm->call_dl_resolve;
11548+ up_read(&current->mm->mmap_sem);
11549+ if (likely(call_dl_resolve))
11550+ goto emulate;
11551+
11552+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11553+
11554+ down_write(&current->mm->mmap_sem);
11555+ if (current->mm->call_dl_resolve) {
11556+ call_dl_resolve = current->mm->call_dl_resolve;
11557+ up_write(&current->mm->mmap_sem);
11558+ if (vma)
11559+ kmem_cache_free(vm_area_cachep, vma);
11560+ goto emulate;
11561+ }
11562+
11563+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11564+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11565+ up_write(&current->mm->mmap_sem);
11566+ if (vma)
11567+ kmem_cache_free(vm_area_cachep, vma);
11568+ return 1;
11569+ }
11570+
11571+ if (pax_insert_vma(vma, call_dl_resolve)) {
11572+ up_write(&current->mm->mmap_sem);
11573+ kmem_cache_free(vm_area_cachep, vma);
11574+ return 1;
11575+ }
11576+
11577+ current->mm->call_dl_resolve = call_dl_resolve;
11578+ up_write(&current->mm->mmap_sem);
11579+
11580+emulate:
11581+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11582+ regs->tpc = call_dl_resolve;
11583+ regs->tnpc = addr+4;
11584+ return 3;
11585+ }
11586+#endif
11587+
11588+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11589+ if ((save & 0xFFC00000U) == 0x05000000U &&
11590+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11591+ nop == 0x01000000U)
11592+ {
11593+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11594+ regs->u_regs[UREG_G2] = addr + 4;
11595+ addr = (save & 0x003FFFFFU) << 10;
11596+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11597+
11598+ if (test_thread_flag(TIF_32BIT))
11599+ addr &= 0xFFFFFFFFUL;
11600+
11601+ regs->tpc = addr;
11602+ regs->tnpc = addr+4;
11603+ return 3;
11604+ }
11605+
11606+ /* PaX: 64-bit PLT stub */
11607+ err = get_user(sethi1, (unsigned int *)addr);
11608+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11609+ err |= get_user(or1, (unsigned int *)(addr+8));
11610+ err |= get_user(or2, (unsigned int *)(addr+12));
11611+ err |= get_user(sllx, (unsigned int *)(addr+16));
11612+ err |= get_user(add, (unsigned int *)(addr+20));
11613+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11614+ err |= get_user(nop, (unsigned int *)(addr+28));
11615+ if (err)
11616+ break;
11617+
11618+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11619+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11620+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11621+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11622+ sllx == 0x89293020U &&
11623+ add == 0x8A010005U &&
11624+ jmpl == 0x89C14000U &&
11625+ nop == 0x01000000U)
11626+ {
11627+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11628+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11629+ regs->u_regs[UREG_G4] <<= 32;
11630+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11631+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11632+ regs->u_regs[UREG_G4] = addr + 24;
11633+ addr = regs->u_regs[UREG_G5];
11634+ regs->tpc = addr;
11635+ regs->tnpc = addr+4;
11636+ return 3;
11637+ }
11638+ }
11639+ } while (0);
11640+
11641+#ifdef CONFIG_PAX_DLRESOLVE
11642+ do { /* PaX: unpatched PLT emulation step 2 */
11643+ unsigned int save, call, nop;
11644+
11645+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11646+ err |= get_user(call, (unsigned int *)regs->tpc);
11647+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11648+ if (err)
11649+ break;
11650+
11651+ if (save == 0x9DE3BFA8U &&
11652+ (call & 0xC0000000U) == 0x40000000U &&
11653+ nop == 0x01000000U)
11654+ {
11655+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11656+
11657+ if (test_thread_flag(TIF_32BIT))
11658+ dl_resolve &= 0xFFFFFFFFUL;
11659+
11660+ regs->u_regs[UREG_RETPC] = regs->tpc;
11661+ regs->tpc = dl_resolve;
11662+ regs->tnpc = dl_resolve+4;
11663+ return 3;
11664+ }
11665+ } while (0);
11666+#endif
11667+
11668+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11669+ unsigned int sethi, ba, nop;
11670+
11671+ err = get_user(sethi, (unsigned int *)regs->tpc);
11672+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11673+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11674+
11675+ if (err)
11676+ break;
11677+
11678+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11679+ (ba & 0xFFF00000U) == 0x30600000U &&
11680+ nop == 0x01000000U)
11681+ {
11682+ unsigned long addr;
11683+
11684+ addr = (sethi & 0x003FFFFFU) << 10;
11685+ regs->u_regs[UREG_G1] = addr;
11686+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11687+
11688+ if (test_thread_flag(TIF_32BIT))
11689+ addr &= 0xFFFFFFFFUL;
11690+
11691+ regs->tpc = addr;
11692+ regs->tnpc = addr+4;
11693+ return 2;
11694+ }
11695+ } while (0);
11696+
11697+#endif
11698+
11699+ return 1;
11700+}
11701+
11702+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11703+{
11704+ unsigned long i;
11705+
11706+ printk(KERN_ERR "PAX: bytes at PC: ");
11707+ for (i = 0; i < 8; i++) {
11708+ unsigned int c;
11709+ if (get_user(c, (unsigned int *)pc+i))
11710+ printk(KERN_CONT "???????? ");
11711+ else
11712+ printk(KERN_CONT "%08x ", c);
11713+ }
11714+ printk("\n");
11715+}
11716+#endif
11717+
11718 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11719 {
11720 enum ctx_state prev_state = exception_enter();
11721@@ -344,6 +807,29 @@ retry:
11722 if (!vma)
11723 goto bad_area;
11724
11725+#ifdef CONFIG_PAX_PAGEEXEC
11726+ /* PaX: detect ITLB misses on non-exec pages */
11727+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11728+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11729+ {
11730+ if (address != regs->tpc)
11731+ goto good_area;
11732+
11733+ up_read(&mm->mmap_sem);
11734+ switch (pax_handle_fetch_fault(regs)) {
11735+
11736+#ifdef CONFIG_PAX_EMUPLT
11737+ case 2:
11738+ case 3:
11739+ return;
11740+#endif
11741+
11742+ }
11743+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11744+ do_group_exit(SIGKILL);
11745+ }
11746+#endif
11747+
11748 /* Pure DTLB misses do not tell us whether the fault causing
11749 * load/store/atomic was a write or not, it only says that there
11750 * was no match. So in such a case we (carefully) read the
11751diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11752index 9bd9ce8..dc84852 100644
11753--- a/arch/sparc/mm/hugetlbpage.c
11754+++ b/arch/sparc/mm/hugetlbpage.c
11755@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11756 unsigned long addr,
11757 unsigned long len,
11758 unsigned long pgoff,
11759- unsigned long flags)
11760+ unsigned long flags,
11761+ unsigned long offset)
11762 {
11763+ struct mm_struct *mm = current->mm;
11764 unsigned long task_size = TASK_SIZE;
11765 struct vm_unmapped_area_info info;
11766
11767@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11768
11769 info.flags = 0;
11770 info.length = len;
11771- info.low_limit = TASK_UNMAPPED_BASE;
11772+ info.low_limit = mm->mmap_base;
11773 info.high_limit = min(task_size, VA_EXCLUDE_START);
11774 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11775 info.align_offset = 0;
11776+ info.threadstack_offset = offset;
11777 addr = vm_unmapped_area(&info);
11778
11779 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11780 VM_BUG_ON(addr != -ENOMEM);
11781 info.low_limit = VA_EXCLUDE_END;
11782+
11783+#ifdef CONFIG_PAX_RANDMMAP
11784+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11785+ info.low_limit += mm->delta_mmap;
11786+#endif
11787+
11788 info.high_limit = task_size;
11789 addr = vm_unmapped_area(&info);
11790 }
11791@@ -55,7 +64,8 @@ static unsigned long
11792 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11793 const unsigned long len,
11794 const unsigned long pgoff,
11795- const unsigned long flags)
11796+ const unsigned long flags,
11797+ const unsigned long offset)
11798 {
11799 struct mm_struct *mm = current->mm;
11800 unsigned long addr = addr0;
11801@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11802 info.high_limit = mm->mmap_base;
11803 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11804 info.align_offset = 0;
11805+ info.threadstack_offset = offset;
11806 addr = vm_unmapped_area(&info);
11807
11808 /*
11809@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11810 VM_BUG_ON(addr != -ENOMEM);
11811 info.flags = 0;
11812 info.low_limit = TASK_UNMAPPED_BASE;
11813+
11814+#ifdef CONFIG_PAX_RANDMMAP
11815+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11816+ info.low_limit += mm->delta_mmap;
11817+#endif
11818+
11819 info.high_limit = STACK_TOP32;
11820 addr = vm_unmapped_area(&info);
11821 }
11822@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11823 struct mm_struct *mm = current->mm;
11824 struct vm_area_struct *vma;
11825 unsigned long task_size = TASK_SIZE;
11826+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11827
11828 if (test_thread_flag(TIF_32BIT))
11829 task_size = STACK_TOP32;
11830@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11831 return addr;
11832 }
11833
11834+#ifdef CONFIG_PAX_RANDMMAP
11835+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11836+#endif
11837+
11838 if (addr) {
11839 addr = ALIGN(addr, HPAGE_SIZE);
11840 vma = find_vma(mm, addr);
11841- if (task_size - len >= addr &&
11842- (!vma || addr + len <= vma->vm_start))
11843+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11844 return addr;
11845 }
11846 if (mm->get_unmapped_area == arch_get_unmapped_area)
11847 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11848- pgoff, flags);
11849+ pgoff, flags, offset);
11850 else
11851 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11852- pgoff, flags);
11853+ pgoff, flags, offset);
11854 }
11855
11856 pte_t *huge_pte_alloc(struct mm_struct *mm,
11857diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11858index eafbc65..5a8070d 100644
11859--- a/arch/sparc/mm/init_64.c
11860+++ b/arch/sparc/mm/init_64.c
11861@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11862 int num_kernel_image_mappings;
11863
11864 #ifdef CONFIG_DEBUG_DCFLUSH
11865-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11866+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11867 #ifdef CONFIG_SMP
11868-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11869+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11870 #endif
11871 #endif
11872
11873@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11874 {
11875 BUG_ON(tlb_type == hypervisor);
11876 #ifdef CONFIG_DEBUG_DCFLUSH
11877- atomic_inc(&dcpage_flushes);
11878+ atomic_inc_unchecked(&dcpage_flushes);
11879 #endif
11880
11881 #ifdef DCACHE_ALIASING_POSSIBLE
11882@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11883
11884 #ifdef CONFIG_DEBUG_DCFLUSH
11885 seq_printf(m, "DCPageFlushes\t: %d\n",
11886- atomic_read(&dcpage_flushes));
11887+ atomic_read_unchecked(&dcpage_flushes));
11888 #ifdef CONFIG_SMP
11889 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11890- atomic_read(&dcpage_flushes_xcall));
11891+ atomic_read_unchecked(&dcpage_flushes_xcall));
11892 #endif /* CONFIG_SMP */
11893 #endif /* CONFIG_DEBUG_DCFLUSH */
11894 }
11895diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11896index b3692ce..e4517c9 100644
11897--- a/arch/tile/Kconfig
11898+++ b/arch/tile/Kconfig
11899@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11900
11901 config KEXEC
11902 bool "kexec system call"
11903+ depends on !GRKERNSEC_KMEM
11904 ---help---
11905 kexec is a system call that implements the ability to shutdown your
11906 current kernel, and to start another kernel. It is like a reboot
11907diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11908index ad220ee..2f537b3 100644
11909--- a/arch/tile/include/asm/atomic_64.h
11910+++ b/arch/tile/include/asm/atomic_64.h
11911@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11912
11913 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11914
11915+#define atomic64_read_unchecked(v) atomic64_read(v)
11916+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11917+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11918+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11919+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11920+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11921+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11922+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11923+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11924+
11925 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11926 #define smp_mb__before_atomic_dec() smp_mb()
11927 #define smp_mb__after_atomic_dec() smp_mb()
11928diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11929index 6160761..00cac88 100644
11930--- a/arch/tile/include/asm/cache.h
11931+++ b/arch/tile/include/asm/cache.h
11932@@ -15,11 +15,12 @@
11933 #ifndef _ASM_TILE_CACHE_H
11934 #define _ASM_TILE_CACHE_H
11935
11936+#include <linux/const.h>
11937 #include <arch/chip.h>
11938
11939 /* bytes per L1 data cache line */
11940 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11941-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11942+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11943
11944 /* bytes per L2 cache line */
11945 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11946diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11947index b6cde32..c0cb736 100644
11948--- a/arch/tile/include/asm/uaccess.h
11949+++ b/arch/tile/include/asm/uaccess.h
11950@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11951 const void __user *from,
11952 unsigned long n)
11953 {
11954- int sz = __compiletime_object_size(to);
11955+ size_t sz = __compiletime_object_size(to);
11956
11957- if (likely(sz == -1 || sz >= n))
11958+ if (likely(sz == (size_t)-1 || sz >= n))
11959 n = _copy_from_user(to, from, n);
11960 else
11961 copy_from_user_overflow();
11962diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11963index 0cb3bba..7338b2d 100644
11964--- a/arch/tile/mm/hugetlbpage.c
11965+++ b/arch/tile/mm/hugetlbpage.c
11966@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11967 info.high_limit = TASK_SIZE;
11968 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11969 info.align_offset = 0;
11970+ info.threadstack_offset = 0;
11971 return vm_unmapped_area(&info);
11972 }
11973
11974@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11975 info.high_limit = current->mm->mmap_base;
11976 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11977 info.align_offset = 0;
11978+ info.threadstack_offset = 0;
11979 addr = vm_unmapped_area(&info);
11980
11981 /*
11982diff --git a/arch/um/Makefile b/arch/um/Makefile
11983index 36e658a..71a5c5a 100644
11984--- a/arch/um/Makefile
11985+++ b/arch/um/Makefile
11986@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11987 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11988 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11989
11990+ifdef CONSTIFY_PLUGIN
11991+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11992+endif
11993+
11994 #This will adjust *FLAGS accordingly to the platform.
11995 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11996
11997diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11998index 19e1bdd..3665b77 100644
11999--- a/arch/um/include/asm/cache.h
12000+++ b/arch/um/include/asm/cache.h
12001@@ -1,6 +1,7 @@
12002 #ifndef __UM_CACHE_H
12003 #define __UM_CACHE_H
12004
12005+#include <linux/const.h>
12006
12007 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12008 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12009@@ -12,6 +13,6 @@
12010 # define L1_CACHE_SHIFT 5
12011 #endif
12012
12013-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12014+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12015
12016 #endif
12017diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12018index 2e0a6b1..a64d0f5 100644
12019--- a/arch/um/include/asm/kmap_types.h
12020+++ b/arch/um/include/asm/kmap_types.h
12021@@ -8,6 +8,6 @@
12022
12023 /* No more #include "asm/arch/kmap_types.h" ! */
12024
12025-#define KM_TYPE_NR 14
12026+#define KM_TYPE_NR 15
12027
12028 #endif
12029diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12030index 5ff53d9..5850cdf 100644
12031--- a/arch/um/include/asm/page.h
12032+++ b/arch/um/include/asm/page.h
12033@@ -14,6 +14,9 @@
12034 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12035 #define PAGE_MASK (~(PAGE_SIZE-1))
12036
12037+#define ktla_ktva(addr) (addr)
12038+#define ktva_ktla(addr) (addr)
12039+
12040 #ifndef __ASSEMBLY__
12041
12042 struct page;
12043diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12044index 0032f92..cd151e0 100644
12045--- a/arch/um/include/asm/pgtable-3level.h
12046+++ b/arch/um/include/asm/pgtable-3level.h
12047@@ -58,6 +58,7 @@
12048 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12049 #define pud_populate(mm, pud, pmd) \
12050 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12051+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12052
12053 #ifdef CONFIG_64BIT
12054 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12055diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12056index eecc414..48adb87 100644
12057--- a/arch/um/kernel/process.c
12058+++ b/arch/um/kernel/process.c
12059@@ -356,22 +356,6 @@ int singlestepping(void * t)
12060 return 2;
12061 }
12062
12063-/*
12064- * Only x86 and x86_64 have an arch_align_stack().
12065- * All other arches have "#define arch_align_stack(x) (x)"
12066- * in their asm/system.h
12067- * As this is included in UML from asm-um/system-generic.h,
12068- * we can use it to behave as the subarch does.
12069- */
12070-#ifndef arch_align_stack
12071-unsigned long arch_align_stack(unsigned long sp)
12072-{
12073- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12074- sp -= get_random_int() % 8192;
12075- return sp & ~0xf;
12076-}
12077-#endif
12078-
12079 unsigned long get_wchan(struct task_struct *p)
12080 {
12081 unsigned long stack_page, sp, ip;
12082diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12083index ad8f795..2c7eec6 100644
12084--- a/arch/unicore32/include/asm/cache.h
12085+++ b/arch/unicore32/include/asm/cache.h
12086@@ -12,8 +12,10 @@
12087 #ifndef __UNICORE_CACHE_H__
12088 #define __UNICORE_CACHE_H__
12089
12090-#define L1_CACHE_SHIFT (5)
12091-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12092+#include <linux/const.h>
12093+
12094+#define L1_CACHE_SHIFT 5
12095+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12096
12097 /*
12098 * Memory returned by kmalloc() may be used for DMA, so we must make
12099diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12100index 0af5250..59f9597 100644
12101--- a/arch/x86/Kconfig
12102+++ b/arch/x86/Kconfig
12103@@ -126,7 +126,7 @@ config X86
12104 select RTC_LIB
12105 select HAVE_DEBUG_STACKOVERFLOW
12106 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12107- select HAVE_CC_STACKPROTECTOR
12108+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12109
12110 config INSTRUCTION_DECODER
12111 def_bool y
12112@@ -251,7 +251,7 @@ config X86_HT
12113
12114 config X86_32_LAZY_GS
12115 def_bool y
12116- depends on X86_32 && !CC_STACKPROTECTOR
12117+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12118
12119 config ARCH_HWEIGHT_CFLAGS
12120 string
12121@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12122
12123 menuconfig HYPERVISOR_GUEST
12124 bool "Linux guest support"
12125+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12126 ---help---
12127 Say Y here to enable options for running Linux under various hyper-
12128 visors. This option enables basic hypervisor detection and platform
12129@@ -1111,7 +1112,7 @@ choice
12130
12131 config NOHIGHMEM
12132 bool "off"
12133- depends on !X86_NUMAQ
12134+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12135 ---help---
12136 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12137 However, the address space of 32-bit x86 processors is only 4
12138@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12139
12140 config HIGHMEM4G
12141 bool "4GB"
12142- depends on !X86_NUMAQ
12143+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12144 ---help---
12145 Select this if you have a 32-bit processor and between 1 and 4
12146 gigabytes of physical RAM.
12147@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12148 hex
12149 default 0xB0000000 if VMSPLIT_3G_OPT
12150 default 0x80000000 if VMSPLIT_2G
12151- default 0x78000000 if VMSPLIT_2G_OPT
12152+ default 0x70000000 if VMSPLIT_2G_OPT
12153 default 0x40000000 if VMSPLIT_1G
12154 default 0xC0000000
12155 depends on X86_32
12156@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12157
12158 config KEXEC
12159 bool "kexec system call"
12160+ depends on !GRKERNSEC_KMEM
12161 ---help---
12162 kexec is a system call that implements the ability to shutdown your
12163 current kernel, and to start another kernel. It is like a reboot
12164@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12165
12166 config PHYSICAL_ALIGN
12167 hex "Alignment value to which kernel should be aligned"
12168- default "0x200000"
12169+ default "0x1000000"
12170+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12171+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12172 range 0x2000 0x1000000 if X86_32
12173 range 0x200000 0x1000000 if X86_64
12174 ---help---
12175@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12176 If unsure, say N.
12177
12178 config COMPAT_VDSO
12179- def_bool y
12180+ def_bool n
12181 prompt "Compat VDSO support"
12182 depends on X86_32 || IA32_EMULATION
12183+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12184 ---help---
12185 Map the 32-bit VDSO to the predictable old-style address too.
12186
12187diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12188index f3aaf23..a1d3c49 100644
12189--- a/arch/x86/Kconfig.cpu
12190+++ b/arch/x86/Kconfig.cpu
12191@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12192
12193 config X86_F00F_BUG
12194 def_bool y
12195- depends on M586MMX || M586TSC || M586 || M486
12196+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12197
12198 config X86_INVD_BUG
12199 def_bool y
12200@@ -327,7 +327,7 @@ config X86_INVD_BUG
12201
12202 config X86_ALIGNMENT_16
12203 def_bool y
12204- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12205+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12206
12207 config X86_INTEL_USERCOPY
12208 def_bool y
12209@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12210 # generates cmov.
12211 config X86_CMOV
12212 def_bool y
12213- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12214+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12215
12216 config X86_MINIMUM_CPU_FAMILY
12217 int
12218diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12219index 321a52c..3d51a5e 100644
12220--- a/arch/x86/Kconfig.debug
12221+++ b/arch/x86/Kconfig.debug
12222@@ -84,7 +84,7 @@ config X86_PTDUMP
12223 config DEBUG_RODATA
12224 bool "Write protect kernel read-only data structures"
12225 default y
12226- depends on DEBUG_KERNEL
12227+ depends on DEBUG_KERNEL && BROKEN
12228 ---help---
12229 Mark the kernel read-only data as write-protected in the pagetables,
12230 in order to catch accidental (and incorrect) writes to such const
12231@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12232
12233 config DEBUG_SET_MODULE_RONX
12234 bool "Set loadable kernel module data as NX and text as RO"
12235- depends on MODULES
12236+ depends on MODULES && BROKEN
12237 ---help---
12238 This option helps catch unintended modifications to loadable
12239 kernel module's text and read-only data. It also prevents execution
12240diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12241index f8842c4..e893775 100644
12242--- a/arch/x86/Makefile
12243+++ b/arch/x86/Makefile
12244@@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12245 # CPU-specific tuning. Anything which can be shared with UML should go here.
12246 include $(srctree)/arch/x86/Makefile_32.cpu
12247 KBUILD_CFLAGS += $(cflags-y)
12248-
12249- # temporary until string.h is fixed
12250- KBUILD_CFLAGS += -ffreestanding
12251 else
12252 BITS := 64
12253 UTS_MACHINE := x86_64
12254 CHECKFLAGS += -D__x86_64__ -m64
12255
12256+ biarch := $(call cc-option,-m64)
12257 KBUILD_AFLAGS += -m64
12258 KBUILD_CFLAGS += -m64
12259
12260@@ -111,6 +109,9 @@ else
12261 KBUILD_CFLAGS += -maccumulate-outgoing-args
12262 endif
12263
12264+# temporary until string.h is fixed
12265+KBUILD_CFLAGS += -ffreestanding
12266+
12267 # Make sure compiler does not have buggy stack-protector support.
12268 ifdef CONFIG_CC_STACKPROTECTOR
12269 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12270@@ -268,3 +269,12 @@ define archhelp
12271 echo ' FDINITRD=file initrd for the booted kernel'
12272 echo ' kvmconfig - Enable additional options for guest kernel support'
12273 endef
12274+
12275+define OLD_LD
12276+
12277+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12278+*** Please upgrade your binutils to 2.18 or newer
12279+endef
12280+
12281+archprepare:
12282+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12283diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12284index 878df7e..a803913 100644
12285--- a/arch/x86/boot/Makefile
12286+++ b/arch/x86/boot/Makefile
12287@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12288 # ---------------------------------------------------------------------------
12289
12290 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12291+ifdef CONSTIFY_PLUGIN
12292+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12293+endif
12294 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12295 GCOV_PROFILE := n
12296
12297diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12298index 878e4b9..20537ab 100644
12299--- a/arch/x86/boot/bitops.h
12300+++ b/arch/x86/boot/bitops.h
12301@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12302 u8 v;
12303 const u32 *p = (const u32 *)addr;
12304
12305- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12306+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12307 return v;
12308 }
12309
12310@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12311
12312 static inline void set_bit(int nr, void *addr)
12313 {
12314- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12315+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12316 }
12317
12318 #endif /* BOOT_BITOPS_H */
12319diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12320index 50f8c5e..4f84fff 100644
12321--- a/arch/x86/boot/boot.h
12322+++ b/arch/x86/boot/boot.h
12323@@ -84,7 +84,7 @@ static inline void io_delay(void)
12324 static inline u16 ds(void)
12325 {
12326 u16 seg;
12327- asm("movw %%ds,%0" : "=rm" (seg));
12328+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12329 return seg;
12330 }
12331
12332@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12333 static inline int memcmp(const void *s1, const void *s2, size_t len)
12334 {
12335 u8 diff;
12336- asm("repe; cmpsb; setnz %0"
12337+ asm volatile("repe; cmpsb; setnz %0"
12338 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12339 return diff;
12340 }
12341diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12342index 0fcd913..3bb5c42 100644
12343--- a/arch/x86/boot/compressed/Makefile
12344+++ b/arch/x86/boot/compressed/Makefile
12345@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12346 KBUILD_CFLAGS += -mno-mmx -mno-sse
12347 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12348 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12349+ifdef CONSTIFY_PLUGIN
12350+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12351+endif
12352
12353 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12354 GCOV_PROFILE := n
12355diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12356index a53440e..c3dbf1e 100644
12357--- a/arch/x86/boot/compressed/efi_stub_32.S
12358+++ b/arch/x86/boot/compressed/efi_stub_32.S
12359@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12360 * parameter 2, ..., param n. To make things easy, we save the return
12361 * address of efi_call_phys in a global variable.
12362 */
12363- popl %ecx
12364- movl %ecx, saved_return_addr(%edx)
12365- /* get the function pointer into ECX*/
12366- popl %ecx
12367- movl %ecx, efi_rt_function_ptr(%edx)
12368+ popl saved_return_addr(%edx)
12369+ popl efi_rt_function_ptr(%edx)
12370
12371 /*
12372 * 3. Call the physical function.
12373 */
12374- call *%ecx
12375+ call *efi_rt_function_ptr(%edx)
12376
12377 /*
12378 * 4. Balance the stack. And because EAX contain the return value,
12379@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12380 1: popl %edx
12381 subl $1b, %edx
12382
12383- movl efi_rt_function_ptr(%edx), %ecx
12384- pushl %ecx
12385+ pushl efi_rt_function_ptr(%edx)
12386
12387 /*
12388 * 10. Push the saved return address onto the stack and return.
12389 */
12390- movl saved_return_addr(%edx), %ecx
12391- pushl %ecx
12392- ret
12393+ jmpl *saved_return_addr(%edx)
12394 ENDPROC(efi_call_phys)
12395 .previous
12396
12397diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12398index f45ab7a..ebc015f 100644
12399--- a/arch/x86/boot/compressed/head_32.S
12400+++ b/arch/x86/boot/compressed/head_32.S
12401@@ -119,10 +119,10 @@ preferred_addr:
12402 addl %eax, %ebx
12403 notl %eax
12404 andl %eax, %ebx
12405- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12406+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12407 jge 1f
12408 #endif
12409- movl $LOAD_PHYSICAL_ADDR, %ebx
12410+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12411 1:
12412
12413 /* Target address to relocate to for decompression */
12414diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12415index b10fa66..5ee0472 100644
12416--- a/arch/x86/boot/compressed/head_64.S
12417+++ b/arch/x86/boot/compressed/head_64.S
12418@@ -94,10 +94,10 @@ ENTRY(startup_32)
12419 addl %eax, %ebx
12420 notl %eax
12421 andl %eax, %ebx
12422- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12423+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12424 jge 1f
12425 #endif
12426- movl $LOAD_PHYSICAL_ADDR, %ebx
12427+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12428 1:
12429
12430 /* Target address to relocate to for decompression */
12431@@ -268,10 +268,10 @@ preferred_addr:
12432 addq %rax, %rbp
12433 notq %rax
12434 andq %rax, %rbp
12435- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12436+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12437 jge 1f
12438 #endif
12439- movq $LOAD_PHYSICAL_ADDR, %rbp
12440+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12441 1:
12442
12443 /* Target address to relocate to for decompression */
12444@@ -363,8 +363,8 @@ gdt:
12445 .long gdt
12446 .word 0
12447 .quad 0x0000000000000000 /* NULL descriptor */
12448- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12449- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12450+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12451+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12452 .quad 0x0080890000000000 /* TS descriptor */
12453 .quad 0x0000000000000000 /* TS continued */
12454 gdt_end:
12455diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12456index 196eaf3..c96716d 100644
12457--- a/arch/x86/boot/compressed/misc.c
12458+++ b/arch/x86/boot/compressed/misc.c
12459@@ -218,7 +218,7 @@ void __putstr(const char *s)
12460
12461 void *memset(void *s, int c, size_t n)
12462 {
12463- int i;
12464+ size_t i;
12465 char *ss = s;
12466
12467 for (i = 0; i < n; i++)
12468@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12469 * Calculate the delta between where vmlinux was linked to load
12470 * and where it was actually loaded.
12471 */
12472- delta = min_addr - LOAD_PHYSICAL_ADDR;
12473+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12474 if (!delta) {
12475 debug_putstr("No relocation needed... ");
12476 return;
12477@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12478 Elf32_Ehdr ehdr;
12479 Elf32_Phdr *phdrs, *phdr;
12480 #endif
12481- void *dest;
12482+ void *dest, *prev;
12483 int i;
12484
12485 memcpy(&ehdr, output, sizeof(ehdr));
12486@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12487 case PT_LOAD:
12488 #ifdef CONFIG_RELOCATABLE
12489 dest = output;
12490- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12491+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12492 #else
12493 dest = (void *)(phdr->p_paddr);
12494 #endif
12495 memcpy(dest,
12496 output + phdr->p_offset,
12497 phdr->p_filesz);
12498+ if (i)
12499+ memset(prev, 0xff, dest - prev);
12500+ prev = dest + phdr->p_filesz;
12501 break;
12502 default: /* Ignore other PT_* */ break;
12503 }
12504@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12505 error("Destination address too large");
12506 #endif
12507 #ifndef CONFIG_RELOCATABLE
12508- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12509+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12510 error("Wrong destination address");
12511 #endif
12512
12513diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12514index 100a9a1..bb3bdb0 100644
12515--- a/arch/x86/boot/cpucheck.c
12516+++ b/arch/x86/boot/cpucheck.c
12517@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12518 u32 ecx = MSR_K7_HWCR;
12519 u32 eax, edx;
12520
12521- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12522+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12523 eax &= ~(1 << 15);
12524- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12525+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12526
12527 get_cpuflags(); /* Make sure it really did something */
12528 err = check_cpuflags();
12529@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12530 u32 ecx = MSR_VIA_FCR;
12531 u32 eax, edx;
12532
12533- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12534+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12535 eax |= (1<<1)|(1<<7);
12536- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12537+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12538
12539 set_bit(X86_FEATURE_CX8, cpu.flags);
12540 err = check_cpuflags();
12541@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12542 u32 eax, edx;
12543 u32 level = 1;
12544
12545- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12546- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12547- asm("cpuid"
12548+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12549+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12550+ asm volatile("cpuid"
12551 : "+a" (level), "=d" (cpu.flags[0])
12552 : : "ecx", "ebx");
12553- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12554+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12555
12556 err = check_cpuflags();
12557 }
12558diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12559index ec3b8ba..6a0db1f 100644
12560--- a/arch/x86/boot/header.S
12561+++ b/arch/x86/boot/header.S
12562@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12563 # single linked list of
12564 # struct setup_data
12565
12566-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12567+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12568
12569 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12570+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12571+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12572+#else
12573 #define VO_INIT_SIZE (VO__end - VO__text)
12574+#endif
12575 #if ZO_INIT_SIZE > VO_INIT_SIZE
12576 #define INIT_SIZE ZO_INIT_SIZE
12577 #else
12578diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12579index db75d07..8e6d0af 100644
12580--- a/arch/x86/boot/memory.c
12581+++ b/arch/x86/boot/memory.c
12582@@ -19,7 +19,7 @@
12583
12584 static int detect_memory_e820(void)
12585 {
12586- int count = 0;
12587+ unsigned int count = 0;
12588 struct biosregs ireg, oreg;
12589 struct e820entry *desc = boot_params.e820_map;
12590 static struct e820entry buf; /* static so it is zeroed */
12591diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12592index 11e8c6e..fdbb1ed 100644
12593--- a/arch/x86/boot/video-vesa.c
12594+++ b/arch/x86/boot/video-vesa.c
12595@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12596
12597 boot_params.screen_info.vesapm_seg = oreg.es;
12598 boot_params.screen_info.vesapm_off = oreg.di;
12599+ boot_params.screen_info.vesapm_size = oreg.cx;
12600 }
12601
12602 /*
12603diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12604index 43eda28..5ab5fdb 100644
12605--- a/arch/x86/boot/video.c
12606+++ b/arch/x86/boot/video.c
12607@@ -96,7 +96,7 @@ static void store_mode_params(void)
12608 static unsigned int get_entry(void)
12609 {
12610 char entry_buf[4];
12611- int i, len = 0;
12612+ unsigned int i, len = 0;
12613 int key;
12614 unsigned int v;
12615
12616diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12617index 9105655..41779c1 100644
12618--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12619+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12620@@ -8,6 +8,8 @@
12621 * including this sentence is retained in full.
12622 */
12623
12624+#include <asm/alternative-asm.h>
12625+
12626 .extern crypto_ft_tab
12627 .extern crypto_it_tab
12628 .extern crypto_fl_tab
12629@@ -70,6 +72,8 @@
12630 je B192; \
12631 leaq 32(r9),r9;
12632
12633+#define ret pax_force_retaddr; ret
12634+
12635 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12636 movq r1,r2; \
12637 movq r3,r4; \
12638diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12639index 477e9d7..c92c7d8 100644
12640--- a/arch/x86/crypto/aesni-intel_asm.S
12641+++ b/arch/x86/crypto/aesni-intel_asm.S
12642@@ -31,6 +31,7 @@
12643
12644 #include <linux/linkage.h>
12645 #include <asm/inst.h>
12646+#include <asm/alternative-asm.h>
12647
12648 #ifdef __x86_64__
12649 .data
12650@@ -205,7 +206,7 @@ enc: .octa 0x2
12651 * num_initial_blocks = b mod 4
12652 * encrypt the initial num_initial_blocks blocks and apply ghash on
12653 * the ciphertext
12654-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12655+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12656 * are clobbered
12657 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12658 */
12659@@ -214,8 +215,8 @@ enc: .octa 0x2
12660 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12661 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12662 mov arg7, %r10 # %r10 = AAD
12663- mov arg8, %r12 # %r12 = aadLen
12664- mov %r12, %r11
12665+ mov arg8, %r15 # %r15 = aadLen
12666+ mov %r15, %r11
12667 pxor %xmm\i, %xmm\i
12668 _get_AAD_loop\num_initial_blocks\operation:
12669 movd (%r10), \TMP1
12670@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12671 psrldq $4, %xmm\i
12672 pxor \TMP1, %xmm\i
12673 add $4, %r10
12674- sub $4, %r12
12675+ sub $4, %r15
12676 jne _get_AAD_loop\num_initial_blocks\operation
12677 cmp $16, %r11
12678 je _get_AAD_loop2_done\num_initial_blocks\operation
12679- mov $16, %r12
12680+ mov $16, %r15
12681 _get_AAD_loop2\num_initial_blocks\operation:
12682 psrldq $4, %xmm\i
12683- sub $4, %r12
12684- cmp %r11, %r12
12685+ sub $4, %r15
12686+ cmp %r11, %r15
12687 jne _get_AAD_loop2\num_initial_blocks\operation
12688 _get_AAD_loop2_done\num_initial_blocks\operation:
12689 movdqa SHUF_MASK(%rip), %xmm14
12690@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12691 * num_initial_blocks = b mod 4
12692 * encrypt the initial num_initial_blocks blocks and apply ghash on
12693 * the ciphertext
12694-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12695+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12696 * are clobbered
12697 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12698 */
12699@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12700 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12701 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12702 mov arg7, %r10 # %r10 = AAD
12703- mov arg8, %r12 # %r12 = aadLen
12704- mov %r12, %r11
12705+ mov arg8, %r15 # %r15 = aadLen
12706+ mov %r15, %r11
12707 pxor %xmm\i, %xmm\i
12708 _get_AAD_loop\num_initial_blocks\operation:
12709 movd (%r10), \TMP1
12710@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12711 psrldq $4, %xmm\i
12712 pxor \TMP1, %xmm\i
12713 add $4, %r10
12714- sub $4, %r12
12715+ sub $4, %r15
12716 jne _get_AAD_loop\num_initial_blocks\operation
12717 cmp $16, %r11
12718 je _get_AAD_loop2_done\num_initial_blocks\operation
12719- mov $16, %r12
12720+ mov $16, %r15
12721 _get_AAD_loop2\num_initial_blocks\operation:
12722 psrldq $4, %xmm\i
12723- sub $4, %r12
12724- cmp %r11, %r12
12725+ sub $4, %r15
12726+ cmp %r11, %r15
12727 jne _get_AAD_loop2\num_initial_blocks\operation
12728 _get_AAD_loop2_done\num_initial_blocks\operation:
12729 movdqa SHUF_MASK(%rip), %xmm14
12730@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12731 *
12732 *****************************************************************************/
12733 ENTRY(aesni_gcm_dec)
12734- push %r12
12735+ push %r15
12736 push %r13
12737 push %r14
12738 mov %rsp, %r14
12739@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12740 */
12741 sub $VARIABLE_OFFSET, %rsp
12742 and $~63, %rsp # align rsp to 64 bytes
12743- mov %arg6, %r12
12744- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12745+ mov %arg6, %r15
12746+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12747 movdqa SHUF_MASK(%rip), %xmm2
12748 PSHUFB_XMM %xmm2, %xmm13
12749
12750@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12751 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12752 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12753 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12754- mov %r13, %r12
12755- and $(3<<4), %r12
12756+ mov %r13, %r15
12757+ and $(3<<4), %r15
12758 jz _initial_num_blocks_is_0_decrypt
12759- cmp $(2<<4), %r12
12760+ cmp $(2<<4), %r15
12761 jb _initial_num_blocks_is_1_decrypt
12762 je _initial_num_blocks_is_2_decrypt
12763 _initial_num_blocks_is_3_decrypt:
12764@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12765 sub $16, %r11
12766 add %r13, %r11
12767 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12768- lea SHIFT_MASK+16(%rip), %r12
12769- sub %r13, %r12
12770+ lea SHIFT_MASK+16(%rip), %r15
12771+ sub %r13, %r15
12772 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12773 # (%r13 is the number of bytes in plaintext mod 16)
12774- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12775+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12776 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12777
12778 movdqa %xmm1, %xmm2
12779 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12780- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12781+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12782 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12783 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12784 pand %xmm1, %xmm2
12785@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12786 sub $1, %r13
12787 jne _less_than_8_bytes_left_decrypt
12788 _multiple_of_16_bytes_decrypt:
12789- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12790- shl $3, %r12 # convert into number of bits
12791- movd %r12d, %xmm15 # len(A) in %xmm15
12792+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12793+ shl $3, %r15 # convert into number of bits
12794+ movd %r15d, %xmm15 # len(A) in %xmm15
12795 shl $3, %arg4 # len(C) in bits (*128)
12796 MOVQ_R64_XMM %arg4, %xmm1
12797 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12798@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12799 mov %r14, %rsp
12800 pop %r14
12801 pop %r13
12802- pop %r12
12803+ pop %r15
12804+ pax_force_retaddr
12805 ret
12806 ENDPROC(aesni_gcm_dec)
12807
12808@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12809 * poly = x^128 + x^127 + x^126 + x^121 + 1
12810 ***************************************************************************/
12811 ENTRY(aesni_gcm_enc)
12812- push %r12
12813+ push %r15
12814 push %r13
12815 push %r14
12816 mov %rsp, %r14
12817@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12818 #
12819 sub $VARIABLE_OFFSET, %rsp
12820 and $~63, %rsp
12821- mov %arg6, %r12
12822- movdqu (%r12), %xmm13
12823+ mov %arg6, %r15
12824+ movdqu (%r15), %xmm13
12825 movdqa SHUF_MASK(%rip), %xmm2
12826 PSHUFB_XMM %xmm2, %xmm13
12827
12828@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12829 movdqa %xmm13, HashKey(%rsp)
12830 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12831 and $-16, %r13
12832- mov %r13, %r12
12833+ mov %r13, %r15
12834
12835 # Encrypt first few blocks
12836
12837- and $(3<<4), %r12
12838+ and $(3<<4), %r15
12839 jz _initial_num_blocks_is_0_encrypt
12840- cmp $(2<<4), %r12
12841+ cmp $(2<<4), %r15
12842 jb _initial_num_blocks_is_1_encrypt
12843 je _initial_num_blocks_is_2_encrypt
12844 _initial_num_blocks_is_3_encrypt:
12845@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12846 sub $16, %r11
12847 add %r13, %r11
12848 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12849- lea SHIFT_MASK+16(%rip), %r12
12850- sub %r13, %r12
12851+ lea SHIFT_MASK+16(%rip), %r15
12852+ sub %r13, %r15
12853 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12854 # (%r13 is the number of bytes in plaintext mod 16)
12855- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12856+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12857 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12858 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12859- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12860+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12861 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12862 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12863 movdqa SHUF_MASK(%rip), %xmm10
12864@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12865 sub $1, %r13
12866 jne _less_than_8_bytes_left_encrypt
12867 _multiple_of_16_bytes_encrypt:
12868- mov arg8, %r12 # %r12 = addLen (number of bytes)
12869- shl $3, %r12
12870- movd %r12d, %xmm15 # len(A) in %xmm15
12871+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12872+ shl $3, %r15
12873+ movd %r15d, %xmm15 # len(A) in %xmm15
12874 shl $3, %arg4 # len(C) in bits (*128)
12875 MOVQ_R64_XMM %arg4, %xmm1
12876 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12877@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12878 mov %r14, %rsp
12879 pop %r14
12880 pop %r13
12881- pop %r12
12882+ pop %r15
12883+ pax_force_retaddr
12884 ret
12885 ENDPROC(aesni_gcm_enc)
12886
12887@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12888 pxor %xmm1, %xmm0
12889 movaps %xmm0, (TKEYP)
12890 add $0x10, TKEYP
12891+ pax_force_retaddr
12892 ret
12893 ENDPROC(_key_expansion_128)
12894 ENDPROC(_key_expansion_256a)
12895@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12896 shufps $0b01001110, %xmm2, %xmm1
12897 movaps %xmm1, 0x10(TKEYP)
12898 add $0x20, TKEYP
12899+ pax_force_retaddr
12900 ret
12901 ENDPROC(_key_expansion_192a)
12902
12903@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12904
12905 movaps %xmm0, (TKEYP)
12906 add $0x10, TKEYP
12907+ pax_force_retaddr
12908 ret
12909 ENDPROC(_key_expansion_192b)
12910
12911@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12912 pxor %xmm1, %xmm2
12913 movaps %xmm2, (TKEYP)
12914 add $0x10, TKEYP
12915+ pax_force_retaddr
12916 ret
12917 ENDPROC(_key_expansion_256b)
12918
12919@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12920 #ifndef __x86_64__
12921 popl KEYP
12922 #endif
12923+ pax_force_retaddr
12924 ret
12925 ENDPROC(aesni_set_key)
12926
12927@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12928 popl KLEN
12929 popl KEYP
12930 #endif
12931+ pax_force_retaddr
12932 ret
12933 ENDPROC(aesni_enc)
12934
12935@@ -1974,6 +1983,7 @@ _aesni_enc1:
12936 AESENC KEY STATE
12937 movaps 0x70(TKEYP), KEY
12938 AESENCLAST KEY STATE
12939+ pax_force_retaddr
12940 ret
12941 ENDPROC(_aesni_enc1)
12942
12943@@ -2083,6 +2093,7 @@ _aesni_enc4:
12944 AESENCLAST KEY STATE2
12945 AESENCLAST KEY STATE3
12946 AESENCLAST KEY STATE4
12947+ pax_force_retaddr
12948 ret
12949 ENDPROC(_aesni_enc4)
12950
12951@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12952 popl KLEN
12953 popl KEYP
12954 #endif
12955+ pax_force_retaddr
12956 ret
12957 ENDPROC(aesni_dec)
12958
12959@@ -2164,6 +2176,7 @@ _aesni_dec1:
12960 AESDEC KEY STATE
12961 movaps 0x70(TKEYP), KEY
12962 AESDECLAST KEY STATE
12963+ pax_force_retaddr
12964 ret
12965 ENDPROC(_aesni_dec1)
12966
12967@@ -2273,6 +2286,7 @@ _aesni_dec4:
12968 AESDECLAST KEY STATE2
12969 AESDECLAST KEY STATE3
12970 AESDECLAST KEY STATE4
12971+ pax_force_retaddr
12972 ret
12973 ENDPROC(_aesni_dec4)
12974
12975@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12976 popl KEYP
12977 popl LEN
12978 #endif
12979+ pax_force_retaddr
12980 ret
12981 ENDPROC(aesni_ecb_enc)
12982
12983@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12984 popl KEYP
12985 popl LEN
12986 #endif
12987+ pax_force_retaddr
12988 ret
12989 ENDPROC(aesni_ecb_dec)
12990
12991@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12992 popl LEN
12993 popl IVP
12994 #endif
12995+ pax_force_retaddr
12996 ret
12997 ENDPROC(aesni_cbc_enc)
12998
12999@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13000 popl LEN
13001 popl IVP
13002 #endif
13003+ pax_force_retaddr
13004 ret
13005 ENDPROC(aesni_cbc_dec)
13006
13007@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13008 mov $1, TCTR_LOW
13009 MOVQ_R64_XMM TCTR_LOW INC
13010 MOVQ_R64_XMM CTR TCTR_LOW
13011+ pax_force_retaddr
13012 ret
13013 ENDPROC(_aesni_inc_init)
13014
13015@@ -2579,6 +2598,7 @@ _aesni_inc:
13016 .Linc_low:
13017 movaps CTR, IV
13018 PSHUFB_XMM BSWAP_MASK IV
13019+ pax_force_retaddr
13020 ret
13021 ENDPROC(_aesni_inc)
13022
13023@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13024 .Lctr_enc_ret:
13025 movups IV, (IVP)
13026 .Lctr_enc_just_ret:
13027+ pax_force_retaddr
13028 ret
13029 ENDPROC(aesni_ctr_enc)
13030
13031@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13032 pxor INC, STATE4
13033 movdqu STATE4, 0x70(OUTP)
13034
13035+ pax_force_retaddr
13036 ret
13037 ENDPROC(aesni_xts_crypt8)
13038
13039diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13040index 246c670..466e2d6 100644
13041--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13042+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13043@@ -21,6 +21,7 @@
13044 */
13045
13046 #include <linux/linkage.h>
13047+#include <asm/alternative-asm.h>
13048
13049 .file "blowfish-x86_64-asm.S"
13050 .text
13051@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13052 jnz .L__enc_xor;
13053
13054 write_block();
13055+ pax_force_retaddr
13056 ret;
13057 .L__enc_xor:
13058 xor_block();
13059+ pax_force_retaddr
13060 ret;
13061 ENDPROC(__blowfish_enc_blk)
13062
13063@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13064
13065 movq %r11, %rbp;
13066
13067+ pax_force_retaddr
13068 ret;
13069 ENDPROC(blowfish_dec_blk)
13070
13071@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13072
13073 popq %rbx;
13074 popq %rbp;
13075+ pax_force_retaddr
13076 ret;
13077
13078 .L__enc_xor4:
13079@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13080
13081 popq %rbx;
13082 popq %rbp;
13083+ pax_force_retaddr
13084 ret;
13085 ENDPROC(__blowfish_enc_blk_4way)
13086
13087@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13088 popq %rbx;
13089 popq %rbp;
13090
13091+ pax_force_retaddr
13092 ret;
13093 ENDPROC(blowfish_dec_blk_4way)
13094diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13095index ce71f92..1dce7ec 100644
13096--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13097+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13098@@ -16,6 +16,7 @@
13099 */
13100
13101 #include <linux/linkage.h>
13102+#include <asm/alternative-asm.h>
13103
13104 #define CAMELLIA_TABLE_BYTE_LEN 272
13105
13106@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13107 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13108 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13109 %rcx, (%r9));
13110+ pax_force_retaddr
13111 ret;
13112 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13113
13114@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13115 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13116 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13117 %rax, (%r9));
13118+ pax_force_retaddr
13119 ret;
13120 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13121
13122@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13123 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13124 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13125
13126+ pax_force_retaddr
13127 ret;
13128
13129 .align 8
13130@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13131 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13132 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13133
13134+ pax_force_retaddr
13135 ret;
13136
13137 .align 8
13138@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13139 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13140 %xmm8, %rsi);
13141
13142+ pax_force_retaddr
13143 ret;
13144 ENDPROC(camellia_ecb_enc_16way)
13145
13146@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13147 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13148 %xmm8, %rsi);
13149
13150+ pax_force_retaddr
13151 ret;
13152 ENDPROC(camellia_ecb_dec_16way)
13153
13154@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13155 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13156 %xmm8, %rsi);
13157
13158+ pax_force_retaddr
13159 ret;
13160 ENDPROC(camellia_cbc_dec_16way)
13161
13162@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13163 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13164 %xmm8, %rsi);
13165
13166+ pax_force_retaddr
13167 ret;
13168 ENDPROC(camellia_ctr_16way)
13169
13170@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13171 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13172 %xmm8, %rsi);
13173
13174+ pax_force_retaddr
13175 ret;
13176 ENDPROC(camellia_xts_crypt_16way)
13177
13178diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13179index 0e0b886..5a3123c 100644
13180--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13181+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13182@@ -11,6 +11,7 @@
13183 */
13184
13185 #include <linux/linkage.h>
13186+#include <asm/alternative-asm.h>
13187
13188 #define CAMELLIA_TABLE_BYTE_LEN 272
13189
13190@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13191 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13192 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13193 %rcx, (%r9));
13194+ pax_force_retaddr
13195 ret;
13196 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13197
13198@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13199 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13200 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13201 %rax, (%r9));
13202+ pax_force_retaddr
13203 ret;
13204 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13205
13206@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13207 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13208 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13209
13210+ pax_force_retaddr
13211 ret;
13212
13213 .align 8
13214@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13215 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13216 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13217
13218+ pax_force_retaddr
13219 ret;
13220
13221 .align 8
13222@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13223
13224 vzeroupper;
13225
13226+ pax_force_retaddr
13227 ret;
13228 ENDPROC(camellia_ecb_enc_32way)
13229
13230@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13231
13232 vzeroupper;
13233
13234+ pax_force_retaddr
13235 ret;
13236 ENDPROC(camellia_ecb_dec_32way)
13237
13238@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13239
13240 vzeroupper;
13241
13242+ pax_force_retaddr
13243 ret;
13244 ENDPROC(camellia_cbc_dec_32way)
13245
13246@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13247
13248 vzeroupper;
13249
13250+ pax_force_retaddr
13251 ret;
13252 ENDPROC(camellia_ctr_32way)
13253
13254@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13255
13256 vzeroupper;
13257
13258+ pax_force_retaddr
13259 ret;
13260 ENDPROC(camellia_xts_crypt_32way)
13261
13262diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13263index 310319c..db3d7b5 100644
13264--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13265+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13266@@ -21,6 +21,7 @@
13267 */
13268
13269 #include <linux/linkage.h>
13270+#include <asm/alternative-asm.h>
13271
13272 .file "camellia-x86_64-asm_64.S"
13273 .text
13274@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13275 enc_outunpack(mov, RT1);
13276
13277 movq RRBP, %rbp;
13278+ pax_force_retaddr
13279 ret;
13280
13281 .L__enc_xor:
13282 enc_outunpack(xor, RT1);
13283
13284 movq RRBP, %rbp;
13285+ pax_force_retaddr
13286 ret;
13287 ENDPROC(__camellia_enc_blk)
13288
13289@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13290 dec_outunpack();
13291
13292 movq RRBP, %rbp;
13293+ pax_force_retaddr
13294 ret;
13295 ENDPROC(camellia_dec_blk)
13296
13297@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13298
13299 movq RRBP, %rbp;
13300 popq %rbx;
13301+ pax_force_retaddr
13302 ret;
13303
13304 .L__enc2_xor:
13305@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13306
13307 movq RRBP, %rbp;
13308 popq %rbx;
13309+ pax_force_retaddr
13310 ret;
13311 ENDPROC(__camellia_enc_blk_2way)
13312
13313@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13314
13315 movq RRBP, %rbp;
13316 movq RXOR, %rbx;
13317+ pax_force_retaddr
13318 ret;
13319 ENDPROC(camellia_dec_blk_2way)
13320diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13321index c35fd5d..2d8c7db 100644
13322--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13323+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13324@@ -24,6 +24,7 @@
13325 */
13326
13327 #include <linux/linkage.h>
13328+#include <asm/alternative-asm.h>
13329
13330 .file "cast5-avx-x86_64-asm_64.S"
13331
13332@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13333 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13334 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13335
13336+ pax_force_retaddr
13337 ret;
13338 ENDPROC(__cast5_enc_blk16)
13339
13340@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13341 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13342 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13343
13344+ pax_force_retaddr
13345 ret;
13346
13347 .L__skip_dec:
13348@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13349 vmovdqu RR4, (6*4*4)(%r11);
13350 vmovdqu RL4, (7*4*4)(%r11);
13351
13352+ pax_force_retaddr
13353 ret;
13354 ENDPROC(cast5_ecb_enc_16way)
13355
13356@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13357 vmovdqu RR4, (6*4*4)(%r11);
13358 vmovdqu RL4, (7*4*4)(%r11);
13359
13360+ pax_force_retaddr
13361 ret;
13362 ENDPROC(cast5_ecb_dec_16way)
13363
13364@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13365 * %rdx: src
13366 */
13367
13368- pushq %r12;
13369+ pushq %r14;
13370
13371 movq %rsi, %r11;
13372- movq %rdx, %r12;
13373+ movq %rdx, %r14;
13374
13375 vmovdqu (0*16)(%rdx), RL1;
13376 vmovdqu (1*16)(%rdx), RR1;
13377@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13378 call __cast5_dec_blk16;
13379
13380 /* xor with src */
13381- vmovq (%r12), RX;
13382+ vmovq (%r14), RX;
13383 vpshufd $0x4f, RX, RX;
13384 vpxor RX, RR1, RR1;
13385- vpxor 0*16+8(%r12), RL1, RL1;
13386- vpxor 1*16+8(%r12), RR2, RR2;
13387- vpxor 2*16+8(%r12), RL2, RL2;
13388- vpxor 3*16+8(%r12), RR3, RR3;
13389- vpxor 4*16+8(%r12), RL3, RL3;
13390- vpxor 5*16+8(%r12), RR4, RR4;
13391- vpxor 6*16+8(%r12), RL4, RL4;
13392+ vpxor 0*16+8(%r14), RL1, RL1;
13393+ vpxor 1*16+8(%r14), RR2, RR2;
13394+ vpxor 2*16+8(%r14), RL2, RL2;
13395+ vpxor 3*16+8(%r14), RR3, RR3;
13396+ vpxor 4*16+8(%r14), RL3, RL3;
13397+ vpxor 5*16+8(%r14), RR4, RR4;
13398+ vpxor 6*16+8(%r14), RL4, RL4;
13399
13400 vmovdqu RR1, (0*16)(%r11);
13401 vmovdqu RL1, (1*16)(%r11);
13402@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13403 vmovdqu RR4, (6*16)(%r11);
13404 vmovdqu RL4, (7*16)(%r11);
13405
13406- popq %r12;
13407+ popq %r14;
13408
13409+ pax_force_retaddr
13410 ret;
13411 ENDPROC(cast5_cbc_dec_16way)
13412
13413@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13414 * %rcx: iv (big endian, 64bit)
13415 */
13416
13417- pushq %r12;
13418+ pushq %r14;
13419
13420 movq %rsi, %r11;
13421- movq %rdx, %r12;
13422+ movq %rdx, %r14;
13423
13424 vpcmpeqd RTMP, RTMP, RTMP;
13425 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13426@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13427 call __cast5_enc_blk16;
13428
13429 /* dst = src ^ iv */
13430- vpxor (0*16)(%r12), RR1, RR1;
13431- vpxor (1*16)(%r12), RL1, RL1;
13432- vpxor (2*16)(%r12), RR2, RR2;
13433- vpxor (3*16)(%r12), RL2, RL2;
13434- vpxor (4*16)(%r12), RR3, RR3;
13435- vpxor (5*16)(%r12), RL3, RL3;
13436- vpxor (6*16)(%r12), RR4, RR4;
13437- vpxor (7*16)(%r12), RL4, RL4;
13438+ vpxor (0*16)(%r14), RR1, RR1;
13439+ vpxor (1*16)(%r14), RL1, RL1;
13440+ vpxor (2*16)(%r14), RR2, RR2;
13441+ vpxor (3*16)(%r14), RL2, RL2;
13442+ vpxor (4*16)(%r14), RR3, RR3;
13443+ vpxor (5*16)(%r14), RL3, RL3;
13444+ vpxor (6*16)(%r14), RR4, RR4;
13445+ vpxor (7*16)(%r14), RL4, RL4;
13446 vmovdqu RR1, (0*16)(%r11);
13447 vmovdqu RL1, (1*16)(%r11);
13448 vmovdqu RR2, (2*16)(%r11);
13449@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13450 vmovdqu RR4, (6*16)(%r11);
13451 vmovdqu RL4, (7*16)(%r11);
13452
13453- popq %r12;
13454+ popq %r14;
13455
13456+ pax_force_retaddr
13457 ret;
13458 ENDPROC(cast5_ctr_16way)
13459diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13460index e3531f8..e123f35 100644
13461--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13462+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13463@@ -24,6 +24,7 @@
13464 */
13465
13466 #include <linux/linkage.h>
13467+#include <asm/alternative-asm.h>
13468 #include "glue_helper-asm-avx.S"
13469
13470 .file "cast6-avx-x86_64-asm_64.S"
13471@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13472 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13473 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13474
13475+ pax_force_retaddr
13476 ret;
13477 ENDPROC(__cast6_enc_blk8)
13478
13479@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13480 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13481 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13482
13483+ pax_force_retaddr
13484 ret;
13485 ENDPROC(__cast6_dec_blk8)
13486
13487@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13488
13489 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13490
13491+ pax_force_retaddr
13492 ret;
13493 ENDPROC(cast6_ecb_enc_8way)
13494
13495@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13496
13497 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13498
13499+ pax_force_retaddr
13500 ret;
13501 ENDPROC(cast6_ecb_dec_8way)
13502
13503@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13504 * %rdx: src
13505 */
13506
13507- pushq %r12;
13508+ pushq %r14;
13509
13510 movq %rsi, %r11;
13511- movq %rdx, %r12;
13512+ movq %rdx, %r14;
13513
13514 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13515
13516 call __cast6_dec_blk8;
13517
13518- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13519+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13520
13521- popq %r12;
13522+ popq %r14;
13523
13524+ pax_force_retaddr
13525 ret;
13526 ENDPROC(cast6_cbc_dec_8way)
13527
13528@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13529 * %rcx: iv (little endian, 128bit)
13530 */
13531
13532- pushq %r12;
13533+ pushq %r14;
13534
13535 movq %rsi, %r11;
13536- movq %rdx, %r12;
13537+ movq %rdx, %r14;
13538
13539 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13540 RD2, RX, RKR, RKM);
13541
13542 call __cast6_enc_blk8;
13543
13544- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13545+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13546
13547- popq %r12;
13548+ popq %r14;
13549
13550+ pax_force_retaddr
13551 ret;
13552 ENDPROC(cast6_ctr_8way)
13553
13554@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13555 /* dst <= regs xor IVs(in dst) */
13556 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13557
13558+ pax_force_retaddr
13559 ret;
13560 ENDPROC(cast6_xts_enc_8way)
13561
13562@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13563 /* dst <= regs xor IVs(in dst) */
13564 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13565
13566+ pax_force_retaddr
13567 ret;
13568 ENDPROC(cast6_xts_dec_8way)
13569diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13570index dbc4339..de6e120 100644
13571--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13572+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13573@@ -45,6 +45,7 @@
13574
13575 #include <asm/inst.h>
13576 #include <linux/linkage.h>
13577+#include <asm/alternative-asm.h>
13578
13579 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13580
13581@@ -312,6 +313,7 @@ do_return:
13582 popq %rsi
13583 popq %rdi
13584 popq %rbx
13585+ pax_force_retaddr
13586 ret
13587
13588 ################################################################
13589diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13590index 185fad4..ff4cd36 100644
13591--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13592+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13593@@ -18,6 +18,7 @@
13594
13595 #include <linux/linkage.h>
13596 #include <asm/inst.h>
13597+#include <asm/alternative-asm.h>
13598
13599 .data
13600
13601@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13602 psrlq $1, T2
13603 pxor T2, T1
13604 pxor T1, DATA
13605+ pax_force_retaddr
13606 ret
13607 ENDPROC(__clmul_gf128mul_ble)
13608
13609@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13610 call __clmul_gf128mul_ble
13611 PSHUFB_XMM BSWAP DATA
13612 movups DATA, (%rdi)
13613+ pax_force_retaddr
13614 ret
13615 ENDPROC(clmul_ghash_mul)
13616
13617@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13618 PSHUFB_XMM BSWAP DATA
13619 movups DATA, (%rdi)
13620 .Lupdate_just_ret:
13621+ pax_force_retaddr
13622 ret
13623 ENDPROC(clmul_ghash_update)
13624diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13625index 9279e0b..c4b3d2c 100644
13626--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13627+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13628@@ -1,4 +1,5 @@
13629 #include <linux/linkage.h>
13630+#include <asm/alternative-asm.h>
13631
13632 # enter salsa20_encrypt_bytes
13633 ENTRY(salsa20_encrypt_bytes)
13634@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13635 add %r11,%rsp
13636 mov %rdi,%rax
13637 mov %rsi,%rdx
13638+ pax_force_retaddr
13639 ret
13640 # bytesatleast65:
13641 ._bytesatleast65:
13642@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13643 add %r11,%rsp
13644 mov %rdi,%rax
13645 mov %rsi,%rdx
13646+ pax_force_retaddr
13647 ret
13648 ENDPROC(salsa20_keysetup)
13649
13650@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13651 add %r11,%rsp
13652 mov %rdi,%rax
13653 mov %rsi,%rdx
13654+ pax_force_retaddr
13655 ret
13656 ENDPROC(salsa20_ivsetup)
13657diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13658index 2f202f4..d9164d6 100644
13659--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13660+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13661@@ -24,6 +24,7 @@
13662 */
13663
13664 #include <linux/linkage.h>
13665+#include <asm/alternative-asm.h>
13666 #include "glue_helper-asm-avx.S"
13667
13668 .file "serpent-avx-x86_64-asm_64.S"
13669@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13670 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13671 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13672
13673+ pax_force_retaddr
13674 ret;
13675 ENDPROC(__serpent_enc_blk8_avx)
13676
13677@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13678 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13679 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13680
13681+ pax_force_retaddr
13682 ret;
13683 ENDPROC(__serpent_dec_blk8_avx)
13684
13685@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13686
13687 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13688
13689+ pax_force_retaddr
13690 ret;
13691 ENDPROC(serpent_ecb_enc_8way_avx)
13692
13693@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13694
13695 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13696
13697+ pax_force_retaddr
13698 ret;
13699 ENDPROC(serpent_ecb_dec_8way_avx)
13700
13701@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13702
13703 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13704
13705+ pax_force_retaddr
13706 ret;
13707 ENDPROC(serpent_cbc_dec_8way_avx)
13708
13709@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13710
13711 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13712
13713+ pax_force_retaddr
13714 ret;
13715 ENDPROC(serpent_ctr_8way_avx)
13716
13717@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13718 /* dst <= regs xor IVs(in dst) */
13719 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13720
13721+ pax_force_retaddr
13722 ret;
13723 ENDPROC(serpent_xts_enc_8way_avx)
13724
13725@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13726 /* dst <= regs xor IVs(in dst) */
13727 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13728
13729+ pax_force_retaddr
13730 ret;
13731 ENDPROC(serpent_xts_dec_8way_avx)
13732diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13733index b222085..abd483c 100644
13734--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13735+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13736@@ -15,6 +15,7 @@
13737 */
13738
13739 #include <linux/linkage.h>
13740+#include <asm/alternative-asm.h>
13741 #include "glue_helper-asm-avx2.S"
13742
13743 .file "serpent-avx2-asm_64.S"
13744@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13745 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13746 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13747
13748+ pax_force_retaddr
13749 ret;
13750 ENDPROC(__serpent_enc_blk16)
13751
13752@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13753 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13754 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13755
13756+ pax_force_retaddr
13757 ret;
13758 ENDPROC(__serpent_dec_blk16)
13759
13760@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13761
13762 vzeroupper;
13763
13764+ pax_force_retaddr
13765 ret;
13766 ENDPROC(serpent_ecb_enc_16way)
13767
13768@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13769
13770 vzeroupper;
13771
13772+ pax_force_retaddr
13773 ret;
13774 ENDPROC(serpent_ecb_dec_16way)
13775
13776@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13777
13778 vzeroupper;
13779
13780+ pax_force_retaddr
13781 ret;
13782 ENDPROC(serpent_cbc_dec_16way)
13783
13784@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13785
13786 vzeroupper;
13787
13788+ pax_force_retaddr
13789 ret;
13790 ENDPROC(serpent_ctr_16way)
13791
13792@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13793
13794 vzeroupper;
13795
13796+ pax_force_retaddr
13797 ret;
13798 ENDPROC(serpent_xts_enc_16way)
13799
13800@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13801
13802 vzeroupper;
13803
13804+ pax_force_retaddr
13805 ret;
13806 ENDPROC(serpent_xts_dec_16way)
13807diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13808index acc066c..1559cc4 100644
13809--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13810+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13811@@ -25,6 +25,7 @@
13812 */
13813
13814 #include <linux/linkage.h>
13815+#include <asm/alternative-asm.h>
13816
13817 .file "serpent-sse2-x86_64-asm_64.S"
13818 .text
13819@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13820 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13821 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13822
13823+ pax_force_retaddr
13824 ret;
13825
13826 .L__enc_xor8:
13827 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13828 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13829
13830+ pax_force_retaddr
13831 ret;
13832 ENDPROC(__serpent_enc_blk_8way)
13833
13834@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13835 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13836 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13837
13838+ pax_force_retaddr
13839 ret;
13840 ENDPROC(serpent_dec_blk_8way)
13841diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13842index a410950..9dfe7ad 100644
13843--- a/arch/x86/crypto/sha1_ssse3_asm.S
13844+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13845@@ -29,6 +29,7 @@
13846 */
13847
13848 #include <linux/linkage.h>
13849+#include <asm/alternative-asm.h>
13850
13851 #define CTX %rdi // arg1
13852 #define BUF %rsi // arg2
13853@@ -75,9 +76,9 @@
13854
13855 push %rbx
13856 push %rbp
13857- push %r12
13858+ push %r14
13859
13860- mov %rsp, %r12
13861+ mov %rsp, %r14
13862 sub $64, %rsp # allocate workspace
13863 and $~15, %rsp # align stack
13864
13865@@ -99,11 +100,12 @@
13866 xor %rax, %rax
13867 rep stosq
13868
13869- mov %r12, %rsp # deallocate workspace
13870+ mov %r14, %rsp # deallocate workspace
13871
13872- pop %r12
13873+ pop %r14
13874 pop %rbp
13875 pop %rbx
13876+ pax_force_retaddr
13877 ret
13878
13879 ENDPROC(\name)
13880diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13881index 642f156..51a513c 100644
13882--- a/arch/x86/crypto/sha256-avx-asm.S
13883+++ b/arch/x86/crypto/sha256-avx-asm.S
13884@@ -49,6 +49,7 @@
13885
13886 #ifdef CONFIG_AS_AVX
13887 #include <linux/linkage.h>
13888+#include <asm/alternative-asm.h>
13889
13890 ## assume buffers not aligned
13891 #define VMOVDQ vmovdqu
13892@@ -460,6 +461,7 @@ done_hash:
13893 popq %r13
13894 popq %rbp
13895 popq %rbx
13896+ pax_force_retaddr
13897 ret
13898 ENDPROC(sha256_transform_avx)
13899
13900diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13901index 9e86944..3795e6a 100644
13902--- a/arch/x86/crypto/sha256-avx2-asm.S
13903+++ b/arch/x86/crypto/sha256-avx2-asm.S
13904@@ -50,6 +50,7 @@
13905
13906 #ifdef CONFIG_AS_AVX2
13907 #include <linux/linkage.h>
13908+#include <asm/alternative-asm.h>
13909
13910 ## assume buffers not aligned
13911 #define VMOVDQ vmovdqu
13912@@ -720,6 +721,7 @@ done_hash:
13913 popq %r12
13914 popq %rbp
13915 popq %rbx
13916+ pax_force_retaddr
13917 ret
13918 ENDPROC(sha256_transform_rorx)
13919
13920diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13921index f833b74..8c62a9e 100644
13922--- a/arch/x86/crypto/sha256-ssse3-asm.S
13923+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13924@@ -47,6 +47,7 @@
13925 ########################################################################
13926
13927 #include <linux/linkage.h>
13928+#include <asm/alternative-asm.h>
13929
13930 ## assume buffers not aligned
13931 #define MOVDQ movdqu
13932@@ -471,6 +472,7 @@ done_hash:
13933 popq %rbp
13934 popq %rbx
13935
13936+ pax_force_retaddr
13937 ret
13938 ENDPROC(sha256_transform_ssse3)
13939
13940diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13941index 974dde9..a823ff9 100644
13942--- a/arch/x86/crypto/sha512-avx-asm.S
13943+++ b/arch/x86/crypto/sha512-avx-asm.S
13944@@ -49,6 +49,7 @@
13945
13946 #ifdef CONFIG_AS_AVX
13947 #include <linux/linkage.h>
13948+#include <asm/alternative-asm.h>
13949
13950 .text
13951
13952@@ -364,6 +365,7 @@ updateblock:
13953 mov frame_RSPSAVE(%rsp), %rsp
13954
13955 nowork:
13956+ pax_force_retaddr
13957 ret
13958 ENDPROC(sha512_transform_avx)
13959
13960diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13961index 568b961..ed20c37 100644
13962--- a/arch/x86/crypto/sha512-avx2-asm.S
13963+++ b/arch/x86/crypto/sha512-avx2-asm.S
13964@@ -51,6 +51,7 @@
13965
13966 #ifdef CONFIG_AS_AVX2
13967 #include <linux/linkage.h>
13968+#include <asm/alternative-asm.h>
13969
13970 .text
13971
13972@@ -678,6 +679,7 @@ done_hash:
13973
13974 # Restore Stack Pointer
13975 mov frame_RSPSAVE(%rsp), %rsp
13976+ pax_force_retaddr
13977 ret
13978 ENDPROC(sha512_transform_rorx)
13979
13980diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13981index fb56855..6edd768 100644
13982--- a/arch/x86/crypto/sha512-ssse3-asm.S
13983+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13984@@ -48,6 +48,7 @@
13985 ########################################################################
13986
13987 #include <linux/linkage.h>
13988+#include <asm/alternative-asm.h>
13989
13990 .text
13991
13992@@ -363,6 +364,7 @@ updateblock:
13993 mov frame_RSPSAVE(%rsp), %rsp
13994
13995 nowork:
13996+ pax_force_retaddr
13997 ret
13998 ENDPROC(sha512_transform_ssse3)
13999
14000diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14001index 0505813..b067311 100644
14002--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14003+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14004@@ -24,6 +24,7 @@
14005 */
14006
14007 #include <linux/linkage.h>
14008+#include <asm/alternative-asm.h>
14009 #include "glue_helper-asm-avx.S"
14010
14011 .file "twofish-avx-x86_64-asm_64.S"
14012@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14013 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14014 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14015
14016+ pax_force_retaddr
14017 ret;
14018 ENDPROC(__twofish_enc_blk8)
14019
14020@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14021 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14022 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14023
14024+ pax_force_retaddr
14025 ret;
14026 ENDPROC(__twofish_dec_blk8)
14027
14028@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14029
14030 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14031
14032+ pax_force_retaddr
14033 ret;
14034 ENDPROC(twofish_ecb_enc_8way)
14035
14036@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14037
14038 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14039
14040+ pax_force_retaddr
14041 ret;
14042 ENDPROC(twofish_ecb_dec_8way)
14043
14044@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14045 * %rdx: src
14046 */
14047
14048- pushq %r12;
14049+ pushq %r14;
14050
14051 movq %rsi, %r11;
14052- movq %rdx, %r12;
14053+ movq %rdx, %r14;
14054
14055 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14056
14057 call __twofish_dec_blk8;
14058
14059- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14060+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14061
14062- popq %r12;
14063+ popq %r14;
14064
14065+ pax_force_retaddr
14066 ret;
14067 ENDPROC(twofish_cbc_dec_8way)
14068
14069@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14070 * %rcx: iv (little endian, 128bit)
14071 */
14072
14073- pushq %r12;
14074+ pushq %r14;
14075
14076 movq %rsi, %r11;
14077- movq %rdx, %r12;
14078+ movq %rdx, %r14;
14079
14080 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14081 RD2, RX0, RX1, RY0);
14082
14083 call __twofish_enc_blk8;
14084
14085- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14086+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14087
14088- popq %r12;
14089+ popq %r14;
14090
14091+ pax_force_retaddr
14092 ret;
14093 ENDPROC(twofish_ctr_8way)
14094
14095@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14096 /* dst <= regs xor IVs(in dst) */
14097 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14098
14099+ pax_force_retaddr
14100 ret;
14101 ENDPROC(twofish_xts_enc_8way)
14102
14103@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14104 /* dst <= regs xor IVs(in dst) */
14105 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14106
14107+ pax_force_retaddr
14108 ret;
14109 ENDPROC(twofish_xts_dec_8way)
14110diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14111index 1c3b7ce..02f578d 100644
14112--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14113+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14114@@ -21,6 +21,7 @@
14115 */
14116
14117 #include <linux/linkage.h>
14118+#include <asm/alternative-asm.h>
14119
14120 .file "twofish-x86_64-asm-3way.S"
14121 .text
14122@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14123 popq %r13;
14124 popq %r14;
14125 popq %r15;
14126+ pax_force_retaddr
14127 ret;
14128
14129 .L__enc_xor3:
14130@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14131 popq %r13;
14132 popq %r14;
14133 popq %r15;
14134+ pax_force_retaddr
14135 ret;
14136 ENDPROC(__twofish_enc_blk_3way)
14137
14138@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14139 popq %r13;
14140 popq %r14;
14141 popq %r15;
14142+ pax_force_retaddr
14143 ret;
14144 ENDPROC(twofish_dec_blk_3way)
14145diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14146index a039d21..524b8b2 100644
14147--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14148+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14149@@ -22,6 +22,7 @@
14150
14151 #include <linux/linkage.h>
14152 #include <asm/asm-offsets.h>
14153+#include <asm/alternative-asm.h>
14154
14155 #define a_offset 0
14156 #define b_offset 4
14157@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14158
14159 popq R1
14160 movq $1,%rax
14161+ pax_force_retaddr
14162 ret
14163 ENDPROC(twofish_enc_blk)
14164
14165@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14166
14167 popq R1
14168 movq $1,%rax
14169+ pax_force_retaddr
14170 ret
14171 ENDPROC(twofish_dec_blk)
14172diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14173index d21ff89..6da8e6e 100644
14174--- a/arch/x86/ia32/ia32_aout.c
14175+++ b/arch/x86/ia32/ia32_aout.c
14176@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14177 unsigned long dump_start, dump_size;
14178 struct user32 dump;
14179
14180+ memset(&dump, 0, sizeof(dump));
14181+
14182 fs = get_fs();
14183 set_fs(KERNEL_DS);
14184 has_dumped = 1;
14185diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14186index 2206757..85cbcfa 100644
14187--- a/arch/x86/ia32/ia32_signal.c
14188+++ b/arch/x86/ia32/ia32_signal.c
14189@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14190 if (__get_user(set.sig[0], &frame->sc.oldmask)
14191 || (_COMPAT_NSIG_WORDS > 1
14192 && __copy_from_user((((char *) &set.sig) + 4),
14193- &frame->extramask,
14194+ frame->extramask,
14195 sizeof(frame->extramask))))
14196 goto badframe;
14197
14198@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14199 sp -= frame_size;
14200 /* Align the stack pointer according to the i386 ABI,
14201 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14202- sp = ((sp + 4) & -16ul) - 4;
14203+ sp = ((sp - 12) & -16ul) - 4;
14204 return (void __user *) sp;
14205 }
14206
14207@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14208 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14209 sigreturn);
14210 else
14211- restorer = &frame->retcode;
14212+ restorer = frame->retcode;
14213 }
14214
14215 put_user_try {
14216@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14217 * These are actually not used anymore, but left because some
14218 * gdb versions depend on them as a marker.
14219 */
14220- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14221+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14222 } put_user_catch(err);
14223
14224 if (err)
14225@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14226 0xb8,
14227 __NR_ia32_rt_sigreturn,
14228 0x80cd,
14229- 0,
14230+ 0
14231 };
14232
14233 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14234@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14235
14236 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14237 restorer = ksig->ka.sa.sa_restorer;
14238+ else if (current->mm->context.vdso)
14239+ /* Return stub is in 32bit vsyscall page */
14240+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14241 else
14242- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14243- rt_sigreturn);
14244+ restorer = frame->retcode;
14245 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14246
14247 /*
14248 * Not actually used anymore, but left because some gdb
14249 * versions need it.
14250 */
14251- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14252+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14253 } put_user_catch(err);
14254
14255 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14256diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14257index 4299eb0..c0687a7 100644
14258--- a/arch/x86/ia32/ia32entry.S
14259+++ b/arch/x86/ia32/ia32entry.S
14260@@ -15,8 +15,10 @@
14261 #include <asm/irqflags.h>
14262 #include <asm/asm.h>
14263 #include <asm/smap.h>
14264+#include <asm/pgtable.h>
14265 #include <linux/linkage.h>
14266 #include <linux/err.h>
14267+#include <asm/alternative-asm.h>
14268
14269 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14270 #include <linux/elf-em.h>
14271@@ -62,12 +64,12 @@
14272 */
14273 .macro LOAD_ARGS32 offset, _r9=0
14274 .if \_r9
14275- movl \offset+16(%rsp),%r9d
14276+ movl \offset+R9(%rsp),%r9d
14277 .endif
14278- movl \offset+40(%rsp),%ecx
14279- movl \offset+48(%rsp),%edx
14280- movl \offset+56(%rsp),%esi
14281- movl \offset+64(%rsp),%edi
14282+ movl \offset+RCX(%rsp),%ecx
14283+ movl \offset+RDX(%rsp),%edx
14284+ movl \offset+RSI(%rsp),%esi
14285+ movl \offset+RDI(%rsp),%edi
14286 movl %eax,%eax /* zero extension */
14287 .endm
14288
14289@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14290 ENDPROC(native_irq_enable_sysexit)
14291 #endif
14292
14293+ .macro pax_enter_kernel_user
14294+ pax_set_fptr_mask
14295+#ifdef CONFIG_PAX_MEMORY_UDEREF
14296+ call pax_enter_kernel_user
14297+#endif
14298+ .endm
14299+
14300+ .macro pax_exit_kernel_user
14301+#ifdef CONFIG_PAX_MEMORY_UDEREF
14302+ call pax_exit_kernel_user
14303+#endif
14304+#ifdef CONFIG_PAX_RANDKSTACK
14305+ pushq %rax
14306+ pushq %r11
14307+ call pax_randomize_kstack
14308+ popq %r11
14309+ popq %rax
14310+#endif
14311+ .endm
14312+
14313+ .macro pax_erase_kstack
14314+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14315+ call pax_erase_kstack
14316+#endif
14317+ .endm
14318+
14319 /*
14320 * 32bit SYSENTER instruction entry.
14321 *
14322@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14323 CFI_REGISTER rsp,rbp
14324 SWAPGS_UNSAFE_STACK
14325 movq PER_CPU_VAR(kernel_stack), %rsp
14326- addq $(KERNEL_STACK_OFFSET),%rsp
14327- /*
14328- * No need to follow this irqs on/off section: the syscall
14329- * disabled irqs, here we enable it straight after entry:
14330- */
14331- ENABLE_INTERRUPTS(CLBR_NONE)
14332 movl %ebp,%ebp /* zero extension */
14333 pushq_cfi $__USER32_DS
14334 /*CFI_REL_OFFSET ss,0*/
14335@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14336 CFI_REL_OFFSET rsp,0
14337 pushfq_cfi
14338 /*CFI_REL_OFFSET rflags,0*/
14339- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14340- CFI_REGISTER rip,r10
14341+ orl $X86_EFLAGS_IF,(%rsp)
14342+ GET_THREAD_INFO(%r11)
14343+ movl TI_sysenter_return(%r11), %r11d
14344+ CFI_REGISTER rip,r11
14345 pushq_cfi $__USER32_CS
14346 /*CFI_REL_OFFSET cs,0*/
14347 movl %eax, %eax
14348- pushq_cfi %r10
14349+ pushq_cfi %r11
14350 CFI_REL_OFFSET rip,0
14351 pushq_cfi %rax
14352 cld
14353 SAVE_ARGS 0,1,0
14354+ pax_enter_kernel_user
14355+
14356+#ifdef CONFIG_PAX_RANDKSTACK
14357+ pax_erase_kstack
14358+#endif
14359+
14360+ /*
14361+ * No need to follow this irqs on/off section: the syscall
14362+ * disabled irqs, here we enable it straight after entry:
14363+ */
14364+ ENABLE_INTERRUPTS(CLBR_NONE)
14365 /* no need to do an access_ok check here because rbp has been
14366 32bit zero extended */
14367+
14368+#ifdef CONFIG_PAX_MEMORY_UDEREF
14369+ addq pax_user_shadow_base,%rbp
14370+ ASM_PAX_OPEN_USERLAND
14371+#endif
14372+
14373 ASM_STAC
14374 1: movl (%rbp),%ebp
14375 _ASM_EXTABLE(1b,ia32_badarg)
14376 ASM_CLAC
14377- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14378- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14379+
14380+#ifdef CONFIG_PAX_MEMORY_UDEREF
14381+ ASM_PAX_CLOSE_USERLAND
14382+#endif
14383+
14384+ GET_THREAD_INFO(%r11)
14385+ orl $TS_COMPAT,TI_status(%r11)
14386+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14387 CFI_REMEMBER_STATE
14388 jnz sysenter_tracesys
14389 cmpq $(IA32_NR_syscalls-1),%rax
14390@@ -162,15 +209,18 @@ sysenter_do_call:
14391 sysenter_dispatch:
14392 call *ia32_sys_call_table(,%rax,8)
14393 movq %rax,RAX-ARGOFFSET(%rsp)
14394+ GET_THREAD_INFO(%r11)
14395 DISABLE_INTERRUPTS(CLBR_NONE)
14396 TRACE_IRQS_OFF
14397- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14398+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14399 jnz sysexit_audit
14400 sysexit_from_sys_call:
14401- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14402+ pax_exit_kernel_user
14403+ pax_erase_kstack
14404+ andl $~TS_COMPAT,TI_status(%r11)
14405 /* clear IF, that popfq doesn't enable interrupts early */
14406- andl $~0x200,EFLAGS-R11(%rsp)
14407- movl RIP-R11(%rsp),%edx /* User %eip */
14408+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14409+ movl RIP(%rsp),%edx /* User %eip */
14410 CFI_REGISTER rip,rdx
14411 RESTORE_ARGS 0,24,0,0,0,0
14412 xorq %r8,%r8
14413@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14414 movl %eax,%esi /* 2nd arg: syscall number */
14415 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14416 call __audit_syscall_entry
14417+
14418+ pax_erase_kstack
14419+
14420 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14421 cmpq $(IA32_NR_syscalls-1),%rax
14422 ja ia32_badsys
14423@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14424 .endm
14425
14426 .macro auditsys_exit exit
14427- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14428+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14429 jnz ia32_ret_from_sys_call
14430 TRACE_IRQS_ON
14431 ENABLE_INTERRUPTS(CLBR_NONE)
14432@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14433 1: setbe %al /* 1 if error, 0 if not */
14434 movzbl %al,%edi /* zero-extend that into %edi */
14435 call __audit_syscall_exit
14436+ GET_THREAD_INFO(%r11)
14437 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14438 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14439 DISABLE_INTERRUPTS(CLBR_NONE)
14440 TRACE_IRQS_OFF
14441- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14442+ testl %edi,TI_flags(%r11)
14443 jz \exit
14444 CLEAR_RREGS -ARGOFFSET
14445 jmp int_with_check
14446@@ -237,7 +291,7 @@ sysexit_audit:
14447
14448 sysenter_tracesys:
14449 #ifdef CONFIG_AUDITSYSCALL
14450- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14451+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14452 jz sysenter_auditsys
14453 #endif
14454 SAVE_REST
14455@@ -249,6 +303,9 @@ sysenter_tracesys:
14456 RESTORE_REST
14457 cmpq $(IA32_NR_syscalls-1),%rax
14458 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14459+
14460+ pax_erase_kstack
14461+
14462 jmp sysenter_do_call
14463 CFI_ENDPROC
14464 ENDPROC(ia32_sysenter_target)
14465@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14466 ENTRY(ia32_cstar_target)
14467 CFI_STARTPROC32 simple
14468 CFI_SIGNAL_FRAME
14469- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14470+ CFI_DEF_CFA rsp,0
14471 CFI_REGISTER rip,rcx
14472 /*CFI_REGISTER rflags,r11*/
14473 SWAPGS_UNSAFE_STACK
14474 movl %esp,%r8d
14475 CFI_REGISTER rsp,r8
14476 movq PER_CPU_VAR(kernel_stack),%rsp
14477+ SAVE_ARGS 8*6,0,0
14478+ pax_enter_kernel_user
14479+
14480+#ifdef CONFIG_PAX_RANDKSTACK
14481+ pax_erase_kstack
14482+#endif
14483+
14484 /*
14485 * No need to follow this irqs on/off section: the syscall
14486 * disabled irqs and here we enable it straight after entry:
14487 */
14488 ENABLE_INTERRUPTS(CLBR_NONE)
14489- SAVE_ARGS 8,0,0
14490 movl %eax,%eax /* zero extension */
14491 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14492 movq %rcx,RIP-ARGOFFSET(%rsp)
14493@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14494 /* no need to do an access_ok check here because r8 has been
14495 32bit zero extended */
14496 /* hardware stack frame is complete now */
14497+
14498+#ifdef CONFIG_PAX_MEMORY_UDEREF
14499+ ASM_PAX_OPEN_USERLAND
14500+ movq pax_user_shadow_base,%r8
14501+ addq RSP-ARGOFFSET(%rsp),%r8
14502+#endif
14503+
14504 ASM_STAC
14505 1: movl (%r8),%r9d
14506 _ASM_EXTABLE(1b,ia32_badarg)
14507 ASM_CLAC
14508- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14509- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14510+
14511+#ifdef CONFIG_PAX_MEMORY_UDEREF
14512+ ASM_PAX_CLOSE_USERLAND
14513+#endif
14514+
14515+ GET_THREAD_INFO(%r11)
14516+ orl $TS_COMPAT,TI_status(%r11)
14517+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14518 CFI_REMEMBER_STATE
14519 jnz cstar_tracesys
14520 cmpq $IA32_NR_syscalls-1,%rax
14521@@ -319,13 +395,16 @@ cstar_do_call:
14522 cstar_dispatch:
14523 call *ia32_sys_call_table(,%rax,8)
14524 movq %rax,RAX-ARGOFFSET(%rsp)
14525+ GET_THREAD_INFO(%r11)
14526 DISABLE_INTERRUPTS(CLBR_NONE)
14527 TRACE_IRQS_OFF
14528- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14529+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14530 jnz sysretl_audit
14531 sysretl_from_sys_call:
14532- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14533- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14534+ pax_exit_kernel_user
14535+ pax_erase_kstack
14536+ andl $~TS_COMPAT,TI_status(%r11)
14537+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14538 movl RIP-ARGOFFSET(%rsp),%ecx
14539 CFI_REGISTER rip,rcx
14540 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14541@@ -352,7 +431,7 @@ sysretl_audit:
14542
14543 cstar_tracesys:
14544 #ifdef CONFIG_AUDITSYSCALL
14545- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14546+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14547 jz cstar_auditsys
14548 #endif
14549 xchgl %r9d,%ebp
14550@@ -366,11 +445,19 @@ cstar_tracesys:
14551 xchgl %ebp,%r9d
14552 cmpq $(IA32_NR_syscalls-1),%rax
14553 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14554+
14555+ pax_erase_kstack
14556+
14557 jmp cstar_do_call
14558 END(ia32_cstar_target)
14559
14560 ia32_badarg:
14561 ASM_CLAC
14562+
14563+#ifdef CONFIG_PAX_MEMORY_UDEREF
14564+ ASM_PAX_CLOSE_USERLAND
14565+#endif
14566+
14567 movq $-EFAULT,%rax
14568 jmp ia32_sysret
14569 CFI_ENDPROC
14570@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14571 CFI_REL_OFFSET rip,RIP-RIP
14572 PARAVIRT_ADJUST_EXCEPTION_FRAME
14573 SWAPGS
14574- /*
14575- * No need to follow this irqs on/off section: the syscall
14576- * disabled irqs and here we enable it straight after entry:
14577- */
14578- ENABLE_INTERRUPTS(CLBR_NONE)
14579 movl %eax,%eax
14580 pushq_cfi %rax
14581 cld
14582 /* note the registers are not zero extended to the sf.
14583 this could be a problem. */
14584 SAVE_ARGS 0,1,0
14585- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14586- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587+ pax_enter_kernel_user
14588+
14589+#ifdef CONFIG_PAX_RANDKSTACK
14590+ pax_erase_kstack
14591+#endif
14592+
14593+ /*
14594+ * No need to follow this irqs on/off section: the syscall
14595+ * disabled irqs and here we enable it straight after entry:
14596+ */
14597+ ENABLE_INTERRUPTS(CLBR_NONE)
14598+ GET_THREAD_INFO(%r11)
14599+ orl $TS_COMPAT,TI_status(%r11)
14600+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14601 jnz ia32_tracesys
14602 cmpq $(IA32_NR_syscalls-1),%rax
14603 ja ia32_badsys
14604@@ -442,6 +536,9 @@ ia32_tracesys:
14605 RESTORE_REST
14606 cmpq $(IA32_NR_syscalls-1),%rax
14607 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14608+
14609+ pax_erase_kstack
14610+
14611 jmp ia32_do_call
14612 END(ia32_syscall)
14613
14614diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14615index 8e0ceec..af13504 100644
14616--- a/arch/x86/ia32/sys_ia32.c
14617+++ b/arch/x86/ia32/sys_ia32.c
14618@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14619 */
14620 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14621 {
14622- typeof(ubuf->st_uid) uid = 0;
14623- typeof(ubuf->st_gid) gid = 0;
14624+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14625+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14626 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14627 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14628 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14629diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14630index 372231c..51b537d 100644
14631--- a/arch/x86/include/asm/alternative-asm.h
14632+++ b/arch/x86/include/asm/alternative-asm.h
14633@@ -18,6 +18,45 @@
14634 .endm
14635 #endif
14636
14637+#ifdef KERNEXEC_PLUGIN
14638+ .macro pax_force_retaddr_bts rip=0
14639+ btsq $63,\rip(%rsp)
14640+ .endm
14641+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14642+ .macro pax_force_retaddr rip=0, reload=0
14643+ btsq $63,\rip(%rsp)
14644+ .endm
14645+ .macro pax_force_fptr ptr
14646+ btsq $63,\ptr
14647+ .endm
14648+ .macro pax_set_fptr_mask
14649+ .endm
14650+#endif
14651+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14652+ .macro pax_force_retaddr rip=0, reload=0
14653+ .if \reload
14654+ pax_set_fptr_mask
14655+ .endif
14656+ orq %r12,\rip(%rsp)
14657+ .endm
14658+ .macro pax_force_fptr ptr
14659+ orq %r12,\ptr
14660+ .endm
14661+ .macro pax_set_fptr_mask
14662+ movabs $0x8000000000000000,%r12
14663+ .endm
14664+#endif
14665+#else
14666+ .macro pax_force_retaddr rip=0, reload=0
14667+ .endm
14668+ .macro pax_force_fptr ptr
14669+ .endm
14670+ .macro pax_force_retaddr_bts rip=0
14671+ .endm
14672+ .macro pax_set_fptr_mask
14673+ .endm
14674+#endif
14675+
14676 .macro altinstruction_entry orig alt feature orig_len alt_len
14677 .long \orig - .
14678 .long \alt - .
14679diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14680index 0a3f9c9..c9d081d 100644
14681--- a/arch/x86/include/asm/alternative.h
14682+++ b/arch/x86/include/asm/alternative.h
14683@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14684 ".pushsection .discard,\"aw\",@progbits\n" \
14685 DISCARD_ENTRY(1) \
14686 ".popsection\n" \
14687- ".pushsection .altinstr_replacement, \"ax\"\n" \
14688+ ".pushsection .altinstr_replacement, \"a\"\n" \
14689 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14690 ".popsection"
14691
14692@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14693 DISCARD_ENTRY(1) \
14694 DISCARD_ENTRY(2) \
14695 ".popsection\n" \
14696- ".pushsection .altinstr_replacement, \"ax\"\n" \
14697+ ".pushsection .altinstr_replacement, \"a\"\n" \
14698 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14699 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14700 ".popsection"
14701diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14702index 1d2091a..f5074c1 100644
14703--- a/arch/x86/include/asm/apic.h
14704+++ b/arch/x86/include/asm/apic.h
14705@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14706
14707 #ifdef CONFIG_X86_LOCAL_APIC
14708
14709-extern unsigned int apic_verbosity;
14710+extern int apic_verbosity;
14711 extern int local_apic_timer_c2_ok;
14712
14713 extern int disable_apic;
14714diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14715index 20370c6..a2eb9b0 100644
14716--- a/arch/x86/include/asm/apm.h
14717+++ b/arch/x86/include/asm/apm.h
14718@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14719 __asm__ __volatile__(APM_DO_ZERO_SEGS
14720 "pushl %%edi\n\t"
14721 "pushl %%ebp\n\t"
14722- "lcall *%%cs:apm_bios_entry\n\t"
14723+ "lcall *%%ss:apm_bios_entry\n\t"
14724 "setc %%al\n\t"
14725 "popl %%ebp\n\t"
14726 "popl %%edi\n\t"
14727@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14728 __asm__ __volatile__(APM_DO_ZERO_SEGS
14729 "pushl %%edi\n\t"
14730 "pushl %%ebp\n\t"
14731- "lcall *%%cs:apm_bios_entry\n\t"
14732+ "lcall *%%ss:apm_bios_entry\n\t"
14733 "setc %%bl\n\t"
14734 "popl %%ebp\n\t"
14735 "popl %%edi\n\t"
14736diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14737index b17f4f4..9620151 100644
14738--- a/arch/x86/include/asm/atomic.h
14739+++ b/arch/x86/include/asm/atomic.h
14740@@ -23,7 +23,18 @@
14741 */
14742 static inline int atomic_read(const atomic_t *v)
14743 {
14744- return (*(volatile int *)&(v)->counter);
14745+ return (*(volatile const int *)&(v)->counter);
14746+}
14747+
14748+/**
14749+ * atomic_read_unchecked - read atomic variable
14750+ * @v: pointer of type atomic_unchecked_t
14751+ *
14752+ * Atomically reads the value of @v.
14753+ */
14754+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14755+{
14756+ return (*(volatile const int *)&(v)->counter);
14757 }
14758
14759 /**
14760@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14761 }
14762
14763 /**
14764+ * atomic_set_unchecked - set atomic variable
14765+ * @v: pointer of type atomic_unchecked_t
14766+ * @i: required value
14767+ *
14768+ * Atomically sets the value of @v to @i.
14769+ */
14770+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14771+{
14772+ v->counter = i;
14773+}
14774+
14775+/**
14776 * atomic_add - add integer to atomic variable
14777 * @i: integer value to add
14778 * @v: pointer of type atomic_t
14779@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14780 */
14781 static inline void atomic_add(int i, atomic_t *v)
14782 {
14783- asm volatile(LOCK_PREFIX "addl %1,%0"
14784+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14785+
14786+#ifdef CONFIG_PAX_REFCOUNT
14787+ "jno 0f\n"
14788+ LOCK_PREFIX "subl %1,%0\n"
14789+ "int $4\n0:\n"
14790+ _ASM_EXTABLE(0b, 0b)
14791+#endif
14792+
14793+ : "+m" (v->counter)
14794+ : "ir" (i));
14795+}
14796+
14797+/**
14798+ * atomic_add_unchecked - add integer to atomic variable
14799+ * @i: integer value to add
14800+ * @v: pointer of type atomic_unchecked_t
14801+ *
14802+ * Atomically adds @i to @v.
14803+ */
14804+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14805+{
14806+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14807 : "+m" (v->counter)
14808 : "ir" (i));
14809 }
14810@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14811 */
14812 static inline void atomic_sub(int i, atomic_t *v)
14813 {
14814- asm volatile(LOCK_PREFIX "subl %1,%0"
14815+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14816+
14817+#ifdef CONFIG_PAX_REFCOUNT
14818+ "jno 0f\n"
14819+ LOCK_PREFIX "addl %1,%0\n"
14820+ "int $4\n0:\n"
14821+ _ASM_EXTABLE(0b, 0b)
14822+#endif
14823+
14824+ : "+m" (v->counter)
14825+ : "ir" (i));
14826+}
14827+
14828+/**
14829+ * atomic_sub_unchecked - subtract integer from atomic variable
14830+ * @i: integer value to subtract
14831+ * @v: pointer of type atomic_unchecked_t
14832+ *
14833+ * Atomically subtracts @i from @v.
14834+ */
14835+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14836+{
14837+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14838 : "+m" (v->counter)
14839 : "ir" (i));
14840 }
14841@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14842 */
14843 static inline int atomic_sub_and_test(int i, atomic_t *v)
14844 {
14845- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14846+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14847 }
14848
14849 /**
14850@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14851 */
14852 static inline void atomic_inc(atomic_t *v)
14853 {
14854- asm volatile(LOCK_PREFIX "incl %0"
14855+ asm volatile(LOCK_PREFIX "incl %0\n"
14856+
14857+#ifdef CONFIG_PAX_REFCOUNT
14858+ "jno 0f\n"
14859+ LOCK_PREFIX "decl %0\n"
14860+ "int $4\n0:\n"
14861+ _ASM_EXTABLE(0b, 0b)
14862+#endif
14863+
14864+ : "+m" (v->counter));
14865+}
14866+
14867+/**
14868+ * atomic_inc_unchecked - increment atomic variable
14869+ * @v: pointer of type atomic_unchecked_t
14870+ *
14871+ * Atomically increments @v by 1.
14872+ */
14873+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14874+{
14875+ asm volatile(LOCK_PREFIX "incl %0\n"
14876 : "+m" (v->counter));
14877 }
14878
14879@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14880 */
14881 static inline void atomic_dec(atomic_t *v)
14882 {
14883- asm volatile(LOCK_PREFIX "decl %0"
14884+ asm volatile(LOCK_PREFIX "decl %0\n"
14885+
14886+#ifdef CONFIG_PAX_REFCOUNT
14887+ "jno 0f\n"
14888+ LOCK_PREFIX "incl %0\n"
14889+ "int $4\n0:\n"
14890+ _ASM_EXTABLE(0b, 0b)
14891+#endif
14892+
14893+ : "+m" (v->counter));
14894+}
14895+
14896+/**
14897+ * atomic_dec_unchecked - decrement atomic variable
14898+ * @v: pointer of type atomic_unchecked_t
14899+ *
14900+ * Atomically decrements @v by 1.
14901+ */
14902+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14903+{
14904+ asm volatile(LOCK_PREFIX "decl %0\n"
14905 : "+m" (v->counter));
14906 }
14907
14908@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14909 */
14910 static inline int atomic_dec_and_test(atomic_t *v)
14911 {
14912- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14913+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14914 }
14915
14916 /**
14917@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14918 */
14919 static inline int atomic_inc_and_test(atomic_t *v)
14920 {
14921- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14922+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14923+}
14924+
14925+/**
14926+ * atomic_inc_and_test_unchecked - increment and test
14927+ * @v: pointer of type atomic_unchecked_t
14928+ *
14929+ * Atomically increments @v by 1
14930+ * and returns true if the result is zero, or false for all
14931+ * other cases.
14932+ */
14933+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14934+{
14935+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14936 }
14937
14938 /**
14939@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14940 */
14941 static inline int atomic_add_negative(int i, atomic_t *v)
14942 {
14943- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14944+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14945 }
14946
14947 /**
14948@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14949 */
14950 static inline int atomic_add_return(int i, atomic_t *v)
14951 {
14952+ return i + xadd_check_overflow(&v->counter, i);
14953+}
14954+
14955+/**
14956+ * atomic_add_return_unchecked - add integer and return
14957+ * @i: integer value to add
14958+ * @v: pointer of type atomic_unchecked_t
14959+ *
14960+ * Atomically adds @i to @v and returns @i + @v
14961+ */
14962+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14963+{
14964 return i + xadd(&v->counter, i);
14965 }
14966
14967@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14968 }
14969
14970 #define atomic_inc_return(v) (atomic_add_return(1, v))
14971+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14972+{
14973+ return atomic_add_return_unchecked(1, v);
14974+}
14975 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14976
14977-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14978+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14979+{
14980+ return cmpxchg(&v->counter, old, new);
14981+}
14982+
14983+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14984 {
14985 return cmpxchg(&v->counter, old, new);
14986 }
14987@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14988 return xchg(&v->counter, new);
14989 }
14990
14991+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14992+{
14993+ return xchg(&v->counter, new);
14994+}
14995+
14996 /**
14997 * __atomic_add_unless - add unless the number is already a given value
14998 * @v: pointer of type atomic_t
14999@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15000 * Atomically adds @a to @v, so long as @v was not already @u.
15001 * Returns the old value of @v.
15002 */
15003-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15004+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15005 {
15006- int c, old;
15007+ int c, old, new;
15008 c = atomic_read(v);
15009 for (;;) {
15010- if (unlikely(c == (u)))
15011+ if (unlikely(c == u))
15012 break;
15013- old = atomic_cmpxchg((v), c, c + (a));
15014+
15015+ asm volatile("addl %2,%0\n"
15016+
15017+#ifdef CONFIG_PAX_REFCOUNT
15018+ "jno 0f\n"
15019+ "subl %2,%0\n"
15020+ "int $4\n0:\n"
15021+ _ASM_EXTABLE(0b, 0b)
15022+#endif
15023+
15024+ : "=r" (new)
15025+ : "0" (c), "ir" (a));
15026+
15027+ old = atomic_cmpxchg(v, c, new);
15028 if (likely(old == c))
15029 break;
15030 c = old;
15031@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15032 }
15033
15034 /**
15035+ * atomic_inc_not_zero_hint - increment if not null
15036+ * @v: pointer of type atomic_t
15037+ * @hint: probable value of the atomic before the increment
15038+ *
15039+ * This version of atomic_inc_not_zero() gives a hint of probable
15040+ * value of the atomic. This helps processor to not read the memory
15041+ * before doing the atomic read/modify/write cycle, lowering
15042+ * number of bus transactions on some arches.
15043+ *
15044+ * Returns: 0 if increment was not done, 1 otherwise.
15045+ */
15046+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15047+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15048+{
15049+ int val, c = hint, new;
15050+
15051+ /* sanity test, should be removed by compiler if hint is a constant */
15052+ if (!hint)
15053+ return __atomic_add_unless(v, 1, 0);
15054+
15055+ do {
15056+ asm volatile("incl %0\n"
15057+
15058+#ifdef CONFIG_PAX_REFCOUNT
15059+ "jno 0f\n"
15060+ "decl %0\n"
15061+ "int $4\n0:\n"
15062+ _ASM_EXTABLE(0b, 0b)
15063+#endif
15064+
15065+ : "=r" (new)
15066+ : "0" (c));
15067+
15068+ val = atomic_cmpxchg(v, c, new);
15069+ if (val == c)
15070+ return 1;
15071+ c = val;
15072+ } while (c);
15073+
15074+ return 0;
15075+}
15076+
15077+/**
15078 * atomic_inc_short - increment of a short integer
15079 * @v: pointer to type int
15080 *
15081@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15082 #endif
15083
15084 /* These are x86-specific, used by some header files */
15085-#define atomic_clear_mask(mask, addr) \
15086- asm volatile(LOCK_PREFIX "andl %0,%1" \
15087- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15088+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15089+{
15090+ asm volatile(LOCK_PREFIX "andl %1,%0"
15091+ : "+m" (v->counter)
15092+ : "r" (~(mask))
15093+ : "memory");
15094+}
15095
15096-#define atomic_set_mask(mask, addr) \
15097- asm volatile(LOCK_PREFIX "orl %0,%1" \
15098- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15099- : "memory")
15100+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15101+{
15102+ asm volatile(LOCK_PREFIX "andl %1,%0"
15103+ : "+m" (v->counter)
15104+ : "r" (~(mask))
15105+ : "memory");
15106+}
15107+
15108+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15109+{
15110+ asm volatile(LOCK_PREFIX "orl %1,%0"
15111+ : "+m" (v->counter)
15112+ : "r" (mask)
15113+ : "memory");
15114+}
15115+
15116+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15117+{
15118+ asm volatile(LOCK_PREFIX "orl %1,%0"
15119+ : "+m" (v->counter)
15120+ : "r" (mask)
15121+ : "memory");
15122+}
15123
15124 /* Atomic operations are already serializing on x86 */
15125 #define smp_mb__before_atomic_dec() barrier()
15126diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15127index b154de7..bf18a5a 100644
15128--- a/arch/x86/include/asm/atomic64_32.h
15129+++ b/arch/x86/include/asm/atomic64_32.h
15130@@ -12,6 +12,14 @@ typedef struct {
15131 u64 __aligned(8) counter;
15132 } atomic64_t;
15133
15134+#ifdef CONFIG_PAX_REFCOUNT
15135+typedef struct {
15136+ u64 __aligned(8) counter;
15137+} atomic64_unchecked_t;
15138+#else
15139+typedef atomic64_t atomic64_unchecked_t;
15140+#endif
15141+
15142 #define ATOMIC64_INIT(val) { (val) }
15143
15144 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15145@@ -37,21 +45,31 @@ typedef struct {
15146 ATOMIC64_DECL_ONE(sym##_386)
15147
15148 ATOMIC64_DECL_ONE(add_386);
15149+ATOMIC64_DECL_ONE(add_unchecked_386);
15150 ATOMIC64_DECL_ONE(sub_386);
15151+ATOMIC64_DECL_ONE(sub_unchecked_386);
15152 ATOMIC64_DECL_ONE(inc_386);
15153+ATOMIC64_DECL_ONE(inc_unchecked_386);
15154 ATOMIC64_DECL_ONE(dec_386);
15155+ATOMIC64_DECL_ONE(dec_unchecked_386);
15156 #endif
15157
15158 #define alternative_atomic64(f, out, in...) \
15159 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15160
15161 ATOMIC64_DECL(read);
15162+ATOMIC64_DECL(read_unchecked);
15163 ATOMIC64_DECL(set);
15164+ATOMIC64_DECL(set_unchecked);
15165 ATOMIC64_DECL(xchg);
15166 ATOMIC64_DECL(add_return);
15167+ATOMIC64_DECL(add_return_unchecked);
15168 ATOMIC64_DECL(sub_return);
15169+ATOMIC64_DECL(sub_return_unchecked);
15170 ATOMIC64_DECL(inc_return);
15171+ATOMIC64_DECL(inc_return_unchecked);
15172 ATOMIC64_DECL(dec_return);
15173+ATOMIC64_DECL(dec_return_unchecked);
15174 ATOMIC64_DECL(dec_if_positive);
15175 ATOMIC64_DECL(inc_not_zero);
15176 ATOMIC64_DECL(add_unless);
15177@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15178 }
15179
15180 /**
15181+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15182+ * @p: pointer to type atomic64_unchecked_t
15183+ * @o: expected value
15184+ * @n: new value
15185+ *
15186+ * Atomically sets @v to @n if it was equal to @o and returns
15187+ * the old value.
15188+ */
15189+
15190+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15191+{
15192+ return cmpxchg64(&v->counter, o, n);
15193+}
15194+
15195+/**
15196 * atomic64_xchg - xchg atomic64 variable
15197 * @v: pointer to type atomic64_t
15198 * @n: value to assign
15199@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15200 }
15201
15202 /**
15203+ * atomic64_set_unchecked - set atomic64 variable
15204+ * @v: pointer to type atomic64_unchecked_t
15205+ * @n: value to assign
15206+ *
15207+ * Atomically sets the value of @v to @n.
15208+ */
15209+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15210+{
15211+ unsigned high = (unsigned)(i >> 32);
15212+ unsigned low = (unsigned)i;
15213+ alternative_atomic64(set, /* no output */,
15214+ "S" (v), "b" (low), "c" (high)
15215+ : "eax", "edx", "memory");
15216+}
15217+
15218+/**
15219 * atomic64_read - read atomic64 variable
15220 * @v: pointer to type atomic64_t
15221 *
15222@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15223 }
15224
15225 /**
15226+ * atomic64_read_unchecked - read atomic64 variable
15227+ * @v: pointer to type atomic64_unchecked_t
15228+ *
15229+ * Atomically reads the value of @v and returns it.
15230+ */
15231+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15232+{
15233+ long long r;
15234+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15235+ return r;
15236+ }
15237+
15238+/**
15239 * atomic64_add_return - add and return
15240 * @i: integer value to add
15241 * @v: pointer to type atomic64_t
15242@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15243 return i;
15244 }
15245
15246+/**
15247+ * atomic64_add_return_unchecked - add and return
15248+ * @i: integer value to add
15249+ * @v: pointer to type atomic64_unchecked_t
15250+ *
15251+ * Atomically adds @i to @v and returns @i + *@v
15252+ */
15253+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15254+{
15255+ alternative_atomic64(add_return_unchecked,
15256+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15257+ ASM_NO_INPUT_CLOBBER("memory"));
15258+ return i;
15259+}
15260+
15261 /*
15262 * Other variants with different arithmetic operators:
15263 */
15264@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15265 return a;
15266 }
15267
15268+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15269+{
15270+ long long a;
15271+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15272+ "S" (v) : "memory", "ecx");
15273+ return a;
15274+}
15275+
15276 static inline long long atomic64_dec_return(atomic64_t *v)
15277 {
15278 long long a;
15279@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15280 }
15281
15282 /**
15283+ * atomic64_add_unchecked - add integer to atomic64 variable
15284+ * @i: integer value to add
15285+ * @v: pointer to type atomic64_unchecked_t
15286+ *
15287+ * Atomically adds @i to @v.
15288+ */
15289+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15290+{
15291+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15292+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15293+ ASM_NO_INPUT_CLOBBER("memory"));
15294+ return i;
15295+}
15296+
15297+/**
15298 * atomic64_sub - subtract the atomic64 variable
15299 * @i: integer value to subtract
15300 * @v: pointer to type atomic64_t
15301diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15302index 46e9052..ae45136 100644
15303--- a/arch/x86/include/asm/atomic64_64.h
15304+++ b/arch/x86/include/asm/atomic64_64.h
15305@@ -18,7 +18,19 @@
15306 */
15307 static inline long atomic64_read(const atomic64_t *v)
15308 {
15309- return (*(volatile long *)&(v)->counter);
15310+ return (*(volatile const long *)&(v)->counter);
15311+}
15312+
15313+/**
15314+ * atomic64_read_unchecked - read atomic64 variable
15315+ * @v: pointer of type atomic64_unchecked_t
15316+ *
15317+ * Atomically reads the value of @v.
15318+ * Doesn't imply a read memory barrier.
15319+ */
15320+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15321+{
15322+ return (*(volatile const long *)&(v)->counter);
15323 }
15324
15325 /**
15326@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15327 }
15328
15329 /**
15330+ * atomic64_set_unchecked - set atomic64 variable
15331+ * @v: pointer to type atomic64_unchecked_t
15332+ * @i: required value
15333+ *
15334+ * Atomically sets the value of @v to @i.
15335+ */
15336+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15337+{
15338+ v->counter = i;
15339+}
15340+
15341+/**
15342 * atomic64_add - add integer to atomic64 variable
15343 * @i: integer value to add
15344 * @v: pointer to type atomic64_t
15345@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15346 */
15347 static inline void atomic64_add(long i, atomic64_t *v)
15348 {
15349+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15350+
15351+#ifdef CONFIG_PAX_REFCOUNT
15352+ "jno 0f\n"
15353+ LOCK_PREFIX "subq %1,%0\n"
15354+ "int $4\n0:\n"
15355+ _ASM_EXTABLE(0b, 0b)
15356+#endif
15357+
15358+ : "=m" (v->counter)
15359+ : "er" (i), "m" (v->counter));
15360+}
15361+
15362+/**
15363+ * atomic64_add_unchecked - add integer to atomic64 variable
15364+ * @i: integer value to add
15365+ * @v: pointer to type atomic64_unchecked_t
15366+ *
15367+ * Atomically adds @i to @v.
15368+ */
15369+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15370+{
15371 asm volatile(LOCK_PREFIX "addq %1,%0"
15372 : "=m" (v->counter)
15373 : "er" (i), "m" (v->counter));
15374@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15375 */
15376 static inline void atomic64_sub(long i, atomic64_t *v)
15377 {
15378- asm volatile(LOCK_PREFIX "subq %1,%0"
15379+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15380+
15381+#ifdef CONFIG_PAX_REFCOUNT
15382+ "jno 0f\n"
15383+ LOCK_PREFIX "addq %1,%0\n"
15384+ "int $4\n0:\n"
15385+ _ASM_EXTABLE(0b, 0b)
15386+#endif
15387+
15388+ : "=m" (v->counter)
15389+ : "er" (i), "m" (v->counter));
15390+}
15391+
15392+/**
15393+ * atomic64_sub_unchecked - subtract the atomic64 variable
15394+ * @i: integer value to subtract
15395+ * @v: pointer to type atomic64_unchecked_t
15396+ *
15397+ * Atomically subtracts @i from @v.
15398+ */
15399+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15400+{
15401+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15402 : "=m" (v->counter)
15403 : "er" (i), "m" (v->counter));
15404 }
15405@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15406 */
15407 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15408 {
15409- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15410+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15411 }
15412
15413 /**
15414@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15415 */
15416 static inline void atomic64_inc(atomic64_t *v)
15417 {
15418+ asm volatile(LOCK_PREFIX "incq %0\n"
15419+
15420+#ifdef CONFIG_PAX_REFCOUNT
15421+ "jno 0f\n"
15422+ LOCK_PREFIX "decq %0\n"
15423+ "int $4\n0:\n"
15424+ _ASM_EXTABLE(0b, 0b)
15425+#endif
15426+
15427+ : "=m" (v->counter)
15428+ : "m" (v->counter));
15429+}
15430+
15431+/**
15432+ * atomic64_inc_unchecked - increment atomic64 variable
15433+ * @v: pointer to type atomic64_unchecked_t
15434+ *
15435+ * Atomically increments @v by 1.
15436+ */
15437+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15438+{
15439 asm volatile(LOCK_PREFIX "incq %0"
15440 : "=m" (v->counter)
15441 : "m" (v->counter));
15442@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15443 */
15444 static inline void atomic64_dec(atomic64_t *v)
15445 {
15446- asm volatile(LOCK_PREFIX "decq %0"
15447+ asm volatile(LOCK_PREFIX "decq %0\n"
15448+
15449+#ifdef CONFIG_PAX_REFCOUNT
15450+ "jno 0f\n"
15451+ LOCK_PREFIX "incq %0\n"
15452+ "int $4\n0:\n"
15453+ _ASM_EXTABLE(0b, 0b)
15454+#endif
15455+
15456+ : "=m" (v->counter)
15457+ : "m" (v->counter));
15458+}
15459+
15460+/**
15461+ * atomic64_dec_unchecked - decrement atomic64 variable
15462+ * @v: pointer to type atomic64_t
15463+ *
15464+ * Atomically decrements @v by 1.
15465+ */
15466+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15467+{
15468+ asm volatile(LOCK_PREFIX "decq %0\n"
15469 : "=m" (v->counter)
15470 : "m" (v->counter));
15471 }
15472@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15473 */
15474 static inline int atomic64_dec_and_test(atomic64_t *v)
15475 {
15476- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15477+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15478 }
15479
15480 /**
15481@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15482 */
15483 static inline int atomic64_inc_and_test(atomic64_t *v)
15484 {
15485- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15486+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15487 }
15488
15489 /**
15490@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15491 */
15492 static inline int atomic64_add_negative(long i, atomic64_t *v)
15493 {
15494- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15495+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15496 }
15497
15498 /**
15499@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15500 */
15501 static inline long atomic64_add_return(long i, atomic64_t *v)
15502 {
15503+ return i + xadd_check_overflow(&v->counter, i);
15504+}
15505+
15506+/**
15507+ * atomic64_add_return_unchecked - add and return
15508+ * @i: integer value to add
15509+ * @v: pointer to type atomic64_unchecked_t
15510+ *
15511+ * Atomically adds @i to @v and returns @i + @v
15512+ */
15513+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15514+{
15515 return i + xadd(&v->counter, i);
15516 }
15517
15518@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15519 }
15520
15521 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15522+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15523+{
15524+ return atomic64_add_return_unchecked(1, v);
15525+}
15526 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15527
15528 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15529@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15530 return cmpxchg(&v->counter, old, new);
15531 }
15532
15533+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15534+{
15535+ return cmpxchg(&v->counter, old, new);
15536+}
15537+
15538 static inline long atomic64_xchg(atomic64_t *v, long new)
15539 {
15540 return xchg(&v->counter, new);
15541@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15542 */
15543 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15544 {
15545- long c, old;
15546+ long c, old, new;
15547 c = atomic64_read(v);
15548 for (;;) {
15549- if (unlikely(c == (u)))
15550+ if (unlikely(c == u))
15551 break;
15552- old = atomic64_cmpxchg((v), c, c + (a));
15553+
15554+ asm volatile("add %2,%0\n"
15555+
15556+#ifdef CONFIG_PAX_REFCOUNT
15557+ "jno 0f\n"
15558+ "sub %2,%0\n"
15559+ "int $4\n0:\n"
15560+ _ASM_EXTABLE(0b, 0b)
15561+#endif
15562+
15563+ : "=r" (new)
15564+ : "0" (c), "ir" (a));
15565+
15566+ old = atomic64_cmpxchg(v, c, new);
15567 if (likely(old == c))
15568 break;
15569 c = old;
15570 }
15571- return c != (u);
15572+ return c != u;
15573 }
15574
15575 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15576diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15577index 9fc1af7..fc71228 100644
15578--- a/arch/x86/include/asm/bitops.h
15579+++ b/arch/x86/include/asm/bitops.h
15580@@ -49,7 +49,7 @@
15581 * a mask operation on a byte.
15582 */
15583 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15584-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15585+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15586 #define CONST_MASK(nr) (1 << ((nr) & 7))
15587
15588 /**
15589@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15590 */
15591 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15592 {
15593- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15594+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15595 }
15596
15597 /**
15598@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15599 */
15600 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15601 {
15602- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15603+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15604 }
15605
15606 /**
15607@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15608 */
15609 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15610 {
15611- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15612+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15613 }
15614
15615 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15616@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15617 *
15618 * Undefined if no bit exists, so code should check against 0 first.
15619 */
15620-static inline unsigned long __ffs(unsigned long word)
15621+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15622 {
15623 asm("rep; bsf %1,%0"
15624 : "=r" (word)
15625@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15626 *
15627 * Undefined if no zero exists, so code should check against ~0UL first.
15628 */
15629-static inline unsigned long ffz(unsigned long word)
15630+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15631 {
15632 asm("rep; bsf %1,%0"
15633 : "=r" (word)
15634@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15635 *
15636 * Undefined if no set bit exists, so code should check against 0 first.
15637 */
15638-static inline unsigned long __fls(unsigned long word)
15639+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15640 {
15641 asm("bsr %1,%0"
15642 : "=r" (word)
15643@@ -436,7 +436,7 @@ static inline int ffs(int x)
15644 * set bit if value is nonzero. The last (most significant) bit is
15645 * at position 32.
15646 */
15647-static inline int fls(int x)
15648+static inline int __intentional_overflow(-1) fls(int x)
15649 {
15650 int r;
15651
15652@@ -478,7 +478,7 @@ static inline int fls(int x)
15653 * at position 64.
15654 */
15655 #ifdef CONFIG_X86_64
15656-static __always_inline int fls64(__u64 x)
15657+static __always_inline long fls64(__u64 x)
15658 {
15659 int bitpos = -1;
15660 /*
15661diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15662index 4fa687a..60f2d39 100644
15663--- a/arch/x86/include/asm/boot.h
15664+++ b/arch/x86/include/asm/boot.h
15665@@ -6,10 +6,15 @@
15666 #include <uapi/asm/boot.h>
15667
15668 /* Physical address where kernel should be loaded. */
15669-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15670+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15671 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15672 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15673
15674+#ifndef __ASSEMBLY__
15675+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15676+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15677+#endif
15678+
15679 /* Minimum kernel alignment, as a power of two */
15680 #ifdef CONFIG_X86_64
15681 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15682diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15683index 48f99f1..d78ebf9 100644
15684--- a/arch/x86/include/asm/cache.h
15685+++ b/arch/x86/include/asm/cache.h
15686@@ -5,12 +5,13 @@
15687
15688 /* L1 cache line size */
15689 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15690-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15692
15693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15694+#define __read_only __attribute__((__section__(".data..read_only")))
15695
15696 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15697-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15698+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15699
15700 #ifdef CONFIG_X86_VSMP
15701 #ifdef CONFIG_SMP
15702diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15703index 9863ee3..4a1f8e1 100644
15704--- a/arch/x86/include/asm/cacheflush.h
15705+++ b/arch/x86/include/asm/cacheflush.h
15706@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15707 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15708
15709 if (pg_flags == _PGMT_DEFAULT)
15710- return -1;
15711+ return ~0UL;
15712 else if (pg_flags == _PGMT_WC)
15713 return _PAGE_CACHE_WC;
15714 else if (pg_flags == _PGMT_UC_MINUS)
15715diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15716index cb4c73b..c473c29 100644
15717--- a/arch/x86/include/asm/calling.h
15718+++ b/arch/x86/include/asm/calling.h
15719@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15720 #define RSP 152
15721 #define SS 160
15722
15723-#define ARGOFFSET R11
15724-#define SWFRAME ORIG_RAX
15725+#define ARGOFFSET R15
15726
15727 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15728- subq $9*8+\addskip, %rsp
15729- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15730- movq_cfi rdi, 8*8
15731- movq_cfi rsi, 7*8
15732- movq_cfi rdx, 6*8
15733+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15734+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15735+ movq_cfi rdi, RDI
15736+ movq_cfi rsi, RSI
15737+ movq_cfi rdx, RDX
15738
15739 .if \save_rcx
15740- movq_cfi rcx, 5*8
15741+ movq_cfi rcx, RCX
15742 .endif
15743
15744- movq_cfi rax, 4*8
15745+ movq_cfi rax, RAX
15746
15747 .if \save_r891011
15748- movq_cfi r8, 3*8
15749- movq_cfi r9, 2*8
15750- movq_cfi r10, 1*8
15751- movq_cfi r11, 0*8
15752+ movq_cfi r8, R8
15753+ movq_cfi r9, R9
15754+ movq_cfi r10, R10
15755+ movq_cfi r11, R11
15756 .endif
15757
15758+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15759+ movq_cfi r12, R12
15760+#endif
15761+
15762 .endm
15763
15764-#define ARG_SKIP (9*8)
15765+#define ARG_SKIP ORIG_RAX
15766
15767 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15768 rstor_r8910=1, rstor_rdx=1
15769+
15770+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15771+ movq_cfi_restore R12, r12
15772+#endif
15773+
15774 .if \rstor_r11
15775- movq_cfi_restore 0*8, r11
15776+ movq_cfi_restore R11, r11
15777 .endif
15778
15779 .if \rstor_r8910
15780- movq_cfi_restore 1*8, r10
15781- movq_cfi_restore 2*8, r9
15782- movq_cfi_restore 3*8, r8
15783+ movq_cfi_restore R10, r10
15784+ movq_cfi_restore R9, r9
15785+ movq_cfi_restore R8, r8
15786 .endif
15787
15788 .if \rstor_rax
15789- movq_cfi_restore 4*8, rax
15790+ movq_cfi_restore RAX, rax
15791 .endif
15792
15793 .if \rstor_rcx
15794- movq_cfi_restore 5*8, rcx
15795+ movq_cfi_restore RCX, rcx
15796 .endif
15797
15798 .if \rstor_rdx
15799- movq_cfi_restore 6*8, rdx
15800+ movq_cfi_restore RDX, rdx
15801 .endif
15802
15803- movq_cfi_restore 7*8, rsi
15804- movq_cfi_restore 8*8, rdi
15805+ movq_cfi_restore RSI, rsi
15806+ movq_cfi_restore RDI, rdi
15807
15808- .if ARG_SKIP+\addskip > 0
15809- addq $ARG_SKIP+\addskip, %rsp
15810- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15811+ .if ORIG_RAX+\addskip > 0
15812+ addq $ORIG_RAX+\addskip, %rsp
15813+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15814 .endif
15815 .endm
15816
15817- .macro LOAD_ARGS offset, skiprax=0
15818- movq \offset(%rsp), %r11
15819- movq \offset+8(%rsp), %r10
15820- movq \offset+16(%rsp), %r9
15821- movq \offset+24(%rsp), %r8
15822- movq \offset+40(%rsp), %rcx
15823- movq \offset+48(%rsp), %rdx
15824- movq \offset+56(%rsp), %rsi
15825- movq \offset+64(%rsp), %rdi
15826+ .macro LOAD_ARGS skiprax=0
15827+ movq R11(%rsp), %r11
15828+ movq R10(%rsp), %r10
15829+ movq R9(%rsp), %r9
15830+ movq R8(%rsp), %r8
15831+ movq RCX(%rsp), %rcx
15832+ movq RDX(%rsp), %rdx
15833+ movq RSI(%rsp), %rsi
15834+ movq RDI(%rsp), %rdi
15835 .if \skiprax
15836 .else
15837- movq \offset+72(%rsp), %rax
15838+ movq RAX(%rsp), %rax
15839 .endif
15840 .endm
15841
15842-#define REST_SKIP (6*8)
15843-
15844 .macro SAVE_REST
15845- subq $REST_SKIP, %rsp
15846- CFI_ADJUST_CFA_OFFSET REST_SKIP
15847- movq_cfi rbx, 5*8
15848- movq_cfi rbp, 4*8
15849- movq_cfi r12, 3*8
15850- movq_cfi r13, 2*8
15851- movq_cfi r14, 1*8
15852- movq_cfi r15, 0*8
15853+ movq_cfi rbx, RBX
15854+ movq_cfi rbp, RBP
15855+
15856+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15857+ movq_cfi r12, R12
15858+#endif
15859+
15860+ movq_cfi r13, R13
15861+ movq_cfi r14, R14
15862+ movq_cfi r15, R15
15863 .endm
15864
15865 .macro RESTORE_REST
15866- movq_cfi_restore 0*8, r15
15867- movq_cfi_restore 1*8, r14
15868- movq_cfi_restore 2*8, r13
15869- movq_cfi_restore 3*8, r12
15870- movq_cfi_restore 4*8, rbp
15871- movq_cfi_restore 5*8, rbx
15872- addq $REST_SKIP, %rsp
15873- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15874+ movq_cfi_restore R15, r15
15875+ movq_cfi_restore R14, r14
15876+ movq_cfi_restore R13, r13
15877+
15878+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15879+ movq_cfi_restore R12, r12
15880+#endif
15881+
15882+ movq_cfi_restore RBP, rbp
15883+ movq_cfi_restore RBX, rbx
15884 .endm
15885
15886 .macro SAVE_ALL
15887diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15888index f50de69..2b0a458 100644
15889--- a/arch/x86/include/asm/checksum_32.h
15890+++ b/arch/x86/include/asm/checksum_32.h
15891@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15892 int len, __wsum sum,
15893 int *src_err_ptr, int *dst_err_ptr);
15894
15895+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15896+ int len, __wsum sum,
15897+ int *src_err_ptr, int *dst_err_ptr);
15898+
15899+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15900+ int len, __wsum sum,
15901+ int *src_err_ptr, int *dst_err_ptr);
15902+
15903 /*
15904 * Note: when you get a NULL pointer exception here this means someone
15905 * passed in an incorrect kernel address to one of these functions.
15906@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15907
15908 might_sleep();
15909 stac();
15910- ret = csum_partial_copy_generic((__force void *)src, dst,
15911+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15912 len, sum, err_ptr, NULL);
15913 clac();
15914
15915@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15916 might_sleep();
15917 if (access_ok(VERIFY_WRITE, dst, len)) {
15918 stac();
15919- ret = csum_partial_copy_generic(src, (__force void *)dst,
15920+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15921 len, sum, NULL, err_ptr);
15922 clac();
15923 return ret;
15924diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15925index d47786a..2d8883e 100644
15926--- a/arch/x86/include/asm/cmpxchg.h
15927+++ b/arch/x86/include/asm/cmpxchg.h
15928@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15929 __compiletime_error("Bad argument size for cmpxchg");
15930 extern void __xadd_wrong_size(void)
15931 __compiletime_error("Bad argument size for xadd");
15932+extern void __xadd_check_overflow_wrong_size(void)
15933+ __compiletime_error("Bad argument size for xadd_check_overflow");
15934 extern void __add_wrong_size(void)
15935 __compiletime_error("Bad argument size for add");
15936+extern void __add_check_overflow_wrong_size(void)
15937+ __compiletime_error("Bad argument size for add_check_overflow");
15938
15939 /*
15940 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15941@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
15942 __ret; \
15943 })
15944
15945+#ifdef CONFIG_PAX_REFCOUNT
15946+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15947+ ({ \
15948+ __typeof__ (*(ptr)) __ret = (arg); \
15949+ switch (sizeof(*(ptr))) { \
15950+ case __X86_CASE_L: \
15951+ asm volatile (lock #op "l %0, %1\n" \
15952+ "jno 0f\n" \
15953+ "mov %0,%1\n" \
15954+ "int $4\n0:\n" \
15955+ _ASM_EXTABLE(0b, 0b) \
15956+ : "+r" (__ret), "+m" (*(ptr)) \
15957+ : : "memory", "cc"); \
15958+ break; \
15959+ case __X86_CASE_Q: \
15960+ asm volatile (lock #op "q %q0, %1\n" \
15961+ "jno 0f\n" \
15962+ "mov %0,%1\n" \
15963+ "int $4\n0:\n" \
15964+ _ASM_EXTABLE(0b, 0b) \
15965+ : "+r" (__ret), "+m" (*(ptr)) \
15966+ : : "memory", "cc"); \
15967+ break; \
15968+ default: \
15969+ __ ## op ## _check_overflow_wrong_size(); \
15970+ } \
15971+ __ret; \
15972+ })
15973+#else
15974+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
15975+#endif
15976+
15977 /*
15978 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15979 * Since this is generally used to protect other memory information, we
15980@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
15981 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15982 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15983
15984+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15985+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15986+
15987 #define __add(ptr, inc, lock) \
15988 ({ \
15989 __typeof__ (*(ptr)) __ret = (inc); \
15990diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15991index 59c6c40..5e0b22c 100644
15992--- a/arch/x86/include/asm/compat.h
15993+++ b/arch/x86/include/asm/compat.h
15994@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15995 typedef u32 compat_uint_t;
15996 typedef u32 compat_ulong_t;
15997 typedef u64 __attribute__((aligned(4))) compat_u64;
15998-typedef u32 compat_uptr_t;
15999+typedef u32 __user compat_uptr_t;
16000
16001 struct compat_timespec {
16002 compat_time_t tv_sec;
16003diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16004index 5f12968..a383517 100644
16005--- a/arch/x86/include/asm/cpufeature.h
16006+++ b/arch/x86/include/asm/cpufeature.h
16007@@ -203,7 +203,7 @@
16008 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16009 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16010 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16011-
16012+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16013
16014 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16015 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16016@@ -211,7 +211,7 @@
16017 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16018 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16019 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16020-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16021+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16022 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16023 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16024 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16025@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16026 #undef cpu_has_centaur_mcr
16027 #define cpu_has_centaur_mcr 0
16028
16029+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16030 #endif /* CONFIG_X86_64 */
16031
16032 #if __GNUC__ >= 4
16033@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16034
16035 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16036 t_warn:
16037- warn_pre_alternatives();
16038+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16039+ warn_pre_alternatives();
16040 return false;
16041 #endif
16042
16043@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16044 ".section .discard,\"aw\",@progbits\n"
16045 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16046 ".previous\n"
16047- ".section .altinstr_replacement,\"ax\"\n"
16048+ ".section .altinstr_replacement,\"a\"\n"
16049 "3: movb $1,%0\n"
16050 "4:\n"
16051 ".previous\n"
16052@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16053 " .byte 2b - 1b\n" /* src len */
16054 " .byte 4f - 3f\n" /* repl len */
16055 ".previous\n"
16056- ".section .altinstr_replacement,\"ax\"\n"
16057+ ".section .altinstr_replacement,\"a\"\n"
16058 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16059 "4:\n"
16060 ".previous\n"
16061@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16062 ".section .discard,\"aw\",@progbits\n"
16063 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16064 ".previous\n"
16065- ".section .altinstr_replacement,\"ax\"\n"
16066+ ".section .altinstr_replacement,\"a\"\n"
16067 "3: movb $0,%0\n"
16068 "4:\n"
16069 ".previous\n"
16070@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16071 ".section .discard,\"aw\",@progbits\n"
16072 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16073 ".previous\n"
16074- ".section .altinstr_replacement,\"ax\"\n"
16075+ ".section .altinstr_replacement,\"a\"\n"
16076 "5: movb $1,%0\n"
16077 "6:\n"
16078 ".previous\n"
16079diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16080index 50d033a..37deb26 100644
16081--- a/arch/x86/include/asm/desc.h
16082+++ b/arch/x86/include/asm/desc.h
16083@@ -4,6 +4,7 @@
16084 #include <asm/desc_defs.h>
16085 #include <asm/ldt.h>
16086 #include <asm/mmu.h>
16087+#include <asm/pgtable.h>
16088
16089 #include <linux/smp.h>
16090 #include <linux/percpu.h>
16091@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16092
16093 desc->type = (info->read_exec_only ^ 1) << 1;
16094 desc->type |= info->contents << 2;
16095+ desc->type |= info->seg_not_present ^ 1;
16096
16097 desc->s = 1;
16098 desc->dpl = 0x3;
16099@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16100 }
16101
16102 extern struct desc_ptr idt_descr;
16103-extern gate_desc idt_table[];
16104-extern struct desc_ptr debug_idt_descr;
16105-extern gate_desc debug_idt_table[];
16106-
16107-struct gdt_page {
16108- struct desc_struct gdt[GDT_ENTRIES];
16109-} __attribute__((aligned(PAGE_SIZE)));
16110-
16111-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16112+extern gate_desc idt_table[IDT_ENTRIES];
16113+extern const struct desc_ptr debug_idt_descr;
16114+extern gate_desc debug_idt_table[IDT_ENTRIES];
16115
16116+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16117 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16118 {
16119- return per_cpu(gdt_page, cpu).gdt;
16120+ return cpu_gdt_table[cpu];
16121 }
16122
16123 #ifdef CONFIG_X86_64
16124@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16125 unsigned long base, unsigned dpl, unsigned flags,
16126 unsigned short seg)
16127 {
16128- gate->a = (seg << 16) | (base & 0xffff);
16129- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16130+ gate->gate.offset_low = base;
16131+ gate->gate.seg = seg;
16132+ gate->gate.reserved = 0;
16133+ gate->gate.type = type;
16134+ gate->gate.s = 0;
16135+ gate->gate.dpl = dpl;
16136+ gate->gate.p = 1;
16137+ gate->gate.offset_high = base >> 16;
16138 }
16139
16140 #endif
16141@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16142
16143 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16144 {
16145+ pax_open_kernel();
16146 memcpy(&idt[entry], gate, sizeof(*gate));
16147+ pax_close_kernel();
16148 }
16149
16150 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16151 {
16152+ pax_open_kernel();
16153 memcpy(&ldt[entry], desc, 8);
16154+ pax_close_kernel();
16155 }
16156
16157 static inline void
16158@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16159 default: size = sizeof(*gdt); break;
16160 }
16161
16162+ pax_open_kernel();
16163 memcpy(&gdt[entry], desc, size);
16164+ pax_close_kernel();
16165 }
16166
16167 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16168@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16169
16170 static inline void native_load_tr_desc(void)
16171 {
16172+ pax_open_kernel();
16173 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16174+ pax_close_kernel();
16175 }
16176
16177 static inline void native_load_gdt(const struct desc_ptr *dtr)
16178@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16179 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16180 unsigned int i;
16181
16182+ pax_open_kernel();
16183 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16184 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16185+ pax_close_kernel();
16186 }
16187
16188 #define _LDT_empty(info) \
16189@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16190 preempt_enable();
16191 }
16192
16193-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16194+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16195 {
16196 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16197 }
16198@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16199 }
16200
16201 #ifdef CONFIG_X86_64
16202-static inline void set_nmi_gate(int gate, void *addr)
16203+static inline void set_nmi_gate(int gate, const void *addr)
16204 {
16205 gate_desc s;
16206
16207@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16208 #endif
16209
16210 #ifdef CONFIG_TRACING
16211-extern struct desc_ptr trace_idt_descr;
16212-extern gate_desc trace_idt_table[];
16213+extern const struct desc_ptr trace_idt_descr;
16214+extern gate_desc trace_idt_table[IDT_ENTRIES];
16215 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16216 {
16217 write_idt_entry(trace_idt_table, entry, gate);
16218 }
16219
16220-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16221+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16222 unsigned dpl, unsigned ist, unsigned seg)
16223 {
16224 gate_desc s;
16225@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16226 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16227 #endif
16228
16229-static inline void _set_gate(int gate, unsigned type, void *addr,
16230+static inline void _set_gate(int gate, unsigned type, const void *addr,
16231 unsigned dpl, unsigned ist, unsigned seg)
16232 {
16233 gate_desc s;
16234@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16235 #define set_intr_gate(n, addr) \
16236 do { \
16237 BUG_ON((unsigned)n > 0xFF); \
16238- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16239+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16240 __KERNEL_CS); \
16241- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16242+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16243 0, 0, __KERNEL_CS); \
16244 } while (0)
16245
16246@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16247 /*
16248 * This routine sets up an interrupt gate at directory privilege level 3.
16249 */
16250-static inline void set_system_intr_gate(unsigned int n, void *addr)
16251+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16252 {
16253 BUG_ON((unsigned)n > 0xFF);
16254 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16255 }
16256
16257-static inline void set_system_trap_gate(unsigned int n, void *addr)
16258+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16259 {
16260 BUG_ON((unsigned)n > 0xFF);
16261 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16262 }
16263
16264-static inline void set_trap_gate(unsigned int n, void *addr)
16265+static inline void set_trap_gate(unsigned int n, const void *addr)
16266 {
16267 BUG_ON((unsigned)n > 0xFF);
16268 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16269@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16270 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16271 {
16272 BUG_ON((unsigned)n > 0xFF);
16273- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16274+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16275 }
16276
16277-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16278+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16279 {
16280 BUG_ON((unsigned)n > 0xFF);
16281 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16282 }
16283
16284-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16285+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16286 {
16287 BUG_ON((unsigned)n > 0xFF);
16288 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16289@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16290 else
16291 load_idt((const struct desc_ptr *)&idt_descr);
16292 }
16293+
16294+#ifdef CONFIG_X86_32
16295+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16296+{
16297+ struct desc_struct d;
16298+
16299+ if (likely(limit))
16300+ limit = (limit - 1UL) >> PAGE_SHIFT;
16301+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16302+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16303+}
16304+#endif
16305+
16306 #endif /* _ASM_X86_DESC_H */
16307diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16308index 278441f..b95a174 100644
16309--- a/arch/x86/include/asm/desc_defs.h
16310+++ b/arch/x86/include/asm/desc_defs.h
16311@@ -31,6 +31,12 @@ struct desc_struct {
16312 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16313 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16314 };
16315+ struct {
16316+ u16 offset_low;
16317+ u16 seg;
16318+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16319+ unsigned offset_high: 16;
16320+ } gate;
16321 };
16322 } __attribute__((packed));
16323
16324diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16325index ced283a..ffe04cc 100644
16326--- a/arch/x86/include/asm/div64.h
16327+++ b/arch/x86/include/asm/div64.h
16328@@ -39,7 +39,7 @@
16329 __mod; \
16330 })
16331
16332-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16333+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16334 {
16335 union {
16336 u64 v64;
16337diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16338index 9c999c1..3860cb8 100644
16339--- a/arch/x86/include/asm/elf.h
16340+++ b/arch/x86/include/asm/elf.h
16341@@ -243,7 +243,25 @@ extern int force_personality32;
16342 the loader. We need to make sure that it is out of the way of the program
16343 that it will "exec", and that there is sufficient room for the brk. */
16344
16345+#ifdef CONFIG_PAX_SEGMEXEC
16346+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16347+#else
16348 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16349+#endif
16350+
16351+#ifdef CONFIG_PAX_ASLR
16352+#ifdef CONFIG_X86_32
16353+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16354+
16355+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16356+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16357+#else
16358+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16359+
16360+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16361+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16362+#endif
16363+#endif
16364
16365 /* This yields a mask that user programs can use to figure out what
16366 instruction set this CPU supports. This could be done in user space,
16367@@ -296,16 +314,12 @@ do { \
16368
16369 #define ARCH_DLINFO \
16370 do { \
16371- if (vdso_enabled) \
16372- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16373- (unsigned long)current->mm->context.vdso); \
16374+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16375 } while (0)
16376
16377 #define ARCH_DLINFO_X32 \
16378 do { \
16379- if (vdso_enabled) \
16380- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16381- (unsigned long)current->mm->context.vdso); \
16382+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16383 } while (0)
16384
16385 #define AT_SYSINFO 32
16386@@ -320,7 +334,7 @@ else \
16387
16388 #endif /* !CONFIG_X86_32 */
16389
16390-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16391+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16392
16393 #define VDSO_ENTRY \
16394 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16395@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16396 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16397 #define compat_arch_setup_additional_pages syscall32_setup_pages
16398
16399-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16400-#define arch_randomize_brk arch_randomize_brk
16401-
16402 /*
16403 * True on X86_32 or when emulating IA32 on X86_64
16404 */
16405diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16406index 77a99ac..39ff7f5 100644
16407--- a/arch/x86/include/asm/emergency-restart.h
16408+++ b/arch/x86/include/asm/emergency-restart.h
16409@@ -1,6 +1,6 @@
16410 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16411 #define _ASM_X86_EMERGENCY_RESTART_H
16412
16413-extern void machine_emergency_restart(void);
16414+extern void machine_emergency_restart(void) __noreturn;
16415
16416 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16417diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16418index d3d7469..677ef72 100644
16419--- a/arch/x86/include/asm/floppy.h
16420+++ b/arch/x86/include/asm/floppy.h
16421@@ -229,18 +229,18 @@ static struct fd_routine_l {
16422 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16423 } fd_routine[] = {
16424 {
16425- request_dma,
16426- free_dma,
16427- get_dma_residue,
16428- dma_mem_alloc,
16429- hard_dma_setup
16430+ ._request_dma = request_dma,
16431+ ._free_dma = free_dma,
16432+ ._get_dma_residue = get_dma_residue,
16433+ ._dma_mem_alloc = dma_mem_alloc,
16434+ ._dma_setup = hard_dma_setup
16435 },
16436 {
16437- vdma_request_dma,
16438- vdma_nop,
16439- vdma_get_dma_residue,
16440- vdma_mem_alloc,
16441- vdma_dma_setup
16442+ ._request_dma = vdma_request_dma,
16443+ ._free_dma = vdma_nop,
16444+ ._get_dma_residue = vdma_get_dma_residue,
16445+ ._dma_mem_alloc = vdma_mem_alloc,
16446+ ._dma_setup = vdma_dma_setup
16447 }
16448 };
16449
16450diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16451index cea1c76..6c0d79b 100644
16452--- a/arch/x86/include/asm/fpu-internal.h
16453+++ b/arch/x86/include/asm/fpu-internal.h
16454@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16455 #define user_insn(insn, output, input...) \
16456 ({ \
16457 int err; \
16458+ pax_open_userland(); \
16459 asm volatile(ASM_STAC "\n" \
16460- "1:" #insn "\n\t" \
16461+ "1:" \
16462+ __copyuser_seg \
16463+ #insn "\n\t" \
16464 "2: " ASM_CLAC "\n" \
16465 ".section .fixup,\"ax\"\n" \
16466 "3: movl $-1,%[err]\n" \
16467@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16468 _ASM_EXTABLE(1b, 3b) \
16469 : [err] "=r" (err), output \
16470 : "0"(0), input); \
16471+ pax_close_userland(); \
16472 err; \
16473 })
16474
16475@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16476 "fnclex\n\t"
16477 "emms\n\t"
16478 "fildl %P[addr]" /* set F?P to defined value */
16479- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16480+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16481 }
16482
16483 return fpu_restore_checking(&tsk->thread.fpu);
16484diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16485index b4c1f54..e290c08 100644
16486--- a/arch/x86/include/asm/futex.h
16487+++ b/arch/x86/include/asm/futex.h
16488@@ -12,6 +12,7 @@
16489 #include <asm/smap.h>
16490
16491 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16492+ typecheck(u32 __user *, uaddr); \
16493 asm volatile("\t" ASM_STAC "\n" \
16494 "1:\t" insn "\n" \
16495 "2:\t" ASM_CLAC "\n" \
16496@@ -20,15 +21,16 @@
16497 "\tjmp\t2b\n" \
16498 "\t.previous\n" \
16499 _ASM_EXTABLE(1b, 3b) \
16500- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16501+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16502 : "i" (-EFAULT), "0" (oparg), "1" (0))
16503
16504 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16505+ typecheck(u32 __user *, uaddr); \
16506 asm volatile("\t" ASM_STAC "\n" \
16507 "1:\tmovl %2, %0\n" \
16508 "\tmovl\t%0, %3\n" \
16509 "\t" insn "\n" \
16510- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16511+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16512 "\tjnz\t1b\n" \
16513 "3:\t" ASM_CLAC "\n" \
16514 "\t.section .fixup,\"ax\"\n" \
16515@@ -38,7 +40,7 @@
16516 _ASM_EXTABLE(1b, 4b) \
16517 _ASM_EXTABLE(2b, 4b) \
16518 : "=&a" (oldval), "=&r" (ret), \
16519- "+m" (*uaddr), "=&r" (tem) \
16520+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16521 : "r" (oparg), "i" (-EFAULT), "1" (0))
16522
16523 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16524@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16525
16526 pagefault_disable();
16527
16528+ pax_open_userland();
16529 switch (op) {
16530 case FUTEX_OP_SET:
16531- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16532+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16533 break;
16534 case FUTEX_OP_ADD:
16535- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16536+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16537 uaddr, oparg);
16538 break;
16539 case FUTEX_OP_OR:
16540@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16541 default:
16542 ret = -ENOSYS;
16543 }
16544+ pax_close_userland();
16545
16546 pagefault_enable();
16547
16548diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16549index 67d69b8..50e4b77 100644
16550--- a/arch/x86/include/asm/hw_irq.h
16551+++ b/arch/x86/include/asm/hw_irq.h
16552@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16553 extern void enable_IO_APIC(void);
16554
16555 /* Statistics */
16556-extern atomic_t irq_err_count;
16557-extern atomic_t irq_mis_count;
16558+extern atomic_unchecked_t irq_err_count;
16559+extern atomic_unchecked_t irq_mis_count;
16560
16561 /* EISA */
16562 extern void eisa_set_level_irq(unsigned int irq);
16563diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16564index a203659..9889f1c 100644
16565--- a/arch/x86/include/asm/i8259.h
16566+++ b/arch/x86/include/asm/i8259.h
16567@@ -62,7 +62,7 @@ struct legacy_pic {
16568 void (*init)(int auto_eoi);
16569 int (*irq_pending)(unsigned int irq);
16570 void (*make_irq)(unsigned int irq);
16571-};
16572+} __do_const;
16573
16574 extern struct legacy_pic *legacy_pic;
16575 extern struct legacy_pic null_legacy_pic;
16576diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16577index 91d9c69..dfae7d0 100644
16578--- a/arch/x86/include/asm/io.h
16579+++ b/arch/x86/include/asm/io.h
16580@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16581 "m" (*(volatile type __force *)addr) barrier); }
16582
16583 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16584-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16585-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16586+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16587+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16588
16589 build_mmio_read(__readb, "b", unsigned char, "=q", )
16590-build_mmio_read(__readw, "w", unsigned short, "=r", )
16591-build_mmio_read(__readl, "l", unsigned int, "=r", )
16592+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16593+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16594
16595 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16596 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16597@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16598 return ioremap_nocache(offset, size);
16599 }
16600
16601-extern void iounmap(volatile void __iomem *addr);
16602+extern void iounmap(const volatile void __iomem *addr);
16603
16604 extern void set_iounmap_nonlazy(void);
16605
16606@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16607
16608 #include <linux/vmalloc.h>
16609
16610+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16611+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16612+{
16613+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16614+}
16615+
16616+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16617+{
16618+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16619+}
16620+
16621 /*
16622 * Convert a virtual cached pointer to an uncached pointer
16623 */
16624diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16625index bba3cf8..06bc8da 100644
16626--- a/arch/x86/include/asm/irqflags.h
16627+++ b/arch/x86/include/asm/irqflags.h
16628@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16629 sti; \
16630 sysexit
16631
16632+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16633+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16634+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16635+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16636+
16637 #else
16638 #define INTERRUPT_RETURN iret
16639 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16640diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16641index 9454c16..e4100e3 100644
16642--- a/arch/x86/include/asm/kprobes.h
16643+++ b/arch/x86/include/asm/kprobes.h
16644@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16645 #define RELATIVEJUMP_SIZE 5
16646 #define RELATIVECALL_OPCODE 0xe8
16647 #define RELATIVE_ADDR_SIZE 4
16648-#define MAX_STACK_SIZE 64
16649-#define MIN_STACK_SIZE(ADDR) \
16650- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16651- THREAD_SIZE - (unsigned long)(ADDR))) \
16652- ? (MAX_STACK_SIZE) \
16653- : (((unsigned long)current_thread_info()) + \
16654- THREAD_SIZE - (unsigned long)(ADDR)))
16655+#define MAX_STACK_SIZE 64UL
16656+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16657
16658 #define flush_insn_slot(p) do { } while (0)
16659
16660diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16661index 4ad6560..75c7bdd 100644
16662--- a/arch/x86/include/asm/local.h
16663+++ b/arch/x86/include/asm/local.h
16664@@ -10,33 +10,97 @@ typedef struct {
16665 atomic_long_t a;
16666 } local_t;
16667
16668+typedef struct {
16669+ atomic_long_unchecked_t a;
16670+} local_unchecked_t;
16671+
16672 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16673
16674 #define local_read(l) atomic_long_read(&(l)->a)
16675+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16676 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16677+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16678
16679 static inline void local_inc(local_t *l)
16680 {
16681- asm volatile(_ASM_INC "%0"
16682+ asm volatile(_ASM_INC "%0\n"
16683+
16684+#ifdef CONFIG_PAX_REFCOUNT
16685+ "jno 0f\n"
16686+ _ASM_DEC "%0\n"
16687+ "int $4\n0:\n"
16688+ _ASM_EXTABLE(0b, 0b)
16689+#endif
16690+
16691+ : "+m" (l->a.counter));
16692+}
16693+
16694+static inline void local_inc_unchecked(local_unchecked_t *l)
16695+{
16696+ asm volatile(_ASM_INC "%0\n"
16697 : "+m" (l->a.counter));
16698 }
16699
16700 static inline void local_dec(local_t *l)
16701 {
16702- asm volatile(_ASM_DEC "%0"
16703+ asm volatile(_ASM_DEC "%0\n"
16704+
16705+#ifdef CONFIG_PAX_REFCOUNT
16706+ "jno 0f\n"
16707+ _ASM_INC "%0\n"
16708+ "int $4\n0:\n"
16709+ _ASM_EXTABLE(0b, 0b)
16710+#endif
16711+
16712+ : "+m" (l->a.counter));
16713+}
16714+
16715+static inline void local_dec_unchecked(local_unchecked_t *l)
16716+{
16717+ asm volatile(_ASM_DEC "%0\n"
16718 : "+m" (l->a.counter));
16719 }
16720
16721 static inline void local_add(long i, local_t *l)
16722 {
16723- asm volatile(_ASM_ADD "%1,%0"
16724+ asm volatile(_ASM_ADD "%1,%0\n"
16725+
16726+#ifdef CONFIG_PAX_REFCOUNT
16727+ "jno 0f\n"
16728+ _ASM_SUB "%1,%0\n"
16729+ "int $4\n0:\n"
16730+ _ASM_EXTABLE(0b, 0b)
16731+#endif
16732+
16733+ : "+m" (l->a.counter)
16734+ : "ir" (i));
16735+}
16736+
16737+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16738+{
16739+ asm volatile(_ASM_ADD "%1,%0\n"
16740 : "+m" (l->a.counter)
16741 : "ir" (i));
16742 }
16743
16744 static inline void local_sub(long i, local_t *l)
16745 {
16746- asm volatile(_ASM_SUB "%1,%0"
16747+ asm volatile(_ASM_SUB "%1,%0\n"
16748+
16749+#ifdef CONFIG_PAX_REFCOUNT
16750+ "jno 0f\n"
16751+ _ASM_ADD "%1,%0\n"
16752+ "int $4\n0:\n"
16753+ _ASM_EXTABLE(0b, 0b)
16754+#endif
16755+
16756+ : "+m" (l->a.counter)
16757+ : "ir" (i));
16758+}
16759+
16760+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16761+{
16762+ asm volatile(_ASM_SUB "%1,%0\n"
16763 : "+m" (l->a.counter)
16764 : "ir" (i));
16765 }
16766@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16767 */
16768 static inline int local_sub_and_test(long i, local_t *l)
16769 {
16770- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16771+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16772 }
16773
16774 /**
16775@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16776 */
16777 static inline int local_dec_and_test(local_t *l)
16778 {
16779- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16780+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16781 }
16782
16783 /**
16784@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16785 */
16786 static inline int local_inc_and_test(local_t *l)
16787 {
16788- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16789+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16790 }
16791
16792 /**
16793@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16794 */
16795 static inline int local_add_negative(long i, local_t *l)
16796 {
16797- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16798+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16799 }
16800
16801 /**
16802@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16803 static inline long local_add_return(long i, local_t *l)
16804 {
16805 long __i = i;
16806+ asm volatile(_ASM_XADD "%0, %1\n"
16807+
16808+#ifdef CONFIG_PAX_REFCOUNT
16809+ "jno 0f\n"
16810+ _ASM_MOV "%0,%1\n"
16811+ "int $4\n0:\n"
16812+ _ASM_EXTABLE(0b, 0b)
16813+#endif
16814+
16815+ : "+r" (i), "+m" (l->a.counter)
16816+ : : "memory");
16817+ return i + __i;
16818+}
16819+
16820+/**
16821+ * local_add_return_unchecked - add and return
16822+ * @i: integer value to add
16823+ * @l: pointer to type local_unchecked_t
16824+ *
16825+ * Atomically adds @i to @l and returns @i + @l
16826+ */
16827+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16828+{
16829+ long __i = i;
16830 asm volatile(_ASM_XADD "%0, %1;"
16831 : "+r" (i), "+m" (l->a.counter)
16832 : : "memory");
16833@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16834
16835 #define local_cmpxchg(l, o, n) \
16836 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16837+#define local_cmpxchg_unchecked(l, o, n) \
16838+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16839 /* Always has a lock prefix */
16840 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16841
16842diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16843new file mode 100644
16844index 0000000..2bfd3ba
16845--- /dev/null
16846+++ b/arch/x86/include/asm/mman.h
16847@@ -0,0 +1,15 @@
16848+#ifndef _X86_MMAN_H
16849+#define _X86_MMAN_H
16850+
16851+#include <uapi/asm/mman.h>
16852+
16853+#ifdef __KERNEL__
16854+#ifndef __ASSEMBLY__
16855+#ifdef CONFIG_X86_32
16856+#define arch_mmap_check i386_mmap_check
16857+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16858+#endif
16859+#endif
16860+#endif
16861+
16862+#endif /* X86_MMAN_H */
16863diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16864index 5f55e69..e20bfb1 100644
16865--- a/arch/x86/include/asm/mmu.h
16866+++ b/arch/x86/include/asm/mmu.h
16867@@ -9,7 +9,7 @@
16868 * we put the segment information here.
16869 */
16870 typedef struct {
16871- void *ldt;
16872+ struct desc_struct *ldt;
16873 int size;
16874
16875 #ifdef CONFIG_X86_64
16876@@ -18,7 +18,19 @@ typedef struct {
16877 #endif
16878
16879 struct mutex lock;
16880- void *vdso;
16881+ unsigned long vdso;
16882+
16883+#ifdef CONFIG_X86_32
16884+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16885+ unsigned long user_cs_base;
16886+ unsigned long user_cs_limit;
16887+
16888+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16889+ cpumask_t cpu_user_cs_mask;
16890+#endif
16891+
16892+#endif
16893+#endif
16894 } mm_context_t;
16895
16896 #ifdef CONFIG_SMP
16897diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16898index be12c53..4d24039 100644
16899--- a/arch/x86/include/asm/mmu_context.h
16900+++ b/arch/x86/include/asm/mmu_context.h
16901@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16902
16903 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16904 {
16905+
16906+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16907+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16908+ unsigned int i;
16909+ pgd_t *pgd;
16910+
16911+ pax_open_kernel();
16912+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16913+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16914+ set_pgd_batched(pgd+i, native_make_pgd(0));
16915+ pax_close_kernel();
16916+ }
16917+#endif
16918+
16919 #ifdef CONFIG_SMP
16920 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16921 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16922@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16923 struct task_struct *tsk)
16924 {
16925 unsigned cpu = smp_processor_id();
16926+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16927+ int tlbstate = TLBSTATE_OK;
16928+#endif
16929
16930 if (likely(prev != next)) {
16931 #ifdef CONFIG_SMP
16932+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16933+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16934+#endif
16935 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16936 this_cpu_write(cpu_tlbstate.active_mm, next);
16937 #endif
16938 cpumask_set_cpu(cpu, mm_cpumask(next));
16939
16940 /* Re-load page tables */
16941+#ifdef CONFIG_PAX_PER_CPU_PGD
16942+ pax_open_kernel();
16943+
16944+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16945+ if (static_cpu_has(X86_FEATURE_PCID))
16946+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16947+ else
16948+#endif
16949+
16950+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16951+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16952+ pax_close_kernel();
16953+ 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));
16954+
16955+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16956+ if (static_cpu_has(X86_FEATURE_PCID)) {
16957+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16958+ u64 descriptor[2];
16959+ descriptor[0] = PCID_USER;
16960+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16961+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16962+ descriptor[0] = PCID_KERNEL;
16963+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16964+ }
16965+ } else {
16966+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16967+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16968+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16969+ else
16970+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16971+ }
16972+ } else
16973+#endif
16974+
16975+ load_cr3(get_cpu_pgd(cpu, kernel));
16976+#else
16977 load_cr3(next->pgd);
16978+#endif
16979
16980 /* Stop flush ipis for the previous mm */
16981 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16982@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16983 /* Load the LDT, if the LDT is different: */
16984 if (unlikely(prev->context.ldt != next->context.ldt))
16985 load_LDT_nolock(&next->context);
16986+
16987+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16988+ if (!(__supported_pte_mask & _PAGE_NX)) {
16989+ smp_mb__before_clear_bit();
16990+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16991+ smp_mb__after_clear_bit();
16992+ cpu_set(cpu, next->context.cpu_user_cs_mask);
16993+ }
16994+#endif
16995+
16996+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16997+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16998+ prev->context.user_cs_limit != next->context.user_cs_limit))
16999+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17000+#ifdef CONFIG_SMP
17001+ else if (unlikely(tlbstate != TLBSTATE_OK))
17002+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17003+#endif
17004+#endif
17005+
17006 }
17007+ else {
17008+
17009+#ifdef CONFIG_PAX_PER_CPU_PGD
17010+ pax_open_kernel();
17011+
17012+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17013+ if (static_cpu_has(X86_FEATURE_PCID))
17014+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17015+ else
17016+#endif
17017+
17018+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17019+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17020+ pax_close_kernel();
17021+ 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));
17022+
17023+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17024+ if (static_cpu_has(X86_FEATURE_PCID)) {
17025+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17026+ u64 descriptor[2];
17027+ descriptor[0] = PCID_USER;
17028+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17029+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17030+ descriptor[0] = PCID_KERNEL;
17031+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17032+ }
17033+ } else {
17034+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17035+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17036+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17037+ else
17038+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17039+ }
17040+ } else
17041+#endif
17042+
17043+ load_cr3(get_cpu_pgd(cpu, kernel));
17044+#endif
17045+
17046 #ifdef CONFIG_SMP
17047- else {
17048 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17049 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17050
17051@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17052 * tlb flush IPI delivery. We must reload CR3
17053 * to make sure to use no freed page tables.
17054 */
17055+
17056+#ifndef CONFIG_PAX_PER_CPU_PGD
17057 load_cr3(next->pgd);
17058+#endif
17059+
17060 load_LDT_nolock(&next->context);
17061+
17062+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17063+ if (!(__supported_pte_mask & _PAGE_NX))
17064+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17065+#endif
17066+
17067+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17068+#ifdef CONFIG_PAX_PAGEEXEC
17069+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17070+#endif
17071+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17072+#endif
17073+
17074 }
17075+#endif
17076 }
17077-#endif
17078 }
17079
17080 #define activate_mm(prev, next) \
17081diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17082index e3b7819..b257c64 100644
17083--- a/arch/x86/include/asm/module.h
17084+++ b/arch/x86/include/asm/module.h
17085@@ -5,6 +5,7 @@
17086
17087 #ifdef CONFIG_X86_64
17088 /* X86_64 does not define MODULE_PROC_FAMILY */
17089+#define MODULE_PROC_FAMILY ""
17090 #elif defined CONFIG_M486
17091 #define MODULE_PROC_FAMILY "486 "
17092 #elif defined CONFIG_M586
17093@@ -57,8 +58,20 @@
17094 #error unknown processor family
17095 #endif
17096
17097-#ifdef CONFIG_X86_32
17098-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17099+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17100+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17101+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17102+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17103+#else
17104+#define MODULE_PAX_KERNEXEC ""
17105 #endif
17106
17107+#ifdef CONFIG_PAX_MEMORY_UDEREF
17108+#define MODULE_PAX_UDEREF "UDEREF "
17109+#else
17110+#define MODULE_PAX_UDEREF ""
17111+#endif
17112+
17113+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17114+
17115 #endif /* _ASM_X86_MODULE_H */
17116diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17117index 86f9301..b365cda 100644
17118--- a/arch/x86/include/asm/nmi.h
17119+++ b/arch/x86/include/asm/nmi.h
17120@@ -40,11 +40,11 @@ struct nmiaction {
17121 nmi_handler_t handler;
17122 unsigned long flags;
17123 const char *name;
17124-};
17125+} __do_const;
17126
17127 #define register_nmi_handler(t, fn, fg, n, init...) \
17128 ({ \
17129- static struct nmiaction init fn##_na = { \
17130+ static const struct nmiaction init fn##_na = { \
17131 .handler = (fn), \
17132 .name = (n), \
17133 .flags = (fg), \
17134@@ -52,7 +52,7 @@ struct nmiaction {
17135 __register_nmi_handler((t), &fn##_na); \
17136 })
17137
17138-int __register_nmi_handler(unsigned int, struct nmiaction *);
17139+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17140
17141 void unregister_nmi_handler(unsigned int, const char *);
17142
17143diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17144index 775873d..de5f0304 100644
17145--- a/arch/x86/include/asm/page.h
17146+++ b/arch/x86/include/asm/page.h
17147@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17148 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17149
17150 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17151+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17152
17153 #define __boot_va(x) __va(x)
17154 #define __boot_pa(x) __pa(x)
17155diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17156index 0f1ddee..e2fc3d1 100644
17157--- a/arch/x86/include/asm/page_64.h
17158+++ b/arch/x86/include/asm/page_64.h
17159@@ -7,9 +7,9 @@
17160
17161 /* duplicated to the one in bootmem.h */
17162 extern unsigned long max_pfn;
17163-extern unsigned long phys_base;
17164+extern const unsigned long phys_base;
17165
17166-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17167+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17168 {
17169 unsigned long y = x - __START_KERNEL_map;
17170
17171diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17172index cd6e1610..70f4418 100644
17173--- a/arch/x86/include/asm/paravirt.h
17174+++ b/arch/x86/include/asm/paravirt.h
17175@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17176 return (pmd_t) { ret };
17177 }
17178
17179-static inline pmdval_t pmd_val(pmd_t pmd)
17180+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17181 {
17182 pmdval_t ret;
17183
17184@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17185 val);
17186 }
17187
17188+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17189+{
17190+ pgdval_t val = native_pgd_val(pgd);
17191+
17192+ if (sizeof(pgdval_t) > sizeof(long))
17193+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17194+ val, (u64)val >> 32);
17195+ else
17196+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17197+ val);
17198+}
17199+
17200 static inline void pgd_clear(pgd_t *pgdp)
17201 {
17202 set_pgd(pgdp, __pgd(0));
17203@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17204 pv_mmu_ops.set_fixmap(idx, phys, flags);
17205 }
17206
17207+#ifdef CONFIG_PAX_KERNEXEC
17208+static inline unsigned long pax_open_kernel(void)
17209+{
17210+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17211+}
17212+
17213+static inline unsigned long pax_close_kernel(void)
17214+{
17215+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17216+}
17217+#else
17218+static inline unsigned long pax_open_kernel(void) { return 0; }
17219+static inline unsigned long pax_close_kernel(void) { return 0; }
17220+#endif
17221+
17222 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17223
17224 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17225@@ -906,7 +933,7 @@ extern void default_banner(void);
17226
17227 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17228 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17229-#define PARA_INDIRECT(addr) *%cs:addr
17230+#define PARA_INDIRECT(addr) *%ss:addr
17231 #endif
17232
17233 #define INTERRUPT_RETURN \
17234@@ -981,6 +1008,21 @@ extern void default_banner(void);
17235 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17236 CLBR_NONE, \
17237 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17238+
17239+#define GET_CR0_INTO_RDI \
17240+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17241+ mov %rax,%rdi
17242+
17243+#define SET_RDI_INTO_CR0 \
17244+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17245+
17246+#define GET_CR3_INTO_RDI \
17247+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17248+ mov %rax,%rdi
17249+
17250+#define SET_RDI_INTO_CR3 \
17251+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17252+
17253 #endif /* CONFIG_X86_32 */
17254
17255 #endif /* __ASSEMBLY__ */
17256diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17257index 7549b8b..f0edfda 100644
17258--- a/arch/x86/include/asm/paravirt_types.h
17259+++ b/arch/x86/include/asm/paravirt_types.h
17260@@ -84,7 +84,7 @@ struct pv_init_ops {
17261 */
17262 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17263 unsigned long addr, unsigned len);
17264-};
17265+} __no_const __no_randomize_layout;
17266
17267
17268 struct pv_lazy_ops {
17269@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17270 void (*enter)(void);
17271 void (*leave)(void);
17272 void (*flush)(void);
17273-};
17274+} __no_randomize_layout;
17275
17276 struct pv_time_ops {
17277 unsigned long long (*sched_clock)(void);
17278 unsigned long long (*steal_clock)(int cpu);
17279 unsigned long (*get_tsc_khz)(void);
17280-};
17281+} __no_const __no_randomize_layout;
17282
17283 struct pv_cpu_ops {
17284 /* hooks for various privileged instructions */
17285@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17286
17287 void (*start_context_switch)(struct task_struct *prev);
17288 void (*end_context_switch)(struct task_struct *next);
17289-};
17290+} __no_const __no_randomize_layout;
17291
17292 struct pv_irq_ops {
17293 /*
17294@@ -215,7 +215,7 @@ struct pv_irq_ops {
17295 #ifdef CONFIG_X86_64
17296 void (*adjust_exception_frame)(void);
17297 #endif
17298-};
17299+} __no_randomize_layout;
17300
17301 struct pv_apic_ops {
17302 #ifdef CONFIG_X86_LOCAL_APIC
17303@@ -223,7 +223,7 @@ struct pv_apic_ops {
17304 unsigned long start_eip,
17305 unsigned long start_esp);
17306 #endif
17307-};
17308+} __no_const __no_randomize_layout;
17309
17310 struct pv_mmu_ops {
17311 unsigned long (*read_cr2)(void);
17312@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17313 struct paravirt_callee_save make_pud;
17314
17315 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17316+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17317 #endif /* PAGETABLE_LEVELS == 4 */
17318 #endif /* PAGETABLE_LEVELS >= 3 */
17319
17320@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17321 an mfn. We can tell which is which from the index. */
17322 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17323 phys_addr_t phys, pgprot_t flags);
17324-};
17325+
17326+#ifdef CONFIG_PAX_KERNEXEC
17327+ unsigned long (*pax_open_kernel)(void);
17328+ unsigned long (*pax_close_kernel)(void);
17329+#endif
17330+
17331+} __no_randomize_layout;
17332
17333 struct arch_spinlock;
17334 #ifdef CONFIG_SMP
17335@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17336 struct pv_lock_ops {
17337 struct paravirt_callee_save lock_spinning;
17338 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17339-};
17340+} __no_randomize_layout;
17341
17342 /* This contains all the paravirt structures: we get a convenient
17343 * number for each function using the offset which we use to indicate
17344- * what to patch. */
17345+ * what to patch.
17346+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17347+ */
17348+
17349 struct paravirt_patch_template {
17350 struct pv_init_ops pv_init_ops;
17351 struct pv_time_ops pv_time_ops;
17352@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17353 struct pv_apic_ops pv_apic_ops;
17354 struct pv_mmu_ops pv_mmu_ops;
17355 struct pv_lock_ops pv_lock_ops;
17356-};
17357+} __no_randomize_layout;
17358
17359 extern struct pv_info pv_info;
17360 extern struct pv_init_ops pv_init_ops;
17361diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17362index c4412e9..90e88c5 100644
17363--- a/arch/x86/include/asm/pgalloc.h
17364+++ b/arch/x86/include/asm/pgalloc.h
17365@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17366 pmd_t *pmd, pte_t *pte)
17367 {
17368 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17369+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17370+}
17371+
17372+static inline void pmd_populate_user(struct mm_struct *mm,
17373+ pmd_t *pmd, pte_t *pte)
17374+{
17375+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17376 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17377 }
17378
17379@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17380
17381 #ifdef CONFIG_X86_PAE
17382 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17383+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17384+{
17385+ pud_populate(mm, pudp, pmd);
17386+}
17387 #else /* !CONFIG_X86_PAE */
17388 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17389 {
17390 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17391 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17392 }
17393+
17394+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17395+{
17396+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17397+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17398+}
17399 #endif /* CONFIG_X86_PAE */
17400
17401 #if PAGETABLE_LEVELS > 3
17402@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17403 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17404 }
17405
17406+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17407+{
17408+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17409+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17410+}
17411+
17412 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17413 {
17414 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17415diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17416index 0d193e2..bf59aeb 100644
17417--- a/arch/x86/include/asm/pgtable-2level.h
17418+++ b/arch/x86/include/asm/pgtable-2level.h
17419@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17420
17421 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17422 {
17423+ pax_open_kernel();
17424 *pmdp = pmd;
17425+ pax_close_kernel();
17426 }
17427
17428 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17429diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17430index 81bb91b..9392125 100644
17431--- a/arch/x86/include/asm/pgtable-3level.h
17432+++ b/arch/x86/include/asm/pgtable-3level.h
17433@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17434
17435 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17436 {
17437+ pax_open_kernel();
17438 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17439+ pax_close_kernel();
17440 }
17441
17442 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17443 {
17444+ pax_open_kernel();
17445 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17446+ pax_close_kernel();
17447 }
17448
17449 /*
17450diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17451index bbc8b12..f228861 100644
17452--- a/arch/x86/include/asm/pgtable.h
17453+++ b/arch/x86/include/asm/pgtable.h
17454@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17455
17456 #ifndef __PAGETABLE_PUD_FOLDED
17457 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17458+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17459 #define pgd_clear(pgd) native_pgd_clear(pgd)
17460 #endif
17461
17462@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17463
17464 #define arch_end_context_switch(prev) do {} while(0)
17465
17466+#define pax_open_kernel() native_pax_open_kernel()
17467+#define pax_close_kernel() native_pax_close_kernel()
17468 #endif /* CONFIG_PARAVIRT */
17469
17470+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17471+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17472+
17473+#ifdef CONFIG_PAX_KERNEXEC
17474+static inline unsigned long native_pax_open_kernel(void)
17475+{
17476+ unsigned long cr0;
17477+
17478+ preempt_disable();
17479+ barrier();
17480+ cr0 = read_cr0() ^ X86_CR0_WP;
17481+ BUG_ON(cr0 & X86_CR0_WP);
17482+ write_cr0(cr0);
17483+ return cr0 ^ X86_CR0_WP;
17484+}
17485+
17486+static inline unsigned long native_pax_close_kernel(void)
17487+{
17488+ unsigned long cr0;
17489+
17490+ cr0 = read_cr0() ^ X86_CR0_WP;
17491+ BUG_ON(!(cr0 & X86_CR0_WP));
17492+ write_cr0(cr0);
17493+ barrier();
17494+ preempt_enable_no_resched();
17495+ return cr0 ^ X86_CR0_WP;
17496+}
17497+#else
17498+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17499+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17500+#endif
17501+
17502 /*
17503 * The following only work if pte_present() is true.
17504 * Undefined behaviour if not..
17505 */
17506+static inline int pte_user(pte_t pte)
17507+{
17508+ return pte_val(pte) & _PAGE_USER;
17509+}
17510+
17511 static inline int pte_dirty(pte_t pte)
17512 {
17513 return pte_flags(pte) & _PAGE_DIRTY;
17514@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17515 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17516 }
17517
17518+static inline unsigned long pgd_pfn(pgd_t pgd)
17519+{
17520+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17521+}
17522+
17523 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17524
17525 static inline int pmd_large(pmd_t pte)
17526@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17527 return pte_clear_flags(pte, _PAGE_RW);
17528 }
17529
17530+static inline pte_t pte_mkread(pte_t pte)
17531+{
17532+ return __pte(pte_val(pte) | _PAGE_USER);
17533+}
17534+
17535 static inline pte_t pte_mkexec(pte_t pte)
17536 {
17537- return pte_clear_flags(pte, _PAGE_NX);
17538+#ifdef CONFIG_X86_PAE
17539+ if (__supported_pte_mask & _PAGE_NX)
17540+ return pte_clear_flags(pte, _PAGE_NX);
17541+ else
17542+#endif
17543+ return pte_set_flags(pte, _PAGE_USER);
17544+}
17545+
17546+static inline pte_t pte_exprotect(pte_t pte)
17547+{
17548+#ifdef CONFIG_X86_PAE
17549+ if (__supported_pte_mask & _PAGE_NX)
17550+ return pte_set_flags(pte, _PAGE_NX);
17551+ else
17552+#endif
17553+ return pte_clear_flags(pte, _PAGE_USER);
17554 }
17555
17556 static inline pte_t pte_mkdirty(pte_t pte)
17557@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17558 #endif
17559
17560 #ifndef __ASSEMBLY__
17561+
17562+#ifdef CONFIG_PAX_PER_CPU_PGD
17563+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17564+enum cpu_pgd_type {kernel = 0, user = 1};
17565+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17566+{
17567+ return cpu_pgd[cpu][type];
17568+}
17569+#endif
17570+
17571 #include <linux/mm_types.h>
17572 #include <linux/mmdebug.h>
17573 #include <linux/log2.h>
17574@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17575 * Currently stuck as a macro due to indirect forward reference to
17576 * linux/mmzone.h's __section_mem_map_addr() definition:
17577 */
17578-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17579+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17580
17581 /* Find an entry in the second-level page table.. */
17582 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17583@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17584 * Currently stuck as a macro due to indirect forward reference to
17585 * linux/mmzone.h's __section_mem_map_addr() definition:
17586 */
17587-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17588+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17589
17590 /* to find an entry in a page-table-directory. */
17591 static inline unsigned long pud_index(unsigned long address)
17592@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17593
17594 static inline int pgd_bad(pgd_t pgd)
17595 {
17596- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17597+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17598 }
17599
17600 static inline int pgd_none(pgd_t pgd)
17601@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17602 * pgd_offset() returns a (pgd_t *)
17603 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17604 */
17605-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17606+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17607+
17608+#ifdef CONFIG_PAX_PER_CPU_PGD
17609+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17610+#endif
17611+
17612 /*
17613 * a shortcut which implies the use of the kernel's pgd, instead
17614 * of a process's
17615@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17616 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17617 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17618
17619+#ifdef CONFIG_X86_32
17620+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17621+#else
17622+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17623+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17624+
17625+#ifdef CONFIG_PAX_MEMORY_UDEREF
17626+#ifdef __ASSEMBLY__
17627+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17628+#else
17629+extern unsigned long pax_user_shadow_base;
17630+extern pgdval_t clone_pgd_mask;
17631+#endif
17632+#endif
17633+
17634+#endif
17635+
17636 #ifndef __ASSEMBLY__
17637
17638 extern int direct_gbpages;
17639@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17640 * dst and src can be on the same page, but the range must not overlap,
17641 * and must not cross a page boundary.
17642 */
17643-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17644+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17645 {
17646- memcpy(dst, src, count * sizeof(pgd_t));
17647+ pax_open_kernel();
17648+ while (count--)
17649+ *dst++ = *src++;
17650+ pax_close_kernel();
17651 }
17652
17653+#ifdef CONFIG_PAX_PER_CPU_PGD
17654+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17655+#endif
17656+
17657+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17658+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17659+#else
17660+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17661+#endif
17662+
17663 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17664 static inline int page_level_shift(enum pg_level level)
17665 {
17666diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17667index 9ee3221..b979c6b 100644
17668--- a/arch/x86/include/asm/pgtable_32.h
17669+++ b/arch/x86/include/asm/pgtable_32.h
17670@@ -25,9 +25,6 @@
17671 struct mm_struct;
17672 struct vm_area_struct;
17673
17674-extern pgd_t swapper_pg_dir[1024];
17675-extern pgd_t initial_page_table[1024];
17676-
17677 static inline void pgtable_cache_init(void) { }
17678 static inline void check_pgt_cache(void) { }
17679 void paging_init(void);
17680@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17681 # include <asm/pgtable-2level.h>
17682 #endif
17683
17684+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17685+extern pgd_t initial_page_table[PTRS_PER_PGD];
17686+#ifdef CONFIG_X86_PAE
17687+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17688+#endif
17689+
17690 #if defined(CONFIG_HIGHPTE)
17691 #define pte_offset_map(dir, address) \
17692 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17693@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17694 /* Clear a kernel PTE and flush it from the TLB */
17695 #define kpte_clear_flush(ptep, vaddr) \
17696 do { \
17697+ pax_open_kernel(); \
17698 pte_clear(&init_mm, (vaddr), (ptep)); \
17699+ pax_close_kernel(); \
17700 __flush_tlb_one((vaddr)); \
17701 } while (0)
17702
17703 #endif /* !__ASSEMBLY__ */
17704
17705+#define HAVE_ARCH_UNMAPPED_AREA
17706+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17707+
17708 /*
17709 * kern_addr_valid() is (1) for FLATMEM and (0) for
17710 * SPARSEMEM and DISCONTIGMEM
17711diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17712index ed5903b..c7fe163 100644
17713--- a/arch/x86/include/asm/pgtable_32_types.h
17714+++ b/arch/x86/include/asm/pgtable_32_types.h
17715@@ -8,7 +8,7 @@
17716 */
17717 #ifdef CONFIG_X86_PAE
17718 # include <asm/pgtable-3level_types.h>
17719-# define PMD_SIZE (1UL << PMD_SHIFT)
17720+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17721 # define PMD_MASK (~(PMD_SIZE - 1))
17722 #else
17723 # include <asm/pgtable-2level_types.h>
17724@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17725 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17726 #endif
17727
17728+#ifdef CONFIG_PAX_KERNEXEC
17729+#ifndef __ASSEMBLY__
17730+extern unsigned char MODULES_EXEC_VADDR[];
17731+extern unsigned char MODULES_EXEC_END[];
17732+#endif
17733+#include <asm/boot.h>
17734+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17735+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17736+#else
17737+#define ktla_ktva(addr) (addr)
17738+#define ktva_ktla(addr) (addr)
17739+#endif
17740+
17741 #define MODULES_VADDR VMALLOC_START
17742 #define MODULES_END VMALLOC_END
17743 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17744diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17745index e22c1db..23a625a 100644
17746--- a/arch/x86/include/asm/pgtable_64.h
17747+++ b/arch/x86/include/asm/pgtable_64.h
17748@@ -16,10 +16,14 @@
17749
17750 extern pud_t level3_kernel_pgt[512];
17751 extern pud_t level3_ident_pgt[512];
17752+extern pud_t level3_vmalloc_start_pgt[512];
17753+extern pud_t level3_vmalloc_end_pgt[512];
17754+extern pud_t level3_vmemmap_pgt[512];
17755+extern pud_t level2_vmemmap_pgt[512];
17756 extern pmd_t level2_kernel_pgt[512];
17757 extern pmd_t level2_fixmap_pgt[512];
17758-extern pmd_t level2_ident_pgt[512];
17759-extern pgd_t init_level4_pgt[];
17760+extern pmd_t level2_ident_pgt[512*2];
17761+extern pgd_t init_level4_pgt[512];
17762
17763 #define swapper_pg_dir init_level4_pgt
17764
17765@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17766
17767 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17768 {
17769+ pax_open_kernel();
17770 *pmdp = pmd;
17771+ pax_close_kernel();
17772 }
17773
17774 static inline void native_pmd_clear(pmd_t *pmd)
17775@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17776
17777 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17778 {
17779+ pax_open_kernel();
17780 *pudp = pud;
17781+ pax_close_kernel();
17782 }
17783
17784 static inline void native_pud_clear(pud_t *pud)
17785@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17786
17787 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17788 {
17789+ pax_open_kernel();
17790+ *pgdp = pgd;
17791+ pax_close_kernel();
17792+}
17793+
17794+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17795+{
17796 *pgdp = pgd;
17797 }
17798
17799diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17800index c883bf7..19970b3 100644
17801--- a/arch/x86/include/asm/pgtable_64_types.h
17802+++ b/arch/x86/include/asm/pgtable_64_types.h
17803@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17804 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17805 #define MODULES_END _AC(0xffffffffff000000, UL)
17806 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17807+#define MODULES_EXEC_VADDR MODULES_VADDR
17808+#define MODULES_EXEC_END MODULES_END
17809+
17810+#define ktla_ktva(addr) (addr)
17811+#define ktva_ktla(addr) (addr)
17812
17813 #define EARLY_DYNAMIC_PAGE_TABLES 64
17814
17815diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17816index 94e40f1..ebd03e4 100644
17817--- a/arch/x86/include/asm/pgtable_types.h
17818+++ b/arch/x86/include/asm/pgtable_types.h
17819@@ -16,13 +16,12 @@
17820 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17821 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17822 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17823-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17824+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17825 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17826 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17827 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17828-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17829-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17830-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17831+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17832+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17833 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17834
17835 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17836@@ -40,7 +39,6 @@
17837 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17838 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17839 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17840-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17841 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17842 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17843 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17844@@ -87,8 +85,10 @@
17845
17846 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17847 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17848-#else
17849+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17850 #define _PAGE_NX (_AT(pteval_t, 0))
17851+#else
17852+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17853 #endif
17854
17855 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17856@@ -147,6 +147,9 @@
17857 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17858 _PAGE_ACCESSED)
17859
17860+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17861+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17862+
17863 #define __PAGE_KERNEL_EXEC \
17864 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17865 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17866@@ -157,7 +160,7 @@
17867 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17868 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17869 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17870-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17871+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17872 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17873 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17874 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17875@@ -219,8 +222,8 @@
17876 * bits are combined, this will alow user to access the high address mapped
17877 * VDSO in the presence of CONFIG_COMPAT_VDSO
17878 */
17879-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17880-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17881+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17882+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17883 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17884 #endif
17885
17886@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17887 {
17888 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17889 }
17890+#endif
17891
17892+#if PAGETABLE_LEVELS == 3
17893+#include <asm-generic/pgtable-nopud.h>
17894+#endif
17895+
17896+#if PAGETABLE_LEVELS == 2
17897+#include <asm-generic/pgtable-nopmd.h>
17898+#endif
17899+
17900+#ifndef __ASSEMBLY__
17901 #if PAGETABLE_LEVELS > 3
17902 typedef struct { pudval_t pud; } pud_t;
17903
17904@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17905 return pud.pud;
17906 }
17907 #else
17908-#include <asm-generic/pgtable-nopud.h>
17909-
17910 static inline pudval_t native_pud_val(pud_t pud)
17911 {
17912 return native_pgd_val(pud.pgd);
17913@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17914 return pmd.pmd;
17915 }
17916 #else
17917-#include <asm-generic/pgtable-nopmd.h>
17918-
17919 static inline pmdval_t native_pmd_val(pmd_t pmd)
17920 {
17921 return native_pgd_val(pmd.pud.pgd);
17922@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17923
17924 extern pteval_t __supported_pte_mask;
17925 extern void set_nx(void);
17926-extern int nx_enabled;
17927
17928 #define pgprot_writecombine pgprot_writecombine
17929 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17930diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17931index c8b0519..fd29e73 100644
17932--- a/arch/x86/include/asm/preempt.h
17933+++ b/arch/x86/include/asm/preempt.h
17934@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17935 */
17936 static __always_inline bool __preempt_count_dec_and_test(void)
17937 {
17938- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17939+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17940 }
17941
17942 /*
17943diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17944index fdedd38..95c02c2 100644
17945--- a/arch/x86/include/asm/processor.h
17946+++ b/arch/x86/include/asm/processor.h
17947@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17948 /* Index into per_cpu list: */
17949 u16 cpu_index;
17950 u32 microcode;
17951-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17952+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17953
17954 #define X86_VENDOR_INTEL 0
17955 #define X86_VENDOR_CYRIX 1
17956@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17957 : "memory");
17958 }
17959
17960+/* invpcid (%rdx),%rax */
17961+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17962+
17963+#define INVPCID_SINGLE_ADDRESS 0UL
17964+#define INVPCID_SINGLE_CONTEXT 1UL
17965+#define INVPCID_ALL_GLOBAL 2UL
17966+#define INVPCID_ALL_MONGLOBAL 3UL
17967+
17968+#define PCID_KERNEL 0UL
17969+#define PCID_USER 1UL
17970+#define PCID_NOFLUSH (1UL << 63)
17971+
17972 static inline void load_cr3(pgd_t *pgdir)
17973 {
17974- write_cr3(__pa(pgdir));
17975+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17976 }
17977
17978 #ifdef CONFIG_X86_32
17979@@ -283,7 +295,7 @@ struct tss_struct {
17980
17981 } ____cacheline_aligned;
17982
17983-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17984+extern struct tss_struct init_tss[NR_CPUS];
17985
17986 /*
17987 * Save the original ist values for checking stack pointers during debugging
17988@@ -470,6 +482,7 @@ struct thread_struct {
17989 unsigned short ds;
17990 unsigned short fsindex;
17991 unsigned short gsindex;
17992+ unsigned short ss;
17993 #endif
17994 #ifdef CONFIG_X86_32
17995 unsigned long ip;
17996@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
17997 extern unsigned long mmu_cr4_features;
17998 extern u32 *trampoline_cr4_features;
17999
18000-static inline void set_in_cr4(unsigned long mask)
18001-{
18002- unsigned long cr4;
18003-
18004- mmu_cr4_features |= mask;
18005- if (trampoline_cr4_features)
18006- *trampoline_cr4_features = mmu_cr4_features;
18007- cr4 = read_cr4();
18008- cr4 |= mask;
18009- write_cr4(cr4);
18010-}
18011-
18012-static inline void clear_in_cr4(unsigned long mask)
18013-{
18014- unsigned long cr4;
18015-
18016- mmu_cr4_features &= ~mask;
18017- if (trampoline_cr4_features)
18018- *trampoline_cr4_features = mmu_cr4_features;
18019- cr4 = read_cr4();
18020- cr4 &= ~mask;
18021- write_cr4(cr4);
18022-}
18023+extern void set_in_cr4(unsigned long mask);
18024+extern void clear_in_cr4(unsigned long mask);
18025
18026 typedef struct {
18027 unsigned long seg;
18028@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18029 */
18030 #define TASK_SIZE PAGE_OFFSET
18031 #define TASK_SIZE_MAX TASK_SIZE
18032+
18033+#ifdef CONFIG_PAX_SEGMEXEC
18034+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18035+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18036+#else
18037 #define STACK_TOP TASK_SIZE
18038-#define STACK_TOP_MAX STACK_TOP
18039+#endif
18040+
18041+#define STACK_TOP_MAX TASK_SIZE
18042
18043 #define INIT_THREAD { \
18044- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18045+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18046 .vm86_info = NULL, \
18047 .sysenter_cs = __KERNEL_CS, \
18048 .io_bitmap_ptr = NULL, \
18049@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18050 */
18051 #define INIT_TSS { \
18052 .x86_tss = { \
18053- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18054+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18055 .ss0 = __KERNEL_DS, \
18056 .ss1 = __KERNEL_CS, \
18057 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18058@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18059 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18060
18061 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18062-#define KSTK_TOP(info) \
18063-({ \
18064- unsigned long *__ptr = (unsigned long *)(info); \
18065- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18066-})
18067+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18068
18069 /*
18070 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18071@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18072 #define task_pt_regs(task) \
18073 ({ \
18074 struct pt_regs *__regs__; \
18075- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18076+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18077 __regs__ - 1; \
18078 })
18079
18080@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18081 /*
18082 * User space process size. 47bits minus one guard page.
18083 */
18084-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18085+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18086
18087 /* This decides where the kernel will search for a free chunk of vm
18088 * space during mmap's.
18089 */
18090 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18091- 0xc0000000 : 0xFFFFe000)
18092+ 0xc0000000 : 0xFFFFf000)
18093
18094 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18095 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18096@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18097 #define STACK_TOP_MAX TASK_SIZE_MAX
18098
18099 #define INIT_THREAD { \
18100- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18101+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18102 }
18103
18104 #define INIT_TSS { \
18105- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18106+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18107 }
18108
18109 /*
18110@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18111 */
18112 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18113
18114+#ifdef CONFIG_PAX_SEGMEXEC
18115+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18116+#endif
18117+
18118 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18119
18120 /* Get/set a process' ability to use the timestamp counter instruction */
18121@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18122 return 0;
18123 }
18124
18125-extern unsigned long arch_align_stack(unsigned long sp);
18126+#define arch_align_stack(x) ((x) & ~0xfUL)
18127 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18128
18129 void default_idle(void);
18130@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18131 #define xen_set_default_idle 0
18132 #endif
18133
18134-void stop_this_cpu(void *dummy);
18135+void stop_this_cpu(void *dummy) __noreturn;
18136 void df_debug(struct pt_regs *regs, long error_code);
18137 #endif /* _ASM_X86_PROCESSOR_H */
18138diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18139index 14fd6fd..6740420 100644
18140--- a/arch/x86/include/asm/ptrace.h
18141+++ b/arch/x86/include/asm/ptrace.h
18142@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18143 }
18144
18145 /*
18146- * user_mode_vm(regs) determines whether a register set came from user mode.
18147+ * user_mode(regs) determines whether a register set came from user mode.
18148 * This is true if V8086 mode was enabled OR if the register set was from
18149 * protected mode with RPL-3 CS value. This tricky test checks that with
18150 * one comparison. Many places in the kernel can bypass this full check
18151- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18152+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18153+ * be used.
18154 */
18155-static inline int user_mode(struct pt_regs *regs)
18156+static inline int user_mode_novm(struct pt_regs *regs)
18157 {
18158 #ifdef CONFIG_X86_32
18159 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18160 #else
18161- return !!(regs->cs & 3);
18162+ return !!(regs->cs & SEGMENT_RPL_MASK);
18163 #endif
18164 }
18165
18166-static inline int user_mode_vm(struct pt_regs *regs)
18167+static inline int user_mode(struct pt_regs *regs)
18168 {
18169 #ifdef CONFIG_X86_32
18170 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18171 USER_RPL;
18172 #else
18173- return user_mode(regs);
18174+ return user_mode_novm(regs);
18175 #endif
18176 }
18177
18178@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18179 #ifdef CONFIG_X86_64
18180 static inline bool user_64bit_mode(struct pt_regs *regs)
18181 {
18182+ unsigned long cs = regs->cs & 0xffff;
18183 #ifndef CONFIG_PARAVIRT
18184 /*
18185 * On non-paravirt systems, this is the only long mode CPL 3
18186 * selector. We do not allow long mode selectors in the LDT.
18187 */
18188- return regs->cs == __USER_CS;
18189+ return cs == __USER_CS;
18190 #else
18191 /* Headers are too twisted for this to go in paravirt.h. */
18192- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18193+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18194 #endif
18195 }
18196
18197@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18198 * Traps from the kernel do not save sp and ss.
18199 * Use the helper function to retrieve sp.
18200 */
18201- if (offset == offsetof(struct pt_regs, sp) &&
18202- regs->cs == __KERNEL_CS)
18203- return kernel_stack_pointer(regs);
18204+ if (offset == offsetof(struct pt_regs, sp)) {
18205+ unsigned long cs = regs->cs & 0xffff;
18206+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18207+ return kernel_stack_pointer(regs);
18208+ }
18209 #endif
18210 return *(unsigned long *)((unsigned long)regs + offset);
18211 }
18212diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18213index 9c6b890..5305f53 100644
18214--- a/arch/x86/include/asm/realmode.h
18215+++ b/arch/x86/include/asm/realmode.h
18216@@ -22,16 +22,14 @@ struct real_mode_header {
18217 #endif
18218 /* APM/BIOS reboot */
18219 u32 machine_real_restart_asm;
18220-#ifdef CONFIG_X86_64
18221 u32 machine_real_restart_seg;
18222-#endif
18223 };
18224
18225 /* This must match data at trampoline_32/64.S */
18226 struct trampoline_header {
18227 #ifdef CONFIG_X86_32
18228 u32 start;
18229- u16 gdt_pad;
18230+ u16 boot_cs;
18231 u16 gdt_limit;
18232 u32 gdt_base;
18233 #else
18234diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18235index a82c4f1..ac45053 100644
18236--- a/arch/x86/include/asm/reboot.h
18237+++ b/arch/x86/include/asm/reboot.h
18238@@ -6,13 +6,13 @@
18239 struct pt_regs;
18240
18241 struct machine_ops {
18242- void (*restart)(char *cmd);
18243- void (*halt)(void);
18244- void (*power_off)(void);
18245+ void (* __noreturn restart)(char *cmd);
18246+ void (* __noreturn halt)(void);
18247+ void (* __noreturn power_off)(void);
18248 void (*shutdown)(void);
18249 void (*crash_shutdown)(struct pt_regs *);
18250- void (*emergency_restart)(void);
18251-};
18252+ void (* __noreturn emergency_restart)(void);
18253+} __no_const;
18254
18255 extern struct machine_ops machine_ops;
18256
18257diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18258index 8f7866a..e442f20 100644
18259--- a/arch/x86/include/asm/rmwcc.h
18260+++ b/arch/x86/include/asm/rmwcc.h
18261@@ -3,7 +3,34 @@
18262
18263 #ifdef CC_HAVE_ASM_GOTO
18264
18265-#define __GEN_RMWcc(fullop, var, cc, ...) \
18266+#ifdef CONFIG_PAX_REFCOUNT
18267+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18268+do { \
18269+ asm_volatile_goto (fullop \
18270+ ";jno 0f\n" \
18271+ fullantiop \
18272+ ";int $4\n0:\n" \
18273+ _ASM_EXTABLE(0b, 0b) \
18274+ ";j" cc " %l[cc_label]" \
18275+ : : "m" (var), ## __VA_ARGS__ \
18276+ : "memory" : cc_label); \
18277+ return 0; \
18278+cc_label: \
18279+ return 1; \
18280+} while (0)
18281+#else
18282+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18283+do { \
18284+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18285+ : : "m" (var), ## __VA_ARGS__ \
18286+ : "memory" : cc_label); \
18287+ return 0; \
18288+cc_label: \
18289+ return 1; \
18290+} while (0)
18291+#endif
18292+
18293+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18294 do { \
18295 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18296 : : "m" (var), ## __VA_ARGS__ \
18297@@ -13,15 +40,46 @@ cc_label: \
18298 return 1; \
18299 } while (0)
18300
18301-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18302- __GEN_RMWcc(op " " arg0, var, cc)
18303+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18304+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18305
18306-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18307- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18308+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18309+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18310+
18311+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18312+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18313+
18314+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18315+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18316
18317 #else /* !CC_HAVE_ASM_GOTO */
18318
18319-#define __GEN_RMWcc(fullop, var, cc, ...) \
18320+#ifdef CONFIG_PAX_REFCOUNT
18321+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18322+do { \
18323+ char c; \
18324+ asm volatile (fullop \
18325+ ";jno 0f\n" \
18326+ fullantiop \
18327+ ";int $4\n0:\n" \
18328+ _ASM_EXTABLE(0b, 0b) \
18329+ "; set" cc " %1" \
18330+ : "+m" (var), "=qm" (c) \
18331+ : __VA_ARGS__ : "memory"); \
18332+ return c != 0; \
18333+} while (0)
18334+#else
18335+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18336+do { \
18337+ char c; \
18338+ asm volatile (fullop "; set" cc " %1" \
18339+ : "+m" (var), "=qm" (c) \
18340+ : __VA_ARGS__ : "memory"); \
18341+ return c != 0; \
18342+} while (0)
18343+#endif
18344+
18345+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18346 do { \
18347 char c; \
18348 asm volatile (fullop "; set" cc " %1" \
18349@@ -30,11 +88,17 @@ do { \
18350 return c != 0; \
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_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18359+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18360+
18361+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18362+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18363
18364-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18365- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18366+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18367+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18368
18369 #endif /* CC_HAVE_ASM_GOTO */
18370
18371diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18372index cad82c9..2e5c5c1 100644
18373--- a/arch/x86/include/asm/rwsem.h
18374+++ b/arch/x86/include/asm/rwsem.h
18375@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18376 {
18377 asm volatile("# beginning down_read\n\t"
18378 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18379+
18380+#ifdef CONFIG_PAX_REFCOUNT
18381+ "jno 0f\n"
18382+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18383+ "int $4\n0:\n"
18384+ _ASM_EXTABLE(0b, 0b)
18385+#endif
18386+
18387 /* adds 0x00000001 */
18388 " jns 1f\n"
18389 " call call_rwsem_down_read_failed\n"
18390@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18391 "1:\n\t"
18392 " mov %1,%2\n\t"
18393 " add %3,%2\n\t"
18394+
18395+#ifdef CONFIG_PAX_REFCOUNT
18396+ "jno 0f\n"
18397+ "sub %3,%2\n"
18398+ "int $4\n0:\n"
18399+ _ASM_EXTABLE(0b, 0b)
18400+#endif
18401+
18402 " jle 2f\n\t"
18403 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18404 " jnz 1b\n\t"
18405@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18406 long tmp;
18407 asm volatile("# beginning down_write\n\t"
18408 LOCK_PREFIX " xadd %1,(%2)\n\t"
18409+
18410+#ifdef CONFIG_PAX_REFCOUNT
18411+ "jno 0f\n"
18412+ "mov %1,(%2)\n"
18413+ "int $4\n0:\n"
18414+ _ASM_EXTABLE(0b, 0b)
18415+#endif
18416+
18417 /* adds 0xffff0001, returns the old value */
18418 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18419 /* was the active mask 0 before? */
18420@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18421 long tmp;
18422 asm volatile("# beginning __up_read\n\t"
18423 LOCK_PREFIX " xadd %1,(%2)\n\t"
18424+
18425+#ifdef CONFIG_PAX_REFCOUNT
18426+ "jno 0f\n"
18427+ "mov %1,(%2)\n"
18428+ "int $4\n0:\n"
18429+ _ASM_EXTABLE(0b, 0b)
18430+#endif
18431+
18432 /* subtracts 1, returns the old value */
18433 " jns 1f\n\t"
18434 " call call_rwsem_wake\n" /* expects old value in %edx */
18435@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18436 long tmp;
18437 asm volatile("# beginning __up_write\n\t"
18438 LOCK_PREFIX " xadd %1,(%2)\n\t"
18439+
18440+#ifdef CONFIG_PAX_REFCOUNT
18441+ "jno 0f\n"
18442+ "mov %1,(%2)\n"
18443+ "int $4\n0:\n"
18444+ _ASM_EXTABLE(0b, 0b)
18445+#endif
18446+
18447 /* subtracts 0xffff0001, returns the old value */
18448 " jns 1f\n\t"
18449 " call call_rwsem_wake\n" /* expects old value in %edx */
18450@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18451 {
18452 asm volatile("# beginning __downgrade_write\n\t"
18453 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18454+
18455+#ifdef CONFIG_PAX_REFCOUNT
18456+ "jno 0f\n"
18457+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18458+ "int $4\n0:\n"
18459+ _ASM_EXTABLE(0b, 0b)
18460+#endif
18461+
18462 /*
18463 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18464 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18465@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18466 */
18467 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18468 {
18469- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18470+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18471+
18472+#ifdef CONFIG_PAX_REFCOUNT
18473+ "jno 0f\n"
18474+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18475+ "int $4\n0:\n"
18476+ _ASM_EXTABLE(0b, 0b)
18477+#endif
18478+
18479 : "+m" (sem->count)
18480 : "er" (delta));
18481 }
18482@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18483 */
18484 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18485 {
18486- return delta + xadd(&sem->count, delta);
18487+ return delta + xadd_check_overflow(&sem->count, delta);
18488 }
18489
18490 #endif /* __KERNEL__ */
18491diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18492index 6f1c3a8..7744f19 100644
18493--- a/arch/x86/include/asm/segment.h
18494+++ b/arch/x86/include/asm/segment.h
18495@@ -64,10 +64,15 @@
18496 * 26 - ESPFIX small SS
18497 * 27 - per-cpu [ offset to per-cpu data area ]
18498 * 28 - stack_canary-20 [ for stack protector ]
18499- * 29 - unused
18500- * 30 - unused
18501+ * 29 - PCI BIOS CS
18502+ * 30 - PCI BIOS DS
18503 * 31 - TSS for double fault handler
18504 */
18505+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18506+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18507+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18508+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18509+
18510 #define GDT_ENTRY_TLS_MIN 6
18511 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18512
18513@@ -79,6 +84,8 @@
18514
18515 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18516
18517+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18518+
18519 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18520
18521 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18522@@ -104,6 +111,12 @@
18523 #define __KERNEL_STACK_CANARY 0
18524 #endif
18525
18526+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18527+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18528+
18529+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18530+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18531+
18532 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18533
18534 /*
18535@@ -141,7 +154,7 @@
18536 */
18537
18538 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18539-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18540+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18541
18542
18543 #else
18544@@ -165,6 +178,8 @@
18545 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18546 #define __USER32_DS __USER_DS
18547
18548+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18549+
18550 #define GDT_ENTRY_TSS 8 /* needs two entries */
18551 #define GDT_ENTRY_LDT 10 /* needs two entries */
18552 #define GDT_ENTRY_TLS_MIN 12
18553@@ -173,6 +188,8 @@
18554 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18555 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18556
18557+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18558+
18559 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18560 #define FS_TLS 0
18561 #define GS_TLS 1
18562@@ -180,12 +197,14 @@
18563 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18564 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18565
18566-#define GDT_ENTRIES 16
18567+#define GDT_ENTRIES 17
18568
18569 #endif
18570
18571 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18572+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18573 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18574+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18575 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18576 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18577 #ifndef CONFIG_PARAVIRT
18578@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18579 {
18580 unsigned long __limit;
18581 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18582- return __limit + 1;
18583+ return __limit;
18584 }
18585
18586 #endif /* !__ASSEMBLY__ */
18587diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18588index 8d3120f..352b440 100644
18589--- a/arch/x86/include/asm/smap.h
18590+++ b/arch/x86/include/asm/smap.h
18591@@ -25,11 +25,40 @@
18592
18593 #include <asm/alternative-asm.h>
18594
18595+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18596+#define ASM_PAX_OPEN_USERLAND \
18597+ 661: jmp 663f; \
18598+ .pushsection .altinstr_replacement, "a" ; \
18599+ 662: pushq %rax; nop; \
18600+ .popsection ; \
18601+ .pushsection .altinstructions, "a" ; \
18602+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18603+ .popsection ; \
18604+ call __pax_open_userland; \
18605+ popq %rax; \
18606+ 663:
18607+
18608+#define ASM_PAX_CLOSE_USERLAND \
18609+ 661: jmp 663f; \
18610+ .pushsection .altinstr_replacement, "a" ; \
18611+ 662: pushq %rax; nop; \
18612+ .popsection; \
18613+ .pushsection .altinstructions, "a" ; \
18614+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18615+ .popsection; \
18616+ call __pax_close_userland; \
18617+ popq %rax; \
18618+ 663:
18619+#else
18620+#define ASM_PAX_OPEN_USERLAND
18621+#define ASM_PAX_CLOSE_USERLAND
18622+#endif
18623+
18624 #ifdef CONFIG_X86_SMAP
18625
18626 #define ASM_CLAC \
18627 661: ASM_NOP3 ; \
18628- .pushsection .altinstr_replacement, "ax" ; \
18629+ .pushsection .altinstr_replacement, "a" ; \
18630 662: __ASM_CLAC ; \
18631 .popsection ; \
18632 .pushsection .altinstructions, "a" ; \
18633@@ -38,7 +67,7 @@
18634
18635 #define ASM_STAC \
18636 661: ASM_NOP3 ; \
18637- .pushsection .altinstr_replacement, "ax" ; \
18638+ .pushsection .altinstr_replacement, "a" ; \
18639 662: __ASM_STAC ; \
18640 .popsection ; \
18641 .pushsection .altinstructions, "a" ; \
18642@@ -56,6 +85,37 @@
18643
18644 #include <asm/alternative.h>
18645
18646+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18647+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18648+
18649+extern void __pax_open_userland(void);
18650+static __always_inline unsigned long pax_open_userland(void)
18651+{
18652+
18653+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18654+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18655+ :
18656+ : [open] "i" (__pax_open_userland)
18657+ : "memory", "rax");
18658+#endif
18659+
18660+ return 0;
18661+}
18662+
18663+extern void __pax_close_userland(void);
18664+static __always_inline unsigned long pax_close_userland(void)
18665+{
18666+
18667+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18668+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18669+ :
18670+ : [close] "i" (__pax_close_userland)
18671+ : "memory", "rax");
18672+#endif
18673+
18674+ return 0;
18675+}
18676+
18677 #ifdef CONFIG_X86_SMAP
18678
18679 static __always_inline void clac(void)
18680diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18681index 8cd27e0..7f05ec8 100644
18682--- a/arch/x86/include/asm/smp.h
18683+++ b/arch/x86/include/asm/smp.h
18684@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18685 /* cpus sharing the last level cache: */
18686 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18687 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18688-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18689+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18690
18691 static inline struct cpumask *cpu_sibling_mask(int cpu)
18692 {
18693@@ -78,7 +78,7 @@ struct smp_ops {
18694
18695 void (*send_call_func_ipi)(const struct cpumask *mask);
18696 void (*send_call_func_single_ipi)(int cpu);
18697-};
18698+} __no_const;
18699
18700 /* Globals due to paravirt */
18701 extern void set_cpu_sibling_map(int cpu);
18702@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18703 extern int safe_smp_processor_id(void);
18704
18705 #elif defined(CONFIG_X86_64_SMP)
18706-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18707-
18708-#define stack_smp_processor_id() \
18709-({ \
18710- struct thread_info *ti; \
18711- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18712- ti->cpu; \
18713-})
18714+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18715+#define stack_smp_processor_id() raw_smp_processor_id()
18716 #define safe_smp_processor_id() smp_processor_id()
18717
18718 #endif
18719diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18720index 0f62f54..cb5d0dd 100644
18721--- a/arch/x86/include/asm/spinlock.h
18722+++ b/arch/x86/include/asm/spinlock.h
18723@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18724 static inline void arch_read_lock(arch_rwlock_t *rw)
18725 {
18726 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18727+
18728+#ifdef CONFIG_PAX_REFCOUNT
18729+ "jno 0f\n"
18730+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18731+ "int $4\n0:\n"
18732+ _ASM_EXTABLE(0b, 0b)
18733+#endif
18734+
18735 "jns 1f\n"
18736 "call __read_lock_failed\n\t"
18737 "1:\n"
18738@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18739 static inline void arch_write_lock(arch_rwlock_t *rw)
18740 {
18741 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18742+
18743+#ifdef CONFIG_PAX_REFCOUNT
18744+ "jno 0f\n"
18745+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18746+ "int $4\n0:\n"
18747+ _ASM_EXTABLE(0b, 0b)
18748+#endif
18749+
18750 "jz 1f\n"
18751 "call __write_lock_failed\n\t"
18752 "1:\n"
18753@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18754
18755 static inline void arch_read_unlock(arch_rwlock_t *rw)
18756 {
18757- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18758+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18759+
18760+#ifdef CONFIG_PAX_REFCOUNT
18761+ "jno 0f\n"
18762+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18763+ "int $4\n0:\n"
18764+ _ASM_EXTABLE(0b, 0b)
18765+#endif
18766+
18767 :"+m" (rw->lock) : : "memory");
18768 }
18769
18770 static inline void arch_write_unlock(arch_rwlock_t *rw)
18771 {
18772- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18773+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18774+
18775+#ifdef CONFIG_PAX_REFCOUNT
18776+ "jno 0f\n"
18777+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18778+ "int $4\n0:\n"
18779+ _ASM_EXTABLE(0b, 0b)
18780+#endif
18781+
18782 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18783 }
18784
18785diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18786index 6a99859..03cb807 100644
18787--- a/arch/x86/include/asm/stackprotector.h
18788+++ b/arch/x86/include/asm/stackprotector.h
18789@@ -47,7 +47,7 @@
18790 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18791 */
18792 #define GDT_STACK_CANARY_INIT \
18793- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18794+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18795
18796 /*
18797 * Initialize the stackprotector canary value.
18798@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18799
18800 static inline void load_stack_canary_segment(void)
18801 {
18802-#ifdef CONFIG_X86_32
18803+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18804 asm volatile ("mov %0, %%gs" : : "r" (0));
18805 #endif
18806 }
18807diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18808index 70bbe39..4ae2bd4 100644
18809--- a/arch/x86/include/asm/stacktrace.h
18810+++ b/arch/x86/include/asm/stacktrace.h
18811@@ -11,28 +11,20 @@
18812
18813 extern int kstack_depth_to_print;
18814
18815-struct thread_info;
18816+struct task_struct;
18817 struct stacktrace_ops;
18818
18819-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18820- unsigned long *stack,
18821- unsigned long bp,
18822- const struct stacktrace_ops *ops,
18823- void *data,
18824- unsigned long *end,
18825- int *graph);
18826+typedef unsigned long walk_stack_t(struct task_struct *task,
18827+ void *stack_start,
18828+ unsigned long *stack,
18829+ unsigned long bp,
18830+ const struct stacktrace_ops *ops,
18831+ void *data,
18832+ unsigned long *end,
18833+ int *graph);
18834
18835-extern unsigned long
18836-print_context_stack(struct thread_info *tinfo,
18837- unsigned long *stack, unsigned long bp,
18838- const struct stacktrace_ops *ops, void *data,
18839- unsigned long *end, int *graph);
18840-
18841-extern unsigned long
18842-print_context_stack_bp(struct thread_info *tinfo,
18843- unsigned long *stack, unsigned long bp,
18844- const struct stacktrace_ops *ops, void *data,
18845- unsigned long *end, int *graph);
18846+extern walk_stack_t print_context_stack;
18847+extern walk_stack_t print_context_stack_bp;
18848
18849 /* Generic stack tracer with callbacks */
18850
18851@@ -40,7 +32,7 @@ struct stacktrace_ops {
18852 void (*address)(void *data, unsigned long address, int reliable);
18853 /* On negative return stop dumping */
18854 int (*stack)(void *data, char *name);
18855- walk_stack_t walk_stack;
18856+ walk_stack_t *walk_stack;
18857 };
18858
18859 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18860diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18861index d7f3b3b..3cc39f1 100644
18862--- a/arch/x86/include/asm/switch_to.h
18863+++ b/arch/x86/include/asm/switch_to.h
18864@@ -108,7 +108,7 @@ do { \
18865 "call __switch_to\n\t" \
18866 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18867 __switch_canary \
18868- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18869+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18870 "movq %%rax,%%rdi\n\t" \
18871 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18872 "jnz ret_from_fork\n\t" \
18873@@ -119,7 +119,7 @@ do { \
18874 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18875 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18876 [_tif_fork] "i" (_TIF_FORK), \
18877- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18878+ [thread_info] "m" (current_tinfo), \
18879 [current_task] "m" (current_task) \
18880 __switch_canary_iparam \
18881 : "memory", "cc" __EXTRA_CLOBBER)
18882diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18883index e1940c0..ac50dd8 100644
18884--- a/arch/x86/include/asm/thread_info.h
18885+++ b/arch/x86/include/asm/thread_info.h
18886@@ -10,6 +10,7 @@
18887 #include <linux/compiler.h>
18888 #include <asm/page.h>
18889 #include <asm/types.h>
18890+#include <asm/percpu.h>
18891
18892 /*
18893 * low level task data that entry.S needs immediate access to
18894@@ -23,7 +24,6 @@ struct exec_domain;
18895 #include <linux/atomic.h>
18896
18897 struct thread_info {
18898- struct task_struct *task; /* main task structure */
18899 struct exec_domain *exec_domain; /* execution domain */
18900 __u32 flags; /* low level flags */
18901 __u32 status; /* thread synchronous flags */
18902@@ -32,19 +32,13 @@ struct thread_info {
18903 mm_segment_t addr_limit;
18904 struct restart_block restart_block;
18905 void __user *sysenter_return;
18906-#ifdef CONFIG_X86_32
18907- unsigned long previous_esp; /* ESP of the previous stack in
18908- case of nested (IRQ) stacks
18909- */
18910- __u8 supervisor_stack[0];
18911-#endif
18912+ unsigned long lowest_stack;
18913 unsigned int sig_on_uaccess_error:1;
18914 unsigned int uaccess_err:1; /* uaccess failed */
18915 };
18916
18917-#define INIT_THREAD_INFO(tsk) \
18918+#define INIT_THREAD_INFO \
18919 { \
18920- .task = &tsk, \
18921 .exec_domain = &default_exec_domain, \
18922 .flags = 0, \
18923 .cpu = 0, \
18924@@ -55,7 +49,7 @@ struct thread_info {
18925 }, \
18926 }
18927
18928-#define init_thread_info (init_thread_union.thread_info)
18929+#define init_thread_info (init_thread_union.stack)
18930 #define init_stack (init_thread_union.stack)
18931
18932 #else /* !__ASSEMBLY__ */
18933@@ -95,6 +89,7 @@ struct thread_info {
18934 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18935 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18936 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18937+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18938
18939 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18940 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18941@@ -118,17 +113,18 @@ struct thread_info {
18942 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18943 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18944 #define _TIF_X32 (1 << TIF_X32)
18945+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18946
18947 /* work to do in syscall_trace_enter() */
18948 #define _TIF_WORK_SYSCALL_ENTRY \
18949 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18950 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18951- _TIF_NOHZ)
18952+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18953
18954 /* work to do in syscall_trace_leave() */
18955 #define _TIF_WORK_SYSCALL_EXIT \
18956 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18957- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18958+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18959
18960 /* work to do on interrupt/exception return */
18961 #define _TIF_WORK_MASK \
18962@@ -139,7 +135,7 @@ struct thread_info {
18963 /* work to do on any return to user space */
18964 #define _TIF_ALLWORK_MASK \
18965 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18966- _TIF_NOHZ)
18967+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18968
18969 /* Only used for 64 bit */
18970 #define _TIF_DO_NOTIFY_MASK \
18971@@ -153,6 +149,23 @@ struct thread_info {
18972 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18973 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18974
18975+#ifdef __ASSEMBLY__
18976+/* how to get the thread information struct from ASM */
18977+#define GET_THREAD_INFO(reg) \
18978+ mov PER_CPU_VAR(current_tinfo), reg
18979+
18980+/* use this one if reg already contains %esp */
18981+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18982+#else
18983+/* how to get the thread information struct from C */
18984+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18985+
18986+static __always_inline struct thread_info *current_thread_info(void)
18987+{
18988+ return this_cpu_read_stable(current_tinfo);
18989+}
18990+#endif
18991+
18992 #ifdef CONFIG_X86_32
18993
18994 #define STACK_WARN (THREAD_SIZE/8)
18995@@ -169,31 +182,10 @@ struct thread_info {
18996 sp; \
18997 })
18998
18999-/* how to get the thread information struct from C */
19000-static inline struct thread_info *current_thread_info(void)
19001-{
19002- return (struct thread_info *)
19003- (current_stack_pointer & ~(THREAD_SIZE - 1));
19004-}
19005-
19006-#else /* !__ASSEMBLY__ */
19007-
19008-/* how to get the thread information struct from ASM */
19009-#define GET_THREAD_INFO(reg) \
19010- movl $-THREAD_SIZE, reg; \
19011- andl %esp, reg
19012-
19013-/* use this one if reg already contains %esp */
19014-#define GET_THREAD_INFO_WITH_ESP(reg) \
19015- andl $-THREAD_SIZE, reg
19016-
19017 #endif
19018
19019 #else /* X86_32 */
19020
19021-#include <asm/percpu.h>
19022-#define KERNEL_STACK_OFFSET (5*8)
19023-
19024 /*
19025 * macros/functions for gaining access to the thread information structure
19026 * preempt_count needs to be 1 initially, until the scheduler is functional.
19027@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19028 #ifndef __ASSEMBLY__
19029 DECLARE_PER_CPU(unsigned long, kernel_stack);
19030
19031-static inline struct thread_info *current_thread_info(void)
19032-{
19033- struct thread_info *ti;
19034- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19035- KERNEL_STACK_OFFSET - THREAD_SIZE);
19036- return ti;
19037-}
19038-
19039-#else /* !__ASSEMBLY__ */
19040-
19041-/* how to get the thread information struct from ASM */
19042-#define GET_THREAD_INFO(reg) \
19043- movq PER_CPU_VAR(kernel_stack),reg ; \
19044- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19045-
19046-/*
19047- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19048- * a certain register (to be used in assembler memory operands).
19049- */
19050-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19051-
19052+/* how to get the current stack pointer from C */
19053+register unsigned long current_stack_pointer asm("rsp") __used;
19054 #endif
19055
19056 #endif /* !X86_32 */
19057@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19058 extern void arch_task_cache_init(void);
19059 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19060 extern void arch_release_task_struct(struct task_struct *tsk);
19061+
19062+#define __HAVE_THREAD_FUNCTIONS
19063+#define task_thread_info(task) (&(task)->tinfo)
19064+#define task_stack_page(task) ((task)->stack)
19065+#define setup_thread_stack(p, org) do {} while (0)
19066+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19067+
19068 #endif
19069 #endif /* _ASM_X86_THREAD_INFO_H */
19070diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19071index 04905bf..49203ca 100644
19072--- a/arch/x86/include/asm/tlbflush.h
19073+++ b/arch/x86/include/asm/tlbflush.h
19074@@ -17,18 +17,44 @@
19075
19076 static inline void __native_flush_tlb(void)
19077 {
19078+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19079+ u64 descriptor[2];
19080+
19081+ descriptor[0] = PCID_KERNEL;
19082+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19083+ return;
19084+ }
19085+
19086+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19087+ if (static_cpu_has(X86_FEATURE_PCID)) {
19088+ unsigned int cpu = raw_get_cpu();
19089+
19090+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19091+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19092+ raw_put_cpu_no_resched();
19093+ return;
19094+ }
19095+#endif
19096+
19097 native_write_cr3(native_read_cr3());
19098 }
19099
19100 static inline void __native_flush_tlb_global_irq_disabled(void)
19101 {
19102- unsigned long cr4;
19103+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19104+ u64 descriptor[2];
19105
19106- cr4 = native_read_cr4();
19107- /* clear PGE */
19108- native_write_cr4(cr4 & ~X86_CR4_PGE);
19109- /* write old PGE again and flush TLBs */
19110- native_write_cr4(cr4);
19111+ descriptor[0] = PCID_KERNEL;
19112+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19113+ } else {
19114+ unsigned long cr4;
19115+
19116+ cr4 = native_read_cr4();
19117+ /* clear PGE */
19118+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19119+ /* write old PGE again and flush TLBs */
19120+ native_write_cr4(cr4);
19121+ }
19122 }
19123
19124 static inline void __native_flush_tlb_global(void)
19125@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19126
19127 static inline void __native_flush_tlb_single(unsigned long addr)
19128 {
19129+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19130+ u64 descriptor[2];
19131+
19132+ descriptor[0] = PCID_KERNEL;
19133+ descriptor[1] = addr;
19134+
19135+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19136+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19137+ if (addr < TASK_SIZE_MAX)
19138+ descriptor[1] += pax_user_shadow_base;
19139+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19140+ }
19141+
19142+ descriptor[0] = PCID_USER;
19143+ descriptor[1] = addr;
19144+#endif
19145+
19146+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19147+ return;
19148+ }
19149+
19150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19151+ if (static_cpu_has(X86_FEATURE_PCID)) {
19152+ unsigned int cpu = raw_get_cpu();
19153+
19154+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19155+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19156+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19157+ raw_put_cpu_no_resched();
19158+
19159+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19160+ addr += pax_user_shadow_base;
19161+ }
19162+#endif
19163+
19164 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19165 }
19166
19167diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19168index 0d592e0..f58a222 100644
19169--- a/arch/x86/include/asm/uaccess.h
19170+++ b/arch/x86/include/asm/uaccess.h
19171@@ -7,6 +7,7 @@
19172 #include <linux/compiler.h>
19173 #include <linux/thread_info.h>
19174 #include <linux/string.h>
19175+#include <linux/spinlock.h>
19176 #include <asm/asm.h>
19177 #include <asm/page.h>
19178 #include <asm/smap.h>
19179@@ -29,7 +30,12 @@
19180
19181 #define get_ds() (KERNEL_DS)
19182 #define get_fs() (current_thread_info()->addr_limit)
19183+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19184+void __set_fs(mm_segment_t x);
19185+void set_fs(mm_segment_t x);
19186+#else
19187 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19188+#endif
19189
19190 #define segment_eq(a, b) ((a).seg == (b).seg)
19191
19192@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19193 * checks that the pointer is in the user space range - after calling
19194 * this function, memory access functions may still return -EFAULT.
19195 */
19196-#define access_ok(type, addr, size) \
19197- likely(!__range_not_ok(addr, size, user_addr_max()))
19198+extern int _cond_resched(void);
19199+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19200+#define access_ok(type, addr, size) \
19201+({ \
19202+ long __size = size; \
19203+ unsigned long __addr = (unsigned long)addr; \
19204+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19205+ unsigned long __end_ao = __addr + __size - 1; \
19206+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19207+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19208+ while(__addr_ao <= __end_ao) { \
19209+ char __c_ao; \
19210+ __addr_ao += PAGE_SIZE; \
19211+ if (__size > PAGE_SIZE) \
19212+ _cond_resched(); \
19213+ if (__get_user(__c_ao, (char __user *)__addr)) \
19214+ break; \
19215+ if (type != VERIFY_WRITE) { \
19216+ __addr = __addr_ao; \
19217+ continue; \
19218+ } \
19219+ if (__put_user(__c_ao, (char __user *)__addr)) \
19220+ break; \
19221+ __addr = __addr_ao; \
19222+ } \
19223+ } \
19224+ __ret_ao; \
19225+})
19226
19227 /*
19228 * The exception table consists of pairs of addresses relative to the
19229@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19230 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19231 __chk_user_ptr(ptr); \
19232 might_fault(); \
19233+ pax_open_userland(); \
19234 asm volatile("call __get_user_%P3" \
19235 : "=a" (__ret_gu), "=r" (__val_gu) \
19236 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19237 (x) = (__typeof__(*(ptr))) __val_gu; \
19238+ pax_close_userland(); \
19239 __ret_gu; \
19240 })
19241
19242@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19243 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19244 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19245
19246-
19247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19248+#define __copyuser_seg "gs;"
19249+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19250+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19251+#else
19252+#define __copyuser_seg
19253+#define __COPYUSER_SET_ES
19254+#define __COPYUSER_RESTORE_ES
19255+#endif
19256
19257 #ifdef CONFIG_X86_32
19258 #define __put_user_asm_u64(x, addr, err, errret) \
19259 asm volatile(ASM_STAC "\n" \
19260- "1: movl %%eax,0(%2)\n" \
19261- "2: movl %%edx,4(%2)\n" \
19262+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19263+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19264 "3: " ASM_CLAC "\n" \
19265 ".section .fixup,\"ax\"\n" \
19266 "4: movl %3,%0\n" \
19267@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19268
19269 #define __put_user_asm_ex_u64(x, addr) \
19270 asm volatile(ASM_STAC "\n" \
19271- "1: movl %%eax,0(%1)\n" \
19272- "2: movl %%edx,4(%1)\n" \
19273+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19274+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19275 "3: " ASM_CLAC "\n" \
19276 _ASM_EXTABLE_EX(1b, 2b) \
19277 _ASM_EXTABLE_EX(2b, 3b) \
19278@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19279 __typeof__(*(ptr)) __pu_val; \
19280 __chk_user_ptr(ptr); \
19281 might_fault(); \
19282- __pu_val = x; \
19283+ __pu_val = (x); \
19284+ pax_open_userland(); \
19285 switch (sizeof(*(ptr))) { \
19286 case 1: \
19287 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19288@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19289 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19290 break; \
19291 } \
19292+ pax_close_userland(); \
19293 __ret_pu; \
19294 })
19295
19296@@ -355,8 +399,10 @@ do { \
19297 } while (0)
19298
19299 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19300+do { \
19301+ pax_open_userland(); \
19302 asm volatile(ASM_STAC "\n" \
19303- "1: mov"itype" %2,%"rtype"1\n" \
19304+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19305 "2: " ASM_CLAC "\n" \
19306 ".section .fixup,\"ax\"\n" \
19307 "3: mov %3,%0\n" \
19308@@ -364,8 +410,10 @@ do { \
19309 " jmp 2b\n" \
19310 ".previous\n" \
19311 _ASM_EXTABLE(1b, 3b) \
19312- : "=r" (err), ltype(x) \
19313- : "m" (__m(addr)), "i" (errret), "0" (err))
19314+ : "=r" (err), ltype (x) \
19315+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19316+ pax_close_userland(); \
19317+} while (0)
19318
19319 #define __get_user_size_ex(x, ptr, size) \
19320 do { \
19321@@ -389,7 +437,7 @@ do { \
19322 } while (0)
19323
19324 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19325- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19326+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19327 "2:\n" \
19328 _ASM_EXTABLE_EX(1b, 2b) \
19329 : ltype(x) : "m" (__m(addr)))
19330@@ -406,13 +454,24 @@ do { \
19331 int __gu_err; \
19332 unsigned long __gu_val; \
19333 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19334- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19335+ (x) = (__typeof__(*(ptr)))__gu_val; \
19336 __gu_err; \
19337 })
19338
19339 /* FIXME: this hack is definitely wrong -AK */
19340 struct __large_struct { unsigned long buf[100]; };
19341-#define __m(x) (*(struct __large_struct __user *)(x))
19342+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19343+#define ____m(x) \
19344+({ \
19345+ unsigned long ____x = (unsigned long)(x); \
19346+ if (____x < pax_user_shadow_base) \
19347+ ____x += pax_user_shadow_base; \
19348+ (typeof(x))____x; \
19349+})
19350+#else
19351+#define ____m(x) (x)
19352+#endif
19353+#define __m(x) (*(struct __large_struct __user *)____m(x))
19354
19355 /*
19356 * Tell gcc we read from memory instead of writing: this is because
19357@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19358 * aliasing issues.
19359 */
19360 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19361+do { \
19362+ pax_open_userland(); \
19363 asm volatile(ASM_STAC "\n" \
19364- "1: mov"itype" %"rtype"1,%2\n" \
19365+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19366 "2: " ASM_CLAC "\n" \
19367 ".section .fixup,\"ax\"\n" \
19368 "3: mov %3,%0\n" \
19369@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19370 ".previous\n" \
19371 _ASM_EXTABLE(1b, 3b) \
19372 : "=r"(err) \
19373- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19374+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19375+ pax_close_userland(); \
19376+} while (0)
19377
19378 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19379- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19380+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19381 "2:\n" \
19382 _ASM_EXTABLE_EX(1b, 2b) \
19383 : : ltype(x), "m" (__m(addr)))
19384@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19385 */
19386 #define uaccess_try do { \
19387 current_thread_info()->uaccess_err = 0; \
19388+ pax_open_userland(); \
19389 stac(); \
19390 barrier();
19391
19392 #define uaccess_catch(err) \
19393 clac(); \
19394+ pax_close_userland(); \
19395 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19396 } while (0)
19397
19398@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19399 * On error, the variable @x is set to zero.
19400 */
19401
19402+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19403+#define __get_user(x, ptr) get_user((x), (ptr))
19404+#else
19405 #define __get_user(x, ptr) \
19406 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19407+#endif
19408
19409 /**
19410 * __put_user: - Write a simple value into user space, with less checking.
19411@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19412 * Returns zero on success, or -EFAULT on error.
19413 */
19414
19415+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19416+#define __put_user(x, ptr) put_user((x), (ptr))
19417+#else
19418 #define __put_user(x, ptr) \
19419 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19420+#endif
19421
19422 #define __get_user_unaligned __get_user
19423 #define __put_user_unaligned __put_user
19424@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19425 #define get_user_ex(x, ptr) do { \
19426 unsigned long __gue_val; \
19427 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19428- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19429+ (x) = (__typeof__(*(ptr)))__gue_val; \
19430 } while (0)
19431
19432 #define put_user_try uaccess_try
19433@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19434 __typeof__(ptr) __uval = (uval); \
19435 __typeof__(*(ptr)) __old = (old); \
19436 __typeof__(*(ptr)) __new = (new); \
19437+ pax_open_userland(); \
19438 switch (size) { \
19439 case 1: \
19440 { \
19441 asm volatile("\t" ASM_STAC "\n" \
19442- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19443+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19444 "2:\t" ASM_CLAC "\n" \
19445 "\t.section .fixup, \"ax\"\n" \
19446 "3:\tmov %3, %0\n" \
19447 "\tjmp 2b\n" \
19448 "\t.previous\n" \
19449 _ASM_EXTABLE(1b, 3b) \
19450- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19451+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19452 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19453 : "memory" \
19454 ); \
19455@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19456 case 2: \
19457 { \
19458 asm volatile("\t" ASM_STAC "\n" \
19459- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19460+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19461 "2:\t" ASM_CLAC "\n" \
19462 "\t.section .fixup, \"ax\"\n" \
19463 "3:\tmov %3, %0\n" \
19464 "\tjmp 2b\n" \
19465 "\t.previous\n" \
19466 _ASM_EXTABLE(1b, 3b) \
19467- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19468+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19469 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19470 : "memory" \
19471 ); \
19472@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19473 case 4: \
19474 { \
19475 asm volatile("\t" ASM_STAC "\n" \
19476- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19477+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19478 "2:\t" ASM_CLAC "\n" \
19479 "\t.section .fixup, \"ax\"\n" \
19480 "3:\tmov %3, %0\n" \
19481 "\tjmp 2b\n" \
19482 "\t.previous\n" \
19483 _ASM_EXTABLE(1b, 3b) \
19484- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19485+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19486 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19487 : "memory" \
19488 ); \
19489@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19490 __cmpxchg_wrong_size(); \
19491 \
19492 asm volatile("\t" ASM_STAC "\n" \
19493- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19494+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19495 "2:\t" ASM_CLAC "\n" \
19496 "\t.section .fixup, \"ax\"\n" \
19497 "3:\tmov %3, %0\n" \
19498 "\tjmp 2b\n" \
19499 "\t.previous\n" \
19500 _ASM_EXTABLE(1b, 3b) \
19501- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19502+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19503 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19504 : "memory" \
19505 ); \
19506@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19507 default: \
19508 __cmpxchg_wrong_size(); \
19509 } \
19510+ pax_close_userland(); \
19511 *__uval = __old; \
19512 __ret; \
19513 })
19514@@ -636,17 +711,6 @@ extern struct movsl_mask {
19515
19516 #define ARCH_HAS_NOCACHE_UACCESS 1
19517
19518-#ifdef CONFIG_X86_32
19519-# include <asm/uaccess_32.h>
19520-#else
19521-# include <asm/uaccess_64.h>
19522-#endif
19523-
19524-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19525- unsigned n);
19526-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19527- unsigned n);
19528-
19529 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19530 # define copy_user_diag __compiletime_error
19531 #else
19532@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19533 extern void copy_user_diag("copy_from_user() buffer size is too small")
19534 copy_from_user_overflow(void);
19535 extern void copy_user_diag("copy_to_user() buffer size is too small")
19536-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19537+copy_to_user_overflow(void);
19538
19539 #undef copy_user_diag
19540
19541@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19542
19543 extern void
19544 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19545-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19546+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19547 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19548
19549 #else
19550@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19551
19552 #endif
19553
19554+#ifdef CONFIG_X86_32
19555+# include <asm/uaccess_32.h>
19556+#else
19557+# include <asm/uaccess_64.h>
19558+#endif
19559+
19560 static inline unsigned long __must_check
19561 copy_from_user(void *to, const void __user *from, unsigned long n)
19562 {
19563- int sz = __compiletime_object_size(to);
19564+ size_t sz = __compiletime_object_size(to);
19565
19566 might_fault();
19567
19568@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19569 * case, and do only runtime checking for non-constant sizes.
19570 */
19571
19572- if (likely(sz < 0 || sz >= n))
19573- n = _copy_from_user(to, from, n);
19574- else if(__builtin_constant_p(n))
19575- copy_from_user_overflow();
19576- else
19577- __copy_from_user_overflow(sz, n);
19578+ if (likely(sz != (size_t)-1 && sz < n)) {
19579+ if(__builtin_constant_p(n))
19580+ copy_from_user_overflow();
19581+ else
19582+ __copy_from_user_overflow(sz, n);
19583+ } if (access_ok(VERIFY_READ, from, n))
19584+ n = __copy_from_user(to, from, n);
19585+ else if ((long)n > 0)
19586+ memset(to, 0, n);
19587
19588 return n;
19589 }
19590@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19591 static inline unsigned long __must_check
19592 copy_to_user(void __user *to, const void *from, unsigned long n)
19593 {
19594- int sz = __compiletime_object_size(from);
19595+ size_t sz = __compiletime_object_size(from);
19596
19597 might_fault();
19598
19599 /* See the comment in copy_from_user() above. */
19600- if (likely(sz < 0 || sz >= n))
19601- n = _copy_to_user(to, from, n);
19602- else if(__builtin_constant_p(n))
19603- copy_to_user_overflow();
19604- else
19605- __copy_to_user_overflow(sz, n);
19606+ if (likely(sz != (size_t)-1 && sz < n)) {
19607+ if(__builtin_constant_p(n))
19608+ copy_to_user_overflow();
19609+ else
19610+ __copy_to_user_overflow(sz, n);
19611+ } else if (access_ok(VERIFY_WRITE, to, n))
19612+ n = __copy_to_user(to, from, n);
19613
19614 return n;
19615 }
19616diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19617index 3c03a5d..1071638 100644
19618--- a/arch/x86/include/asm/uaccess_32.h
19619+++ b/arch/x86/include/asm/uaccess_32.h
19620@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19621 static __always_inline unsigned long __must_check
19622 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19623 {
19624+ if ((long)n < 0)
19625+ return n;
19626+
19627+ check_object_size(from, n, true);
19628+
19629 if (__builtin_constant_p(n)) {
19630 unsigned long ret;
19631
19632@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19633 __copy_to_user(void __user *to, const void *from, unsigned long n)
19634 {
19635 might_fault();
19636+
19637 return __copy_to_user_inatomic(to, from, n);
19638 }
19639
19640 static __always_inline unsigned long
19641 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19642 {
19643+ if ((long)n < 0)
19644+ return n;
19645+
19646 /* Avoid zeroing the tail if the copy fails..
19647 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19648 * but as the zeroing behaviour is only significant when n is not
19649@@ -137,6 +146,12 @@ static __always_inline unsigned long
19650 __copy_from_user(void *to, const void __user *from, unsigned long n)
19651 {
19652 might_fault();
19653+
19654+ if ((long)n < 0)
19655+ return n;
19656+
19657+ check_object_size(to, n, false);
19658+
19659 if (__builtin_constant_p(n)) {
19660 unsigned long ret;
19661
19662@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19663 const void __user *from, unsigned long n)
19664 {
19665 might_fault();
19666+
19667+ if ((long)n < 0)
19668+ return n;
19669+
19670 if (__builtin_constant_p(n)) {
19671 unsigned long ret;
19672
19673@@ -181,7 +200,10 @@ static __always_inline unsigned long
19674 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19675 unsigned long n)
19676 {
19677- return __copy_from_user_ll_nocache_nozero(to, from, n);
19678+ if ((long)n < 0)
19679+ return n;
19680+
19681+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19682 }
19683
19684 #endif /* _ASM_X86_UACCESS_32_H */
19685diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19686index 12a26b9..206c200 100644
19687--- a/arch/x86/include/asm/uaccess_64.h
19688+++ b/arch/x86/include/asm/uaccess_64.h
19689@@ -10,6 +10,9 @@
19690 #include <asm/alternative.h>
19691 #include <asm/cpufeature.h>
19692 #include <asm/page.h>
19693+#include <asm/pgtable.h>
19694+
19695+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19696
19697 /*
19698 * Copy To/From Userspace
19699@@ -17,14 +20,14 @@
19700
19701 /* Handles exceptions in both to and from, but doesn't do access_ok */
19702 __must_check unsigned long
19703-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19704+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19705 __must_check unsigned long
19706-copy_user_generic_string(void *to, const void *from, unsigned len);
19707+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19708 __must_check unsigned long
19709-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19710+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19711
19712 static __always_inline __must_check unsigned long
19713-copy_user_generic(void *to, const void *from, unsigned len)
19714+copy_user_generic(void *to, const void *from, unsigned long len)
19715 {
19716 unsigned ret;
19717
19718@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19719 }
19720
19721 __must_check unsigned long
19722-copy_in_user(void __user *to, const void __user *from, unsigned len);
19723+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19724
19725 static __always_inline __must_check
19726-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19727+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19728 {
19729- int ret = 0;
19730+ size_t sz = __compiletime_object_size(dst);
19731+ unsigned ret = 0;
19732+
19733+ if (size > INT_MAX)
19734+ return size;
19735+
19736+ check_object_size(dst, size, false);
19737+
19738+#ifdef CONFIG_PAX_MEMORY_UDEREF
19739+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19740+ return size;
19741+#endif
19742+
19743+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19744+ if(__builtin_constant_p(size))
19745+ copy_from_user_overflow();
19746+ else
19747+ __copy_from_user_overflow(sz, size);
19748+ return size;
19749+ }
19750
19751 if (!__builtin_constant_p(size))
19752- return copy_user_generic(dst, (__force void *)src, size);
19753+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19754 switch (size) {
19755- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19756+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19757 ret, "b", "b", "=q", 1);
19758 return ret;
19759- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19760+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19761 ret, "w", "w", "=r", 2);
19762 return ret;
19763- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19764+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19765 ret, "l", "k", "=r", 4);
19766 return ret;
19767- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19768+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19769 ret, "q", "", "=r", 8);
19770 return ret;
19771 case 10:
19772- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19773+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19774 ret, "q", "", "=r", 10);
19775 if (unlikely(ret))
19776 return ret;
19777 __get_user_asm(*(u16 *)(8 + (char *)dst),
19778- (u16 __user *)(8 + (char __user *)src),
19779+ (const u16 __user *)(8 + (const char __user *)src),
19780 ret, "w", "w", "=r", 2);
19781 return ret;
19782 case 16:
19783- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19784+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19785 ret, "q", "", "=r", 16);
19786 if (unlikely(ret))
19787 return ret;
19788 __get_user_asm(*(u64 *)(8 + (char *)dst),
19789- (u64 __user *)(8 + (char __user *)src),
19790+ (const u64 __user *)(8 + (const char __user *)src),
19791 ret, "q", "", "=r", 8);
19792 return ret;
19793 default:
19794- return copy_user_generic(dst, (__force void *)src, size);
19795+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19796 }
19797 }
19798
19799 static __always_inline __must_check
19800-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19801+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19802 {
19803 might_fault();
19804 return __copy_from_user_nocheck(dst, src, size);
19805 }
19806
19807 static __always_inline __must_check
19808-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19809+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19810 {
19811- int ret = 0;
19812+ size_t sz = __compiletime_object_size(src);
19813+ unsigned ret = 0;
19814+
19815+ if (size > INT_MAX)
19816+ return size;
19817+
19818+ check_object_size(src, size, true);
19819+
19820+#ifdef CONFIG_PAX_MEMORY_UDEREF
19821+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19822+ return size;
19823+#endif
19824+
19825+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19826+ if(__builtin_constant_p(size))
19827+ copy_to_user_overflow();
19828+ else
19829+ __copy_to_user_overflow(sz, size);
19830+ return size;
19831+ }
19832
19833 if (!__builtin_constant_p(size))
19834- return copy_user_generic((__force void *)dst, src, size);
19835+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19836 switch (size) {
19837- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19838+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19839 ret, "b", "b", "iq", 1);
19840 return ret;
19841- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19842+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19843 ret, "w", "w", "ir", 2);
19844 return ret;
19845- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19846+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19847 ret, "l", "k", "ir", 4);
19848 return ret;
19849- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19850+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19851 ret, "q", "", "er", 8);
19852 return ret;
19853 case 10:
19854- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19855+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19856 ret, "q", "", "er", 10);
19857 if (unlikely(ret))
19858 return ret;
19859 asm("":::"memory");
19860- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19861+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19862 ret, "w", "w", "ir", 2);
19863 return ret;
19864 case 16:
19865- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19866+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19867 ret, "q", "", "er", 16);
19868 if (unlikely(ret))
19869 return ret;
19870 asm("":::"memory");
19871- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19872+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19873 ret, "q", "", "er", 8);
19874 return ret;
19875 default:
19876- return copy_user_generic((__force void *)dst, src, size);
19877+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19878 }
19879 }
19880
19881 static __always_inline __must_check
19882-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19883+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19884 {
19885 might_fault();
19886 return __copy_to_user_nocheck(dst, src, size);
19887 }
19888
19889 static __always_inline __must_check
19890-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19891+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19892 {
19893- int ret = 0;
19894+ unsigned ret = 0;
19895
19896 might_fault();
19897+
19898+ if (size > INT_MAX)
19899+ return size;
19900+
19901+#ifdef CONFIG_PAX_MEMORY_UDEREF
19902+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19903+ return size;
19904+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19905+ return size;
19906+#endif
19907+
19908 if (!__builtin_constant_p(size))
19909- return copy_user_generic((__force void *)dst,
19910- (__force void *)src, size);
19911+ return copy_user_generic((__force_kernel void *)____m(dst),
19912+ (__force_kernel const void *)____m(src), size);
19913 switch (size) {
19914 case 1: {
19915 u8 tmp;
19916- __get_user_asm(tmp, (u8 __user *)src,
19917+ __get_user_asm(tmp, (const u8 __user *)src,
19918 ret, "b", "b", "=q", 1);
19919 if (likely(!ret))
19920 __put_user_asm(tmp, (u8 __user *)dst,
19921@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19922 }
19923 case 2: {
19924 u16 tmp;
19925- __get_user_asm(tmp, (u16 __user *)src,
19926+ __get_user_asm(tmp, (const u16 __user *)src,
19927 ret, "w", "w", "=r", 2);
19928 if (likely(!ret))
19929 __put_user_asm(tmp, (u16 __user *)dst,
19930@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19931
19932 case 4: {
19933 u32 tmp;
19934- __get_user_asm(tmp, (u32 __user *)src,
19935+ __get_user_asm(tmp, (const u32 __user *)src,
19936 ret, "l", "k", "=r", 4);
19937 if (likely(!ret))
19938 __put_user_asm(tmp, (u32 __user *)dst,
19939@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19940 }
19941 case 8: {
19942 u64 tmp;
19943- __get_user_asm(tmp, (u64 __user *)src,
19944+ __get_user_asm(tmp, (const u64 __user *)src,
19945 ret, "q", "", "=r", 8);
19946 if (likely(!ret))
19947 __put_user_asm(tmp, (u64 __user *)dst,
19948@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19949 return ret;
19950 }
19951 default:
19952- return copy_user_generic((__force void *)dst,
19953- (__force void *)src, size);
19954+ return copy_user_generic((__force_kernel void *)____m(dst),
19955+ (__force_kernel const void *)____m(src), size);
19956 }
19957 }
19958
19959-static __must_check __always_inline int
19960-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19961+static __must_check __always_inline unsigned long
19962+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19963 {
19964 return __copy_from_user_nocheck(dst, src, size);
19965 }
19966
19967-static __must_check __always_inline int
19968-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19969+static __must_check __always_inline unsigned long
19970+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19971 {
19972 return __copy_to_user_nocheck(dst, src, size);
19973 }
19974
19975-extern long __copy_user_nocache(void *dst, const void __user *src,
19976- unsigned size, int zerorest);
19977+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19978+ unsigned long size, int zerorest);
19979
19980-static inline int
19981-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19982+static inline unsigned long
19983+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19984 {
19985 might_fault();
19986+
19987+ if (size > INT_MAX)
19988+ return size;
19989+
19990+#ifdef CONFIG_PAX_MEMORY_UDEREF
19991+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19992+ return size;
19993+#endif
19994+
19995 return __copy_user_nocache(dst, src, size, 1);
19996 }
19997
19998-static inline int
19999+static inline unsigned long
20000 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20001- unsigned size)
20002+ unsigned long size)
20003 {
20004+ if (size > INT_MAX)
20005+ return size;
20006+
20007+#ifdef CONFIG_PAX_MEMORY_UDEREF
20008+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20009+ return size;
20010+#endif
20011+
20012 return __copy_user_nocache(dst, src, size, 0);
20013 }
20014
20015 unsigned long
20016-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20017+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20018
20019 #endif /* _ASM_X86_UACCESS_64_H */
20020diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20021index 5b238981..77fdd78 100644
20022--- a/arch/x86/include/asm/word-at-a-time.h
20023+++ b/arch/x86/include/asm/word-at-a-time.h
20024@@ -11,7 +11,7 @@
20025 * and shift, for example.
20026 */
20027 struct word_at_a_time {
20028- const unsigned long one_bits, high_bits;
20029+ unsigned long one_bits, high_bits;
20030 };
20031
20032 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20033diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20034index e45e4da..44e8572 100644
20035--- a/arch/x86/include/asm/x86_init.h
20036+++ b/arch/x86/include/asm/x86_init.h
20037@@ -129,7 +129,7 @@ struct x86_init_ops {
20038 struct x86_init_timers timers;
20039 struct x86_init_iommu iommu;
20040 struct x86_init_pci pci;
20041-};
20042+} __no_const;
20043
20044 /**
20045 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20046@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20047 void (*setup_percpu_clockev)(void);
20048 void (*early_percpu_clock_init)(void);
20049 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20050-};
20051+} __no_const;
20052
20053 struct timespec;
20054
20055@@ -168,7 +168,7 @@ struct x86_platform_ops {
20056 void (*save_sched_clock_state)(void);
20057 void (*restore_sched_clock_state)(void);
20058 void (*apic_post_init)(void);
20059-};
20060+} __no_const;
20061
20062 struct pci_dev;
20063 struct msi_msg;
20064@@ -185,7 +185,7 @@ struct x86_msi_ops {
20065 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20066 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20067 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20068-};
20069+} __no_const;
20070
20071 struct IO_APIC_route_entry;
20072 struct io_apic_irq_attr;
20073@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20074 unsigned int destination, int vector,
20075 struct io_apic_irq_attr *attr);
20076 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20077-};
20078+} __no_const;
20079
20080 extern struct x86_init_ops x86_init;
20081 extern struct x86_cpuinit_ops x86_cpuinit;
20082diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20083index 3e276eb..2eb3c30 100644
20084--- a/arch/x86/include/asm/xen/page.h
20085+++ b/arch/x86/include/asm/xen/page.h
20086@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20087 extern struct page *m2p_find_override(unsigned long mfn);
20088 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20089
20090-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20091+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20092 {
20093 unsigned long mfn;
20094
20095diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20096index 6c1d741..39e6ecf 100644
20097--- a/arch/x86/include/asm/xsave.h
20098+++ b/arch/x86/include/asm/xsave.h
20099@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20100 if (unlikely(err))
20101 return -EFAULT;
20102
20103+ pax_open_userland();
20104 __asm__ __volatile__(ASM_STAC "\n"
20105- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20106+ "1:"
20107+ __copyuser_seg
20108+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20109 "2: " ASM_CLAC "\n"
20110 ".section .fixup,\"ax\"\n"
20111 "3: movl $-1,%[err]\n"
20112@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20113 : [err] "=r" (err)
20114 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20115 : "memory");
20116+ pax_close_userland();
20117 return err;
20118 }
20119
20120 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20121 {
20122 int err;
20123- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20124+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20125 u32 lmask = mask;
20126 u32 hmask = mask >> 32;
20127
20128+ pax_open_userland();
20129 __asm__ __volatile__(ASM_STAC "\n"
20130- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20131+ "1:"
20132+ __copyuser_seg
20133+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20134 "2: " ASM_CLAC "\n"
20135 ".section .fixup,\"ax\"\n"
20136 "3: movl $-1,%[err]\n"
20137@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20138 : [err] "=r" (err)
20139 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20140 : "memory"); /* memory required? */
20141+ pax_close_userland();
20142 return err;
20143 }
20144
20145diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20146index bbae024..e1528f9 100644
20147--- a/arch/x86/include/uapi/asm/e820.h
20148+++ b/arch/x86/include/uapi/asm/e820.h
20149@@ -63,7 +63,7 @@ struct e820map {
20150 #define ISA_START_ADDRESS 0xa0000
20151 #define ISA_END_ADDRESS 0x100000
20152
20153-#define BIOS_BEGIN 0x000a0000
20154+#define BIOS_BEGIN 0x000c0000
20155 #define BIOS_END 0x00100000
20156
20157 #define BIOS_ROM_BASE 0xffe00000
20158diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20159index 7b0a55a..ad115bf 100644
20160--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20161+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20162@@ -49,7 +49,6 @@
20163 #define EFLAGS 144
20164 #define RSP 152
20165 #define SS 160
20166-#define ARGOFFSET R11
20167 #endif /* __ASSEMBLY__ */
20168
20169 /* top of stack page */
20170diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20171index cb648c8..91cb07e 100644
20172--- a/arch/x86/kernel/Makefile
20173+++ b/arch/x86/kernel/Makefile
20174@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20175 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20176 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20177 obj-y += probe_roms.o
20178-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20179+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20180 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20181 obj-y += syscall_$(BITS).o
20182 obj-$(CONFIG_X86_64) += vsyscall_64.o
20183diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20184index 1dac942..19c8b0c 100644
20185--- a/arch/x86/kernel/acpi/boot.c
20186+++ b/arch/x86/kernel/acpi/boot.c
20187@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20188 * If your system is blacklisted here, but you find that acpi=force
20189 * works for you, please contact linux-acpi@vger.kernel.org
20190 */
20191-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20192+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20193 /*
20194 * Boxes that need ACPI disabled
20195 */
20196@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20197 };
20198
20199 /* second table for DMI checks that should run after early-quirks */
20200-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20201+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20202 /*
20203 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20204 * which includes some code which overrides all temperature
20205diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20206index 3a2ae4c..9db31d6 100644
20207--- a/arch/x86/kernel/acpi/sleep.c
20208+++ b/arch/x86/kernel/acpi/sleep.c
20209@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20210 #else /* CONFIG_64BIT */
20211 #ifdef CONFIG_SMP
20212 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20213+
20214+ pax_open_kernel();
20215 early_gdt_descr.address =
20216 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20217+ pax_close_kernel();
20218+
20219 initial_gs = per_cpu_offset(smp_processor_id());
20220 #endif
20221 initial_code = (unsigned long)wakeup_long64;
20222diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20223index 665c6b7..eae4d56 100644
20224--- a/arch/x86/kernel/acpi/wakeup_32.S
20225+++ b/arch/x86/kernel/acpi/wakeup_32.S
20226@@ -29,13 +29,11 @@ wakeup_pmode_return:
20227 # and restore the stack ... but you need gdt for this to work
20228 movl saved_context_esp, %esp
20229
20230- movl %cs:saved_magic, %eax
20231- cmpl $0x12345678, %eax
20232+ cmpl $0x12345678, saved_magic
20233 jne bogus_magic
20234
20235 # jump to place where we left off
20236- movl saved_eip, %eax
20237- jmp *%eax
20238+ jmp *(saved_eip)
20239
20240 bogus_magic:
20241 jmp bogus_magic
20242diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20243index df94598..f3b29bf 100644
20244--- a/arch/x86/kernel/alternative.c
20245+++ b/arch/x86/kernel/alternative.c
20246@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20247 */
20248 for (a = start; a < end; a++) {
20249 instr = (u8 *)&a->instr_offset + a->instr_offset;
20250+
20251+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20252+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20253+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20254+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20255+#endif
20256+
20257 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20258 BUG_ON(a->replacementlen > a->instrlen);
20259 BUG_ON(a->instrlen > sizeof(insnbuf));
20260@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20261 for (poff = start; poff < end; poff++) {
20262 u8 *ptr = (u8 *)poff + *poff;
20263
20264+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20265+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20266+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20267+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20268+#endif
20269+
20270 if (!*poff || ptr < text || ptr >= text_end)
20271 continue;
20272 /* turn DS segment override prefix into lock prefix */
20273- if (*ptr == 0x3e)
20274+ if (*ktla_ktva(ptr) == 0x3e)
20275 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20276 }
20277 mutex_unlock(&text_mutex);
20278@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20279 for (poff = start; poff < end; poff++) {
20280 u8 *ptr = (u8 *)poff + *poff;
20281
20282+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20283+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20284+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20285+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20286+#endif
20287+
20288 if (!*poff || ptr < text || ptr >= text_end)
20289 continue;
20290 /* turn lock prefix into DS segment override prefix */
20291- if (*ptr == 0xf0)
20292+ if (*ktla_ktva(ptr) == 0xf0)
20293 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20294 }
20295 mutex_unlock(&text_mutex);
20296@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20297
20298 BUG_ON(p->len > MAX_PATCH_LEN);
20299 /* prep the buffer with the original instructions */
20300- memcpy(insnbuf, p->instr, p->len);
20301+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20302 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20303 (unsigned long)p->instr, p->len);
20304
20305@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20306 if (!uniproc_patched || num_possible_cpus() == 1)
20307 free_init_pages("SMP alternatives",
20308 (unsigned long)__smp_locks,
20309- (unsigned long)__smp_locks_end);
20310+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20311 #endif
20312
20313 apply_paravirt(__parainstructions, __parainstructions_end);
20314@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20315 * instructions. And on the local CPU you need to be protected again NMI or MCE
20316 * handlers seeing an inconsistent instruction while you patch.
20317 */
20318-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20319+void *__kprobes text_poke_early(void *addr, const void *opcode,
20320 size_t len)
20321 {
20322 unsigned long flags;
20323 local_irq_save(flags);
20324- memcpy(addr, opcode, len);
20325+
20326+ pax_open_kernel();
20327+ memcpy(ktla_ktva(addr), opcode, len);
20328 sync_core();
20329+ pax_close_kernel();
20330+
20331 local_irq_restore(flags);
20332 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20333 that causes hangs on some VIA CPUs. */
20334@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20335 */
20336 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20337 {
20338- unsigned long flags;
20339- char *vaddr;
20340+ unsigned char *vaddr = ktla_ktva(addr);
20341 struct page *pages[2];
20342- int i;
20343+ size_t i;
20344
20345 if (!core_kernel_text((unsigned long)addr)) {
20346- pages[0] = vmalloc_to_page(addr);
20347- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20348+ pages[0] = vmalloc_to_page(vaddr);
20349+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20350 } else {
20351- pages[0] = virt_to_page(addr);
20352+ pages[0] = virt_to_page(vaddr);
20353 WARN_ON(!PageReserved(pages[0]));
20354- pages[1] = virt_to_page(addr + PAGE_SIZE);
20355+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20356 }
20357 BUG_ON(!pages[0]);
20358- local_irq_save(flags);
20359- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20360- if (pages[1])
20361- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20362- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20363- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20364- clear_fixmap(FIX_TEXT_POKE0);
20365- if (pages[1])
20366- clear_fixmap(FIX_TEXT_POKE1);
20367- local_flush_tlb();
20368- sync_core();
20369- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20370- that causes hangs on some VIA CPUs. */
20371+ text_poke_early(addr, opcode, len);
20372 for (i = 0; i < len; i++)
20373- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20374- local_irq_restore(flags);
20375+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20376 return addr;
20377 }
20378
20379@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20380 if (likely(!bp_patching_in_progress))
20381 return 0;
20382
20383- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20384+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20385 return 0;
20386
20387 /* set up the specified breakpoint handler */
20388@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20389 */
20390 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20391 {
20392- unsigned char int3 = 0xcc;
20393+ const unsigned char int3 = 0xcc;
20394
20395 bp_int3_handler = handler;
20396 bp_int3_addr = (u8 *)addr + sizeof(int3);
20397diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20398index 7f26c9a..694544e 100644
20399--- a/arch/x86/kernel/apic/apic.c
20400+++ b/arch/x86/kernel/apic/apic.c
20401@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20402 /*
20403 * Debug level, exported for io_apic.c
20404 */
20405-unsigned int apic_verbosity;
20406+int apic_verbosity;
20407
20408 int pic_mode;
20409
20410@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20411 apic_write(APIC_ESR, 0);
20412 v = apic_read(APIC_ESR);
20413 ack_APIC_irq();
20414- atomic_inc(&irq_err_count);
20415+ atomic_inc_unchecked(&irq_err_count);
20416
20417 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20418 smp_processor_id(), v);
20419diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20420index 2c621a6..fa2b1ae 100644
20421--- a/arch/x86/kernel/apic/apic_flat_64.c
20422+++ b/arch/x86/kernel/apic/apic_flat_64.c
20423@@ -154,7 +154,7 @@ static int flat_probe(void)
20424 return 1;
20425 }
20426
20427-static struct apic apic_flat = {
20428+static struct apic apic_flat __read_only = {
20429 .name = "flat",
20430 .probe = flat_probe,
20431 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20432@@ -268,7 +268,7 @@ static int physflat_probe(void)
20433 return 0;
20434 }
20435
20436-static struct apic apic_physflat = {
20437+static struct apic apic_physflat __read_only = {
20438
20439 .name = "physical flat",
20440 .probe = physflat_probe,
20441diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20442index 191ce75..2db6d63 100644
20443--- a/arch/x86/kernel/apic/apic_noop.c
20444+++ b/arch/x86/kernel/apic/apic_noop.c
20445@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20446 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20447 }
20448
20449-struct apic apic_noop = {
20450+struct apic apic_noop __read_only = {
20451 .name = "noop",
20452 .probe = noop_probe,
20453 .acpi_madt_oem_check = NULL,
20454diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20455index d50e364..543bee3 100644
20456--- a/arch/x86/kernel/apic/bigsmp_32.c
20457+++ b/arch/x86/kernel/apic/bigsmp_32.c
20458@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20459 return dmi_bigsmp;
20460 }
20461
20462-static struct apic apic_bigsmp = {
20463+static struct apic apic_bigsmp __read_only = {
20464
20465 .name = "bigsmp",
20466 .probe = probe_bigsmp,
20467diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20468index c552247..587a316 100644
20469--- a/arch/x86/kernel/apic/es7000_32.c
20470+++ b/arch/x86/kernel/apic/es7000_32.c
20471@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20472 return ret && es7000_apic_is_cluster();
20473 }
20474
20475-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20476-static struct apic __refdata apic_es7000_cluster = {
20477+static struct apic apic_es7000_cluster __read_only = {
20478
20479 .name = "es7000",
20480 .probe = probe_es7000,
20481@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20482 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20483 };
20484
20485-static struct apic __refdata apic_es7000 = {
20486+static struct apic apic_es7000 __read_only = {
20487
20488 .name = "es7000",
20489 .probe = probe_es7000,
20490diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20491index 6ad4658..38a7b5c 100644
20492--- a/arch/x86/kernel/apic/io_apic.c
20493+++ b/arch/x86/kernel/apic/io_apic.c
20494@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20495 }
20496 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20497
20498-void lock_vector_lock(void)
20499+void lock_vector_lock(void) __acquires(vector_lock)
20500 {
20501 /* Used to the online set of cpus does not change
20502 * during assign_irq_vector.
20503@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20504 raw_spin_lock(&vector_lock);
20505 }
20506
20507-void unlock_vector_lock(void)
20508+void unlock_vector_lock(void) __releases(vector_lock)
20509 {
20510 raw_spin_unlock(&vector_lock);
20511 }
20512@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20513 ack_APIC_irq();
20514 }
20515
20516-atomic_t irq_mis_count;
20517+atomic_unchecked_t irq_mis_count;
20518
20519 #ifdef CONFIG_GENERIC_PENDING_IRQ
20520 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20521@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20522 * at the cpu.
20523 */
20524 if (!(v & (1 << (i & 0x1f)))) {
20525- atomic_inc(&irq_mis_count);
20526+ atomic_inc_unchecked(&irq_mis_count);
20527
20528 eoi_ioapic_irq(irq, cfg);
20529 }
20530diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20531index 1e42e8f..daacf44 100644
20532--- a/arch/x86/kernel/apic/numaq_32.c
20533+++ b/arch/x86/kernel/apic/numaq_32.c
20534@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20535 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20536 }
20537
20538-/* Use __refdata to keep false positive warning calm. */
20539-static struct apic __refdata apic_numaq = {
20540+static struct apic apic_numaq __read_only = {
20541
20542 .name = "NUMAQ",
20543 .probe = probe_numaq,
20544diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20545index eb35ef9..f184a21 100644
20546--- a/arch/x86/kernel/apic/probe_32.c
20547+++ b/arch/x86/kernel/apic/probe_32.c
20548@@ -72,7 +72,7 @@ static int probe_default(void)
20549 return 1;
20550 }
20551
20552-static struct apic apic_default = {
20553+static struct apic apic_default __read_only = {
20554
20555 .name = "default",
20556 .probe = probe_default,
20557diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20558index 00146f9..5e299b8 100644
20559--- a/arch/x86/kernel/apic/summit_32.c
20560+++ b/arch/x86/kernel/apic/summit_32.c
20561@@ -485,7 +485,7 @@ void setup_summit(void)
20562 }
20563 #endif
20564
20565-static struct apic apic_summit = {
20566+static struct apic apic_summit __read_only = {
20567
20568 .name = "summit",
20569 .probe = probe_summit,
20570diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20571index cac85ee..01fa741 100644
20572--- a/arch/x86/kernel/apic/x2apic_cluster.c
20573+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20574@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20575 return notifier_from_errno(err);
20576 }
20577
20578-static struct notifier_block __refdata x2apic_cpu_notifier = {
20579+static struct notifier_block x2apic_cpu_notifier = {
20580 .notifier_call = update_clusterinfo,
20581 };
20582
20583@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20584 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20585 }
20586
20587-static struct apic apic_x2apic_cluster = {
20588+static struct apic apic_x2apic_cluster __read_only = {
20589
20590 .name = "cluster x2apic",
20591 .probe = x2apic_cluster_probe,
20592diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20593index de231e3..1d1b2ee 100644
20594--- a/arch/x86/kernel/apic/x2apic_phys.c
20595+++ b/arch/x86/kernel/apic/x2apic_phys.c
20596@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20597 return apic == &apic_x2apic_phys;
20598 }
20599
20600-static struct apic apic_x2apic_phys = {
20601+static struct apic apic_x2apic_phys __read_only = {
20602
20603 .name = "physical x2apic",
20604 .probe = x2apic_phys_probe,
20605diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20606index d263b13..963258b 100644
20607--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20608+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20609@@ -350,7 +350,7 @@ static int uv_probe(void)
20610 return apic == &apic_x2apic_uv_x;
20611 }
20612
20613-static struct apic __refdata apic_x2apic_uv_x = {
20614+static struct apic apic_x2apic_uv_x __read_only = {
20615
20616 .name = "UV large system",
20617 .probe = uv_probe,
20618diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20619index 3ab0343..814c4787 100644
20620--- a/arch/x86/kernel/apm_32.c
20621+++ b/arch/x86/kernel/apm_32.c
20622@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20623 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20624 * even though they are called in protected mode.
20625 */
20626-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20627+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20628 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20629
20630 static const char driver_version[] = "1.16ac"; /* no spaces */
20631@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20632 BUG_ON(cpu != 0);
20633 gdt = get_cpu_gdt_table(cpu);
20634 save_desc_40 = gdt[0x40 / 8];
20635+
20636+ pax_open_kernel();
20637 gdt[0x40 / 8] = bad_bios_desc;
20638+ pax_close_kernel();
20639
20640 apm_irq_save(flags);
20641 APM_DO_SAVE_SEGS;
20642@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20643 &call->esi);
20644 APM_DO_RESTORE_SEGS;
20645 apm_irq_restore(flags);
20646+
20647+ pax_open_kernel();
20648 gdt[0x40 / 8] = save_desc_40;
20649+ pax_close_kernel();
20650+
20651 put_cpu();
20652
20653 return call->eax & 0xff;
20654@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20655 BUG_ON(cpu != 0);
20656 gdt = get_cpu_gdt_table(cpu);
20657 save_desc_40 = gdt[0x40 / 8];
20658+
20659+ pax_open_kernel();
20660 gdt[0x40 / 8] = bad_bios_desc;
20661+ pax_close_kernel();
20662
20663 apm_irq_save(flags);
20664 APM_DO_SAVE_SEGS;
20665@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20666 &call->eax);
20667 APM_DO_RESTORE_SEGS;
20668 apm_irq_restore(flags);
20669+
20670+ pax_open_kernel();
20671 gdt[0x40 / 8] = save_desc_40;
20672+ pax_close_kernel();
20673+
20674 put_cpu();
20675 return error;
20676 }
20677@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20678 * code to that CPU.
20679 */
20680 gdt = get_cpu_gdt_table(0);
20681+
20682+ pax_open_kernel();
20683 set_desc_base(&gdt[APM_CS >> 3],
20684 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20685 set_desc_base(&gdt[APM_CS_16 >> 3],
20686 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20687 set_desc_base(&gdt[APM_DS >> 3],
20688 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20689+ pax_close_kernel();
20690
20691 proc_create("apm", 0, NULL, &apm_file_ops);
20692
20693diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20694index 9f6b934..cf5ffb3 100644
20695--- a/arch/x86/kernel/asm-offsets.c
20696+++ b/arch/x86/kernel/asm-offsets.c
20697@@ -32,6 +32,8 @@ void common(void) {
20698 OFFSET(TI_flags, thread_info, flags);
20699 OFFSET(TI_status, thread_info, status);
20700 OFFSET(TI_addr_limit, thread_info, addr_limit);
20701+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20702+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20703
20704 BLANK();
20705 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20706@@ -52,8 +54,26 @@ void common(void) {
20707 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20708 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20709 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20710+
20711+#ifdef CONFIG_PAX_KERNEXEC
20712+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20713 #endif
20714
20715+#ifdef CONFIG_PAX_MEMORY_UDEREF
20716+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20717+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20718+#ifdef CONFIG_X86_64
20719+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20720+#endif
20721+#endif
20722+
20723+#endif
20724+
20725+ BLANK();
20726+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20727+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20728+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20729+
20730 #ifdef CONFIG_XEN
20731 BLANK();
20732 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20733diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20734index e7c798b..2b2019b 100644
20735--- a/arch/x86/kernel/asm-offsets_64.c
20736+++ b/arch/x86/kernel/asm-offsets_64.c
20737@@ -77,6 +77,7 @@ int main(void)
20738 BLANK();
20739 #undef ENTRY
20740
20741+ DEFINE(TSS_size, sizeof(struct tss_struct));
20742 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20743 BLANK();
20744
20745diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20746index 7fd54f0..0691410 100644
20747--- a/arch/x86/kernel/cpu/Makefile
20748+++ b/arch/x86/kernel/cpu/Makefile
20749@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20750 CFLAGS_REMOVE_perf_event.o = -pg
20751 endif
20752
20753-# Make sure load_percpu_segment has no stackprotector
20754-nostackp := $(call cc-option, -fno-stack-protector)
20755-CFLAGS_common.o := $(nostackp)
20756-
20757 obj-y := intel_cacheinfo.o scattered.o topology.o
20758 obj-y += proc.o capflags.o powerflags.o common.o
20759 obj-y += rdrand.o
20760diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20761index c67ffa6..f41fbbf 100644
20762--- a/arch/x86/kernel/cpu/amd.c
20763+++ b/arch/x86/kernel/cpu/amd.c
20764@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20765 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20766 {
20767 /* AMD errata T13 (order #21922) */
20768- if ((c->x86 == 6)) {
20769+ if (c->x86 == 6) {
20770 /* Duron Rev A0 */
20771 if (c->x86_model == 3 && c->x86_mask == 0)
20772 size = 64;
20773diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20774index 8e28bf2..bf5c0d2 100644
20775--- a/arch/x86/kernel/cpu/common.c
20776+++ b/arch/x86/kernel/cpu/common.c
20777@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20778
20779 static const struct cpu_dev *this_cpu = &default_cpu;
20780
20781-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20782-#ifdef CONFIG_X86_64
20783- /*
20784- * We need valid kernel segments for data and code in long mode too
20785- * IRET will check the segment types kkeil 2000/10/28
20786- * Also sysret mandates a special GDT layout
20787- *
20788- * TLS descriptors are currently at a different place compared to i386.
20789- * Hopefully nobody expects them at a fixed place (Wine?)
20790- */
20791- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20792- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20793- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20794- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20795- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20796- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20797-#else
20798- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20799- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20800- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20801- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20802- /*
20803- * Segments used for calling PnP BIOS have byte granularity.
20804- * They code segments and data segments have fixed 64k limits,
20805- * the transfer segment sizes are set at run time.
20806- */
20807- /* 32-bit code */
20808- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20809- /* 16-bit code */
20810- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20811- /* 16-bit data */
20812- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20813- /* 16-bit data */
20814- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20815- /* 16-bit data */
20816- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20817- /*
20818- * The APM segments have byte granularity and their bases
20819- * are set at run time. All have 64k limits.
20820- */
20821- /* 32-bit code */
20822- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20823- /* 16-bit code */
20824- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20825- /* data */
20826- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20827-
20828- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20829- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20830- GDT_STACK_CANARY_INIT
20831-#endif
20832-} };
20833-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20834-
20835 static int __init x86_xsave_setup(char *s)
20836 {
20837 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20838@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20839 }
20840 }
20841
20842+#ifdef CONFIG_X86_64
20843+static __init int setup_disable_pcid(char *arg)
20844+{
20845+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20846+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20847+
20848+#ifdef CONFIG_PAX_MEMORY_UDEREF
20849+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20850+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20851+#endif
20852+
20853+ return 1;
20854+}
20855+__setup("nopcid", setup_disable_pcid);
20856+
20857+static void setup_pcid(struct cpuinfo_x86 *c)
20858+{
20859+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20860+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20861+
20862+#ifdef CONFIG_PAX_MEMORY_UDEREF
20863+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20864+ pax_open_kernel();
20865+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20866+ pax_close_kernel();
20867+ printk("PAX: slow and weak UDEREF enabled\n");
20868+ } else
20869+ printk("PAX: UDEREF disabled\n");
20870+#endif
20871+
20872+ return;
20873+ }
20874+
20875+ printk("PAX: PCID detected\n");
20876+ set_in_cr4(X86_CR4_PCIDE);
20877+
20878+#ifdef CONFIG_PAX_MEMORY_UDEREF
20879+ pax_open_kernel();
20880+ clone_pgd_mask = ~(pgdval_t)0UL;
20881+ pax_close_kernel();
20882+ if (pax_user_shadow_base)
20883+ printk("PAX: weak UDEREF enabled\n");
20884+ else {
20885+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20886+ printk("PAX: strong UDEREF enabled\n");
20887+ }
20888+#endif
20889+
20890+ if (cpu_has(c, X86_FEATURE_INVPCID))
20891+ printk("PAX: INVPCID detected\n");
20892+}
20893+#endif
20894+
20895 /*
20896 * Some CPU features depend on higher CPUID levels, which may not always
20897 * be available due to CPUID level capping or broken virtualization
20898@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20899 {
20900 struct desc_ptr gdt_descr;
20901
20902- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20903+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20904 gdt_descr.size = GDT_SIZE - 1;
20905 load_gdt(&gdt_descr);
20906 /* Reload the per-cpu base */
20907@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20908 setup_smep(c);
20909 setup_smap(c);
20910
20911+#ifdef CONFIG_X86_64
20912+ setup_pcid(c);
20913+#endif
20914+
20915 /*
20916 * The vendor-specific functions might have changed features.
20917 * Now we do "generic changes."
20918@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20919 /* Filter out anything that depends on CPUID levels we don't have */
20920 filter_cpuid_features(c, true);
20921
20922+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20923+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20924+#endif
20925+
20926 /* If the model name is still unset, do table lookup. */
20927 if (!c->x86_model_id[0]) {
20928 const char *p;
20929@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20930 }
20931 __setup("clearcpuid=", setup_disablecpuid);
20932
20933+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20934+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20935+
20936 #ifdef CONFIG_X86_64
20937-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20938-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20939- (unsigned long) debug_idt_table };
20940+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20941+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20942
20943 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20944 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20945@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20946 EXPORT_PER_CPU_SYMBOL(current_task);
20947
20948 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20949- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20950+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20951 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20952
20953 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20954@@ -1245,7 +1254,7 @@ void cpu_init(void)
20955 load_ucode_ap();
20956
20957 cpu = stack_smp_processor_id();
20958- t = &per_cpu(init_tss, cpu);
20959+ t = init_tss + cpu;
20960 oist = &per_cpu(orig_ist, cpu);
20961
20962 #ifdef CONFIG_NUMA
20963@@ -1280,7 +1289,6 @@ void cpu_init(void)
20964 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20965 barrier();
20966
20967- x86_configure_nx();
20968 enable_x2apic();
20969
20970 /*
20971@@ -1332,7 +1340,7 @@ void cpu_init(void)
20972 {
20973 int cpu = smp_processor_id();
20974 struct task_struct *curr = current;
20975- struct tss_struct *t = &per_cpu(init_tss, cpu);
20976+ struct tss_struct *t = init_tss + cpu;
20977 struct thread_struct *thread = &curr->thread;
20978
20979 show_ucode_info_early();
20980diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20981index 0641113..06f5ba4 100644
20982--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20983+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20984@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20985 };
20986
20987 #ifdef CONFIG_AMD_NB
20988+static struct attribute *default_attrs_amd_nb[] = {
20989+ &type.attr,
20990+ &level.attr,
20991+ &coherency_line_size.attr,
20992+ &physical_line_partition.attr,
20993+ &ways_of_associativity.attr,
20994+ &number_of_sets.attr,
20995+ &size.attr,
20996+ &shared_cpu_map.attr,
20997+ &shared_cpu_list.attr,
20998+ NULL,
20999+ NULL,
21000+ NULL,
21001+ NULL
21002+};
21003+
21004 static struct attribute **amd_l3_attrs(void)
21005 {
21006 static struct attribute **attrs;
21007@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21008
21009 n = ARRAY_SIZE(default_attrs);
21010
21011- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21012- n += 2;
21013-
21014- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21015- n += 1;
21016-
21017- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21018- if (attrs == NULL)
21019- return attrs = default_attrs;
21020-
21021- for (n = 0; default_attrs[n]; n++)
21022- attrs[n] = default_attrs[n];
21023+ attrs = default_attrs_amd_nb;
21024
21025 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21026 attrs[n++] = &cache_disable_0.attr;
21027@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21028 .default_attrs = default_attrs,
21029 };
21030
21031+#ifdef CONFIG_AMD_NB
21032+static struct kobj_type ktype_cache_amd_nb = {
21033+ .sysfs_ops = &sysfs_ops,
21034+ .default_attrs = default_attrs_amd_nb,
21035+};
21036+#endif
21037+
21038 static struct kobj_type ktype_percpu_entry = {
21039 .sysfs_ops = &sysfs_ops,
21040 };
21041@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21042 return retval;
21043 }
21044
21045+#ifdef CONFIG_AMD_NB
21046+ amd_l3_attrs();
21047+#endif
21048+
21049 for (i = 0; i < num_cache_leaves; i++) {
21050+ struct kobj_type *ktype;
21051+
21052 this_object = INDEX_KOBJECT_PTR(cpu, i);
21053 this_object->cpu = cpu;
21054 this_object->index = i;
21055
21056 this_leaf = CPUID4_INFO_IDX(cpu, i);
21057
21058- ktype_cache.default_attrs = default_attrs;
21059+ ktype = &ktype_cache;
21060 #ifdef CONFIG_AMD_NB
21061 if (this_leaf->base.nb)
21062- ktype_cache.default_attrs = amd_l3_attrs();
21063+ ktype = &ktype_cache_amd_nb;
21064 #endif
21065 retval = kobject_init_and_add(&(this_object->kobj),
21066- &ktype_cache,
21067+ ktype,
21068 per_cpu(ici_cache_kobject, cpu),
21069 "index%1lu", i);
21070 if (unlikely(retval)) {
21071diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21072index 4d5419b..95f11bb 100644
21073--- a/arch/x86/kernel/cpu/mcheck/mce.c
21074+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21075@@ -45,6 +45,7 @@
21076 #include <asm/processor.h>
21077 #include <asm/mce.h>
21078 #include <asm/msr.h>
21079+#include <asm/local.h>
21080
21081 #include "mce-internal.h"
21082
21083@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21084 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21085 m->cs, m->ip);
21086
21087- if (m->cs == __KERNEL_CS)
21088+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21089 print_symbol("{%s}", m->ip);
21090 pr_cont("\n");
21091 }
21092@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21093
21094 #define PANIC_TIMEOUT 5 /* 5 seconds */
21095
21096-static atomic_t mce_paniced;
21097+static atomic_unchecked_t mce_paniced;
21098
21099 static int fake_panic;
21100-static atomic_t mce_fake_paniced;
21101+static atomic_unchecked_t mce_fake_paniced;
21102
21103 /* Panic in progress. Enable interrupts and wait for final IPI */
21104 static void wait_for_panic(void)
21105@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21106 /*
21107 * Make sure only one CPU runs in machine check panic
21108 */
21109- if (atomic_inc_return(&mce_paniced) > 1)
21110+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21111 wait_for_panic();
21112 barrier();
21113
21114@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21115 console_verbose();
21116 } else {
21117 /* Don't log too much for fake panic */
21118- if (atomic_inc_return(&mce_fake_paniced) > 1)
21119+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21120 return;
21121 }
21122 /* First print corrected ones that are still unlogged */
21123@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21124 if (!fake_panic) {
21125 if (panic_timeout == 0)
21126 panic_timeout = mca_cfg.panic_timeout;
21127- panic(msg);
21128+ panic("%s", msg);
21129 } else
21130 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21131 }
21132@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21133 * might have been modified by someone else.
21134 */
21135 rmb();
21136- if (atomic_read(&mce_paniced))
21137+ if (atomic_read_unchecked(&mce_paniced))
21138 wait_for_panic();
21139 if (!mca_cfg.monarch_timeout)
21140 goto out;
21141@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21142 }
21143
21144 /* Call the installed machine check handler for this CPU setup. */
21145-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21146+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21147 unexpected_machine_check;
21148
21149 /*
21150@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21151 return;
21152 }
21153
21154+ pax_open_kernel();
21155 machine_check_vector = do_machine_check;
21156+ pax_close_kernel();
21157
21158 __mcheck_cpu_init_generic();
21159 __mcheck_cpu_init_vendor(c);
21160@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21161 */
21162
21163 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21164-static int mce_chrdev_open_count; /* #times opened */
21165+static local_t mce_chrdev_open_count; /* #times opened */
21166 static int mce_chrdev_open_exclu; /* already open exclusive? */
21167
21168 static int mce_chrdev_open(struct inode *inode, struct file *file)
21169@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21170 spin_lock(&mce_chrdev_state_lock);
21171
21172 if (mce_chrdev_open_exclu ||
21173- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21174+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21175 spin_unlock(&mce_chrdev_state_lock);
21176
21177 return -EBUSY;
21178@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21179
21180 if (file->f_flags & O_EXCL)
21181 mce_chrdev_open_exclu = 1;
21182- mce_chrdev_open_count++;
21183+ local_inc(&mce_chrdev_open_count);
21184
21185 spin_unlock(&mce_chrdev_state_lock);
21186
21187@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21188 {
21189 spin_lock(&mce_chrdev_state_lock);
21190
21191- mce_chrdev_open_count--;
21192+ local_dec(&mce_chrdev_open_count);
21193 mce_chrdev_open_exclu = 0;
21194
21195 spin_unlock(&mce_chrdev_state_lock);
21196@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21197
21198 for (i = 0; i < mca_cfg.banks; i++) {
21199 struct mce_bank *b = &mce_banks[i];
21200- struct device_attribute *a = &b->attr;
21201+ device_attribute_no_const *a = &b->attr;
21202
21203 sysfs_attr_init(&a->attr);
21204 a->attr.name = b->attrname;
21205@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21206 static void mce_reset(void)
21207 {
21208 cpu_missing = 0;
21209- atomic_set(&mce_fake_paniced, 0);
21210+ atomic_set_unchecked(&mce_fake_paniced, 0);
21211 atomic_set(&mce_executing, 0);
21212 atomic_set(&mce_callin, 0);
21213 atomic_set(&global_nwo, 0);
21214diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21215index a304298..49b6d06 100644
21216--- a/arch/x86/kernel/cpu/mcheck/p5.c
21217+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21218@@ -10,6 +10,7 @@
21219 #include <asm/processor.h>
21220 #include <asm/mce.h>
21221 #include <asm/msr.h>
21222+#include <asm/pgtable.h>
21223
21224 /* By default disabled */
21225 int mce_p5_enabled __read_mostly;
21226@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21227 if (!cpu_has(c, X86_FEATURE_MCE))
21228 return;
21229
21230+ pax_open_kernel();
21231 machine_check_vector = pentium_machine_check;
21232+ pax_close_kernel();
21233 /* Make sure the vector pointer is visible before we enable MCEs: */
21234 wmb();
21235
21236diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21237index 7dc5564..1273569 100644
21238--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21239+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21240@@ -9,6 +9,7 @@
21241 #include <asm/processor.h>
21242 #include <asm/mce.h>
21243 #include <asm/msr.h>
21244+#include <asm/pgtable.h>
21245
21246 /* Machine check handler for WinChip C6: */
21247 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21248@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21249 {
21250 u32 lo, hi;
21251
21252+ pax_open_kernel();
21253 machine_check_vector = winchip_machine_check;
21254+ pax_close_kernel();
21255 /* Make sure the vector pointer is visible before we enable MCEs: */
21256 wmb();
21257
21258diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21259index 15c9876..0a43909 100644
21260--- a/arch/x86/kernel/cpu/microcode/core.c
21261+++ b/arch/x86/kernel/cpu/microcode/core.c
21262@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21263 return NOTIFY_OK;
21264 }
21265
21266-static struct notifier_block __refdata mc_cpu_notifier = {
21267+static struct notifier_block mc_cpu_notifier = {
21268 .notifier_call = mc_cpu_callback,
21269 };
21270
21271diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21272index a276fa7..e66810f 100644
21273--- a/arch/x86/kernel/cpu/microcode/intel.c
21274+++ b/arch/x86/kernel/cpu/microcode/intel.c
21275@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21276
21277 static int get_ucode_user(void *to, const void *from, size_t n)
21278 {
21279- return copy_from_user(to, from, n);
21280+ return copy_from_user(to, (const void __force_user *)from, n);
21281 }
21282
21283 static enum ucode_state
21284 request_microcode_user(int cpu, const void __user *buf, size_t size)
21285 {
21286- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21287+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21288 }
21289
21290 static void microcode_fini_cpu(int cpu)
21291diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21292index f961de9..8a9d332 100644
21293--- a/arch/x86/kernel/cpu/mtrr/main.c
21294+++ b/arch/x86/kernel/cpu/mtrr/main.c
21295@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21296 u64 size_or_mask, size_and_mask;
21297 static bool mtrr_aps_delayed_init;
21298
21299-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21300+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21301
21302 const struct mtrr_ops *mtrr_if;
21303
21304diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21305index df5e41f..816c719 100644
21306--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21307+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21308@@ -25,7 +25,7 @@ struct mtrr_ops {
21309 int (*validate_add_page)(unsigned long base, unsigned long size,
21310 unsigned int type);
21311 int (*have_wrcomb)(void);
21312-};
21313+} __do_const;
21314
21315 extern int generic_get_free_region(unsigned long base, unsigned long size,
21316 int replace_reg);
21317diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21318index 79f9f84..38ace52 100644
21319--- a/arch/x86/kernel/cpu/perf_event.c
21320+++ b/arch/x86/kernel/cpu/perf_event.c
21321@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21322 pr_info("no hardware sampling interrupt available.\n");
21323 }
21324
21325-static struct attribute_group x86_pmu_format_group = {
21326+static attribute_group_no_const x86_pmu_format_group = {
21327 .name = "format",
21328 .attrs = NULL,
21329 };
21330@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21331 NULL,
21332 };
21333
21334-static struct attribute_group x86_pmu_events_group = {
21335+static attribute_group_no_const x86_pmu_events_group = {
21336 .name = "events",
21337 .attrs = events_attr,
21338 };
21339@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21340 if (idx > GDT_ENTRIES)
21341 return 0;
21342
21343- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21344+ desc = get_cpu_gdt_table(smp_processor_id());
21345 }
21346
21347 return get_desc_base(desc + idx);
21348@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21349 break;
21350
21351 perf_callchain_store(entry, frame.return_address);
21352- fp = frame.next_frame;
21353+ fp = (const void __force_user *)frame.next_frame;
21354 }
21355 }
21356
21357diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21358index 639d128..e92d7e5 100644
21359--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21360+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21361@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21362 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21363 {
21364 struct attribute **attrs;
21365- struct attribute_group *attr_group;
21366+ attribute_group_no_const *attr_group;
21367 int i = 0, j;
21368
21369 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21370diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21371index aa333d9..f9db700 100644
21372--- a/arch/x86/kernel/cpu/perf_event_intel.c
21373+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21374@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21375 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21376
21377 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21378- u64 capabilities;
21379+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21380
21381- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21382- x86_pmu.intel_cap.capabilities = capabilities;
21383+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21384+ x86_pmu.intel_cap.capabilities = capabilities;
21385 }
21386
21387 intel_ds_init();
21388diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21389index 5ad35ad..e0a3960 100644
21390--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21391+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21392@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21393 NULL,
21394 };
21395
21396-static struct attribute_group rapl_pmu_events_group = {
21397+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21398 .name = "events",
21399 .attrs = NULL, /* patched at runtime */
21400 };
21401diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21402index 047f540..afdeba0 100644
21403--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21404+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21405@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21406 static int __init uncore_type_init(struct intel_uncore_type *type)
21407 {
21408 struct intel_uncore_pmu *pmus;
21409- struct attribute_group *attr_group;
21410+ attribute_group_no_const *attr_group;
21411 struct attribute **attrs;
21412 int i, j;
21413
21414diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21415index a80ab71..4089da5 100644
21416--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21417+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21418@@ -498,7 +498,7 @@ struct intel_uncore_box {
21419 struct uncore_event_desc {
21420 struct kobj_attribute attr;
21421 const char *config;
21422-};
21423+} __do_const;
21424
21425 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21426 { \
21427diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21428index 7d9481c..99c7e4b 100644
21429--- a/arch/x86/kernel/cpuid.c
21430+++ b/arch/x86/kernel/cpuid.c
21431@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21432 return notifier_from_errno(err);
21433 }
21434
21435-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21436+static struct notifier_block cpuid_class_cpu_notifier =
21437 {
21438 .notifier_call = cpuid_class_cpu_callback,
21439 };
21440diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21441index a57902e..ebaae2a 100644
21442--- a/arch/x86/kernel/crash.c
21443+++ b/arch/x86/kernel/crash.c
21444@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21445 {
21446 #ifdef CONFIG_X86_32
21447 struct pt_regs fixed_regs;
21448-#endif
21449
21450-#ifdef CONFIG_X86_32
21451- if (!user_mode_vm(regs)) {
21452+ if (!user_mode(regs)) {
21453 crash_fixup_ss_esp(&fixed_regs, regs);
21454 regs = &fixed_regs;
21455 }
21456diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21457index afa64ad..dce67dd 100644
21458--- a/arch/x86/kernel/crash_dump_64.c
21459+++ b/arch/x86/kernel/crash_dump_64.c
21460@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21461 return -ENOMEM;
21462
21463 if (userbuf) {
21464- if (copy_to_user(buf, vaddr + offset, csize)) {
21465+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21466 iounmap(vaddr);
21467 return -EFAULT;
21468 }
21469diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21470index f6dfd93..892ade4 100644
21471--- a/arch/x86/kernel/doublefault.c
21472+++ b/arch/x86/kernel/doublefault.c
21473@@ -12,7 +12,7 @@
21474
21475 #define DOUBLEFAULT_STACKSIZE (1024)
21476 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21477-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21478+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21479
21480 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21481
21482@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21483 unsigned long gdt, tss;
21484
21485 native_store_gdt(&gdt_desc);
21486- gdt = gdt_desc.address;
21487+ gdt = (unsigned long)gdt_desc.address;
21488
21489 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21490
21491@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21492 /* 0x2 bit is always set */
21493 .flags = X86_EFLAGS_SF | 0x2,
21494 .sp = STACK_START,
21495- .es = __USER_DS,
21496+ .es = __KERNEL_DS,
21497 .cs = __KERNEL_CS,
21498 .ss = __KERNEL_DS,
21499- .ds = __USER_DS,
21500+ .ds = __KERNEL_DS,
21501 .fs = __KERNEL_PERCPU,
21502
21503 .__cr3 = __pa_nodebug(swapper_pg_dir),
21504diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21505index d9c12d3..7858b62 100644
21506--- a/arch/x86/kernel/dumpstack.c
21507+++ b/arch/x86/kernel/dumpstack.c
21508@@ -2,6 +2,9 @@
21509 * Copyright (C) 1991, 1992 Linus Torvalds
21510 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21511 */
21512+#ifdef CONFIG_GRKERNSEC_HIDESYM
21513+#define __INCLUDED_BY_HIDESYM 1
21514+#endif
21515 #include <linux/kallsyms.h>
21516 #include <linux/kprobes.h>
21517 #include <linux/uaccess.h>
21518@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21519 static void
21520 print_ftrace_graph_addr(unsigned long addr, void *data,
21521 const struct stacktrace_ops *ops,
21522- struct thread_info *tinfo, int *graph)
21523+ struct task_struct *task, int *graph)
21524 {
21525- struct task_struct *task;
21526 unsigned long ret_addr;
21527 int index;
21528
21529 if (addr != (unsigned long)return_to_handler)
21530 return;
21531
21532- task = tinfo->task;
21533 index = task->curr_ret_stack;
21534
21535 if (!task->ret_stack || index < *graph)
21536@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21537 static inline void
21538 print_ftrace_graph_addr(unsigned long addr, void *data,
21539 const struct stacktrace_ops *ops,
21540- struct thread_info *tinfo, int *graph)
21541+ struct task_struct *task, int *graph)
21542 { }
21543 #endif
21544
21545@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21546 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21547 */
21548
21549-static inline int valid_stack_ptr(struct thread_info *tinfo,
21550- void *p, unsigned int size, void *end)
21551+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21552 {
21553- void *t = tinfo;
21554 if (end) {
21555 if (p < end && p >= (end-THREAD_SIZE))
21556 return 1;
21557@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21558 }
21559
21560 unsigned long
21561-print_context_stack(struct thread_info *tinfo,
21562+print_context_stack(struct task_struct *task, void *stack_start,
21563 unsigned long *stack, unsigned long bp,
21564 const struct stacktrace_ops *ops, void *data,
21565 unsigned long *end, int *graph)
21566 {
21567 struct stack_frame *frame = (struct stack_frame *)bp;
21568
21569- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21570+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21571 unsigned long addr;
21572
21573 addr = *stack;
21574@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21575 } else {
21576 ops->address(data, addr, 0);
21577 }
21578- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21579+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21580 }
21581 stack++;
21582 }
21583@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21584 EXPORT_SYMBOL_GPL(print_context_stack);
21585
21586 unsigned long
21587-print_context_stack_bp(struct thread_info *tinfo,
21588+print_context_stack_bp(struct task_struct *task, void *stack_start,
21589 unsigned long *stack, unsigned long bp,
21590 const struct stacktrace_ops *ops, void *data,
21591 unsigned long *end, int *graph)
21592@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21593 struct stack_frame *frame = (struct stack_frame *)bp;
21594 unsigned long *ret_addr = &frame->return_address;
21595
21596- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21597+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21598 unsigned long addr = *ret_addr;
21599
21600 if (!__kernel_text_address(addr))
21601@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21602 ops->address(data, addr, 1);
21603 frame = frame->next_frame;
21604 ret_addr = &frame->return_address;
21605- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21606+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21607 }
21608
21609 return (unsigned long)frame;
21610@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21611 static void print_trace_address(void *data, unsigned long addr, int reliable)
21612 {
21613 touch_nmi_watchdog();
21614- printk(data);
21615+ printk("%s", (char *)data);
21616 printk_stack_address(addr, reliable);
21617 }
21618
21619@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21620 }
21621 EXPORT_SYMBOL_GPL(oops_begin);
21622
21623+extern void gr_handle_kernel_exploit(void);
21624+
21625 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21626 {
21627 if (regs && kexec_should_crash(current))
21628@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21629 panic("Fatal exception in interrupt");
21630 if (panic_on_oops)
21631 panic("Fatal exception");
21632- do_exit(signr);
21633+
21634+ gr_handle_kernel_exploit();
21635+
21636+ do_group_exit(signr);
21637 }
21638
21639 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21640@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21641 print_modules();
21642 show_regs(regs);
21643 #ifdef CONFIG_X86_32
21644- if (user_mode_vm(regs)) {
21645+ if (user_mode(regs)) {
21646 sp = regs->sp;
21647 ss = regs->ss & 0xffff;
21648 } else {
21649@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21650 unsigned long flags = oops_begin();
21651 int sig = SIGSEGV;
21652
21653- if (!user_mode_vm(regs))
21654+ if (!user_mode(regs))
21655 report_bug(regs->ip, regs);
21656
21657 if (__die(str, regs, err))
21658diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21659index f2a1770..540657f 100644
21660--- a/arch/x86/kernel/dumpstack_32.c
21661+++ b/arch/x86/kernel/dumpstack_32.c
21662@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21663 bp = stack_frame(task, regs);
21664
21665 for (;;) {
21666- struct thread_info *context;
21667+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21668
21669- context = (struct thread_info *)
21670- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21671- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21672+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21673
21674- stack = (unsigned long *)context->previous_esp;
21675- if (!stack)
21676+ if (stack_start == task_stack_page(task))
21677 break;
21678+ stack = *(unsigned long **)stack_start;
21679 if (ops->stack(data, "IRQ") < 0)
21680 break;
21681 touch_nmi_watchdog();
21682@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21683 int i;
21684
21685 show_regs_print_info(KERN_EMERG);
21686- __show_regs(regs, !user_mode_vm(regs));
21687+ __show_regs(regs, !user_mode(regs));
21688
21689 /*
21690 * When in-kernel, we also print out the stack and code at the
21691 * time of the fault..
21692 */
21693- if (!user_mode_vm(regs)) {
21694+ if (!user_mode(regs)) {
21695 unsigned int code_prologue = code_bytes * 43 / 64;
21696 unsigned int code_len = code_bytes;
21697 unsigned char c;
21698 u8 *ip;
21699+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21700
21701 pr_emerg("Stack:\n");
21702 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21703
21704 pr_emerg("Code:");
21705
21706- ip = (u8 *)regs->ip - code_prologue;
21707+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21708 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21709 /* try starting at IP */
21710- ip = (u8 *)regs->ip;
21711+ ip = (u8 *)regs->ip + cs_base;
21712 code_len = code_len - code_prologue + 1;
21713 }
21714 for (i = 0; i < code_len; i++, ip++) {
21715@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21716 pr_cont(" Bad EIP value.");
21717 break;
21718 }
21719- if (ip == (u8 *)regs->ip)
21720+ if (ip == (u8 *)regs->ip + cs_base)
21721 pr_cont(" <%02x>", c);
21722 else
21723 pr_cont(" %02x", c);
21724@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21725 {
21726 unsigned short ud2;
21727
21728+ ip = ktla_ktva(ip);
21729 if (ip < PAGE_OFFSET)
21730 return 0;
21731 if (probe_kernel_address((unsigned short *)ip, ud2))
21732@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21733
21734 return ud2 == 0x0b0f;
21735 }
21736+
21737+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21738+void pax_check_alloca(unsigned long size)
21739+{
21740+ unsigned long sp = (unsigned long)&sp, stack_left;
21741+
21742+ /* all kernel stacks are of the same size */
21743+ stack_left = sp & (THREAD_SIZE - 1);
21744+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21745+}
21746+EXPORT_SYMBOL(pax_check_alloca);
21747+#endif
21748diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21749index addb207..99635fa 100644
21750--- a/arch/x86/kernel/dumpstack_64.c
21751+++ b/arch/x86/kernel/dumpstack_64.c
21752@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21753 unsigned long *irq_stack_end =
21754 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21755 unsigned used = 0;
21756- struct thread_info *tinfo;
21757 int graph = 0;
21758 unsigned long dummy;
21759+ void *stack_start;
21760
21761 if (!task)
21762 task = current;
21763@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21764 * current stack address. If the stacks consist of nested
21765 * exceptions
21766 */
21767- tinfo = task_thread_info(task);
21768 for (;;) {
21769 char *id;
21770 unsigned long *estack_end;
21771+
21772 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21773 &used, &id);
21774
21775@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21776 if (ops->stack(data, id) < 0)
21777 break;
21778
21779- bp = ops->walk_stack(tinfo, stack, bp, ops,
21780+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21781 data, estack_end, &graph);
21782 ops->stack(data, "<EOE>");
21783 /*
21784@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21785 * second-to-last pointer (index -2 to end) in the
21786 * exception stack:
21787 */
21788+ if ((u16)estack_end[-1] != __KERNEL_DS)
21789+ goto out;
21790 stack = (unsigned long *) estack_end[-2];
21791 continue;
21792 }
21793@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21794 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21795 if (ops->stack(data, "IRQ") < 0)
21796 break;
21797- bp = ops->walk_stack(tinfo, stack, bp,
21798+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21799 ops, data, irq_stack_end, &graph);
21800 /*
21801 * We link to the next stack (which would be
21802@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21803 /*
21804 * This handles the process stack:
21805 */
21806- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21807+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21808+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21809+out:
21810 put_cpu();
21811 }
21812 EXPORT_SYMBOL(dump_trace);
21813@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21814
21815 return ud2 == 0x0b0f;
21816 }
21817+
21818+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21819+void pax_check_alloca(unsigned long size)
21820+{
21821+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21822+ unsigned cpu, used;
21823+ char *id;
21824+
21825+ /* check the process stack first */
21826+ stack_start = (unsigned long)task_stack_page(current);
21827+ stack_end = stack_start + THREAD_SIZE;
21828+ if (likely(stack_start <= sp && sp < stack_end)) {
21829+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21830+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21831+ return;
21832+ }
21833+
21834+ cpu = get_cpu();
21835+
21836+ /* check the irq stacks */
21837+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21838+ stack_start = stack_end - IRQ_STACK_SIZE;
21839+ if (stack_start <= sp && sp < stack_end) {
21840+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21841+ put_cpu();
21842+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21843+ return;
21844+ }
21845+
21846+ /* check the exception stacks */
21847+ used = 0;
21848+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21849+ stack_start = stack_end - EXCEPTION_STKSZ;
21850+ if (stack_end && stack_start <= sp && sp < stack_end) {
21851+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21852+ put_cpu();
21853+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21854+ return;
21855+ }
21856+
21857+ put_cpu();
21858+
21859+ /* unknown stack */
21860+ BUG();
21861+}
21862+EXPORT_SYMBOL(pax_check_alloca);
21863+#endif
21864diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21865index 988c00a..4f673b6 100644
21866--- a/arch/x86/kernel/e820.c
21867+++ b/arch/x86/kernel/e820.c
21868@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21869
21870 static void early_panic(char *msg)
21871 {
21872- early_printk(msg);
21873- panic(msg);
21874+ early_printk("%s", msg);
21875+ panic("%s", msg);
21876 }
21877
21878 static int userdef __initdata;
21879diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21880index 01d1c18..8073693 100644
21881--- a/arch/x86/kernel/early_printk.c
21882+++ b/arch/x86/kernel/early_printk.c
21883@@ -7,6 +7,7 @@
21884 #include <linux/pci_regs.h>
21885 #include <linux/pci_ids.h>
21886 #include <linux/errno.h>
21887+#include <linux/sched.h>
21888 #include <asm/io.h>
21889 #include <asm/processor.h>
21890 #include <asm/fcntl.h>
21891diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21892index a2a4f46..6cab058 100644
21893--- a/arch/x86/kernel/entry_32.S
21894+++ b/arch/x86/kernel/entry_32.S
21895@@ -177,13 +177,153 @@
21896 /*CFI_REL_OFFSET gs, PT_GS*/
21897 .endm
21898 .macro SET_KERNEL_GS reg
21899+
21900+#ifdef CONFIG_CC_STACKPROTECTOR
21901 movl $(__KERNEL_STACK_CANARY), \reg
21902+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21903+ movl $(__USER_DS), \reg
21904+#else
21905+ xorl \reg, \reg
21906+#endif
21907+
21908 movl \reg, %gs
21909 .endm
21910
21911 #endif /* CONFIG_X86_32_LAZY_GS */
21912
21913-.macro SAVE_ALL
21914+.macro pax_enter_kernel
21915+#ifdef CONFIG_PAX_KERNEXEC
21916+ call pax_enter_kernel
21917+#endif
21918+.endm
21919+
21920+.macro pax_exit_kernel
21921+#ifdef CONFIG_PAX_KERNEXEC
21922+ call pax_exit_kernel
21923+#endif
21924+.endm
21925+
21926+#ifdef CONFIG_PAX_KERNEXEC
21927+ENTRY(pax_enter_kernel)
21928+#ifdef CONFIG_PARAVIRT
21929+ pushl %eax
21930+ pushl %ecx
21931+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21932+ mov %eax, %esi
21933+#else
21934+ mov %cr0, %esi
21935+#endif
21936+ bts $16, %esi
21937+ jnc 1f
21938+ mov %cs, %esi
21939+ cmp $__KERNEL_CS, %esi
21940+ jz 3f
21941+ ljmp $__KERNEL_CS, $3f
21942+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21943+2:
21944+#ifdef CONFIG_PARAVIRT
21945+ mov %esi, %eax
21946+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21947+#else
21948+ mov %esi, %cr0
21949+#endif
21950+3:
21951+#ifdef CONFIG_PARAVIRT
21952+ popl %ecx
21953+ popl %eax
21954+#endif
21955+ ret
21956+ENDPROC(pax_enter_kernel)
21957+
21958+ENTRY(pax_exit_kernel)
21959+#ifdef CONFIG_PARAVIRT
21960+ pushl %eax
21961+ pushl %ecx
21962+#endif
21963+ mov %cs, %esi
21964+ cmp $__KERNEXEC_KERNEL_CS, %esi
21965+ jnz 2f
21966+#ifdef CONFIG_PARAVIRT
21967+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21968+ mov %eax, %esi
21969+#else
21970+ mov %cr0, %esi
21971+#endif
21972+ btr $16, %esi
21973+ ljmp $__KERNEL_CS, $1f
21974+1:
21975+#ifdef CONFIG_PARAVIRT
21976+ mov %esi, %eax
21977+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21978+#else
21979+ mov %esi, %cr0
21980+#endif
21981+2:
21982+#ifdef CONFIG_PARAVIRT
21983+ popl %ecx
21984+ popl %eax
21985+#endif
21986+ ret
21987+ENDPROC(pax_exit_kernel)
21988+#endif
21989+
21990+ .macro pax_erase_kstack
21991+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21992+ call pax_erase_kstack
21993+#endif
21994+ .endm
21995+
21996+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21997+/*
21998+ * ebp: thread_info
21999+ */
22000+ENTRY(pax_erase_kstack)
22001+ pushl %edi
22002+ pushl %ecx
22003+ pushl %eax
22004+
22005+ mov TI_lowest_stack(%ebp), %edi
22006+ mov $-0xBEEF, %eax
22007+ std
22008+
22009+1: mov %edi, %ecx
22010+ and $THREAD_SIZE_asm - 1, %ecx
22011+ shr $2, %ecx
22012+ repne scasl
22013+ jecxz 2f
22014+
22015+ cmp $2*16, %ecx
22016+ jc 2f
22017+
22018+ mov $2*16, %ecx
22019+ repe scasl
22020+ jecxz 2f
22021+ jne 1b
22022+
22023+2: cld
22024+ mov %esp, %ecx
22025+ sub %edi, %ecx
22026+
22027+ cmp $THREAD_SIZE_asm, %ecx
22028+ jb 3f
22029+ ud2
22030+3:
22031+
22032+ shr $2, %ecx
22033+ rep stosl
22034+
22035+ mov TI_task_thread_sp0(%ebp), %edi
22036+ sub $128, %edi
22037+ mov %edi, TI_lowest_stack(%ebp)
22038+
22039+ popl %eax
22040+ popl %ecx
22041+ popl %edi
22042+ ret
22043+ENDPROC(pax_erase_kstack)
22044+#endif
22045+
22046+.macro __SAVE_ALL _DS
22047 cld
22048 PUSH_GS
22049 pushl_cfi %fs
22050@@ -206,7 +346,7 @@
22051 CFI_REL_OFFSET ecx, 0
22052 pushl_cfi %ebx
22053 CFI_REL_OFFSET ebx, 0
22054- movl $(__USER_DS), %edx
22055+ movl $\_DS, %edx
22056 movl %edx, %ds
22057 movl %edx, %es
22058 movl $(__KERNEL_PERCPU), %edx
22059@@ -214,6 +354,15 @@
22060 SET_KERNEL_GS %edx
22061 .endm
22062
22063+.macro SAVE_ALL
22064+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22065+ __SAVE_ALL __KERNEL_DS
22066+ pax_enter_kernel
22067+#else
22068+ __SAVE_ALL __USER_DS
22069+#endif
22070+.endm
22071+
22072 .macro RESTORE_INT_REGS
22073 popl_cfi %ebx
22074 CFI_RESTORE ebx
22075@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22076 popfl_cfi
22077 jmp syscall_exit
22078 CFI_ENDPROC
22079-END(ret_from_fork)
22080+ENDPROC(ret_from_fork)
22081
22082 ENTRY(ret_from_kernel_thread)
22083 CFI_STARTPROC
22084@@ -344,7 +493,15 @@ ret_from_intr:
22085 andl $SEGMENT_RPL_MASK, %eax
22086 #endif
22087 cmpl $USER_RPL, %eax
22088+
22089+#ifdef CONFIG_PAX_KERNEXEC
22090+ jae resume_userspace
22091+
22092+ pax_exit_kernel
22093+ jmp resume_kernel
22094+#else
22095 jb resume_kernel # not returning to v8086 or userspace
22096+#endif
22097
22098 ENTRY(resume_userspace)
22099 LOCKDEP_SYS_EXIT
22100@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22101 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22102 # int/exception return?
22103 jne work_pending
22104- jmp restore_all
22105-END(ret_from_exception)
22106+ jmp restore_all_pax
22107+ENDPROC(ret_from_exception)
22108
22109 #ifdef CONFIG_PREEMPT
22110 ENTRY(resume_kernel)
22111@@ -369,7 +526,7 @@ need_resched:
22112 jz restore_all
22113 call preempt_schedule_irq
22114 jmp need_resched
22115-END(resume_kernel)
22116+ENDPROC(resume_kernel)
22117 #endif
22118 CFI_ENDPROC
22119 /*
22120@@ -403,30 +560,45 @@ sysenter_past_esp:
22121 /*CFI_REL_OFFSET cs, 0*/
22122 /*
22123 * Push current_thread_info()->sysenter_return to the stack.
22124- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22125- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22126 */
22127- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22128+ pushl_cfi $0
22129 CFI_REL_OFFSET eip, 0
22130
22131 pushl_cfi %eax
22132 SAVE_ALL
22133+ GET_THREAD_INFO(%ebp)
22134+ movl TI_sysenter_return(%ebp),%ebp
22135+ movl %ebp,PT_EIP(%esp)
22136 ENABLE_INTERRUPTS(CLBR_NONE)
22137
22138 /*
22139 * Load the potential sixth argument from user stack.
22140 * Careful about security.
22141 */
22142+ movl PT_OLDESP(%esp),%ebp
22143+
22144+#ifdef CONFIG_PAX_MEMORY_UDEREF
22145+ mov PT_OLDSS(%esp),%ds
22146+1: movl %ds:(%ebp),%ebp
22147+ push %ss
22148+ pop %ds
22149+#else
22150 cmpl $__PAGE_OFFSET-3,%ebp
22151 jae syscall_fault
22152 ASM_STAC
22153 1: movl (%ebp),%ebp
22154 ASM_CLAC
22155+#endif
22156+
22157 movl %ebp,PT_EBP(%esp)
22158 _ASM_EXTABLE(1b,syscall_fault)
22159
22160 GET_THREAD_INFO(%ebp)
22161
22162+#ifdef CONFIG_PAX_RANDKSTACK
22163+ pax_erase_kstack
22164+#endif
22165+
22166 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22167 jnz sysenter_audit
22168 sysenter_do_call:
22169@@ -441,12 +613,24 @@ sysenter_do_call:
22170 testl $_TIF_ALLWORK_MASK, %ecx
22171 jne sysexit_audit
22172 sysenter_exit:
22173+
22174+#ifdef CONFIG_PAX_RANDKSTACK
22175+ pushl_cfi %eax
22176+ movl %esp, %eax
22177+ call pax_randomize_kstack
22178+ popl_cfi %eax
22179+#endif
22180+
22181+ pax_erase_kstack
22182+
22183 /* if something modifies registers it must also disable sysexit */
22184 movl PT_EIP(%esp), %edx
22185 movl PT_OLDESP(%esp), %ecx
22186 xorl %ebp,%ebp
22187 TRACE_IRQS_ON
22188 1: mov PT_FS(%esp), %fs
22189+2: mov PT_DS(%esp), %ds
22190+3: mov PT_ES(%esp), %es
22191 PTGS_TO_GS
22192 ENABLE_INTERRUPTS_SYSEXIT
22193
22194@@ -463,6 +647,9 @@ sysenter_audit:
22195 movl %eax,%edx /* 2nd arg: syscall number */
22196 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22197 call __audit_syscall_entry
22198+
22199+ pax_erase_kstack
22200+
22201 pushl_cfi %ebx
22202 movl PT_EAX(%esp),%eax /* reload syscall number */
22203 jmp sysenter_do_call
22204@@ -488,10 +675,16 @@ sysexit_audit:
22205
22206 CFI_ENDPROC
22207 .pushsection .fixup,"ax"
22208-2: movl $0,PT_FS(%esp)
22209+4: movl $0,PT_FS(%esp)
22210+ jmp 1b
22211+5: movl $0,PT_DS(%esp)
22212+ jmp 1b
22213+6: movl $0,PT_ES(%esp)
22214 jmp 1b
22215 .popsection
22216- _ASM_EXTABLE(1b,2b)
22217+ _ASM_EXTABLE(1b,4b)
22218+ _ASM_EXTABLE(2b,5b)
22219+ _ASM_EXTABLE(3b,6b)
22220 PTGS_TO_GS_EX
22221 ENDPROC(ia32_sysenter_target)
22222
22223@@ -506,6 +699,11 @@ ENTRY(system_call)
22224 pushl_cfi %eax # save orig_eax
22225 SAVE_ALL
22226 GET_THREAD_INFO(%ebp)
22227+
22228+#ifdef CONFIG_PAX_RANDKSTACK
22229+ pax_erase_kstack
22230+#endif
22231+
22232 # system call tracing in operation / emulation
22233 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22234 jnz syscall_trace_entry
22235@@ -524,6 +722,15 @@ syscall_exit:
22236 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22237 jne syscall_exit_work
22238
22239+restore_all_pax:
22240+
22241+#ifdef CONFIG_PAX_RANDKSTACK
22242+ movl %esp, %eax
22243+ call pax_randomize_kstack
22244+#endif
22245+
22246+ pax_erase_kstack
22247+
22248 restore_all:
22249 TRACE_IRQS_IRET
22250 restore_all_notrace:
22251@@ -580,14 +787,34 @@ ldt_ss:
22252 * compensating for the offset by changing to the ESPFIX segment with
22253 * a base address that matches for the difference.
22254 */
22255-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22256+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22257 mov %esp, %edx /* load kernel esp */
22258 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22259 mov %dx, %ax /* eax: new kernel esp */
22260 sub %eax, %edx /* offset (low word is 0) */
22261+#ifdef CONFIG_SMP
22262+ movl PER_CPU_VAR(cpu_number), %ebx
22263+ shll $PAGE_SHIFT_asm, %ebx
22264+ addl $cpu_gdt_table, %ebx
22265+#else
22266+ movl $cpu_gdt_table, %ebx
22267+#endif
22268 shr $16, %edx
22269- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22270- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22271+
22272+#ifdef CONFIG_PAX_KERNEXEC
22273+ mov %cr0, %esi
22274+ btr $16, %esi
22275+ mov %esi, %cr0
22276+#endif
22277+
22278+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22279+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22280+
22281+#ifdef CONFIG_PAX_KERNEXEC
22282+ bts $16, %esi
22283+ mov %esi, %cr0
22284+#endif
22285+
22286 pushl_cfi $__ESPFIX_SS
22287 pushl_cfi %eax /* new kernel esp */
22288 /* Disable interrupts, but do not irqtrace this section: we
22289@@ -616,20 +843,18 @@ work_resched:
22290 movl TI_flags(%ebp), %ecx
22291 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22292 # than syscall tracing?
22293- jz restore_all
22294+ jz restore_all_pax
22295 testb $_TIF_NEED_RESCHED, %cl
22296 jnz work_resched
22297
22298 work_notifysig: # deal with pending signals and
22299 # notify-resume requests
22300+ movl %esp, %eax
22301 #ifdef CONFIG_VM86
22302 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22303- movl %esp, %eax
22304 jne work_notifysig_v86 # returning to kernel-space or
22305 # vm86-space
22306 1:
22307-#else
22308- movl %esp, %eax
22309 #endif
22310 TRACE_IRQS_ON
22311 ENABLE_INTERRUPTS(CLBR_NONE)
22312@@ -650,7 +875,7 @@ work_notifysig_v86:
22313 movl %eax, %esp
22314 jmp 1b
22315 #endif
22316-END(work_pending)
22317+ENDPROC(work_pending)
22318
22319 # perform syscall exit tracing
22320 ALIGN
22321@@ -658,11 +883,14 @@ syscall_trace_entry:
22322 movl $-ENOSYS,PT_EAX(%esp)
22323 movl %esp, %eax
22324 call syscall_trace_enter
22325+
22326+ pax_erase_kstack
22327+
22328 /* What it returned is what we'll actually use. */
22329 cmpl $(NR_syscalls), %eax
22330 jnae syscall_call
22331 jmp syscall_exit
22332-END(syscall_trace_entry)
22333+ENDPROC(syscall_trace_entry)
22334
22335 # perform syscall exit tracing
22336 ALIGN
22337@@ -675,21 +903,25 @@ syscall_exit_work:
22338 movl %esp, %eax
22339 call syscall_trace_leave
22340 jmp resume_userspace
22341-END(syscall_exit_work)
22342+ENDPROC(syscall_exit_work)
22343 CFI_ENDPROC
22344
22345 RING0_INT_FRAME # can't unwind into user space anyway
22346 syscall_fault:
22347+#ifdef CONFIG_PAX_MEMORY_UDEREF
22348+ push %ss
22349+ pop %ds
22350+#endif
22351 ASM_CLAC
22352 GET_THREAD_INFO(%ebp)
22353 movl $-EFAULT,PT_EAX(%esp)
22354 jmp resume_userspace
22355-END(syscall_fault)
22356+ENDPROC(syscall_fault)
22357
22358 syscall_badsys:
22359 movl $-ENOSYS,PT_EAX(%esp)
22360 jmp resume_userspace
22361-END(syscall_badsys)
22362+ENDPROC(syscall_badsys)
22363 CFI_ENDPROC
22364 /*
22365 * End of kprobes section
22366@@ -705,8 +937,15 @@ END(syscall_badsys)
22367 * normal stack and adjusts ESP with the matching offset.
22368 */
22369 /* fixup the stack */
22370- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22371- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22372+#ifdef CONFIG_SMP
22373+ movl PER_CPU_VAR(cpu_number), %ebx
22374+ shll $PAGE_SHIFT_asm, %ebx
22375+ addl $cpu_gdt_table, %ebx
22376+#else
22377+ movl $cpu_gdt_table, %ebx
22378+#endif
22379+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22380+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22381 shl $16, %eax
22382 addl %esp, %eax /* the adjusted stack pointer */
22383 pushl_cfi $__KERNEL_DS
22384@@ -759,7 +998,7 @@ vector=vector+1
22385 .endr
22386 2: jmp common_interrupt
22387 .endr
22388-END(irq_entries_start)
22389+ENDPROC(irq_entries_start)
22390
22391 .previous
22392 END(interrupt)
22393@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22394 pushl_cfi $do_coprocessor_error
22395 jmp error_code
22396 CFI_ENDPROC
22397-END(coprocessor_error)
22398+ENDPROC(coprocessor_error)
22399
22400 ENTRY(simd_coprocessor_error)
22401 RING0_INT_FRAME
22402@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22403 .section .altinstructions,"a"
22404 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22405 .previous
22406-.section .altinstr_replacement,"ax"
22407+.section .altinstr_replacement,"a"
22408 663: pushl $do_simd_coprocessor_error
22409 664:
22410 .previous
22411@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22412 #endif
22413 jmp error_code
22414 CFI_ENDPROC
22415-END(simd_coprocessor_error)
22416+ENDPROC(simd_coprocessor_error)
22417
22418 ENTRY(device_not_available)
22419 RING0_INT_FRAME
22420@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22421 pushl_cfi $do_device_not_available
22422 jmp error_code
22423 CFI_ENDPROC
22424-END(device_not_available)
22425+ENDPROC(device_not_available)
22426
22427 #ifdef CONFIG_PARAVIRT
22428 ENTRY(native_iret)
22429 iret
22430 _ASM_EXTABLE(native_iret, iret_exc)
22431-END(native_iret)
22432+ENDPROC(native_iret)
22433
22434 ENTRY(native_irq_enable_sysexit)
22435 sti
22436 sysexit
22437-END(native_irq_enable_sysexit)
22438+ENDPROC(native_irq_enable_sysexit)
22439 #endif
22440
22441 ENTRY(overflow)
22442@@ -872,7 +1111,7 @@ ENTRY(overflow)
22443 pushl_cfi $do_overflow
22444 jmp error_code
22445 CFI_ENDPROC
22446-END(overflow)
22447+ENDPROC(overflow)
22448
22449 ENTRY(bounds)
22450 RING0_INT_FRAME
22451@@ -881,7 +1120,7 @@ ENTRY(bounds)
22452 pushl_cfi $do_bounds
22453 jmp error_code
22454 CFI_ENDPROC
22455-END(bounds)
22456+ENDPROC(bounds)
22457
22458 ENTRY(invalid_op)
22459 RING0_INT_FRAME
22460@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22461 pushl_cfi $do_invalid_op
22462 jmp error_code
22463 CFI_ENDPROC
22464-END(invalid_op)
22465+ENDPROC(invalid_op)
22466
22467 ENTRY(coprocessor_segment_overrun)
22468 RING0_INT_FRAME
22469@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22470 pushl_cfi $do_coprocessor_segment_overrun
22471 jmp error_code
22472 CFI_ENDPROC
22473-END(coprocessor_segment_overrun)
22474+ENDPROC(coprocessor_segment_overrun)
22475
22476 ENTRY(invalid_TSS)
22477 RING0_EC_FRAME
22478@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22479 pushl_cfi $do_invalid_TSS
22480 jmp error_code
22481 CFI_ENDPROC
22482-END(invalid_TSS)
22483+ENDPROC(invalid_TSS)
22484
22485 ENTRY(segment_not_present)
22486 RING0_EC_FRAME
22487@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22488 pushl_cfi $do_segment_not_present
22489 jmp error_code
22490 CFI_ENDPROC
22491-END(segment_not_present)
22492+ENDPROC(segment_not_present)
22493
22494 ENTRY(stack_segment)
22495 RING0_EC_FRAME
22496@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22497 pushl_cfi $do_stack_segment
22498 jmp error_code
22499 CFI_ENDPROC
22500-END(stack_segment)
22501+ENDPROC(stack_segment)
22502
22503 ENTRY(alignment_check)
22504 RING0_EC_FRAME
22505@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22506 pushl_cfi $do_alignment_check
22507 jmp error_code
22508 CFI_ENDPROC
22509-END(alignment_check)
22510+ENDPROC(alignment_check)
22511
22512 ENTRY(divide_error)
22513 RING0_INT_FRAME
22514@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22515 pushl_cfi $do_divide_error
22516 jmp error_code
22517 CFI_ENDPROC
22518-END(divide_error)
22519+ENDPROC(divide_error)
22520
22521 #ifdef CONFIG_X86_MCE
22522 ENTRY(machine_check)
22523@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22524 pushl_cfi machine_check_vector
22525 jmp error_code
22526 CFI_ENDPROC
22527-END(machine_check)
22528+ENDPROC(machine_check)
22529 #endif
22530
22531 ENTRY(spurious_interrupt_bug)
22532@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22533 pushl_cfi $do_spurious_interrupt_bug
22534 jmp error_code
22535 CFI_ENDPROC
22536-END(spurious_interrupt_bug)
22537+ENDPROC(spurious_interrupt_bug)
22538 /*
22539 * End of kprobes section
22540 */
22541@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22542
22543 ENTRY(mcount)
22544 ret
22545-END(mcount)
22546+ENDPROC(mcount)
22547
22548 ENTRY(ftrace_caller)
22549 cmpl $0, function_trace_stop
22550@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22551 .globl ftrace_stub
22552 ftrace_stub:
22553 ret
22554-END(ftrace_caller)
22555+ENDPROC(ftrace_caller)
22556
22557 ENTRY(ftrace_regs_caller)
22558 pushf /* push flags before compare (in cs location) */
22559@@ -1207,7 +1446,7 @@ trace:
22560 popl %ecx
22561 popl %eax
22562 jmp ftrace_stub
22563-END(mcount)
22564+ENDPROC(mcount)
22565 #endif /* CONFIG_DYNAMIC_FTRACE */
22566 #endif /* CONFIG_FUNCTION_TRACER */
22567
22568@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22569 popl %ecx
22570 popl %eax
22571 ret
22572-END(ftrace_graph_caller)
22573+ENDPROC(ftrace_graph_caller)
22574
22575 .globl return_to_handler
22576 return_to_handler:
22577@@ -1291,15 +1530,18 @@ error_code:
22578 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22579 REG_TO_PTGS %ecx
22580 SET_KERNEL_GS %ecx
22581- movl $(__USER_DS), %ecx
22582+ movl $(__KERNEL_DS), %ecx
22583 movl %ecx, %ds
22584 movl %ecx, %es
22585+
22586+ pax_enter_kernel
22587+
22588 TRACE_IRQS_OFF
22589 movl %esp,%eax # pt_regs pointer
22590 call *%edi
22591 jmp ret_from_exception
22592 CFI_ENDPROC
22593-END(page_fault)
22594+ENDPROC(page_fault)
22595
22596 /*
22597 * Debug traps and NMI can happen at the one SYSENTER instruction
22598@@ -1342,7 +1584,7 @@ debug_stack_correct:
22599 call do_debug
22600 jmp ret_from_exception
22601 CFI_ENDPROC
22602-END(debug)
22603+ENDPROC(debug)
22604
22605 /*
22606 * NMI is doubly nasty. It can happen _while_ we're handling
22607@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22608 xorl %edx,%edx # zero error code
22609 movl %esp,%eax # pt_regs pointer
22610 call do_nmi
22611+
22612+ pax_exit_kernel
22613+
22614 jmp restore_all_notrace
22615 CFI_ENDPROC
22616
22617@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22618 FIXUP_ESPFIX_STACK # %eax == %esp
22619 xorl %edx,%edx # zero error code
22620 call do_nmi
22621+
22622+ pax_exit_kernel
22623+
22624 RESTORE_REGS
22625 lss 12+4(%esp), %esp # back to espfix stack
22626 CFI_ADJUST_CFA_OFFSET -24
22627 jmp irq_return
22628 CFI_ENDPROC
22629-END(nmi)
22630+ENDPROC(nmi)
22631
22632 ENTRY(int3)
22633 RING0_INT_FRAME
22634@@ -1434,14 +1682,14 @@ ENTRY(int3)
22635 call do_int3
22636 jmp ret_from_exception
22637 CFI_ENDPROC
22638-END(int3)
22639+ENDPROC(int3)
22640
22641 ENTRY(general_protection)
22642 RING0_EC_FRAME
22643 pushl_cfi $do_general_protection
22644 jmp error_code
22645 CFI_ENDPROC
22646-END(general_protection)
22647+ENDPROC(general_protection)
22648
22649 #ifdef CONFIG_KVM_GUEST
22650 ENTRY(async_page_fault)
22651@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22652 pushl_cfi $do_async_page_fault
22653 jmp error_code
22654 CFI_ENDPROC
22655-END(async_page_fault)
22656+ENDPROC(async_page_fault)
22657 #endif
22658
22659 /*
22660diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22661index 1e96c36..3ff710a 100644
22662--- a/arch/x86/kernel/entry_64.S
22663+++ b/arch/x86/kernel/entry_64.S
22664@@ -59,6 +59,8 @@
22665 #include <asm/context_tracking.h>
22666 #include <asm/smap.h>
22667 #include <linux/err.h>
22668+#include <asm/pgtable.h>
22669+#include <asm/alternative-asm.h>
22670
22671 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22672 #include <linux/elf-em.h>
22673@@ -80,8 +82,9 @@
22674 #ifdef CONFIG_DYNAMIC_FTRACE
22675
22676 ENTRY(function_hook)
22677+ pax_force_retaddr
22678 retq
22679-END(function_hook)
22680+ENDPROC(function_hook)
22681
22682 /* skip is set if stack has been adjusted */
22683 .macro ftrace_caller_setup skip=0
22684@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22685 #endif
22686
22687 GLOBAL(ftrace_stub)
22688+ pax_force_retaddr
22689 retq
22690-END(ftrace_caller)
22691+ENDPROC(ftrace_caller)
22692
22693 ENTRY(ftrace_regs_caller)
22694 /* Save the current flags before compare (in SS location)*/
22695@@ -191,7 +195,7 @@ ftrace_restore_flags:
22696 popfq
22697 jmp ftrace_stub
22698
22699-END(ftrace_regs_caller)
22700+ENDPROC(ftrace_regs_caller)
22701
22702
22703 #else /* ! CONFIG_DYNAMIC_FTRACE */
22704@@ -212,6 +216,7 @@ ENTRY(function_hook)
22705 #endif
22706
22707 GLOBAL(ftrace_stub)
22708+ pax_force_retaddr
22709 retq
22710
22711 trace:
22712@@ -225,12 +230,13 @@ trace:
22713 #endif
22714 subq $MCOUNT_INSN_SIZE, %rdi
22715
22716+ pax_force_fptr ftrace_trace_function
22717 call *ftrace_trace_function
22718
22719 MCOUNT_RESTORE_FRAME
22720
22721 jmp ftrace_stub
22722-END(function_hook)
22723+ENDPROC(function_hook)
22724 #endif /* CONFIG_DYNAMIC_FTRACE */
22725 #endif /* CONFIG_FUNCTION_TRACER */
22726
22727@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22728
22729 MCOUNT_RESTORE_FRAME
22730
22731+ pax_force_retaddr
22732 retq
22733-END(ftrace_graph_caller)
22734+ENDPROC(ftrace_graph_caller)
22735
22736 GLOBAL(return_to_handler)
22737 subq $24, %rsp
22738@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22739 movq 8(%rsp), %rdx
22740 movq (%rsp), %rax
22741 addq $24, %rsp
22742+ pax_force_fptr %rdi
22743 jmp *%rdi
22744+ENDPROC(return_to_handler)
22745 #endif
22746
22747
22748@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22749 ENDPROC(native_usergs_sysret64)
22750 #endif /* CONFIG_PARAVIRT */
22751
22752+ .macro ljmpq sel, off
22753+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22754+ .byte 0x48; ljmp *1234f(%rip)
22755+ .pushsection .rodata
22756+ .align 16
22757+ 1234: .quad \off; .word \sel
22758+ .popsection
22759+#else
22760+ pushq $\sel
22761+ pushq $\off
22762+ lretq
22763+#endif
22764+ .endm
22765+
22766+ .macro pax_enter_kernel
22767+ pax_set_fptr_mask
22768+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22769+ call pax_enter_kernel
22770+#endif
22771+ .endm
22772+
22773+ .macro pax_exit_kernel
22774+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22775+ call pax_exit_kernel
22776+#endif
22777+
22778+ .endm
22779+
22780+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22781+ENTRY(pax_enter_kernel)
22782+ pushq %rdi
22783+
22784+#ifdef CONFIG_PARAVIRT
22785+ PV_SAVE_REGS(CLBR_RDI)
22786+#endif
22787+
22788+#ifdef CONFIG_PAX_KERNEXEC
22789+ GET_CR0_INTO_RDI
22790+ bts $16,%rdi
22791+ jnc 3f
22792+ mov %cs,%edi
22793+ cmp $__KERNEL_CS,%edi
22794+ jnz 2f
22795+1:
22796+#endif
22797+
22798+#ifdef CONFIG_PAX_MEMORY_UDEREF
22799+ 661: jmp 111f
22800+ .pushsection .altinstr_replacement, "a"
22801+ 662: ASM_NOP2
22802+ .popsection
22803+ .pushsection .altinstructions, "a"
22804+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22805+ .popsection
22806+ GET_CR3_INTO_RDI
22807+ cmp $0,%dil
22808+ jnz 112f
22809+ mov $__KERNEL_DS,%edi
22810+ mov %edi,%ss
22811+ jmp 111f
22812+112: cmp $1,%dil
22813+ jz 113f
22814+ ud2
22815+113: sub $4097,%rdi
22816+ bts $63,%rdi
22817+ SET_RDI_INTO_CR3
22818+ mov $__UDEREF_KERNEL_DS,%edi
22819+ mov %edi,%ss
22820+111:
22821+#endif
22822+
22823+#ifdef CONFIG_PARAVIRT
22824+ PV_RESTORE_REGS(CLBR_RDI)
22825+#endif
22826+
22827+ popq %rdi
22828+ pax_force_retaddr
22829+ retq
22830+
22831+#ifdef CONFIG_PAX_KERNEXEC
22832+2: ljmpq __KERNEL_CS,1b
22833+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22834+4: SET_RDI_INTO_CR0
22835+ jmp 1b
22836+#endif
22837+ENDPROC(pax_enter_kernel)
22838+
22839+ENTRY(pax_exit_kernel)
22840+ pushq %rdi
22841+
22842+#ifdef CONFIG_PARAVIRT
22843+ PV_SAVE_REGS(CLBR_RDI)
22844+#endif
22845+
22846+#ifdef CONFIG_PAX_KERNEXEC
22847+ mov %cs,%rdi
22848+ cmp $__KERNEXEC_KERNEL_CS,%edi
22849+ jz 2f
22850+ GET_CR0_INTO_RDI
22851+ bts $16,%rdi
22852+ jnc 4f
22853+1:
22854+#endif
22855+
22856+#ifdef CONFIG_PAX_MEMORY_UDEREF
22857+ 661: jmp 111f
22858+ .pushsection .altinstr_replacement, "a"
22859+ 662: ASM_NOP2
22860+ .popsection
22861+ .pushsection .altinstructions, "a"
22862+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22863+ .popsection
22864+ mov %ss,%edi
22865+ cmp $__UDEREF_KERNEL_DS,%edi
22866+ jnz 111f
22867+ GET_CR3_INTO_RDI
22868+ cmp $0,%dil
22869+ jz 112f
22870+ ud2
22871+112: add $4097,%rdi
22872+ bts $63,%rdi
22873+ SET_RDI_INTO_CR3
22874+ mov $__KERNEL_DS,%edi
22875+ mov %edi,%ss
22876+111:
22877+#endif
22878+
22879+#ifdef CONFIG_PARAVIRT
22880+ PV_RESTORE_REGS(CLBR_RDI);
22881+#endif
22882+
22883+ popq %rdi
22884+ pax_force_retaddr
22885+ retq
22886+
22887+#ifdef CONFIG_PAX_KERNEXEC
22888+2: GET_CR0_INTO_RDI
22889+ btr $16,%rdi
22890+ jnc 4f
22891+ ljmpq __KERNEL_CS,3f
22892+3: SET_RDI_INTO_CR0
22893+ jmp 1b
22894+4: ud2
22895+ jmp 4b
22896+#endif
22897+ENDPROC(pax_exit_kernel)
22898+#endif
22899+
22900+ .macro pax_enter_kernel_user
22901+ pax_set_fptr_mask
22902+#ifdef CONFIG_PAX_MEMORY_UDEREF
22903+ call pax_enter_kernel_user
22904+#endif
22905+ .endm
22906+
22907+ .macro pax_exit_kernel_user
22908+#ifdef CONFIG_PAX_MEMORY_UDEREF
22909+ call pax_exit_kernel_user
22910+#endif
22911+#ifdef CONFIG_PAX_RANDKSTACK
22912+ pushq %rax
22913+ pushq %r11
22914+ call pax_randomize_kstack
22915+ popq %r11
22916+ popq %rax
22917+#endif
22918+ .endm
22919+
22920+#ifdef CONFIG_PAX_MEMORY_UDEREF
22921+ENTRY(pax_enter_kernel_user)
22922+ pushq %rdi
22923+ pushq %rbx
22924+
22925+#ifdef CONFIG_PARAVIRT
22926+ PV_SAVE_REGS(CLBR_RDI)
22927+#endif
22928+
22929+ 661: jmp 111f
22930+ .pushsection .altinstr_replacement, "a"
22931+ 662: ASM_NOP2
22932+ .popsection
22933+ .pushsection .altinstructions, "a"
22934+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22935+ .popsection
22936+ GET_CR3_INTO_RDI
22937+ cmp $1,%dil
22938+ jnz 4f
22939+ sub $4097,%rdi
22940+ bts $63,%rdi
22941+ SET_RDI_INTO_CR3
22942+ jmp 3f
22943+111:
22944+
22945+ GET_CR3_INTO_RDI
22946+ mov %rdi,%rbx
22947+ add $__START_KERNEL_map,%rbx
22948+ sub phys_base(%rip),%rbx
22949+
22950+#ifdef CONFIG_PARAVIRT
22951+ cmpl $0, pv_info+PARAVIRT_enabled
22952+ jz 1f
22953+ pushq %rdi
22954+ i = 0
22955+ .rept USER_PGD_PTRS
22956+ mov i*8(%rbx),%rsi
22957+ mov $0,%sil
22958+ lea i*8(%rbx),%rdi
22959+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22960+ i = i + 1
22961+ .endr
22962+ popq %rdi
22963+ jmp 2f
22964+1:
22965+#endif
22966+
22967+ i = 0
22968+ .rept USER_PGD_PTRS
22969+ movb $0,i*8(%rbx)
22970+ i = i + 1
22971+ .endr
22972+
22973+2: SET_RDI_INTO_CR3
22974+
22975+#ifdef CONFIG_PAX_KERNEXEC
22976+ GET_CR0_INTO_RDI
22977+ bts $16,%rdi
22978+ SET_RDI_INTO_CR0
22979+#endif
22980+
22981+3:
22982+
22983+#ifdef CONFIG_PARAVIRT
22984+ PV_RESTORE_REGS(CLBR_RDI)
22985+#endif
22986+
22987+ popq %rbx
22988+ popq %rdi
22989+ pax_force_retaddr
22990+ retq
22991+4: ud2
22992+ENDPROC(pax_enter_kernel_user)
22993+
22994+ENTRY(pax_exit_kernel_user)
22995+ pushq %rdi
22996+ pushq %rbx
22997+
22998+#ifdef CONFIG_PARAVIRT
22999+ PV_SAVE_REGS(CLBR_RDI)
23000+#endif
23001+
23002+ GET_CR3_INTO_RDI
23003+ 661: jmp 1f
23004+ .pushsection .altinstr_replacement, "a"
23005+ 662: ASM_NOP2
23006+ .popsection
23007+ .pushsection .altinstructions, "a"
23008+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23009+ .popsection
23010+ cmp $0,%dil
23011+ jnz 3f
23012+ add $4097,%rdi
23013+ bts $63,%rdi
23014+ SET_RDI_INTO_CR3
23015+ jmp 2f
23016+1:
23017+
23018+ mov %rdi,%rbx
23019+
23020+#ifdef CONFIG_PAX_KERNEXEC
23021+ GET_CR0_INTO_RDI
23022+ btr $16,%rdi
23023+ jnc 3f
23024+ SET_RDI_INTO_CR0
23025+#endif
23026+
23027+ add $__START_KERNEL_map,%rbx
23028+ sub phys_base(%rip),%rbx
23029+
23030+#ifdef CONFIG_PARAVIRT
23031+ cmpl $0, pv_info+PARAVIRT_enabled
23032+ jz 1f
23033+ i = 0
23034+ .rept USER_PGD_PTRS
23035+ mov i*8(%rbx),%rsi
23036+ mov $0x67,%sil
23037+ lea i*8(%rbx),%rdi
23038+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23039+ i = i + 1
23040+ .endr
23041+ jmp 2f
23042+1:
23043+#endif
23044+
23045+ i = 0
23046+ .rept USER_PGD_PTRS
23047+ movb $0x67,i*8(%rbx)
23048+ i = i + 1
23049+ .endr
23050+2:
23051+
23052+#ifdef CONFIG_PARAVIRT
23053+ PV_RESTORE_REGS(CLBR_RDI)
23054+#endif
23055+
23056+ popq %rbx
23057+ popq %rdi
23058+ pax_force_retaddr
23059+ retq
23060+3: ud2
23061+ENDPROC(pax_exit_kernel_user)
23062+#endif
23063+
23064+ .macro pax_enter_kernel_nmi
23065+ pax_set_fptr_mask
23066+
23067+#ifdef CONFIG_PAX_KERNEXEC
23068+ GET_CR0_INTO_RDI
23069+ bts $16,%rdi
23070+ jc 110f
23071+ SET_RDI_INTO_CR0
23072+ or $2,%ebx
23073+110:
23074+#endif
23075+
23076+#ifdef CONFIG_PAX_MEMORY_UDEREF
23077+ 661: jmp 111f
23078+ .pushsection .altinstr_replacement, "a"
23079+ 662: ASM_NOP2
23080+ .popsection
23081+ .pushsection .altinstructions, "a"
23082+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23083+ .popsection
23084+ GET_CR3_INTO_RDI
23085+ cmp $0,%dil
23086+ jz 111f
23087+ sub $4097,%rdi
23088+ or $4,%ebx
23089+ bts $63,%rdi
23090+ SET_RDI_INTO_CR3
23091+ mov $__UDEREF_KERNEL_DS,%edi
23092+ mov %edi,%ss
23093+111:
23094+#endif
23095+ .endm
23096+
23097+ .macro pax_exit_kernel_nmi
23098+#ifdef CONFIG_PAX_KERNEXEC
23099+ btr $1,%ebx
23100+ jnc 110f
23101+ GET_CR0_INTO_RDI
23102+ btr $16,%rdi
23103+ SET_RDI_INTO_CR0
23104+110:
23105+#endif
23106+
23107+#ifdef CONFIG_PAX_MEMORY_UDEREF
23108+ btr $2,%ebx
23109+ jnc 111f
23110+ GET_CR3_INTO_RDI
23111+ add $4097,%rdi
23112+ bts $63,%rdi
23113+ SET_RDI_INTO_CR3
23114+ mov $__KERNEL_DS,%edi
23115+ mov %edi,%ss
23116+111:
23117+#endif
23118+ .endm
23119+
23120+ .macro pax_erase_kstack
23121+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23122+ call pax_erase_kstack
23123+#endif
23124+ .endm
23125+
23126+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23127+ENTRY(pax_erase_kstack)
23128+ pushq %rdi
23129+ pushq %rcx
23130+ pushq %rax
23131+ pushq %r11
23132+
23133+ GET_THREAD_INFO(%r11)
23134+ mov TI_lowest_stack(%r11), %rdi
23135+ mov $-0xBEEF, %rax
23136+ std
23137+
23138+1: mov %edi, %ecx
23139+ and $THREAD_SIZE_asm - 1, %ecx
23140+ shr $3, %ecx
23141+ repne scasq
23142+ jecxz 2f
23143+
23144+ cmp $2*8, %ecx
23145+ jc 2f
23146+
23147+ mov $2*8, %ecx
23148+ repe scasq
23149+ jecxz 2f
23150+ jne 1b
23151+
23152+2: cld
23153+ mov %esp, %ecx
23154+ sub %edi, %ecx
23155+
23156+ cmp $THREAD_SIZE_asm, %rcx
23157+ jb 3f
23158+ ud2
23159+3:
23160+
23161+ shr $3, %ecx
23162+ rep stosq
23163+
23164+ mov TI_task_thread_sp0(%r11), %rdi
23165+ sub $256, %rdi
23166+ mov %rdi, TI_lowest_stack(%r11)
23167+
23168+ popq %r11
23169+ popq %rax
23170+ popq %rcx
23171+ popq %rdi
23172+ pax_force_retaddr
23173+ ret
23174+ENDPROC(pax_erase_kstack)
23175+#endif
23176
23177 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23178 #ifdef CONFIG_TRACE_IRQFLAGS
23179@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23180 .endm
23181
23182 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23183- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23184+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23185 jnc 1f
23186 TRACE_IRQS_ON_DEBUG
23187 1:
23188@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23189 movq \tmp,R11+\offset(%rsp)
23190 .endm
23191
23192- .macro FAKE_STACK_FRAME child_rip
23193- /* push in order ss, rsp, eflags, cs, rip */
23194- xorl %eax, %eax
23195- pushq_cfi $__KERNEL_DS /* ss */
23196- /*CFI_REL_OFFSET ss,0*/
23197- pushq_cfi %rax /* rsp */
23198- CFI_REL_OFFSET rsp,0
23199- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23200- /*CFI_REL_OFFSET rflags,0*/
23201- pushq_cfi $__KERNEL_CS /* cs */
23202- /*CFI_REL_OFFSET cs,0*/
23203- pushq_cfi \child_rip /* rip */
23204- CFI_REL_OFFSET rip,0
23205- pushq_cfi %rax /* orig rax */
23206- .endm
23207-
23208- .macro UNFAKE_STACK_FRAME
23209- addq $8*6, %rsp
23210- CFI_ADJUST_CFA_OFFSET -(6*8)
23211- .endm
23212-
23213 /*
23214 * initial frame state for interrupts (and exceptions without error code)
23215 */
23216@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23217 /* save partial stack frame */
23218 .macro SAVE_ARGS_IRQ
23219 cld
23220- /* start from rbp in pt_regs and jump over */
23221- movq_cfi rdi, (RDI-RBP)
23222- movq_cfi rsi, (RSI-RBP)
23223- movq_cfi rdx, (RDX-RBP)
23224- movq_cfi rcx, (RCX-RBP)
23225- movq_cfi rax, (RAX-RBP)
23226- movq_cfi r8, (R8-RBP)
23227- movq_cfi r9, (R9-RBP)
23228- movq_cfi r10, (R10-RBP)
23229- movq_cfi r11, (R11-RBP)
23230+ /* start from r15 in pt_regs and jump over */
23231+ movq_cfi rdi, RDI
23232+ movq_cfi rsi, RSI
23233+ movq_cfi rdx, RDX
23234+ movq_cfi rcx, RCX
23235+ movq_cfi rax, RAX
23236+ movq_cfi r8, R8
23237+ movq_cfi r9, R9
23238+ movq_cfi r10, R10
23239+ movq_cfi r11, R11
23240+ movq_cfi r12, R12
23241
23242 /* Save rbp so that we can unwind from get_irq_regs() */
23243- movq_cfi rbp, 0
23244+ movq_cfi rbp, RBP
23245
23246 /* Save previous stack value */
23247 movq %rsp, %rsi
23248
23249- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23250- testl $3, CS-RBP(%rsi)
23251+ movq %rsp,%rdi /* arg1 for handler */
23252+ testb $3, CS(%rsi)
23253 je 1f
23254 SWAPGS
23255 /*
23256@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23257 0x06 /* DW_OP_deref */, \
23258 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23259 0x22 /* DW_OP_plus */
23260+
23261+#ifdef CONFIG_PAX_MEMORY_UDEREF
23262+ testb $3, CS(%rdi)
23263+ jnz 1f
23264+ pax_enter_kernel
23265+ jmp 2f
23266+1: pax_enter_kernel_user
23267+2:
23268+#else
23269+ pax_enter_kernel
23270+#endif
23271+
23272 /* We entered an interrupt context - irqs are off: */
23273 TRACE_IRQS_OFF
23274 .endm
23275@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23276 js 1f /* negative -> in kernel */
23277 SWAPGS
23278 xorl %ebx,%ebx
23279-1: ret
23280+1:
23281+#ifdef CONFIG_PAX_MEMORY_UDEREF
23282+ testb $3, CS+8(%rsp)
23283+ jnz 1f
23284+ pax_enter_kernel
23285+ jmp 2f
23286+1: pax_enter_kernel_user
23287+2:
23288+#else
23289+ pax_enter_kernel
23290+#endif
23291+ pax_force_retaddr
23292+ ret
23293 CFI_ENDPROC
23294-END(save_paranoid)
23295+ENDPROC(save_paranoid)
23296+
23297+ENTRY(save_paranoid_nmi)
23298+ XCPT_FRAME 1 RDI+8
23299+ cld
23300+ movq_cfi rdi, RDI+8
23301+ movq_cfi rsi, RSI+8
23302+ movq_cfi rdx, RDX+8
23303+ movq_cfi rcx, RCX+8
23304+ movq_cfi rax, RAX+8
23305+ movq_cfi r8, R8+8
23306+ movq_cfi r9, R9+8
23307+ movq_cfi r10, R10+8
23308+ movq_cfi r11, R11+8
23309+ movq_cfi rbx, RBX+8
23310+ movq_cfi rbp, RBP+8
23311+ movq_cfi r12, R12+8
23312+ movq_cfi r13, R13+8
23313+ movq_cfi r14, R14+8
23314+ movq_cfi r15, R15+8
23315+ movl $1,%ebx
23316+ movl $MSR_GS_BASE,%ecx
23317+ rdmsr
23318+ testl %edx,%edx
23319+ js 1f /* negative -> in kernel */
23320+ SWAPGS
23321+ xorl %ebx,%ebx
23322+1: pax_enter_kernel_nmi
23323+ pax_force_retaddr
23324+ ret
23325+ CFI_ENDPROC
23326+ENDPROC(save_paranoid_nmi)
23327 .popsection
23328
23329 /*
23330@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23331
23332 RESTORE_REST
23333
23334- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23335+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23336 jz 1f
23337
23338 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23339@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23340 jmp ret_from_sys_call # go to the SYSRET fastpath
23341
23342 1:
23343- subq $REST_SKIP, %rsp # leave space for volatiles
23344- CFI_ADJUST_CFA_OFFSET REST_SKIP
23345 movq %rbp, %rdi
23346 call *%rbx
23347 movl $0, RAX(%rsp)
23348 RESTORE_REST
23349 jmp int_ret_from_sys_call
23350 CFI_ENDPROC
23351-END(ret_from_fork)
23352+ENDPROC(ret_from_fork)
23353
23354 /*
23355 * System call entry. Up to 6 arguments in registers are supported.
23356@@ -593,7 +1059,7 @@ END(ret_from_fork)
23357 ENTRY(system_call)
23358 CFI_STARTPROC simple
23359 CFI_SIGNAL_FRAME
23360- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23361+ CFI_DEF_CFA rsp,0
23362 CFI_REGISTER rip,rcx
23363 /*CFI_REGISTER rflags,r11*/
23364 SWAPGS_UNSAFE_STACK
23365@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23366
23367 movq %rsp,PER_CPU_VAR(old_rsp)
23368 movq PER_CPU_VAR(kernel_stack),%rsp
23369+ SAVE_ARGS 8*6,0
23370+ pax_enter_kernel_user
23371+
23372+#ifdef CONFIG_PAX_RANDKSTACK
23373+ pax_erase_kstack
23374+#endif
23375+
23376 /*
23377 * No need to follow this irqs off/on section - it's straight
23378 * and short:
23379 */
23380 ENABLE_INTERRUPTS(CLBR_NONE)
23381- SAVE_ARGS 8,0
23382 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23383 movq %rcx,RIP-ARGOFFSET(%rsp)
23384 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23385- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23386+ GET_THREAD_INFO(%rcx)
23387+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23388 jnz tracesys
23389 system_call_fastpath:
23390 #if __SYSCALL_MASK == ~0
23391@@ -639,10 +1112,13 @@ sysret_check:
23392 LOCKDEP_SYS_EXIT
23393 DISABLE_INTERRUPTS(CLBR_NONE)
23394 TRACE_IRQS_OFF
23395- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23396+ GET_THREAD_INFO(%rcx)
23397+ movl TI_flags(%rcx),%edx
23398 andl %edi,%edx
23399 jnz sysret_careful
23400 CFI_REMEMBER_STATE
23401+ pax_exit_kernel_user
23402+ pax_erase_kstack
23403 /*
23404 * sysretq will re-enable interrupts:
23405 */
23406@@ -701,6 +1177,9 @@ auditsys:
23407 movq %rax,%rsi /* 2nd arg: syscall number */
23408 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23409 call __audit_syscall_entry
23410+
23411+ pax_erase_kstack
23412+
23413 LOAD_ARGS 0 /* reload call-clobbered registers */
23414 jmp system_call_fastpath
23415
23416@@ -722,7 +1201,7 @@ sysret_audit:
23417 /* Do syscall tracing */
23418 tracesys:
23419 #ifdef CONFIG_AUDITSYSCALL
23420- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23421+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23422 jz auditsys
23423 #endif
23424 SAVE_REST
23425@@ -730,12 +1209,15 @@ tracesys:
23426 FIXUP_TOP_OF_STACK %rdi
23427 movq %rsp,%rdi
23428 call syscall_trace_enter
23429+
23430+ pax_erase_kstack
23431+
23432 /*
23433 * Reload arg registers from stack in case ptrace changed them.
23434 * We don't reload %rax because syscall_trace_enter() returned
23435 * the value it wants us to use in the table lookup.
23436 */
23437- LOAD_ARGS ARGOFFSET, 1
23438+ LOAD_ARGS 1
23439 RESTORE_REST
23440 #if __SYSCALL_MASK == ~0
23441 cmpq $__NR_syscall_max,%rax
23442@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23443 andl %edi,%edx
23444 jnz int_careful
23445 andl $~TS_COMPAT,TI_status(%rcx)
23446- jmp retint_swapgs
23447+ pax_exit_kernel_user
23448+ pax_erase_kstack
23449+ jmp retint_swapgs_pax
23450
23451 /* Either reschedule or signal or syscall exit tracking needed. */
23452 /* First do a reschedule test. */
23453@@ -811,7 +1295,7 @@ int_restore_rest:
23454 TRACE_IRQS_OFF
23455 jmp int_with_check
23456 CFI_ENDPROC
23457-END(system_call)
23458+ENDPROC(system_call)
23459
23460 .macro FORK_LIKE func
23461 ENTRY(stub_\func)
23462@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23463 DEFAULT_FRAME 0 8 /* offset 8: return address */
23464 call sys_\func
23465 RESTORE_TOP_OF_STACK %r11, 8
23466- ret $REST_SKIP /* pop extended registers */
23467+ pax_force_retaddr
23468+ ret
23469 CFI_ENDPROC
23470-END(stub_\func)
23471+ENDPROC(stub_\func)
23472 .endm
23473
23474 .macro FIXED_FRAME label,func
23475@@ -836,9 +1321,10 @@ ENTRY(\label)
23476 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23477 call \func
23478 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23479+ pax_force_retaddr
23480 ret
23481 CFI_ENDPROC
23482-END(\label)
23483+ENDPROC(\label)
23484 .endm
23485
23486 FORK_LIKE clone
23487@@ -846,19 +1332,6 @@ END(\label)
23488 FORK_LIKE vfork
23489 FIXED_FRAME stub_iopl, sys_iopl
23490
23491-ENTRY(ptregscall_common)
23492- DEFAULT_FRAME 1 8 /* offset 8: return address */
23493- RESTORE_TOP_OF_STACK %r11, 8
23494- movq_cfi_restore R15+8, r15
23495- movq_cfi_restore R14+8, r14
23496- movq_cfi_restore R13+8, r13
23497- movq_cfi_restore R12+8, r12
23498- movq_cfi_restore RBP+8, rbp
23499- movq_cfi_restore RBX+8, rbx
23500- ret $REST_SKIP /* pop extended registers */
23501- CFI_ENDPROC
23502-END(ptregscall_common)
23503-
23504 ENTRY(stub_execve)
23505 CFI_STARTPROC
23506 addq $8, %rsp
23507@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23508 RESTORE_REST
23509 jmp int_ret_from_sys_call
23510 CFI_ENDPROC
23511-END(stub_execve)
23512+ENDPROC(stub_execve)
23513
23514 /*
23515 * sigreturn is special because it needs to restore all registers on return.
23516@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23517 RESTORE_REST
23518 jmp int_ret_from_sys_call
23519 CFI_ENDPROC
23520-END(stub_rt_sigreturn)
23521+ENDPROC(stub_rt_sigreturn)
23522
23523 #ifdef CONFIG_X86_X32_ABI
23524 ENTRY(stub_x32_rt_sigreturn)
23525@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23526 RESTORE_REST
23527 jmp int_ret_from_sys_call
23528 CFI_ENDPROC
23529-END(stub_x32_rt_sigreturn)
23530+ENDPROC(stub_x32_rt_sigreturn)
23531
23532 ENTRY(stub_x32_execve)
23533 CFI_STARTPROC
23534@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23535 RESTORE_REST
23536 jmp int_ret_from_sys_call
23537 CFI_ENDPROC
23538-END(stub_x32_execve)
23539+ENDPROC(stub_x32_execve)
23540
23541 #endif
23542
23543@@ -952,7 +1425,7 @@ vector=vector+1
23544 2: jmp common_interrupt
23545 .endr
23546 CFI_ENDPROC
23547-END(irq_entries_start)
23548+ENDPROC(irq_entries_start)
23549
23550 .previous
23551 END(interrupt)
23552@@ -969,8 +1442,8 @@ END(interrupt)
23553 /* 0(%rsp): ~(interrupt number) */
23554 .macro interrupt func
23555 /* reserve pt_regs for scratch regs and rbp */
23556- subq $ORIG_RAX-RBP, %rsp
23557- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23558+ subq $ORIG_RAX, %rsp
23559+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23560 SAVE_ARGS_IRQ
23561 call \func
23562 .endm
23563@@ -997,14 +1470,14 @@ ret_from_intr:
23564
23565 /* Restore saved previous stack */
23566 popq %rsi
23567- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23568- leaq ARGOFFSET-RBP(%rsi), %rsp
23569+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23570+ movq %rsi, %rsp
23571 CFI_DEF_CFA_REGISTER rsp
23572- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23573+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23574
23575 exit_intr:
23576 GET_THREAD_INFO(%rcx)
23577- testl $3,CS-ARGOFFSET(%rsp)
23578+ testb $3,CS-ARGOFFSET(%rsp)
23579 je retint_kernel
23580
23581 /* Interrupt came from user space */
23582@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23583 * The iretq could re-enable interrupts:
23584 */
23585 DISABLE_INTERRUPTS(CLBR_ANY)
23586+ pax_exit_kernel_user
23587+retint_swapgs_pax:
23588 TRACE_IRQS_IRETQ
23589 SWAPGS
23590 jmp restore_args
23591
23592 retint_restore_args: /* return to kernel space */
23593 DISABLE_INTERRUPTS(CLBR_ANY)
23594+ pax_exit_kernel
23595+ pax_force_retaddr (RIP-ARGOFFSET)
23596 /*
23597 * The iretq could re-enable interrupts:
23598 */
23599@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23600 #endif
23601
23602 CFI_ENDPROC
23603-END(common_interrupt)
23604+ENDPROC(common_interrupt)
23605 /*
23606 * End of kprobes section
23607 */
23608@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23609 interrupt \do_sym
23610 jmp ret_from_intr
23611 CFI_ENDPROC
23612-END(\sym)
23613+ENDPROC(\sym)
23614 .endm
23615
23616 #ifdef CONFIG_TRACING
23617@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23618 call \do_sym
23619 jmp error_exit /* %ebx: no swapgs flag */
23620 CFI_ENDPROC
23621-END(\sym)
23622+ENDPROC(\sym)
23623 .endm
23624
23625 .macro paranoidzeroentry sym do_sym
23626@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23627 call \do_sym
23628 jmp paranoid_exit /* %ebx: no swapgs flag */
23629 CFI_ENDPROC
23630-END(\sym)
23631+ENDPROC(\sym)
23632 .endm
23633
23634-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23635+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23636 .macro paranoidzeroentry_ist sym do_sym ist
23637 ENTRY(\sym)
23638 INTR_FRAME
23639@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23640 TRACE_IRQS_OFF_DEBUG
23641 movq %rsp,%rdi /* pt_regs pointer */
23642 xorl %esi,%esi /* no error code */
23643+#ifdef CONFIG_SMP
23644+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23645+ lea init_tss(%r13), %r13
23646+#else
23647+ lea init_tss(%rip), %r13
23648+#endif
23649 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23650 call \do_sym
23651 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23652 jmp paranoid_exit /* %ebx: no swapgs flag */
23653 CFI_ENDPROC
23654-END(\sym)
23655+ENDPROC(\sym)
23656 .endm
23657
23658 .macro errorentry sym do_sym
23659@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23660 call \do_sym
23661 jmp error_exit /* %ebx: no swapgs flag */
23662 CFI_ENDPROC
23663-END(\sym)
23664+ENDPROC(\sym)
23665 .endm
23666
23667 #ifdef CONFIG_TRACING
23668@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23669 call \do_sym
23670 jmp paranoid_exit /* %ebx: no swapgs flag */
23671 CFI_ENDPROC
23672-END(\sym)
23673+ENDPROC(\sym)
23674 .endm
23675
23676 zeroentry divide_error do_divide_error
23677@@ -1336,9 +1819,10 @@ gs_change:
23678 2: mfence /* workaround */
23679 SWAPGS
23680 popfq_cfi
23681+ pax_force_retaddr
23682 ret
23683 CFI_ENDPROC
23684-END(native_load_gs_index)
23685+ENDPROC(native_load_gs_index)
23686
23687 _ASM_EXTABLE(gs_change,bad_gs)
23688 .section .fixup,"ax"
23689@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23690 CFI_DEF_CFA_REGISTER rsp
23691 CFI_ADJUST_CFA_OFFSET -8
23692 decl PER_CPU_VAR(irq_count)
23693+ pax_force_retaddr
23694 ret
23695 CFI_ENDPROC
23696-END(do_softirq_own_stack)
23697+ENDPROC(do_softirq_own_stack)
23698
23699 #ifdef CONFIG_XEN
23700 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23701@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23702 decl PER_CPU_VAR(irq_count)
23703 jmp error_exit
23704 CFI_ENDPROC
23705-END(xen_do_hypervisor_callback)
23706+ENDPROC(xen_do_hypervisor_callback)
23707
23708 /*
23709 * Hypervisor uses this for application faults while it executes.
23710@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23711 SAVE_ALL
23712 jmp error_exit
23713 CFI_ENDPROC
23714-END(xen_failsafe_callback)
23715+ENDPROC(xen_failsafe_callback)
23716
23717 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23718 xen_hvm_callback_vector xen_evtchn_do_upcall
23719@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23720 DEFAULT_FRAME
23721 DISABLE_INTERRUPTS(CLBR_NONE)
23722 TRACE_IRQS_OFF_DEBUG
23723- testl %ebx,%ebx /* swapgs needed? */
23724+ testl $1,%ebx /* swapgs needed? */
23725 jnz paranoid_restore
23726- testl $3,CS(%rsp)
23727+ testb $3,CS(%rsp)
23728 jnz paranoid_userspace
23729+#ifdef CONFIG_PAX_MEMORY_UDEREF
23730+ pax_exit_kernel
23731+ TRACE_IRQS_IRETQ 0
23732+ SWAPGS_UNSAFE_STACK
23733+ RESTORE_ALL 8
23734+ pax_force_retaddr_bts
23735+ jmp irq_return
23736+#endif
23737 paranoid_swapgs:
23738+#ifdef CONFIG_PAX_MEMORY_UDEREF
23739+ pax_exit_kernel_user
23740+#else
23741+ pax_exit_kernel
23742+#endif
23743 TRACE_IRQS_IRETQ 0
23744 SWAPGS_UNSAFE_STACK
23745 RESTORE_ALL 8
23746 jmp irq_return
23747 paranoid_restore:
23748+ pax_exit_kernel
23749 TRACE_IRQS_IRETQ_DEBUG 0
23750 RESTORE_ALL 8
23751+ pax_force_retaddr_bts
23752 jmp irq_return
23753 paranoid_userspace:
23754 GET_THREAD_INFO(%rcx)
23755@@ -1557,7 +2057,7 @@ paranoid_schedule:
23756 TRACE_IRQS_OFF
23757 jmp paranoid_userspace
23758 CFI_ENDPROC
23759-END(paranoid_exit)
23760+ENDPROC(paranoid_exit)
23761
23762 /*
23763 * Exception entry point. This expects an error code/orig_rax on the stack.
23764@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23765 movq_cfi r14, R14+8
23766 movq_cfi r15, R15+8
23767 xorl %ebx,%ebx
23768- testl $3,CS+8(%rsp)
23769+ testb $3,CS+8(%rsp)
23770 je error_kernelspace
23771 error_swapgs:
23772 SWAPGS
23773 error_sti:
23774+#ifdef CONFIG_PAX_MEMORY_UDEREF
23775+ testb $3, CS+8(%rsp)
23776+ jnz 1f
23777+ pax_enter_kernel
23778+ jmp 2f
23779+1: pax_enter_kernel_user
23780+2:
23781+#else
23782+ pax_enter_kernel
23783+#endif
23784 TRACE_IRQS_OFF
23785+ pax_force_retaddr
23786 ret
23787
23788 /*
23789@@ -1616,7 +2127,7 @@ bstep_iret:
23790 movq %rcx,RIP+8(%rsp)
23791 jmp error_swapgs
23792 CFI_ENDPROC
23793-END(error_entry)
23794+ENDPROC(error_entry)
23795
23796
23797 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23798@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23799 DISABLE_INTERRUPTS(CLBR_NONE)
23800 TRACE_IRQS_OFF
23801 GET_THREAD_INFO(%rcx)
23802- testl %eax,%eax
23803+ testl $1,%eax
23804 jne retint_kernel
23805 LOCKDEP_SYS_EXIT_IRQ
23806 movl TI_flags(%rcx),%edx
23807@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23808 jnz retint_careful
23809 jmp retint_swapgs
23810 CFI_ENDPROC
23811-END(error_exit)
23812+ENDPROC(error_exit)
23813
23814 /*
23815 * Test if a given stack is an NMI stack or not.
23816@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23817 * If %cs was not the kernel segment, then the NMI triggered in user
23818 * space, which means it is definitely not nested.
23819 */
23820+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23821+ je 1f
23822 cmpl $__KERNEL_CS, 16(%rsp)
23823 jne first_nmi
23824-
23825+1:
23826 /*
23827 * Check the special variable on the stack to see if NMIs are
23828 * executing.
23829@@ -1730,8 +2243,7 @@ nested_nmi:
23830
23831 1:
23832 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23833- leaq -1*8(%rsp), %rdx
23834- movq %rdx, %rsp
23835+ subq $8, %rsp
23836 CFI_ADJUST_CFA_OFFSET 1*8
23837 leaq -10*8(%rsp), %rdx
23838 pushq_cfi $__KERNEL_DS
23839@@ -1749,6 +2261,7 @@ nested_nmi_out:
23840 CFI_RESTORE rdx
23841
23842 /* No need to check faults here */
23843+# pax_force_retaddr_bts
23844 INTERRUPT_RETURN
23845
23846 CFI_RESTORE_STATE
23847@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23848 subq $ORIG_RAX-R15, %rsp
23849 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23850 /*
23851- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23852+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23853 * as we should not be calling schedule in NMI context.
23854 * Even with normal interrupts enabled. An NMI should not be
23855 * setting NEED_RESCHED or anything that normal interrupts and
23856 * exceptions might do.
23857 */
23858- call save_paranoid
23859+ call save_paranoid_nmi
23860 DEFAULT_FRAME 0
23861
23862 /*
23863@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23864 * NMI itself takes a page fault, the page fault that was preempted
23865 * will read the information from the NMI page fault and not the
23866 * origin fault. Save it off and restore it if it changes.
23867- * Use the r12 callee-saved register.
23868+ * Use the r13 callee-saved register.
23869 */
23870- movq %cr2, %r12
23871+ movq %cr2, %r13
23872
23873 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23874 movq %rsp,%rdi
23875@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23876
23877 /* Did the NMI take a page fault? Restore cr2 if it did */
23878 movq %cr2, %rcx
23879- cmpq %rcx, %r12
23880+ cmpq %rcx, %r13
23881 je 1f
23882- movq %r12, %cr2
23883+ movq %r13, %cr2
23884 1:
23885
23886- testl %ebx,%ebx /* swapgs needed? */
23887+ testl $1,%ebx /* swapgs needed? */
23888 jnz nmi_restore
23889 nmi_swapgs:
23890 SWAPGS_UNSAFE_STACK
23891 nmi_restore:
23892+ pax_exit_kernel_nmi
23893 /* Pop the extra iret frame at once */
23894 RESTORE_ALL 6*8
23895+ testb $3, 8(%rsp)
23896+ jnz 1f
23897+ pax_force_retaddr_bts
23898+1:
23899
23900 /* Clear the NMI executing stack variable */
23901 movq $0, 5*8(%rsp)
23902 jmp irq_return
23903 CFI_ENDPROC
23904-END(nmi)
23905+ENDPROC(nmi)
23906
23907 ENTRY(ignore_sysret)
23908 CFI_STARTPROC
23909 mov $-ENOSYS,%eax
23910 sysret
23911 CFI_ENDPROC
23912-END(ignore_sysret)
23913+ENDPROC(ignore_sysret)
23914
23915 /*
23916 * End of kprobes section
23917diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23918index 1ffc32d..e52c745 100644
23919--- a/arch/x86/kernel/ftrace.c
23920+++ b/arch/x86/kernel/ftrace.c
23921@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23922 {
23923 unsigned char replaced[MCOUNT_INSN_SIZE];
23924
23925+ ip = ktla_ktva(ip);
23926+
23927 /*
23928 * Note: Due to modules and __init, code can
23929 * disappear and change, we need to protect against faulting
23930@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23931 unsigned char old[MCOUNT_INSN_SIZE];
23932 int ret;
23933
23934- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23935+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23936
23937 ftrace_update_func = ip;
23938 /* Make sure the breakpoints see the ftrace_update_func update */
23939@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23940 * kernel identity mapping to modify code.
23941 */
23942 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23943- ip = (unsigned long)__va(__pa_symbol(ip));
23944+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23945
23946 return probe_kernel_write((void *)ip, val, size);
23947 }
23948@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23949 unsigned char replaced[MCOUNT_INSN_SIZE];
23950 unsigned char brk = BREAKPOINT_INSTRUCTION;
23951
23952- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23953+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23954 return -EFAULT;
23955
23956 /* Make sure it is what we expect it to be */
23957@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23958 return ret;
23959
23960 fail_update:
23961- probe_kernel_write((void *)ip, &old_code[0], 1);
23962+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23963 goto out;
23964 }
23965
23966diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23967index 85126cc..1bbce17 100644
23968--- a/arch/x86/kernel/head64.c
23969+++ b/arch/x86/kernel/head64.c
23970@@ -67,12 +67,12 @@ again:
23971 pgd = *pgd_p;
23972
23973 /*
23974- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23975- * critical -- __PAGE_OFFSET would point us back into the dynamic
23976+ * The use of __early_va rather than __va here is critical:
23977+ * __va would point us back into the dynamic
23978 * range and we might end up looping forever...
23979 */
23980 if (pgd)
23981- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23982+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23983 else {
23984 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23985 reset_early_page_tables();
23986@@ -82,13 +82,13 @@ again:
23987 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23988 for (i = 0; i < PTRS_PER_PUD; i++)
23989 pud_p[i] = 0;
23990- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23991+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23992 }
23993 pud_p += pud_index(address);
23994 pud = *pud_p;
23995
23996 if (pud)
23997- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23998+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23999 else {
24000 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24001 reset_early_page_tables();
24002@@ -98,7 +98,7 @@ again:
24003 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24004 for (i = 0; i < PTRS_PER_PMD; i++)
24005 pmd_p[i] = 0;
24006- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24007+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24008 }
24009 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24010 pmd_p[pmd_index(address)] = pmd;
24011@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24012 if (console_loglevel == 10)
24013 early_printk("Kernel alive\n");
24014
24015- clear_page(init_level4_pgt);
24016 /* set init_level4_pgt kernel high mapping*/
24017 init_level4_pgt[511] = early_level4_pgt[511];
24018
24019diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24020index f36bd42..56ee1534 100644
24021--- a/arch/x86/kernel/head_32.S
24022+++ b/arch/x86/kernel/head_32.S
24023@@ -26,6 +26,12 @@
24024 /* Physical address */
24025 #define pa(X) ((X) - __PAGE_OFFSET)
24026
24027+#ifdef CONFIG_PAX_KERNEXEC
24028+#define ta(X) (X)
24029+#else
24030+#define ta(X) ((X) - __PAGE_OFFSET)
24031+#endif
24032+
24033 /*
24034 * References to members of the new_cpu_data structure.
24035 */
24036@@ -55,11 +61,7 @@
24037 * and small than max_low_pfn, otherwise will waste some page table entries
24038 */
24039
24040-#if PTRS_PER_PMD > 1
24041-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24042-#else
24043-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24044-#endif
24045+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24046
24047 /* Number of possible pages in the lowmem region */
24048 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24049@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24050 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24051
24052 /*
24053+ * Real beginning of normal "text" segment
24054+ */
24055+ENTRY(stext)
24056+ENTRY(_stext)
24057+
24058+/*
24059 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24060 * %esi points to the real-mode code as a 32-bit pointer.
24061 * CS and DS must be 4 GB flat segments, but we don't depend on
24062@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24063 * can.
24064 */
24065 __HEAD
24066+
24067+#ifdef CONFIG_PAX_KERNEXEC
24068+ jmp startup_32
24069+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24070+.fill PAGE_SIZE-5,1,0xcc
24071+#endif
24072+
24073 ENTRY(startup_32)
24074 movl pa(stack_start),%ecx
24075
24076@@ -106,6 +121,59 @@ ENTRY(startup_32)
24077 2:
24078 leal -__PAGE_OFFSET(%ecx),%esp
24079
24080+#ifdef CONFIG_SMP
24081+ movl $pa(cpu_gdt_table),%edi
24082+ movl $__per_cpu_load,%eax
24083+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24084+ rorl $16,%eax
24085+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24086+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24087+ movl $__per_cpu_end - 1,%eax
24088+ subl $__per_cpu_start,%eax
24089+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24090+#endif
24091+
24092+#ifdef CONFIG_PAX_MEMORY_UDEREF
24093+ movl $NR_CPUS,%ecx
24094+ movl $pa(cpu_gdt_table),%edi
24095+1:
24096+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24097+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24098+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24099+ addl $PAGE_SIZE_asm,%edi
24100+ loop 1b
24101+#endif
24102+
24103+#ifdef CONFIG_PAX_KERNEXEC
24104+ movl $pa(boot_gdt),%edi
24105+ movl $__LOAD_PHYSICAL_ADDR,%eax
24106+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24107+ rorl $16,%eax
24108+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24109+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24110+ rorl $16,%eax
24111+
24112+ ljmp $(__BOOT_CS),$1f
24113+1:
24114+
24115+ movl $NR_CPUS,%ecx
24116+ movl $pa(cpu_gdt_table),%edi
24117+ addl $__PAGE_OFFSET,%eax
24118+1:
24119+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24120+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24121+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24122+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24123+ rorl $16,%eax
24124+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24125+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24126+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24127+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24128+ rorl $16,%eax
24129+ addl $PAGE_SIZE_asm,%edi
24130+ loop 1b
24131+#endif
24132+
24133 /*
24134 * Clear BSS first so that there are no surprises...
24135 */
24136@@ -201,8 +269,11 @@ ENTRY(startup_32)
24137 movl %eax, pa(max_pfn_mapped)
24138
24139 /* Do early initialization of the fixmap area */
24140- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24141- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24142+#ifdef CONFIG_COMPAT_VDSO
24143+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24144+#else
24145+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24146+#endif
24147 #else /* Not PAE */
24148
24149 page_pde_offset = (__PAGE_OFFSET >> 20);
24150@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24151 movl %eax, pa(max_pfn_mapped)
24152
24153 /* Do early initialization of the fixmap area */
24154- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24155- movl %eax,pa(initial_page_table+0xffc)
24156+#ifdef CONFIG_COMPAT_VDSO
24157+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24158+#else
24159+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24160+#endif
24161 #endif
24162
24163 #ifdef CONFIG_PARAVIRT
24164@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24165 cmpl $num_subarch_entries, %eax
24166 jae bad_subarch
24167
24168- movl pa(subarch_entries)(,%eax,4), %eax
24169- subl $__PAGE_OFFSET, %eax
24170- jmp *%eax
24171+ jmp *pa(subarch_entries)(,%eax,4)
24172
24173 bad_subarch:
24174 WEAK(lguest_entry)
24175@@ -261,10 +333,10 @@ WEAK(xen_entry)
24176 __INITDATA
24177
24178 subarch_entries:
24179- .long default_entry /* normal x86/PC */
24180- .long lguest_entry /* lguest hypervisor */
24181- .long xen_entry /* Xen hypervisor */
24182- .long default_entry /* Moorestown MID */
24183+ .long ta(default_entry) /* normal x86/PC */
24184+ .long ta(lguest_entry) /* lguest hypervisor */
24185+ .long ta(xen_entry) /* Xen hypervisor */
24186+ .long ta(default_entry) /* Moorestown MID */
24187 num_subarch_entries = (. - subarch_entries) / 4
24188 .previous
24189 #else
24190@@ -354,6 +426,7 @@ default_entry:
24191 movl pa(mmu_cr4_features),%eax
24192 movl %eax,%cr4
24193
24194+#ifdef CONFIG_X86_PAE
24195 testb $X86_CR4_PAE, %al # check if PAE is enabled
24196 jz enable_paging
24197
24198@@ -382,6 +455,9 @@ default_entry:
24199 /* Make changes effective */
24200 wrmsr
24201
24202+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24203+#endif
24204+
24205 enable_paging:
24206
24207 /*
24208@@ -449,14 +525,20 @@ is486:
24209 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24210 movl %eax,%ss # after changing gdt.
24211
24212- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24213+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24214 movl %eax,%ds
24215 movl %eax,%es
24216
24217 movl $(__KERNEL_PERCPU), %eax
24218 movl %eax,%fs # set this cpu's percpu
24219
24220+#ifdef CONFIG_CC_STACKPROTECTOR
24221 movl $(__KERNEL_STACK_CANARY),%eax
24222+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24223+ movl $(__USER_DS),%eax
24224+#else
24225+ xorl %eax,%eax
24226+#endif
24227 movl %eax,%gs
24228
24229 xorl %eax,%eax # Clear LDT
24230@@ -512,8 +594,11 @@ setup_once:
24231 * relocation. Manually set base address in stack canary
24232 * segment descriptor.
24233 */
24234- movl $gdt_page,%eax
24235+ movl $cpu_gdt_table,%eax
24236 movl $stack_canary,%ecx
24237+#ifdef CONFIG_SMP
24238+ addl $__per_cpu_load,%ecx
24239+#endif
24240 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24241 shrl $16, %ecx
24242 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24243@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24244 cmpl $2,(%esp) # X86_TRAP_NMI
24245 je is_nmi # Ignore NMI
24246
24247- cmpl $2,%ss:early_recursion_flag
24248+ cmpl $1,%ss:early_recursion_flag
24249 je hlt_loop
24250 incl %ss:early_recursion_flag
24251
24252@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24253 pushl (20+6*4)(%esp) /* trapno */
24254 pushl $fault_msg
24255 call printk
24256-#endif
24257 call dump_stack
24258+#endif
24259 hlt_loop:
24260 hlt
24261 jmp hlt_loop
24262@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24263 /* This is the default interrupt "handler" :-) */
24264 ALIGN
24265 ignore_int:
24266- cld
24267 #ifdef CONFIG_PRINTK
24268+ cmpl $2,%ss:early_recursion_flag
24269+ je hlt_loop
24270+ incl %ss:early_recursion_flag
24271+ cld
24272 pushl %eax
24273 pushl %ecx
24274 pushl %edx
24275@@ -617,9 +705,6 @@ ignore_int:
24276 movl $(__KERNEL_DS),%eax
24277 movl %eax,%ds
24278 movl %eax,%es
24279- cmpl $2,early_recursion_flag
24280- je hlt_loop
24281- incl early_recursion_flag
24282 pushl 16(%esp)
24283 pushl 24(%esp)
24284 pushl 32(%esp)
24285@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24286 /*
24287 * BSS section
24288 */
24289-__PAGE_ALIGNED_BSS
24290- .align PAGE_SIZE
24291 #ifdef CONFIG_X86_PAE
24292+.section .initial_pg_pmd,"a",@progbits
24293 initial_pg_pmd:
24294 .fill 1024*KPMDS,4,0
24295 #else
24296+.section .initial_page_table,"a",@progbits
24297 ENTRY(initial_page_table)
24298 .fill 1024,4,0
24299 #endif
24300+.section .initial_pg_fixmap,"a",@progbits
24301 initial_pg_fixmap:
24302 .fill 1024,4,0
24303+.section .empty_zero_page,"a",@progbits
24304 ENTRY(empty_zero_page)
24305 .fill 4096,1,0
24306+.section .swapper_pg_dir,"a",@progbits
24307 ENTRY(swapper_pg_dir)
24308+#ifdef CONFIG_X86_PAE
24309+ .fill 4,8,0
24310+#else
24311 .fill 1024,4,0
24312+#endif
24313
24314 /*
24315 * This starts the data section.
24316 */
24317 #ifdef CONFIG_X86_PAE
24318-__PAGE_ALIGNED_DATA
24319- /* Page-aligned for the benefit of paravirt? */
24320- .align PAGE_SIZE
24321+.section .initial_page_table,"a",@progbits
24322 ENTRY(initial_page_table)
24323 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24324 # if KPMDS == 3
24325@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24326 # error "Kernel PMDs should be 1, 2 or 3"
24327 # endif
24328 .align PAGE_SIZE /* needs to be page-sized too */
24329+
24330+#ifdef CONFIG_PAX_PER_CPU_PGD
24331+ENTRY(cpu_pgd)
24332+ .rept 2*NR_CPUS
24333+ .fill 4,8,0
24334+ .endr
24335+#endif
24336+
24337 #endif
24338
24339 .data
24340 .balign 4
24341 ENTRY(stack_start)
24342- .long init_thread_union+THREAD_SIZE
24343+ .long init_thread_union+THREAD_SIZE-8
24344
24345 __INITRODATA
24346 int_msg:
24347@@ -727,7 +825,7 @@ fault_msg:
24348 * segment size, and 32-bit linear address value:
24349 */
24350
24351- .data
24352+.section .rodata,"a",@progbits
24353 .globl boot_gdt_descr
24354 .globl idt_descr
24355
24356@@ -736,7 +834,7 @@ fault_msg:
24357 .word 0 # 32 bit align gdt_desc.address
24358 boot_gdt_descr:
24359 .word __BOOT_DS+7
24360- .long boot_gdt - __PAGE_OFFSET
24361+ .long pa(boot_gdt)
24362
24363 .word 0 # 32-bit align idt_desc.address
24364 idt_descr:
24365@@ -747,7 +845,7 @@ idt_descr:
24366 .word 0 # 32 bit align gdt_desc.address
24367 ENTRY(early_gdt_descr)
24368 .word GDT_ENTRIES*8-1
24369- .long gdt_page /* Overwritten for secondary CPUs */
24370+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24371
24372 /*
24373 * The boot_gdt must mirror the equivalent in setup.S and is
24374@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24375 .align L1_CACHE_BYTES
24376 ENTRY(boot_gdt)
24377 .fill GDT_ENTRY_BOOT_CS,8,0
24378- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24379- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24380+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24381+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24382+
24383+ .align PAGE_SIZE_asm
24384+ENTRY(cpu_gdt_table)
24385+ .rept NR_CPUS
24386+ .quad 0x0000000000000000 /* NULL descriptor */
24387+ .quad 0x0000000000000000 /* 0x0b reserved */
24388+ .quad 0x0000000000000000 /* 0x13 reserved */
24389+ .quad 0x0000000000000000 /* 0x1b reserved */
24390+
24391+#ifdef CONFIG_PAX_KERNEXEC
24392+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24393+#else
24394+ .quad 0x0000000000000000 /* 0x20 unused */
24395+#endif
24396+
24397+ .quad 0x0000000000000000 /* 0x28 unused */
24398+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24399+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24400+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24401+ .quad 0x0000000000000000 /* 0x4b reserved */
24402+ .quad 0x0000000000000000 /* 0x53 reserved */
24403+ .quad 0x0000000000000000 /* 0x5b reserved */
24404+
24405+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24406+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24407+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24408+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24409+
24410+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24411+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24412+
24413+ /*
24414+ * Segments used for calling PnP BIOS have byte granularity.
24415+ * The code segments and data segments have fixed 64k limits,
24416+ * the transfer segment sizes are set at run time.
24417+ */
24418+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24419+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24420+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24421+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24422+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24423+
24424+ /*
24425+ * The APM segments have byte granularity and their bases
24426+ * are set at run time. All have 64k limits.
24427+ */
24428+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24429+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24430+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24431+
24432+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24433+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24434+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24435+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24436+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24437+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24438+
24439+ /* Be sure this is zeroed to avoid false validations in Xen */
24440+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24441+ .endr
24442diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24443index a468c0a..c7dec74 100644
24444--- a/arch/x86/kernel/head_64.S
24445+++ b/arch/x86/kernel/head_64.S
24446@@ -20,6 +20,8 @@
24447 #include <asm/processor-flags.h>
24448 #include <asm/percpu.h>
24449 #include <asm/nops.h>
24450+#include <asm/cpufeature.h>
24451+#include <asm/alternative-asm.h>
24452
24453 #ifdef CONFIG_PARAVIRT
24454 #include <asm/asm-offsets.h>
24455@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24456 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24457 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24458 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24459+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24460+L3_VMALLOC_START = pud_index(VMALLOC_START)
24461+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24462+L3_VMALLOC_END = pud_index(VMALLOC_END)
24463+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24464+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24465
24466 .text
24467 __HEAD
24468@@ -89,11 +97,24 @@ startup_64:
24469 * Fixup the physical addresses in the page table
24470 */
24471 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24472+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24473+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24474+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24475+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24476+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24477
24478- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24479- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24480+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24481+#ifndef CONFIG_XEN
24482+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24483+#endif
24484+
24485+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24486+
24487+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24488+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24489
24490 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24491+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24492
24493 /*
24494 * Set up the identity mapping for the switchover. These
24495@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24496 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24497 1:
24498
24499- /* Enable PAE mode and PGE */
24500- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24501+ /* Enable PAE mode and PSE/PGE */
24502+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24503 movq %rcx, %cr4
24504
24505 /* Setup early boot stage 4 level pagetables. */
24506@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24507 movl $MSR_EFER, %ecx
24508 rdmsr
24509 btsl $_EFER_SCE, %eax /* Enable System Call */
24510- btl $20,%edi /* No Execute supported? */
24511+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24512 jnc 1f
24513 btsl $_EFER_NX, %eax
24514 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24515+#ifndef CONFIG_EFI
24516+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24517+#endif
24518+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24519+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24520+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24521+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24522+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24523+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24524 1: wrmsr /* Make changes effective */
24525
24526 /* Setup cr0 */
24527@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24528 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24529 * address given in m16:64.
24530 */
24531+ pax_set_fptr_mask
24532 movq initial_code(%rip),%rax
24533 pushq $0 # fake return address to stop unwinder
24534 pushq $__KERNEL_CS # set correct cs
24535@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24536 .quad INIT_PER_CPU_VAR(irq_stack_union)
24537
24538 GLOBAL(stack_start)
24539- .quad init_thread_union+THREAD_SIZE-8
24540+ .quad init_thread_union+THREAD_SIZE-16
24541 .word 0
24542 __FINITDATA
24543
24544@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24545 call dump_stack
24546 #ifdef CONFIG_KALLSYMS
24547 leaq early_idt_ripmsg(%rip),%rdi
24548- movq 40(%rsp),%rsi # %rip again
24549+ movq 88(%rsp),%rsi # %rip again
24550 call __print_symbol
24551 #endif
24552 #endif /* EARLY_PRINTK */
24553@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24554 early_recursion_flag:
24555 .long 0
24556
24557+ .section .rodata,"a",@progbits
24558 #ifdef CONFIG_EARLY_PRINTK
24559 early_idt_msg:
24560 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24561@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24562 NEXT_PAGE(early_dynamic_pgts)
24563 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24564
24565- .data
24566+ .section .rodata,"a",@progbits
24567
24568-#ifndef CONFIG_XEN
24569 NEXT_PAGE(init_level4_pgt)
24570- .fill 512,8,0
24571-#else
24572-NEXT_PAGE(init_level4_pgt)
24573- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24574 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24575 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24576+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24577+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24578+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24579+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24580+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24581+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24582 .org init_level4_pgt + L4_START_KERNEL*8, 0
24583 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24584 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24585
24586+#ifdef CONFIG_PAX_PER_CPU_PGD
24587+NEXT_PAGE(cpu_pgd)
24588+ .rept 2*NR_CPUS
24589+ .fill 512,8,0
24590+ .endr
24591+#endif
24592+
24593 NEXT_PAGE(level3_ident_pgt)
24594 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24595+#ifdef CONFIG_XEN
24596 .fill 511, 8, 0
24597+#else
24598+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24599+ .fill 510,8,0
24600+#endif
24601+
24602+NEXT_PAGE(level3_vmalloc_start_pgt)
24603+ .fill 512,8,0
24604+
24605+NEXT_PAGE(level3_vmalloc_end_pgt)
24606+ .fill 512,8,0
24607+
24608+NEXT_PAGE(level3_vmemmap_pgt)
24609+ .fill L3_VMEMMAP_START,8,0
24610+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24611+
24612 NEXT_PAGE(level2_ident_pgt)
24613- /* Since I easily can, map the first 1G.
24614+ /* Since I easily can, map the first 2G.
24615 * Don't set NX because code runs from these pages.
24616 */
24617- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24618-#endif
24619+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24620
24621 NEXT_PAGE(level3_kernel_pgt)
24622 .fill L3_START_KERNEL,8,0
24623@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24624 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24625 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24626
24627+NEXT_PAGE(level2_vmemmap_pgt)
24628+ .fill 512,8,0
24629+
24630 NEXT_PAGE(level2_kernel_pgt)
24631 /*
24632 * 512 MB kernel mapping. We spend a full page on this pagetable
24633@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24634 NEXT_PAGE(level2_fixmap_pgt)
24635 .fill 506,8,0
24636 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24637- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24638- .fill 5,8,0
24639+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24640+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24641+ .fill 4,8,0
24642
24643 NEXT_PAGE(level1_fixmap_pgt)
24644 .fill 512,8,0
24645
24646+NEXT_PAGE(level1_vsyscall_pgt)
24647+ .fill 512,8,0
24648+
24649 #undef PMDS
24650
24651- .data
24652+ .align PAGE_SIZE
24653+ENTRY(cpu_gdt_table)
24654+ .rept NR_CPUS
24655+ .quad 0x0000000000000000 /* NULL descriptor */
24656+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24657+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24658+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24659+ .quad 0x00cffb000000ffff /* __USER32_CS */
24660+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24661+ .quad 0x00affb000000ffff /* __USER_CS */
24662+
24663+#ifdef CONFIG_PAX_KERNEXEC
24664+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24665+#else
24666+ .quad 0x0 /* unused */
24667+#endif
24668+
24669+ .quad 0,0 /* TSS */
24670+ .quad 0,0 /* LDT */
24671+ .quad 0,0,0 /* three TLS descriptors */
24672+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24673+ /* asm/segment.h:GDT_ENTRIES must match this */
24674+
24675+#ifdef CONFIG_PAX_MEMORY_UDEREF
24676+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24677+#else
24678+ .quad 0x0 /* unused */
24679+#endif
24680+
24681+ /* zero the remaining page */
24682+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24683+ .endr
24684+
24685 .align 16
24686 .globl early_gdt_descr
24687 early_gdt_descr:
24688 .word GDT_ENTRIES*8-1
24689 early_gdt_descr_base:
24690- .quad INIT_PER_CPU_VAR(gdt_page)
24691+ .quad cpu_gdt_table
24692
24693 ENTRY(phys_base)
24694 /* This must match the first entry in level2_kernel_pgt */
24695 .quad 0x0000000000000000
24696
24697 #include "../../x86/xen/xen-head.S"
24698-
24699- __PAGE_ALIGNED_BSS
24700+
24701+ .section .rodata,"a",@progbits
24702 NEXT_PAGE(empty_zero_page)
24703 .skip PAGE_SIZE
24704diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24705index 05fd74f..c3548b1 100644
24706--- a/arch/x86/kernel/i386_ksyms_32.c
24707+++ b/arch/x86/kernel/i386_ksyms_32.c
24708@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24709 EXPORT_SYMBOL(cmpxchg8b_emu);
24710 #endif
24711
24712+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24713+
24714 /* Networking helper routines. */
24715 EXPORT_SYMBOL(csum_partial_copy_generic);
24716+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24717+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24718
24719 EXPORT_SYMBOL(__get_user_1);
24720 EXPORT_SYMBOL(__get_user_2);
24721@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24722 EXPORT_SYMBOL(___preempt_schedule_context);
24723 #endif
24724 #endif
24725+
24726+#ifdef CONFIG_PAX_KERNEXEC
24727+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24728+#endif
24729+
24730+#ifdef CONFIG_PAX_PER_CPU_PGD
24731+EXPORT_SYMBOL(cpu_pgd);
24732+#endif
24733diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24734index d5dd808..b6432cf 100644
24735--- a/arch/x86/kernel/i387.c
24736+++ b/arch/x86/kernel/i387.c
24737@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24738 static inline bool interrupted_user_mode(void)
24739 {
24740 struct pt_regs *regs = get_irq_regs();
24741- return regs && user_mode_vm(regs);
24742+ return regs && user_mode(regs);
24743 }
24744
24745 /*
24746diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24747index 2e977b5..5f2c273 100644
24748--- a/arch/x86/kernel/i8259.c
24749+++ b/arch/x86/kernel/i8259.c
24750@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24751 static void make_8259A_irq(unsigned int irq)
24752 {
24753 disable_irq_nosync(irq);
24754- io_apic_irqs &= ~(1<<irq);
24755+ io_apic_irqs &= ~(1UL<<irq);
24756 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24757 i8259A_chip.name);
24758 enable_irq(irq);
24759@@ -209,7 +209,7 @@ spurious_8259A_irq:
24760 "spurious 8259A interrupt: IRQ%d.\n", irq);
24761 spurious_irq_mask |= irqmask;
24762 }
24763- atomic_inc(&irq_err_count);
24764+ atomic_inc_unchecked(&irq_err_count);
24765 /*
24766 * Theoretically we do not have to handle this IRQ,
24767 * but in Linux this does not cause problems and is
24768@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24769 /* (slave's support for AEOI in flat mode is to be investigated) */
24770 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24771
24772+ pax_open_kernel();
24773 if (auto_eoi)
24774 /*
24775 * In AEOI mode we just have to mask the interrupt
24776 * when acking.
24777 */
24778- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24779+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24780 else
24781- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24782+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24783+ pax_close_kernel();
24784
24785 udelay(100); /* wait for 8259A to initialize */
24786
24787diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24788index a979b5b..1d6db75 100644
24789--- a/arch/x86/kernel/io_delay.c
24790+++ b/arch/x86/kernel/io_delay.c
24791@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24792 * Quirk table for systems that misbehave (lock up, etc.) if port
24793 * 0x80 is used:
24794 */
24795-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24796+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24797 {
24798 .callback = dmi_io_delay_0xed_port,
24799 .ident = "Compaq Presario V6000",
24800diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24801index 4ddaf66..49d5c18 100644
24802--- a/arch/x86/kernel/ioport.c
24803+++ b/arch/x86/kernel/ioport.c
24804@@ -6,6 +6,7 @@
24805 #include <linux/sched.h>
24806 #include <linux/kernel.h>
24807 #include <linux/capability.h>
24808+#include <linux/security.h>
24809 #include <linux/errno.h>
24810 #include <linux/types.h>
24811 #include <linux/ioport.h>
24812@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24813 return -EINVAL;
24814 if (turn_on && !capable(CAP_SYS_RAWIO))
24815 return -EPERM;
24816+#ifdef CONFIG_GRKERNSEC_IO
24817+ if (turn_on && grsec_disable_privio) {
24818+ gr_handle_ioperm();
24819+ return -ENODEV;
24820+ }
24821+#endif
24822
24823 /*
24824 * If it's the first ioperm() call in this thread's lifetime, set the
24825@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24826 * because the ->io_bitmap_max value must match the bitmap
24827 * contents:
24828 */
24829- tss = &per_cpu(init_tss, get_cpu());
24830+ tss = init_tss + get_cpu();
24831
24832 if (turn_on)
24833 bitmap_clear(t->io_bitmap_ptr, from, num);
24834@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24835 if (level > old) {
24836 if (!capable(CAP_SYS_RAWIO))
24837 return -EPERM;
24838+#ifdef CONFIG_GRKERNSEC_IO
24839+ if (grsec_disable_privio) {
24840+ gr_handle_iopl();
24841+ return -ENODEV;
24842+ }
24843+#endif
24844 }
24845 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24846 t->iopl = level << 12;
24847diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24848index d99f31d..1c0f466 100644
24849--- a/arch/x86/kernel/irq.c
24850+++ b/arch/x86/kernel/irq.c
24851@@ -21,7 +21,7 @@
24852 #define CREATE_TRACE_POINTS
24853 #include <asm/trace/irq_vectors.h>
24854
24855-atomic_t irq_err_count;
24856+atomic_unchecked_t irq_err_count;
24857
24858 /* Function pointer for generic interrupt vector handling */
24859 void (*x86_platform_ipi_callback)(void) = NULL;
24860@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24861 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24862 seq_printf(p, " Machine check polls\n");
24863 #endif
24864- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24865+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24866 #if defined(CONFIG_X86_IO_APIC)
24867- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24868+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24869 #endif
24870 return 0;
24871 }
24872@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24873
24874 u64 arch_irq_stat(void)
24875 {
24876- u64 sum = atomic_read(&irq_err_count);
24877+ u64 sum = atomic_read_unchecked(&irq_err_count);
24878 return sum;
24879 }
24880
24881diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24882index d7fcbed..1f747f7 100644
24883--- a/arch/x86/kernel/irq_32.c
24884+++ b/arch/x86/kernel/irq_32.c
24885@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24886 __asm__ __volatile__("andl %%esp,%0" :
24887 "=r" (sp) : "0" (THREAD_SIZE - 1));
24888
24889- return sp < (sizeof(struct thread_info) + STACK_WARN);
24890+ return sp < STACK_WARN;
24891 }
24892
24893 static void print_stack_overflow(void)
24894@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24895 * per-CPU IRQ handling contexts (thread information and stack)
24896 */
24897 union irq_ctx {
24898- struct thread_info tinfo;
24899- u32 stack[THREAD_SIZE/sizeof(u32)];
24900+ unsigned long previous_esp;
24901+ u32 stack[THREAD_SIZE/sizeof(u32)];
24902 } __attribute__((aligned(THREAD_SIZE)));
24903
24904 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24905@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24906 static inline int
24907 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24908 {
24909- union irq_ctx *curctx, *irqctx;
24910+ union irq_ctx *irqctx;
24911 u32 *isp, arg1, arg2;
24912
24913- curctx = (union irq_ctx *) current_thread_info();
24914 irqctx = __this_cpu_read(hardirq_ctx);
24915
24916 /*
24917@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24918 * handler) we can't do that and just have to keep using the
24919 * current stack (which is the irq stack already after all)
24920 */
24921- if (unlikely(curctx == irqctx))
24922+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24923 return 0;
24924
24925 /* build the stack frame on the IRQ stack */
24926- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24927- irqctx->tinfo.task = curctx->tinfo.task;
24928- irqctx->tinfo.previous_esp = current_stack_pointer;
24929+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24930+ irqctx->previous_esp = current_stack_pointer;
24931+
24932+#ifdef CONFIG_PAX_MEMORY_UDEREF
24933+ __set_fs(MAKE_MM_SEG(0));
24934+#endif
24935
24936 if (unlikely(overflow))
24937 call_on_stack(print_stack_overflow, isp);
24938@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24939 : "0" (irq), "1" (desc), "2" (isp),
24940 "D" (desc->handle_irq)
24941 : "memory", "cc", "ecx");
24942+
24943+#ifdef CONFIG_PAX_MEMORY_UDEREF
24944+ __set_fs(current_thread_info()->addr_limit);
24945+#endif
24946+
24947 return 1;
24948 }
24949
24950@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24951 */
24952 void irq_ctx_init(int cpu)
24953 {
24954- union irq_ctx *irqctx;
24955-
24956 if (per_cpu(hardirq_ctx, cpu))
24957 return;
24958
24959- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24960- THREADINFO_GFP,
24961- THREAD_SIZE_ORDER));
24962- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24963- irqctx->tinfo.cpu = cpu;
24964- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24965-
24966- per_cpu(hardirq_ctx, cpu) = irqctx;
24967-
24968- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24969- THREADINFO_GFP,
24970- THREAD_SIZE_ORDER));
24971- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24972- irqctx->tinfo.cpu = cpu;
24973- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24974-
24975- per_cpu(softirq_ctx, cpu) = irqctx;
24976-
24977- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24978- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24979+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24980+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24981 }
24982
24983 void do_softirq_own_stack(void)
24984 {
24985- struct thread_info *curctx;
24986 union irq_ctx *irqctx;
24987 u32 *isp;
24988
24989- curctx = current_thread_info();
24990 irqctx = __this_cpu_read(softirq_ctx);
24991- irqctx->tinfo.task = curctx->task;
24992- irqctx->tinfo.previous_esp = current_stack_pointer;
24993+ irqctx->previous_esp = current_stack_pointer;
24994
24995 /* build the stack frame on the softirq stack */
24996- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24997+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24998+
24999+#ifdef CONFIG_PAX_MEMORY_UDEREF
25000+ __set_fs(MAKE_MM_SEG(0));
25001+#endif
25002
25003 call_on_stack(__do_softirq, isp);
25004+
25005+#ifdef CONFIG_PAX_MEMORY_UDEREF
25006+ __set_fs(current_thread_info()->addr_limit);
25007+#endif
25008+
25009 }
25010
25011 bool handle_irq(unsigned irq, struct pt_regs *regs)
25012@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25013 if (unlikely(!desc))
25014 return false;
25015
25016- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25017+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25018 if (unlikely(overflow))
25019 print_stack_overflow();
25020 desc->handle_irq(irq, desc);
25021diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25022index 4d1c746..232961d 100644
25023--- a/arch/x86/kernel/irq_64.c
25024+++ b/arch/x86/kernel/irq_64.c
25025@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25026 u64 estack_top, estack_bottom;
25027 u64 curbase = (u64)task_stack_page(current);
25028
25029- if (user_mode_vm(regs))
25030+ if (user_mode(regs))
25031 return;
25032
25033 if (regs->sp >= curbase + sizeof(struct thread_info) +
25034diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25035index 26d5a55..a01160a 100644
25036--- a/arch/x86/kernel/jump_label.c
25037+++ b/arch/x86/kernel/jump_label.c
25038@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25039 * Jump label is enabled for the first time.
25040 * So we expect a default_nop...
25041 */
25042- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25043+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25044 != 0))
25045 bug_at((void *)entry->code, __LINE__);
25046 } else {
25047@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25048 * ...otherwise expect an ideal_nop. Otherwise
25049 * something went horribly wrong.
25050 */
25051- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25052+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25053 != 0))
25054 bug_at((void *)entry->code, __LINE__);
25055 }
25056@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25057 * are converting the default nop to the ideal nop.
25058 */
25059 if (init) {
25060- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25061+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25062 bug_at((void *)entry->code, __LINE__);
25063 } else {
25064 code.jump = 0xe9;
25065 code.offset = entry->target -
25066 (entry->code + JUMP_LABEL_NOP_SIZE);
25067- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25068+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25069 bug_at((void *)entry->code, __LINE__);
25070 }
25071 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25072diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25073index 7ec1d5f..5a7d130 100644
25074--- a/arch/x86/kernel/kgdb.c
25075+++ b/arch/x86/kernel/kgdb.c
25076@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25077 #ifdef CONFIG_X86_32
25078 switch (regno) {
25079 case GDB_SS:
25080- if (!user_mode_vm(regs))
25081+ if (!user_mode(regs))
25082 *(unsigned long *)mem = __KERNEL_DS;
25083 break;
25084 case GDB_SP:
25085- if (!user_mode_vm(regs))
25086+ if (!user_mode(regs))
25087 *(unsigned long *)mem = kernel_stack_pointer(regs);
25088 break;
25089 case GDB_GS:
25090@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25091 bp->attr.bp_addr = breakinfo[breakno].addr;
25092 bp->attr.bp_len = breakinfo[breakno].len;
25093 bp->attr.bp_type = breakinfo[breakno].type;
25094- info->address = breakinfo[breakno].addr;
25095+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25096+ info->address = ktla_ktva(breakinfo[breakno].addr);
25097+ else
25098+ info->address = breakinfo[breakno].addr;
25099 info->len = breakinfo[breakno].len;
25100 info->type = breakinfo[breakno].type;
25101 val = arch_install_hw_breakpoint(bp);
25102@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25103 case 'k':
25104 /* clear the trace bit */
25105 linux_regs->flags &= ~X86_EFLAGS_TF;
25106- atomic_set(&kgdb_cpu_doing_single_step, -1);
25107+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25108
25109 /* set the trace bit if we're stepping */
25110 if (remcomInBuffer[0] == 's') {
25111 linux_regs->flags |= X86_EFLAGS_TF;
25112- atomic_set(&kgdb_cpu_doing_single_step,
25113+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25114 raw_smp_processor_id());
25115 }
25116
25117@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25118
25119 switch (cmd) {
25120 case DIE_DEBUG:
25121- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25122+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25123 if (user_mode(regs))
25124 return single_step_cont(regs, args);
25125 break;
25126@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25127 #endif /* CONFIG_DEBUG_RODATA */
25128
25129 bpt->type = BP_BREAKPOINT;
25130- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25131+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25132 BREAK_INSTR_SIZE);
25133 if (err)
25134 return err;
25135- err = probe_kernel_write((char *)bpt->bpt_addr,
25136+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25137 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25138 #ifdef CONFIG_DEBUG_RODATA
25139 if (!err)
25140@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25141 return -EBUSY;
25142 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25143 BREAK_INSTR_SIZE);
25144- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25145+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25146 if (err)
25147 return err;
25148 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25149@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25150 if (mutex_is_locked(&text_mutex))
25151 goto knl_write;
25152 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25153- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25154+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25155 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25156 goto knl_write;
25157 return err;
25158 knl_write:
25159 #endif /* CONFIG_DEBUG_RODATA */
25160- return probe_kernel_write((char *)bpt->bpt_addr,
25161+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25162 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25163 }
25164
25165diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25166index 79a3f96..6ba030a 100644
25167--- a/arch/x86/kernel/kprobes/core.c
25168+++ b/arch/x86/kernel/kprobes/core.c
25169@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25170 s32 raddr;
25171 } __packed *insn;
25172
25173- insn = (struct __arch_relative_insn *)from;
25174+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25175+
25176+ pax_open_kernel();
25177 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25178 insn->op = op;
25179+ pax_close_kernel();
25180 }
25181
25182 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25183@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25184 kprobe_opcode_t opcode;
25185 kprobe_opcode_t *orig_opcodes = opcodes;
25186
25187- if (search_exception_tables((unsigned long)opcodes))
25188+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25189 return 0; /* Page fault may occur on this address. */
25190
25191 retry:
25192@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25193 * for the first byte, we can recover the original instruction
25194 * from it and kp->opcode.
25195 */
25196- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25197+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25198 buf[0] = kp->opcode;
25199- return (unsigned long)buf;
25200+ return ktva_ktla((unsigned long)buf);
25201 }
25202
25203 /*
25204@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25205 /* Another subsystem puts a breakpoint, failed to recover */
25206 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25207 return 0;
25208+ pax_open_kernel();
25209 memcpy(dest, insn.kaddr, insn.length);
25210+ pax_close_kernel();
25211
25212 #ifdef CONFIG_X86_64
25213 if (insn_rip_relative(&insn)) {
25214@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25215 return 0;
25216 }
25217 disp = (u8 *) dest + insn_offset_displacement(&insn);
25218+ pax_open_kernel();
25219 *(s32 *) disp = (s32) newdisp;
25220+ pax_close_kernel();
25221 }
25222 #endif
25223 return insn.length;
25224@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25225 * nor set current_kprobe, because it doesn't use single
25226 * stepping.
25227 */
25228- regs->ip = (unsigned long)p->ainsn.insn;
25229+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25230 preempt_enable_no_resched();
25231 return;
25232 }
25233@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25234 regs->flags &= ~X86_EFLAGS_IF;
25235 /* single step inline if the instruction is an int3 */
25236 if (p->opcode == BREAKPOINT_INSTRUCTION)
25237- regs->ip = (unsigned long)p->addr;
25238+ regs->ip = ktla_ktva((unsigned long)p->addr);
25239 else
25240- regs->ip = (unsigned long)p->ainsn.insn;
25241+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25242 }
25243
25244 /*
25245@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25246 setup_singlestep(p, regs, kcb, 0);
25247 return 1;
25248 }
25249- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25250+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25251 /*
25252 * The breakpoint instruction was removed right
25253 * after we hit it. Another cpu has removed
25254@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25255 " movq %rax, 152(%rsp)\n"
25256 RESTORE_REGS_STRING
25257 " popfq\n"
25258+#ifdef KERNEXEC_PLUGIN
25259+ " btsq $63,(%rsp)\n"
25260+#endif
25261 #else
25262 " pushf\n"
25263 SAVE_REGS_STRING
25264@@ -779,7 +789,7 @@ static void __kprobes
25265 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25266 {
25267 unsigned long *tos = stack_addr(regs);
25268- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25269+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25270 unsigned long orig_ip = (unsigned long)p->addr;
25271 kprobe_opcode_t *insn = p->ainsn.insn;
25272
25273@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25274 struct die_args *args = data;
25275 int ret = NOTIFY_DONE;
25276
25277- if (args->regs && user_mode_vm(args->regs))
25278+ if (args->regs && user_mode(args->regs))
25279 return ret;
25280
25281 switch (val) {
25282diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25283index 898160b..758cde8 100644
25284--- a/arch/x86/kernel/kprobes/opt.c
25285+++ b/arch/x86/kernel/kprobes/opt.c
25286@@ -79,6 +79,7 @@ found:
25287 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25288 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25289 {
25290+ pax_open_kernel();
25291 #ifdef CONFIG_X86_64
25292 *addr++ = 0x48;
25293 *addr++ = 0xbf;
25294@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25295 *addr++ = 0xb8;
25296 #endif
25297 *(unsigned long *)addr = val;
25298+ pax_close_kernel();
25299 }
25300
25301 asm (
25302@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25303 * Verify if the address gap is in 2GB range, because this uses
25304 * a relative jump.
25305 */
25306- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25307+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25308 if (abs(rel) > 0x7fffffff)
25309 return -ERANGE;
25310
25311@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25312 op->optinsn.size = ret;
25313
25314 /* Copy arch-dep-instance from template */
25315- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25316+ pax_open_kernel();
25317+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25318+ pax_close_kernel();
25319
25320 /* Set probe information */
25321 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25322
25323 /* Set probe function call */
25324- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25325+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25326
25327 /* Set returning jmp instruction at the tail of out-of-line buffer */
25328- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25329+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25330 (u8 *)op->kp.addr + op->optinsn.size);
25331
25332 flush_icache_range((unsigned long) buf,
25333@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25334 WARN_ON(kprobe_disabled(&op->kp));
25335
25336 /* Backup instructions which will be replaced by jump address */
25337- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25338+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25339 RELATIVE_ADDR_SIZE);
25340
25341 insn_buf[0] = RELATIVEJUMP_OPCODE;
25342@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25343 /* This kprobe is really able to run optimized path. */
25344 op = container_of(p, struct optimized_kprobe, kp);
25345 /* Detour through copied instructions */
25346- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25347+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25348 if (!reenter)
25349 reset_current_kprobe();
25350 preempt_enable_no_resched();
25351diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25352index c2bedae..25e7ab6 100644
25353--- a/arch/x86/kernel/ksysfs.c
25354+++ b/arch/x86/kernel/ksysfs.c
25355@@ -184,7 +184,7 @@ out:
25356
25357 static struct kobj_attribute type_attr = __ATTR_RO(type);
25358
25359-static struct bin_attribute data_attr = {
25360+static bin_attribute_no_const data_attr __read_only = {
25361 .attr = {
25362 .name = "data",
25363 .mode = S_IRUGO,
25364diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25365index af1d14a..37b8776 100644
25366--- a/arch/x86/kernel/ldt.c
25367+++ b/arch/x86/kernel/ldt.c
25368@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25369 if (reload) {
25370 #ifdef CONFIG_SMP
25371 preempt_disable();
25372- load_LDT(pc);
25373+ load_LDT_nolock(pc);
25374 if (!cpumask_equal(mm_cpumask(current->mm),
25375 cpumask_of(smp_processor_id())))
25376 smp_call_function(flush_ldt, current->mm, 1);
25377 preempt_enable();
25378 #else
25379- load_LDT(pc);
25380+ load_LDT_nolock(pc);
25381 #endif
25382 }
25383 if (oldsize) {
25384@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25385 return err;
25386
25387 for (i = 0; i < old->size; i++)
25388- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25389+ write_ldt_entry(new->ldt, i, old->ldt + i);
25390 return 0;
25391 }
25392
25393@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25394 retval = copy_ldt(&mm->context, &old_mm->context);
25395 mutex_unlock(&old_mm->context.lock);
25396 }
25397+
25398+ if (tsk == current) {
25399+ mm->context.vdso = 0;
25400+
25401+#ifdef CONFIG_X86_32
25402+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25403+ mm->context.user_cs_base = 0UL;
25404+ mm->context.user_cs_limit = ~0UL;
25405+
25406+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25407+ cpus_clear(mm->context.cpu_user_cs_mask);
25408+#endif
25409+
25410+#endif
25411+#endif
25412+
25413+ }
25414+
25415 return retval;
25416 }
25417
25418@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25419 }
25420 }
25421
25422+#ifdef CONFIG_PAX_SEGMEXEC
25423+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25424+ error = -EINVAL;
25425+ goto out_unlock;
25426+ }
25427+#endif
25428+
25429 /*
25430 * On x86-64 we do not support 16-bit segments due to
25431 * IRET leaking the high bits of the kernel stack address.
25432diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25433index 1667b1d..16492c5 100644
25434--- a/arch/x86/kernel/machine_kexec_32.c
25435+++ b/arch/x86/kernel/machine_kexec_32.c
25436@@ -25,7 +25,7 @@
25437 #include <asm/cacheflush.h>
25438 #include <asm/debugreg.h>
25439
25440-static void set_idt(void *newidt, __u16 limit)
25441+static void set_idt(struct desc_struct *newidt, __u16 limit)
25442 {
25443 struct desc_ptr curidt;
25444
25445@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25446 }
25447
25448
25449-static void set_gdt(void *newgdt, __u16 limit)
25450+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25451 {
25452 struct desc_ptr curgdt;
25453
25454@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25455 }
25456
25457 control_page = page_address(image->control_code_page);
25458- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25459+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25460
25461 relocate_kernel_ptr = control_page;
25462 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25463diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25464index 18be189..4a9fe40 100644
25465--- a/arch/x86/kernel/module.c
25466+++ b/arch/x86/kernel/module.c
25467@@ -43,15 +43,60 @@ do { \
25468 } while (0)
25469 #endif
25470
25471-void *module_alloc(unsigned long size)
25472+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25473 {
25474- if (PAGE_ALIGN(size) > MODULES_LEN)
25475+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25476 return NULL;
25477 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25478- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25479+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25480 NUMA_NO_NODE, __builtin_return_address(0));
25481 }
25482
25483+void *module_alloc(unsigned long size)
25484+{
25485+
25486+#ifdef CONFIG_PAX_KERNEXEC
25487+ return __module_alloc(size, PAGE_KERNEL);
25488+#else
25489+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25490+#endif
25491+
25492+}
25493+
25494+#ifdef CONFIG_PAX_KERNEXEC
25495+#ifdef CONFIG_X86_32
25496+void *module_alloc_exec(unsigned long size)
25497+{
25498+ struct vm_struct *area;
25499+
25500+ if (size == 0)
25501+ return NULL;
25502+
25503+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25504+ return area ? area->addr : NULL;
25505+}
25506+EXPORT_SYMBOL(module_alloc_exec);
25507+
25508+void module_free_exec(struct module *mod, void *module_region)
25509+{
25510+ vunmap(module_region);
25511+}
25512+EXPORT_SYMBOL(module_free_exec);
25513+#else
25514+void module_free_exec(struct module *mod, void *module_region)
25515+{
25516+ module_free(mod, module_region);
25517+}
25518+EXPORT_SYMBOL(module_free_exec);
25519+
25520+void *module_alloc_exec(unsigned long size)
25521+{
25522+ return __module_alloc(size, PAGE_KERNEL_RX);
25523+}
25524+EXPORT_SYMBOL(module_alloc_exec);
25525+#endif
25526+#endif
25527+
25528 #ifdef CONFIG_X86_32
25529 int apply_relocate(Elf32_Shdr *sechdrs,
25530 const char *strtab,
25531@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25532 unsigned int i;
25533 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25534 Elf32_Sym *sym;
25535- uint32_t *location;
25536+ uint32_t *plocation, location;
25537
25538 DEBUGP("Applying relocate section %u to %u\n",
25539 relsec, sechdrs[relsec].sh_info);
25540 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25541 /* This is where to make the change */
25542- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25543- + rel[i].r_offset;
25544+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25545+ location = (uint32_t)plocation;
25546+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25547+ plocation = ktla_ktva((void *)plocation);
25548 /* This is the symbol it is referring to. Note that all
25549 undefined symbols have been resolved. */
25550 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25551@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25552 switch (ELF32_R_TYPE(rel[i].r_info)) {
25553 case R_386_32:
25554 /* We add the value into the location given */
25555- *location += sym->st_value;
25556+ pax_open_kernel();
25557+ *plocation += sym->st_value;
25558+ pax_close_kernel();
25559 break;
25560 case R_386_PC32:
25561 /* Add the value, subtract its position */
25562- *location += sym->st_value - (uint32_t)location;
25563+ pax_open_kernel();
25564+ *plocation += sym->st_value - location;
25565+ pax_close_kernel();
25566 break;
25567 default:
25568 pr_err("%s: Unknown relocation: %u\n",
25569@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25570 case R_X86_64_NONE:
25571 break;
25572 case R_X86_64_64:
25573+ pax_open_kernel();
25574 *(u64 *)loc = val;
25575+ pax_close_kernel();
25576 break;
25577 case R_X86_64_32:
25578+ pax_open_kernel();
25579 *(u32 *)loc = val;
25580+ pax_close_kernel();
25581 if (val != *(u32 *)loc)
25582 goto overflow;
25583 break;
25584 case R_X86_64_32S:
25585+ pax_open_kernel();
25586 *(s32 *)loc = val;
25587+ pax_close_kernel();
25588 if ((s64)val != *(s32 *)loc)
25589 goto overflow;
25590 break;
25591 case R_X86_64_PC32:
25592 val -= (u64)loc;
25593+ pax_open_kernel();
25594 *(u32 *)loc = val;
25595+ pax_close_kernel();
25596+
25597 #if 0
25598 if ((s64)val != *(s32 *)loc)
25599 goto overflow;
25600diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25601index 05266b5..3432443 100644
25602--- a/arch/x86/kernel/msr.c
25603+++ b/arch/x86/kernel/msr.c
25604@@ -37,6 +37,7 @@
25605 #include <linux/notifier.h>
25606 #include <linux/uaccess.h>
25607 #include <linux/gfp.h>
25608+#include <linux/grsecurity.h>
25609
25610 #include <asm/processor.h>
25611 #include <asm/msr.h>
25612@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25613 int err = 0;
25614 ssize_t bytes = 0;
25615
25616+#ifdef CONFIG_GRKERNSEC_KMEM
25617+ gr_handle_msr_write();
25618+ return -EPERM;
25619+#endif
25620+
25621 if (count % 8)
25622 return -EINVAL; /* Invalid chunk size */
25623
25624@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25625 err = -EBADF;
25626 break;
25627 }
25628+#ifdef CONFIG_GRKERNSEC_KMEM
25629+ gr_handle_msr_write();
25630+ return -EPERM;
25631+#endif
25632 if (copy_from_user(&regs, uregs, sizeof regs)) {
25633 err = -EFAULT;
25634 break;
25635@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25636 return notifier_from_errno(err);
25637 }
25638
25639-static struct notifier_block __refdata msr_class_cpu_notifier = {
25640+static struct notifier_block msr_class_cpu_notifier = {
25641 .notifier_call = msr_class_cpu_callback,
25642 };
25643
25644diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25645index 6fcb49c..5b3f4ff 100644
25646--- a/arch/x86/kernel/nmi.c
25647+++ b/arch/x86/kernel/nmi.c
25648@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25649 return handled;
25650 }
25651
25652-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25653+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25654 {
25655 struct nmi_desc *desc = nmi_to_desc(type);
25656 unsigned long flags;
25657@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25658 * event confuses some handlers (kdump uses this flag)
25659 */
25660 if (action->flags & NMI_FLAG_FIRST)
25661- list_add_rcu(&action->list, &desc->head);
25662+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25663 else
25664- list_add_tail_rcu(&action->list, &desc->head);
25665+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25666
25667 spin_unlock_irqrestore(&desc->lock, flags);
25668 return 0;
25669@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25670 if (!strcmp(n->name, name)) {
25671 WARN(in_nmi(),
25672 "Trying to free NMI (%s) from NMI context!\n", n->name);
25673- list_del_rcu(&n->list);
25674+ pax_list_del_rcu((struct list_head *)&n->list);
25675 break;
25676 }
25677 }
25678@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25679 dotraplinkage notrace __kprobes void
25680 do_nmi(struct pt_regs *regs, long error_code)
25681 {
25682+
25683+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25684+ if (!user_mode(regs)) {
25685+ unsigned long cs = regs->cs & 0xFFFF;
25686+ unsigned long ip = ktva_ktla(regs->ip);
25687+
25688+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25689+ regs->ip = ip;
25690+ }
25691+#endif
25692+
25693 nmi_nesting_preprocess(regs);
25694
25695 nmi_enter();
25696diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25697index 6d9582e..f746287 100644
25698--- a/arch/x86/kernel/nmi_selftest.c
25699+++ b/arch/x86/kernel/nmi_selftest.c
25700@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25701 {
25702 /* trap all the unknown NMIs we may generate */
25703 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25704- __initdata);
25705+ __initconst);
25706 }
25707
25708 static void __init cleanup_nmi_testsuite(void)
25709@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25710 unsigned long timeout;
25711
25712 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25713- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25714+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25715 nmi_fail = FAILURE;
25716 return;
25717 }
25718diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25719index bbb6c73..24a58ef 100644
25720--- a/arch/x86/kernel/paravirt-spinlocks.c
25721+++ b/arch/x86/kernel/paravirt-spinlocks.c
25722@@ -8,7 +8,7 @@
25723
25724 #include <asm/paravirt.h>
25725
25726-struct pv_lock_ops pv_lock_ops = {
25727+struct pv_lock_ops pv_lock_ops __read_only = {
25728 #ifdef CONFIG_SMP
25729 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25730 .unlock_kick = paravirt_nop,
25731diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25732index 1b10af8..0b58cbc 100644
25733--- a/arch/x86/kernel/paravirt.c
25734+++ b/arch/x86/kernel/paravirt.c
25735@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25736 {
25737 return x;
25738 }
25739+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25740+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25741+#endif
25742
25743 void __init default_banner(void)
25744 {
25745@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25746 if (opfunc == NULL)
25747 /* If there's no function, patch it with a ud2a (BUG) */
25748 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25749- else if (opfunc == _paravirt_nop)
25750+ else if (opfunc == (void *)_paravirt_nop)
25751 /* If the operation is a nop, then nop the callsite */
25752 ret = paravirt_patch_nop();
25753
25754 /* identity functions just return their single argument */
25755- else if (opfunc == _paravirt_ident_32)
25756+ else if (opfunc == (void *)_paravirt_ident_32)
25757 ret = paravirt_patch_ident_32(insnbuf, len);
25758- else if (opfunc == _paravirt_ident_64)
25759+ else if (opfunc == (void *)_paravirt_ident_64)
25760 ret = paravirt_patch_ident_64(insnbuf, len);
25761+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25762+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25763+ ret = paravirt_patch_ident_64(insnbuf, len);
25764+#endif
25765
25766 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25767 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25768@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25769 if (insn_len > len || start == NULL)
25770 insn_len = len;
25771 else
25772- memcpy(insnbuf, start, insn_len);
25773+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25774
25775 return insn_len;
25776 }
25777@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25778 return this_cpu_read(paravirt_lazy_mode);
25779 }
25780
25781-struct pv_info pv_info = {
25782+struct pv_info pv_info __read_only = {
25783 .name = "bare hardware",
25784 .paravirt_enabled = 0,
25785 .kernel_rpl = 0,
25786@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25787 #endif
25788 };
25789
25790-struct pv_init_ops pv_init_ops = {
25791+struct pv_init_ops pv_init_ops __read_only = {
25792 .patch = native_patch,
25793 };
25794
25795-struct pv_time_ops pv_time_ops = {
25796+struct pv_time_ops pv_time_ops __read_only = {
25797 .sched_clock = native_sched_clock,
25798 .steal_clock = native_steal_clock,
25799 };
25800
25801-__visible struct pv_irq_ops pv_irq_ops = {
25802+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25803 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25804 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25805 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25806@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25807 #endif
25808 };
25809
25810-__visible struct pv_cpu_ops pv_cpu_ops = {
25811+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25812 .cpuid = native_cpuid,
25813 .get_debugreg = native_get_debugreg,
25814 .set_debugreg = native_set_debugreg,
25815@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25816 .end_context_switch = paravirt_nop,
25817 };
25818
25819-struct pv_apic_ops pv_apic_ops = {
25820+struct pv_apic_ops pv_apic_ops __read_only= {
25821 #ifdef CONFIG_X86_LOCAL_APIC
25822 .startup_ipi_hook = paravirt_nop,
25823 #endif
25824 };
25825
25826-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25827+#ifdef CONFIG_X86_32
25828+#ifdef CONFIG_X86_PAE
25829+/* 64-bit pagetable entries */
25830+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25831+#else
25832 /* 32-bit pagetable entries */
25833 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25834+#endif
25835 #else
25836 /* 64-bit pagetable entries */
25837 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25838 #endif
25839
25840-struct pv_mmu_ops pv_mmu_ops = {
25841+struct pv_mmu_ops pv_mmu_ops __read_only = {
25842
25843 .read_cr2 = native_read_cr2,
25844 .write_cr2 = native_write_cr2,
25845@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25846 .make_pud = PTE_IDENT,
25847
25848 .set_pgd = native_set_pgd,
25849+ .set_pgd_batched = native_set_pgd_batched,
25850 #endif
25851 #endif /* PAGETABLE_LEVELS >= 3 */
25852
25853@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25854 },
25855
25856 .set_fixmap = native_set_fixmap,
25857+
25858+#ifdef CONFIG_PAX_KERNEXEC
25859+ .pax_open_kernel = native_pax_open_kernel,
25860+ .pax_close_kernel = native_pax_close_kernel,
25861+#endif
25862+
25863 };
25864
25865 EXPORT_SYMBOL_GPL(pv_time_ops);
25866diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25867index 299d493..2ccb0ee 100644
25868--- a/arch/x86/kernel/pci-calgary_64.c
25869+++ b/arch/x86/kernel/pci-calgary_64.c
25870@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25871 tce_space = be64_to_cpu(readq(target));
25872 tce_space = tce_space & TAR_SW_BITS;
25873
25874- tce_space = tce_space & (~specified_table_size);
25875+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25876 info->tce_space = (u64 *)__va(tce_space);
25877 }
25878 }
25879diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25880index 35ccf75..7a15747 100644
25881--- a/arch/x86/kernel/pci-iommu_table.c
25882+++ b/arch/x86/kernel/pci-iommu_table.c
25883@@ -2,7 +2,7 @@
25884 #include <asm/iommu_table.h>
25885 #include <linux/string.h>
25886 #include <linux/kallsyms.h>
25887-
25888+#include <linux/sched.h>
25889
25890 #define DEBUG 1
25891
25892diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25893index 6c483ba..d10ce2f 100644
25894--- a/arch/x86/kernel/pci-swiotlb.c
25895+++ b/arch/x86/kernel/pci-swiotlb.c
25896@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25897 void *vaddr, dma_addr_t dma_addr,
25898 struct dma_attrs *attrs)
25899 {
25900- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25901+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25902 }
25903
25904 static struct dma_map_ops swiotlb_dma_ops = {
25905diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25906index ca7f0d5..8996469 100644
25907--- a/arch/x86/kernel/preempt.S
25908+++ b/arch/x86/kernel/preempt.S
25909@@ -3,12 +3,14 @@
25910 #include <asm/dwarf2.h>
25911 #include <asm/asm.h>
25912 #include <asm/calling.h>
25913+#include <asm/alternative-asm.h>
25914
25915 ENTRY(___preempt_schedule)
25916 CFI_STARTPROC
25917 SAVE_ALL
25918 call preempt_schedule
25919 RESTORE_ALL
25920+ pax_force_retaddr
25921 ret
25922 CFI_ENDPROC
25923
25924@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25925 SAVE_ALL
25926 call preempt_schedule_context
25927 RESTORE_ALL
25928+ pax_force_retaddr
25929 ret
25930 CFI_ENDPROC
25931
25932diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25933index 3fb8d95..254dc51 100644
25934--- a/arch/x86/kernel/process.c
25935+++ b/arch/x86/kernel/process.c
25936@@ -36,7 +36,8 @@
25937 * section. Since TSS's are completely CPU-local, we want them
25938 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25939 */
25940-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25941+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25942+EXPORT_SYMBOL(init_tss);
25943
25944 #ifdef CONFIG_X86_64
25945 static DEFINE_PER_CPU(unsigned char, is_idle);
25946@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25947 task_xstate_cachep =
25948 kmem_cache_create("task_xstate", xstate_size,
25949 __alignof__(union thread_xstate),
25950- SLAB_PANIC | SLAB_NOTRACK, NULL);
25951+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25952 }
25953
25954 /*
25955@@ -105,7 +106,7 @@ void exit_thread(void)
25956 unsigned long *bp = t->io_bitmap_ptr;
25957
25958 if (bp) {
25959- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25960+ struct tss_struct *tss = init_tss + get_cpu();
25961
25962 t->io_bitmap_ptr = NULL;
25963 clear_thread_flag(TIF_IO_BITMAP);
25964@@ -125,6 +126,9 @@ void flush_thread(void)
25965 {
25966 struct task_struct *tsk = current;
25967
25968+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25969+ loadsegment(gs, 0);
25970+#endif
25971 flush_ptrace_hw_breakpoint(tsk);
25972 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25973 drop_init_fpu(tsk);
25974@@ -271,7 +275,7 @@ static void __exit_idle(void)
25975 void exit_idle(void)
25976 {
25977 /* idle loop has pid 0 */
25978- if (current->pid)
25979+ if (task_pid_nr(current))
25980 return;
25981 __exit_idle();
25982 }
25983@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25984 return ret;
25985 }
25986 #endif
25987-void stop_this_cpu(void *dummy)
25988+__noreturn void stop_this_cpu(void *dummy)
25989 {
25990 local_irq_disable();
25991 /*
25992@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25993 }
25994 early_param("idle", idle_setup);
25995
25996-unsigned long arch_align_stack(unsigned long sp)
25997+#ifdef CONFIG_PAX_RANDKSTACK
25998+void pax_randomize_kstack(struct pt_regs *regs)
25999 {
26000- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26001- sp -= get_random_int() % 8192;
26002- return sp & ~0xf;
26003-}
26004+ struct thread_struct *thread = &current->thread;
26005+ unsigned long time;
26006
26007-unsigned long arch_randomize_brk(struct mm_struct *mm)
26008-{
26009- unsigned long range_end = mm->brk + 0x02000000;
26010- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26011-}
26012+ if (!randomize_va_space)
26013+ return;
26014+
26015+ if (v8086_mode(regs))
26016+ return;
26017
26018+ rdtscl(time);
26019+
26020+ /* P4 seems to return a 0 LSB, ignore it */
26021+#ifdef CONFIG_MPENTIUM4
26022+ time &= 0x3EUL;
26023+ time <<= 2;
26024+#elif defined(CONFIG_X86_64)
26025+ time &= 0xFUL;
26026+ time <<= 4;
26027+#else
26028+ time &= 0x1FUL;
26029+ time <<= 3;
26030+#endif
26031+
26032+ thread->sp0 ^= time;
26033+ load_sp0(init_tss + smp_processor_id(), thread);
26034+
26035+#ifdef CONFIG_X86_64
26036+ this_cpu_write(kernel_stack, thread->sp0);
26037+#endif
26038+}
26039+#endif
26040diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26041index 0de43e9..056b840 100644
26042--- a/arch/x86/kernel/process_32.c
26043+++ b/arch/x86/kernel/process_32.c
26044@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26045 unsigned long thread_saved_pc(struct task_struct *tsk)
26046 {
26047 return ((unsigned long *)tsk->thread.sp)[3];
26048+//XXX return tsk->thread.eip;
26049 }
26050
26051 void __show_regs(struct pt_regs *regs, int all)
26052@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26053 unsigned long sp;
26054 unsigned short ss, gs;
26055
26056- if (user_mode_vm(regs)) {
26057+ if (user_mode(regs)) {
26058 sp = regs->sp;
26059 ss = regs->ss & 0xffff;
26060- gs = get_user_gs(regs);
26061 } else {
26062 sp = kernel_stack_pointer(regs);
26063 savesegment(ss, ss);
26064- savesegment(gs, gs);
26065 }
26066+ gs = get_user_gs(regs);
26067
26068 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26069 (u16)regs->cs, regs->ip, regs->flags,
26070- smp_processor_id());
26071+ raw_smp_processor_id());
26072 print_symbol("EIP is at %s\n", regs->ip);
26073
26074 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26075@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26076 int copy_thread(unsigned long clone_flags, unsigned long sp,
26077 unsigned long arg, struct task_struct *p)
26078 {
26079- struct pt_regs *childregs = task_pt_regs(p);
26080+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26081 struct task_struct *tsk;
26082 int err;
26083
26084 p->thread.sp = (unsigned long) childregs;
26085 p->thread.sp0 = (unsigned long) (childregs+1);
26086+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26087
26088 if (unlikely(p->flags & PF_KTHREAD)) {
26089 /* kernel thread */
26090 memset(childregs, 0, sizeof(struct pt_regs));
26091 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26092- task_user_gs(p) = __KERNEL_STACK_CANARY;
26093- childregs->ds = __USER_DS;
26094- childregs->es = __USER_DS;
26095+ savesegment(gs, childregs->gs);
26096+ childregs->ds = __KERNEL_DS;
26097+ childregs->es = __KERNEL_DS;
26098 childregs->fs = __KERNEL_PERCPU;
26099 childregs->bx = sp; /* function */
26100 childregs->bp = arg;
26101@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26102 struct thread_struct *prev = &prev_p->thread,
26103 *next = &next_p->thread;
26104 int cpu = smp_processor_id();
26105- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26106+ struct tss_struct *tss = init_tss + cpu;
26107 fpu_switch_t fpu;
26108
26109 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26110@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26111 */
26112 lazy_save_gs(prev->gs);
26113
26114+#ifdef CONFIG_PAX_MEMORY_UDEREF
26115+ __set_fs(task_thread_info(next_p)->addr_limit);
26116+#endif
26117+
26118 /*
26119 * Load the per-thread Thread-Local Storage descriptor.
26120 */
26121@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26122 */
26123 arch_end_context_switch(next_p);
26124
26125+ this_cpu_write(current_task, next_p);
26126+ this_cpu_write(current_tinfo, &next_p->tinfo);
26127+
26128 /*
26129 * Restore %gs if needed (which is common)
26130 */
26131@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26132
26133 switch_fpu_finish(next_p, fpu);
26134
26135- this_cpu_write(current_task, next_p);
26136-
26137 return prev_p;
26138 }
26139
26140@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26141 } while (count++ < 16);
26142 return 0;
26143 }
26144-
26145diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26146index 9c0280f..5bbb1c0 100644
26147--- a/arch/x86/kernel/process_64.c
26148+++ b/arch/x86/kernel/process_64.c
26149@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26150 struct pt_regs *childregs;
26151 struct task_struct *me = current;
26152
26153- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26154+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26155 childregs = task_pt_regs(p);
26156 p->thread.sp = (unsigned long) childregs;
26157 p->thread.usersp = me->thread.usersp;
26158+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26159 set_tsk_thread_flag(p, TIF_FORK);
26160 p->thread.fpu_counter = 0;
26161 p->thread.io_bitmap_ptr = NULL;
26162@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26163 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26164 savesegment(es, p->thread.es);
26165 savesegment(ds, p->thread.ds);
26166+ savesegment(ss, p->thread.ss);
26167+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26168 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26169
26170 if (unlikely(p->flags & PF_KTHREAD)) {
26171@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26172 struct thread_struct *prev = &prev_p->thread;
26173 struct thread_struct *next = &next_p->thread;
26174 int cpu = smp_processor_id();
26175- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26176+ struct tss_struct *tss = init_tss + cpu;
26177 unsigned fsindex, gsindex;
26178 fpu_switch_t fpu;
26179
26180@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26181 if (unlikely(next->ds | prev->ds))
26182 loadsegment(ds, next->ds);
26183
26184+ savesegment(ss, prev->ss);
26185+ if (unlikely(next->ss != prev->ss))
26186+ loadsegment(ss, next->ss);
26187
26188 /* We must save %fs and %gs before load_TLS() because
26189 * %fs and %gs may be cleared by load_TLS().
26190@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26191 prev->usersp = this_cpu_read(old_rsp);
26192 this_cpu_write(old_rsp, next->usersp);
26193 this_cpu_write(current_task, next_p);
26194+ this_cpu_write(current_tinfo, &next_p->tinfo);
26195
26196 /*
26197 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26198@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26199 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26200 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26201
26202- this_cpu_write(kernel_stack,
26203- (unsigned long)task_stack_page(next_p) +
26204- THREAD_SIZE - KERNEL_STACK_OFFSET);
26205+ this_cpu_write(kernel_stack, next->sp0);
26206
26207 /*
26208 * Now maybe reload the debug registers and handle I/O bitmaps
26209@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26210 if (!p || p == current || p->state == TASK_RUNNING)
26211 return 0;
26212 stack = (unsigned long)task_stack_page(p);
26213- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26214+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26215 return 0;
26216 fp = *(u64 *)(p->thread.sp);
26217 do {
26218- if (fp < (unsigned long)stack ||
26219- fp >= (unsigned long)stack+THREAD_SIZE)
26220+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26221 return 0;
26222 ip = *(u64 *)(fp+8);
26223 if (!in_sched_functions(ip))
26224diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26225index 7461f50..1334029 100644
26226--- a/arch/x86/kernel/ptrace.c
26227+++ b/arch/x86/kernel/ptrace.c
26228@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26229 {
26230 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26231 unsigned long sp = (unsigned long)&regs->sp;
26232- struct thread_info *tinfo;
26233
26234- if (context == (sp & ~(THREAD_SIZE - 1)))
26235+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26236 return sp;
26237
26238- tinfo = (struct thread_info *)context;
26239- if (tinfo->previous_esp)
26240- return tinfo->previous_esp;
26241+ sp = *(unsigned long *)context;
26242+ if (sp)
26243+ return sp;
26244
26245 return (unsigned long)regs;
26246 }
26247@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26248 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26249 {
26250 int i;
26251- int dr7 = 0;
26252+ unsigned long dr7 = 0;
26253 struct arch_hw_breakpoint *info;
26254
26255 for (i = 0; i < HBP_NUM; i++) {
26256@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26257 unsigned long addr, unsigned long data)
26258 {
26259 int ret;
26260- unsigned long __user *datap = (unsigned long __user *)data;
26261+ unsigned long __user *datap = (__force unsigned long __user *)data;
26262
26263 switch (request) {
26264 /* read the word at location addr in the USER area. */
26265@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26266 if ((int) addr < 0)
26267 return -EIO;
26268 ret = do_get_thread_area(child, addr,
26269- (struct user_desc __user *)data);
26270+ (__force struct user_desc __user *) data);
26271 break;
26272
26273 case PTRACE_SET_THREAD_AREA:
26274 if ((int) addr < 0)
26275 return -EIO;
26276 ret = do_set_thread_area(child, addr,
26277- (struct user_desc __user *)data, 0);
26278+ (__force struct user_desc __user *) data, 0);
26279 break;
26280 #endif
26281
26282@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26283
26284 #ifdef CONFIG_X86_64
26285
26286-static struct user_regset x86_64_regsets[] __read_mostly = {
26287+static user_regset_no_const x86_64_regsets[] __read_only = {
26288 [REGSET_GENERAL] = {
26289 .core_note_type = NT_PRSTATUS,
26290 .n = sizeof(struct user_regs_struct) / sizeof(long),
26291@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26292 #endif /* CONFIG_X86_64 */
26293
26294 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26295-static struct user_regset x86_32_regsets[] __read_mostly = {
26296+static user_regset_no_const x86_32_regsets[] __read_only = {
26297 [REGSET_GENERAL] = {
26298 .core_note_type = NT_PRSTATUS,
26299 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26300@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26301 */
26302 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26303
26304-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26305+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26306 {
26307 #ifdef CONFIG_X86_64
26308 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26309@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26310 memset(info, 0, sizeof(*info));
26311 info->si_signo = SIGTRAP;
26312 info->si_code = si_code;
26313- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26314+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26315 }
26316
26317 void user_single_step_siginfo(struct task_struct *tsk,
26318@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26319 # define IS_IA32 0
26320 #endif
26321
26322+#ifdef CONFIG_GRKERNSEC_SETXID
26323+extern void gr_delayed_cred_worker(void);
26324+#endif
26325+
26326 /*
26327 * We must return the syscall number to actually look up in the table.
26328 * This can be -1L to skip running any syscall at all.
26329@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26330
26331 user_exit();
26332
26333+#ifdef CONFIG_GRKERNSEC_SETXID
26334+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26335+ gr_delayed_cred_worker();
26336+#endif
26337+
26338 /*
26339 * If we stepped into a sysenter/syscall insn, it trapped in
26340 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26341@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26342 */
26343 user_exit();
26344
26345+#ifdef CONFIG_GRKERNSEC_SETXID
26346+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26347+ gr_delayed_cred_worker();
26348+#endif
26349+
26350 audit_syscall_exit(regs);
26351
26352 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26353diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26354index 2f355d2..e75ed0a 100644
26355--- a/arch/x86/kernel/pvclock.c
26356+++ b/arch/x86/kernel/pvclock.c
26357@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26358 reset_hung_task_detector();
26359 }
26360
26361-static atomic64_t last_value = ATOMIC64_INIT(0);
26362+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26363
26364 void pvclock_resume(void)
26365 {
26366- atomic64_set(&last_value, 0);
26367+ atomic64_set_unchecked(&last_value, 0);
26368 }
26369
26370 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26371@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26372 * updating at the same time, and one of them could be slightly behind,
26373 * making the assumption that last_value always go forward fail to hold.
26374 */
26375- last = atomic64_read(&last_value);
26376+ last = atomic64_read_unchecked(&last_value);
26377 do {
26378 if (ret < last)
26379 return last;
26380- last = atomic64_cmpxchg(&last_value, last, ret);
26381+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26382 } while (unlikely(last != ret));
26383
26384 return ret;
26385diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26386index c752cb4..866c432 100644
26387--- a/arch/x86/kernel/reboot.c
26388+++ b/arch/x86/kernel/reboot.c
26389@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26390
26391 void __noreturn machine_real_restart(unsigned int type)
26392 {
26393+
26394+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26395+ struct desc_struct *gdt;
26396+#endif
26397+
26398 local_irq_disable();
26399
26400 /*
26401@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26402
26403 /* Jump to the identity-mapped low memory code */
26404 #ifdef CONFIG_X86_32
26405- asm volatile("jmpl *%0" : :
26406+
26407+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26408+ gdt = get_cpu_gdt_table(smp_processor_id());
26409+ pax_open_kernel();
26410+#ifdef CONFIG_PAX_MEMORY_UDEREF
26411+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26412+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26413+ loadsegment(ds, __KERNEL_DS);
26414+ loadsegment(es, __KERNEL_DS);
26415+ loadsegment(ss, __KERNEL_DS);
26416+#endif
26417+#ifdef CONFIG_PAX_KERNEXEC
26418+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26419+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26420+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26421+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26422+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26423+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26424+#endif
26425+ pax_close_kernel();
26426+#endif
26427+
26428+ asm volatile("ljmpl *%0" : :
26429 "rm" (real_mode_header->machine_real_restart_asm),
26430 "a" (type));
26431 #else
26432@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26433 * try to force a triple fault and then cycle between hitting the keyboard
26434 * controller and doing that
26435 */
26436-static void native_machine_emergency_restart(void)
26437+static void __noreturn native_machine_emergency_restart(void)
26438 {
26439 int i;
26440 int attempt = 0;
26441@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26442 #endif
26443 }
26444
26445-static void __machine_emergency_restart(int emergency)
26446+static void __noreturn __machine_emergency_restart(int emergency)
26447 {
26448 reboot_emergency = emergency;
26449 machine_ops.emergency_restart();
26450 }
26451
26452-static void native_machine_restart(char *__unused)
26453+static void __noreturn native_machine_restart(char *__unused)
26454 {
26455 pr_notice("machine restart\n");
26456
26457@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26458 __machine_emergency_restart(0);
26459 }
26460
26461-static void native_machine_halt(void)
26462+static void __noreturn native_machine_halt(void)
26463 {
26464 /* Stop other cpus and apics */
26465 machine_shutdown();
26466@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26467 stop_this_cpu(NULL);
26468 }
26469
26470-static void native_machine_power_off(void)
26471+static void __noreturn native_machine_power_off(void)
26472 {
26473 if (pm_power_off) {
26474 if (!reboot_force)
26475@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26476 }
26477 /* A fallback in case there is no PM info available */
26478 tboot_shutdown(TB_SHUTDOWN_HALT);
26479+ unreachable();
26480 }
26481
26482-struct machine_ops machine_ops = {
26483+struct machine_ops machine_ops __read_only = {
26484 .power_off = native_machine_power_off,
26485 .shutdown = native_machine_shutdown,
26486 .emergency_restart = native_machine_emergency_restart,
26487diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26488index c8e41e9..64049ef 100644
26489--- a/arch/x86/kernel/reboot_fixups_32.c
26490+++ b/arch/x86/kernel/reboot_fixups_32.c
26491@@ -57,7 +57,7 @@ struct device_fixup {
26492 unsigned int vendor;
26493 unsigned int device;
26494 void (*reboot_fixup)(struct pci_dev *);
26495-};
26496+} __do_const;
26497
26498 /*
26499 * PCI ids solely used for fixups_table go here
26500diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26501index 3fd2c69..a444264 100644
26502--- a/arch/x86/kernel/relocate_kernel_64.S
26503+++ b/arch/x86/kernel/relocate_kernel_64.S
26504@@ -96,8 +96,7 @@ relocate_kernel:
26505
26506 /* jump to identity mapped page */
26507 addq $(identity_mapped - relocate_kernel), %r8
26508- pushq %r8
26509- ret
26510+ jmp *%r8
26511
26512 identity_mapped:
26513 /* set return address to 0 if not preserving context */
26514diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26515index ce72964..be8aea7 100644
26516--- a/arch/x86/kernel/setup.c
26517+++ b/arch/x86/kernel/setup.c
26518@@ -110,6 +110,7 @@
26519 #include <asm/mce.h>
26520 #include <asm/alternative.h>
26521 #include <asm/prom.h>
26522+#include <asm/boot.h>
26523
26524 /*
26525 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26526@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26527 #endif
26528
26529
26530-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26531-__visible unsigned long mmu_cr4_features;
26532+#ifdef CONFIG_X86_64
26533+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26534+#elif defined(CONFIG_X86_PAE)
26535+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26536 #else
26537-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26538+__visible unsigned long mmu_cr4_features __read_only;
26539 #endif
26540
26541+void set_in_cr4(unsigned long mask)
26542+{
26543+ unsigned long cr4 = read_cr4();
26544+
26545+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26546+ return;
26547+
26548+ pax_open_kernel();
26549+ mmu_cr4_features |= mask;
26550+ pax_close_kernel();
26551+
26552+ if (trampoline_cr4_features)
26553+ *trampoline_cr4_features = mmu_cr4_features;
26554+ cr4 |= mask;
26555+ write_cr4(cr4);
26556+}
26557+EXPORT_SYMBOL(set_in_cr4);
26558+
26559+void clear_in_cr4(unsigned long mask)
26560+{
26561+ unsigned long cr4 = read_cr4();
26562+
26563+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26564+ return;
26565+
26566+ pax_open_kernel();
26567+ mmu_cr4_features &= ~mask;
26568+ pax_close_kernel();
26569+
26570+ if (trampoline_cr4_features)
26571+ *trampoline_cr4_features = mmu_cr4_features;
26572+ cr4 &= ~mask;
26573+ write_cr4(cr4);
26574+}
26575+EXPORT_SYMBOL(clear_in_cr4);
26576+
26577 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26578 int bootloader_type, bootloader_version;
26579
26580@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26581 * area (640->1Mb) as ram even though it is not.
26582 * take them out.
26583 */
26584- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26585+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26586
26587 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26588 }
26589@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26590 /* called before trim_bios_range() to spare extra sanitize */
26591 static void __init e820_add_kernel_range(void)
26592 {
26593- u64 start = __pa_symbol(_text);
26594+ u64 start = __pa_symbol(ktla_ktva(_text));
26595 u64 size = __pa_symbol(_end) - start;
26596
26597 /*
26598@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26599
26600 void __init setup_arch(char **cmdline_p)
26601 {
26602+#ifdef CONFIG_X86_32
26603+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26604+#else
26605 memblock_reserve(__pa_symbol(_text),
26606 (unsigned long)__bss_stop - (unsigned long)_text);
26607+#endif
26608
26609 early_reserve_initrd();
26610
26611@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26612
26613 if (!boot_params.hdr.root_flags)
26614 root_mountflags &= ~MS_RDONLY;
26615- init_mm.start_code = (unsigned long) _text;
26616- init_mm.end_code = (unsigned long) _etext;
26617+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26618+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26619 init_mm.end_data = (unsigned long) _edata;
26620 init_mm.brk = _brk_end;
26621
26622- code_resource.start = __pa_symbol(_text);
26623- code_resource.end = __pa_symbol(_etext)-1;
26624- data_resource.start = __pa_symbol(_etext);
26625+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26626+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26627+ data_resource.start = __pa_symbol(_sdata);
26628 data_resource.end = __pa_symbol(_edata)-1;
26629 bss_resource.start = __pa_symbol(__bss_start);
26630 bss_resource.end = __pa_symbol(__bss_stop)-1;
26631diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26632index 5cdff03..80fa283 100644
26633--- a/arch/x86/kernel/setup_percpu.c
26634+++ b/arch/x86/kernel/setup_percpu.c
26635@@ -21,19 +21,17 @@
26636 #include <asm/cpu.h>
26637 #include <asm/stackprotector.h>
26638
26639-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26640+#ifdef CONFIG_SMP
26641+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26642 EXPORT_PER_CPU_SYMBOL(cpu_number);
26643+#endif
26644
26645-#ifdef CONFIG_X86_64
26646 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26647-#else
26648-#define BOOT_PERCPU_OFFSET 0
26649-#endif
26650
26651 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26652 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26653
26654-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26655+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26656 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26657 };
26658 EXPORT_SYMBOL(__per_cpu_offset);
26659@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26660 {
26661 #ifdef CONFIG_NEED_MULTIPLE_NODES
26662 pg_data_t *last = NULL;
26663- unsigned int cpu;
26664+ int cpu;
26665
26666 for_each_possible_cpu(cpu) {
26667 int node = early_cpu_to_node(cpu);
26668@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26669 {
26670 #ifdef CONFIG_X86_32
26671 struct desc_struct gdt;
26672+ unsigned long base = per_cpu_offset(cpu);
26673
26674- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26675- 0x2 | DESCTYPE_S, 0x8);
26676- gdt.s = 1;
26677+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26678+ 0x83 | DESCTYPE_S, 0xC);
26679 write_gdt_entry(get_cpu_gdt_table(cpu),
26680 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26681 #endif
26682@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26683 /* alrighty, percpu areas up and running */
26684 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26685 for_each_possible_cpu(cpu) {
26686+#ifdef CONFIG_CC_STACKPROTECTOR
26687+#ifdef CONFIG_X86_32
26688+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26689+#endif
26690+#endif
26691 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26692 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26693 per_cpu(cpu_number, cpu) = cpu;
26694@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26695 */
26696 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26697 #endif
26698+#ifdef CONFIG_CC_STACKPROTECTOR
26699+#ifdef CONFIG_X86_32
26700+ if (!cpu)
26701+ per_cpu(stack_canary.canary, cpu) = canary;
26702+#endif
26703+#endif
26704 /*
26705 * Up to this point, the boot CPU has been using .init.data
26706 * area. Reload any changed state for the boot CPU.
26707diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26708index 9e5de68..16c53cb 100644
26709--- a/arch/x86/kernel/signal.c
26710+++ b/arch/x86/kernel/signal.c
26711@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26712 * Align the stack pointer according to the i386 ABI,
26713 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26714 */
26715- sp = ((sp + 4) & -16ul) - 4;
26716+ sp = ((sp - 12) & -16ul) - 4;
26717 #else /* !CONFIG_X86_32 */
26718 sp = round_down(sp, 16) - 8;
26719 #endif
26720@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26721 }
26722
26723 if (current->mm->context.vdso)
26724- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26725+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26726 else
26727- restorer = &frame->retcode;
26728+ restorer = (void __user *)&frame->retcode;
26729 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26730 restorer = ksig->ka.sa.sa_restorer;
26731
26732@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26733 * reasons and because gdb uses it as a signature to notice
26734 * signal handler stack frames.
26735 */
26736- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26737+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26738
26739 if (err)
26740 return -EFAULT;
26741@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26742 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26743
26744 /* Set up to return from userspace. */
26745- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26746+ if (current->mm->context.vdso)
26747+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26748+ else
26749+ restorer = (void __user *)&frame->retcode;
26750 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26751 restorer = ksig->ka.sa.sa_restorer;
26752 put_user_ex(restorer, &frame->pretcode);
26753@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26754 * reasons and because gdb uses it as a signature to notice
26755 * signal handler stack frames.
26756 */
26757- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26758+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26759 } put_user_catch(err);
26760
26761 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26762@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26763 {
26764 int usig = signr_convert(ksig->sig);
26765 sigset_t *set = sigmask_to_save();
26766- compat_sigset_t *cset = (compat_sigset_t *) set;
26767+ sigset_t sigcopy;
26768+ compat_sigset_t *cset;
26769+
26770+ sigcopy = *set;
26771+
26772+ cset = (compat_sigset_t *) &sigcopy;
26773
26774 /* Set up the stack frame */
26775 if (is_ia32_frame()) {
26776@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26777 } else if (is_x32_frame()) {
26778 return x32_setup_rt_frame(ksig, cset, regs);
26779 } else {
26780- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26781+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26782 }
26783 }
26784
26785diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26786index 7c3a5a6..f0a8961 100644
26787--- a/arch/x86/kernel/smp.c
26788+++ b/arch/x86/kernel/smp.c
26789@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26790
26791 __setup("nonmi_ipi", nonmi_ipi_setup);
26792
26793-struct smp_ops smp_ops = {
26794+struct smp_ops smp_ops __read_only = {
26795 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26796 .smp_prepare_cpus = native_smp_prepare_cpus,
26797 .smp_cpus_done = native_smp_cpus_done,
26798diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26799index a32da80..30c97f1 100644
26800--- a/arch/x86/kernel/smpboot.c
26801+++ b/arch/x86/kernel/smpboot.c
26802@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26803
26804 enable_start_cpu0 = 0;
26805
26806-#ifdef CONFIG_X86_32
26807- /* switch away from the initial page table */
26808- load_cr3(swapper_pg_dir);
26809- __flush_tlb_all();
26810-#endif
26811-
26812 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26813 barrier();
26814+
26815+ /* switch away from the initial page table */
26816+#ifdef CONFIG_PAX_PER_CPU_PGD
26817+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26818+ __flush_tlb_all();
26819+#elif defined(CONFIG_X86_32)
26820+ load_cr3(swapper_pg_dir);
26821+ __flush_tlb_all();
26822+#endif
26823+
26824 /*
26825 * Check TSC synchronization with the BP:
26826 */
26827@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26828 alternatives_enable_smp();
26829
26830 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26831- (THREAD_SIZE + task_stack_page(idle))) - 1);
26832+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26833 per_cpu(current_task, cpu) = idle;
26834+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26835
26836 #ifdef CONFIG_X86_32
26837 /* Stack for startup_32 can be just as for start_secondary onwards */
26838@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26839 #else
26840 clear_tsk_thread_flag(idle, TIF_FORK);
26841 initial_gs = per_cpu_offset(cpu);
26842- per_cpu(kernel_stack, cpu) =
26843- (unsigned long)task_stack_page(idle) -
26844- KERNEL_STACK_OFFSET + THREAD_SIZE;
26845+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26846 #endif
26847+
26848+ pax_open_kernel();
26849 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26850+ pax_close_kernel();
26851+
26852 initial_code = (unsigned long)start_secondary;
26853 stack_start = idle->thread.sp;
26854
26855@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26856 /* the FPU context is blank, nobody can own it */
26857 __cpu_disable_lazy_restore(cpu);
26858
26859+#ifdef CONFIG_PAX_PER_CPU_PGD
26860+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26861+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26862+ KERNEL_PGD_PTRS);
26863+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26864+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26865+ KERNEL_PGD_PTRS);
26866+#endif
26867+
26868 err = do_boot_cpu(apicid, cpu, tidle);
26869 if (err) {
26870 pr_debug("do_boot_cpu failed %d\n", err);
26871diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26872index 9b4d51d..5d28b58 100644
26873--- a/arch/x86/kernel/step.c
26874+++ b/arch/x86/kernel/step.c
26875@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26876 struct desc_struct *desc;
26877 unsigned long base;
26878
26879- seg &= ~7UL;
26880+ seg >>= 3;
26881
26882 mutex_lock(&child->mm->context.lock);
26883- if (unlikely((seg >> 3) >= child->mm->context.size))
26884+ if (unlikely(seg >= child->mm->context.size))
26885 addr = -1L; /* bogus selector, access would fault */
26886 else {
26887 desc = child->mm->context.ldt + seg;
26888@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26889 addr += base;
26890 }
26891 mutex_unlock(&child->mm->context.lock);
26892- }
26893+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26894+ addr = ktla_ktva(addr);
26895
26896 return addr;
26897 }
26898@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26899 unsigned char opcode[15];
26900 unsigned long addr = convert_ip_to_linear(child, regs);
26901
26902+ if (addr == -EINVAL)
26903+ return 0;
26904+
26905 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26906 for (i = 0; i < copied; i++) {
26907 switch (opcode[i]) {
26908diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26909new file mode 100644
26910index 0000000..5877189
26911--- /dev/null
26912+++ b/arch/x86/kernel/sys_i386_32.c
26913@@ -0,0 +1,189 @@
26914+/*
26915+ * This file contains various random system calls that
26916+ * have a non-standard calling sequence on the Linux/i386
26917+ * platform.
26918+ */
26919+
26920+#include <linux/errno.h>
26921+#include <linux/sched.h>
26922+#include <linux/mm.h>
26923+#include <linux/fs.h>
26924+#include <linux/smp.h>
26925+#include <linux/sem.h>
26926+#include <linux/msg.h>
26927+#include <linux/shm.h>
26928+#include <linux/stat.h>
26929+#include <linux/syscalls.h>
26930+#include <linux/mman.h>
26931+#include <linux/file.h>
26932+#include <linux/utsname.h>
26933+#include <linux/ipc.h>
26934+#include <linux/elf.h>
26935+
26936+#include <linux/uaccess.h>
26937+#include <linux/unistd.h>
26938+
26939+#include <asm/syscalls.h>
26940+
26941+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26942+{
26943+ unsigned long pax_task_size = TASK_SIZE;
26944+
26945+#ifdef CONFIG_PAX_SEGMEXEC
26946+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26947+ pax_task_size = SEGMEXEC_TASK_SIZE;
26948+#endif
26949+
26950+ if (flags & MAP_FIXED)
26951+ if (len > pax_task_size || addr > pax_task_size - len)
26952+ return -EINVAL;
26953+
26954+ return 0;
26955+}
26956+
26957+/*
26958+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26959+ */
26960+static unsigned long get_align_mask(void)
26961+{
26962+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26963+ return 0;
26964+
26965+ if (!(current->flags & PF_RANDOMIZE))
26966+ return 0;
26967+
26968+ return va_align.mask;
26969+}
26970+
26971+unsigned long
26972+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26973+ unsigned long len, unsigned long pgoff, unsigned long flags)
26974+{
26975+ struct mm_struct *mm = current->mm;
26976+ struct vm_area_struct *vma;
26977+ unsigned long pax_task_size = TASK_SIZE;
26978+ struct vm_unmapped_area_info info;
26979+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26980+
26981+#ifdef CONFIG_PAX_SEGMEXEC
26982+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26983+ pax_task_size = SEGMEXEC_TASK_SIZE;
26984+#endif
26985+
26986+ pax_task_size -= PAGE_SIZE;
26987+
26988+ if (len > pax_task_size)
26989+ return -ENOMEM;
26990+
26991+ if (flags & MAP_FIXED)
26992+ return addr;
26993+
26994+#ifdef CONFIG_PAX_RANDMMAP
26995+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26996+#endif
26997+
26998+ if (addr) {
26999+ addr = PAGE_ALIGN(addr);
27000+ if (pax_task_size - len >= addr) {
27001+ vma = find_vma(mm, addr);
27002+ if (check_heap_stack_gap(vma, addr, len, offset))
27003+ return addr;
27004+ }
27005+ }
27006+
27007+ info.flags = 0;
27008+ info.length = len;
27009+ info.align_mask = filp ? get_align_mask() : 0;
27010+ info.align_offset = pgoff << PAGE_SHIFT;
27011+ info.threadstack_offset = offset;
27012+
27013+#ifdef CONFIG_PAX_PAGEEXEC
27014+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27015+ info.low_limit = 0x00110000UL;
27016+ info.high_limit = mm->start_code;
27017+
27018+#ifdef CONFIG_PAX_RANDMMAP
27019+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27020+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27021+#endif
27022+
27023+ if (info.low_limit < info.high_limit) {
27024+ addr = vm_unmapped_area(&info);
27025+ if (!IS_ERR_VALUE(addr))
27026+ return addr;
27027+ }
27028+ } else
27029+#endif
27030+
27031+ info.low_limit = mm->mmap_base;
27032+ info.high_limit = pax_task_size;
27033+
27034+ return vm_unmapped_area(&info);
27035+}
27036+
27037+unsigned long
27038+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27039+ const unsigned long len, const unsigned long pgoff,
27040+ const unsigned long flags)
27041+{
27042+ struct vm_area_struct *vma;
27043+ struct mm_struct *mm = current->mm;
27044+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27045+ struct vm_unmapped_area_info info;
27046+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27047+
27048+#ifdef CONFIG_PAX_SEGMEXEC
27049+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27050+ pax_task_size = SEGMEXEC_TASK_SIZE;
27051+#endif
27052+
27053+ pax_task_size -= PAGE_SIZE;
27054+
27055+ /* requested length too big for entire address space */
27056+ if (len > pax_task_size)
27057+ return -ENOMEM;
27058+
27059+ if (flags & MAP_FIXED)
27060+ return addr;
27061+
27062+#ifdef CONFIG_PAX_PAGEEXEC
27063+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27064+ goto bottomup;
27065+#endif
27066+
27067+#ifdef CONFIG_PAX_RANDMMAP
27068+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27069+#endif
27070+
27071+ /* requesting a specific address */
27072+ if (addr) {
27073+ addr = PAGE_ALIGN(addr);
27074+ if (pax_task_size - len >= addr) {
27075+ vma = find_vma(mm, addr);
27076+ if (check_heap_stack_gap(vma, addr, len, offset))
27077+ return addr;
27078+ }
27079+ }
27080+
27081+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27082+ info.length = len;
27083+ info.low_limit = PAGE_SIZE;
27084+ info.high_limit = mm->mmap_base;
27085+ info.align_mask = filp ? get_align_mask() : 0;
27086+ info.align_offset = pgoff << PAGE_SHIFT;
27087+ info.threadstack_offset = offset;
27088+
27089+ addr = vm_unmapped_area(&info);
27090+ if (!(addr & ~PAGE_MASK))
27091+ return addr;
27092+ VM_BUG_ON(addr != -ENOMEM);
27093+
27094+bottomup:
27095+ /*
27096+ * A failed mmap() very likely causes application failure,
27097+ * so fall back to the bottom-up function here. This scenario
27098+ * can happen with large stack limits and large mmap()
27099+ * allocations.
27100+ */
27101+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27102+}
27103diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27104index 30277e2..5664a29 100644
27105--- a/arch/x86/kernel/sys_x86_64.c
27106+++ b/arch/x86/kernel/sys_x86_64.c
27107@@ -81,8 +81,8 @@ out:
27108 return error;
27109 }
27110
27111-static void find_start_end(unsigned long flags, unsigned long *begin,
27112- unsigned long *end)
27113+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27114+ unsigned long *begin, unsigned long *end)
27115 {
27116 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27117 unsigned long new_begin;
27118@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27119 *begin = new_begin;
27120 }
27121 } else {
27122- *begin = current->mm->mmap_legacy_base;
27123+ *begin = mm->mmap_legacy_base;
27124 *end = TASK_SIZE;
27125 }
27126 }
27127@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27128 struct vm_area_struct *vma;
27129 struct vm_unmapped_area_info info;
27130 unsigned long begin, end;
27131+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27132
27133 if (flags & MAP_FIXED)
27134 return addr;
27135
27136- find_start_end(flags, &begin, &end);
27137+ find_start_end(mm, flags, &begin, &end);
27138
27139 if (len > end)
27140 return -ENOMEM;
27141
27142+#ifdef CONFIG_PAX_RANDMMAP
27143+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27144+#endif
27145+
27146 if (addr) {
27147 addr = PAGE_ALIGN(addr);
27148 vma = find_vma(mm, addr);
27149- if (end - len >= addr &&
27150- (!vma || addr + len <= vma->vm_start))
27151+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27152 return addr;
27153 }
27154
27155@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27156 info.high_limit = end;
27157 info.align_mask = filp ? get_align_mask() : 0;
27158 info.align_offset = pgoff << PAGE_SHIFT;
27159+ info.threadstack_offset = offset;
27160 return vm_unmapped_area(&info);
27161 }
27162
27163@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27164 struct mm_struct *mm = current->mm;
27165 unsigned long addr = addr0;
27166 struct vm_unmapped_area_info info;
27167+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27168
27169 /* requested length too big for entire address space */
27170 if (len > TASK_SIZE)
27171@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27172 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27173 goto bottomup;
27174
27175+#ifdef CONFIG_PAX_RANDMMAP
27176+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27177+#endif
27178+
27179 /* requesting a specific address */
27180 if (addr) {
27181 addr = PAGE_ALIGN(addr);
27182 vma = find_vma(mm, addr);
27183- if (TASK_SIZE - len >= addr &&
27184- (!vma || addr + len <= vma->vm_start))
27185+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27186 return addr;
27187 }
27188
27189@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27190 info.high_limit = mm->mmap_base;
27191 info.align_mask = filp ? get_align_mask() : 0;
27192 info.align_offset = pgoff << PAGE_SHIFT;
27193+ info.threadstack_offset = offset;
27194 addr = vm_unmapped_area(&info);
27195 if (!(addr & ~PAGE_MASK))
27196 return addr;
27197diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27198index 91a4496..bb87552 100644
27199--- a/arch/x86/kernel/tboot.c
27200+++ b/arch/x86/kernel/tboot.c
27201@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27202
27203 void tboot_shutdown(u32 shutdown_type)
27204 {
27205- void (*shutdown)(void);
27206+ void (* __noreturn shutdown)(void);
27207
27208 if (!tboot_enabled())
27209 return;
27210@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27211
27212 switch_to_tboot_pt();
27213
27214- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27215+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27216 shutdown();
27217
27218 /* should not reach here */
27219@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27220 return -ENODEV;
27221 }
27222
27223-static atomic_t ap_wfs_count;
27224+static atomic_unchecked_t ap_wfs_count;
27225
27226 static int tboot_wait_for_aps(int num_aps)
27227 {
27228@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27229 {
27230 switch (action) {
27231 case CPU_DYING:
27232- atomic_inc(&ap_wfs_count);
27233+ atomic_inc_unchecked(&ap_wfs_count);
27234 if (num_online_cpus() == 1)
27235- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27236+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27237 return NOTIFY_BAD;
27238 break;
27239 }
27240@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27241
27242 tboot_create_trampoline();
27243
27244- atomic_set(&ap_wfs_count, 0);
27245+ atomic_set_unchecked(&ap_wfs_count, 0);
27246 register_hotcpu_notifier(&tboot_cpu_notifier);
27247
27248 #ifdef CONFIG_DEBUG_FS
27249diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27250index 24d3c91..d06b473 100644
27251--- a/arch/x86/kernel/time.c
27252+++ b/arch/x86/kernel/time.c
27253@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27254 {
27255 unsigned long pc = instruction_pointer(regs);
27256
27257- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27258+ if (!user_mode(regs) && in_lock_functions(pc)) {
27259 #ifdef CONFIG_FRAME_POINTER
27260- return *(unsigned long *)(regs->bp + sizeof(long));
27261+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27262 #else
27263 unsigned long *sp =
27264 (unsigned long *)kernel_stack_pointer(regs);
27265@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27266 * or above a saved flags. Eflags has bits 22-31 zero,
27267 * kernel addresses don't.
27268 */
27269+
27270+#ifdef CONFIG_PAX_KERNEXEC
27271+ return ktla_ktva(sp[0]);
27272+#else
27273 if (sp[0] >> 22)
27274 return sp[0];
27275 if (sp[1] >> 22)
27276 return sp[1];
27277 #endif
27278+
27279+#endif
27280 }
27281 return pc;
27282 }
27283diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27284index f7fec09..9991981 100644
27285--- a/arch/x86/kernel/tls.c
27286+++ b/arch/x86/kernel/tls.c
27287@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27288 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27289 return -EINVAL;
27290
27291+#ifdef CONFIG_PAX_SEGMEXEC
27292+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27293+ return -EINVAL;
27294+#endif
27295+
27296 set_tls_desc(p, idx, &info, 1);
27297
27298 return 0;
27299@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27300
27301 if (kbuf)
27302 info = kbuf;
27303- else if (__copy_from_user(infobuf, ubuf, count))
27304+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27305 return -EFAULT;
27306 else
27307 info = infobuf;
27308diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27309index 1c113db..287b42e 100644
27310--- a/arch/x86/kernel/tracepoint.c
27311+++ b/arch/x86/kernel/tracepoint.c
27312@@ -9,11 +9,11 @@
27313 #include <linux/atomic.h>
27314
27315 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27316-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27317+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27318 (unsigned long) trace_idt_table };
27319
27320 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27321-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27322+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27323
27324 static int trace_irq_vector_refcount;
27325 static DEFINE_MUTEX(irq_vector_mutex);
27326diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27327index 57409f6..e2c17e1 100644
27328--- a/arch/x86/kernel/traps.c
27329+++ b/arch/x86/kernel/traps.c
27330@@ -66,7 +66,7 @@
27331 #include <asm/proto.h>
27332
27333 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27334-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27335+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27336 #else
27337 #include <asm/processor-flags.h>
27338 #include <asm/setup.h>
27339@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27340 #endif
27341
27342 /* Must be page-aligned because the real IDT is used in a fixmap. */
27343-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27344+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27345
27346 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27347 EXPORT_SYMBOL_GPL(used_vectors);
27348@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27349 }
27350
27351 static int __kprobes
27352-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27353+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27354 struct pt_regs *regs, long error_code)
27355 {
27356 #ifdef CONFIG_X86_32
27357- if (regs->flags & X86_VM_MASK) {
27358+ if (v8086_mode(regs)) {
27359 /*
27360 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27361 * On nmi (interrupt 2), do_trap should not be called.
27362@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27363 return -1;
27364 }
27365 #endif
27366- if (!user_mode(regs)) {
27367+ if (!user_mode_novm(regs)) {
27368 if (!fixup_exception(regs)) {
27369 tsk->thread.error_code = error_code;
27370 tsk->thread.trap_nr = trapnr;
27371+
27372+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27373+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27374+ str = "PAX: suspicious stack segment fault";
27375+#endif
27376+
27377 die(str, regs, error_code);
27378 }
27379+
27380+#ifdef CONFIG_PAX_REFCOUNT
27381+ if (trapnr == X86_TRAP_OF)
27382+ pax_report_refcount_overflow(regs);
27383+#endif
27384+
27385 return 0;
27386 }
27387
27388@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27389 }
27390
27391 static void __kprobes
27392-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27393+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27394 long error_code, siginfo_t *info)
27395 {
27396 struct task_struct *tsk = current;
27397@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27398 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27399 printk_ratelimit()) {
27400 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27401- tsk->comm, tsk->pid, str,
27402+ tsk->comm, task_pid_nr(tsk), str,
27403 regs->ip, regs->sp, error_code);
27404 print_vma_addr(" in ", regs->ip);
27405 pr_cont("\n");
27406@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27407 conditional_sti(regs);
27408
27409 #ifdef CONFIG_X86_32
27410- if (regs->flags & X86_VM_MASK) {
27411+ if (v8086_mode(regs)) {
27412 local_irq_enable();
27413 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27414 goto exit;
27415@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27416 #endif
27417
27418 tsk = current;
27419- if (!user_mode(regs)) {
27420+ if (!user_mode_novm(regs)) {
27421 if (fixup_exception(regs))
27422 goto exit;
27423
27424 tsk->thread.error_code = error_code;
27425 tsk->thread.trap_nr = X86_TRAP_GP;
27426 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27427- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27428+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27429+
27430+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27431+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27432+ die("PAX: suspicious general protection fault", regs, error_code);
27433+ else
27434+#endif
27435+
27436 die("general protection fault", regs, error_code);
27437+ }
27438 goto exit;
27439 }
27440
27441+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27442+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27443+ struct mm_struct *mm = tsk->mm;
27444+ unsigned long limit;
27445+
27446+ down_write(&mm->mmap_sem);
27447+ limit = mm->context.user_cs_limit;
27448+ if (limit < TASK_SIZE) {
27449+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27450+ up_write(&mm->mmap_sem);
27451+ return;
27452+ }
27453+ up_write(&mm->mmap_sem);
27454+ }
27455+#endif
27456+
27457 tsk->thread.error_code = error_code;
27458 tsk->thread.trap_nr = X86_TRAP_GP;
27459
27460@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27461 /* It's safe to allow irq's after DR6 has been saved */
27462 preempt_conditional_sti(regs);
27463
27464- if (regs->flags & X86_VM_MASK) {
27465+ if (v8086_mode(regs)) {
27466 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27467 X86_TRAP_DB);
27468 preempt_conditional_cli(regs);
27469@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27470 * We already checked v86 mode above, so we can check for kernel mode
27471 * by just checking the CPL of CS.
27472 */
27473- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27474+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27475 tsk->thread.debugreg6 &= ~DR_STEP;
27476 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27477 regs->flags &= ~X86_EFLAGS_TF;
27478@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27479 return;
27480 conditional_sti(regs);
27481
27482- if (!user_mode_vm(regs))
27483+ if (!user_mode(regs))
27484 {
27485 if (!fixup_exception(regs)) {
27486 task->thread.error_code = error_code;
27487diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27488index cfbe99f..a6e8fa7 100644
27489--- a/arch/x86/kernel/tsc.c
27490+++ b/arch/x86/kernel/tsc.c
27491@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27492 */
27493 smp_wmb();
27494
27495- ACCESS_ONCE(c2n->head) = data;
27496+ ACCESS_ONCE_RW(c2n->head) = data;
27497 }
27498
27499 /*
27500diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27501index 2ed8459..7cf329f 100644
27502--- a/arch/x86/kernel/uprobes.c
27503+++ b/arch/x86/kernel/uprobes.c
27504@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27505 int ret = NOTIFY_DONE;
27506
27507 /* We are only interested in userspace traps */
27508- if (regs && !user_mode_vm(regs))
27509+ if (regs && !user_mode(regs))
27510 return NOTIFY_DONE;
27511
27512 switch (val) {
27513@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27514
27515 if (ncopied != rasize) {
27516 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27517- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27518+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27519
27520 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27521 }
27522diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27523index b9242ba..50c5edd 100644
27524--- a/arch/x86/kernel/verify_cpu.S
27525+++ b/arch/x86/kernel/verify_cpu.S
27526@@ -20,6 +20,7 @@
27527 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27528 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27529 * arch/x86/kernel/head_32.S: processor startup
27530+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27531 *
27532 * verify_cpu, returns the status of longmode and SSE in register %eax.
27533 * 0: Success 1: Failure
27534diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27535index e8edcf5..27f9344 100644
27536--- a/arch/x86/kernel/vm86_32.c
27537+++ b/arch/x86/kernel/vm86_32.c
27538@@ -44,6 +44,7 @@
27539 #include <linux/ptrace.h>
27540 #include <linux/audit.h>
27541 #include <linux/stddef.h>
27542+#include <linux/grsecurity.h>
27543
27544 #include <asm/uaccess.h>
27545 #include <asm/io.h>
27546@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27547 do_exit(SIGSEGV);
27548 }
27549
27550- tss = &per_cpu(init_tss, get_cpu());
27551+ tss = init_tss + get_cpu();
27552 current->thread.sp0 = current->thread.saved_sp0;
27553 current->thread.sysenter_cs = __KERNEL_CS;
27554 load_sp0(tss, &current->thread);
27555@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27556
27557 if (tsk->thread.saved_sp0)
27558 return -EPERM;
27559+
27560+#ifdef CONFIG_GRKERNSEC_VM86
27561+ if (!capable(CAP_SYS_RAWIO)) {
27562+ gr_handle_vm86();
27563+ return -EPERM;
27564+ }
27565+#endif
27566+
27567 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27568 offsetof(struct kernel_vm86_struct, vm86plus) -
27569 sizeof(info.regs));
27570@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27571 int tmp;
27572 struct vm86plus_struct __user *v86;
27573
27574+#ifdef CONFIG_GRKERNSEC_VM86
27575+ if (!capable(CAP_SYS_RAWIO)) {
27576+ gr_handle_vm86();
27577+ return -EPERM;
27578+ }
27579+#endif
27580+
27581 tsk = current;
27582 switch (cmd) {
27583 case VM86_REQUEST_IRQ:
27584@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27585 tsk->thread.saved_fs = info->regs32->fs;
27586 tsk->thread.saved_gs = get_user_gs(info->regs32);
27587
27588- tss = &per_cpu(init_tss, get_cpu());
27589+ tss = init_tss + get_cpu();
27590 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27591 if (cpu_has_sep)
27592 tsk->thread.sysenter_cs = 0;
27593@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27594 goto cannot_handle;
27595 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27596 goto cannot_handle;
27597- intr_ptr = (unsigned long __user *) (i << 2);
27598+ intr_ptr = (__force unsigned long __user *) (i << 2);
27599 if (get_user(segoffs, intr_ptr))
27600 goto cannot_handle;
27601 if ((segoffs >> 16) == BIOSSEG)
27602diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27603index da6b35a..977e9cf 100644
27604--- a/arch/x86/kernel/vmlinux.lds.S
27605+++ b/arch/x86/kernel/vmlinux.lds.S
27606@@ -26,6 +26,13 @@
27607 #include <asm/page_types.h>
27608 #include <asm/cache.h>
27609 #include <asm/boot.h>
27610+#include <asm/segment.h>
27611+
27612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27613+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27614+#else
27615+#define __KERNEL_TEXT_OFFSET 0
27616+#endif
27617
27618 #undef i386 /* in case the preprocessor is a 32bit one */
27619
27620@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27621
27622 PHDRS {
27623 text PT_LOAD FLAGS(5); /* R_E */
27624+#ifdef CONFIG_X86_32
27625+ module PT_LOAD FLAGS(5); /* R_E */
27626+#endif
27627+#ifdef CONFIG_XEN
27628+ rodata PT_LOAD FLAGS(5); /* R_E */
27629+#else
27630+ rodata PT_LOAD FLAGS(4); /* R__ */
27631+#endif
27632 data PT_LOAD FLAGS(6); /* RW_ */
27633-#ifdef CONFIG_X86_64
27634+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27635 #ifdef CONFIG_SMP
27636 percpu PT_LOAD FLAGS(6); /* RW_ */
27637 #endif
27638+ text.init PT_LOAD FLAGS(5); /* R_E */
27639+ text.exit PT_LOAD FLAGS(5); /* R_E */
27640 init PT_LOAD FLAGS(7); /* RWE */
27641-#endif
27642 note PT_NOTE FLAGS(0); /* ___ */
27643 }
27644
27645 SECTIONS
27646 {
27647 #ifdef CONFIG_X86_32
27648- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27649- phys_startup_32 = startup_32 - LOAD_OFFSET;
27650+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27651 #else
27652- . = __START_KERNEL;
27653- phys_startup_64 = startup_64 - LOAD_OFFSET;
27654+ . = __START_KERNEL;
27655 #endif
27656
27657 /* Text and read-only data */
27658- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27659- _text = .;
27660+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27661 /* bootstrapping code */
27662+#ifdef CONFIG_X86_32
27663+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27664+#else
27665+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27666+#endif
27667+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27668+ _text = .;
27669 HEAD_TEXT
27670 . = ALIGN(8);
27671 _stext = .;
27672@@ -104,13 +124,47 @@ SECTIONS
27673 IRQENTRY_TEXT
27674 *(.fixup)
27675 *(.gnu.warning)
27676- /* End of text section */
27677- _etext = .;
27678 } :text = 0x9090
27679
27680- NOTES :text :note
27681+ . += __KERNEL_TEXT_OFFSET;
27682
27683- EXCEPTION_TABLE(16) :text = 0x9090
27684+#ifdef CONFIG_X86_32
27685+ . = ALIGN(PAGE_SIZE);
27686+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27687+
27688+#ifdef CONFIG_PAX_KERNEXEC
27689+ MODULES_EXEC_VADDR = .;
27690+ BYTE(0)
27691+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27692+ . = ALIGN(HPAGE_SIZE) - 1;
27693+ MODULES_EXEC_END = .;
27694+#endif
27695+
27696+ } :module
27697+#endif
27698+
27699+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27700+ /* End of text section */
27701+ BYTE(0)
27702+ _etext = . - __KERNEL_TEXT_OFFSET;
27703+ }
27704+
27705+#ifdef CONFIG_X86_32
27706+ . = ALIGN(PAGE_SIZE);
27707+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27708+ . = ALIGN(PAGE_SIZE);
27709+ *(.empty_zero_page)
27710+ *(.initial_pg_fixmap)
27711+ *(.initial_pg_pmd)
27712+ *(.initial_page_table)
27713+ *(.swapper_pg_dir)
27714+ } :rodata
27715+#endif
27716+
27717+ . = ALIGN(PAGE_SIZE);
27718+ NOTES :rodata :note
27719+
27720+ EXCEPTION_TABLE(16) :rodata
27721
27722 #if defined(CONFIG_DEBUG_RODATA)
27723 /* .text should occupy whole number of pages */
27724@@ -122,16 +176,20 @@ SECTIONS
27725
27726 /* Data */
27727 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27728+
27729+#ifdef CONFIG_PAX_KERNEXEC
27730+ . = ALIGN(HPAGE_SIZE);
27731+#else
27732+ . = ALIGN(PAGE_SIZE);
27733+#endif
27734+
27735 /* Start of data section */
27736 _sdata = .;
27737
27738 /* init_task */
27739 INIT_TASK_DATA(THREAD_SIZE)
27740
27741-#ifdef CONFIG_X86_32
27742- /* 32 bit has nosave before _edata */
27743 NOSAVE_DATA
27744-#endif
27745
27746 PAGE_ALIGNED_DATA(PAGE_SIZE)
27747
27748@@ -172,12 +230,19 @@ SECTIONS
27749 #endif /* CONFIG_X86_64 */
27750
27751 /* Init code and data - will be freed after init */
27752- . = ALIGN(PAGE_SIZE);
27753 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27754+ BYTE(0)
27755+
27756+#ifdef CONFIG_PAX_KERNEXEC
27757+ . = ALIGN(HPAGE_SIZE);
27758+#else
27759+ . = ALIGN(PAGE_SIZE);
27760+#endif
27761+
27762 __init_begin = .; /* paired with __init_end */
27763- }
27764+ } :init.begin
27765
27766-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27767+#ifdef CONFIG_SMP
27768 /*
27769 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27770 * output PHDR, so the next output section - .init.text - should
27771@@ -186,12 +251,27 @@ SECTIONS
27772 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27773 #endif
27774
27775- INIT_TEXT_SECTION(PAGE_SIZE)
27776-#ifdef CONFIG_X86_64
27777- :init
27778-#endif
27779+ . = ALIGN(PAGE_SIZE);
27780+ init_begin = .;
27781+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27782+ VMLINUX_SYMBOL(_sinittext) = .;
27783+ INIT_TEXT
27784+ VMLINUX_SYMBOL(_einittext) = .;
27785+ . = ALIGN(PAGE_SIZE);
27786+ } :text.init
27787
27788- INIT_DATA_SECTION(16)
27789+ /*
27790+ * .exit.text is discard at runtime, not link time, to deal with
27791+ * references from .altinstructions and .eh_frame
27792+ */
27793+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27794+ EXIT_TEXT
27795+ . = ALIGN(16);
27796+ } :text.exit
27797+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27798+
27799+ . = ALIGN(PAGE_SIZE);
27800+ INIT_DATA_SECTION(16) :init
27801
27802 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27803 __x86_cpu_dev_start = .;
27804@@ -262,19 +342,12 @@ SECTIONS
27805 }
27806
27807 . = ALIGN(8);
27808- /*
27809- * .exit.text is discard at runtime, not link time, to deal with
27810- * references from .altinstructions and .eh_frame
27811- */
27812- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27813- EXIT_TEXT
27814- }
27815
27816 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27817 EXIT_DATA
27818 }
27819
27820-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27821+#ifndef CONFIG_SMP
27822 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27823 #endif
27824
27825@@ -293,16 +366,10 @@ SECTIONS
27826 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27827 __smp_locks = .;
27828 *(.smp_locks)
27829- . = ALIGN(PAGE_SIZE);
27830 __smp_locks_end = .;
27831+ . = ALIGN(PAGE_SIZE);
27832 }
27833
27834-#ifdef CONFIG_X86_64
27835- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27836- NOSAVE_DATA
27837- }
27838-#endif
27839-
27840 /* BSS */
27841 . = ALIGN(PAGE_SIZE);
27842 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27843@@ -318,6 +385,7 @@ SECTIONS
27844 __brk_base = .;
27845 . += 64 * 1024; /* 64k alignment slop space */
27846 *(.brk_reservation) /* areas brk users have reserved */
27847+ . = ALIGN(HPAGE_SIZE);
27848 __brk_limit = .;
27849 }
27850
27851@@ -344,13 +412,12 @@ SECTIONS
27852 * for the boot processor.
27853 */
27854 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27855-INIT_PER_CPU(gdt_page);
27856 INIT_PER_CPU(irq_stack_union);
27857
27858 /*
27859 * Build-time check on the image size:
27860 */
27861-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27862+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27863 "kernel image bigger than KERNEL_IMAGE_SIZE");
27864
27865 #ifdef CONFIG_SMP
27866diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27867index 1f96f93..d5c8f7a 100644
27868--- a/arch/x86/kernel/vsyscall_64.c
27869+++ b/arch/x86/kernel/vsyscall_64.c
27870@@ -56,15 +56,13 @@
27871 DEFINE_VVAR(int, vgetcpu_mode);
27872 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27873
27874-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27875+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27876
27877 static int __init vsyscall_setup(char *str)
27878 {
27879 if (str) {
27880 if (!strcmp("emulate", str))
27881 vsyscall_mode = EMULATE;
27882- else if (!strcmp("native", str))
27883- vsyscall_mode = NATIVE;
27884 else if (!strcmp("none", str))
27885 vsyscall_mode = NONE;
27886 else
27887@@ -323,8 +321,7 @@ do_ret:
27888 return true;
27889
27890 sigsegv:
27891- force_sig(SIGSEGV, current);
27892- return true;
27893+ do_group_exit(SIGKILL);
27894 }
27895
27896 /*
27897@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27898 extern char __vvar_page;
27899 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27900
27901- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27902- vsyscall_mode == NATIVE
27903- ? PAGE_KERNEL_VSYSCALL
27904- : PAGE_KERNEL_VVAR);
27905+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27906 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27907 (unsigned long)VSYSCALL_START);
27908
27909diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27910index 04068192..4d75aa6 100644
27911--- a/arch/x86/kernel/x8664_ksyms_64.c
27912+++ b/arch/x86/kernel/x8664_ksyms_64.c
27913@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27914 EXPORT_SYMBOL(copy_user_generic_unrolled);
27915 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27916 EXPORT_SYMBOL(__copy_user_nocache);
27917-EXPORT_SYMBOL(_copy_from_user);
27918-EXPORT_SYMBOL(_copy_to_user);
27919
27920 EXPORT_SYMBOL(copy_page);
27921 EXPORT_SYMBOL(clear_page);
27922@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27923 EXPORT_SYMBOL(___preempt_schedule_context);
27924 #endif
27925 #endif
27926+
27927+#ifdef CONFIG_PAX_PER_CPU_PGD
27928+EXPORT_SYMBOL(cpu_pgd);
27929+#endif
27930diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27931index e48b674..a451dd9 100644
27932--- a/arch/x86/kernel/x86_init.c
27933+++ b/arch/x86/kernel/x86_init.c
27934@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27935 static void default_nmi_init(void) { };
27936 static int default_i8042_detect(void) { return 1; };
27937
27938-struct x86_platform_ops x86_platform = {
27939+struct x86_platform_ops x86_platform __read_only = {
27940 .calibrate_tsc = native_calibrate_tsc,
27941 .get_wallclock = mach_get_cmos_time,
27942 .set_wallclock = mach_set_rtc_mmss,
27943@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27944 EXPORT_SYMBOL_GPL(x86_platform);
27945
27946 #if defined(CONFIG_PCI_MSI)
27947-struct x86_msi_ops x86_msi = {
27948+struct x86_msi_ops x86_msi __read_only = {
27949 .setup_msi_irqs = native_setup_msi_irqs,
27950 .compose_msi_msg = native_compose_msi_msg,
27951 .teardown_msi_irq = native_teardown_msi_irq,
27952@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27953 }
27954 #endif
27955
27956-struct x86_io_apic_ops x86_io_apic_ops = {
27957+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27958 .init = native_io_apic_init_mappings,
27959 .read = native_io_apic_read,
27960 .write = native_io_apic_write,
27961diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27962index a4b451c..8dfe1ad 100644
27963--- a/arch/x86/kernel/xsave.c
27964+++ b/arch/x86/kernel/xsave.c
27965@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27966
27967 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27968 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27969- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27970+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27971
27972 if (!use_xsave())
27973 return err;
27974
27975- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27976+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27977
27978 /*
27979 * Read the xstate_bv which we copied (directly from the cpu or
27980 * from the state in task struct) to the user buffers.
27981 */
27982- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27983+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27984
27985 /*
27986 * For legacy compatible, we always set FP/SSE bits in the bit
27987@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27988 */
27989 xstate_bv |= XSTATE_FPSSE;
27990
27991- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27992+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27993
27994 return err;
27995 }
27996@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27997 {
27998 int err;
27999
28000+ buf = (struct xsave_struct __user *)____m(buf);
28001 if (use_xsave())
28002 err = xsave_user(buf);
28003 else if (use_fxsr())
28004@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28005 */
28006 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28007 {
28008+ buf = (void __user *)____m(buf);
28009 if (use_xsave()) {
28010 if ((unsigned long)buf % 64 || fx_only) {
28011 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28012diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28013index c697625..a032162 100644
28014--- a/arch/x86/kvm/cpuid.c
28015+++ b/arch/x86/kvm/cpuid.c
28016@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28017 struct kvm_cpuid2 *cpuid,
28018 struct kvm_cpuid_entry2 __user *entries)
28019 {
28020- int r;
28021+ int r, i;
28022
28023 r = -E2BIG;
28024 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28025 goto out;
28026 r = -EFAULT;
28027- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28028- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28029+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28030 goto out;
28031+ for (i = 0; i < cpuid->nent; ++i) {
28032+ struct kvm_cpuid_entry2 cpuid_entry;
28033+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28034+ goto out;
28035+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28036+ }
28037 vcpu->arch.cpuid_nent = cpuid->nent;
28038 kvm_apic_set_version(vcpu);
28039 kvm_x86_ops->cpuid_update(vcpu);
28040@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28041 struct kvm_cpuid2 *cpuid,
28042 struct kvm_cpuid_entry2 __user *entries)
28043 {
28044- int r;
28045+ int r, i;
28046
28047 r = -E2BIG;
28048 if (cpuid->nent < vcpu->arch.cpuid_nent)
28049 goto out;
28050 r = -EFAULT;
28051- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28052- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28053+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28054 goto out;
28055+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28056+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28057+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28058+ goto out;
28059+ }
28060 return 0;
28061
28062 out:
28063diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28064index 9736529..ab4f54c 100644
28065--- a/arch/x86/kvm/lapic.c
28066+++ b/arch/x86/kvm/lapic.c
28067@@ -55,7 +55,7 @@
28068 #define APIC_BUS_CYCLE_NS 1
28069
28070 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28071-#define apic_debug(fmt, arg...)
28072+#define apic_debug(fmt, arg...) do {} while (0)
28073
28074 #define APIC_LVT_NUM 6
28075 /* 14 is the version for Xeon and Pentium 8.4.8*/
28076diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28077index cba218a..1cc1bed 100644
28078--- a/arch/x86/kvm/paging_tmpl.h
28079+++ b/arch/x86/kvm/paging_tmpl.h
28080@@ -331,7 +331,7 @@ retry_walk:
28081 if (unlikely(kvm_is_error_hva(host_addr)))
28082 goto error;
28083
28084- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28085+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28086 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28087 goto error;
28088 walker->ptep_user[walker->level - 1] = ptep_user;
28089diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28090index 2de1bc0..22251ee 100644
28091--- a/arch/x86/kvm/svm.c
28092+++ b/arch/x86/kvm/svm.c
28093@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28094 int cpu = raw_smp_processor_id();
28095
28096 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28097+
28098+ pax_open_kernel();
28099 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28100+ pax_close_kernel();
28101+
28102 load_TR_desc();
28103 }
28104
28105@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28106 #endif
28107 #endif
28108
28109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28110+ __set_fs(current_thread_info()->addr_limit);
28111+#endif
28112+
28113 reload_tss(vcpu);
28114
28115 local_irq_disable();
28116diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28117index 3927528..fc19971 100644
28118--- a/arch/x86/kvm/vmx.c
28119+++ b/arch/x86/kvm/vmx.c
28120@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28121 #endif
28122 }
28123
28124-static void vmcs_clear_bits(unsigned long field, u32 mask)
28125+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28126 {
28127 vmcs_writel(field, vmcs_readl(field) & ~mask);
28128 }
28129
28130-static void vmcs_set_bits(unsigned long field, u32 mask)
28131+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28132 {
28133 vmcs_writel(field, vmcs_readl(field) | mask);
28134 }
28135@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28136 struct desc_struct *descs;
28137
28138 descs = (void *)gdt->address;
28139+
28140+ pax_open_kernel();
28141 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28142+ pax_close_kernel();
28143+
28144 load_TR_desc();
28145 }
28146
28147@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28148 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28149 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28150
28151+#ifdef CONFIG_PAX_PER_CPU_PGD
28152+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28153+#endif
28154+
28155 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28156 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28157 vmx->loaded_vmcs->cpu = cpu;
28158@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28159 * reads and returns guest's timestamp counter "register"
28160 * guest_tsc = host_tsc + tsc_offset -- 21.3
28161 */
28162-static u64 guest_read_tsc(void)
28163+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28164 {
28165 u64 host_tsc, tsc_offset;
28166
28167@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28168 if (!cpu_has_vmx_flexpriority())
28169 flexpriority_enabled = 0;
28170
28171- if (!cpu_has_vmx_tpr_shadow())
28172- kvm_x86_ops->update_cr8_intercept = NULL;
28173+ if (!cpu_has_vmx_tpr_shadow()) {
28174+ pax_open_kernel();
28175+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28176+ pax_close_kernel();
28177+ }
28178
28179 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28180 kvm_disable_largepages();
28181@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28182 if (!cpu_has_vmx_apicv())
28183 enable_apicv = 0;
28184
28185+ pax_open_kernel();
28186 if (enable_apicv)
28187- kvm_x86_ops->update_cr8_intercept = NULL;
28188+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28189 else {
28190- kvm_x86_ops->hwapic_irr_update = NULL;
28191- kvm_x86_ops->deliver_posted_interrupt = NULL;
28192- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28193+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28194+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28195+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28196 }
28197+ pax_close_kernel();
28198
28199 if (nested)
28200 nested_vmx_setup_ctls_msrs();
28201@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28202
28203 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28204 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28205+
28206+#ifndef CONFIG_PAX_PER_CPU_PGD
28207 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28208+#endif
28209
28210 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28211 #ifdef CONFIG_X86_64
28212@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28213 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28214 vmx->host_idt_base = dt.address;
28215
28216- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28217+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28218
28219 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28220 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28221@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28222 "jmp 2f \n\t"
28223 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28224 "2: "
28225+
28226+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28227+ "ljmp %[cs],$3f\n\t"
28228+ "3: "
28229+#endif
28230+
28231 /* Save guest registers, load host registers, keep flags */
28232 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28233 "pop %0 \n\t"
28234@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28235 #endif
28236 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28237 [wordsize]"i"(sizeof(ulong))
28238+
28239+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28240+ ,[cs]"i"(__KERNEL_CS)
28241+#endif
28242+
28243 : "cc", "memory"
28244 #ifdef CONFIG_X86_64
28245 , "rax", "rbx", "rdi", "rsi"
28246@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28247 if (debugctlmsr)
28248 update_debugctlmsr(debugctlmsr);
28249
28250-#ifndef CONFIG_X86_64
28251+#ifdef CONFIG_X86_32
28252 /*
28253 * The sysexit path does not restore ds/es, so we must set them to
28254 * a reasonable value ourselves.
28255@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28256 * may be executed in interrupt context, which saves and restore segments
28257 * around it, nullifying its effect.
28258 */
28259- loadsegment(ds, __USER_DS);
28260- loadsegment(es, __USER_DS);
28261+ loadsegment(ds, __KERNEL_DS);
28262+ loadsegment(es, __KERNEL_DS);
28263+ loadsegment(ss, __KERNEL_DS);
28264+
28265+#ifdef CONFIG_PAX_KERNEXEC
28266+ loadsegment(fs, __KERNEL_PERCPU);
28267+#endif
28268+
28269+#ifdef CONFIG_PAX_MEMORY_UDEREF
28270+ __set_fs(current_thread_info()->addr_limit);
28271+#endif
28272+
28273 #endif
28274
28275 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28276diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28277index 2b85784..ad70e19 100644
28278--- a/arch/x86/kvm/x86.c
28279+++ b/arch/x86/kvm/x86.c
28280@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28281 {
28282 struct kvm *kvm = vcpu->kvm;
28283 int lm = is_long_mode(vcpu);
28284- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28285- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28286+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28287+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28288 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28289 : kvm->arch.xen_hvm_config.blob_size_32;
28290 u32 page_num = data & ~PAGE_MASK;
28291@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28292 if (n < msr_list.nmsrs)
28293 goto out;
28294 r = -EFAULT;
28295+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28296+ goto out;
28297 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28298 num_msrs_to_save * sizeof(u32)))
28299 goto out;
28300@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28301 };
28302 #endif
28303
28304-int kvm_arch_init(void *opaque)
28305+int kvm_arch_init(const void *opaque)
28306 {
28307 int r;
28308 struct kvm_x86_ops *ops = opaque;
28309diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28310index ad1fb5f..fe30b66 100644
28311--- a/arch/x86/lguest/boot.c
28312+++ b/arch/x86/lguest/boot.c
28313@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28314 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28315 * Launcher to reboot us.
28316 */
28317-static void lguest_restart(char *reason)
28318+static __noreturn void lguest_restart(char *reason)
28319 {
28320 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28321+ BUG();
28322 }
28323
28324 /*G:050
28325diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28326index 00933d5..3a64af9 100644
28327--- a/arch/x86/lib/atomic64_386_32.S
28328+++ b/arch/x86/lib/atomic64_386_32.S
28329@@ -48,6 +48,10 @@ BEGIN(read)
28330 movl (v), %eax
28331 movl 4(v), %edx
28332 RET_ENDP
28333+BEGIN(read_unchecked)
28334+ movl (v), %eax
28335+ movl 4(v), %edx
28336+RET_ENDP
28337 #undef v
28338
28339 #define v %esi
28340@@ -55,6 +59,10 @@ BEGIN(set)
28341 movl %ebx, (v)
28342 movl %ecx, 4(v)
28343 RET_ENDP
28344+BEGIN(set_unchecked)
28345+ movl %ebx, (v)
28346+ movl %ecx, 4(v)
28347+RET_ENDP
28348 #undef v
28349
28350 #define v %esi
28351@@ -70,6 +78,20 @@ RET_ENDP
28352 BEGIN(add)
28353 addl %eax, (v)
28354 adcl %edx, 4(v)
28355+
28356+#ifdef CONFIG_PAX_REFCOUNT
28357+ jno 0f
28358+ subl %eax, (v)
28359+ sbbl %edx, 4(v)
28360+ int $4
28361+0:
28362+ _ASM_EXTABLE(0b, 0b)
28363+#endif
28364+
28365+RET_ENDP
28366+BEGIN(add_unchecked)
28367+ addl %eax, (v)
28368+ adcl %edx, 4(v)
28369 RET_ENDP
28370 #undef v
28371
28372@@ -77,6 +99,24 @@ RET_ENDP
28373 BEGIN(add_return)
28374 addl (v), %eax
28375 adcl 4(v), %edx
28376+
28377+#ifdef CONFIG_PAX_REFCOUNT
28378+ into
28379+1234:
28380+ _ASM_EXTABLE(1234b, 2f)
28381+#endif
28382+
28383+ movl %eax, (v)
28384+ movl %edx, 4(v)
28385+
28386+#ifdef CONFIG_PAX_REFCOUNT
28387+2:
28388+#endif
28389+
28390+RET_ENDP
28391+BEGIN(add_return_unchecked)
28392+ addl (v), %eax
28393+ adcl 4(v), %edx
28394 movl %eax, (v)
28395 movl %edx, 4(v)
28396 RET_ENDP
28397@@ -86,6 +126,20 @@ RET_ENDP
28398 BEGIN(sub)
28399 subl %eax, (v)
28400 sbbl %edx, 4(v)
28401+
28402+#ifdef CONFIG_PAX_REFCOUNT
28403+ jno 0f
28404+ addl %eax, (v)
28405+ adcl %edx, 4(v)
28406+ int $4
28407+0:
28408+ _ASM_EXTABLE(0b, 0b)
28409+#endif
28410+
28411+RET_ENDP
28412+BEGIN(sub_unchecked)
28413+ subl %eax, (v)
28414+ sbbl %edx, 4(v)
28415 RET_ENDP
28416 #undef v
28417
28418@@ -96,6 +150,27 @@ BEGIN(sub_return)
28419 sbbl $0, %edx
28420 addl (v), %eax
28421 adcl 4(v), %edx
28422+
28423+#ifdef CONFIG_PAX_REFCOUNT
28424+ into
28425+1234:
28426+ _ASM_EXTABLE(1234b, 2f)
28427+#endif
28428+
28429+ movl %eax, (v)
28430+ movl %edx, 4(v)
28431+
28432+#ifdef CONFIG_PAX_REFCOUNT
28433+2:
28434+#endif
28435+
28436+RET_ENDP
28437+BEGIN(sub_return_unchecked)
28438+ negl %edx
28439+ negl %eax
28440+ sbbl $0, %edx
28441+ addl (v), %eax
28442+ adcl 4(v), %edx
28443 movl %eax, (v)
28444 movl %edx, 4(v)
28445 RET_ENDP
28446@@ -105,6 +180,20 @@ RET_ENDP
28447 BEGIN(inc)
28448 addl $1, (v)
28449 adcl $0, 4(v)
28450+
28451+#ifdef CONFIG_PAX_REFCOUNT
28452+ jno 0f
28453+ subl $1, (v)
28454+ sbbl $0, 4(v)
28455+ int $4
28456+0:
28457+ _ASM_EXTABLE(0b, 0b)
28458+#endif
28459+
28460+RET_ENDP
28461+BEGIN(inc_unchecked)
28462+ addl $1, (v)
28463+ adcl $0, 4(v)
28464 RET_ENDP
28465 #undef v
28466
28467@@ -114,6 +203,26 @@ BEGIN(inc_return)
28468 movl 4(v), %edx
28469 addl $1, %eax
28470 adcl $0, %edx
28471+
28472+#ifdef CONFIG_PAX_REFCOUNT
28473+ into
28474+1234:
28475+ _ASM_EXTABLE(1234b, 2f)
28476+#endif
28477+
28478+ movl %eax, (v)
28479+ movl %edx, 4(v)
28480+
28481+#ifdef CONFIG_PAX_REFCOUNT
28482+2:
28483+#endif
28484+
28485+RET_ENDP
28486+BEGIN(inc_return_unchecked)
28487+ movl (v), %eax
28488+ movl 4(v), %edx
28489+ addl $1, %eax
28490+ adcl $0, %edx
28491 movl %eax, (v)
28492 movl %edx, 4(v)
28493 RET_ENDP
28494@@ -123,6 +232,20 @@ RET_ENDP
28495 BEGIN(dec)
28496 subl $1, (v)
28497 sbbl $0, 4(v)
28498+
28499+#ifdef CONFIG_PAX_REFCOUNT
28500+ jno 0f
28501+ addl $1, (v)
28502+ adcl $0, 4(v)
28503+ int $4
28504+0:
28505+ _ASM_EXTABLE(0b, 0b)
28506+#endif
28507+
28508+RET_ENDP
28509+BEGIN(dec_unchecked)
28510+ subl $1, (v)
28511+ sbbl $0, 4(v)
28512 RET_ENDP
28513 #undef v
28514
28515@@ -132,6 +255,26 @@ BEGIN(dec_return)
28516 movl 4(v), %edx
28517 subl $1, %eax
28518 sbbl $0, %edx
28519+
28520+#ifdef CONFIG_PAX_REFCOUNT
28521+ into
28522+1234:
28523+ _ASM_EXTABLE(1234b, 2f)
28524+#endif
28525+
28526+ movl %eax, (v)
28527+ movl %edx, 4(v)
28528+
28529+#ifdef CONFIG_PAX_REFCOUNT
28530+2:
28531+#endif
28532+
28533+RET_ENDP
28534+BEGIN(dec_return_unchecked)
28535+ movl (v), %eax
28536+ movl 4(v), %edx
28537+ subl $1, %eax
28538+ sbbl $0, %edx
28539 movl %eax, (v)
28540 movl %edx, 4(v)
28541 RET_ENDP
28542@@ -143,6 +286,13 @@ BEGIN(add_unless)
28543 adcl %edx, %edi
28544 addl (v), %eax
28545 adcl 4(v), %edx
28546+
28547+#ifdef CONFIG_PAX_REFCOUNT
28548+ into
28549+1234:
28550+ _ASM_EXTABLE(1234b, 2f)
28551+#endif
28552+
28553 cmpl %eax, %ecx
28554 je 3f
28555 1:
28556@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28557 1:
28558 addl $1, %eax
28559 adcl $0, %edx
28560+
28561+#ifdef CONFIG_PAX_REFCOUNT
28562+ into
28563+1234:
28564+ _ASM_EXTABLE(1234b, 2f)
28565+#endif
28566+
28567 movl %eax, (v)
28568 movl %edx, 4(v)
28569 movl $1, %eax
28570@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28571 movl 4(v), %edx
28572 subl $1, %eax
28573 sbbl $0, %edx
28574+
28575+#ifdef CONFIG_PAX_REFCOUNT
28576+ into
28577+1234:
28578+ _ASM_EXTABLE(1234b, 1f)
28579+#endif
28580+
28581 js 1f
28582 movl %eax, (v)
28583 movl %edx, 4(v)
28584diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28585index f5cc9eb..51fa319 100644
28586--- a/arch/x86/lib/atomic64_cx8_32.S
28587+++ b/arch/x86/lib/atomic64_cx8_32.S
28588@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28589 CFI_STARTPROC
28590
28591 read64 %ecx
28592+ pax_force_retaddr
28593 ret
28594 CFI_ENDPROC
28595 ENDPROC(atomic64_read_cx8)
28596
28597+ENTRY(atomic64_read_unchecked_cx8)
28598+ CFI_STARTPROC
28599+
28600+ read64 %ecx
28601+ pax_force_retaddr
28602+ ret
28603+ CFI_ENDPROC
28604+ENDPROC(atomic64_read_unchecked_cx8)
28605+
28606 ENTRY(atomic64_set_cx8)
28607 CFI_STARTPROC
28608
28609@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28610 cmpxchg8b (%esi)
28611 jne 1b
28612
28613+ pax_force_retaddr
28614 ret
28615 CFI_ENDPROC
28616 ENDPROC(atomic64_set_cx8)
28617
28618+ENTRY(atomic64_set_unchecked_cx8)
28619+ CFI_STARTPROC
28620+
28621+1:
28622+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28623+ * are atomic on 586 and newer */
28624+ cmpxchg8b (%esi)
28625+ jne 1b
28626+
28627+ pax_force_retaddr
28628+ ret
28629+ CFI_ENDPROC
28630+ENDPROC(atomic64_set_unchecked_cx8)
28631+
28632 ENTRY(atomic64_xchg_cx8)
28633 CFI_STARTPROC
28634
28635@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28636 cmpxchg8b (%esi)
28637 jne 1b
28638
28639+ pax_force_retaddr
28640 ret
28641 CFI_ENDPROC
28642 ENDPROC(atomic64_xchg_cx8)
28643
28644-.macro addsub_return func ins insc
28645-ENTRY(atomic64_\func\()_return_cx8)
28646+.macro addsub_return func ins insc unchecked=""
28647+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28648 CFI_STARTPROC
28649 SAVE ebp
28650 SAVE ebx
28651@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28652 movl %edx, %ecx
28653 \ins\()l %esi, %ebx
28654 \insc\()l %edi, %ecx
28655+
28656+.ifb \unchecked
28657+#ifdef CONFIG_PAX_REFCOUNT
28658+ into
28659+2:
28660+ _ASM_EXTABLE(2b, 3f)
28661+#endif
28662+.endif
28663+
28664 LOCK_PREFIX
28665 cmpxchg8b (%ebp)
28666 jne 1b
28667-
28668-10:
28669 movl %ebx, %eax
28670 movl %ecx, %edx
28671+
28672+.ifb \unchecked
28673+#ifdef CONFIG_PAX_REFCOUNT
28674+3:
28675+#endif
28676+.endif
28677+
28678 RESTORE edi
28679 RESTORE esi
28680 RESTORE ebx
28681 RESTORE ebp
28682+ pax_force_retaddr
28683 ret
28684 CFI_ENDPROC
28685-ENDPROC(atomic64_\func\()_return_cx8)
28686+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28687 .endm
28688
28689 addsub_return add add adc
28690 addsub_return sub sub sbb
28691+addsub_return add add adc _unchecked
28692+addsub_return sub sub sbb _unchecked
28693
28694-.macro incdec_return func ins insc
28695-ENTRY(atomic64_\func\()_return_cx8)
28696+.macro incdec_return func ins insc unchecked=""
28697+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28698 CFI_STARTPROC
28699 SAVE ebx
28700
28701@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28702 movl %edx, %ecx
28703 \ins\()l $1, %ebx
28704 \insc\()l $0, %ecx
28705+
28706+.ifb \unchecked
28707+#ifdef CONFIG_PAX_REFCOUNT
28708+ into
28709+2:
28710+ _ASM_EXTABLE(2b, 3f)
28711+#endif
28712+.endif
28713+
28714 LOCK_PREFIX
28715 cmpxchg8b (%esi)
28716 jne 1b
28717
28718-10:
28719 movl %ebx, %eax
28720 movl %ecx, %edx
28721+
28722+.ifb \unchecked
28723+#ifdef CONFIG_PAX_REFCOUNT
28724+3:
28725+#endif
28726+.endif
28727+
28728 RESTORE ebx
28729+ pax_force_retaddr
28730 ret
28731 CFI_ENDPROC
28732-ENDPROC(atomic64_\func\()_return_cx8)
28733+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28734 .endm
28735
28736 incdec_return inc add adc
28737 incdec_return dec sub sbb
28738+incdec_return inc add adc _unchecked
28739+incdec_return dec sub sbb _unchecked
28740
28741 ENTRY(atomic64_dec_if_positive_cx8)
28742 CFI_STARTPROC
28743@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28744 movl %edx, %ecx
28745 subl $1, %ebx
28746 sbb $0, %ecx
28747+
28748+#ifdef CONFIG_PAX_REFCOUNT
28749+ into
28750+1234:
28751+ _ASM_EXTABLE(1234b, 2f)
28752+#endif
28753+
28754 js 2f
28755 LOCK_PREFIX
28756 cmpxchg8b (%esi)
28757@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28758 movl %ebx, %eax
28759 movl %ecx, %edx
28760 RESTORE ebx
28761+ pax_force_retaddr
28762 ret
28763 CFI_ENDPROC
28764 ENDPROC(atomic64_dec_if_positive_cx8)
28765@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28766 movl %edx, %ecx
28767 addl %ebp, %ebx
28768 adcl %edi, %ecx
28769+
28770+#ifdef CONFIG_PAX_REFCOUNT
28771+ into
28772+1234:
28773+ _ASM_EXTABLE(1234b, 3f)
28774+#endif
28775+
28776 LOCK_PREFIX
28777 cmpxchg8b (%esi)
28778 jne 1b
28779@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28780 CFI_ADJUST_CFA_OFFSET -8
28781 RESTORE ebx
28782 RESTORE ebp
28783+ pax_force_retaddr
28784 ret
28785 4:
28786 cmpl %edx, 4(%esp)
28787@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28788 xorl %ecx, %ecx
28789 addl $1, %ebx
28790 adcl %edx, %ecx
28791+
28792+#ifdef CONFIG_PAX_REFCOUNT
28793+ into
28794+1234:
28795+ _ASM_EXTABLE(1234b, 3f)
28796+#endif
28797+
28798 LOCK_PREFIX
28799 cmpxchg8b (%esi)
28800 jne 1b
28801@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28802 movl $1, %eax
28803 3:
28804 RESTORE ebx
28805+ pax_force_retaddr
28806 ret
28807 CFI_ENDPROC
28808 ENDPROC(atomic64_inc_not_zero_cx8)
28809diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28810index e78b8ee..7e173a8 100644
28811--- a/arch/x86/lib/checksum_32.S
28812+++ b/arch/x86/lib/checksum_32.S
28813@@ -29,7 +29,8 @@
28814 #include <asm/dwarf2.h>
28815 #include <asm/errno.h>
28816 #include <asm/asm.h>
28817-
28818+#include <asm/segment.h>
28819+
28820 /*
28821 * computes a partial checksum, e.g. for TCP/UDP fragments
28822 */
28823@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28824
28825 #define ARGBASE 16
28826 #define FP 12
28827-
28828-ENTRY(csum_partial_copy_generic)
28829+
28830+ENTRY(csum_partial_copy_generic_to_user)
28831 CFI_STARTPROC
28832+
28833+#ifdef CONFIG_PAX_MEMORY_UDEREF
28834+ pushl_cfi %gs
28835+ popl_cfi %es
28836+ jmp csum_partial_copy_generic
28837+#endif
28838+
28839+ENTRY(csum_partial_copy_generic_from_user)
28840+
28841+#ifdef CONFIG_PAX_MEMORY_UDEREF
28842+ pushl_cfi %gs
28843+ popl_cfi %ds
28844+#endif
28845+
28846+ENTRY(csum_partial_copy_generic)
28847 subl $4,%esp
28848 CFI_ADJUST_CFA_OFFSET 4
28849 pushl_cfi %edi
28850@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28851 jmp 4f
28852 SRC(1: movw (%esi), %bx )
28853 addl $2, %esi
28854-DST( movw %bx, (%edi) )
28855+DST( movw %bx, %es:(%edi) )
28856 addl $2, %edi
28857 addw %bx, %ax
28858 adcl $0, %eax
28859@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28860 SRC(1: movl (%esi), %ebx )
28861 SRC( movl 4(%esi), %edx )
28862 adcl %ebx, %eax
28863-DST( movl %ebx, (%edi) )
28864+DST( movl %ebx, %es:(%edi) )
28865 adcl %edx, %eax
28866-DST( movl %edx, 4(%edi) )
28867+DST( movl %edx, %es:4(%edi) )
28868
28869 SRC( movl 8(%esi), %ebx )
28870 SRC( movl 12(%esi), %edx )
28871 adcl %ebx, %eax
28872-DST( movl %ebx, 8(%edi) )
28873+DST( movl %ebx, %es:8(%edi) )
28874 adcl %edx, %eax
28875-DST( movl %edx, 12(%edi) )
28876+DST( movl %edx, %es:12(%edi) )
28877
28878 SRC( movl 16(%esi), %ebx )
28879 SRC( movl 20(%esi), %edx )
28880 adcl %ebx, %eax
28881-DST( movl %ebx, 16(%edi) )
28882+DST( movl %ebx, %es:16(%edi) )
28883 adcl %edx, %eax
28884-DST( movl %edx, 20(%edi) )
28885+DST( movl %edx, %es:20(%edi) )
28886
28887 SRC( movl 24(%esi), %ebx )
28888 SRC( movl 28(%esi), %edx )
28889 adcl %ebx, %eax
28890-DST( movl %ebx, 24(%edi) )
28891+DST( movl %ebx, %es:24(%edi) )
28892 adcl %edx, %eax
28893-DST( movl %edx, 28(%edi) )
28894+DST( movl %edx, %es:28(%edi) )
28895
28896 lea 32(%esi), %esi
28897 lea 32(%edi), %edi
28898@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28899 shrl $2, %edx # This clears CF
28900 SRC(3: movl (%esi), %ebx )
28901 adcl %ebx, %eax
28902-DST( movl %ebx, (%edi) )
28903+DST( movl %ebx, %es:(%edi) )
28904 lea 4(%esi), %esi
28905 lea 4(%edi), %edi
28906 dec %edx
28907@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28908 jb 5f
28909 SRC( movw (%esi), %cx )
28910 leal 2(%esi), %esi
28911-DST( movw %cx, (%edi) )
28912+DST( movw %cx, %es:(%edi) )
28913 leal 2(%edi), %edi
28914 je 6f
28915 shll $16,%ecx
28916 SRC(5: movb (%esi), %cl )
28917-DST( movb %cl, (%edi) )
28918+DST( movb %cl, %es:(%edi) )
28919 6: addl %ecx, %eax
28920 adcl $0, %eax
28921 7:
28922@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28923
28924 6001:
28925 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28926- movl $-EFAULT, (%ebx)
28927+ movl $-EFAULT, %ss:(%ebx)
28928
28929 # zero the complete destination - computing the rest
28930 # is too much work
28931@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28932
28933 6002:
28934 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28935- movl $-EFAULT,(%ebx)
28936+ movl $-EFAULT,%ss:(%ebx)
28937 jmp 5000b
28938
28939 .previous
28940
28941+ pushl_cfi %ss
28942+ popl_cfi %ds
28943+ pushl_cfi %ss
28944+ popl_cfi %es
28945 popl_cfi %ebx
28946 CFI_RESTORE ebx
28947 popl_cfi %esi
28948@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28949 popl_cfi %ecx # equivalent to addl $4,%esp
28950 ret
28951 CFI_ENDPROC
28952-ENDPROC(csum_partial_copy_generic)
28953+ENDPROC(csum_partial_copy_generic_to_user)
28954
28955 #else
28956
28957 /* Version for PentiumII/PPro */
28958
28959 #define ROUND1(x) \
28960+ nop; nop; nop; \
28961 SRC(movl x(%esi), %ebx ) ; \
28962 addl %ebx, %eax ; \
28963- DST(movl %ebx, x(%edi) ) ;
28964+ DST(movl %ebx, %es:x(%edi)) ;
28965
28966 #define ROUND(x) \
28967+ nop; nop; nop; \
28968 SRC(movl x(%esi), %ebx ) ; \
28969 adcl %ebx, %eax ; \
28970- DST(movl %ebx, x(%edi) ) ;
28971+ DST(movl %ebx, %es:x(%edi)) ;
28972
28973 #define ARGBASE 12
28974-
28975-ENTRY(csum_partial_copy_generic)
28976+
28977+ENTRY(csum_partial_copy_generic_to_user)
28978 CFI_STARTPROC
28979+
28980+#ifdef CONFIG_PAX_MEMORY_UDEREF
28981+ pushl_cfi %gs
28982+ popl_cfi %es
28983+ jmp csum_partial_copy_generic
28984+#endif
28985+
28986+ENTRY(csum_partial_copy_generic_from_user)
28987+
28988+#ifdef CONFIG_PAX_MEMORY_UDEREF
28989+ pushl_cfi %gs
28990+ popl_cfi %ds
28991+#endif
28992+
28993+ENTRY(csum_partial_copy_generic)
28994 pushl_cfi %ebx
28995 CFI_REL_OFFSET ebx, 0
28996 pushl_cfi %edi
28997@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28998 subl %ebx, %edi
28999 lea -1(%esi),%edx
29000 andl $-32,%edx
29001- lea 3f(%ebx,%ebx), %ebx
29002+ lea 3f(%ebx,%ebx,2), %ebx
29003 testl %esi, %esi
29004 jmp *%ebx
29005 1: addl $64,%esi
29006@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29007 jb 5f
29008 SRC( movw (%esi), %dx )
29009 leal 2(%esi), %esi
29010-DST( movw %dx, (%edi) )
29011+DST( movw %dx, %es:(%edi) )
29012 leal 2(%edi), %edi
29013 je 6f
29014 shll $16,%edx
29015 5:
29016 SRC( movb (%esi), %dl )
29017-DST( movb %dl, (%edi) )
29018+DST( movb %dl, %es:(%edi) )
29019 6: addl %edx, %eax
29020 adcl $0, %eax
29021 7:
29022 .section .fixup, "ax"
29023 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29024- movl $-EFAULT, (%ebx)
29025+ movl $-EFAULT, %ss:(%ebx)
29026 # zero the complete destination (computing the rest is too much work)
29027 movl ARGBASE+8(%esp),%edi # dst
29028 movl ARGBASE+12(%esp),%ecx # len
29029@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29030 rep; stosb
29031 jmp 7b
29032 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29033- movl $-EFAULT, (%ebx)
29034+ movl $-EFAULT, %ss:(%ebx)
29035 jmp 7b
29036 .previous
29037
29038+#ifdef CONFIG_PAX_MEMORY_UDEREF
29039+ pushl_cfi %ss
29040+ popl_cfi %ds
29041+ pushl_cfi %ss
29042+ popl_cfi %es
29043+#endif
29044+
29045 popl_cfi %esi
29046 CFI_RESTORE esi
29047 popl_cfi %edi
29048@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29049 CFI_RESTORE ebx
29050 ret
29051 CFI_ENDPROC
29052-ENDPROC(csum_partial_copy_generic)
29053+ENDPROC(csum_partial_copy_generic_to_user)
29054
29055 #undef ROUND
29056 #undef ROUND1
29057diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29058index f2145cf..cea889d 100644
29059--- a/arch/x86/lib/clear_page_64.S
29060+++ b/arch/x86/lib/clear_page_64.S
29061@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29062 movl $4096/8,%ecx
29063 xorl %eax,%eax
29064 rep stosq
29065+ pax_force_retaddr
29066 ret
29067 CFI_ENDPROC
29068 ENDPROC(clear_page_c)
29069@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29070 movl $4096,%ecx
29071 xorl %eax,%eax
29072 rep stosb
29073+ pax_force_retaddr
29074 ret
29075 CFI_ENDPROC
29076 ENDPROC(clear_page_c_e)
29077@@ -43,6 +45,7 @@ ENTRY(clear_page)
29078 leaq 64(%rdi),%rdi
29079 jnz .Lloop
29080 nop
29081+ pax_force_retaddr
29082 ret
29083 CFI_ENDPROC
29084 .Lclear_page_end:
29085@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29086
29087 #include <asm/cpufeature.h>
29088
29089- .section .altinstr_replacement,"ax"
29090+ .section .altinstr_replacement,"a"
29091 1: .byte 0xeb /* jmp <disp8> */
29092 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29093 2: .byte 0xeb /* jmp <disp8> */
29094diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29095index 1e572c5..2a162cd 100644
29096--- a/arch/x86/lib/cmpxchg16b_emu.S
29097+++ b/arch/x86/lib/cmpxchg16b_emu.S
29098@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29099
29100 popf
29101 mov $1, %al
29102+ pax_force_retaddr
29103 ret
29104
29105 not_same:
29106 popf
29107 xor %al,%al
29108+ pax_force_retaddr
29109 ret
29110
29111 CFI_ENDPROC
29112diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29113index 176cca6..e0d658e 100644
29114--- a/arch/x86/lib/copy_page_64.S
29115+++ b/arch/x86/lib/copy_page_64.S
29116@@ -9,6 +9,7 @@ copy_page_rep:
29117 CFI_STARTPROC
29118 movl $4096/8, %ecx
29119 rep movsq
29120+ pax_force_retaddr
29121 ret
29122 CFI_ENDPROC
29123 ENDPROC(copy_page_rep)
29124@@ -24,8 +25,8 @@ ENTRY(copy_page)
29125 CFI_ADJUST_CFA_OFFSET 2*8
29126 movq %rbx, (%rsp)
29127 CFI_REL_OFFSET rbx, 0
29128- movq %r12, 1*8(%rsp)
29129- CFI_REL_OFFSET r12, 1*8
29130+ movq %r13, 1*8(%rsp)
29131+ CFI_REL_OFFSET r13, 1*8
29132
29133 movl $(4096/64)-5, %ecx
29134 .p2align 4
29135@@ -38,7 +39,7 @@ ENTRY(copy_page)
29136 movq 0x8*4(%rsi), %r9
29137 movq 0x8*5(%rsi), %r10
29138 movq 0x8*6(%rsi), %r11
29139- movq 0x8*7(%rsi), %r12
29140+ movq 0x8*7(%rsi), %r13
29141
29142 prefetcht0 5*64(%rsi)
29143
29144@@ -49,7 +50,7 @@ ENTRY(copy_page)
29145 movq %r9, 0x8*4(%rdi)
29146 movq %r10, 0x8*5(%rdi)
29147 movq %r11, 0x8*6(%rdi)
29148- movq %r12, 0x8*7(%rdi)
29149+ movq %r13, 0x8*7(%rdi)
29150
29151 leaq 64 (%rsi), %rsi
29152 leaq 64 (%rdi), %rdi
29153@@ -68,7 +69,7 @@ ENTRY(copy_page)
29154 movq 0x8*4(%rsi), %r9
29155 movq 0x8*5(%rsi), %r10
29156 movq 0x8*6(%rsi), %r11
29157- movq 0x8*7(%rsi), %r12
29158+ movq 0x8*7(%rsi), %r13
29159
29160 movq %rax, 0x8*0(%rdi)
29161 movq %rbx, 0x8*1(%rdi)
29162@@ -77,7 +78,7 @@ ENTRY(copy_page)
29163 movq %r9, 0x8*4(%rdi)
29164 movq %r10, 0x8*5(%rdi)
29165 movq %r11, 0x8*6(%rdi)
29166- movq %r12, 0x8*7(%rdi)
29167+ movq %r13, 0x8*7(%rdi)
29168
29169 leaq 64(%rdi), %rdi
29170 leaq 64(%rsi), %rsi
29171@@ -85,10 +86,11 @@ ENTRY(copy_page)
29172
29173 movq (%rsp), %rbx
29174 CFI_RESTORE rbx
29175- movq 1*8(%rsp), %r12
29176- CFI_RESTORE r12
29177+ movq 1*8(%rsp), %r13
29178+ CFI_RESTORE r13
29179 addq $2*8, %rsp
29180 CFI_ADJUST_CFA_OFFSET -2*8
29181+ pax_force_retaddr
29182 ret
29183 .Lcopy_page_end:
29184 CFI_ENDPROC
29185@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29186
29187 #include <asm/cpufeature.h>
29188
29189- .section .altinstr_replacement,"ax"
29190+ .section .altinstr_replacement,"a"
29191 1: .byte 0xeb /* jmp <disp8> */
29192 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29193 2:
29194diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29195index dee945d..a84067b 100644
29196--- a/arch/x86/lib/copy_user_64.S
29197+++ b/arch/x86/lib/copy_user_64.S
29198@@ -18,31 +18,7 @@
29199 #include <asm/alternative-asm.h>
29200 #include <asm/asm.h>
29201 #include <asm/smap.h>
29202-
29203-/*
29204- * By placing feature2 after feature1 in altinstructions section, we logically
29205- * implement:
29206- * If CPU has feature2, jmp to alt2 is used
29207- * else if CPU has feature1, jmp to alt1 is used
29208- * else jmp to orig is used.
29209- */
29210- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29211-0:
29212- .byte 0xe9 /* 32bit jump */
29213- .long \orig-1f /* by default jump to orig */
29214-1:
29215- .section .altinstr_replacement,"ax"
29216-2: .byte 0xe9 /* near jump with 32bit immediate */
29217- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29218-3: .byte 0xe9 /* near jump with 32bit immediate */
29219- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29220- .previous
29221-
29222- .section .altinstructions,"a"
29223- altinstruction_entry 0b,2b,\feature1,5,5
29224- altinstruction_entry 0b,3b,\feature2,5,5
29225- .previous
29226- .endm
29227+#include <asm/pgtable.h>
29228
29229 .macro ALIGN_DESTINATION
29230 #ifdef FIX_ALIGNMENT
29231@@ -70,52 +46,6 @@
29232 #endif
29233 .endm
29234
29235-/* Standard copy_to_user with segment limit checking */
29236-ENTRY(_copy_to_user)
29237- CFI_STARTPROC
29238- GET_THREAD_INFO(%rax)
29239- movq %rdi,%rcx
29240- addq %rdx,%rcx
29241- jc bad_to_user
29242- cmpq TI_addr_limit(%rax),%rcx
29243- ja bad_to_user
29244- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29245- copy_user_generic_unrolled,copy_user_generic_string, \
29246- copy_user_enhanced_fast_string
29247- CFI_ENDPROC
29248-ENDPROC(_copy_to_user)
29249-
29250-/* Standard copy_from_user with segment limit checking */
29251-ENTRY(_copy_from_user)
29252- CFI_STARTPROC
29253- GET_THREAD_INFO(%rax)
29254- movq %rsi,%rcx
29255- addq %rdx,%rcx
29256- jc bad_from_user
29257- cmpq TI_addr_limit(%rax),%rcx
29258- ja bad_from_user
29259- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29260- copy_user_generic_unrolled,copy_user_generic_string, \
29261- copy_user_enhanced_fast_string
29262- CFI_ENDPROC
29263-ENDPROC(_copy_from_user)
29264-
29265- .section .fixup,"ax"
29266- /* must zero dest */
29267-ENTRY(bad_from_user)
29268-bad_from_user:
29269- CFI_STARTPROC
29270- movl %edx,%ecx
29271- xorl %eax,%eax
29272- rep
29273- stosb
29274-bad_to_user:
29275- movl %edx,%eax
29276- ret
29277- CFI_ENDPROC
29278-ENDPROC(bad_from_user)
29279- .previous
29280-
29281 /*
29282 * copy_user_generic_unrolled - memory copy with exception handling.
29283 * This version is for CPUs like P4 that don't have efficient micro
29284@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29285 */
29286 ENTRY(copy_user_generic_unrolled)
29287 CFI_STARTPROC
29288+ ASM_PAX_OPEN_USERLAND
29289 ASM_STAC
29290 cmpl $8,%edx
29291 jb 20f /* less then 8 bytes, go to byte copy loop */
29292@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29293 jnz 21b
29294 23: xor %eax,%eax
29295 ASM_CLAC
29296+ ASM_PAX_CLOSE_USERLAND
29297+ pax_force_retaddr
29298 ret
29299
29300 .section .fixup,"ax"
29301@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29302 */
29303 ENTRY(copy_user_generic_string)
29304 CFI_STARTPROC
29305+ ASM_PAX_OPEN_USERLAND
29306 ASM_STAC
29307 cmpl $8,%edx
29308 jb 2f /* less than 8 bytes, go to byte copy loop */
29309@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29310 movsb
29311 xorl %eax,%eax
29312 ASM_CLAC
29313+ ASM_PAX_CLOSE_USERLAND
29314+ pax_force_retaddr
29315 ret
29316
29317 .section .fixup,"ax"
29318@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29319 */
29320 ENTRY(copy_user_enhanced_fast_string)
29321 CFI_STARTPROC
29322+ ASM_PAX_OPEN_USERLAND
29323 ASM_STAC
29324 movl %edx,%ecx
29325 1: rep
29326 movsb
29327 xorl %eax,%eax
29328 ASM_CLAC
29329+ ASM_PAX_CLOSE_USERLAND
29330+ pax_force_retaddr
29331 ret
29332
29333 .section .fixup,"ax"
29334diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29335index 6a4f43c..c70fb52 100644
29336--- a/arch/x86/lib/copy_user_nocache_64.S
29337+++ b/arch/x86/lib/copy_user_nocache_64.S
29338@@ -8,6 +8,7 @@
29339
29340 #include <linux/linkage.h>
29341 #include <asm/dwarf2.h>
29342+#include <asm/alternative-asm.h>
29343
29344 #define FIX_ALIGNMENT 1
29345
29346@@ -16,6 +17,7 @@
29347 #include <asm/thread_info.h>
29348 #include <asm/asm.h>
29349 #include <asm/smap.h>
29350+#include <asm/pgtable.h>
29351
29352 .macro ALIGN_DESTINATION
29353 #ifdef FIX_ALIGNMENT
29354@@ -49,6 +51,16 @@
29355 */
29356 ENTRY(__copy_user_nocache)
29357 CFI_STARTPROC
29358+
29359+#ifdef CONFIG_PAX_MEMORY_UDEREF
29360+ mov pax_user_shadow_base,%rcx
29361+ cmp %rcx,%rsi
29362+ jae 1f
29363+ add %rcx,%rsi
29364+1:
29365+#endif
29366+
29367+ ASM_PAX_OPEN_USERLAND
29368 ASM_STAC
29369 cmpl $8,%edx
29370 jb 20f /* less then 8 bytes, go to byte copy loop */
29371@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29372 jnz 21b
29373 23: xorl %eax,%eax
29374 ASM_CLAC
29375+ ASM_PAX_CLOSE_USERLAND
29376 sfence
29377+ pax_force_retaddr
29378 ret
29379
29380 .section .fixup,"ax"
29381diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29382index 2419d5f..fe52d0e 100644
29383--- a/arch/x86/lib/csum-copy_64.S
29384+++ b/arch/x86/lib/csum-copy_64.S
29385@@ -9,6 +9,7 @@
29386 #include <asm/dwarf2.h>
29387 #include <asm/errno.h>
29388 #include <asm/asm.h>
29389+#include <asm/alternative-asm.h>
29390
29391 /*
29392 * Checksum copy with exception handling.
29393@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29394 CFI_ADJUST_CFA_OFFSET 7*8
29395 movq %rbx, 2*8(%rsp)
29396 CFI_REL_OFFSET rbx, 2*8
29397- movq %r12, 3*8(%rsp)
29398- CFI_REL_OFFSET r12, 3*8
29399+ movq %r15, 3*8(%rsp)
29400+ CFI_REL_OFFSET r15, 3*8
29401 movq %r14, 4*8(%rsp)
29402 CFI_REL_OFFSET r14, 4*8
29403 movq %r13, 5*8(%rsp)
29404@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29405 movl %edx, %ecx
29406
29407 xorl %r9d, %r9d
29408- movq %rcx, %r12
29409+ movq %rcx, %r15
29410
29411- shrq $6, %r12
29412+ shrq $6, %r15
29413 jz .Lhandle_tail /* < 64 */
29414
29415 clc
29416
29417 /* main loop. clear in 64 byte blocks */
29418 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29419- /* r11: temp3, rdx: temp4, r12 loopcnt */
29420+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29421 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29422 .p2align 4
29423 .Lloop:
29424@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29425 adcq %r14, %rax
29426 adcq %r13, %rax
29427
29428- decl %r12d
29429+ decl %r15d
29430
29431 dest
29432 movq %rbx, (%rsi)
29433@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29434 .Lende:
29435 movq 2*8(%rsp), %rbx
29436 CFI_RESTORE rbx
29437- movq 3*8(%rsp), %r12
29438- CFI_RESTORE r12
29439+ movq 3*8(%rsp), %r15
29440+ CFI_RESTORE r15
29441 movq 4*8(%rsp), %r14
29442 CFI_RESTORE r14
29443 movq 5*8(%rsp), %r13
29444@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29445 CFI_RESTORE rbp
29446 addq $7*8, %rsp
29447 CFI_ADJUST_CFA_OFFSET -7*8
29448+ pax_force_retaddr
29449 ret
29450 CFI_RESTORE_STATE
29451
29452diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29453index 7609e0e..b449b98 100644
29454--- a/arch/x86/lib/csum-wrappers_64.c
29455+++ b/arch/x86/lib/csum-wrappers_64.c
29456@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29457 len -= 2;
29458 }
29459 }
29460+ pax_open_userland();
29461 stac();
29462- isum = csum_partial_copy_generic((__force const void *)src,
29463+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29464 dst, len, isum, errp, NULL);
29465 clac();
29466+ pax_close_userland();
29467 if (unlikely(*errp))
29468 goto out_err;
29469
29470@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29471 }
29472
29473 *errp = 0;
29474+ pax_open_userland();
29475 stac();
29476- ret = csum_partial_copy_generic(src, (void __force *)dst,
29477+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29478 len, isum, NULL, errp);
29479 clac();
29480+ pax_close_userland();
29481 return ret;
29482 }
29483 EXPORT_SYMBOL(csum_partial_copy_to_user);
29484diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29485index a451235..1daa956 100644
29486--- a/arch/x86/lib/getuser.S
29487+++ b/arch/x86/lib/getuser.S
29488@@ -33,17 +33,40 @@
29489 #include <asm/thread_info.h>
29490 #include <asm/asm.h>
29491 #include <asm/smap.h>
29492+#include <asm/segment.h>
29493+#include <asm/pgtable.h>
29494+#include <asm/alternative-asm.h>
29495+
29496+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29497+#define __copyuser_seg gs;
29498+#else
29499+#define __copyuser_seg
29500+#endif
29501
29502 .text
29503 ENTRY(__get_user_1)
29504 CFI_STARTPROC
29505+
29506+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29507 GET_THREAD_INFO(%_ASM_DX)
29508 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29509 jae bad_get_user
29510 ASM_STAC
29511-1: movzbl (%_ASM_AX),%edx
29512+
29513+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29514+ mov pax_user_shadow_base,%_ASM_DX
29515+ cmp %_ASM_DX,%_ASM_AX
29516+ jae 1234f
29517+ add %_ASM_DX,%_ASM_AX
29518+1234:
29519+#endif
29520+
29521+#endif
29522+
29523+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29524 xor %eax,%eax
29525 ASM_CLAC
29526+ pax_force_retaddr
29527 ret
29528 CFI_ENDPROC
29529 ENDPROC(__get_user_1)
29530@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29531 ENTRY(__get_user_2)
29532 CFI_STARTPROC
29533 add $1,%_ASM_AX
29534+
29535+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29536 jc bad_get_user
29537 GET_THREAD_INFO(%_ASM_DX)
29538 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29539 jae bad_get_user
29540 ASM_STAC
29541-2: movzwl -1(%_ASM_AX),%edx
29542+
29543+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29544+ mov pax_user_shadow_base,%_ASM_DX
29545+ cmp %_ASM_DX,%_ASM_AX
29546+ jae 1234f
29547+ add %_ASM_DX,%_ASM_AX
29548+1234:
29549+#endif
29550+
29551+#endif
29552+
29553+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29554 xor %eax,%eax
29555 ASM_CLAC
29556+ pax_force_retaddr
29557 ret
29558 CFI_ENDPROC
29559 ENDPROC(__get_user_2)
29560@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29561 ENTRY(__get_user_4)
29562 CFI_STARTPROC
29563 add $3,%_ASM_AX
29564+
29565+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29566 jc bad_get_user
29567 GET_THREAD_INFO(%_ASM_DX)
29568 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29569 jae bad_get_user
29570 ASM_STAC
29571-3: movl -3(%_ASM_AX),%edx
29572+
29573+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29574+ mov pax_user_shadow_base,%_ASM_DX
29575+ cmp %_ASM_DX,%_ASM_AX
29576+ jae 1234f
29577+ add %_ASM_DX,%_ASM_AX
29578+1234:
29579+#endif
29580+
29581+#endif
29582+
29583+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29584 xor %eax,%eax
29585 ASM_CLAC
29586+ pax_force_retaddr
29587 ret
29588 CFI_ENDPROC
29589 ENDPROC(__get_user_4)
29590@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29591 GET_THREAD_INFO(%_ASM_DX)
29592 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29593 jae bad_get_user
29594+
29595+#ifdef CONFIG_PAX_MEMORY_UDEREF
29596+ mov pax_user_shadow_base,%_ASM_DX
29597+ cmp %_ASM_DX,%_ASM_AX
29598+ jae 1234f
29599+ add %_ASM_DX,%_ASM_AX
29600+1234:
29601+#endif
29602+
29603 ASM_STAC
29604 4: movq -7(%_ASM_AX),%rdx
29605 xor %eax,%eax
29606 ASM_CLAC
29607+ pax_force_retaddr
29608 ret
29609 #else
29610 add $7,%_ASM_AX
29611@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29612 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29613 jae bad_get_user_8
29614 ASM_STAC
29615-4: movl -7(%_ASM_AX),%edx
29616-5: movl -3(%_ASM_AX),%ecx
29617+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29618+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29619 xor %eax,%eax
29620 ASM_CLAC
29621+ pax_force_retaddr
29622 ret
29623 #endif
29624 CFI_ENDPROC
29625@@ -113,6 +175,7 @@ bad_get_user:
29626 xor %edx,%edx
29627 mov $(-EFAULT),%_ASM_AX
29628 ASM_CLAC
29629+ pax_force_retaddr
29630 ret
29631 CFI_ENDPROC
29632 END(bad_get_user)
29633@@ -124,6 +187,7 @@ bad_get_user_8:
29634 xor %ecx,%ecx
29635 mov $(-EFAULT),%_ASM_AX
29636 ASM_CLAC
29637+ pax_force_retaddr
29638 ret
29639 CFI_ENDPROC
29640 END(bad_get_user_8)
29641diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29642index 54fcffe..7be149e 100644
29643--- a/arch/x86/lib/insn.c
29644+++ b/arch/x86/lib/insn.c
29645@@ -20,8 +20,10 @@
29646
29647 #ifdef __KERNEL__
29648 #include <linux/string.h>
29649+#include <asm/pgtable_types.h>
29650 #else
29651 #include <string.h>
29652+#define ktla_ktva(addr) addr
29653 #endif
29654 #include <asm/inat.h>
29655 #include <asm/insn.h>
29656@@ -53,8 +55,8 @@
29657 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29658 {
29659 memset(insn, 0, sizeof(*insn));
29660- insn->kaddr = kaddr;
29661- insn->next_byte = kaddr;
29662+ insn->kaddr = ktla_ktva(kaddr);
29663+ insn->next_byte = ktla_ktva(kaddr);
29664 insn->x86_64 = x86_64 ? 1 : 0;
29665 insn->opnd_bytes = 4;
29666 if (x86_64)
29667diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29668index 05a95e7..326f2fa 100644
29669--- a/arch/x86/lib/iomap_copy_64.S
29670+++ b/arch/x86/lib/iomap_copy_64.S
29671@@ -17,6 +17,7 @@
29672
29673 #include <linux/linkage.h>
29674 #include <asm/dwarf2.h>
29675+#include <asm/alternative-asm.h>
29676
29677 /*
29678 * override generic version in lib/iomap_copy.c
29679@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29680 CFI_STARTPROC
29681 movl %edx,%ecx
29682 rep movsd
29683+ pax_force_retaddr
29684 ret
29685 CFI_ENDPROC
29686 ENDPROC(__iowrite32_copy)
29687diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29688index 56313a3..0db417e 100644
29689--- a/arch/x86/lib/memcpy_64.S
29690+++ b/arch/x86/lib/memcpy_64.S
29691@@ -24,7 +24,7 @@
29692 * This gets patched over the unrolled variant (below) via the
29693 * alternative instructions framework:
29694 */
29695- .section .altinstr_replacement, "ax", @progbits
29696+ .section .altinstr_replacement, "a", @progbits
29697 .Lmemcpy_c:
29698 movq %rdi, %rax
29699 movq %rdx, %rcx
29700@@ -33,6 +33,7 @@
29701 rep movsq
29702 movl %edx, %ecx
29703 rep movsb
29704+ pax_force_retaddr
29705 ret
29706 .Lmemcpy_e:
29707 .previous
29708@@ -44,11 +45,12 @@
29709 * This gets patched over the unrolled variant (below) via the
29710 * alternative instructions framework:
29711 */
29712- .section .altinstr_replacement, "ax", @progbits
29713+ .section .altinstr_replacement, "a", @progbits
29714 .Lmemcpy_c_e:
29715 movq %rdi, %rax
29716 movq %rdx, %rcx
29717 rep movsb
29718+ pax_force_retaddr
29719 ret
29720 .Lmemcpy_e_e:
29721 .previous
29722@@ -136,6 +138,7 @@ ENTRY(memcpy)
29723 movq %r9, 1*8(%rdi)
29724 movq %r10, -2*8(%rdi, %rdx)
29725 movq %r11, -1*8(%rdi, %rdx)
29726+ pax_force_retaddr
29727 retq
29728 .p2align 4
29729 .Lless_16bytes:
29730@@ -148,6 +151,7 @@ ENTRY(memcpy)
29731 movq -1*8(%rsi, %rdx), %r9
29732 movq %r8, 0*8(%rdi)
29733 movq %r9, -1*8(%rdi, %rdx)
29734+ pax_force_retaddr
29735 retq
29736 .p2align 4
29737 .Lless_8bytes:
29738@@ -161,6 +165,7 @@ ENTRY(memcpy)
29739 movl -4(%rsi, %rdx), %r8d
29740 movl %ecx, (%rdi)
29741 movl %r8d, -4(%rdi, %rdx)
29742+ pax_force_retaddr
29743 retq
29744 .p2align 4
29745 .Lless_3bytes:
29746@@ -179,6 +184,7 @@ ENTRY(memcpy)
29747 movb %cl, (%rdi)
29748
29749 .Lend:
29750+ pax_force_retaddr
29751 retq
29752 CFI_ENDPROC
29753 ENDPROC(memcpy)
29754diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29755index 65268a6..dd1de11 100644
29756--- a/arch/x86/lib/memmove_64.S
29757+++ b/arch/x86/lib/memmove_64.S
29758@@ -202,14 +202,16 @@ ENTRY(memmove)
29759 movb (%rsi), %r11b
29760 movb %r11b, (%rdi)
29761 13:
29762+ pax_force_retaddr
29763 retq
29764 CFI_ENDPROC
29765
29766- .section .altinstr_replacement,"ax"
29767+ .section .altinstr_replacement,"a"
29768 .Lmemmove_begin_forward_efs:
29769 /* Forward moving data. */
29770 movq %rdx, %rcx
29771 rep movsb
29772+ pax_force_retaddr
29773 retq
29774 .Lmemmove_end_forward_efs:
29775 .previous
29776diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29777index 2dcb380..2eb79fe 100644
29778--- a/arch/x86/lib/memset_64.S
29779+++ b/arch/x86/lib/memset_64.S
29780@@ -16,7 +16,7 @@
29781 *
29782 * rax original destination
29783 */
29784- .section .altinstr_replacement, "ax", @progbits
29785+ .section .altinstr_replacement, "a", @progbits
29786 .Lmemset_c:
29787 movq %rdi,%r9
29788 movq %rdx,%rcx
29789@@ -30,6 +30,7 @@
29790 movl %edx,%ecx
29791 rep stosb
29792 movq %r9,%rax
29793+ pax_force_retaddr
29794 ret
29795 .Lmemset_e:
29796 .previous
29797@@ -45,13 +46,14 @@
29798 *
29799 * rax original destination
29800 */
29801- .section .altinstr_replacement, "ax", @progbits
29802+ .section .altinstr_replacement, "a", @progbits
29803 .Lmemset_c_e:
29804 movq %rdi,%r9
29805 movb %sil,%al
29806 movq %rdx,%rcx
29807 rep stosb
29808 movq %r9,%rax
29809+ pax_force_retaddr
29810 ret
29811 .Lmemset_e_e:
29812 .previous
29813@@ -118,6 +120,7 @@ ENTRY(__memset)
29814
29815 .Lende:
29816 movq %r10,%rax
29817+ pax_force_retaddr
29818 ret
29819
29820 CFI_RESTORE_STATE
29821diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29822index c9f2d9b..e7fd2c0 100644
29823--- a/arch/x86/lib/mmx_32.c
29824+++ b/arch/x86/lib/mmx_32.c
29825@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29826 {
29827 void *p;
29828 int i;
29829+ unsigned long cr0;
29830
29831 if (unlikely(in_interrupt()))
29832 return __memcpy(to, from, len);
29833@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29834 kernel_fpu_begin();
29835
29836 __asm__ __volatile__ (
29837- "1: prefetch (%0)\n" /* This set is 28 bytes */
29838- " prefetch 64(%0)\n"
29839- " prefetch 128(%0)\n"
29840- " prefetch 192(%0)\n"
29841- " prefetch 256(%0)\n"
29842+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29843+ " prefetch 64(%1)\n"
29844+ " prefetch 128(%1)\n"
29845+ " prefetch 192(%1)\n"
29846+ " prefetch 256(%1)\n"
29847 "2: \n"
29848 ".section .fixup, \"ax\"\n"
29849- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29850+ "3: \n"
29851+
29852+#ifdef CONFIG_PAX_KERNEXEC
29853+ " movl %%cr0, %0\n"
29854+ " movl %0, %%eax\n"
29855+ " andl $0xFFFEFFFF, %%eax\n"
29856+ " movl %%eax, %%cr0\n"
29857+#endif
29858+
29859+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29860+
29861+#ifdef CONFIG_PAX_KERNEXEC
29862+ " movl %0, %%cr0\n"
29863+#endif
29864+
29865 " jmp 2b\n"
29866 ".previous\n"
29867 _ASM_EXTABLE(1b, 3b)
29868- : : "r" (from));
29869+ : "=&r" (cr0) : "r" (from) : "ax");
29870
29871 for ( ; i > 5; i--) {
29872 __asm__ __volatile__ (
29873- "1: prefetch 320(%0)\n"
29874- "2: movq (%0), %%mm0\n"
29875- " movq 8(%0), %%mm1\n"
29876- " movq 16(%0), %%mm2\n"
29877- " movq 24(%0), %%mm3\n"
29878- " movq %%mm0, (%1)\n"
29879- " movq %%mm1, 8(%1)\n"
29880- " movq %%mm2, 16(%1)\n"
29881- " movq %%mm3, 24(%1)\n"
29882- " movq 32(%0), %%mm0\n"
29883- " movq 40(%0), %%mm1\n"
29884- " movq 48(%0), %%mm2\n"
29885- " movq 56(%0), %%mm3\n"
29886- " movq %%mm0, 32(%1)\n"
29887- " movq %%mm1, 40(%1)\n"
29888- " movq %%mm2, 48(%1)\n"
29889- " movq %%mm3, 56(%1)\n"
29890+ "1: prefetch 320(%1)\n"
29891+ "2: movq (%1), %%mm0\n"
29892+ " movq 8(%1), %%mm1\n"
29893+ " movq 16(%1), %%mm2\n"
29894+ " movq 24(%1), %%mm3\n"
29895+ " movq %%mm0, (%2)\n"
29896+ " movq %%mm1, 8(%2)\n"
29897+ " movq %%mm2, 16(%2)\n"
29898+ " movq %%mm3, 24(%2)\n"
29899+ " movq 32(%1), %%mm0\n"
29900+ " movq 40(%1), %%mm1\n"
29901+ " movq 48(%1), %%mm2\n"
29902+ " movq 56(%1), %%mm3\n"
29903+ " movq %%mm0, 32(%2)\n"
29904+ " movq %%mm1, 40(%2)\n"
29905+ " movq %%mm2, 48(%2)\n"
29906+ " movq %%mm3, 56(%2)\n"
29907 ".section .fixup, \"ax\"\n"
29908- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29909+ "3:\n"
29910+
29911+#ifdef CONFIG_PAX_KERNEXEC
29912+ " movl %%cr0, %0\n"
29913+ " movl %0, %%eax\n"
29914+ " andl $0xFFFEFFFF, %%eax\n"
29915+ " movl %%eax, %%cr0\n"
29916+#endif
29917+
29918+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29919+
29920+#ifdef CONFIG_PAX_KERNEXEC
29921+ " movl %0, %%cr0\n"
29922+#endif
29923+
29924 " jmp 2b\n"
29925 ".previous\n"
29926 _ASM_EXTABLE(1b, 3b)
29927- : : "r" (from), "r" (to) : "memory");
29928+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29929
29930 from += 64;
29931 to += 64;
29932@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29933 static void fast_copy_page(void *to, void *from)
29934 {
29935 int i;
29936+ unsigned long cr0;
29937
29938 kernel_fpu_begin();
29939
29940@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29941 * but that is for later. -AV
29942 */
29943 __asm__ __volatile__(
29944- "1: prefetch (%0)\n"
29945- " prefetch 64(%0)\n"
29946- " prefetch 128(%0)\n"
29947- " prefetch 192(%0)\n"
29948- " prefetch 256(%0)\n"
29949+ "1: prefetch (%1)\n"
29950+ " prefetch 64(%1)\n"
29951+ " prefetch 128(%1)\n"
29952+ " prefetch 192(%1)\n"
29953+ " prefetch 256(%1)\n"
29954 "2: \n"
29955 ".section .fixup, \"ax\"\n"
29956- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29957+ "3: \n"
29958+
29959+#ifdef CONFIG_PAX_KERNEXEC
29960+ " movl %%cr0, %0\n"
29961+ " movl %0, %%eax\n"
29962+ " andl $0xFFFEFFFF, %%eax\n"
29963+ " movl %%eax, %%cr0\n"
29964+#endif
29965+
29966+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29967+
29968+#ifdef CONFIG_PAX_KERNEXEC
29969+ " movl %0, %%cr0\n"
29970+#endif
29971+
29972 " jmp 2b\n"
29973 ".previous\n"
29974- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29975+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29976
29977 for (i = 0; i < (4096-320)/64; i++) {
29978 __asm__ __volatile__ (
29979- "1: prefetch 320(%0)\n"
29980- "2: movq (%0), %%mm0\n"
29981- " movntq %%mm0, (%1)\n"
29982- " movq 8(%0), %%mm1\n"
29983- " movntq %%mm1, 8(%1)\n"
29984- " movq 16(%0), %%mm2\n"
29985- " movntq %%mm2, 16(%1)\n"
29986- " movq 24(%0), %%mm3\n"
29987- " movntq %%mm3, 24(%1)\n"
29988- " movq 32(%0), %%mm4\n"
29989- " movntq %%mm4, 32(%1)\n"
29990- " movq 40(%0), %%mm5\n"
29991- " movntq %%mm5, 40(%1)\n"
29992- " movq 48(%0), %%mm6\n"
29993- " movntq %%mm6, 48(%1)\n"
29994- " movq 56(%0), %%mm7\n"
29995- " movntq %%mm7, 56(%1)\n"
29996+ "1: prefetch 320(%1)\n"
29997+ "2: movq (%1), %%mm0\n"
29998+ " movntq %%mm0, (%2)\n"
29999+ " movq 8(%1), %%mm1\n"
30000+ " movntq %%mm1, 8(%2)\n"
30001+ " movq 16(%1), %%mm2\n"
30002+ " movntq %%mm2, 16(%2)\n"
30003+ " movq 24(%1), %%mm3\n"
30004+ " movntq %%mm3, 24(%2)\n"
30005+ " movq 32(%1), %%mm4\n"
30006+ " movntq %%mm4, 32(%2)\n"
30007+ " movq 40(%1), %%mm5\n"
30008+ " movntq %%mm5, 40(%2)\n"
30009+ " movq 48(%1), %%mm6\n"
30010+ " movntq %%mm6, 48(%2)\n"
30011+ " movq 56(%1), %%mm7\n"
30012+ " movntq %%mm7, 56(%2)\n"
30013 ".section .fixup, \"ax\"\n"
30014- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30015+ "3:\n"
30016+
30017+#ifdef CONFIG_PAX_KERNEXEC
30018+ " movl %%cr0, %0\n"
30019+ " movl %0, %%eax\n"
30020+ " andl $0xFFFEFFFF, %%eax\n"
30021+ " movl %%eax, %%cr0\n"
30022+#endif
30023+
30024+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30025+
30026+#ifdef CONFIG_PAX_KERNEXEC
30027+ " movl %0, %%cr0\n"
30028+#endif
30029+
30030 " jmp 2b\n"
30031 ".previous\n"
30032- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30033+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30034
30035 from += 64;
30036 to += 64;
30037@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30038 static void fast_copy_page(void *to, void *from)
30039 {
30040 int i;
30041+ unsigned long cr0;
30042
30043 kernel_fpu_begin();
30044
30045 __asm__ __volatile__ (
30046- "1: prefetch (%0)\n"
30047- " prefetch 64(%0)\n"
30048- " prefetch 128(%0)\n"
30049- " prefetch 192(%0)\n"
30050- " prefetch 256(%0)\n"
30051+ "1: prefetch (%1)\n"
30052+ " prefetch 64(%1)\n"
30053+ " prefetch 128(%1)\n"
30054+ " prefetch 192(%1)\n"
30055+ " prefetch 256(%1)\n"
30056 "2: \n"
30057 ".section .fixup, \"ax\"\n"
30058- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30059+ "3: \n"
30060+
30061+#ifdef CONFIG_PAX_KERNEXEC
30062+ " movl %%cr0, %0\n"
30063+ " movl %0, %%eax\n"
30064+ " andl $0xFFFEFFFF, %%eax\n"
30065+ " movl %%eax, %%cr0\n"
30066+#endif
30067+
30068+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30069+
30070+#ifdef CONFIG_PAX_KERNEXEC
30071+ " movl %0, %%cr0\n"
30072+#endif
30073+
30074 " jmp 2b\n"
30075 ".previous\n"
30076- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30077+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30078
30079 for (i = 0; i < 4096/64; i++) {
30080 __asm__ __volatile__ (
30081- "1: prefetch 320(%0)\n"
30082- "2: movq (%0), %%mm0\n"
30083- " movq 8(%0), %%mm1\n"
30084- " movq 16(%0), %%mm2\n"
30085- " movq 24(%0), %%mm3\n"
30086- " movq %%mm0, (%1)\n"
30087- " movq %%mm1, 8(%1)\n"
30088- " movq %%mm2, 16(%1)\n"
30089- " movq %%mm3, 24(%1)\n"
30090- " movq 32(%0), %%mm0\n"
30091- " movq 40(%0), %%mm1\n"
30092- " movq 48(%0), %%mm2\n"
30093- " movq 56(%0), %%mm3\n"
30094- " movq %%mm0, 32(%1)\n"
30095- " movq %%mm1, 40(%1)\n"
30096- " movq %%mm2, 48(%1)\n"
30097- " movq %%mm3, 56(%1)\n"
30098+ "1: prefetch 320(%1)\n"
30099+ "2: movq (%1), %%mm0\n"
30100+ " movq 8(%1), %%mm1\n"
30101+ " movq 16(%1), %%mm2\n"
30102+ " movq 24(%1), %%mm3\n"
30103+ " movq %%mm0, (%2)\n"
30104+ " movq %%mm1, 8(%2)\n"
30105+ " movq %%mm2, 16(%2)\n"
30106+ " movq %%mm3, 24(%2)\n"
30107+ " movq 32(%1), %%mm0\n"
30108+ " movq 40(%1), %%mm1\n"
30109+ " movq 48(%1), %%mm2\n"
30110+ " movq 56(%1), %%mm3\n"
30111+ " movq %%mm0, 32(%2)\n"
30112+ " movq %%mm1, 40(%2)\n"
30113+ " movq %%mm2, 48(%2)\n"
30114+ " movq %%mm3, 56(%2)\n"
30115 ".section .fixup, \"ax\"\n"
30116- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30117+ "3:\n"
30118+
30119+#ifdef CONFIG_PAX_KERNEXEC
30120+ " movl %%cr0, %0\n"
30121+ " movl %0, %%eax\n"
30122+ " andl $0xFFFEFFFF, %%eax\n"
30123+ " movl %%eax, %%cr0\n"
30124+#endif
30125+
30126+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30127+
30128+#ifdef CONFIG_PAX_KERNEXEC
30129+ " movl %0, %%cr0\n"
30130+#endif
30131+
30132 " jmp 2b\n"
30133 ".previous\n"
30134 _ASM_EXTABLE(1b, 3b)
30135- : : "r" (from), "r" (to) : "memory");
30136+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30137
30138 from += 64;
30139 to += 64;
30140diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30141index f6d13ee..d789440 100644
30142--- a/arch/x86/lib/msr-reg.S
30143+++ b/arch/x86/lib/msr-reg.S
30144@@ -3,6 +3,7 @@
30145 #include <asm/dwarf2.h>
30146 #include <asm/asm.h>
30147 #include <asm/msr.h>
30148+#include <asm/alternative-asm.h>
30149
30150 #ifdef CONFIG_X86_64
30151 /*
30152@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30153 movl %edi, 28(%r10)
30154 popq_cfi %rbp
30155 popq_cfi %rbx
30156+ pax_force_retaddr
30157 ret
30158 3:
30159 CFI_RESTORE_STATE
30160diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30161index fc6ba17..d4d989d 100644
30162--- a/arch/x86/lib/putuser.S
30163+++ b/arch/x86/lib/putuser.S
30164@@ -16,7 +16,9 @@
30165 #include <asm/errno.h>
30166 #include <asm/asm.h>
30167 #include <asm/smap.h>
30168-
30169+#include <asm/segment.h>
30170+#include <asm/pgtable.h>
30171+#include <asm/alternative-asm.h>
30172
30173 /*
30174 * __put_user_X
30175@@ -30,57 +32,125 @@
30176 * as they get called from within inline assembly.
30177 */
30178
30179-#define ENTER CFI_STARTPROC ; \
30180- GET_THREAD_INFO(%_ASM_BX)
30181-#define EXIT ASM_CLAC ; \
30182- ret ; \
30183+#define ENTER CFI_STARTPROC
30184+#define EXIT ASM_CLAC ; \
30185+ pax_force_retaddr ; \
30186+ ret ; \
30187 CFI_ENDPROC
30188
30189+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30190+#define _DEST %_ASM_CX,%_ASM_BX
30191+#else
30192+#define _DEST %_ASM_CX
30193+#endif
30194+
30195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30196+#define __copyuser_seg gs;
30197+#else
30198+#define __copyuser_seg
30199+#endif
30200+
30201 .text
30202 ENTRY(__put_user_1)
30203 ENTER
30204+
30205+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30206+ GET_THREAD_INFO(%_ASM_BX)
30207 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30208 jae bad_put_user
30209 ASM_STAC
30210-1: movb %al,(%_ASM_CX)
30211+
30212+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30213+ mov pax_user_shadow_base,%_ASM_BX
30214+ cmp %_ASM_BX,%_ASM_CX
30215+ jb 1234f
30216+ xor %ebx,%ebx
30217+1234:
30218+#endif
30219+
30220+#endif
30221+
30222+1: __copyuser_seg movb %al,(_DEST)
30223 xor %eax,%eax
30224 EXIT
30225 ENDPROC(__put_user_1)
30226
30227 ENTRY(__put_user_2)
30228 ENTER
30229+
30230+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30231+ GET_THREAD_INFO(%_ASM_BX)
30232 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30233 sub $1,%_ASM_BX
30234 cmp %_ASM_BX,%_ASM_CX
30235 jae bad_put_user
30236 ASM_STAC
30237-2: movw %ax,(%_ASM_CX)
30238+
30239+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30240+ mov pax_user_shadow_base,%_ASM_BX
30241+ cmp %_ASM_BX,%_ASM_CX
30242+ jb 1234f
30243+ xor %ebx,%ebx
30244+1234:
30245+#endif
30246+
30247+#endif
30248+
30249+2: __copyuser_seg movw %ax,(_DEST)
30250 xor %eax,%eax
30251 EXIT
30252 ENDPROC(__put_user_2)
30253
30254 ENTRY(__put_user_4)
30255 ENTER
30256+
30257+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30258+ GET_THREAD_INFO(%_ASM_BX)
30259 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30260 sub $3,%_ASM_BX
30261 cmp %_ASM_BX,%_ASM_CX
30262 jae bad_put_user
30263 ASM_STAC
30264-3: movl %eax,(%_ASM_CX)
30265+
30266+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30267+ mov pax_user_shadow_base,%_ASM_BX
30268+ cmp %_ASM_BX,%_ASM_CX
30269+ jb 1234f
30270+ xor %ebx,%ebx
30271+1234:
30272+#endif
30273+
30274+#endif
30275+
30276+3: __copyuser_seg movl %eax,(_DEST)
30277 xor %eax,%eax
30278 EXIT
30279 ENDPROC(__put_user_4)
30280
30281 ENTRY(__put_user_8)
30282 ENTER
30283+
30284+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30285+ GET_THREAD_INFO(%_ASM_BX)
30286 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30287 sub $7,%_ASM_BX
30288 cmp %_ASM_BX,%_ASM_CX
30289 jae bad_put_user
30290 ASM_STAC
30291-4: mov %_ASM_AX,(%_ASM_CX)
30292+
30293+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30294+ mov pax_user_shadow_base,%_ASM_BX
30295+ cmp %_ASM_BX,%_ASM_CX
30296+ jb 1234f
30297+ xor %ebx,%ebx
30298+1234:
30299+#endif
30300+
30301+#endif
30302+
30303+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30304 #ifdef CONFIG_X86_32
30305-5: movl %edx,4(%_ASM_CX)
30306+5: __copyuser_seg movl %edx,4(_DEST)
30307 #endif
30308 xor %eax,%eax
30309 EXIT
30310diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30311index 1cad221..de671ee 100644
30312--- a/arch/x86/lib/rwlock.S
30313+++ b/arch/x86/lib/rwlock.S
30314@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30315 FRAME
30316 0: LOCK_PREFIX
30317 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30318+
30319+#ifdef CONFIG_PAX_REFCOUNT
30320+ jno 1234f
30321+ LOCK_PREFIX
30322+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30323+ int $4
30324+1234:
30325+ _ASM_EXTABLE(1234b, 1234b)
30326+#endif
30327+
30328 1: rep; nop
30329 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30330 jne 1b
30331 LOCK_PREFIX
30332 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30333+
30334+#ifdef CONFIG_PAX_REFCOUNT
30335+ jno 1234f
30336+ LOCK_PREFIX
30337+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30338+ int $4
30339+1234:
30340+ _ASM_EXTABLE(1234b, 1234b)
30341+#endif
30342+
30343 jnz 0b
30344 ENDFRAME
30345+ pax_force_retaddr
30346 ret
30347 CFI_ENDPROC
30348 END(__write_lock_failed)
30349@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30350 FRAME
30351 0: LOCK_PREFIX
30352 READ_LOCK_SIZE(inc) (%__lock_ptr)
30353+
30354+#ifdef CONFIG_PAX_REFCOUNT
30355+ jno 1234f
30356+ LOCK_PREFIX
30357+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30358+ int $4
30359+1234:
30360+ _ASM_EXTABLE(1234b, 1234b)
30361+#endif
30362+
30363 1: rep; nop
30364 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30365 js 1b
30366 LOCK_PREFIX
30367 READ_LOCK_SIZE(dec) (%__lock_ptr)
30368+
30369+#ifdef CONFIG_PAX_REFCOUNT
30370+ jno 1234f
30371+ LOCK_PREFIX
30372+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30373+ int $4
30374+1234:
30375+ _ASM_EXTABLE(1234b, 1234b)
30376+#endif
30377+
30378 js 0b
30379 ENDFRAME
30380+ pax_force_retaddr
30381 ret
30382 CFI_ENDPROC
30383 END(__read_lock_failed)
30384diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30385index 5dff5f0..cadebf4 100644
30386--- a/arch/x86/lib/rwsem.S
30387+++ b/arch/x86/lib/rwsem.S
30388@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30389 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30390 CFI_RESTORE __ASM_REG(dx)
30391 restore_common_regs
30392+ pax_force_retaddr
30393 ret
30394 CFI_ENDPROC
30395 ENDPROC(call_rwsem_down_read_failed)
30396@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30397 movq %rax,%rdi
30398 call rwsem_down_write_failed
30399 restore_common_regs
30400+ pax_force_retaddr
30401 ret
30402 CFI_ENDPROC
30403 ENDPROC(call_rwsem_down_write_failed)
30404@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30405 movq %rax,%rdi
30406 call rwsem_wake
30407 restore_common_regs
30408-1: ret
30409+1: pax_force_retaddr
30410+ ret
30411 CFI_ENDPROC
30412 ENDPROC(call_rwsem_wake)
30413
30414@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30415 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30416 CFI_RESTORE __ASM_REG(dx)
30417 restore_common_regs
30418+ pax_force_retaddr
30419 ret
30420 CFI_ENDPROC
30421 ENDPROC(call_rwsem_downgrade_wake)
30422diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30423index a63efd6..8149fbe 100644
30424--- a/arch/x86/lib/thunk_64.S
30425+++ b/arch/x86/lib/thunk_64.S
30426@@ -8,6 +8,7 @@
30427 #include <linux/linkage.h>
30428 #include <asm/dwarf2.h>
30429 #include <asm/calling.h>
30430+#include <asm/alternative-asm.h>
30431
30432 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30433 .macro THUNK name, func, put_ret_addr_in_rdi=0
30434@@ -15,11 +16,11 @@
30435 \name:
30436 CFI_STARTPROC
30437
30438- /* this one pushes 9 elems, the next one would be %rIP */
30439- SAVE_ARGS
30440+ /* this one pushes 15+1 elems, the next one would be %rIP */
30441+ SAVE_ARGS 8
30442
30443 .if \put_ret_addr_in_rdi
30444- movq_cfi_restore 9*8, rdi
30445+ movq_cfi_restore RIP, rdi
30446 .endif
30447
30448 call \func
30449@@ -38,8 +39,9 @@
30450
30451 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30452 CFI_STARTPROC
30453- SAVE_ARGS
30454+ SAVE_ARGS 8
30455 restore:
30456- RESTORE_ARGS
30457+ RESTORE_ARGS 1,8
30458+ pax_force_retaddr
30459 ret
30460 CFI_ENDPROC
30461diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30462index e2f5e21..4b22130 100644
30463--- a/arch/x86/lib/usercopy_32.c
30464+++ b/arch/x86/lib/usercopy_32.c
30465@@ -42,11 +42,13 @@ do { \
30466 int __d0; \
30467 might_fault(); \
30468 __asm__ __volatile__( \
30469+ __COPYUSER_SET_ES \
30470 ASM_STAC "\n" \
30471 "0: rep; stosl\n" \
30472 " movl %2,%0\n" \
30473 "1: rep; stosb\n" \
30474 "2: " ASM_CLAC "\n" \
30475+ __COPYUSER_RESTORE_ES \
30476 ".section .fixup,\"ax\"\n" \
30477 "3: lea 0(%2,%0,4),%0\n" \
30478 " jmp 2b\n" \
30479@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30480
30481 #ifdef CONFIG_X86_INTEL_USERCOPY
30482 static unsigned long
30483-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30484+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30485 {
30486 int d0, d1;
30487 __asm__ __volatile__(
30488@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30489 " .align 2,0x90\n"
30490 "3: movl 0(%4), %%eax\n"
30491 "4: movl 4(%4), %%edx\n"
30492- "5: movl %%eax, 0(%3)\n"
30493- "6: movl %%edx, 4(%3)\n"
30494+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30495+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30496 "7: movl 8(%4), %%eax\n"
30497 "8: movl 12(%4),%%edx\n"
30498- "9: movl %%eax, 8(%3)\n"
30499- "10: movl %%edx, 12(%3)\n"
30500+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30501+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30502 "11: movl 16(%4), %%eax\n"
30503 "12: movl 20(%4), %%edx\n"
30504- "13: movl %%eax, 16(%3)\n"
30505- "14: movl %%edx, 20(%3)\n"
30506+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30507+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30508 "15: movl 24(%4), %%eax\n"
30509 "16: movl 28(%4), %%edx\n"
30510- "17: movl %%eax, 24(%3)\n"
30511- "18: movl %%edx, 28(%3)\n"
30512+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30513+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30514 "19: movl 32(%4), %%eax\n"
30515 "20: movl 36(%4), %%edx\n"
30516- "21: movl %%eax, 32(%3)\n"
30517- "22: movl %%edx, 36(%3)\n"
30518+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30519+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30520 "23: movl 40(%4), %%eax\n"
30521 "24: movl 44(%4), %%edx\n"
30522- "25: movl %%eax, 40(%3)\n"
30523- "26: movl %%edx, 44(%3)\n"
30524+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30525+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30526 "27: movl 48(%4), %%eax\n"
30527 "28: movl 52(%4), %%edx\n"
30528- "29: movl %%eax, 48(%3)\n"
30529- "30: movl %%edx, 52(%3)\n"
30530+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30531+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30532 "31: movl 56(%4), %%eax\n"
30533 "32: movl 60(%4), %%edx\n"
30534- "33: movl %%eax, 56(%3)\n"
30535- "34: movl %%edx, 60(%3)\n"
30536+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30537+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30538 " addl $-64, %0\n"
30539 " addl $64, %4\n"
30540 " addl $64, %3\n"
30541@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30542 " shrl $2, %0\n"
30543 " andl $3, %%eax\n"
30544 " cld\n"
30545+ __COPYUSER_SET_ES
30546 "99: rep; movsl\n"
30547 "36: movl %%eax, %0\n"
30548 "37: rep; movsb\n"
30549 "100:\n"
30550+ __COPYUSER_RESTORE_ES
30551+ ".section .fixup,\"ax\"\n"
30552+ "101: lea 0(%%eax,%0,4),%0\n"
30553+ " jmp 100b\n"
30554+ ".previous\n"
30555+ _ASM_EXTABLE(1b,100b)
30556+ _ASM_EXTABLE(2b,100b)
30557+ _ASM_EXTABLE(3b,100b)
30558+ _ASM_EXTABLE(4b,100b)
30559+ _ASM_EXTABLE(5b,100b)
30560+ _ASM_EXTABLE(6b,100b)
30561+ _ASM_EXTABLE(7b,100b)
30562+ _ASM_EXTABLE(8b,100b)
30563+ _ASM_EXTABLE(9b,100b)
30564+ _ASM_EXTABLE(10b,100b)
30565+ _ASM_EXTABLE(11b,100b)
30566+ _ASM_EXTABLE(12b,100b)
30567+ _ASM_EXTABLE(13b,100b)
30568+ _ASM_EXTABLE(14b,100b)
30569+ _ASM_EXTABLE(15b,100b)
30570+ _ASM_EXTABLE(16b,100b)
30571+ _ASM_EXTABLE(17b,100b)
30572+ _ASM_EXTABLE(18b,100b)
30573+ _ASM_EXTABLE(19b,100b)
30574+ _ASM_EXTABLE(20b,100b)
30575+ _ASM_EXTABLE(21b,100b)
30576+ _ASM_EXTABLE(22b,100b)
30577+ _ASM_EXTABLE(23b,100b)
30578+ _ASM_EXTABLE(24b,100b)
30579+ _ASM_EXTABLE(25b,100b)
30580+ _ASM_EXTABLE(26b,100b)
30581+ _ASM_EXTABLE(27b,100b)
30582+ _ASM_EXTABLE(28b,100b)
30583+ _ASM_EXTABLE(29b,100b)
30584+ _ASM_EXTABLE(30b,100b)
30585+ _ASM_EXTABLE(31b,100b)
30586+ _ASM_EXTABLE(32b,100b)
30587+ _ASM_EXTABLE(33b,100b)
30588+ _ASM_EXTABLE(34b,100b)
30589+ _ASM_EXTABLE(35b,100b)
30590+ _ASM_EXTABLE(36b,100b)
30591+ _ASM_EXTABLE(37b,100b)
30592+ _ASM_EXTABLE(99b,101b)
30593+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30594+ : "1"(to), "2"(from), "0"(size)
30595+ : "eax", "edx", "memory");
30596+ return size;
30597+}
30598+
30599+static unsigned long
30600+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30601+{
30602+ int d0, d1;
30603+ __asm__ __volatile__(
30604+ " .align 2,0x90\n"
30605+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30606+ " cmpl $67, %0\n"
30607+ " jbe 3f\n"
30608+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30609+ " .align 2,0x90\n"
30610+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30611+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30612+ "5: movl %%eax, 0(%3)\n"
30613+ "6: movl %%edx, 4(%3)\n"
30614+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30615+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30616+ "9: movl %%eax, 8(%3)\n"
30617+ "10: movl %%edx, 12(%3)\n"
30618+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30619+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30620+ "13: movl %%eax, 16(%3)\n"
30621+ "14: movl %%edx, 20(%3)\n"
30622+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30623+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30624+ "17: movl %%eax, 24(%3)\n"
30625+ "18: movl %%edx, 28(%3)\n"
30626+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30627+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30628+ "21: movl %%eax, 32(%3)\n"
30629+ "22: movl %%edx, 36(%3)\n"
30630+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30631+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30632+ "25: movl %%eax, 40(%3)\n"
30633+ "26: movl %%edx, 44(%3)\n"
30634+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30635+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30636+ "29: movl %%eax, 48(%3)\n"
30637+ "30: movl %%edx, 52(%3)\n"
30638+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30639+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30640+ "33: movl %%eax, 56(%3)\n"
30641+ "34: movl %%edx, 60(%3)\n"
30642+ " addl $-64, %0\n"
30643+ " addl $64, %4\n"
30644+ " addl $64, %3\n"
30645+ " cmpl $63, %0\n"
30646+ " ja 1b\n"
30647+ "35: movl %0, %%eax\n"
30648+ " shrl $2, %0\n"
30649+ " andl $3, %%eax\n"
30650+ " cld\n"
30651+ "99: rep; "__copyuser_seg" movsl\n"
30652+ "36: movl %%eax, %0\n"
30653+ "37: rep; "__copyuser_seg" movsb\n"
30654+ "100:\n"
30655 ".section .fixup,\"ax\"\n"
30656 "101: lea 0(%%eax,%0,4),%0\n"
30657 " jmp 100b\n"
30658@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30659 int d0, d1;
30660 __asm__ __volatile__(
30661 " .align 2,0x90\n"
30662- "0: movl 32(%4), %%eax\n"
30663+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30664 " cmpl $67, %0\n"
30665 " jbe 2f\n"
30666- "1: movl 64(%4), %%eax\n"
30667+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30668 " .align 2,0x90\n"
30669- "2: movl 0(%4), %%eax\n"
30670- "21: movl 4(%4), %%edx\n"
30671+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30672+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30673 " movl %%eax, 0(%3)\n"
30674 " movl %%edx, 4(%3)\n"
30675- "3: movl 8(%4), %%eax\n"
30676- "31: movl 12(%4),%%edx\n"
30677+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30678+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30679 " movl %%eax, 8(%3)\n"
30680 " movl %%edx, 12(%3)\n"
30681- "4: movl 16(%4), %%eax\n"
30682- "41: movl 20(%4), %%edx\n"
30683+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30684+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30685 " movl %%eax, 16(%3)\n"
30686 " movl %%edx, 20(%3)\n"
30687- "10: movl 24(%4), %%eax\n"
30688- "51: movl 28(%4), %%edx\n"
30689+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30690+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30691 " movl %%eax, 24(%3)\n"
30692 " movl %%edx, 28(%3)\n"
30693- "11: movl 32(%4), %%eax\n"
30694- "61: movl 36(%4), %%edx\n"
30695+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30696+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30697 " movl %%eax, 32(%3)\n"
30698 " movl %%edx, 36(%3)\n"
30699- "12: movl 40(%4), %%eax\n"
30700- "71: movl 44(%4), %%edx\n"
30701+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30702+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30703 " movl %%eax, 40(%3)\n"
30704 " movl %%edx, 44(%3)\n"
30705- "13: movl 48(%4), %%eax\n"
30706- "81: movl 52(%4), %%edx\n"
30707+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30708+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30709 " movl %%eax, 48(%3)\n"
30710 " movl %%edx, 52(%3)\n"
30711- "14: movl 56(%4), %%eax\n"
30712- "91: movl 60(%4), %%edx\n"
30713+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30714+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30715 " movl %%eax, 56(%3)\n"
30716 " movl %%edx, 60(%3)\n"
30717 " addl $-64, %0\n"
30718@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30719 " shrl $2, %0\n"
30720 " andl $3, %%eax\n"
30721 " cld\n"
30722- "6: rep; movsl\n"
30723+ "6: rep; "__copyuser_seg" movsl\n"
30724 " movl %%eax,%0\n"
30725- "7: rep; movsb\n"
30726+ "7: rep; "__copyuser_seg" movsb\n"
30727 "8:\n"
30728 ".section .fixup,\"ax\"\n"
30729 "9: lea 0(%%eax,%0,4),%0\n"
30730@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30731
30732 __asm__ __volatile__(
30733 " .align 2,0x90\n"
30734- "0: movl 32(%4), %%eax\n"
30735+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30736 " cmpl $67, %0\n"
30737 " jbe 2f\n"
30738- "1: movl 64(%4), %%eax\n"
30739+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30740 " .align 2,0x90\n"
30741- "2: movl 0(%4), %%eax\n"
30742- "21: movl 4(%4), %%edx\n"
30743+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30744+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30745 " movnti %%eax, 0(%3)\n"
30746 " movnti %%edx, 4(%3)\n"
30747- "3: movl 8(%4), %%eax\n"
30748- "31: movl 12(%4),%%edx\n"
30749+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30750+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30751 " movnti %%eax, 8(%3)\n"
30752 " movnti %%edx, 12(%3)\n"
30753- "4: movl 16(%4), %%eax\n"
30754- "41: movl 20(%4), %%edx\n"
30755+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30756+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30757 " movnti %%eax, 16(%3)\n"
30758 " movnti %%edx, 20(%3)\n"
30759- "10: movl 24(%4), %%eax\n"
30760- "51: movl 28(%4), %%edx\n"
30761+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30762+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30763 " movnti %%eax, 24(%3)\n"
30764 " movnti %%edx, 28(%3)\n"
30765- "11: movl 32(%4), %%eax\n"
30766- "61: movl 36(%4), %%edx\n"
30767+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30768+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30769 " movnti %%eax, 32(%3)\n"
30770 " movnti %%edx, 36(%3)\n"
30771- "12: movl 40(%4), %%eax\n"
30772- "71: movl 44(%4), %%edx\n"
30773+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30774+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30775 " movnti %%eax, 40(%3)\n"
30776 " movnti %%edx, 44(%3)\n"
30777- "13: movl 48(%4), %%eax\n"
30778- "81: movl 52(%4), %%edx\n"
30779+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30780+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30781 " movnti %%eax, 48(%3)\n"
30782 " movnti %%edx, 52(%3)\n"
30783- "14: movl 56(%4), %%eax\n"
30784- "91: movl 60(%4), %%edx\n"
30785+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30786+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30787 " movnti %%eax, 56(%3)\n"
30788 " movnti %%edx, 60(%3)\n"
30789 " addl $-64, %0\n"
30790@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30791 " shrl $2, %0\n"
30792 " andl $3, %%eax\n"
30793 " cld\n"
30794- "6: rep; movsl\n"
30795+ "6: rep; "__copyuser_seg" movsl\n"
30796 " movl %%eax,%0\n"
30797- "7: rep; movsb\n"
30798+ "7: rep; "__copyuser_seg" movsb\n"
30799 "8:\n"
30800 ".section .fixup,\"ax\"\n"
30801 "9: lea 0(%%eax,%0,4),%0\n"
30802@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30803
30804 __asm__ __volatile__(
30805 " .align 2,0x90\n"
30806- "0: movl 32(%4), %%eax\n"
30807+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30808 " cmpl $67, %0\n"
30809 " jbe 2f\n"
30810- "1: movl 64(%4), %%eax\n"
30811+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30812 " .align 2,0x90\n"
30813- "2: movl 0(%4), %%eax\n"
30814- "21: movl 4(%4), %%edx\n"
30815+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30816+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30817 " movnti %%eax, 0(%3)\n"
30818 " movnti %%edx, 4(%3)\n"
30819- "3: movl 8(%4), %%eax\n"
30820- "31: movl 12(%4),%%edx\n"
30821+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30822+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30823 " movnti %%eax, 8(%3)\n"
30824 " movnti %%edx, 12(%3)\n"
30825- "4: movl 16(%4), %%eax\n"
30826- "41: movl 20(%4), %%edx\n"
30827+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30828+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30829 " movnti %%eax, 16(%3)\n"
30830 " movnti %%edx, 20(%3)\n"
30831- "10: movl 24(%4), %%eax\n"
30832- "51: movl 28(%4), %%edx\n"
30833+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30834+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30835 " movnti %%eax, 24(%3)\n"
30836 " movnti %%edx, 28(%3)\n"
30837- "11: movl 32(%4), %%eax\n"
30838- "61: movl 36(%4), %%edx\n"
30839+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30840+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30841 " movnti %%eax, 32(%3)\n"
30842 " movnti %%edx, 36(%3)\n"
30843- "12: movl 40(%4), %%eax\n"
30844- "71: movl 44(%4), %%edx\n"
30845+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30846+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30847 " movnti %%eax, 40(%3)\n"
30848 " movnti %%edx, 44(%3)\n"
30849- "13: movl 48(%4), %%eax\n"
30850- "81: movl 52(%4), %%edx\n"
30851+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30852+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30853 " movnti %%eax, 48(%3)\n"
30854 " movnti %%edx, 52(%3)\n"
30855- "14: movl 56(%4), %%eax\n"
30856- "91: movl 60(%4), %%edx\n"
30857+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30858+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30859 " movnti %%eax, 56(%3)\n"
30860 " movnti %%edx, 60(%3)\n"
30861 " addl $-64, %0\n"
30862@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30863 " shrl $2, %0\n"
30864 " andl $3, %%eax\n"
30865 " cld\n"
30866- "6: rep; movsl\n"
30867+ "6: rep; "__copyuser_seg" movsl\n"
30868 " movl %%eax,%0\n"
30869- "7: rep; movsb\n"
30870+ "7: rep; "__copyuser_seg" movsb\n"
30871 "8:\n"
30872 ".section .fixup,\"ax\"\n"
30873 "9: lea 0(%%eax,%0,4),%0\n"
30874@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30875 */
30876 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30877 unsigned long size);
30878-unsigned long __copy_user_intel(void __user *to, const void *from,
30879+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30880+ unsigned long size);
30881+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30882 unsigned long size);
30883 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30884 const void __user *from, unsigned long size);
30885 #endif /* CONFIG_X86_INTEL_USERCOPY */
30886
30887 /* Generic arbitrary sized copy. */
30888-#define __copy_user(to, from, size) \
30889+#define __copy_user(to, from, size, prefix, set, restore) \
30890 do { \
30891 int __d0, __d1, __d2; \
30892 __asm__ __volatile__( \
30893+ set \
30894 " cmp $7,%0\n" \
30895 " jbe 1f\n" \
30896 " movl %1,%0\n" \
30897 " negl %0\n" \
30898 " andl $7,%0\n" \
30899 " subl %0,%3\n" \
30900- "4: rep; movsb\n" \
30901+ "4: rep; "prefix"movsb\n" \
30902 " movl %3,%0\n" \
30903 " shrl $2,%0\n" \
30904 " andl $3,%3\n" \
30905 " .align 2,0x90\n" \
30906- "0: rep; movsl\n" \
30907+ "0: rep; "prefix"movsl\n" \
30908 " movl %3,%0\n" \
30909- "1: rep; movsb\n" \
30910+ "1: rep; "prefix"movsb\n" \
30911 "2:\n" \
30912+ restore \
30913 ".section .fixup,\"ax\"\n" \
30914 "5: addl %3,%0\n" \
30915 " jmp 2b\n" \
30916@@ -538,14 +650,14 @@ do { \
30917 " negl %0\n" \
30918 " andl $7,%0\n" \
30919 " subl %0,%3\n" \
30920- "4: rep; movsb\n" \
30921+ "4: rep; "__copyuser_seg"movsb\n" \
30922 " movl %3,%0\n" \
30923 " shrl $2,%0\n" \
30924 " andl $3,%3\n" \
30925 " .align 2,0x90\n" \
30926- "0: rep; movsl\n" \
30927+ "0: rep; "__copyuser_seg"movsl\n" \
30928 " movl %3,%0\n" \
30929- "1: rep; movsb\n" \
30930+ "1: rep; "__copyuser_seg"movsb\n" \
30931 "2:\n" \
30932 ".section .fixup,\"ax\"\n" \
30933 "5: addl %3,%0\n" \
30934@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30935 {
30936 stac();
30937 if (movsl_is_ok(to, from, n))
30938- __copy_user(to, from, n);
30939+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30940 else
30941- n = __copy_user_intel(to, from, n);
30942+ n = __generic_copy_to_user_intel(to, from, n);
30943 clac();
30944 return n;
30945 }
30946@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30947 {
30948 stac();
30949 if (movsl_is_ok(to, from, n))
30950- __copy_user(to, from, n);
30951+ __copy_user(to, from, n, __copyuser_seg, "", "");
30952 else
30953- n = __copy_user_intel((void __user *)to,
30954- (const void *)from, n);
30955+ n = __generic_copy_from_user_intel(to, from, n);
30956 clac();
30957 return n;
30958 }
30959@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30960 if (n > 64 && cpu_has_xmm2)
30961 n = __copy_user_intel_nocache(to, from, n);
30962 else
30963- __copy_user(to, from, n);
30964+ __copy_user(to, from, n, __copyuser_seg, "", "");
30965 #else
30966- __copy_user(to, from, n);
30967+ __copy_user(to, from, n, __copyuser_seg, "", "");
30968 #endif
30969 clac();
30970 return n;
30971 }
30972 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30973
30974-/**
30975- * copy_to_user: - Copy a block of data into user space.
30976- * @to: Destination address, in user space.
30977- * @from: Source address, in kernel space.
30978- * @n: Number of bytes to copy.
30979- *
30980- * Context: User context only. This function may sleep.
30981- *
30982- * Copy data from kernel space to user space.
30983- *
30984- * Returns number of bytes that could not be copied.
30985- * On success, this will be zero.
30986- */
30987-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30988+#ifdef CONFIG_PAX_MEMORY_UDEREF
30989+void __set_fs(mm_segment_t x)
30990 {
30991- if (access_ok(VERIFY_WRITE, to, n))
30992- n = __copy_to_user(to, from, n);
30993- return n;
30994+ switch (x.seg) {
30995+ case 0:
30996+ loadsegment(gs, 0);
30997+ break;
30998+ case TASK_SIZE_MAX:
30999+ loadsegment(gs, __USER_DS);
31000+ break;
31001+ case -1UL:
31002+ loadsegment(gs, __KERNEL_DS);
31003+ break;
31004+ default:
31005+ BUG();
31006+ }
31007 }
31008-EXPORT_SYMBOL(_copy_to_user);
31009+EXPORT_SYMBOL(__set_fs);
31010
31011-/**
31012- * copy_from_user: - Copy a block of data from user space.
31013- * @to: Destination address, in kernel space.
31014- * @from: Source address, in user space.
31015- * @n: Number of bytes to copy.
31016- *
31017- * Context: User context only. This function may sleep.
31018- *
31019- * Copy data from user space to kernel space.
31020- *
31021- * Returns number of bytes that could not be copied.
31022- * On success, this will be zero.
31023- *
31024- * If some data could not be copied, this function will pad the copied
31025- * data to the requested size using zero bytes.
31026- */
31027-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31028+void set_fs(mm_segment_t x)
31029 {
31030- if (access_ok(VERIFY_READ, from, n))
31031- n = __copy_from_user(to, from, n);
31032- else
31033- memset(to, 0, n);
31034- return n;
31035+ current_thread_info()->addr_limit = x;
31036+ __set_fs(x);
31037 }
31038-EXPORT_SYMBOL(_copy_from_user);
31039+EXPORT_SYMBOL(set_fs);
31040+#endif
31041diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31042index c905e89..01ab928 100644
31043--- a/arch/x86/lib/usercopy_64.c
31044+++ b/arch/x86/lib/usercopy_64.c
31045@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31046 might_fault();
31047 /* no memory constraint because it doesn't change any memory gcc knows
31048 about */
31049+ pax_open_userland();
31050 stac();
31051 asm volatile(
31052 " testq %[size8],%[size8]\n"
31053@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31054 _ASM_EXTABLE(0b,3b)
31055 _ASM_EXTABLE(1b,2b)
31056 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31057- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31058+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31059 [zero] "r" (0UL), [eight] "r" (8UL));
31060 clac();
31061+ pax_close_userland();
31062 return size;
31063 }
31064 EXPORT_SYMBOL(__clear_user);
31065@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31066 }
31067 EXPORT_SYMBOL(clear_user);
31068
31069-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31070+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31071 {
31072- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31073- return copy_user_generic((__force void *)to, (__force void *)from, len);
31074- }
31075- return len;
31076+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31077+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31078+ return len;
31079 }
31080 EXPORT_SYMBOL(copy_in_user);
31081
31082@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31083 * it is not necessary to optimize tail handling.
31084 */
31085 __visible unsigned long
31086-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31087+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31088 {
31089 char c;
31090 unsigned zero_len;
31091
31092+ clac();
31093+ pax_close_userland();
31094 for (; len; --len, to++) {
31095 if (__get_user_nocheck(c, from++, sizeof(char)))
31096 break;
31097@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31098 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31099 if (__put_user_nocheck(c, to++, sizeof(char)))
31100 break;
31101- clac();
31102 return len;
31103 }
31104diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31105index 6a19ad9..1c48f9a 100644
31106--- a/arch/x86/mm/Makefile
31107+++ b/arch/x86/mm/Makefile
31108@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31109 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31110
31111 obj-$(CONFIG_MEMTEST) += memtest.o
31112+
31113+quote:="
31114+obj-$(CONFIG_X86_64) += uderef_64.o
31115+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31116diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31117index 903ec1e..c4166b2 100644
31118--- a/arch/x86/mm/extable.c
31119+++ b/arch/x86/mm/extable.c
31120@@ -6,12 +6,24 @@
31121 static inline unsigned long
31122 ex_insn_addr(const struct exception_table_entry *x)
31123 {
31124- return (unsigned long)&x->insn + x->insn;
31125+ unsigned long reloc = 0;
31126+
31127+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31128+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31129+#endif
31130+
31131+ return (unsigned long)&x->insn + x->insn + reloc;
31132 }
31133 static inline unsigned long
31134 ex_fixup_addr(const struct exception_table_entry *x)
31135 {
31136- return (unsigned long)&x->fixup + x->fixup;
31137+ unsigned long reloc = 0;
31138+
31139+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31140+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31141+#endif
31142+
31143+ return (unsigned long)&x->fixup + x->fixup + reloc;
31144 }
31145
31146 int fixup_exception(struct pt_regs *regs)
31147@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31148 unsigned long new_ip;
31149
31150 #ifdef CONFIG_PNPBIOS
31151- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31152+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31153 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31154 extern u32 pnp_bios_is_utter_crap;
31155 pnp_bios_is_utter_crap = 1;
31156@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31157 i += 4;
31158 p->fixup -= i;
31159 i += 4;
31160+
31161+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31162+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31163+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31164+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31165+#endif
31166+
31167 }
31168 }
31169
31170diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31171index a10c8c7..35a5abb 100644
31172--- a/arch/x86/mm/fault.c
31173+++ b/arch/x86/mm/fault.c
31174@@ -14,11 +14,18 @@
31175 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31176 #include <linux/prefetch.h> /* prefetchw */
31177 #include <linux/context_tracking.h> /* exception_enter(), ... */
31178+#include <linux/unistd.h>
31179+#include <linux/compiler.h>
31180
31181 #include <asm/traps.h> /* dotraplinkage, ... */
31182 #include <asm/pgalloc.h> /* pgd_*(), ... */
31183 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31184 #include <asm/fixmap.h> /* VSYSCALL_START */
31185+#include <asm/tlbflush.h>
31186+
31187+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31188+#include <asm/stacktrace.h>
31189+#endif
31190
31191 #define CREATE_TRACE_POINTS
31192 #include <asm/trace/exceptions.h>
31193@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31194 int ret = 0;
31195
31196 /* kprobe_running() needs smp_processor_id() */
31197- if (kprobes_built_in() && !user_mode_vm(regs)) {
31198+ if (kprobes_built_in() && !user_mode(regs)) {
31199 preempt_disable();
31200 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31201 ret = 1;
31202@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31203 return !instr_lo || (instr_lo>>1) == 1;
31204 case 0x00:
31205 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31206- if (probe_kernel_address(instr, opcode))
31207+ if (user_mode(regs)) {
31208+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31209+ return 0;
31210+ } else if (probe_kernel_address(instr, opcode))
31211 return 0;
31212
31213 *prefetch = (instr_lo == 0xF) &&
31214@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31215 while (instr < max_instr) {
31216 unsigned char opcode;
31217
31218- if (probe_kernel_address(instr, opcode))
31219+ if (user_mode(regs)) {
31220+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31221+ break;
31222+ } else if (probe_kernel_address(instr, opcode))
31223 break;
31224
31225 instr++;
31226@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31227 force_sig_info(si_signo, &info, tsk);
31228 }
31229
31230+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31231+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31232+#endif
31233+
31234+#ifdef CONFIG_PAX_EMUTRAMP
31235+static int pax_handle_fetch_fault(struct pt_regs *regs);
31236+#endif
31237+
31238+#ifdef CONFIG_PAX_PAGEEXEC
31239+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31240+{
31241+ pgd_t *pgd;
31242+ pud_t *pud;
31243+ pmd_t *pmd;
31244+
31245+ pgd = pgd_offset(mm, address);
31246+ if (!pgd_present(*pgd))
31247+ return NULL;
31248+ pud = pud_offset(pgd, address);
31249+ if (!pud_present(*pud))
31250+ return NULL;
31251+ pmd = pmd_offset(pud, address);
31252+ if (!pmd_present(*pmd))
31253+ return NULL;
31254+ return pmd;
31255+}
31256+#endif
31257+
31258 DEFINE_SPINLOCK(pgd_lock);
31259 LIST_HEAD(pgd_list);
31260
31261@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31262 for (address = VMALLOC_START & PMD_MASK;
31263 address >= TASK_SIZE && address < FIXADDR_TOP;
31264 address += PMD_SIZE) {
31265+
31266+#ifdef CONFIG_PAX_PER_CPU_PGD
31267+ unsigned long cpu;
31268+#else
31269 struct page *page;
31270+#endif
31271
31272 spin_lock(&pgd_lock);
31273+
31274+#ifdef CONFIG_PAX_PER_CPU_PGD
31275+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31276+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31277+ pmd_t *ret;
31278+
31279+ ret = vmalloc_sync_one(pgd, address);
31280+ if (!ret)
31281+ break;
31282+ pgd = get_cpu_pgd(cpu, kernel);
31283+#else
31284 list_for_each_entry(page, &pgd_list, lru) {
31285+ pgd_t *pgd;
31286 spinlock_t *pgt_lock;
31287 pmd_t *ret;
31288
31289@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31290 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31291
31292 spin_lock(pgt_lock);
31293- ret = vmalloc_sync_one(page_address(page), address);
31294+ pgd = page_address(page);
31295+#endif
31296+
31297+ ret = vmalloc_sync_one(pgd, address);
31298+
31299+#ifndef CONFIG_PAX_PER_CPU_PGD
31300 spin_unlock(pgt_lock);
31301+#endif
31302
31303 if (!ret)
31304 break;
31305@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31306 * an interrupt in the middle of a task switch..
31307 */
31308 pgd_paddr = read_cr3();
31309+
31310+#ifdef CONFIG_PAX_PER_CPU_PGD
31311+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31312+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31313+#endif
31314+
31315 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31316 if (!pmd_k)
31317 return -1;
31318@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31319 * happen within a race in page table update. In the later
31320 * case just flush:
31321 */
31322- pgd = pgd_offset(current->active_mm, address);
31323+
31324 pgd_ref = pgd_offset_k(address);
31325 if (pgd_none(*pgd_ref))
31326 return -1;
31327
31328+#ifdef CONFIG_PAX_PER_CPU_PGD
31329+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31330+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31331+ if (pgd_none(*pgd)) {
31332+ set_pgd(pgd, *pgd_ref);
31333+ arch_flush_lazy_mmu_mode();
31334+ } else {
31335+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31336+ }
31337+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31338+#else
31339+ pgd = pgd_offset(current->active_mm, address);
31340+#endif
31341+
31342 if (pgd_none(*pgd)) {
31343 set_pgd(pgd, *pgd_ref);
31344 arch_flush_lazy_mmu_mode();
31345@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31346 static int is_errata100(struct pt_regs *regs, unsigned long address)
31347 {
31348 #ifdef CONFIG_X86_64
31349- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31350+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31351 return 1;
31352 #endif
31353 return 0;
31354@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31355 }
31356
31357 static const char nx_warning[] = KERN_CRIT
31358-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31359+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31360
31361 static void
31362 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31363@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31364 if (!oops_may_print())
31365 return;
31366
31367- if (error_code & PF_INSTR) {
31368+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31369 unsigned int level;
31370
31371 pte_t *pte = lookup_address(address, &level);
31372
31373 if (pte && pte_present(*pte) && !pte_exec(*pte))
31374- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31375+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31376 }
31377
31378+#ifdef CONFIG_PAX_KERNEXEC
31379+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31380+ if (current->signal->curr_ip)
31381+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31382+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31383+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31384+ else
31385+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31386+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31387+ }
31388+#endif
31389+
31390 printk(KERN_ALERT "BUG: unable to handle kernel ");
31391 if (address < PAGE_SIZE)
31392 printk(KERN_CONT "NULL pointer dereference");
31393@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31394 return;
31395 }
31396 #endif
31397+
31398+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31399+ if (pax_is_fetch_fault(regs, error_code, address)) {
31400+
31401+#ifdef CONFIG_PAX_EMUTRAMP
31402+ switch (pax_handle_fetch_fault(regs)) {
31403+ case 2:
31404+ return;
31405+ }
31406+#endif
31407+
31408+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31409+ do_group_exit(SIGKILL);
31410+ }
31411+#endif
31412+
31413 /* Kernel addresses are always protection faults: */
31414 if (address >= TASK_SIZE)
31415 error_code |= PF_PROT;
31416@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31417 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31418 printk(KERN_ERR
31419 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31420- tsk->comm, tsk->pid, address);
31421+ tsk->comm, task_pid_nr(tsk), address);
31422 code = BUS_MCEERR_AR;
31423 }
31424 #endif
31425@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31426 return 1;
31427 }
31428
31429+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31430+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31431+{
31432+ pte_t *pte;
31433+ pmd_t *pmd;
31434+ spinlock_t *ptl;
31435+ unsigned char pte_mask;
31436+
31437+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31438+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31439+ return 0;
31440+
31441+ /* PaX: it's our fault, let's handle it if we can */
31442+
31443+ /* PaX: take a look at read faults before acquiring any locks */
31444+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31445+ /* instruction fetch attempt from a protected page in user mode */
31446+ up_read(&mm->mmap_sem);
31447+
31448+#ifdef CONFIG_PAX_EMUTRAMP
31449+ switch (pax_handle_fetch_fault(regs)) {
31450+ case 2:
31451+ return 1;
31452+ }
31453+#endif
31454+
31455+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31456+ do_group_exit(SIGKILL);
31457+ }
31458+
31459+ pmd = pax_get_pmd(mm, address);
31460+ if (unlikely(!pmd))
31461+ return 0;
31462+
31463+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31464+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31465+ pte_unmap_unlock(pte, ptl);
31466+ return 0;
31467+ }
31468+
31469+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31470+ /* write attempt to a protected page in user mode */
31471+ pte_unmap_unlock(pte, ptl);
31472+ return 0;
31473+ }
31474+
31475+#ifdef CONFIG_SMP
31476+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31477+#else
31478+ if (likely(address > get_limit(regs->cs)))
31479+#endif
31480+ {
31481+ set_pte(pte, pte_mkread(*pte));
31482+ __flush_tlb_one(address);
31483+ pte_unmap_unlock(pte, ptl);
31484+ up_read(&mm->mmap_sem);
31485+ return 1;
31486+ }
31487+
31488+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31489+
31490+ /*
31491+ * PaX: fill DTLB with user rights and retry
31492+ */
31493+ __asm__ __volatile__ (
31494+ "orb %2,(%1)\n"
31495+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31496+/*
31497+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31498+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31499+ * page fault when examined during a TLB load attempt. this is true not only
31500+ * for PTEs holding a non-present entry but also present entries that will
31501+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31502+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31503+ * for our target pages since their PTEs are simply not in the TLBs at all.
31504+
31505+ * the best thing in omitting it is that we gain around 15-20% speed in the
31506+ * fast path of the page fault handler and can get rid of tracing since we
31507+ * can no longer flush unintended entries.
31508+ */
31509+ "invlpg (%0)\n"
31510+#endif
31511+ __copyuser_seg"testb $0,(%0)\n"
31512+ "xorb %3,(%1)\n"
31513+ :
31514+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31515+ : "memory", "cc");
31516+ pte_unmap_unlock(pte, ptl);
31517+ up_read(&mm->mmap_sem);
31518+ return 1;
31519+}
31520+#endif
31521+
31522 /*
31523 * Handle a spurious fault caused by a stale TLB entry.
31524 *
31525@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31526 static inline int
31527 access_error(unsigned long error_code, struct vm_area_struct *vma)
31528 {
31529+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31530+ return 1;
31531+
31532 if (error_code & PF_WRITE) {
31533 /* write, present and write, not present: */
31534 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31535@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31536 if (error_code & PF_USER)
31537 return false;
31538
31539- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31540+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31541 return false;
31542
31543 return true;
31544@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31545 tsk = current;
31546 mm = tsk->mm;
31547
31548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31549+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31550+ if (!search_exception_tables(regs->ip)) {
31551+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31552+ bad_area_nosemaphore(regs, error_code, address);
31553+ return;
31554+ }
31555+ if (address < pax_user_shadow_base) {
31556+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31557+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31558+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31559+ } else
31560+ address -= pax_user_shadow_base;
31561+ }
31562+#endif
31563+
31564 /*
31565 * Detect and handle instructions that would cause a page fault for
31566 * both a tracked kernel page and a userspace page.
31567@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31568 * User-mode registers count as a user access even for any
31569 * potential system fault or CPU buglet:
31570 */
31571- if (user_mode_vm(regs)) {
31572+ if (user_mode(regs)) {
31573 local_irq_enable();
31574 error_code |= PF_USER;
31575 flags |= FAULT_FLAG_USER;
31576@@ -1162,6 +1386,11 @@ retry:
31577 might_sleep();
31578 }
31579
31580+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31581+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31582+ return;
31583+#endif
31584+
31585 vma = find_vma(mm, address);
31586 if (unlikely(!vma)) {
31587 bad_area(regs, error_code, address);
31588@@ -1173,18 +1402,24 @@ retry:
31589 bad_area(regs, error_code, address);
31590 return;
31591 }
31592- if (error_code & PF_USER) {
31593- /*
31594- * Accessing the stack below %sp is always a bug.
31595- * The large cushion allows instructions like enter
31596- * and pusha to work. ("enter $65535, $31" pushes
31597- * 32 pointers and then decrements %sp by 65535.)
31598- */
31599- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31600- bad_area(regs, error_code, address);
31601- return;
31602- }
31603+ /*
31604+ * Accessing the stack below %sp is always a bug.
31605+ * The large cushion allows instructions like enter
31606+ * and pusha to work. ("enter $65535, $31" pushes
31607+ * 32 pointers and then decrements %sp by 65535.)
31608+ */
31609+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31610+ bad_area(regs, error_code, address);
31611+ return;
31612 }
31613+
31614+#ifdef CONFIG_PAX_SEGMEXEC
31615+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31616+ bad_area(regs, error_code, address);
31617+ return;
31618+ }
31619+#endif
31620+
31621 if (unlikely(expand_stack(vma, address))) {
31622 bad_area(regs, error_code, address);
31623 return;
31624@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31625 exception_exit(prev_state);
31626 }
31627 #endif /* CONFIG_TRACING */
31628+
31629+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31630+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31631+{
31632+ struct mm_struct *mm = current->mm;
31633+ unsigned long ip = regs->ip;
31634+
31635+ if (v8086_mode(regs))
31636+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31637+
31638+#ifdef CONFIG_PAX_PAGEEXEC
31639+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31640+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31641+ return true;
31642+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31643+ return true;
31644+ return false;
31645+ }
31646+#endif
31647+
31648+#ifdef CONFIG_PAX_SEGMEXEC
31649+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31650+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31651+ return true;
31652+ return false;
31653+ }
31654+#endif
31655+
31656+ return false;
31657+}
31658+#endif
31659+
31660+#ifdef CONFIG_PAX_EMUTRAMP
31661+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31662+{
31663+ int err;
31664+
31665+ do { /* PaX: libffi trampoline emulation */
31666+ unsigned char mov, jmp;
31667+ unsigned int addr1, addr2;
31668+
31669+#ifdef CONFIG_X86_64
31670+ if ((regs->ip + 9) >> 32)
31671+ break;
31672+#endif
31673+
31674+ err = get_user(mov, (unsigned char __user *)regs->ip);
31675+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31676+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31677+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31678+
31679+ if (err)
31680+ break;
31681+
31682+ if (mov == 0xB8 && jmp == 0xE9) {
31683+ regs->ax = addr1;
31684+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31685+ return 2;
31686+ }
31687+ } while (0);
31688+
31689+ do { /* PaX: gcc trampoline emulation #1 */
31690+ unsigned char mov1, mov2;
31691+ unsigned short jmp;
31692+ unsigned int addr1, addr2;
31693+
31694+#ifdef CONFIG_X86_64
31695+ if ((regs->ip + 11) >> 32)
31696+ break;
31697+#endif
31698+
31699+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31700+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31701+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31702+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31703+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31704+
31705+ if (err)
31706+ break;
31707+
31708+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31709+ regs->cx = addr1;
31710+ regs->ax = addr2;
31711+ regs->ip = addr2;
31712+ return 2;
31713+ }
31714+ } while (0);
31715+
31716+ do { /* PaX: gcc trampoline emulation #2 */
31717+ unsigned char mov, jmp;
31718+ unsigned int addr1, addr2;
31719+
31720+#ifdef CONFIG_X86_64
31721+ if ((regs->ip + 9) >> 32)
31722+ break;
31723+#endif
31724+
31725+ err = get_user(mov, (unsigned char __user *)regs->ip);
31726+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31727+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31728+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31729+
31730+ if (err)
31731+ break;
31732+
31733+ if (mov == 0xB9 && jmp == 0xE9) {
31734+ regs->cx = addr1;
31735+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31736+ return 2;
31737+ }
31738+ } while (0);
31739+
31740+ return 1; /* PaX in action */
31741+}
31742+
31743+#ifdef CONFIG_X86_64
31744+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31745+{
31746+ int err;
31747+
31748+ do { /* PaX: libffi trampoline emulation */
31749+ unsigned short mov1, mov2, jmp1;
31750+ unsigned char stcclc, jmp2;
31751+ unsigned long addr1, addr2;
31752+
31753+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31754+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31755+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31756+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31757+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31758+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31759+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31760+
31761+ if (err)
31762+ break;
31763+
31764+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31765+ regs->r11 = addr1;
31766+ regs->r10 = addr2;
31767+ if (stcclc == 0xF8)
31768+ regs->flags &= ~X86_EFLAGS_CF;
31769+ else
31770+ regs->flags |= X86_EFLAGS_CF;
31771+ regs->ip = addr1;
31772+ return 2;
31773+ }
31774+ } while (0);
31775+
31776+ do { /* PaX: gcc trampoline emulation #1 */
31777+ unsigned short mov1, mov2, jmp1;
31778+ unsigned char jmp2;
31779+ unsigned int addr1;
31780+ unsigned long addr2;
31781+
31782+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31783+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31784+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31785+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31786+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31787+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31788+
31789+ if (err)
31790+ break;
31791+
31792+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31793+ regs->r11 = addr1;
31794+ regs->r10 = addr2;
31795+ regs->ip = addr1;
31796+ return 2;
31797+ }
31798+ } while (0);
31799+
31800+ do { /* PaX: gcc trampoline emulation #2 */
31801+ unsigned short mov1, mov2, jmp1;
31802+ unsigned char jmp2;
31803+ unsigned long addr1, addr2;
31804+
31805+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31806+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31807+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31808+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31809+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31810+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31811+
31812+ if (err)
31813+ break;
31814+
31815+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31816+ regs->r11 = addr1;
31817+ regs->r10 = addr2;
31818+ regs->ip = addr1;
31819+ return 2;
31820+ }
31821+ } while (0);
31822+
31823+ return 1; /* PaX in action */
31824+}
31825+#endif
31826+
31827+/*
31828+ * PaX: decide what to do with offenders (regs->ip = fault address)
31829+ *
31830+ * returns 1 when task should be killed
31831+ * 2 when gcc trampoline was detected
31832+ */
31833+static int pax_handle_fetch_fault(struct pt_regs *regs)
31834+{
31835+ if (v8086_mode(regs))
31836+ return 1;
31837+
31838+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31839+ return 1;
31840+
31841+#ifdef CONFIG_X86_32
31842+ return pax_handle_fetch_fault_32(regs);
31843+#else
31844+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31845+ return pax_handle_fetch_fault_32(regs);
31846+ else
31847+ return pax_handle_fetch_fault_64(regs);
31848+#endif
31849+}
31850+#endif
31851+
31852+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31853+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31854+{
31855+ long i;
31856+
31857+ printk(KERN_ERR "PAX: bytes at PC: ");
31858+ for (i = 0; i < 20; i++) {
31859+ unsigned char c;
31860+ if (get_user(c, (unsigned char __force_user *)pc+i))
31861+ printk(KERN_CONT "?? ");
31862+ else
31863+ printk(KERN_CONT "%02x ", c);
31864+ }
31865+ printk("\n");
31866+
31867+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31868+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31869+ unsigned long c;
31870+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31871+#ifdef CONFIG_X86_32
31872+ printk(KERN_CONT "???????? ");
31873+#else
31874+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31875+ printk(KERN_CONT "???????? ???????? ");
31876+ else
31877+ printk(KERN_CONT "???????????????? ");
31878+#endif
31879+ } else {
31880+#ifdef CONFIG_X86_64
31881+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31882+ printk(KERN_CONT "%08x ", (unsigned int)c);
31883+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31884+ } else
31885+#endif
31886+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31887+ }
31888+ }
31889+ printk("\n");
31890+}
31891+#endif
31892+
31893+/**
31894+ * probe_kernel_write(): safely attempt to write to a location
31895+ * @dst: address to write to
31896+ * @src: pointer to the data that shall be written
31897+ * @size: size of the data chunk
31898+ *
31899+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31900+ * happens, handle that and return -EFAULT.
31901+ */
31902+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31903+{
31904+ long ret;
31905+ mm_segment_t old_fs = get_fs();
31906+
31907+ set_fs(KERNEL_DS);
31908+ pagefault_disable();
31909+ pax_open_kernel();
31910+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31911+ pax_close_kernel();
31912+ pagefault_enable();
31913+ set_fs(old_fs);
31914+
31915+ return ret ? -EFAULT : 0;
31916+}
31917diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31918index 207d9aef..69030980 100644
31919--- a/arch/x86/mm/gup.c
31920+++ b/arch/x86/mm/gup.c
31921@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31922 addr = start;
31923 len = (unsigned long) nr_pages << PAGE_SHIFT;
31924 end = start + len;
31925- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31926+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31927 (void __user *)start, len)))
31928 return 0;
31929
31930@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31931 goto slow_irqon;
31932 #endif
31933
31934+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31935+ (void __user *)start, len)))
31936+ return 0;
31937+
31938 /*
31939 * XXX: batch / limit 'nr', to avoid large irq off latency
31940 * needs some instrumenting to determine the common sizes used by
31941diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31942index 4500142..53a363c 100644
31943--- a/arch/x86/mm/highmem_32.c
31944+++ b/arch/x86/mm/highmem_32.c
31945@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31946 idx = type + KM_TYPE_NR*smp_processor_id();
31947 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31948 BUG_ON(!pte_none(*(kmap_pte-idx)));
31949+
31950+ pax_open_kernel();
31951 set_pte(kmap_pte-idx, mk_pte(page, prot));
31952+ pax_close_kernel();
31953+
31954 arch_flush_lazy_mmu_mode();
31955
31956 return (void *)vaddr;
31957diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31958index 8c9f647..57cb402 100644
31959--- a/arch/x86/mm/hugetlbpage.c
31960+++ b/arch/x86/mm/hugetlbpage.c
31961@@ -90,23 +90,24 @@ int pmd_huge_support(void)
31962 #ifdef CONFIG_HUGETLB_PAGE
31963 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31964 unsigned long addr, unsigned long len,
31965- unsigned long pgoff, unsigned long flags)
31966+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31967 {
31968 struct hstate *h = hstate_file(file);
31969 struct vm_unmapped_area_info info;
31970-
31971+
31972 info.flags = 0;
31973 info.length = len;
31974 info.low_limit = current->mm->mmap_legacy_base;
31975 info.high_limit = TASK_SIZE;
31976 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31977 info.align_offset = 0;
31978+ info.threadstack_offset = offset;
31979 return vm_unmapped_area(&info);
31980 }
31981
31982 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31983 unsigned long addr0, unsigned long len,
31984- unsigned long pgoff, unsigned long flags)
31985+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31986 {
31987 struct hstate *h = hstate_file(file);
31988 struct vm_unmapped_area_info info;
31989@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31990 info.high_limit = current->mm->mmap_base;
31991 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31992 info.align_offset = 0;
31993+ info.threadstack_offset = offset;
31994 addr = vm_unmapped_area(&info);
31995
31996 /*
31997@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31998 VM_BUG_ON(addr != -ENOMEM);
31999 info.flags = 0;
32000 info.low_limit = TASK_UNMAPPED_BASE;
32001+
32002+#ifdef CONFIG_PAX_RANDMMAP
32003+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32004+ info.low_limit += current->mm->delta_mmap;
32005+#endif
32006+
32007 info.high_limit = TASK_SIZE;
32008 addr = vm_unmapped_area(&info);
32009 }
32010@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32011 struct hstate *h = hstate_file(file);
32012 struct mm_struct *mm = current->mm;
32013 struct vm_area_struct *vma;
32014+ unsigned long pax_task_size = TASK_SIZE;
32015+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32016
32017 if (len & ~huge_page_mask(h))
32018 return -EINVAL;
32019- if (len > TASK_SIZE)
32020+
32021+#ifdef CONFIG_PAX_SEGMEXEC
32022+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32023+ pax_task_size = SEGMEXEC_TASK_SIZE;
32024+#endif
32025+
32026+ pax_task_size -= PAGE_SIZE;
32027+
32028+ if (len > pax_task_size)
32029 return -ENOMEM;
32030
32031 if (flags & MAP_FIXED) {
32032@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32033 return addr;
32034 }
32035
32036+#ifdef CONFIG_PAX_RANDMMAP
32037+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32038+#endif
32039+
32040 if (addr) {
32041 addr = ALIGN(addr, huge_page_size(h));
32042 vma = find_vma(mm, addr);
32043- if (TASK_SIZE - len >= addr &&
32044- (!vma || addr + len <= vma->vm_start))
32045+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32046 return addr;
32047 }
32048 if (mm->get_unmapped_area == arch_get_unmapped_area)
32049 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32050- pgoff, flags);
32051+ pgoff, flags, offset);
32052 else
32053 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32054- pgoff, flags);
32055+ pgoff, flags, offset);
32056 }
32057 #endif /* CONFIG_HUGETLB_PAGE */
32058
32059diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32060index f971306..e83e0f6 100644
32061--- a/arch/x86/mm/init.c
32062+++ b/arch/x86/mm/init.c
32063@@ -4,6 +4,7 @@
32064 #include <linux/swap.h>
32065 #include <linux/memblock.h>
32066 #include <linux/bootmem.h> /* for max_low_pfn */
32067+#include <linux/tboot.h>
32068
32069 #include <asm/cacheflush.h>
32070 #include <asm/e820.h>
32071@@ -17,6 +18,8 @@
32072 #include <asm/proto.h>
32073 #include <asm/dma.h> /* for MAX_DMA_PFN */
32074 #include <asm/microcode.h>
32075+#include <asm/desc.h>
32076+#include <asm/bios_ebda.h>
32077
32078 #include "mm_internal.h"
32079
32080@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32081 early_ioremap_page_table_range_init();
32082 #endif
32083
32084+#ifdef CONFIG_PAX_PER_CPU_PGD
32085+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32086+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32087+ KERNEL_PGD_PTRS);
32088+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32089+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32090+ KERNEL_PGD_PTRS);
32091+ load_cr3(get_cpu_pgd(0, kernel));
32092+#else
32093 load_cr3(swapper_pg_dir);
32094+#endif
32095+
32096 __flush_tlb_all();
32097
32098 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32099@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32100 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32101 * mmio resources as well as potential bios/acpi data regions.
32102 */
32103+
32104+#ifdef CONFIG_GRKERNSEC_KMEM
32105+static unsigned int ebda_start __read_only;
32106+static unsigned int ebda_end __read_only;
32107+#endif
32108+
32109 int devmem_is_allowed(unsigned long pagenr)
32110 {
32111- if (pagenr < 256)
32112+#ifdef CONFIG_GRKERNSEC_KMEM
32113+ /* allow BDA */
32114+ if (!pagenr)
32115 return 1;
32116+ /* allow EBDA */
32117+ if (pagenr >= ebda_start && pagenr < ebda_end)
32118+ return 1;
32119+ /* if tboot is in use, allow access to its hardcoded serial log range */
32120+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32121+ return 1;
32122+#else
32123+ if (!pagenr)
32124+ return 1;
32125+#ifdef CONFIG_VM86
32126+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32127+ return 1;
32128+#endif
32129+#endif
32130+
32131+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32132+ return 1;
32133+#ifdef CONFIG_GRKERNSEC_KMEM
32134+ /* throw out everything else below 1MB */
32135+ if (pagenr <= 256)
32136+ return 0;
32137+#endif
32138 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32139 return 0;
32140 if (!page_is_ram(pagenr))
32141@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32142 #endif
32143 }
32144
32145+#ifdef CONFIG_GRKERNSEC_KMEM
32146+static inline void gr_init_ebda(void)
32147+{
32148+ unsigned int ebda_addr;
32149+ unsigned int ebda_size = 0;
32150+
32151+ ebda_addr = get_bios_ebda();
32152+ if (ebda_addr) {
32153+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32154+ ebda_size <<= 10;
32155+ }
32156+ if (ebda_addr && ebda_size) {
32157+ ebda_start = ebda_addr >> PAGE_SHIFT;
32158+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32159+ } else {
32160+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32161+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32162+ }
32163+}
32164+#else
32165+static inline void gr_init_ebda(void) { }
32166+#endif
32167+
32168 void free_initmem(void)
32169 {
32170+#ifdef CONFIG_PAX_KERNEXEC
32171+#ifdef CONFIG_X86_32
32172+ /* PaX: limit KERNEL_CS to actual size */
32173+ unsigned long addr, limit;
32174+ struct desc_struct d;
32175+ int cpu;
32176+#else
32177+ pgd_t *pgd;
32178+ pud_t *pud;
32179+ pmd_t *pmd;
32180+ unsigned long addr, end;
32181+#endif
32182+#endif
32183+
32184+ gr_init_ebda();
32185+
32186+#ifdef CONFIG_PAX_KERNEXEC
32187+#ifdef CONFIG_X86_32
32188+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32189+ limit = (limit - 1UL) >> PAGE_SHIFT;
32190+
32191+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32192+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32193+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32194+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32195+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32196+ }
32197+
32198+ /* PaX: make KERNEL_CS read-only */
32199+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32200+ if (!paravirt_enabled())
32201+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32202+/*
32203+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32204+ pgd = pgd_offset_k(addr);
32205+ pud = pud_offset(pgd, addr);
32206+ pmd = pmd_offset(pud, addr);
32207+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32208+ }
32209+*/
32210+#ifdef CONFIG_X86_PAE
32211+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32212+/*
32213+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32214+ pgd = pgd_offset_k(addr);
32215+ pud = pud_offset(pgd, addr);
32216+ pmd = pmd_offset(pud, addr);
32217+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32218+ }
32219+*/
32220+#endif
32221+
32222+#ifdef CONFIG_MODULES
32223+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32224+#endif
32225+
32226+#else
32227+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32228+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32229+ pgd = pgd_offset_k(addr);
32230+ pud = pud_offset(pgd, addr);
32231+ pmd = pmd_offset(pud, addr);
32232+ if (!pmd_present(*pmd))
32233+ continue;
32234+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32235+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32236+ else
32237+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32238+ }
32239+
32240+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32241+ end = addr + KERNEL_IMAGE_SIZE;
32242+ for (; addr < end; addr += PMD_SIZE) {
32243+ pgd = pgd_offset_k(addr);
32244+ pud = pud_offset(pgd, addr);
32245+ pmd = pmd_offset(pud, addr);
32246+ if (!pmd_present(*pmd))
32247+ continue;
32248+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32249+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32250+ }
32251+#endif
32252+
32253+ flush_tlb_all();
32254+#endif
32255+
32256 free_init_pages("unused kernel",
32257 (unsigned long)(&__init_begin),
32258 (unsigned long)(&__init_end));
32259diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32260index e395048..cd38278 100644
32261--- a/arch/x86/mm/init_32.c
32262+++ b/arch/x86/mm/init_32.c
32263@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32264 bool __read_mostly __vmalloc_start_set = false;
32265
32266 /*
32267- * Creates a middle page table and puts a pointer to it in the
32268- * given global directory entry. This only returns the gd entry
32269- * in non-PAE compilation mode, since the middle layer is folded.
32270- */
32271-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32272-{
32273- pud_t *pud;
32274- pmd_t *pmd_table;
32275-
32276-#ifdef CONFIG_X86_PAE
32277- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32278- pmd_table = (pmd_t *)alloc_low_page();
32279- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32280- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32281- pud = pud_offset(pgd, 0);
32282- BUG_ON(pmd_table != pmd_offset(pud, 0));
32283-
32284- return pmd_table;
32285- }
32286-#endif
32287- pud = pud_offset(pgd, 0);
32288- pmd_table = pmd_offset(pud, 0);
32289-
32290- return pmd_table;
32291-}
32292-
32293-/*
32294 * Create a page table and place a pointer to it in a middle page
32295 * directory entry:
32296 */
32297@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32298 pte_t *page_table = (pte_t *)alloc_low_page();
32299
32300 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32301+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32302+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32303+#else
32304 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32305+#endif
32306 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32307 }
32308
32309 return pte_offset_kernel(pmd, 0);
32310 }
32311
32312+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32313+{
32314+ pud_t *pud;
32315+ pmd_t *pmd_table;
32316+
32317+ pud = pud_offset(pgd, 0);
32318+ pmd_table = pmd_offset(pud, 0);
32319+
32320+ return pmd_table;
32321+}
32322+
32323 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32324 {
32325 int pgd_idx = pgd_index(vaddr);
32326@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32327 int pgd_idx, pmd_idx;
32328 unsigned long vaddr;
32329 pgd_t *pgd;
32330+ pud_t *pud;
32331 pmd_t *pmd;
32332 pte_t *pte = NULL;
32333 unsigned long count = page_table_range_init_count(start, end);
32334@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32335 pgd = pgd_base + pgd_idx;
32336
32337 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32338- pmd = one_md_table_init(pgd);
32339- pmd = pmd + pmd_index(vaddr);
32340+ pud = pud_offset(pgd, vaddr);
32341+ pmd = pmd_offset(pud, vaddr);
32342+
32343+#ifdef CONFIG_X86_PAE
32344+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32345+#endif
32346+
32347 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32348 pmd++, pmd_idx++) {
32349 pte = page_table_kmap_check(one_page_table_init(pmd),
32350@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32351 }
32352 }
32353
32354-static inline int is_kernel_text(unsigned long addr)
32355+static inline int is_kernel_text(unsigned long start, unsigned long end)
32356 {
32357- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32358- return 1;
32359- return 0;
32360+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32361+ end <= ktla_ktva((unsigned long)_stext)) &&
32362+ (start >= ktla_ktva((unsigned long)_einittext) ||
32363+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32364+
32365+#ifdef CONFIG_ACPI_SLEEP
32366+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32367+#endif
32368+
32369+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32370+ return 0;
32371+ return 1;
32372 }
32373
32374 /*
32375@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32376 unsigned long last_map_addr = end;
32377 unsigned long start_pfn, end_pfn;
32378 pgd_t *pgd_base = swapper_pg_dir;
32379- int pgd_idx, pmd_idx, pte_ofs;
32380+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32381 unsigned long pfn;
32382 pgd_t *pgd;
32383+ pud_t *pud;
32384 pmd_t *pmd;
32385 pte_t *pte;
32386 unsigned pages_2m, pages_4k;
32387@@ -291,8 +295,13 @@ repeat:
32388 pfn = start_pfn;
32389 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32390 pgd = pgd_base + pgd_idx;
32391- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32392- pmd = one_md_table_init(pgd);
32393+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32394+ pud = pud_offset(pgd, 0);
32395+ pmd = pmd_offset(pud, 0);
32396+
32397+#ifdef CONFIG_X86_PAE
32398+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32399+#endif
32400
32401 if (pfn >= end_pfn)
32402 continue;
32403@@ -304,14 +313,13 @@ repeat:
32404 #endif
32405 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32406 pmd++, pmd_idx++) {
32407- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32408+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32409
32410 /*
32411 * Map with big pages if possible, otherwise
32412 * create normal page tables:
32413 */
32414 if (use_pse) {
32415- unsigned int addr2;
32416 pgprot_t prot = PAGE_KERNEL_LARGE;
32417 /*
32418 * first pass will use the same initial
32419@@ -322,11 +330,7 @@ repeat:
32420 _PAGE_PSE);
32421
32422 pfn &= PMD_MASK >> PAGE_SHIFT;
32423- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32424- PAGE_OFFSET + PAGE_SIZE-1;
32425-
32426- if (is_kernel_text(addr) ||
32427- is_kernel_text(addr2))
32428+ if (is_kernel_text(address, address + PMD_SIZE))
32429 prot = PAGE_KERNEL_LARGE_EXEC;
32430
32431 pages_2m++;
32432@@ -343,7 +347,7 @@ repeat:
32433 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32434 pte += pte_ofs;
32435 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32436- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32437+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32438 pgprot_t prot = PAGE_KERNEL;
32439 /*
32440 * first pass will use the same initial
32441@@ -351,7 +355,7 @@ repeat:
32442 */
32443 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32444
32445- if (is_kernel_text(addr))
32446+ if (is_kernel_text(address, address + PAGE_SIZE))
32447 prot = PAGE_KERNEL_EXEC;
32448
32449 pages_4k++;
32450@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32451
32452 pud = pud_offset(pgd, va);
32453 pmd = pmd_offset(pud, va);
32454- if (!pmd_present(*pmd))
32455+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32456 break;
32457
32458 /* should not be large page here */
32459@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32460
32461 static void __init pagetable_init(void)
32462 {
32463- pgd_t *pgd_base = swapper_pg_dir;
32464-
32465- permanent_kmaps_init(pgd_base);
32466+ permanent_kmaps_init(swapper_pg_dir);
32467 }
32468
32469-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32470+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32471 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32472
32473 /* user-defined highmem size */
32474@@ -787,10 +789,10 @@ void __init mem_init(void)
32475 ((unsigned long)&__init_end -
32476 (unsigned long)&__init_begin) >> 10,
32477
32478- (unsigned long)&_etext, (unsigned long)&_edata,
32479- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32480+ (unsigned long)&_sdata, (unsigned long)&_edata,
32481+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32482
32483- (unsigned long)&_text, (unsigned long)&_etext,
32484+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32485 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32486
32487 /*
32488@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32489 if (!kernel_set_to_readonly)
32490 return;
32491
32492+ start = ktla_ktva(start);
32493 pr_debug("Set kernel text: %lx - %lx for read write\n",
32494 start, start+size);
32495
32496@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32497 if (!kernel_set_to_readonly)
32498 return;
32499
32500+ start = ktla_ktva(start);
32501 pr_debug("Set kernel text: %lx - %lx for read only\n",
32502 start, start+size);
32503
32504@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32505 unsigned long start = PFN_ALIGN(_text);
32506 unsigned long size = PFN_ALIGN(_etext) - start;
32507
32508+ start = ktla_ktva(start);
32509 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32510 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32511 size >> 10);
32512diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32513index f35c66c..84b95ef 100644
32514--- a/arch/x86/mm/init_64.c
32515+++ b/arch/x86/mm/init_64.c
32516@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32517 * around without checking the pgd every time.
32518 */
32519
32520-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32521+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32522 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32523
32524 int force_personality32;
32525@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32526
32527 for (address = start; address <= end; address += PGDIR_SIZE) {
32528 const pgd_t *pgd_ref = pgd_offset_k(address);
32529+
32530+#ifdef CONFIG_PAX_PER_CPU_PGD
32531+ unsigned long cpu;
32532+#else
32533 struct page *page;
32534+#endif
32535
32536 if (pgd_none(*pgd_ref))
32537 continue;
32538
32539 spin_lock(&pgd_lock);
32540+
32541+#ifdef CONFIG_PAX_PER_CPU_PGD
32542+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32543+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32544+
32545+ if (pgd_none(*pgd))
32546+ set_pgd(pgd, *pgd_ref);
32547+ else
32548+ BUG_ON(pgd_page_vaddr(*pgd)
32549+ != pgd_page_vaddr(*pgd_ref));
32550+ pgd = pgd_offset_cpu(cpu, kernel, address);
32551+#else
32552 list_for_each_entry(page, &pgd_list, lru) {
32553 pgd_t *pgd;
32554 spinlock_t *pgt_lock;
32555@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32556 /* the pgt_lock only for Xen */
32557 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32558 spin_lock(pgt_lock);
32559+#endif
32560
32561 if (pgd_none(*pgd))
32562 set_pgd(pgd, *pgd_ref);
32563@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32564 BUG_ON(pgd_page_vaddr(*pgd)
32565 != pgd_page_vaddr(*pgd_ref));
32566
32567+#ifndef CONFIG_PAX_PER_CPU_PGD
32568 spin_unlock(pgt_lock);
32569+#endif
32570+
32571 }
32572 spin_unlock(&pgd_lock);
32573 }
32574@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32575 {
32576 if (pgd_none(*pgd)) {
32577 pud_t *pud = (pud_t *)spp_getpage();
32578- pgd_populate(&init_mm, pgd, pud);
32579+ pgd_populate_kernel(&init_mm, pgd, pud);
32580 if (pud != pud_offset(pgd, 0))
32581 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32582 pud, pud_offset(pgd, 0));
32583@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32584 {
32585 if (pud_none(*pud)) {
32586 pmd_t *pmd = (pmd_t *) spp_getpage();
32587- pud_populate(&init_mm, pud, pmd);
32588+ pud_populate_kernel(&init_mm, pud, pmd);
32589 if (pmd != pmd_offset(pud, 0))
32590 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32591 pmd, pmd_offset(pud, 0));
32592@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32593 pmd = fill_pmd(pud, vaddr);
32594 pte = fill_pte(pmd, vaddr);
32595
32596+ pax_open_kernel();
32597 set_pte(pte, new_pte);
32598+ pax_close_kernel();
32599
32600 /*
32601 * It's enough to flush this one mapping.
32602@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32603 pgd = pgd_offset_k((unsigned long)__va(phys));
32604 if (pgd_none(*pgd)) {
32605 pud = (pud_t *) spp_getpage();
32606- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32607- _PAGE_USER));
32608+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32609 }
32610 pud = pud_offset(pgd, (unsigned long)__va(phys));
32611 if (pud_none(*pud)) {
32612 pmd = (pmd_t *) spp_getpage();
32613- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32614- _PAGE_USER));
32615+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32616 }
32617 pmd = pmd_offset(pud, phys);
32618 BUG_ON(!pmd_none(*pmd));
32619@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32620 prot);
32621
32622 spin_lock(&init_mm.page_table_lock);
32623- pud_populate(&init_mm, pud, pmd);
32624+ pud_populate_kernel(&init_mm, pud, pmd);
32625 spin_unlock(&init_mm.page_table_lock);
32626 }
32627 __flush_tlb_all();
32628@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32629 page_size_mask);
32630
32631 spin_lock(&init_mm.page_table_lock);
32632- pgd_populate(&init_mm, pgd, pud);
32633+ pgd_populate_kernel(&init_mm, pgd, pud);
32634 spin_unlock(&init_mm.page_table_lock);
32635 pgd_changed = true;
32636 }
32637@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32638 static struct vm_area_struct gate_vma = {
32639 .vm_start = VSYSCALL_START,
32640 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32641- .vm_page_prot = PAGE_READONLY_EXEC,
32642- .vm_flags = VM_READ | VM_EXEC
32643+ .vm_page_prot = PAGE_READONLY,
32644+ .vm_flags = VM_READ
32645 };
32646
32647 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32648@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32649
32650 const char *arch_vma_name(struct vm_area_struct *vma)
32651 {
32652- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32653+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32654 return "[vdso]";
32655 if (vma == &gate_vma)
32656 return "[vsyscall]";
32657diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32658index 7b179b4..6bd17777 100644
32659--- a/arch/x86/mm/iomap_32.c
32660+++ b/arch/x86/mm/iomap_32.c
32661@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32662 type = kmap_atomic_idx_push();
32663 idx = type + KM_TYPE_NR * smp_processor_id();
32664 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32665+
32666+ pax_open_kernel();
32667 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32668+ pax_close_kernel();
32669+
32670 arch_flush_lazy_mmu_mode();
32671
32672 return (void *)vaddr;
32673diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32674index 799580c..72f9fe0 100644
32675--- a/arch/x86/mm/ioremap.c
32676+++ b/arch/x86/mm/ioremap.c
32677@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32678 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32679 int is_ram = page_is_ram(pfn);
32680
32681- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32682+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32683 return NULL;
32684 WARN_ON_ONCE(is_ram);
32685 }
32686@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32687 *
32688 * Caller must ensure there is only one unmapping for the same pointer.
32689 */
32690-void iounmap(volatile void __iomem *addr)
32691+void iounmap(const volatile void __iomem *addr)
32692 {
32693 struct vm_struct *p, *o;
32694
32695@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32696
32697 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32698 if (page_is_ram(start >> PAGE_SHIFT))
32699+#ifdef CONFIG_HIGHMEM
32700+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32701+#endif
32702 return __va(phys);
32703
32704 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32705@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32706 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32707 {
32708 if (page_is_ram(phys >> PAGE_SHIFT))
32709+#ifdef CONFIG_HIGHMEM
32710+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32711+#endif
32712 return;
32713
32714 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32715@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32716 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32717
32718 static __initdata int after_paging_init;
32719-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32720+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32721
32722 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32723 {
32724@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32725 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32726
32727 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32728- memset(bm_pte, 0, sizeof(bm_pte));
32729- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32730+ pmd_populate_user(&init_mm, pmd, bm_pte);
32731
32732 /*
32733 * The boot-ioremap range spans multiple pmds, for which
32734diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32735index d87dd6d..bf3fa66 100644
32736--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32737+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32738@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32739 * memory (e.g. tracked pages)? For now, we need this to avoid
32740 * invoking kmemcheck for PnP BIOS calls.
32741 */
32742- if (regs->flags & X86_VM_MASK)
32743+ if (v8086_mode(regs))
32744 return false;
32745- if (regs->cs != __KERNEL_CS)
32746+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32747 return false;
32748
32749 pte = kmemcheck_pte_lookup(address);
32750diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32751index 25e7e13..1964579 100644
32752--- a/arch/x86/mm/mmap.c
32753+++ b/arch/x86/mm/mmap.c
32754@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32755 * Leave an at least ~128 MB hole with possible stack randomization.
32756 */
32757 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32758-#define MAX_GAP (TASK_SIZE/6*5)
32759+#define MAX_GAP (pax_task_size/6*5)
32760
32761 static int mmap_is_legacy(void)
32762 {
32763@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32764 return rnd << PAGE_SHIFT;
32765 }
32766
32767-static unsigned long mmap_base(void)
32768+static unsigned long mmap_base(struct mm_struct *mm)
32769 {
32770 unsigned long gap = rlimit(RLIMIT_STACK);
32771+ unsigned long pax_task_size = TASK_SIZE;
32772+
32773+#ifdef CONFIG_PAX_SEGMEXEC
32774+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32775+ pax_task_size = SEGMEXEC_TASK_SIZE;
32776+#endif
32777
32778 if (gap < MIN_GAP)
32779 gap = MIN_GAP;
32780 else if (gap > MAX_GAP)
32781 gap = MAX_GAP;
32782
32783- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32784+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32785 }
32786
32787 /*
32788 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32789 * does, but not when emulating X86_32
32790 */
32791-static unsigned long mmap_legacy_base(void)
32792+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32793 {
32794- if (mmap_is_ia32())
32795+ if (mmap_is_ia32()) {
32796+
32797+#ifdef CONFIG_PAX_SEGMEXEC
32798+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32799+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32800+ else
32801+#endif
32802+
32803 return TASK_UNMAPPED_BASE;
32804- else
32805+ } else
32806 return TASK_UNMAPPED_BASE + mmap_rnd();
32807 }
32808
32809@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32810 */
32811 void arch_pick_mmap_layout(struct mm_struct *mm)
32812 {
32813- mm->mmap_legacy_base = mmap_legacy_base();
32814- mm->mmap_base = mmap_base();
32815+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32816+ mm->mmap_base = mmap_base(mm);
32817+
32818+#ifdef CONFIG_PAX_RANDMMAP
32819+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32820+ mm->mmap_legacy_base += mm->delta_mmap;
32821+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32822+ }
32823+#endif
32824
32825 if (mmap_is_legacy()) {
32826 mm->mmap_base = mm->mmap_legacy_base;
32827diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32828index 0057a7a..95c7edd 100644
32829--- a/arch/x86/mm/mmio-mod.c
32830+++ b/arch/x86/mm/mmio-mod.c
32831@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32832 break;
32833 default:
32834 {
32835- unsigned char *ip = (unsigned char *)instptr;
32836+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32837 my_trace->opcode = MMIO_UNKNOWN_OP;
32838 my_trace->width = 0;
32839 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32840@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32841 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32842 void __iomem *addr)
32843 {
32844- static atomic_t next_id;
32845+ static atomic_unchecked_t next_id;
32846 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32847 /* These are page-unaligned. */
32848 struct mmiotrace_map map = {
32849@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32850 .private = trace
32851 },
32852 .phys = offset,
32853- .id = atomic_inc_return(&next_id)
32854+ .id = atomic_inc_return_unchecked(&next_id)
32855 };
32856 map.map_id = trace->id;
32857
32858@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32859 ioremap_trace_core(offset, size, addr);
32860 }
32861
32862-static void iounmap_trace_core(volatile void __iomem *addr)
32863+static void iounmap_trace_core(const volatile void __iomem *addr)
32864 {
32865 struct mmiotrace_map map = {
32866 .phys = 0,
32867@@ -328,7 +328,7 @@ not_enabled:
32868 }
32869 }
32870
32871-void mmiotrace_iounmap(volatile void __iomem *addr)
32872+void mmiotrace_iounmap(const volatile void __iomem *addr)
32873 {
32874 might_sleep();
32875 if (is_enabled()) /* recheck and proper locking in *_core() */
32876diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32877index 27aa0455..0eb1406 100644
32878--- a/arch/x86/mm/numa.c
32879+++ b/arch/x86/mm/numa.c
32880@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32881 return true;
32882 }
32883
32884-static int __init numa_register_memblks(struct numa_meminfo *mi)
32885+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32886 {
32887 unsigned long uninitialized_var(pfn_align);
32888 int i, nid;
32889diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32890index 461bc82..4e091a3 100644
32891--- a/arch/x86/mm/pageattr-test.c
32892+++ b/arch/x86/mm/pageattr-test.c
32893@@ -35,7 +35,7 @@ enum {
32894
32895 static int pte_testbit(pte_t pte)
32896 {
32897- return pte_flags(pte) & _PAGE_UNUSED1;
32898+ return pte_flags(pte) & _PAGE_CPA_TEST;
32899 }
32900
32901 struct split_state {
32902diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32903index a348868..3c64310 100644
32904--- a/arch/x86/mm/pageattr.c
32905+++ b/arch/x86/mm/pageattr.c
32906@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32907 */
32908 #ifdef CONFIG_PCI_BIOS
32909 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32910- pgprot_val(forbidden) |= _PAGE_NX;
32911+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32912 #endif
32913
32914 /*
32915@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32916 * Does not cover __inittext since that is gone later on. On
32917 * 64bit we do not enforce !NX on the low mapping
32918 */
32919- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32920- pgprot_val(forbidden) |= _PAGE_NX;
32921+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32922+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32923
32924+#ifdef CONFIG_DEBUG_RODATA
32925 /*
32926 * The .rodata section needs to be read-only. Using the pfn
32927 * catches all aliases.
32928@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32929 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32930 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32931 pgprot_val(forbidden) |= _PAGE_RW;
32932+#endif
32933
32934 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32935 /*
32936@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32937 }
32938 #endif
32939
32940+#ifdef CONFIG_PAX_KERNEXEC
32941+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32942+ pgprot_val(forbidden) |= _PAGE_RW;
32943+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32944+ }
32945+#endif
32946+
32947 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32948
32949 return prot;
32950@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32951 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32952 {
32953 /* change init_mm */
32954+ pax_open_kernel();
32955 set_pte_atomic(kpte, pte);
32956+
32957 #ifdef CONFIG_X86_32
32958 if (!SHARED_KERNEL_PMD) {
32959+
32960+#ifdef CONFIG_PAX_PER_CPU_PGD
32961+ unsigned long cpu;
32962+#else
32963 struct page *page;
32964+#endif
32965
32966+#ifdef CONFIG_PAX_PER_CPU_PGD
32967+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32968+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32969+#else
32970 list_for_each_entry(page, &pgd_list, lru) {
32971- pgd_t *pgd;
32972+ pgd_t *pgd = (pgd_t *)page_address(page);
32973+#endif
32974+
32975 pud_t *pud;
32976 pmd_t *pmd;
32977
32978- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32979+ pgd += pgd_index(address);
32980 pud = pud_offset(pgd, address);
32981 pmd = pmd_offset(pud, address);
32982 set_pte_atomic((pte_t *)pmd, pte);
32983 }
32984 }
32985 #endif
32986+ pax_close_kernel();
32987 }
32988
32989 static int
32990diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32991index 6574388..87e9bef 100644
32992--- a/arch/x86/mm/pat.c
32993+++ b/arch/x86/mm/pat.c
32994@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32995
32996 if (!entry) {
32997 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32998- current->comm, current->pid, start, end - 1);
32999+ current->comm, task_pid_nr(current), start, end - 1);
33000 return -EINVAL;
33001 }
33002
33003@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33004
33005 while (cursor < to) {
33006 if (!devmem_is_allowed(pfn)) {
33007- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33008- current->comm, from, to - 1);
33009+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33010+ current->comm, from, to - 1, cursor);
33011 return 0;
33012 }
33013 cursor += PAGE_SIZE;
33014@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33015 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33016 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33017 "for [mem %#010Lx-%#010Lx]\n",
33018- current->comm, current->pid,
33019+ current->comm, task_pid_nr(current),
33020 cattr_name(flags),
33021 base, (unsigned long long)(base + size-1));
33022 return -EINVAL;
33023@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33024 flags = lookup_memtype(paddr);
33025 if (want_flags != flags) {
33026 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33027- current->comm, current->pid,
33028+ current->comm, task_pid_nr(current),
33029 cattr_name(want_flags),
33030 (unsigned long long)paddr,
33031 (unsigned long long)(paddr + size - 1),
33032@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33033 free_memtype(paddr, paddr + size);
33034 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33035 " for [mem %#010Lx-%#010Lx], got %s\n",
33036- current->comm, current->pid,
33037+ current->comm, task_pid_nr(current),
33038 cattr_name(want_flags),
33039 (unsigned long long)paddr,
33040 (unsigned long long)(paddr + size - 1),
33041diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33042index 415f6c4..d319983 100644
33043--- a/arch/x86/mm/pat_rbtree.c
33044+++ b/arch/x86/mm/pat_rbtree.c
33045@@ -160,7 +160,7 @@ success:
33046
33047 failure:
33048 printk(KERN_INFO "%s:%d conflicting memory types "
33049- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33050+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33051 end, cattr_name(found_type), cattr_name(match->type));
33052 return -EBUSY;
33053 }
33054diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33055index 9f0614d..92ae64a 100644
33056--- a/arch/x86/mm/pf_in.c
33057+++ b/arch/x86/mm/pf_in.c
33058@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33059 int i;
33060 enum reason_type rv = OTHERS;
33061
33062- p = (unsigned char *)ins_addr;
33063+ p = (unsigned char *)ktla_ktva(ins_addr);
33064 p += skip_prefix(p, &prf);
33065 p += get_opcode(p, &opcode);
33066
33067@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33068 struct prefix_bits prf;
33069 int i;
33070
33071- p = (unsigned char *)ins_addr;
33072+ p = (unsigned char *)ktla_ktva(ins_addr);
33073 p += skip_prefix(p, &prf);
33074 p += get_opcode(p, &opcode);
33075
33076@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33077 struct prefix_bits prf;
33078 int i;
33079
33080- p = (unsigned char *)ins_addr;
33081+ p = (unsigned char *)ktla_ktva(ins_addr);
33082 p += skip_prefix(p, &prf);
33083 p += get_opcode(p, &opcode);
33084
33085@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33086 struct prefix_bits prf;
33087 int i;
33088
33089- p = (unsigned char *)ins_addr;
33090+ p = (unsigned char *)ktla_ktva(ins_addr);
33091 p += skip_prefix(p, &prf);
33092 p += get_opcode(p, &opcode);
33093 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33094@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33095 struct prefix_bits prf;
33096 int i;
33097
33098- p = (unsigned char *)ins_addr;
33099+ p = (unsigned char *)ktla_ktva(ins_addr);
33100 p += skip_prefix(p, &prf);
33101 p += get_opcode(p, &opcode);
33102 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33103diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33104index c96314a..433b127 100644
33105--- a/arch/x86/mm/pgtable.c
33106+++ b/arch/x86/mm/pgtable.c
33107@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33108 list_del(&page->lru);
33109 }
33110
33111-#define UNSHARED_PTRS_PER_PGD \
33112- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33114+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33115
33116+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33117+{
33118+ unsigned int count = USER_PGD_PTRS;
33119
33120+ if (!pax_user_shadow_base)
33121+ return;
33122+
33123+ while (count--)
33124+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33125+}
33126+#endif
33127+
33128+#ifdef CONFIG_PAX_PER_CPU_PGD
33129+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33130+{
33131+ unsigned int count = USER_PGD_PTRS;
33132+
33133+ while (count--) {
33134+ pgd_t pgd;
33135+
33136+#ifdef CONFIG_X86_64
33137+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33138+#else
33139+ pgd = *src++;
33140+#endif
33141+
33142+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33143+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33144+#endif
33145+
33146+ *dst++ = pgd;
33147+ }
33148+
33149+}
33150+#endif
33151+
33152+#ifdef CONFIG_X86_64
33153+#define pxd_t pud_t
33154+#define pyd_t pgd_t
33155+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33156+#define pgtable_pxd_page_ctor(page) true
33157+#define pgtable_pxd_page_dtor(page)
33158+#define pxd_free(mm, pud) pud_free((mm), (pud))
33159+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33160+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33161+#define PYD_SIZE PGDIR_SIZE
33162+#else
33163+#define pxd_t pmd_t
33164+#define pyd_t pud_t
33165+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33166+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33167+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33168+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33169+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33170+#define pyd_offset(mm, address) pud_offset((mm), (address))
33171+#define PYD_SIZE PUD_SIZE
33172+#endif
33173+
33174+#ifdef CONFIG_PAX_PER_CPU_PGD
33175+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33176+static inline void pgd_dtor(pgd_t *pgd) {}
33177+#else
33178 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33179 {
33180 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33181@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33182 pgd_list_del(pgd);
33183 spin_unlock(&pgd_lock);
33184 }
33185+#endif
33186
33187 /*
33188 * List of all pgd's needed for non-PAE so it can invalidate entries
33189@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33190 * -- nyc
33191 */
33192
33193-#ifdef CONFIG_X86_PAE
33194+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33195 /*
33196 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33197 * updating the top-level pagetable entries to guarantee the
33198@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33199 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33200 * and initialize the kernel pmds here.
33201 */
33202-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33203+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33204
33205 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33206 {
33207@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33208 */
33209 flush_tlb_mm(mm);
33210 }
33211+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33212+#define PREALLOCATED_PXDS USER_PGD_PTRS
33213 #else /* !CONFIG_X86_PAE */
33214
33215 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33216-#define PREALLOCATED_PMDS 0
33217+#define PREALLOCATED_PXDS 0
33218
33219 #endif /* CONFIG_X86_PAE */
33220
33221-static void free_pmds(pmd_t *pmds[])
33222+static void free_pxds(pxd_t *pxds[])
33223 {
33224 int i;
33225
33226- for(i = 0; i < PREALLOCATED_PMDS; i++)
33227- if (pmds[i]) {
33228- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33229- free_page((unsigned long)pmds[i]);
33230+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33231+ if (pxds[i]) {
33232+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33233+ free_page((unsigned long)pxds[i]);
33234 }
33235 }
33236
33237-static int preallocate_pmds(pmd_t *pmds[])
33238+static int preallocate_pxds(pxd_t *pxds[])
33239 {
33240 int i;
33241 bool failed = false;
33242
33243- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33244- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33245- if (!pmd)
33246+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33247+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33248+ if (!pxd)
33249 failed = true;
33250- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33251- free_page((unsigned long)pmd);
33252- pmd = NULL;
33253+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33254+ free_page((unsigned long)pxd);
33255+ pxd = NULL;
33256 failed = true;
33257 }
33258- pmds[i] = pmd;
33259+ pxds[i] = pxd;
33260 }
33261
33262 if (failed) {
33263- free_pmds(pmds);
33264+ free_pxds(pxds);
33265 return -ENOMEM;
33266 }
33267
33268@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33269 * preallocate which never got a corresponding vma will need to be
33270 * freed manually.
33271 */
33272-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33273+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33274 {
33275 int i;
33276
33277- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33278+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33279 pgd_t pgd = pgdp[i];
33280
33281 if (pgd_val(pgd) != 0) {
33282- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33283+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33284
33285- pgdp[i] = native_make_pgd(0);
33286+ set_pgd(pgdp + i, native_make_pgd(0));
33287
33288- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33289- pmd_free(mm, pmd);
33290+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33291+ pxd_free(mm, pxd);
33292 }
33293 }
33294 }
33295
33296-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33297+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33298 {
33299- pud_t *pud;
33300+ pyd_t *pyd;
33301 int i;
33302
33303- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33304+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33305 return;
33306
33307- pud = pud_offset(pgd, 0);
33308-
33309- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33310- pmd_t *pmd = pmds[i];
33311+#ifdef CONFIG_X86_64
33312+ pyd = pyd_offset(mm, 0L);
33313+#else
33314+ pyd = pyd_offset(pgd, 0L);
33315+#endif
33316
33317+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33318+ pxd_t *pxd = pxds[i];
33319 if (i >= KERNEL_PGD_BOUNDARY)
33320- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33321- sizeof(pmd_t) * PTRS_PER_PMD);
33322+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33323+ sizeof(pxd_t) * PTRS_PER_PMD);
33324
33325- pud_populate(mm, pud, pmd);
33326+ pyd_populate(mm, pyd, pxd);
33327 }
33328 }
33329
33330 pgd_t *pgd_alloc(struct mm_struct *mm)
33331 {
33332 pgd_t *pgd;
33333- pmd_t *pmds[PREALLOCATED_PMDS];
33334+ pxd_t *pxds[PREALLOCATED_PXDS];
33335
33336 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33337
33338@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33339
33340 mm->pgd = pgd;
33341
33342- if (preallocate_pmds(pmds) != 0)
33343+ if (preallocate_pxds(pxds) != 0)
33344 goto out_free_pgd;
33345
33346 if (paravirt_pgd_alloc(mm) != 0)
33347- goto out_free_pmds;
33348+ goto out_free_pxds;
33349
33350 /*
33351 * Make sure that pre-populating the pmds is atomic with
33352@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33353 spin_lock(&pgd_lock);
33354
33355 pgd_ctor(mm, pgd);
33356- pgd_prepopulate_pmd(mm, pgd, pmds);
33357+ pgd_prepopulate_pxd(mm, pgd, pxds);
33358
33359 spin_unlock(&pgd_lock);
33360
33361 return pgd;
33362
33363-out_free_pmds:
33364- free_pmds(pmds);
33365+out_free_pxds:
33366+ free_pxds(pxds);
33367 out_free_pgd:
33368 free_page((unsigned long)pgd);
33369 out:
33370@@ -313,7 +380,7 @@ out:
33371
33372 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33373 {
33374- pgd_mop_up_pmds(mm, pgd);
33375+ pgd_mop_up_pxds(mm, pgd);
33376 pgd_dtor(pgd);
33377 paravirt_pgd_free(mm, pgd);
33378 free_page((unsigned long)pgd);
33379diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33380index a69bcb8..19068ab 100644
33381--- a/arch/x86/mm/pgtable_32.c
33382+++ b/arch/x86/mm/pgtable_32.c
33383@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33384 return;
33385 }
33386 pte = pte_offset_kernel(pmd, vaddr);
33387+
33388+ pax_open_kernel();
33389 if (pte_val(pteval))
33390 set_pte_at(&init_mm, vaddr, pte, pteval);
33391 else
33392 pte_clear(&init_mm, vaddr, pte);
33393+ pax_close_kernel();
33394
33395 /*
33396 * It's enough to flush this one mapping.
33397diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33398index e666cbb..61788c45 100644
33399--- a/arch/x86/mm/physaddr.c
33400+++ b/arch/x86/mm/physaddr.c
33401@@ -10,7 +10,7 @@
33402 #ifdef CONFIG_X86_64
33403
33404 #ifdef CONFIG_DEBUG_VIRTUAL
33405-unsigned long __phys_addr(unsigned long x)
33406+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33407 {
33408 unsigned long y = x - __START_KERNEL_map;
33409
33410@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33411 #else
33412
33413 #ifdef CONFIG_DEBUG_VIRTUAL
33414-unsigned long __phys_addr(unsigned long x)
33415+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33416 {
33417 unsigned long phys_addr = x - PAGE_OFFSET;
33418 /* VMALLOC_* aren't constants */
33419diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33420index 90555bf..f5f1828 100644
33421--- a/arch/x86/mm/setup_nx.c
33422+++ b/arch/x86/mm/setup_nx.c
33423@@ -5,8 +5,10 @@
33424 #include <asm/pgtable.h>
33425 #include <asm/proto.h>
33426
33427+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33428 static int disable_nx;
33429
33430+#ifndef CONFIG_PAX_PAGEEXEC
33431 /*
33432 * noexec = on|off
33433 *
33434@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33435 return 0;
33436 }
33437 early_param("noexec", noexec_setup);
33438+#endif
33439+
33440+#endif
33441
33442 void x86_configure_nx(void)
33443 {
33444+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33445 if (cpu_has_nx && !disable_nx)
33446 __supported_pte_mask |= _PAGE_NX;
33447 else
33448+#endif
33449 __supported_pte_mask &= ~_PAGE_NX;
33450 }
33451
33452diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33453index dd8dda1..9e9b0f6 100644
33454--- a/arch/x86/mm/tlb.c
33455+++ b/arch/x86/mm/tlb.c
33456@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33457 BUG();
33458 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33459 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33460+
33461+#ifndef CONFIG_PAX_PER_CPU_PGD
33462 load_cr3(swapper_pg_dir);
33463+#endif
33464+
33465 }
33466 }
33467 EXPORT_SYMBOL_GPL(leave_mm);
33468diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33469new file mode 100644
33470index 0000000..dace51c
33471--- /dev/null
33472+++ b/arch/x86/mm/uderef_64.c
33473@@ -0,0 +1,37 @@
33474+#include <linux/mm.h>
33475+#include <asm/pgtable.h>
33476+#include <asm/uaccess.h>
33477+
33478+#ifdef CONFIG_PAX_MEMORY_UDEREF
33479+/* PaX: due to the special call convention these functions must
33480+ * - remain leaf functions under all configurations,
33481+ * - never be called directly, only dereferenced from the wrappers.
33482+ */
33483+void __pax_open_userland(void)
33484+{
33485+ unsigned int cpu;
33486+
33487+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33488+ return;
33489+
33490+ cpu = raw_get_cpu();
33491+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33492+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33493+ raw_put_cpu_no_resched();
33494+}
33495+EXPORT_SYMBOL(__pax_open_userland);
33496+
33497+void __pax_close_userland(void)
33498+{
33499+ unsigned int cpu;
33500+
33501+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33502+ return;
33503+
33504+ cpu = raw_get_cpu();
33505+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33506+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33507+ raw_put_cpu_no_resched();
33508+}
33509+EXPORT_SYMBOL(__pax_close_userland);
33510+#endif
33511diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33512index 0149575..f746de8 100644
33513--- a/arch/x86/net/bpf_jit.S
33514+++ b/arch/x86/net/bpf_jit.S
33515@@ -9,6 +9,7 @@
33516 */
33517 #include <linux/linkage.h>
33518 #include <asm/dwarf2.h>
33519+#include <asm/alternative-asm.h>
33520
33521 /*
33522 * Calling convention :
33523@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33524 jle bpf_slow_path_word
33525 mov (SKBDATA,%rsi),%eax
33526 bswap %eax /* ntohl() */
33527+ pax_force_retaddr
33528 ret
33529
33530 sk_load_half:
33531@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33532 jle bpf_slow_path_half
33533 movzwl (SKBDATA,%rsi),%eax
33534 rol $8,%ax # ntohs()
33535+ pax_force_retaddr
33536 ret
33537
33538 sk_load_byte:
33539@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33540 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33541 jle bpf_slow_path_byte
33542 movzbl (SKBDATA,%rsi),%eax
33543+ pax_force_retaddr
33544 ret
33545
33546 /**
33547@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33548 movzbl (SKBDATA,%rsi),%ebx
33549 and $15,%bl
33550 shl $2,%bl
33551+ pax_force_retaddr
33552 ret
33553
33554 /* rsi contains offset and can be scratched */
33555@@ -109,6 +114,7 @@ bpf_slow_path_word:
33556 js bpf_error
33557 mov -12(%rbp),%eax
33558 bswap %eax
33559+ pax_force_retaddr
33560 ret
33561
33562 bpf_slow_path_half:
33563@@ -117,12 +123,14 @@ bpf_slow_path_half:
33564 mov -12(%rbp),%ax
33565 rol $8,%ax
33566 movzwl %ax,%eax
33567+ pax_force_retaddr
33568 ret
33569
33570 bpf_slow_path_byte:
33571 bpf_slow_path_common(1)
33572 js bpf_error
33573 movzbl -12(%rbp),%eax
33574+ pax_force_retaddr
33575 ret
33576
33577 bpf_slow_path_byte_msh:
33578@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33579 and $15,%al
33580 shl $2,%al
33581 xchg %eax,%ebx
33582+ pax_force_retaddr
33583 ret
33584
33585 #define sk_negative_common(SIZE) \
33586@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33587 sk_negative_common(4)
33588 mov (%rax), %eax
33589 bswap %eax
33590+ pax_force_retaddr
33591 ret
33592
33593 bpf_slow_path_half_neg:
33594@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33595 mov (%rax),%ax
33596 rol $8,%ax
33597 movzwl %ax,%eax
33598+ pax_force_retaddr
33599 ret
33600
33601 bpf_slow_path_byte_neg:
33602@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33603 .globl sk_load_byte_negative_offset
33604 sk_negative_common(1)
33605 movzbl (%rax), %eax
33606+ pax_force_retaddr
33607 ret
33608
33609 bpf_slow_path_byte_msh_neg:
33610@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33611 and $15,%al
33612 shl $2,%al
33613 xchg %eax,%ebx
33614+ pax_force_retaddr
33615 ret
33616
33617 bpf_error:
33618@@ -197,4 +210,5 @@ bpf_error:
33619 xor %eax,%eax
33620 mov -8(%rbp),%rbx
33621 leaveq
33622+ pax_force_retaddr
33623 ret
33624diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33625index 4ed75dd..3cf24f0b 100644
33626--- a/arch/x86/net/bpf_jit_comp.c
33627+++ b/arch/x86/net/bpf_jit_comp.c
33628@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33629 return ptr + len;
33630 }
33631
33632+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33633+#define MAX_INSTR_CODE_SIZE 96
33634+#else
33635+#define MAX_INSTR_CODE_SIZE 64
33636+#endif
33637+
33638 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33639
33640 #define EMIT1(b1) EMIT(b1, 1)
33641 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33642 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33643 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33644+
33645+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33646+/* original constant will appear in ecx */
33647+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33648+do { \
33649+ /* mov ecx, randkey */ \
33650+ EMIT1(0xb9); \
33651+ EMIT(_key, 4); \
33652+ /* xor ecx, randkey ^ off */ \
33653+ EMIT2(0x81, 0xf1); \
33654+ EMIT((_key) ^ (_off), 4); \
33655+} while (0)
33656+
33657+#define EMIT1_off32(b1, _off) \
33658+do { \
33659+ switch (b1) { \
33660+ case 0x05: /* add eax, imm32 */ \
33661+ case 0x2d: /* sub eax, imm32 */ \
33662+ case 0x25: /* and eax, imm32 */ \
33663+ case 0x0d: /* or eax, imm32 */ \
33664+ case 0xb8: /* mov eax, imm32 */ \
33665+ case 0x35: /* xor eax, imm32 */ \
33666+ case 0x3d: /* cmp eax, imm32 */ \
33667+ case 0xa9: /* test eax, imm32 */ \
33668+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33669+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33670+ break; \
33671+ case 0xbb: /* mov ebx, imm32 */ \
33672+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33673+ /* mov ebx, ecx */ \
33674+ EMIT2(0x89, 0xcb); \
33675+ break; \
33676+ case 0xbe: /* mov esi, imm32 */ \
33677+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33678+ /* mov esi, ecx */ \
33679+ EMIT2(0x89, 0xce); \
33680+ break; \
33681+ case 0xe8: /* call rel imm32, always to known funcs */ \
33682+ EMIT1(b1); \
33683+ EMIT(_off, 4); \
33684+ break; \
33685+ case 0xe9: /* jmp rel imm32 */ \
33686+ EMIT1(b1); \
33687+ EMIT(_off, 4); \
33688+ /* prevent fall-through, we're not called if off = 0 */ \
33689+ EMIT(0xcccccccc, 4); \
33690+ EMIT(0xcccccccc, 4); \
33691+ break; \
33692+ default: \
33693+ BUILD_BUG(); \
33694+ } \
33695+} while (0)
33696+
33697+#define EMIT2_off32(b1, b2, _off) \
33698+do { \
33699+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33700+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33701+ EMIT(randkey, 4); \
33702+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33703+ EMIT((_off) - randkey, 4); \
33704+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33705+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33706+ /* imul eax, ecx */ \
33707+ EMIT3(0x0f, 0xaf, 0xc1); \
33708+ } else { \
33709+ BUILD_BUG(); \
33710+ } \
33711+} while (0)
33712+#else
33713 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33714+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33715+#endif
33716
33717 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33718 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33719@@ -91,6 +168,24 @@ do { \
33720 #define X86_JBE 0x76
33721 #define X86_JA 0x77
33722
33723+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33724+#define APPEND_FLOW_VERIFY() \
33725+do { \
33726+ /* mov ecx, randkey */ \
33727+ EMIT1(0xb9); \
33728+ EMIT(randkey, 4); \
33729+ /* cmp ecx, randkey */ \
33730+ EMIT2(0x81, 0xf9); \
33731+ EMIT(randkey, 4); \
33732+ /* jz after 8 int 3s */ \
33733+ EMIT2(0x74, 0x08); \
33734+ EMIT(0xcccccccc, 4); \
33735+ EMIT(0xcccccccc, 4); \
33736+} while (0)
33737+#else
33738+#define APPEND_FLOW_VERIFY() do { } while (0)
33739+#endif
33740+
33741 #define EMIT_COND_JMP(op, offset) \
33742 do { \
33743 if (is_near(offset)) \
33744@@ -98,6 +193,7 @@ do { \
33745 else { \
33746 EMIT2(0x0f, op + 0x10); \
33747 EMIT(offset, 4); /* jxx .+off32 */ \
33748+ APPEND_FLOW_VERIFY(); \
33749 } \
33750 } while (0)
33751
33752@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33753 return -1;
33754 }
33755
33756-struct bpf_binary_header {
33757- unsigned int pages;
33758- /* Note : for security reasons, bpf code will follow a randomly
33759- * sized amount of int3 instructions
33760- */
33761- u8 image[];
33762-};
33763-
33764-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33765+/* Note : for security reasons, bpf code will follow a randomly
33766+ * sized amount of int3 instructions
33767+ */
33768+static u8 *bpf_alloc_binary(unsigned int proglen,
33769 u8 **image_ptr)
33770 {
33771 unsigned int sz, hole;
33772- struct bpf_binary_header *header;
33773+ u8 *header;
33774
33775 /* Most of BPF filters are really small,
33776 * but if some of them fill a page, allow at least
33777 * 128 extra bytes to insert a random section of int3
33778 */
33779- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33780- header = module_alloc(sz);
33781+ sz = round_up(proglen + 128, PAGE_SIZE);
33782+ header = module_alloc_exec(sz);
33783 if (!header)
33784 return NULL;
33785
33786+ pax_open_kernel();
33787 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33788+ pax_close_kernel();
33789
33790- header->pages = sz / PAGE_SIZE;
33791- hole = sz - (proglen + sizeof(*header));
33792+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33793
33794 /* insert a random number of int3 instructions before BPF code */
33795- *image_ptr = &header->image[prandom_u32() % hole];
33796+ *image_ptr = &header[prandom_u32() % hole];
33797 return header;
33798 }
33799
33800 void bpf_jit_compile(struct sk_filter *fp)
33801 {
33802- u8 temp[64];
33803+ u8 temp[MAX_INSTR_CODE_SIZE];
33804 u8 *prog;
33805 unsigned int proglen, oldproglen = 0;
33806 int ilen, i;
33807 int t_offset, f_offset;
33808 u8 t_op, f_op, seen = 0, pass;
33809 u8 *image = NULL;
33810- struct bpf_binary_header *header = NULL;
33811+ u8 *header = NULL;
33812 u8 *func;
33813 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33814 unsigned int cleanup_addr; /* epilogue code offset */
33815 unsigned int *addrs;
33816 const struct sock_filter *filter = fp->insns;
33817 int flen = fp->len;
33818+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33819+ unsigned int randkey;
33820+#endif
33821
33822 if (!bpf_jit_enable)
33823 return;
33824@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33825 return;
33826
33827 /* Before first pass, make a rough estimation of addrs[]
33828- * each bpf instruction is translated to less than 64 bytes
33829+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33830 */
33831 for (proglen = 0, i = 0; i < flen; i++) {
33832- proglen += 64;
33833+ proglen += MAX_INSTR_CODE_SIZE;
33834 addrs[i] = proglen;
33835 }
33836 cleanup_addr = proglen; /* epilogue address */
33837@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33838 for (i = 0; i < flen; i++) {
33839 unsigned int K = filter[i].k;
33840
33841+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33842+ randkey = prandom_u32();
33843+#endif
33844+
33845 switch (filter[i].code) {
33846 case BPF_S_ALU_ADD_X: /* A += X; */
33847 seen |= SEEN_XREG;
33848@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33849 case BPF_S_ALU_MUL_K: /* A *= K */
33850 if (is_imm8(K))
33851 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33852- else {
33853- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33854- EMIT(K, 4);
33855- }
33856+ else
33857+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33858 break;
33859 case BPF_S_ALU_DIV_X: /* A /= X; */
33860 seen |= SEEN_XREG;
33861@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33862 break;
33863 }
33864 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33865+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33866+ DILUTE_CONST_SEQUENCE(K, randkey);
33867+#else
33868 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33869+#endif
33870 EMIT2(0xf7, 0xf1); /* div %ecx */
33871 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33872 break;
33873@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33874 if (K == 1)
33875 break;
33876 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33877+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33878+ DILUTE_CONST_SEQUENCE(K, randkey);
33879+#else
33880 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33881+#endif
33882 EMIT2(0xf7, 0xf1); /* div %ecx */
33883 break;
33884 case BPF_S_ALU_AND_X:
33885@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33886 if (is_imm8(K)) {
33887 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33888 } else {
33889- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33890- EMIT(K, 4);
33891+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33892 }
33893 } else {
33894 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33895@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33896 if (unlikely(proglen + ilen > oldproglen)) {
33897 pr_err("bpb_jit_compile fatal error\n");
33898 kfree(addrs);
33899- module_free(NULL, header);
33900+ module_free_exec(NULL, image);
33901 return;
33902 }
33903+ pax_open_kernel();
33904 memcpy(image + proglen, temp, ilen);
33905+ pax_close_kernel();
33906 }
33907 proglen += ilen;
33908 addrs[i] = proglen;
33909@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33910
33911 if (image) {
33912 bpf_flush_icache(header, image + proglen);
33913- set_memory_ro((unsigned long)header, header->pages);
33914 fp->bpf_func = (void *)image;
33915 }
33916 out:
33917@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33918 {
33919 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33920 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33921- struct bpf_binary_header *header = (void *)addr;
33922
33923- set_memory_rw(addr, header->pages);
33924- module_free(NULL, header);
33925+ set_memory_rw(addr, 1);
33926+ module_free_exec(NULL, (void *)addr);
33927 kfree(fp);
33928 }
33929
33930diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33931index 5d04be5..2beeaa2 100644
33932--- a/arch/x86/oprofile/backtrace.c
33933+++ b/arch/x86/oprofile/backtrace.c
33934@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33935 struct stack_frame_ia32 *fp;
33936 unsigned long bytes;
33937
33938- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33939+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33940 if (bytes != 0)
33941 return NULL;
33942
33943- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33944+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33945
33946 oprofile_add_trace(bufhead[0].return_address);
33947
33948@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33949 struct stack_frame bufhead[2];
33950 unsigned long bytes;
33951
33952- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33953+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33954 if (bytes != 0)
33955 return NULL;
33956
33957@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33958 {
33959 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33960
33961- if (!user_mode_vm(regs)) {
33962+ if (!user_mode(regs)) {
33963 unsigned long stack = kernel_stack_pointer(regs);
33964 if (depth)
33965 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33966diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33967index 6890d84..1dad1f1 100644
33968--- a/arch/x86/oprofile/nmi_int.c
33969+++ b/arch/x86/oprofile/nmi_int.c
33970@@ -23,6 +23,7 @@
33971 #include <asm/nmi.h>
33972 #include <asm/msr.h>
33973 #include <asm/apic.h>
33974+#include <asm/pgtable.h>
33975
33976 #include "op_counter.h"
33977 #include "op_x86_model.h"
33978@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33979 if (ret)
33980 return ret;
33981
33982- if (!model->num_virt_counters)
33983- model->num_virt_counters = model->num_counters;
33984+ if (!model->num_virt_counters) {
33985+ pax_open_kernel();
33986+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33987+ pax_close_kernel();
33988+ }
33989
33990 mux_init(ops);
33991
33992diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33993index 50d86c0..7985318 100644
33994--- a/arch/x86/oprofile/op_model_amd.c
33995+++ b/arch/x86/oprofile/op_model_amd.c
33996@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33997 num_counters = AMD64_NUM_COUNTERS;
33998 }
33999
34000- op_amd_spec.num_counters = num_counters;
34001- op_amd_spec.num_controls = num_counters;
34002- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34003+ pax_open_kernel();
34004+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34005+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34006+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34007+ pax_close_kernel();
34008
34009 return 0;
34010 }
34011diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34012index d90528e..0127e2b 100644
34013--- a/arch/x86/oprofile/op_model_ppro.c
34014+++ b/arch/x86/oprofile/op_model_ppro.c
34015@@ -19,6 +19,7 @@
34016 #include <asm/msr.h>
34017 #include <asm/apic.h>
34018 #include <asm/nmi.h>
34019+#include <asm/pgtable.h>
34020
34021 #include "op_x86_model.h"
34022 #include "op_counter.h"
34023@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34024
34025 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34026
34027- op_arch_perfmon_spec.num_counters = num_counters;
34028- op_arch_perfmon_spec.num_controls = num_counters;
34029+ pax_open_kernel();
34030+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34031+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34032+ pax_close_kernel();
34033 }
34034
34035 static int arch_perfmon_init(struct oprofile_operations *ignore)
34036diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34037index 71e8a67..6a313bb 100644
34038--- a/arch/x86/oprofile/op_x86_model.h
34039+++ b/arch/x86/oprofile/op_x86_model.h
34040@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34041 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34042 struct op_msrs const * const msrs);
34043 #endif
34044-};
34045+} __do_const;
34046
34047 struct op_counter_config;
34048
34049diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34050index 84b9d67..260e5ff 100644
34051--- a/arch/x86/pci/intel_mid_pci.c
34052+++ b/arch/x86/pci/intel_mid_pci.c
34053@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34054 pr_info("Intel MID platform detected, using MID PCI ops\n");
34055 pci_mmcfg_late_init();
34056 pcibios_enable_irq = intel_mid_pci_irq_enable;
34057- pci_root_ops = intel_mid_pci_ops;
34058+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34059 pci_soc_mode = 1;
34060 /* Continue with standard init */
34061 return 1;
34062diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34063index 372e9b8..e775a6c 100644
34064--- a/arch/x86/pci/irq.c
34065+++ b/arch/x86/pci/irq.c
34066@@ -50,7 +50,7 @@ struct irq_router {
34067 struct irq_router_handler {
34068 u16 vendor;
34069 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34070-};
34071+} __do_const;
34072
34073 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34074 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34075@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34076 return 0;
34077 }
34078
34079-static __initdata struct irq_router_handler pirq_routers[] = {
34080+static __initconst const struct irq_router_handler pirq_routers[] = {
34081 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34082 { PCI_VENDOR_ID_AL, ali_router_probe },
34083 { PCI_VENDOR_ID_ITE, ite_router_probe },
34084@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34085 static void __init pirq_find_router(struct irq_router *r)
34086 {
34087 struct irq_routing_table *rt = pirq_table;
34088- struct irq_router_handler *h;
34089+ const struct irq_router_handler *h;
34090
34091 #ifdef CONFIG_PCI_BIOS
34092 if (!rt->signature) {
34093@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34094 return 0;
34095 }
34096
34097-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34098+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34099 {
34100 .callback = fix_broken_hp_bios_irq9,
34101 .ident = "HP Pavilion N5400 Series Laptop",
34102diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34103index c77b24a..c979855 100644
34104--- a/arch/x86/pci/pcbios.c
34105+++ b/arch/x86/pci/pcbios.c
34106@@ -79,7 +79,7 @@ union bios32 {
34107 static struct {
34108 unsigned long address;
34109 unsigned short segment;
34110-} bios32_indirect = { 0, __KERNEL_CS };
34111+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34112
34113 /*
34114 * Returns the entry point for the given service, NULL on error
34115@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34116 unsigned long length; /* %ecx */
34117 unsigned long entry; /* %edx */
34118 unsigned long flags;
34119+ struct desc_struct d, *gdt;
34120
34121 local_irq_save(flags);
34122- __asm__("lcall *(%%edi); cld"
34123+
34124+ gdt = get_cpu_gdt_table(smp_processor_id());
34125+
34126+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34127+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34128+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34129+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34130+
34131+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34132 : "=a" (return_code),
34133 "=b" (address),
34134 "=c" (length),
34135 "=d" (entry)
34136 : "0" (service),
34137 "1" (0),
34138- "D" (&bios32_indirect));
34139+ "D" (&bios32_indirect),
34140+ "r"(__PCIBIOS_DS)
34141+ : "memory");
34142+
34143+ pax_open_kernel();
34144+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34145+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34146+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34147+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34148+ pax_close_kernel();
34149+
34150 local_irq_restore(flags);
34151
34152 switch (return_code) {
34153- case 0:
34154- return address + entry;
34155- case 0x80: /* Not present */
34156- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34157- return 0;
34158- default: /* Shouldn't happen */
34159- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34160- service, return_code);
34161+ case 0: {
34162+ int cpu;
34163+ unsigned char flags;
34164+
34165+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34166+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34167+ printk(KERN_WARNING "bios32_service: not valid\n");
34168 return 0;
34169+ }
34170+ address = address + PAGE_OFFSET;
34171+ length += 16UL; /* some BIOSs underreport this... */
34172+ flags = 4;
34173+ if (length >= 64*1024*1024) {
34174+ length >>= PAGE_SHIFT;
34175+ flags |= 8;
34176+ }
34177+
34178+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34179+ gdt = get_cpu_gdt_table(cpu);
34180+ pack_descriptor(&d, address, length, 0x9b, flags);
34181+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34182+ pack_descriptor(&d, address, length, 0x93, flags);
34183+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34184+ }
34185+ return entry;
34186+ }
34187+ case 0x80: /* Not present */
34188+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34189+ return 0;
34190+ default: /* Shouldn't happen */
34191+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34192+ service, return_code);
34193+ return 0;
34194 }
34195 }
34196
34197 static struct {
34198 unsigned long address;
34199 unsigned short segment;
34200-} pci_indirect = { 0, __KERNEL_CS };
34201+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34202
34203-static int pci_bios_present;
34204+static int pci_bios_present __read_only;
34205
34206 static int check_pcibios(void)
34207 {
34208@@ -131,11 +174,13 @@ static int check_pcibios(void)
34209 unsigned long flags, pcibios_entry;
34210
34211 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34212- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34213+ pci_indirect.address = pcibios_entry;
34214
34215 local_irq_save(flags);
34216- __asm__(
34217- "lcall *(%%edi); cld\n\t"
34218+ __asm__("movw %w6, %%ds\n\t"
34219+ "lcall *%%ss:(%%edi); cld\n\t"
34220+ "push %%ss\n\t"
34221+ "pop %%ds\n\t"
34222 "jc 1f\n\t"
34223 "xor %%ah, %%ah\n"
34224 "1:"
34225@@ -144,7 +189,8 @@ static int check_pcibios(void)
34226 "=b" (ebx),
34227 "=c" (ecx)
34228 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34229- "D" (&pci_indirect)
34230+ "D" (&pci_indirect),
34231+ "r" (__PCIBIOS_DS)
34232 : "memory");
34233 local_irq_restore(flags);
34234
34235@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34236
34237 switch (len) {
34238 case 1:
34239- __asm__("lcall *(%%esi); cld\n\t"
34240+ __asm__("movw %w6, %%ds\n\t"
34241+ "lcall *%%ss:(%%esi); cld\n\t"
34242+ "push %%ss\n\t"
34243+ "pop %%ds\n\t"
34244 "jc 1f\n\t"
34245 "xor %%ah, %%ah\n"
34246 "1:"
34247@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34248 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34249 "b" (bx),
34250 "D" ((long)reg),
34251- "S" (&pci_indirect));
34252+ "S" (&pci_indirect),
34253+ "r" (__PCIBIOS_DS));
34254 /*
34255 * Zero-extend the result beyond 8 bits, do not trust the
34256 * BIOS having done it:
34257@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34258 *value &= 0xff;
34259 break;
34260 case 2:
34261- __asm__("lcall *(%%esi); cld\n\t"
34262+ __asm__("movw %w6, %%ds\n\t"
34263+ "lcall *%%ss:(%%esi); cld\n\t"
34264+ "push %%ss\n\t"
34265+ "pop %%ds\n\t"
34266 "jc 1f\n\t"
34267 "xor %%ah, %%ah\n"
34268 "1:"
34269@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34270 : "1" (PCIBIOS_READ_CONFIG_WORD),
34271 "b" (bx),
34272 "D" ((long)reg),
34273- "S" (&pci_indirect));
34274+ "S" (&pci_indirect),
34275+ "r" (__PCIBIOS_DS));
34276 /*
34277 * Zero-extend the result beyond 16 bits, do not trust the
34278 * BIOS having done it:
34279@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34280 *value &= 0xffff;
34281 break;
34282 case 4:
34283- __asm__("lcall *(%%esi); cld\n\t"
34284+ __asm__("movw %w6, %%ds\n\t"
34285+ "lcall *%%ss:(%%esi); cld\n\t"
34286+ "push %%ss\n\t"
34287+ "pop %%ds\n\t"
34288 "jc 1f\n\t"
34289 "xor %%ah, %%ah\n"
34290 "1:"
34291@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34292 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34293 "b" (bx),
34294 "D" ((long)reg),
34295- "S" (&pci_indirect));
34296+ "S" (&pci_indirect),
34297+ "r" (__PCIBIOS_DS));
34298 break;
34299 }
34300
34301@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34302
34303 switch (len) {
34304 case 1:
34305- __asm__("lcall *(%%esi); cld\n\t"
34306+ __asm__("movw %w6, %%ds\n\t"
34307+ "lcall *%%ss:(%%esi); cld\n\t"
34308+ "push %%ss\n\t"
34309+ "pop %%ds\n\t"
34310 "jc 1f\n\t"
34311 "xor %%ah, %%ah\n"
34312 "1:"
34313@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34314 "c" (value),
34315 "b" (bx),
34316 "D" ((long)reg),
34317- "S" (&pci_indirect));
34318+ "S" (&pci_indirect),
34319+ "r" (__PCIBIOS_DS));
34320 break;
34321 case 2:
34322- __asm__("lcall *(%%esi); cld\n\t"
34323+ __asm__("movw %w6, %%ds\n\t"
34324+ "lcall *%%ss:(%%esi); cld\n\t"
34325+ "push %%ss\n\t"
34326+ "pop %%ds\n\t"
34327 "jc 1f\n\t"
34328 "xor %%ah, %%ah\n"
34329 "1:"
34330@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34331 "c" (value),
34332 "b" (bx),
34333 "D" ((long)reg),
34334- "S" (&pci_indirect));
34335+ "S" (&pci_indirect),
34336+ "r" (__PCIBIOS_DS));
34337 break;
34338 case 4:
34339- __asm__("lcall *(%%esi); cld\n\t"
34340+ __asm__("movw %w6, %%ds\n\t"
34341+ "lcall *%%ss:(%%esi); cld\n\t"
34342+ "push %%ss\n\t"
34343+ "pop %%ds\n\t"
34344 "jc 1f\n\t"
34345 "xor %%ah, %%ah\n"
34346 "1:"
34347@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34348 "c" (value),
34349 "b" (bx),
34350 "D" ((long)reg),
34351- "S" (&pci_indirect));
34352+ "S" (&pci_indirect),
34353+ "r" (__PCIBIOS_DS));
34354 break;
34355 }
34356
34357@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34358
34359 DBG("PCI: Fetching IRQ routing table... ");
34360 __asm__("push %%es\n\t"
34361+ "movw %w8, %%ds\n\t"
34362 "push %%ds\n\t"
34363 "pop %%es\n\t"
34364- "lcall *(%%esi); cld\n\t"
34365+ "lcall *%%ss:(%%esi); cld\n\t"
34366 "pop %%es\n\t"
34367+ "push %%ss\n\t"
34368+ "pop %%ds\n"
34369 "jc 1f\n\t"
34370 "xor %%ah, %%ah\n"
34371 "1:"
34372@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34373 "1" (0),
34374 "D" ((long) &opt),
34375 "S" (&pci_indirect),
34376- "m" (opt)
34377+ "m" (opt),
34378+ "r" (__PCIBIOS_DS)
34379 : "memory");
34380 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34381 if (ret & 0xff00)
34382@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34383 {
34384 int ret;
34385
34386- __asm__("lcall *(%%esi); cld\n\t"
34387+ __asm__("movw %w5, %%ds\n\t"
34388+ "lcall *%%ss:(%%esi); cld\n\t"
34389+ "push %%ss\n\t"
34390+ "pop %%ds\n"
34391 "jc 1f\n\t"
34392 "xor %%ah, %%ah\n"
34393 "1:"
34394@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34395 : "0" (PCIBIOS_SET_PCI_HW_INT),
34396 "b" ((dev->bus->number << 8) | dev->devfn),
34397 "c" ((irq << 8) | (pin + 10)),
34398- "S" (&pci_indirect));
34399+ "S" (&pci_indirect),
34400+ "r" (__PCIBIOS_DS));
34401 return !(ret & 0xff00);
34402 }
34403 EXPORT_SYMBOL(pcibios_set_irq_routing);
34404diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34405index 9ee3491..872192f 100644
34406--- a/arch/x86/platform/efi/efi_32.c
34407+++ b/arch/x86/platform/efi/efi_32.c
34408@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34409 {
34410 struct desc_ptr gdt_descr;
34411
34412+#ifdef CONFIG_PAX_KERNEXEC
34413+ struct desc_struct d;
34414+#endif
34415+
34416 local_irq_save(efi_rt_eflags);
34417
34418 load_cr3(initial_page_table);
34419 __flush_tlb_all();
34420
34421+#ifdef CONFIG_PAX_KERNEXEC
34422+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34423+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34424+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34425+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34426+#endif
34427+
34428 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34429 gdt_descr.size = GDT_SIZE - 1;
34430 load_gdt(&gdt_descr);
34431@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34432 {
34433 struct desc_ptr gdt_descr;
34434
34435+#ifdef CONFIG_PAX_KERNEXEC
34436+ struct desc_struct d;
34437+
34438+ memset(&d, 0, sizeof d);
34439+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34440+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34441+#endif
34442+
34443 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34444 gdt_descr.size = GDT_SIZE - 1;
34445 load_gdt(&gdt_descr);
34446
34447+#ifdef CONFIG_PAX_PER_CPU_PGD
34448+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34449+#else
34450 load_cr3(swapper_pg_dir);
34451+#endif
34452+
34453 __flush_tlb_all();
34454
34455 local_irq_restore(efi_rt_eflags);
34456diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34457index 666b74a..673d88f 100644
34458--- a/arch/x86/platform/efi/efi_64.c
34459+++ b/arch/x86/platform/efi/efi_64.c
34460@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34461 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34462 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34463 }
34464+
34465+#ifdef CONFIG_PAX_PER_CPU_PGD
34466+ load_cr3(swapper_pg_dir);
34467+#endif
34468+
34469 __flush_tlb_all();
34470 }
34471
34472@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34473 for (pgd = 0; pgd < n_pgds; pgd++)
34474 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34475 kfree(save_pgd);
34476+
34477+#ifdef CONFIG_PAX_PER_CPU_PGD
34478+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34479+#endif
34480+
34481 __flush_tlb_all();
34482 local_irq_restore(efi_flags);
34483 early_code_mapping_set_exec(0);
34484diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34485index fbe66e6..eae5e38 100644
34486--- a/arch/x86/platform/efi/efi_stub_32.S
34487+++ b/arch/x86/platform/efi/efi_stub_32.S
34488@@ -6,7 +6,9 @@
34489 */
34490
34491 #include <linux/linkage.h>
34492+#include <linux/init.h>
34493 #include <asm/page_types.h>
34494+#include <asm/segment.h>
34495
34496 /*
34497 * efi_call_phys(void *, ...) is a function with variable parameters.
34498@@ -20,7 +22,7 @@
34499 * service functions will comply with gcc calling convention, too.
34500 */
34501
34502-.text
34503+__INIT
34504 ENTRY(efi_call_phys)
34505 /*
34506 * 0. The function can only be called in Linux kernel. So CS has been
34507@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34508 * The mapping of lower virtual memory has been created in prelog and
34509 * epilog.
34510 */
34511- movl $1f, %edx
34512- subl $__PAGE_OFFSET, %edx
34513- jmp *%edx
34514+#ifdef CONFIG_PAX_KERNEXEC
34515+ movl $(__KERNEXEC_EFI_DS), %edx
34516+ mov %edx, %ds
34517+ mov %edx, %es
34518+ mov %edx, %ss
34519+ addl $2f,(1f)
34520+ ljmp *(1f)
34521+
34522+__INITDATA
34523+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34524+.previous
34525+
34526+2:
34527+ subl $2b,(1b)
34528+#else
34529+ jmp 1f-__PAGE_OFFSET
34530 1:
34531+#endif
34532
34533 /*
34534 * 2. Now on the top of stack is the return
34535@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34536 * parameter 2, ..., param n. To make things easy, we save the return
34537 * address of efi_call_phys in a global variable.
34538 */
34539- popl %edx
34540- movl %edx, saved_return_addr
34541- /* get the function pointer into ECX*/
34542- popl %ecx
34543- movl %ecx, efi_rt_function_ptr
34544- movl $2f, %edx
34545- subl $__PAGE_OFFSET, %edx
34546- pushl %edx
34547+ popl (saved_return_addr)
34548+ popl (efi_rt_function_ptr)
34549
34550 /*
34551 * 3. Clear PG bit in %CR0.
34552@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34553 /*
34554 * 5. Call the physical function.
34555 */
34556- jmp *%ecx
34557+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34558
34559-2:
34560 /*
34561 * 6. After EFI runtime service returns, control will return to
34562 * following instruction. We'd better readjust stack pointer first.
34563@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34564 movl %cr0, %edx
34565 orl $0x80000000, %edx
34566 movl %edx, %cr0
34567- jmp 1f
34568-1:
34569+
34570 /*
34571 * 8. Now restore the virtual mode from flat mode by
34572 * adding EIP with PAGE_OFFSET.
34573 */
34574- movl $1f, %edx
34575- jmp *%edx
34576+#ifdef CONFIG_PAX_KERNEXEC
34577+ movl $(__KERNEL_DS), %edx
34578+ mov %edx, %ds
34579+ mov %edx, %es
34580+ mov %edx, %ss
34581+ ljmp $(__KERNEL_CS),$1f
34582+#else
34583+ jmp 1f+__PAGE_OFFSET
34584+#endif
34585 1:
34586
34587 /*
34588 * 9. Balance the stack. And because EAX contain the return value,
34589 * we'd better not clobber it.
34590 */
34591- leal efi_rt_function_ptr, %edx
34592- movl (%edx), %ecx
34593- pushl %ecx
34594+ pushl (efi_rt_function_ptr)
34595
34596 /*
34597- * 10. Push the saved return address onto the stack and return.
34598+ * 10. Return to the saved return address.
34599 */
34600- leal saved_return_addr, %edx
34601- movl (%edx), %ecx
34602- pushl %ecx
34603- ret
34604+ jmpl *(saved_return_addr)
34605 ENDPROC(efi_call_phys)
34606 .previous
34607
34608-.data
34609+__INITDATA
34610 saved_return_addr:
34611 .long 0
34612 efi_rt_function_ptr:
34613diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34614index 88073b1..1cc2f53 100644
34615--- a/arch/x86/platform/efi/efi_stub_64.S
34616+++ b/arch/x86/platform/efi/efi_stub_64.S
34617@@ -7,6 +7,7 @@
34618 */
34619
34620 #include <linux/linkage.h>
34621+#include <asm/alternative-asm.h>
34622
34623 #define SAVE_XMM \
34624 mov %rsp, %rax; \
34625@@ -77,6 +78,7 @@ ENTRY(efi_call0)
34626 RESTORE_PGT
34627 addq $32, %rsp
34628 RESTORE_XMM
34629+ pax_force_retaddr 0, 1
34630 ret
34631 ENDPROC(efi_call0)
34632
34633@@ -89,6 +91,7 @@ ENTRY(efi_call1)
34634 RESTORE_PGT
34635 addq $32, %rsp
34636 RESTORE_XMM
34637+ pax_force_retaddr 0, 1
34638 ret
34639 ENDPROC(efi_call1)
34640
34641@@ -101,6 +104,7 @@ ENTRY(efi_call2)
34642 RESTORE_PGT
34643 addq $32, %rsp
34644 RESTORE_XMM
34645+ pax_force_retaddr 0, 1
34646 ret
34647 ENDPROC(efi_call2)
34648
34649@@ -114,6 +118,7 @@ ENTRY(efi_call3)
34650 RESTORE_PGT
34651 addq $32, %rsp
34652 RESTORE_XMM
34653+ pax_force_retaddr 0, 1
34654 ret
34655 ENDPROC(efi_call3)
34656
34657@@ -128,6 +133,7 @@ ENTRY(efi_call4)
34658 RESTORE_PGT
34659 addq $32, %rsp
34660 RESTORE_XMM
34661+ pax_force_retaddr 0, 1
34662 ret
34663 ENDPROC(efi_call4)
34664
34665@@ -143,6 +149,7 @@ ENTRY(efi_call5)
34666 RESTORE_PGT
34667 addq $48, %rsp
34668 RESTORE_XMM
34669+ pax_force_retaddr 0, 1
34670 ret
34671 ENDPROC(efi_call5)
34672
34673@@ -161,6 +168,7 @@ ENTRY(efi_call6)
34674 RESTORE_PGT
34675 addq $48, %rsp
34676 RESTORE_XMM
34677+ pax_force_retaddr 0, 1
34678 ret
34679 ENDPROC(efi_call6)
34680
34681diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34682index 1bbedc4..eb795b5 100644
34683--- a/arch/x86/platform/intel-mid/intel-mid.c
34684+++ b/arch/x86/platform/intel-mid/intel-mid.c
34685@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34686 {
34687 };
34688
34689-static void intel_mid_reboot(void)
34690+static void __noreturn intel_mid_reboot(void)
34691 {
34692 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34693+ BUG();
34694 }
34695
34696 static unsigned long __init intel_mid_calibrate_tsc(void)
34697diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34698index d6ee929..3637cb5 100644
34699--- a/arch/x86/platform/olpc/olpc_dt.c
34700+++ b/arch/x86/platform/olpc/olpc_dt.c
34701@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34702 return res;
34703 }
34704
34705-static struct of_pdt_ops prom_olpc_ops __initdata = {
34706+static struct of_pdt_ops prom_olpc_ops __initconst = {
34707 .nextprop = olpc_dt_nextprop,
34708 .getproplen = olpc_dt_getproplen,
34709 .getproperty = olpc_dt_getproperty,
34710diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34711index 424f4c9..f2a2988 100644
34712--- a/arch/x86/power/cpu.c
34713+++ b/arch/x86/power/cpu.c
34714@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34715 static void fix_processor_context(void)
34716 {
34717 int cpu = smp_processor_id();
34718- struct tss_struct *t = &per_cpu(init_tss, cpu);
34719-#ifdef CONFIG_X86_64
34720- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34721- tss_desc tss;
34722-#endif
34723+ struct tss_struct *t = init_tss + cpu;
34724+
34725 set_tss_desc(cpu, t); /*
34726 * This just modifies memory; should not be
34727 * necessary. But... This is necessary, because
34728@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34729 */
34730
34731 #ifdef CONFIG_X86_64
34732- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34733- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34734- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34735-
34736 syscall_init(); /* This sets MSR_*STAR and related */
34737 #endif
34738 load_TR_desc(); /* This does ltr */
34739diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34740index bad628a..a102610 100644
34741--- a/arch/x86/realmode/init.c
34742+++ b/arch/x86/realmode/init.c
34743@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34744 __va(real_mode_header->trampoline_header);
34745
34746 #ifdef CONFIG_X86_32
34747- trampoline_header->start = __pa_symbol(startup_32_smp);
34748+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34749+
34750+#ifdef CONFIG_PAX_KERNEXEC
34751+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34752+#endif
34753+
34754+ trampoline_header->boot_cs = __BOOT_CS;
34755 trampoline_header->gdt_limit = __BOOT_DS + 7;
34756 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34757 #else
34758@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34759 *trampoline_cr4_features = read_cr4();
34760
34761 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34762- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34763+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34764 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34765 #endif
34766 }
34767diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34768index 3497f14..cc73b92 100644
34769--- a/arch/x86/realmode/rm/Makefile
34770+++ b/arch/x86/realmode/rm/Makefile
34771@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34772
34773 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34774 -I$(srctree)/arch/x86/boot
34775+ifdef CONSTIFY_PLUGIN
34776+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34777+endif
34778 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34779 GCOV_PROFILE := n
34780diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34781index a28221d..93c40f1 100644
34782--- a/arch/x86/realmode/rm/header.S
34783+++ b/arch/x86/realmode/rm/header.S
34784@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34785 #endif
34786 /* APM/BIOS reboot */
34787 .long pa_machine_real_restart_asm
34788-#ifdef CONFIG_X86_64
34789+#ifdef CONFIG_X86_32
34790+ .long __KERNEL_CS
34791+#else
34792 .long __KERNEL32_CS
34793 #endif
34794 END(real_mode_header)
34795diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34796index 48ddd76..c26749f 100644
34797--- a/arch/x86/realmode/rm/trampoline_32.S
34798+++ b/arch/x86/realmode/rm/trampoline_32.S
34799@@ -24,6 +24,12 @@
34800 #include <asm/page_types.h>
34801 #include "realmode.h"
34802
34803+#ifdef CONFIG_PAX_KERNEXEC
34804+#define ta(X) (X)
34805+#else
34806+#define ta(X) (pa_ ## X)
34807+#endif
34808+
34809 .text
34810 .code16
34811
34812@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34813
34814 cli # We should be safe anyway
34815
34816- movl tr_start, %eax # where we need to go
34817-
34818 movl $0xA5A5A5A5, trampoline_status
34819 # write marker for master knows we're running
34820
34821@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34822 movw $1, %dx # protected mode (PE) bit
34823 lmsw %dx # into protected mode
34824
34825- ljmpl $__BOOT_CS, $pa_startup_32
34826+ ljmpl *(trampoline_header)
34827
34828 .section ".text32","ax"
34829 .code32
34830@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34831 .balign 8
34832 GLOBAL(trampoline_header)
34833 tr_start: .space 4
34834- tr_gdt_pad: .space 2
34835+ tr_boot_cs: .space 2
34836 tr_gdt: .space 6
34837 END(trampoline_header)
34838
34839diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34840index dac7b20..72dbaca 100644
34841--- a/arch/x86/realmode/rm/trampoline_64.S
34842+++ b/arch/x86/realmode/rm/trampoline_64.S
34843@@ -93,6 +93,7 @@ ENTRY(startup_32)
34844 movl %edx, %gs
34845
34846 movl pa_tr_cr4, %eax
34847+ andl $~X86_CR4_PCIDE, %eax
34848 movl %eax, %cr4 # Enable PAE mode
34849
34850 # Setup trampoline 4 level pagetables
34851@@ -106,7 +107,7 @@ ENTRY(startup_32)
34852 wrmsr
34853
34854 # Enable paging and in turn activate Long Mode
34855- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34856+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34857 movl %eax, %cr0
34858
34859 /*
34860diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34861index e812034..c747134 100644
34862--- a/arch/x86/tools/Makefile
34863+++ b/arch/x86/tools/Makefile
34864@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34865
34866 $(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
34867
34868-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34869+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34870 hostprogs-y += relocs
34871 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34872 relocs: $(obj)/relocs
34873diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34874index cfbdbdb..1aa763c 100644
34875--- a/arch/x86/tools/relocs.c
34876+++ b/arch/x86/tools/relocs.c
34877@@ -1,5 +1,7 @@
34878 /* This is included from relocs_32/64.c */
34879
34880+#include "../../../include/generated/autoconf.h"
34881+
34882 #define ElfW(type) _ElfW(ELF_BITS, type)
34883 #define _ElfW(bits, type) __ElfW(bits, type)
34884 #define __ElfW(bits, type) Elf##bits##_##type
34885@@ -11,6 +13,7 @@
34886 #define Elf_Sym ElfW(Sym)
34887
34888 static Elf_Ehdr ehdr;
34889+static Elf_Phdr *phdr;
34890
34891 struct relocs {
34892 uint32_t *offset;
34893@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34894 }
34895 }
34896
34897+static void read_phdrs(FILE *fp)
34898+{
34899+ unsigned int i;
34900+
34901+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34902+ if (!phdr) {
34903+ die("Unable to allocate %d program headers\n",
34904+ ehdr.e_phnum);
34905+ }
34906+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34907+ die("Seek to %d failed: %s\n",
34908+ ehdr.e_phoff, strerror(errno));
34909+ }
34910+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34911+ die("Cannot read ELF program headers: %s\n",
34912+ strerror(errno));
34913+ }
34914+ for(i = 0; i < ehdr.e_phnum; i++) {
34915+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34916+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34917+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34918+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34919+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34920+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34921+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34922+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34923+ }
34924+
34925+}
34926+
34927 static void read_shdrs(FILE *fp)
34928 {
34929- int i;
34930+ unsigned int i;
34931 Elf_Shdr shdr;
34932
34933 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34934@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34935
34936 static void read_strtabs(FILE *fp)
34937 {
34938- int i;
34939+ unsigned int i;
34940 for (i = 0; i < ehdr.e_shnum; i++) {
34941 struct section *sec = &secs[i];
34942 if (sec->shdr.sh_type != SHT_STRTAB) {
34943@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34944
34945 static void read_symtabs(FILE *fp)
34946 {
34947- int i,j;
34948+ unsigned int i,j;
34949 for (i = 0; i < ehdr.e_shnum; i++) {
34950 struct section *sec = &secs[i];
34951 if (sec->shdr.sh_type != SHT_SYMTAB) {
34952@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34953 }
34954
34955
34956-static void read_relocs(FILE *fp)
34957+static void read_relocs(FILE *fp, int use_real_mode)
34958 {
34959- int i,j;
34960+ unsigned int i,j;
34961+ uint32_t base;
34962+
34963 for (i = 0; i < ehdr.e_shnum; i++) {
34964 struct section *sec = &secs[i];
34965 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34966@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34967 die("Cannot read symbol table: %s\n",
34968 strerror(errno));
34969 }
34970+ base = 0;
34971+
34972+#ifdef CONFIG_X86_32
34973+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34974+ if (phdr[j].p_type != PT_LOAD )
34975+ continue;
34976+ 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)
34977+ continue;
34978+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34979+ break;
34980+ }
34981+#endif
34982+
34983 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34984 Elf_Rel *rel = &sec->reltab[j];
34985- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34986+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34987 rel->r_info = elf_xword_to_cpu(rel->r_info);
34988 #if (SHT_REL_TYPE == SHT_RELA)
34989 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34990@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34991
34992 static void print_absolute_symbols(void)
34993 {
34994- int i;
34995+ unsigned int i;
34996 const char *format;
34997
34998 if (ELF_BITS == 64)
34999@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35000 for (i = 0; i < ehdr.e_shnum; i++) {
35001 struct section *sec = &secs[i];
35002 char *sym_strtab;
35003- int j;
35004+ unsigned int j;
35005
35006 if (sec->shdr.sh_type != SHT_SYMTAB) {
35007 continue;
35008@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35009
35010 static void print_absolute_relocs(void)
35011 {
35012- int i, printed = 0;
35013+ unsigned int i, printed = 0;
35014 const char *format;
35015
35016 if (ELF_BITS == 64)
35017@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35018 struct section *sec_applies, *sec_symtab;
35019 char *sym_strtab;
35020 Elf_Sym *sh_symtab;
35021- int j;
35022+ unsigned int j;
35023 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35024 continue;
35025 }
35026@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35027 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35028 Elf_Sym *sym, const char *symname))
35029 {
35030- int i;
35031+ unsigned int i;
35032 /* Walk through the relocations */
35033 for (i = 0; i < ehdr.e_shnum; i++) {
35034 char *sym_strtab;
35035 Elf_Sym *sh_symtab;
35036 struct section *sec_applies, *sec_symtab;
35037- int j;
35038+ unsigned int j;
35039 struct section *sec = &secs[i];
35040
35041 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35042@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35043 {
35044 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35045 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35046+ char *sym_strtab = sec->link->link->strtab;
35047+
35048+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35049+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35050+ return 0;
35051+
35052+#ifdef CONFIG_PAX_KERNEXEC
35053+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35054+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35055+ return 0;
35056+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35057+ return 0;
35058+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35059+ return 0;
35060+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35061+ return 0;
35062+#endif
35063
35064 switch (r_type) {
35065 case R_386_NONE:
35066@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35067
35068 static void emit_relocs(int as_text, int use_real_mode)
35069 {
35070- int i;
35071+ unsigned int i;
35072 int (*write_reloc)(uint32_t, FILE *) = write32;
35073 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35074 const char *symname);
35075@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35076 {
35077 regex_init(use_real_mode);
35078 read_ehdr(fp);
35079+ read_phdrs(fp);
35080 read_shdrs(fp);
35081 read_strtabs(fp);
35082 read_symtabs(fp);
35083- read_relocs(fp);
35084+ read_relocs(fp, use_real_mode);
35085 if (ELF_BITS == 64)
35086 percpu_init();
35087 if (show_absolute_syms) {
35088diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35089index 80ffa5b..a33bd15 100644
35090--- a/arch/x86/um/tls_32.c
35091+++ b/arch/x86/um/tls_32.c
35092@@ -260,7 +260,7 @@ out:
35093 if (unlikely(task == current &&
35094 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35095 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35096- "without flushed TLS.", current->pid);
35097+ "without flushed TLS.", task_pid_nr(current));
35098 }
35099
35100 return 0;
35101diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35102index fd14be1..e3c79c0 100644
35103--- a/arch/x86/vdso/Makefile
35104+++ b/arch/x86/vdso/Makefile
35105@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35106 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35107 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35108
35109-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35110+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35111 GCOV_PROFILE := n
35112
35113 #
35114diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35115index d6bfb87..876ee18 100644
35116--- a/arch/x86/vdso/vdso32-setup.c
35117+++ b/arch/x86/vdso/vdso32-setup.c
35118@@ -25,6 +25,7 @@
35119 #include <asm/tlbflush.h>
35120 #include <asm/vdso.h>
35121 #include <asm/proto.h>
35122+#include <asm/mman.h>
35123
35124 enum {
35125 VDSO_DISABLED = 0,
35126@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35127 void enable_sep_cpu(void)
35128 {
35129 int cpu = get_cpu();
35130- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35131+ struct tss_struct *tss = init_tss + cpu;
35132
35133 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35134 put_cpu();
35135@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35136 gate_vma.vm_start = FIXADDR_USER_START;
35137 gate_vma.vm_end = FIXADDR_USER_END;
35138 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35139- gate_vma.vm_page_prot = __P101;
35140+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35141
35142 return 0;
35143 }
35144@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35145 if (compat)
35146 addr = VDSO_HIGH_BASE;
35147 else {
35148- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35149+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35150 if (IS_ERR_VALUE(addr)) {
35151 ret = addr;
35152 goto up_fail;
35153 }
35154 }
35155
35156- current->mm->context.vdso = (void *)addr;
35157+ current->mm->context.vdso = addr;
35158
35159 if (compat_uses_vma || !compat) {
35160 /*
35161@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35162 }
35163
35164 current_thread_info()->sysenter_return =
35165- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35166+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35167
35168 up_fail:
35169 if (ret)
35170- current->mm->context.vdso = NULL;
35171+ current->mm->context.vdso = 0;
35172
35173 up_write(&mm->mmap_sem);
35174
35175@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35176
35177 const char *arch_vma_name(struct vm_area_struct *vma)
35178 {
35179- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35180+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35181 return "[vdso]";
35182+
35183+#ifdef CONFIG_PAX_SEGMEXEC
35184+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35185+ return "[vdso]";
35186+#endif
35187+
35188 return NULL;
35189 }
35190
35191@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35192 * Check to see if the corresponding task was created in compat vdso
35193 * mode.
35194 */
35195- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35196+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35197 return &gate_vma;
35198 return NULL;
35199 }
35200diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35201index 431e875..cbb23f3 100644
35202--- a/arch/x86/vdso/vma.c
35203+++ b/arch/x86/vdso/vma.c
35204@@ -16,8 +16,6 @@
35205 #include <asm/vdso.h>
35206 #include <asm/page.h>
35207
35208-unsigned int __read_mostly vdso_enabled = 1;
35209-
35210 extern char vdso_start[], vdso_end[];
35211 extern unsigned short vdso_sync_cpuid;
35212
35213@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35214 * unaligned here as a result of stack start randomization.
35215 */
35216 addr = PAGE_ALIGN(addr);
35217- addr = align_vdso_addr(addr);
35218
35219 return addr;
35220 }
35221@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35222 unsigned size)
35223 {
35224 struct mm_struct *mm = current->mm;
35225- unsigned long addr;
35226+ unsigned long addr = 0;
35227 int ret;
35228
35229- if (!vdso_enabled)
35230- return 0;
35231-
35232 down_write(&mm->mmap_sem);
35233+
35234+#ifdef CONFIG_PAX_RANDMMAP
35235+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35236+#endif
35237+
35238 addr = vdso_addr(mm->start_stack, size);
35239+ addr = align_vdso_addr(addr);
35240 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35241 if (IS_ERR_VALUE(addr)) {
35242 ret = addr;
35243 goto up_fail;
35244 }
35245
35246- current->mm->context.vdso = (void *)addr;
35247+ mm->context.vdso = addr;
35248
35249 ret = install_special_mapping(mm, addr, size,
35250 VM_READ|VM_EXEC|
35251 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35252 pages);
35253- if (ret) {
35254- current->mm->context.vdso = NULL;
35255- goto up_fail;
35256- }
35257+ if (ret)
35258+ mm->context.vdso = 0;
35259
35260 up_fail:
35261 up_write(&mm->mmap_sem);
35262@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35263 vdsox32_size);
35264 }
35265 #endif
35266-
35267-static __init int vdso_setup(char *s)
35268-{
35269- vdso_enabled = simple_strtoul(s, NULL, 0);
35270- return 0;
35271-}
35272-__setup("vdso=", vdso_setup);
35273diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35274index 01b9026..1e476df 100644
35275--- a/arch/x86/xen/Kconfig
35276+++ b/arch/x86/xen/Kconfig
35277@@ -9,6 +9,7 @@ config XEN
35278 select XEN_HAVE_PVMMU
35279 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35280 depends on X86_TSC
35281+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35282 help
35283 This is the Linux Xen port. Enabling this will allow the
35284 kernel to boot in a paravirtualized environment under the
35285diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35286index 201d09a..e4723e5 100644
35287--- a/arch/x86/xen/enlighten.c
35288+++ b/arch/x86/xen/enlighten.c
35289@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35290
35291 struct shared_info xen_dummy_shared_info;
35292
35293-void *xen_initial_gdt;
35294-
35295 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35296 __read_mostly int xen_have_vector_callback;
35297 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35298@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35299 {
35300 unsigned long va = dtr->address;
35301 unsigned int size = dtr->size + 1;
35302- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35303- unsigned long frames[pages];
35304+ unsigned long frames[65536 / PAGE_SIZE];
35305 int f;
35306
35307 /*
35308@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35309 {
35310 unsigned long va = dtr->address;
35311 unsigned int size = dtr->size + 1;
35312- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35313- unsigned long frames[pages];
35314+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35315 int f;
35316
35317 /*
35318@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35319 * 8-byte entries, or 16 4k pages..
35320 */
35321
35322- BUG_ON(size > 65536);
35323+ BUG_ON(size > GDT_SIZE);
35324 BUG_ON(va & ~PAGE_MASK);
35325
35326 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35327@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35328 return 0;
35329 }
35330
35331-static void set_xen_basic_apic_ops(void)
35332+static void __init set_xen_basic_apic_ops(void)
35333 {
35334 apic->read = xen_apic_read;
35335 apic->write = xen_apic_write;
35336@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35337 #endif
35338 };
35339
35340-static void xen_reboot(int reason)
35341+static __noreturn void xen_reboot(int reason)
35342 {
35343 struct sched_shutdown r = { .reason = reason };
35344
35345- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35346- BUG();
35347+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35348+ BUG();
35349 }
35350
35351-static void xen_restart(char *msg)
35352+static __noreturn void xen_restart(char *msg)
35353 {
35354 xen_reboot(SHUTDOWN_reboot);
35355 }
35356
35357-static void xen_emergency_restart(void)
35358+static __noreturn void xen_emergency_restart(void)
35359 {
35360 xen_reboot(SHUTDOWN_reboot);
35361 }
35362
35363-static void xen_machine_halt(void)
35364+static __noreturn void xen_machine_halt(void)
35365 {
35366 xen_reboot(SHUTDOWN_poweroff);
35367 }
35368
35369-static void xen_machine_power_off(void)
35370+static __noreturn void xen_machine_power_off(void)
35371 {
35372 if (pm_power_off)
35373 pm_power_off();
35374@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35375 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35376
35377 /* Work out if we support NX */
35378- x86_configure_nx();
35379+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35380+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35381+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35382+ unsigned l, h;
35383+
35384+ __supported_pte_mask |= _PAGE_NX;
35385+ rdmsr(MSR_EFER, l, h);
35386+ l |= EFER_NX;
35387+ wrmsr(MSR_EFER, l, h);
35388+ }
35389+#endif
35390
35391 /* Get mfn list */
35392 xen_build_dynamic_phys_to_machine();
35393@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35394
35395 machine_ops = xen_machine_ops;
35396
35397- /*
35398- * The only reliable way to retain the initial address of the
35399- * percpu gdt_page is to remember it here, so we can go and
35400- * mark it RW later, when the initial percpu area is freed.
35401- */
35402- xen_initial_gdt = &per_cpu(gdt_page, 0);
35403-
35404 xen_smp_init();
35405
35406 #ifdef CONFIG_ACPI_NUMA
35407diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35408index 2423ef0..4f6fb5b 100644
35409--- a/arch/x86/xen/mmu.c
35410+++ b/arch/x86/xen/mmu.c
35411@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35412 return val;
35413 }
35414
35415-static pteval_t pte_pfn_to_mfn(pteval_t val)
35416+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35417 {
35418 if (val & _PAGE_PRESENT) {
35419 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35420@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35421 /* L3_k[510] -> level2_kernel_pgt
35422 * L3_i[511] -> level2_fixmap_pgt */
35423 convert_pfn_mfn(level3_kernel_pgt);
35424+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35425+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35426+ convert_pfn_mfn(level3_vmemmap_pgt);
35427 }
35428 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35429 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35430@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35431 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35432 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35433 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35434+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35435+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35436+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35437 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35438 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35439+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35440 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35441 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35442
35443@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35444 pv_mmu_ops.set_pud = xen_set_pud;
35445 #if PAGETABLE_LEVELS == 4
35446 pv_mmu_ops.set_pgd = xen_set_pgd;
35447+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35448 #endif
35449
35450 /* This will work as long as patching hasn't happened yet
35451@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35452 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35453 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35454 .set_pgd = xen_set_pgd_hyper,
35455+ .set_pgd_batched = xen_set_pgd_hyper,
35456
35457 .alloc_pud = xen_alloc_pmd_init,
35458 .release_pud = xen_release_pmd_init,
35459diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35460index a18eadd..2e2f10e 100644
35461--- a/arch/x86/xen/smp.c
35462+++ b/arch/x86/xen/smp.c
35463@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35464
35465 if (xen_pv_domain()) {
35466 if (!xen_feature(XENFEAT_writable_page_tables))
35467- /* We've switched to the "real" per-cpu gdt, so make
35468- * sure the old memory can be recycled. */
35469- make_lowmem_page_readwrite(xen_initial_gdt);
35470-
35471 #ifdef CONFIG_X86_32
35472 /*
35473 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35474 * expects __USER_DS
35475 */
35476- loadsegment(ds, __USER_DS);
35477- loadsegment(es, __USER_DS);
35478+ loadsegment(ds, __KERNEL_DS);
35479+ loadsegment(es, __KERNEL_DS);
35480 #endif
35481
35482 xen_filter_cpu_maps();
35483@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35484 #ifdef CONFIG_X86_32
35485 /* Note: PVH is not yet supported on x86_32. */
35486 ctxt->user_regs.fs = __KERNEL_PERCPU;
35487- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35488+ savesegment(gs, ctxt->user_regs.gs);
35489 #endif
35490 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35491
35492@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35493 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35494 ctxt->flags = VGCF_IN_KERNEL;
35495 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35496- ctxt->user_regs.ds = __USER_DS;
35497- ctxt->user_regs.es = __USER_DS;
35498+ ctxt->user_regs.ds = __KERNEL_DS;
35499+ ctxt->user_regs.es = __KERNEL_DS;
35500 ctxt->user_regs.ss = __KERNEL_DS;
35501
35502 xen_copy_trap_info(ctxt->trap_ctxt);
35503@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35504 int rc;
35505
35506 per_cpu(current_task, cpu) = idle;
35507+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35508 #ifdef CONFIG_X86_32
35509 irq_ctx_init(cpu);
35510 #else
35511 clear_tsk_thread_flag(idle, TIF_FORK);
35512- per_cpu(kernel_stack, cpu) =
35513- (unsigned long)task_stack_page(idle) -
35514- KERNEL_STACK_OFFSET + THREAD_SIZE;
35515+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35516 #endif
35517 xen_setup_runstate_info(cpu);
35518 xen_setup_timer(cpu);
35519@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35520
35521 void __init xen_smp_init(void)
35522 {
35523- smp_ops = xen_smp_ops;
35524+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35525 xen_fill_possible_map();
35526 }
35527
35528diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35529index 33ca6e4..0ded929 100644
35530--- a/arch/x86/xen/xen-asm_32.S
35531+++ b/arch/x86/xen/xen-asm_32.S
35532@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35533 ESP_OFFSET=4 # bytes pushed onto stack
35534
35535 /*
35536- * Store vcpu_info pointer for easy access. Do it this way to
35537- * avoid having to reload %fs
35538+ * Store vcpu_info pointer for easy access.
35539 */
35540 #ifdef CONFIG_SMP
35541- GET_THREAD_INFO(%eax)
35542- movl %ss:TI_cpu(%eax), %eax
35543- movl %ss:__per_cpu_offset(,%eax,4), %eax
35544- mov %ss:xen_vcpu(%eax), %eax
35545+ push %fs
35546+ mov $(__KERNEL_PERCPU), %eax
35547+ mov %eax, %fs
35548+ mov PER_CPU_VAR(xen_vcpu), %eax
35549+ pop %fs
35550 #else
35551 movl %ss:xen_vcpu, %eax
35552 #endif
35553diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35554index 485b695..fda3e7c 100644
35555--- a/arch/x86/xen/xen-head.S
35556+++ b/arch/x86/xen/xen-head.S
35557@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35558 #ifdef CONFIG_X86_32
35559 mov %esi,xen_start_info
35560 mov $init_thread_union+THREAD_SIZE,%esp
35561+#ifdef CONFIG_SMP
35562+ movl $cpu_gdt_table,%edi
35563+ movl $__per_cpu_load,%eax
35564+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35565+ rorl $16,%eax
35566+ movb %al,__KERNEL_PERCPU + 4(%edi)
35567+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35568+ movl $__per_cpu_end - 1,%eax
35569+ subl $__per_cpu_start,%eax
35570+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35571+#endif
35572 #else
35573 mov %rsi,xen_start_info
35574 mov $init_thread_union+THREAD_SIZE,%rsp
35575diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35576index 1cb6f4c..9981524 100644
35577--- a/arch/x86/xen/xen-ops.h
35578+++ b/arch/x86/xen/xen-ops.h
35579@@ -10,8 +10,6 @@
35580 extern const char xen_hypervisor_callback[];
35581 extern const char xen_failsafe_callback[];
35582
35583-extern void *xen_initial_gdt;
35584-
35585 struct trap_info;
35586 void xen_copy_trap_info(struct trap_info *traps);
35587
35588diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35589index 525bd3d..ef888b1 100644
35590--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35591+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35592@@ -119,9 +119,9 @@
35593 ----------------------------------------------------------------------*/
35594
35595 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35596-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35597 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35598 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35599+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35600
35601 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35602 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35603diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35604index 2f33760..835e50a 100644
35605--- a/arch/xtensa/variants/fsf/include/variant/core.h
35606+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35607@@ -11,6 +11,7 @@
35608 #ifndef _XTENSA_CORE_H
35609 #define _XTENSA_CORE_H
35610
35611+#include <linux/const.h>
35612
35613 /****************************************************************************
35614 Parameters Useful for Any Code, USER or PRIVILEGED
35615@@ -112,9 +113,9 @@
35616 ----------------------------------------------------------------------*/
35617
35618 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35619-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35620 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35621 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35622+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35623
35624 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35625 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35626diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35627index af00795..2bb8105 100644
35628--- a/arch/xtensa/variants/s6000/include/variant/core.h
35629+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35630@@ -11,6 +11,7 @@
35631 #ifndef _XTENSA_CORE_CONFIGURATION_H
35632 #define _XTENSA_CORE_CONFIGURATION_H
35633
35634+#include <linux/const.h>
35635
35636 /****************************************************************************
35637 Parameters Useful for Any Code, USER or PRIVILEGED
35638@@ -118,9 +119,9 @@
35639 ----------------------------------------------------------------------*/
35640
35641 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35642-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35643 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35644 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35645+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35646
35647 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35648 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35649diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35650index 4e491d9..c8e18e4 100644
35651--- a/block/blk-cgroup.c
35652+++ b/block/blk-cgroup.c
35653@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35654 static struct cgroup_subsys_state *
35655 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35656 {
35657- static atomic64_t id_seq = ATOMIC64_INIT(0);
35658+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35659 struct blkcg *blkcg;
35660
35661 if (!parent_css) {
35662@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35663
35664 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35665 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35666- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35667+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35668 done:
35669 spin_lock_init(&blkcg->lock);
35670 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35671diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35672index 1855bf5..af12b06 100644
35673--- a/block/blk-iopoll.c
35674+++ b/block/blk-iopoll.c
35675@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35676 }
35677 EXPORT_SYMBOL(blk_iopoll_complete);
35678
35679-static void blk_iopoll_softirq(struct softirq_action *h)
35680+static __latent_entropy void blk_iopoll_softirq(void)
35681 {
35682 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35683 int rearm = 0, budget = blk_iopoll_budget;
35684diff --git a/block/blk-map.c b/block/blk-map.c
35685index ae4ae10..c470b8d 100644
35686--- a/block/blk-map.c
35687+++ b/block/blk-map.c
35688@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35689 if (!len || !kbuf)
35690 return -EINVAL;
35691
35692- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35693+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35694 if (do_copy)
35695 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35696 else
35697diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35698index 57790c1..5e988dd 100644
35699--- a/block/blk-softirq.c
35700+++ b/block/blk-softirq.c
35701@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35702 * Softirq action handler - move entries to local list and loop over them
35703 * while passing them to the queue registered handler.
35704 */
35705-static void blk_done_softirq(struct softirq_action *h)
35706+static __latent_entropy void blk_done_softirq(void)
35707 {
35708 struct list_head *cpu_list, local_list;
35709
35710diff --git a/block/bsg.c b/block/bsg.c
35711index 420a5a9..23834aa 100644
35712--- a/block/bsg.c
35713+++ b/block/bsg.c
35714@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35715 struct sg_io_v4 *hdr, struct bsg_device *bd,
35716 fmode_t has_write_perm)
35717 {
35718+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35719+ unsigned char *cmdptr;
35720+
35721 if (hdr->request_len > BLK_MAX_CDB) {
35722 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35723 if (!rq->cmd)
35724 return -ENOMEM;
35725- }
35726+ cmdptr = rq->cmd;
35727+ } else
35728+ cmdptr = tmpcmd;
35729
35730- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35731+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35732 hdr->request_len))
35733 return -EFAULT;
35734
35735+ if (cmdptr != rq->cmd)
35736+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35737+
35738 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35739 if (blk_verify_command(rq->cmd, has_write_perm))
35740 return -EPERM;
35741diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35742index fbd5a67..f24fd95 100644
35743--- a/block/compat_ioctl.c
35744+++ b/block/compat_ioctl.c
35745@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35746 cgc = compat_alloc_user_space(sizeof(*cgc));
35747 cgc32 = compat_ptr(arg);
35748
35749- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35750+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35751 get_user(data, &cgc32->buffer) ||
35752 put_user(compat_ptr(data), &cgc->buffer) ||
35753 copy_in_user(&cgc->buflen, &cgc32->buflen,
35754@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35755 err |= __get_user(f->spec1, &uf->spec1);
35756 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35757 err |= __get_user(name, &uf->name);
35758- f->name = compat_ptr(name);
35759+ f->name = (void __force_kernel *)compat_ptr(name);
35760 if (err) {
35761 err = -EFAULT;
35762 goto out;
35763diff --git a/block/genhd.c b/block/genhd.c
35764index 791f419..89f21c4 100644
35765--- a/block/genhd.c
35766+++ b/block/genhd.c
35767@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35768
35769 /*
35770 * Register device numbers dev..(dev+range-1)
35771- * range must be nonzero
35772+ * Noop if @range is zero.
35773 * The hash chain is sorted on range, so that subranges can override.
35774 */
35775 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35776 struct kobject *(*probe)(dev_t, int *, void *),
35777 int (*lock)(dev_t, void *), void *data)
35778 {
35779- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35780+ if (range)
35781+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35782 }
35783
35784 EXPORT_SYMBOL(blk_register_region);
35785
35786+/* undo blk_register_region(), noop if @range is zero */
35787 void blk_unregister_region(dev_t devt, unsigned long range)
35788 {
35789- kobj_unmap(bdev_map, devt, range);
35790+ if (range)
35791+ kobj_unmap(bdev_map, devt, range);
35792 }
35793
35794 EXPORT_SYMBOL(blk_unregister_region);
35795diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35796index dc51f46..d5446a8 100644
35797--- a/block/partitions/efi.c
35798+++ b/block/partitions/efi.c
35799@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35800 if (!gpt)
35801 return NULL;
35802
35803+ if (!le32_to_cpu(gpt->num_partition_entries))
35804+ return NULL;
35805+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35806+ if (!pte)
35807+ return NULL;
35808+
35809 count = le32_to_cpu(gpt->num_partition_entries) *
35810 le32_to_cpu(gpt->sizeof_partition_entry);
35811- if (!count)
35812- return NULL;
35813- pte = kmalloc(count, GFP_KERNEL);
35814- if (!pte)
35815- return NULL;
35816-
35817 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35818 (u8 *) pte, count) < count) {
35819 kfree(pte);
35820diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35821index 2648797..92ed21f 100644
35822--- a/block/scsi_ioctl.c
35823+++ b/block/scsi_ioctl.c
35824@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35825 return put_user(0, p);
35826 }
35827
35828-static int sg_get_timeout(struct request_queue *q)
35829+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35830 {
35831 return jiffies_to_clock_t(q->sg_timeout);
35832 }
35833@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35834 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35835 struct sg_io_hdr *hdr, fmode_t mode)
35836 {
35837- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35838+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35839+ unsigned char *cmdptr;
35840+
35841+ if (rq->cmd != rq->__cmd)
35842+ cmdptr = rq->cmd;
35843+ else
35844+ cmdptr = tmpcmd;
35845+
35846+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35847 return -EFAULT;
35848+
35849+ if (cmdptr != rq->cmd)
35850+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35851+
35852 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35853 return -EPERM;
35854
35855@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35856 int err;
35857 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35858 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35859+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35860+ unsigned char *cmdptr;
35861
35862 if (!sic)
35863 return -EINVAL;
35864@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35865 */
35866 err = -EFAULT;
35867 rq->cmd_len = cmdlen;
35868- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35869+
35870+ if (rq->cmd != rq->__cmd)
35871+ cmdptr = rq->cmd;
35872+ else
35873+ cmdptr = tmpcmd;
35874+
35875+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35876 goto error;
35877
35878+ if (rq->cmd != cmdptr)
35879+ memcpy(rq->cmd, cmdptr, cmdlen);
35880+
35881 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35882 goto error;
35883
35884diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35885index 7bdd61b..afec999 100644
35886--- a/crypto/cryptd.c
35887+++ b/crypto/cryptd.c
35888@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35889
35890 struct cryptd_blkcipher_request_ctx {
35891 crypto_completion_t complete;
35892-};
35893+} __no_const;
35894
35895 struct cryptd_hash_ctx {
35896 struct crypto_shash *child;
35897@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35898
35899 struct cryptd_aead_request_ctx {
35900 crypto_completion_t complete;
35901-};
35902+} __no_const;
35903
35904 static void cryptd_queue_worker(struct work_struct *work);
35905
35906diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35907index 309d345..1632720 100644
35908--- a/crypto/pcrypt.c
35909+++ b/crypto/pcrypt.c
35910@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35911 int ret;
35912
35913 pinst->kobj.kset = pcrypt_kset;
35914- ret = kobject_add(&pinst->kobj, NULL, name);
35915+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35916 if (!ret)
35917 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35918
35919diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35920index 15dddc1..b61cf0c 100644
35921--- a/drivers/acpi/acpica/hwxfsleep.c
35922+++ b/drivers/acpi/acpica/hwxfsleep.c
35923@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35924 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35925
35926 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35927- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35928- acpi_hw_extended_sleep},
35929- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35930- acpi_hw_extended_wake_prep},
35931- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35932+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35933+ .extended_function = acpi_hw_extended_sleep},
35934+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35935+ .extended_function = acpi_hw_extended_wake_prep},
35936+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35937+ .extended_function = acpi_hw_extended_wake}
35938 };
35939
35940 /*
35941diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35942index e5bcd91..74f050d 100644
35943--- a/drivers/acpi/apei/apei-internal.h
35944+++ b/drivers/acpi/apei/apei-internal.h
35945@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35946 struct apei_exec_ins_type {
35947 u32 flags;
35948 apei_exec_ins_func_t run;
35949-};
35950+} __do_const;
35951
35952 struct apei_exec_context {
35953 u32 ip;
35954diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35955index dab7cb7..f0d2994 100644
35956--- a/drivers/acpi/apei/ghes.c
35957+++ b/drivers/acpi/apei/ghes.c
35958@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
35959 const struct acpi_hest_generic *generic,
35960 const struct acpi_generic_status *estatus)
35961 {
35962- static atomic_t seqno;
35963+ static atomic_unchecked_t seqno;
35964 unsigned int curr_seqno;
35965 char pfx_seq[64];
35966
35967@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
35968 else
35969 pfx = KERN_ERR;
35970 }
35971- curr_seqno = atomic_inc_return(&seqno);
35972+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35973 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35974 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35975 pfx_seq, generic->header.source_id);
35976diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35977index a83e3c6..c3d617f 100644
35978--- a/drivers/acpi/bgrt.c
35979+++ b/drivers/acpi/bgrt.c
35980@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35981 if (!bgrt_image)
35982 return -ENODEV;
35983
35984- bin_attr_image.private = bgrt_image;
35985- bin_attr_image.size = bgrt_image_size;
35986+ pax_open_kernel();
35987+ *(void **)&bin_attr_image.private = bgrt_image;
35988+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
35989+ pax_close_kernel();
35990
35991 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35992 if (!bgrt_kobj)
35993diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35994index afec452..c5d8b96 100644
35995--- a/drivers/acpi/blacklist.c
35996+++ b/drivers/acpi/blacklist.c
35997@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
35998 u32 is_critical_error;
35999 };
36000
36001-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36002+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36003
36004 /*
36005 * POLICY: If *anything* doesn't work, put it on the blacklist.
36006@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36007 return 0;
36008 }
36009
36010-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36011+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36012 {
36013 .callback = dmi_disable_osi_vista,
36014 .ident = "Fujitsu Siemens",
36015diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36016index c68e724..e863008 100644
36017--- a/drivers/acpi/custom_method.c
36018+++ b/drivers/acpi/custom_method.c
36019@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36020 struct acpi_table_header table;
36021 acpi_status status;
36022
36023+#ifdef CONFIG_GRKERNSEC_KMEM
36024+ return -EPERM;
36025+#endif
36026+
36027 if (!(*ppos)) {
36028 /* parse the table header to get the table length */
36029 if (count <= sizeof(struct acpi_table_header))
36030diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36031index 3dca36d..abaf070 100644
36032--- a/drivers/acpi/processor_idle.c
36033+++ b/drivers/acpi/processor_idle.c
36034@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36035 {
36036 int i, count = CPUIDLE_DRIVER_STATE_START;
36037 struct acpi_processor_cx *cx;
36038- struct cpuidle_state *state;
36039+ cpuidle_state_no_const *state;
36040 struct cpuidle_driver *drv = &acpi_idle_driver;
36041
36042 if (!pr->flags.power_setup_done)
36043diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36044index 91a32ce..d77fcaf 100644
36045--- a/drivers/acpi/sysfs.c
36046+++ b/drivers/acpi/sysfs.c
36047@@ -425,11 +425,11 @@ static u32 num_counters;
36048 static struct attribute **all_attrs;
36049 static u32 acpi_gpe_count;
36050
36051-static struct attribute_group interrupt_stats_attr_group = {
36052+static attribute_group_no_const interrupt_stats_attr_group = {
36053 .name = "interrupts",
36054 };
36055
36056-static struct kobj_attribute *counter_attrs;
36057+static kobj_attribute_no_const *counter_attrs;
36058
36059 static void delete_gpe_attr_array(void)
36060 {
36061diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36062index 36605ab..6ef6d4b 100644
36063--- a/drivers/ata/libahci.c
36064+++ b/drivers/ata/libahci.c
36065@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36066 }
36067 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36068
36069-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36070+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36071 struct ata_taskfile *tf, int is_cmd, u16 flags,
36072 unsigned long timeout_msec)
36073 {
36074diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36075index 8cb2522..a815e54 100644
36076--- a/drivers/ata/libata-core.c
36077+++ b/drivers/ata/libata-core.c
36078@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36079 static void ata_dev_xfermask(struct ata_device *dev);
36080 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36081
36082-atomic_t ata_print_id = ATOMIC_INIT(0);
36083+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36084
36085 struct ata_force_param {
36086 const char *name;
36087@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36088 struct ata_port *ap;
36089 unsigned int tag;
36090
36091- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36092+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36093 ap = qc->ap;
36094
36095 qc->flags = 0;
36096@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36097 struct ata_port *ap;
36098 struct ata_link *link;
36099
36100- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36101+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36102 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36103 ap = qc->ap;
36104 link = qc->dev->link;
36105@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36106 return;
36107
36108 spin_lock(&lock);
36109+ pax_open_kernel();
36110
36111 for (cur = ops->inherits; cur; cur = cur->inherits) {
36112 void **inherit = (void **)cur;
36113@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36114 if (IS_ERR(*pp))
36115 *pp = NULL;
36116
36117- ops->inherits = NULL;
36118+ *(struct ata_port_operations **)&ops->inherits = NULL;
36119
36120+ pax_close_kernel();
36121 spin_unlock(&lock);
36122 }
36123
36124@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36125
36126 /* give ports names and add SCSI hosts */
36127 for (i = 0; i < host->n_ports; i++) {
36128- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36129+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36130 host->ports[i]->local_port_no = i + 1;
36131 }
36132
36133diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36134index ef8567d..8bdbd03 100644
36135--- a/drivers/ata/libata-scsi.c
36136+++ b/drivers/ata/libata-scsi.c
36137@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36138
36139 if (rc)
36140 return rc;
36141- ap->print_id = atomic_inc_return(&ata_print_id);
36142+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36143 return 0;
36144 }
36145 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36146diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36147index 45b5ab3..98446b8 100644
36148--- a/drivers/ata/libata.h
36149+++ b/drivers/ata/libata.h
36150@@ -53,7 +53,7 @@ enum {
36151 ATA_DNXFER_QUIET = (1 << 31),
36152 };
36153
36154-extern atomic_t ata_print_id;
36155+extern atomic_unchecked_t ata_print_id;
36156 extern int atapi_passthru16;
36157 extern int libata_fua;
36158 extern int libata_noacpi;
36159diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36160index 73492dd..ca2bff5 100644
36161--- a/drivers/ata/pata_arasan_cf.c
36162+++ b/drivers/ata/pata_arasan_cf.c
36163@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36164 /* Handle platform specific quirks */
36165 if (quirk) {
36166 if (quirk & CF_BROKEN_PIO) {
36167- ap->ops->set_piomode = NULL;
36168+ pax_open_kernel();
36169+ *(void **)&ap->ops->set_piomode = NULL;
36170+ pax_close_kernel();
36171 ap->pio_mask = 0;
36172 }
36173 if (quirk & CF_BROKEN_MWDMA)
36174diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36175index f9b983a..887b9d8 100644
36176--- a/drivers/atm/adummy.c
36177+++ b/drivers/atm/adummy.c
36178@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36179 vcc->pop(vcc, skb);
36180 else
36181 dev_kfree_skb_any(skb);
36182- atomic_inc(&vcc->stats->tx);
36183+ atomic_inc_unchecked(&vcc->stats->tx);
36184
36185 return 0;
36186 }
36187diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36188index 62a7607..cc4be104 100644
36189--- a/drivers/atm/ambassador.c
36190+++ b/drivers/atm/ambassador.c
36191@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36192 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36193
36194 // VC layer stats
36195- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36196+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36197
36198 // free the descriptor
36199 kfree (tx_descr);
36200@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36201 dump_skb ("<<<", vc, skb);
36202
36203 // VC layer stats
36204- atomic_inc(&atm_vcc->stats->rx);
36205+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36206 __net_timestamp(skb);
36207 // end of our responsibility
36208 atm_vcc->push (atm_vcc, skb);
36209@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36210 } else {
36211 PRINTK (KERN_INFO, "dropped over-size frame");
36212 // should we count this?
36213- atomic_inc(&atm_vcc->stats->rx_drop);
36214+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36215 }
36216
36217 } else {
36218@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36219 }
36220
36221 if (check_area (skb->data, skb->len)) {
36222- atomic_inc(&atm_vcc->stats->tx_err);
36223+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36224 return -ENOMEM; // ?
36225 }
36226
36227diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36228index 0e3f8f9..765a7a5 100644
36229--- a/drivers/atm/atmtcp.c
36230+++ b/drivers/atm/atmtcp.c
36231@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36232 if (vcc->pop) vcc->pop(vcc,skb);
36233 else dev_kfree_skb(skb);
36234 if (dev_data) return 0;
36235- atomic_inc(&vcc->stats->tx_err);
36236+ atomic_inc_unchecked(&vcc->stats->tx_err);
36237 return -ENOLINK;
36238 }
36239 size = skb->len+sizeof(struct atmtcp_hdr);
36240@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36241 if (!new_skb) {
36242 if (vcc->pop) vcc->pop(vcc,skb);
36243 else dev_kfree_skb(skb);
36244- atomic_inc(&vcc->stats->tx_err);
36245+ atomic_inc_unchecked(&vcc->stats->tx_err);
36246 return -ENOBUFS;
36247 }
36248 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36249@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36250 if (vcc->pop) vcc->pop(vcc,skb);
36251 else dev_kfree_skb(skb);
36252 out_vcc->push(out_vcc,new_skb);
36253- atomic_inc(&vcc->stats->tx);
36254- atomic_inc(&out_vcc->stats->rx);
36255+ atomic_inc_unchecked(&vcc->stats->tx);
36256+ atomic_inc_unchecked(&out_vcc->stats->rx);
36257 return 0;
36258 }
36259
36260@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36261 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36262 read_unlock(&vcc_sklist_lock);
36263 if (!out_vcc) {
36264- atomic_inc(&vcc->stats->tx_err);
36265+ atomic_inc_unchecked(&vcc->stats->tx_err);
36266 goto done;
36267 }
36268 skb_pull(skb,sizeof(struct atmtcp_hdr));
36269@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36270 __net_timestamp(new_skb);
36271 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36272 out_vcc->push(out_vcc,new_skb);
36273- atomic_inc(&vcc->stats->tx);
36274- atomic_inc(&out_vcc->stats->rx);
36275+ atomic_inc_unchecked(&vcc->stats->tx);
36276+ atomic_inc_unchecked(&out_vcc->stats->rx);
36277 done:
36278 if (vcc->pop) vcc->pop(vcc,skb);
36279 else dev_kfree_skb(skb);
36280diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36281index b1955ba..b179940 100644
36282--- a/drivers/atm/eni.c
36283+++ b/drivers/atm/eni.c
36284@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36285 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36286 vcc->dev->number);
36287 length = 0;
36288- atomic_inc(&vcc->stats->rx_err);
36289+ atomic_inc_unchecked(&vcc->stats->rx_err);
36290 }
36291 else {
36292 length = ATM_CELL_SIZE-1; /* no HEC */
36293@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36294 size);
36295 }
36296 eff = length = 0;
36297- atomic_inc(&vcc->stats->rx_err);
36298+ atomic_inc_unchecked(&vcc->stats->rx_err);
36299 }
36300 else {
36301 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36302@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36303 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36304 vcc->dev->number,vcc->vci,length,size << 2,descr);
36305 length = eff = 0;
36306- atomic_inc(&vcc->stats->rx_err);
36307+ atomic_inc_unchecked(&vcc->stats->rx_err);
36308 }
36309 }
36310 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36311@@ -767,7 +767,7 @@ rx_dequeued++;
36312 vcc->push(vcc,skb);
36313 pushed++;
36314 }
36315- atomic_inc(&vcc->stats->rx);
36316+ atomic_inc_unchecked(&vcc->stats->rx);
36317 }
36318 wake_up(&eni_dev->rx_wait);
36319 }
36320@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36321 PCI_DMA_TODEVICE);
36322 if (vcc->pop) vcc->pop(vcc,skb);
36323 else dev_kfree_skb_irq(skb);
36324- atomic_inc(&vcc->stats->tx);
36325+ atomic_inc_unchecked(&vcc->stats->tx);
36326 wake_up(&eni_dev->tx_wait);
36327 dma_complete++;
36328 }
36329diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36330index b41c948..a002b17 100644
36331--- a/drivers/atm/firestream.c
36332+++ b/drivers/atm/firestream.c
36333@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36334 }
36335 }
36336
36337- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36338+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36339
36340 fs_dprintk (FS_DEBUG_TXMEM, "i");
36341 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36342@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36343 #endif
36344 skb_put (skb, qe->p1 & 0xffff);
36345 ATM_SKB(skb)->vcc = atm_vcc;
36346- atomic_inc(&atm_vcc->stats->rx);
36347+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36348 __net_timestamp(skb);
36349 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36350 atm_vcc->push (atm_vcc, skb);
36351@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36352 kfree (pe);
36353 }
36354 if (atm_vcc)
36355- atomic_inc(&atm_vcc->stats->rx_drop);
36356+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36357 break;
36358 case 0x1f: /* Reassembly abort: no buffers. */
36359 /* Silently increment error counter. */
36360 if (atm_vcc)
36361- atomic_inc(&atm_vcc->stats->rx_drop);
36362+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36363 break;
36364 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36365 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36366diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36367index 204814e..cede831 100644
36368--- a/drivers/atm/fore200e.c
36369+++ b/drivers/atm/fore200e.c
36370@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36371 #endif
36372 /* check error condition */
36373 if (*entry->status & STATUS_ERROR)
36374- atomic_inc(&vcc->stats->tx_err);
36375+ atomic_inc_unchecked(&vcc->stats->tx_err);
36376 else
36377- atomic_inc(&vcc->stats->tx);
36378+ atomic_inc_unchecked(&vcc->stats->tx);
36379 }
36380 }
36381
36382@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36383 if (skb == NULL) {
36384 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36385
36386- atomic_inc(&vcc->stats->rx_drop);
36387+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36388 return -ENOMEM;
36389 }
36390
36391@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36392
36393 dev_kfree_skb_any(skb);
36394
36395- atomic_inc(&vcc->stats->rx_drop);
36396+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36397 return -ENOMEM;
36398 }
36399
36400 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36401
36402 vcc->push(vcc, skb);
36403- atomic_inc(&vcc->stats->rx);
36404+ atomic_inc_unchecked(&vcc->stats->rx);
36405
36406 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36407
36408@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36409 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36410 fore200e->atm_dev->number,
36411 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36412- atomic_inc(&vcc->stats->rx_err);
36413+ atomic_inc_unchecked(&vcc->stats->rx_err);
36414 }
36415 }
36416
36417@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36418 goto retry_here;
36419 }
36420
36421- atomic_inc(&vcc->stats->tx_err);
36422+ atomic_inc_unchecked(&vcc->stats->tx_err);
36423
36424 fore200e->tx_sat++;
36425 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36426diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36427index aa6be26..f70a785 100644
36428--- a/drivers/atm/he.c
36429+++ b/drivers/atm/he.c
36430@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36431
36432 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36433 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36434- atomic_inc(&vcc->stats->rx_drop);
36435+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36436 goto return_host_buffers;
36437 }
36438
36439@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36440 RBRQ_LEN_ERR(he_dev->rbrq_head)
36441 ? "LEN_ERR" : "",
36442 vcc->vpi, vcc->vci);
36443- atomic_inc(&vcc->stats->rx_err);
36444+ atomic_inc_unchecked(&vcc->stats->rx_err);
36445 goto return_host_buffers;
36446 }
36447
36448@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36449 vcc->push(vcc, skb);
36450 spin_lock(&he_dev->global_lock);
36451
36452- atomic_inc(&vcc->stats->rx);
36453+ atomic_inc_unchecked(&vcc->stats->rx);
36454
36455 return_host_buffers:
36456 ++pdus_assembled;
36457@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36458 tpd->vcc->pop(tpd->vcc, tpd->skb);
36459 else
36460 dev_kfree_skb_any(tpd->skb);
36461- atomic_inc(&tpd->vcc->stats->tx_err);
36462+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36463 }
36464 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36465 return;
36466@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36467 vcc->pop(vcc, skb);
36468 else
36469 dev_kfree_skb_any(skb);
36470- atomic_inc(&vcc->stats->tx_err);
36471+ atomic_inc_unchecked(&vcc->stats->tx_err);
36472 return -EINVAL;
36473 }
36474
36475@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36476 vcc->pop(vcc, skb);
36477 else
36478 dev_kfree_skb_any(skb);
36479- atomic_inc(&vcc->stats->tx_err);
36480+ atomic_inc_unchecked(&vcc->stats->tx_err);
36481 return -EINVAL;
36482 }
36483 #endif
36484@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36485 vcc->pop(vcc, skb);
36486 else
36487 dev_kfree_skb_any(skb);
36488- atomic_inc(&vcc->stats->tx_err);
36489+ atomic_inc_unchecked(&vcc->stats->tx_err);
36490 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36491 return -ENOMEM;
36492 }
36493@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36494 vcc->pop(vcc, skb);
36495 else
36496 dev_kfree_skb_any(skb);
36497- atomic_inc(&vcc->stats->tx_err);
36498+ atomic_inc_unchecked(&vcc->stats->tx_err);
36499 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36500 return -ENOMEM;
36501 }
36502@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36503 __enqueue_tpd(he_dev, tpd, cid);
36504 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36505
36506- atomic_inc(&vcc->stats->tx);
36507+ atomic_inc_unchecked(&vcc->stats->tx);
36508
36509 return 0;
36510 }
36511diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36512index 1dc0519..1aadaf7 100644
36513--- a/drivers/atm/horizon.c
36514+++ b/drivers/atm/horizon.c
36515@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36516 {
36517 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36518 // VC layer stats
36519- atomic_inc(&vcc->stats->rx);
36520+ atomic_inc_unchecked(&vcc->stats->rx);
36521 __net_timestamp(skb);
36522 // end of our responsibility
36523 vcc->push (vcc, skb);
36524@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36525 dev->tx_iovec = NULL;
36526
36527 // VC layer stats
36528- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36529+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36530
36531 // free the skb
36532 hrz_kfree_skb (skb);
36533diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36534index 1bdf104..9dc44b1 100644
36535--- a/drivers/atm/idt77252.c
36536+++ b/drivers/atm/idt77252.c
36537@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36538 else
36539 dev_kfree_skb(skb);
36540
36541- atomic_inc(&vcc->stats->tx);
36542+ atomic_inc_unchecked(&vcc->stats->tx);
36543 }
36544
36545 atomic_dec(&scq->used);
36546@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36547 if ((sb = dev_alloc_skb(64)) == NULL) {
36548 printk("%s: Can't allocate buffers for aal0.\n",
36549 card->name);
36550- atomic_add(i, &vcc->stats->rx_drop);
36551+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36552 break;
36553 }
36554 if (!atm_charge(vcc, sb->truesize)) {
36555 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36556 card->name);
36557- atomic_add(i - 1, &vcc->stats->rx_drop);
36558+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36559 dev_kfree_skb(sb);
36560 break;
36561 }
36562@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36563 ATM_SKB(sb)->vcc = vcc;
36564 __net_timestamp(sb);
36565 vcc->push(vcc, sb);
36566- atomic_inc(&vcc->stats->rx);
36567+ atomic_inc_unchecked(&vcc->stats->rx);
36568
36569 cell += ATM_CELL_PAYLOAD;
36570 }
36571@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36572 "(CDC: %08x)\n",
36573 card->name, len, rpp->len, readl(SAR_REG_CDC));
36574 recycle_rx_pool_skb(card, rpp);
36575- atomic_inc(&vcc->stats->rx_err);
36576+ atomic_inc_unchecked(&vcc->stats->rx_err);
36577 return;
36578 }
36579 if (stat & SAR_RSQE_CRC) {
36580 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36581 recycle_rx_pool_skb(card, rpp);
36582- atomic_inc(&vcc->stats->rx_err);
36583+ atomic_inc_unchecked(&vcc->stats->rx_err);
36584 return;
36585 }
36586 if (skb_queue_len(&rpp->queue) > 1) {
36587@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36588 RXPRINTK("%s: Can't alloc RX skb.\n",
36589 card->name);
36590 recycle_rx_pool_skb(card, rpp);
36591- atomic_inc(&vcc->stats->rx_err);
36592+ atomic_inc_unchecked(&vcc->stats->rx_err);
36593 return;
36594 }
36595 if (!atm_charge(vcc, skb->truesize)) {
36596@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36597 __net_timestamp(skb);
36598
36599 vcc->push(vcc, skb);
36600- atomic_inc(&vcc->stats->rx);
36601+ atomic_inc_unchecked(&vcc->stats->rx);
36602
36603 return;
36604 }
36605@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36606 __net_timestamp(skb);
36607
36608 vcc->push(vcc, skb);
36609- atomic_inc(&vcc->stats->rx);
36610+ atomic_inc_unchecked(&vcc->stats->rx);
36611
36612 if (skb->truesize > SAR_FB_SIZE_3)
36613 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36614@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36615 if (vcc->qos.aal != ATM_AAL0) {
36616 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36617 card->name, vpi, vci);
36618- atomic_inc(&vcc->stats->rx_drop);
36619+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36620 goto drop;
36621 }
36622
36623 if ((sb = dev_alloc_skb(64)) == NULL) {
36624 printk("%s: Can't allocate buffers for AAL0.\n",
36625 card->name);
36626- atomic_inc(&vcc->stats->rx_err);
36627+ atomic_inc_unchecked(&vcc->stats->rx_err);
36628 goto drop;
36629 }
36630
36631@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36632 ATM_SKB(sb)->vcc = vcc;
36633 __net_timestamp(sb);
36634 vcc->push(vcc, sb);
36635- atomic_inc(&vcc->stats->rx);
36636+ atomic_inc_unchecked(&vcc->stats->rx);
36637
36638 drop:
36639 skb_pull(queue, 64);
36640@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36641
36642 if (vc == NULL) {
36643 printk("%s: NULL connection in send().\n", card->name);
36644- atomic_inc(&vcc->stats->tx_err);
36645+ atomic_inc_unchecked(&vcc->stats->tx_err);
36646 dev_kfree_skb(skb);
36647 return -EINVAL;
36648 }
36649 if (!test_bit(VCF_TX, &vc->flags)) {
36650 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36651- atomic_inc(&vcc->stats->tx_err);
36652+ atomic_inc_unchecked(&vcc->stats->tx_err);
36653 dev_kfree_skb(skb);
36654 return -EINVAL;
36655 }
36656@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36657 break;
36658 default:
36659 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36660- atomic_inc(&vcc->stats->tx_err);
36661+ atomic_inc_unchecked(&vcc->stats->tx_err);
36662 dev_kfree_skb(skb);
36663 return -EINVAL;
36664 }
36665
36666 if (skb_shinfo(skb)->nr_frags != 0) {
36667 printk("%s: No scatter-gather yet.\n", card->name);
36668- atomic_inc(&vcc->stats->tx_err);
36669+ atomic_inc_unchecked(&vcc->stats->tx_err);
36670 dev_kfree_skb(skb);
36671 return -EINVAL;
36672 }
36673@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36674
36675 err = queue_skb(card, vc, skb, oam);
36676 if (err) {
36677- atomic_inc(&vcc->stats->tx_err);
36678+ atomic_inc_unchecked(&vcc->stats->tx_err);
36679 dev_kfree_skb(skb);
36680 return err;
36681 }
36682@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36683 skb = dev_alloc_skb(64);
36684 if (!skb) {
36685 printk("%s: Out of memory in send_oam().\n", card->name);
36686- atomic_inc(&vcc->stats->tx_err);
36687+ atomic_inc_unchecked(&vcc->stats->tx_err);
36688 return -ENOMEM;
36689 }
36690 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36691diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36692index 4217f29..88f547a 100644
36693--- a/drivers/atm/iphase.c
36694+++ b/drivers/atm/iphase.c
36695@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36696 status = (u_short) (buf_desc_ptr->desc_mode);
36697 if (status & (RX_CER | RX_PTE | RX_OFL))
36698 {
36699- atomic_inc(&vcc->stats->rx_err);
36700+ atomic_inc_unchecked(&vcc->stats->rx_err);
36701 IF_ERR(printk("IA: bad packet, dropping it");)
36702 if (status & RX_CER) {
36703 IF_ERR(printk(" cause: packet CRC error\n");)
36704@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36705 len = dma_addr - buf_addr;
36706 if (len > iadev->rx_buf_sz) {
36707 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36708- atomic_inc(&vcc->stats->rx_err);
36709+ atomic_inc_unchecked(&vcc->stats->rx_err);
36710 goto out_free_desc;
36711 }
36712
36713@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36714 ia_vcc = INPH_IA_VCC(vcc);
36715 if (ia_vcc == NULL)
36716 {
36717- atomic_inc(&vcc->stats->rx_err);
36718+ atomic_inc_unchecked(&vcc->stats->rx_err);
36719 atm_return(vcc, skb->truesize);
36720 dev_kfree_skb_any(skb);
36721 goto INCR_DLE;
36722@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36723 if ((length > iadev->rx_buf_sz) || (length >
36724 (skb->len - sizeof(struct cpcs_trailer))))
36725 {
36726- atomic_inc(&vcc->stats->rx_err);
36727+ atomic_inc_unchecked(&vcc->stats->rx_err);
36728 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36729 length, skb->len);)
36730 atm_return(vcc, skb->truesize);
36731@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36732
36733 IF_RX(printk("rx_dle_intr: skb push");)
36734 vcc->push(vcc,skb);
36735- atomic_inc(&vcc->stats->rx);
36736+ atomic_inc_unchecked(&vcc->stats->rx);
36737 iadev->rx_pkt_cnt++;
36738 }
36739 INCR_DLE:
36740@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36741 {
36742 struct k_sonet_stats *stats;
36743 stats = &PRIV(_ia_dev[board])->sonet_stats;
36744- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36745- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36746- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36747- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36748- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36749- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36750- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36751- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36752- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36753+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36754+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36755+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36756+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36757+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36758+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36759+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36760+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36761+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36762 }
36763 ia_cmds.status = 0;
36764 break;
36765@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36766 if ((desc == 0) || (desc > iadev->num_tx_desc))
36767 {
36768 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36769- atomic_inc(&vcc->stats->tx);
36770+ atomic_inc_unchecked(&vcc->stats->tx);
36771 if (vcc->pop)
36772 vcc->pop(vcc, skb);
36773 else
36774@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36775 ATM_DESC(skb) = vcc->vci;
36776 skb_queue_tail(&iadev->tx_dma_q, skb);
36777
36778- atomic_inc(&vcc->stats->tx);
36779+ atomic_inc_unchecked(&vcc->stats->tx);
36780 iadev->tx_pkt_cnt++;
36781 /* Increment transaction counter */
36782 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36783
36784 #if 0
36785 /* add flow control logic */
36786- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36787+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36788 if (iavcc->vc_desc_cnt > 10) {
36789 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36790 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36791diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36792index fa7d701..1e404c7 100644
36793--- a/drivers/atm/lanai.c
36794+++ b/drivers/atm/lanai.c
36795@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36796 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36797 lanai_endtx(lanai, lvcc);
36798 lanai_free_skb(lvcc->tx.atmvcc, skb);
36799- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36800+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36801 }
36802
36803 /* Try to fill the buffer - don't call unless there is backlog */
36804@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36805 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36806 __net_timestamp(skb);
36807 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36808- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36809+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36810 out:
36811 lvcc->rx.buf.ptr = end;
36812 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36813@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36814 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36815 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36816 lanai->stats.service_rxnotaal5++;
36817- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36818+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36819 return 0;
36820 }
36821 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36822@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36823 int bytes;
36824 read_unlock(&vcc_sklist_lock);
36825 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36826- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36827+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36828 lvcc->stats.x.aal5.service_trash++;
36829 bytes = (SERVICE_GET_END(s) * 16) -
36830 (((unsigned long) lvcc->rx.buf.ptr) -
36831@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36832 }
36833 if (s & SERVICE_STREAM) {
36834 read_unlock(&vcc_sklist_lock);
36835- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36836+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36837 lvcc->stats.x.aal5.service_stream++;
36838 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36839 "PDU on VCI %d!\n", lanai->number, vci);
36840@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36841 return 0;
36842 }
36843 DPRINTK("got rx crc error on vci %d\n", vci);
36844- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36845+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36846 lvcc->stats.x.aal5.service_rxcrc++;
36847 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36848 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36849diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36850index 9587e95..b45c5cb 100644
36851--- a/drivers/atm/nicstar.c
36852+++ b/drivers/atm/nicstar.c
36853@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36854 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36855 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36856 card->index);
36857- atomic_inc(&vcc->stats->tx_err);
36858+ atomic_inc_unchecked(&vcc->stats->tx_err);
36859 dev_kfree_skb_any(skb);
36860 return -EINVAL;
36861 }
36862@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36863 if (!vc->tx) {
36864 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36865 card->index);
36866- atomic_inc(&vcc->stats->tx_err);
36867+ atomic_inc_unchecked(&vcc->stats->tx_err);
36868 dev_kfree_skb_any(skb);
36869 return -EINVAL;
36870 }
36871@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36872 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36873 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36874 card->index);
36875- atomic_inc(&vcc->stats->tx_err);
36876+ atomic_inc_unchecked(&vcc->stats->tx_err);
36877 dev_kfree_skb_any(skb);
36878 return -EINVAL;
36879 }
36880
36881 if (skb_shinfo(skb)->nr_frags != 0) {
36882 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36883- atomic_inc(&vcc->stats->tx_err);
36884+ atomic_inc_unchecked(&vcc->stats->tx_err);
36885 dev_kfree_skb_any(skb);
36886 return -EINVAL;
36887 }
36888@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36889 }
36890
36891 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36892- atomic_inc(&vcc->stats->tx_err);
36893+ atomic_inc_unchecked(&vcc->stats->tx_err);
36894 dev_kfree_skb_any(skb);
36895 return -EIO;
36896 }
36897- atomic_inc(&vcc->stats->tx);
36898+ atomic_inc_unchecked(&vcc->stats->tx);
36899
36900 return 0;
36901 }
36902@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36903 printk
36904 ("nicstar%d: Can't allocate buffers for aal0.\n",
36905 card->index);
36906- atomic_add(i, &vcc->stats->rx_drop);
36907+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36908 break;
36909 }
36910 if (!atm_charge(vcc, sb->truesize)) {
36911 RXPRINTK
36912 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36913 card->index);
36914- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36915+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36916 dev_kfree_skb_any(sb);
36917 break;
36918 }
36919@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36920 ATM_SKB(sb)->vcc = vcc;
36921 __net_timestamp(sb);
36922 vcc->push(vcc, sb);
36923- atomic_inc(&vcc->stats->rx);
36924+ atomic_inc_unchecked(&vcc->stats->rx);
36925 cell += ATM_CELL_PAYLOAD;
36926 }
36927
36928@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36929 if (iovb == NULL) {
36930 printk("nicstar%d: Out of iovec buffers.\n",
36931 card->index);
36932- atomic_inc(&vcc->stats->rx_drop);
36933+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36934 recycle_rx_buf(card, skb);
36935 return;
36936 }
36937@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36938 small or large buffer itself. */
36939 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36940 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36941- atomic_inc(&vcc->stats->rx_err);
36942+ atomic_inc_unchecked(&vcc->stats->rx_err);
36943 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36944 NS_MAX_IOVECS);
36945 NS_PRV_IOVCNT(iovb) = 0;
36946@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36947 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36948 card->index);
36949 which_list(card, skb);
36950- atomic_inc(&vcc->stats->rx_err);
36951+ atomic_inc_unchecked(&vcc->stats->rx_err);
36952 recycle_rx_buf(card, skb);
36953 vc->rx_iov = NULL;
36954 recycle_iov_buf(card, iovb);
36955@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36956 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36957 card->index);
36958 which_list(card, skb);
36959- atomic_inc(&vcc->stats->rx_err);
36960+ atomic_inc_unchecked(&vcc->stats->rx_err);
36961 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36962 NS_PRV_IOVCNT(iovb));
36963 vc->rx_iov = NULL;
36964@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36965 printk(" - PDU size mismatch.\n");
36966 else
36967 printk(".\n");
36968- atomic_inc(&vcc->stats->rx_err);
36969+ atomic_inc_unchecked(&vcc->stats->rx_err);
36970 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36971 NS_PRV_IOVCNT(iovb));
36972 vc->rx_iov = NULL;
36973@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36974 /* skb points to a small buffer */
36975 if (!atm_charge(vcc, skb->truesize)) {
36976 push_rxbufs(card, skb);
36977- atomic_inc(&vcc->stats->rx_drop);
36978+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36979 } else {
36980 skb_put(skb, len);
36981 dequeue_sm_buf(card, skb);
36982@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36983 ATM_SKB(skb)->vcc = vcc;
36984 __net_timestamp(skb);
36985 vcc->push(vcc, skb);
36986- atomic_inc(&vcc->stats->rx);
36987+ atomic_inc_unchecked(&vcc->stats->rx);
36988 }
36989 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36990 struct sk_buff *sb;
36991@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36992 if (len <= NS_SMBUFSIZE) {
36993 if (!atm_charge(vcc, sb->truesize)) {
36994 push_rxbufs(card, sb);
36995- atomic_inc(&vcc->stats->rx_drop);
36996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36997 } else {
36998 skb_put(sb, len);
36999 dequeue_sm_buf(card, sb);
37000@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37001 ATM_SKB(sb)->vcc = vcc;
37002 __net_timestamp(sb);
37003 vcc->push(vcc, sb);
37004- atomic_inc(&vcc->stats->rx);
37005+ atomic_inc_unchecked(&vcc->stats->rx);
37006 }
37007
37008 push_rxbufs(card, skb);
37009@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37010
37011 if (!atm_charge(vcc, skb->truesize)) {
37012 push_rxbufs(card, skb);
37013- atomic_inc(&vcc->stats->rx_drop);
37014+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37015 } else {
37016 dequeue_lg_buf(card, skb);
37017 #ifdef NS_USE_DESTRUCTORS
37018@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37019 ATM_SKB(skb)->vcc = vcc;
37020 __net_timestamp(skb);
37021 vcc->push(vcc, skb);
37022- atomic_inc(&vcc->stats->rx);
37023+ atomic_inc_unchecked(&vcc->stats->rx);
37024 }
37025
37026 push_rxbufs(card, sb);
37027@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37028 printk
37029 ("nicstar%d: Out of huge buffers.\n",
37030 card->index);
37031- atomic_inc(&vcc->stats->rx_drop);
37032+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37033 recycle_iovec_rx_bufs(card,
37034 (struct iovec *)
37035 iovb->data,
37036@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37037 card->hbpool.count++;
37038 } else
37039 dev_kfree_skb_any(hb);
37040- atomic_inc(&vcc->stats->rx_drop);
37041+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37042 } else {
37043 /* Copy the small buffer to the huge buffer */
37044 sb = (struct sk_buff *)iov->iov_base;
37045@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37046 #endif /* NS_USE_DESTRUCTORS */
37047 __net_timestamp(hb);
37048 vcc->push(vcc, hb);
37049- atomic_inc(&vcc->stats->rx);
37050+ atomic_inc_unchecked(&vcc->stats->rx);
37051 }
37052 }
37053
37054diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37055index e3fb496..d9646bf 100644
37056--- a/drivers/atm/solos-pci.c
37057+++ b/drivers/atm/solos-pci.c
37058@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37059 }
37060 atm_charge(vcc, skb->truesize);
37061 vcc->push(vcc, skb);
37062- atomic_inc(&vcc->stats->rx);
37063+ atomic_inc_unchecked(&vcc->stats->rx);
37064 break;
37065
37066 case PKT_STATUS:
37067@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37068 vcc = SKB_CB(oldskb)->vcc;
37069
37070 if (vcc) {
37071- atomic_inc(&vcc->stats->tx);
37072+ atomic_inc_unchecked(&vcc->stats->tx);
37073 solos_pop(vcc, oldskb);
37074 } else {
37075 dev_kfree_skb_irq(oldskb);
37076diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37077index 0215934..ce9f5b1 100644
37078--- a/drivers/atm/suni.c
37079+++ b/drivers/atm/suni.c
37080@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37081
37082
37083 #define ADD_LIMITED(s,v) \
37084- atomic_add((v),&stats->s); \
37085- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37086+ atomic_add_unchecked((v),&stats->s); \
37087+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37088
37089
37090 static void suni_hz(unsigned long from_timer)
37091diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37092index 5120a96..e2572bd 100644
37093--- a/drivers/atm/uPD98402.c
37094+++ b/drivers/atm/uPD98402.c
37095@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37096 struct sonet_stats tmp;
37097 int error = 0;
37098
37099- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37100+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37101 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37102 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37103 if (zero && !error) {
37104@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37105
37106
37107 #define ADD_LIMITED(s,v) \
37108- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37109- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37110- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37111+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37112+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37113+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37114
37115
37116 static void stat_event(struct atm_dev *dev)
37117@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37118 if (reason & uPD98402_INT_PFM) stat_event(dev);
37119 if (reason & uPD98402_INT_PCO) {
37120 (void) GET(PCOCR); /* clear interrupt cause */
37121- atomic_add(GET(HECCT),
37122+ atomic_add_unchecked(GET(HECCT),
37123 &PRIV(dev)->sonet_stats.uncorr_hcs);
37124 }
37125 if ((reason & uPD98402_INT_RFO) &&
37126@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37127 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37128 uPD98402_INT_LOS),PIMR); /* enable them */
37129 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37130- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37131- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37132- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37133+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37134+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37135+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37136 return 0;
37137 }
37138
37139diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37140index 969c3c2..9b72956 100644
37141--- a/drivers/atm/zatm.c
37142+++ b/drivers/atm/zatm.c
37143@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37144 }
37145 if (!size) {
37146 dev_kfree_skb_irq(skb);
37147- if (vcc) atomic_inc(&vcc->stats->rx_err);
37148+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37149 continue;
37150 }
37151 if (!atm_charge(vcc,skb->truesize)) {
37152@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37153 skb->len = size;
37154 ATM_SKB(skb)->vcc = vcc;
37155 vcc->push(vcc,skb);
37156- atomic_inc(&vcc->stats->rx);
37157+ atomic_inc_unchecked(&vcc->stats->rx);
37158 }
37159 zout(pos & 0xffff,MTA(mbx));
37160 #if 0 /* probably a stupid idea */
37161@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37162 skb_queue_head(&zatm_vcc->backlog,skb);
37163 break;
37164 }
37165- atomic_inc(&vcc->stats->tx);
37166+ atomic_inc_unchecked(&vcc->stats->tx);
37167 wake_up(&zatm_vcc->tx_wait);
37168 }
37169
37170diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37171index 59dc808..f10c74e 100644
37172--- a/drivers/base/bus.c
37173+++ b/drivers/base/bus.c
37174@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37175 return -EINVAL;
37176
37177 mutex_lock(&subsys->p->mutex);
37178- list_add_tail(&sif->node, &subsys->p->interfaces);
37179+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37180 if (sif->add_dev) {
37181 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37182 while ((dev = subsys_dev_iter_next(&iter)))
37183@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37184 subsys = sif->subsys;
37185
37186 mutex_lock(&subsys->p->mutex);
37187- list_del_init(&sif->node);
37188+ pax_list_del_init((struct list_head *)&sif->node);
37189 if (sif->remove_dev) {
37190 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37191 while ((dev = subsys_dev_iter_next(&iter)))
37192diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37193index 25798db..15f130e 100644
37194--- a/drivers/base/devtmpfs.c
37195+++ b/drivers/base/devtmpfs.c
37196@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37197 if (!thread)
37198 return 0;
37199
37200- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37201+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37202 if (err)
37203 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37204 else
37205@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37206 *err = sys_unshare(CLONE_NEWNS);
37207 if (*err)
37208 goto out;
37209- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37210+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37211 if (*err)
37212 goto out;
37213- sys_chdir("/.."); /* will traverse into overmounted root */
37214- sys_chroot(".");
37215+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37216+ sys_chroot((char __force_user *)".");
37217 complete(&setup_done);
37218 while (1) {
37219 spin_lock(&req_lock);
37220diff --git a/drivers/base/node.c b/drivers/base/node.c
37221index bc9f43b..29703b8 100644
37222--- a/drivers/base/node.c
37223+++ b/drivers/base/node.c
37224@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37225 struct node_attr {
37226 struct device_attribute attr;
37227 enum node_states state;
37228-};
37229+} __do_const;
37230
37231 static ssize_t show_node_state(struct device *dev,
37232 struct device_attribute *attr, char *buf)
37233diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37234index bfb8955..4ebff34 100644
37235--- a/drivers/base/power/domain.c
37236+++ b/drivers/base/power/domain.c
37237@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37238
37239 if (dev->power.subsys_data->domain_data) {
37240 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37241- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37242+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37243 if (clear_td)
37244- gpd_data->td = (struct gpd_timing_data){ 0 };
37245+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37246
37247 if (--gpd_data->refcount == 0) {
37248 dev->power.subsys_data->domain_data = NULL;
37249@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37250 {
37251 struct cpuidle_driver *cpuidle_drv;
37252 struct gpd_cpu_data *cpu_data;
37253- struct cpuidle_state *idle_state;
37254+ cpuidle_state_no_const *idle_state;
37255 int ret = 0;
37256
37257 if (IS_ERR_OR_NULL(genpd) || state < 0)
37258@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37259 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37260 {
37261 struct gpd_cpu_data *cpu_data;
37262- struct cpuidle_state *idle_state;
37263+ cpuidle_state_no_const *idle_state;
37264 int ret = 0;
37265
37266 if (IS_ERR_OR_NULL(genpd))
37267diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37268index 03e089a..0e9560c 100644
37269--- a/drivers/base/power/sysfs.c
37270+++ b/drivers/base/power/sysfs.c
37271@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37272 return -EIO;
37273 }
37274 }
37275- return sprintf(buf, p);
37276+ return sprintf(buf, "%s", p);
37277 }
37278
37279 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37280diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37281index 2d56f41..8830f19 100644
37282--- a/drivers/base/power/wakeup.c
37283+++ b/drivers/base/power/wakeup.c
37284@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37285 * They need to be modified together atomically, so it's better to use one
37286 * atomic variable to hold them both.
37287 */
37288-static atomic_t combined_event_count = ATOMIC_INIT(0);
37289+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37290
37291 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37292 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37293
37294 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37295 {
37296- unsigned int comb = atomic_read(&combined_event_count);
37297+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37298
37299 *cnt = (comb >> IN_PROGRESS_BITS);
37300 *inpr = comb & MAX_IN_PROGRESS;
37301@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37302 ws->start_prevent_time = ws->last_time;
37303
37304 /* Increment the counter of events in progress. */
37305- cec = atomic_inc_return(&combined_event_count);
37306+ cec = atomic_inc_return_unchecked(&combined_event_count);
37307
37308 trace_wakeup_source_activate(ws->name, cec);
37309 }
37310@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37311 * Increment the counter of registered wakeup events and decrement the
37312 * couter of wakeup events in progress simultaneously.
37313 */
37314- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37315+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37316 trace_wakeup_source_deactivate(ws->name, cec);
37317
37318 split_counters(&cnt, &inpr);
37319diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37320index e8d11b6..7b1b36f 100644
37321--- a/drivers/base/syscore.c
37322+++ b/drivers/base/syscore.c
37323@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37324 void register_syscore_ops(struct syscore_ops *ops)
37325 {
37326 mutex_lock(&syscore_ops_lock);
37327- list_add_tail(&ops->node, &syscore_ops_list);
37328+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37329 mutex_unlock(&syscore_ops_lock);
37330 }
37331 EXPORT_SYMBOL_GPL(register_syscore_ops);
37332@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37333 void unregister_syscore_ops(struct syscore_ops *ops)
37334 {
37335 mutex_lock(&syscore_ops_lock);
37336- list_del(&ops->node);
37337+ pax_list_del((struct list_head *)&ops->node);
37338 mutex_unlock(&syscore_ops_lock);
37339 }
37340 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37341diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37342index 036e8ab..6221dec 100644
37343--- a/drivers/block/cciss.c
37344+++ b/drivers/block/cciss.c
37345@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37346 while (!list_empty(&h->reqQ)) {
37347 c = list_entry(h->reqQ.next, CommandList_struct, list);
37348 /* can't do anything if fifo is full */
37349- if ((h->access.fifo_full(h))) {
37350+ if ((h->access->fifo_full(h))) {
37351 dev_warn(&h->pdev->dev, "fifo full\n");
37352 break;
37353 }
37354@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37355 h->Qdepth--;
37356
37357 /* Tell the controller execute command */
37358- h->access.submit_command(h, c);
37359+ h->access->submit_command(h, c);
37360
37361 /* Put job onto the completed Q */
37362 addQ(&h->cmpQ, c);
37363@@ -3447,17 +3447,17 @@ startio:
37364
37365 static inline unsigned long get_next_completion(ctlr_info_t *h)
37366 {
37367- return h->access.command_completed(h);
37368+ return h->access->command_completed(h);
37369 }
37370
37371 static inline int interrupt_pending(ctlr_info_t *h)
37372 {
37373- return h->access.intr_pending(h);
37374+ return h->access->intr_pending(h);
37375 }
37376
37377 static inline long interrupt_not_for_us(ctlr_info_t *h)
37378 {
37379- return ((h->access.intr_pending(h) == 0) ||
37380+ return ((h->access->intr_pending(h) == 0) ||
37381 (h->interrupts_enabled == 0));
37382 }
37383
37384@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37385 u32 a;
37386
37387 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37388- return h->access.command_completed(h);
37389+ return h->access->command_completed(h);
37390
37391 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37392 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37393@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37394 trans_support & CFGTBL_Trans_use_short_tags);
37395
37396 /* Change the access methods to the performant access methods */
37397- h->access = SA5_performant_access;
37398+ h->access = &SA5_performant_access;
37399 h->transMethod = CFGTBL_Trans_Performant;
37400
37401 return;
37402@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37403 if (prod_index < 0)
37404 return -ENODEV;
37405 h->product_name = products[prod_index].product_name;
37406- h->access = *(products[prod_index].access);
37407+ h->access = products[prod_index].access;
37408
37409 if (cciss_board_disabled(h)) {
37410 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37411@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37412 }
37413
37414 /* make sure the board interrupts are off */
37415- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37416+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37417 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37418 if (rc)
37419 goto clean2;
37420@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37421 * fake ones to scoop up any residual completions.
37422 */
37423 spin_lock_irqsave(&h->lock, flags);
37424- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37425+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37426 spin_unlock_irqrestore(&h->lock, flags);
37427 free_irq(h->intr[h->intr_mode], h);
37428 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37429@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37430 dev_info(&h->pdev->dev, "Board READY.\n");
37431 dev_info(&h->pdev->dev,
37432 "Waiting for stale completions to drain.\n");
37433- h->access.set_intr_mask(h, CCISS_INTR_ON);
37434+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37435 msleep(10000);
37436- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37437+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37438
37439 rc = controller_reset_failed(h->cfgtable);
37440 if (rc)
37441@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37442 cciss_scsi_setup(h);
37443
37444 /* Turn the interrupts on so we can service requests */
37445- h->access.set_intr_mask(h, CCISS_INTR_ON);
37446+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37447
37448 /* Get the firmware version */
37449 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37450@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37451 kfree(flush_buf);
37452 if (return_code != IO_OK)
37453 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37454- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37455+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37456 free_irq(h->intr[h->intr_mode], h);
37457 }
37458
37459diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37460index 7fda30e..2f27946 100644
37461--- a/drivers/block/cciss.h
37462+++ b/drivers/block/cciss.h
37463@@ -101,7 +101,7 @@ struct ctlr_info
37464 /* information about each logical volume */
37465 drive_info_struct *drv[CISS_MAX_LUN];
37466
37467- struct access_method access;
37468+ struct access_method *access;
37469
37470 /* queue and queue Info */
37471 struct list_head reqQ;
37472@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37473 }
37474
37475 static struct access_method SA5_access = {
37476- SA5_submit_command,
37477- SA5_intr_mask,
37478- SA5_fifo_full,
37479- SA5_intr_pending,
37480- SA5_completed,
37481+ .submit_command = SA5_submit_command,
37482+ .set_intr_mask = SA5_intr_mask,
37483+ .fifo_full = SA5_fifo_full,
37484+ .intr_pending = SA5_intr_pending,
37485+ .command_completed = SA5_completed,
37486 };
37487
37488 static struct access_method SA5B_access = {
37489- SA5_submit_command,
37490- SA5B_intr_mask,
37491- SA5_fifo_full,
37492- SA5B_intr_pending,
37493- SA5_completed,
37494+ .submit_command = SA5_submit_command,
37495+ .set_intr_mask = SA5B_intr_mask,
37496+ .fifo_full = SA5_fifo_full,
37497+ .intr_pending = SA5B_intr_pending,
37498+ .command_completed = SA5_completed,
37499 };
37500
37501 static struct access_method SA5_performant_access = {
37502- SA5_submit_command,
37503- SA5_performant_intr_mask,
37504- SA5_fifo_full,
37505- SA5_performant_intr_pending,
37506- SA5_performant_completed,
37507+ .submit_command = SA5_submit_command,
37508+ .set_intr_mask = SA5_performant_intr_mask,
37509+ .fifo_full = SA5_fifo_full,
37510+ .intr_pending = SA5_performant_intr_pending,
37511+ .command_completed = SA5_performant_completed,
37512 };
37513
37514 struct board_type {
37515diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37516index 2b94403..fd6ad1f 100644
37517--- a/drivers/block/cpqarray.c
37518+++ b/drivers/block/cpqarray.c
37519@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37520 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37521 goto Enomem4;
37522 }
37523- hba[i]->access.set_intr_mask(hba[i], 0);
37524+ hba[i]->access->set_intr_mask(hba[i], 0);
37525 if (request_irq(hba[i]->intr, do_ida_intr,
37526 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37527 {
37528@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37529 add_timer(&hba[i]->timer);
37530
37531 /* Enable IRQ now that spinlock and rate limit timer are set up */
37532- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37533+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37534
37535 for(j=0; j<NWD; j++) {
37536 struct gendisk *disk = ida_gendisk[i][j];
37537@@ -694,7 +694,7 @@ DBGINFO(
37538 for(i=0; i<NR_PRODUCTS; i++) {
37539 if (board_id == products[i].board_id) {
37540 c->product_name = products[i].product_name;
37541- c->access = *(products[i].access);
37542+ c->access = products[i].access;
37543 break;
37544 }
37545 }
37546@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37547 hba[ctlr]->intr = intr;
37548 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37549 hba[ctlr]->product_name = products[j].product_name;
37550- hba[ctlr]->access = *(products[j].access);
37551+ hba[ctlr]->access = products[j].access;
37552 hba[ctlr]->ctlr = ctlr;
37553 hba[ctlr]->board_id = board_id;
37554 hba[ctlr]->pci_dev = NULL; /* not PCI */
37555@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37556
37557 while((c = h->reqQ) != NULL) {
37558 /* Can't do anything if we're busy */
37559- if (h->access.fifo_full(h) == 0)
37560+ if (h->access->fifo_full(h) == 0)
37561 return;
37562
37563 /* Get the first entry from the request Q */
37564@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37565 h->Qdepth--;
37566
37567 /* Tell the controller to do our bidding */
37568- h->access.submit_command(h, c);
37569+ h->access->submit_command(h, c);
37570
37571 /* Get onto the completion Q */
37572 addQ(&h->cmpQ, c);
37573@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37574 unsigned long flags;
37575 __u32 a,a1;
37576
37577- istat = h->access.intr_pending(h);
37578+ istat = h->access->intr_pending(h);
37579 /* Is this interrupt for us? */
37580 if (istat == 0)
37581 return IRQ_NONE;
37582@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37583 */
37584 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37585 if (istat & FIFO_NOT_EMPTY) {
37586- while((a = h->access.command_completed(h))) {
37587+ while((a = h->access->command_completed(h))) {
37588 a1 = a; a &= ~3;
37589 if ((c = h->cmpQ) == NULL)
37590 {
37591@@ -1448,11 +1448,11 @@ static int sendcmd(
37592 /*
37593 * Disable interrupt
37594 */
37595- info_p->access.set_intr_mask(info_p, 0);
37596+ info_p->access->set_intr_mask(info_p, 0);
37597 /* Make sure there is room in the command FIFO */
37598 /* Actually it should be completely empty at this time. */
37599 for (i = 200000; i > 0; i--) {
37600- temp = info_p->access.fifo_full(info_p);
37601+ temp = info_p->access->fifo_full(info_p);
37602 if (temp != 0) {
37603 break;
37604 }
37605@@ -1465,7 +1465,7 @@ DBG(
37606 /*
37607 * Send the cmd
37608 */
37609- info_p->access.submit_command(info_p, c);
37610+ info_p->access->submit_command(info_p, c);
37611 complete = pollcomplete(ctlr);
37612
37613 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37614@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37615 * we check the new geometry. Then turn interrupts back on when
37616 * we're done.
37617 */
37618- host->access.set_intr_mask(host, 0);
37619+ host->access->set_intr_mask(host, 0);
37620 getgeometry(ctlr);
37621- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37622+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37623
37624 for(i=0; i<NWD; i++) {
37625 struct gendisk *disk = ida_gendisk[ctlr][i];
37626@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37627 /* Wait (up to 2 seconds) for a command to complete */
37628
37629 for (i = 200000; i > 0; i--) {
37630- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37631+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37632 if (done == 0) {
37633 udelay(10); /* a short fixed delay */
37634 } else
37635diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37636index be73e9d..7fbf140 100644
37637--- a/drivers/block/cpqarray.h
37638+++ b/drivers/block/cpqarray.h
37639@@ -99,7 +99,7 @@ struct ctlr_info {
37640 drv_info_t drv[NWD];
37641 struct proc_dir_entry *proc;
37642
37643- struct access_method access;
37644+ struct access_method *access;
37645
37646 cmdlist_t *reqQ;
37647 cmdlist_t *cmpQ;
37648diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37649index 0e06f0c..c47b81d 100644
37650--- a/drivers/block/drbd/drbd_int.h
37651+++ b/drivers/block/drbd/drbd_int.h
37652@@ -582,7 +582,7 @@ struct drbd_epoch {
37653 struct drbd_tconn *tconn;
37654 struct list_head list;
37655 unsigned int barrier_nr;
37656- atomic_t epoch_size; /* increased on every request added. */
37657+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37658 atomic_t active; /* increased on every req. added, and dec on every finished. */
37659 unsigned long flags;
37660 };
37661@@ -1022,7 +1022,7 @@ struct drbd_conf {
37662 unsigned int al_tr_number;
37663 int al_tr_cycle;
37664 wait_queue_head_t seq_wait;
37665- atomic_t packet_seq;
37666+ atomic_unchecked_t packet_seq;
37667 unsigned int peer_seq;
37668 spinlock_t peer_seq_lock;
37669 unsigned int minor;
37670@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37671 char __user *uoptval;
37672 int err;
37673
37674- uoptval = (char __user __force *)optval;
37675+ uoptval = (char __force_user *)optval;
37676
37677 set_fs(KERNEL_DS);
37678 if (level == SOL_SOCKET)
37679diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37680index 89c497c..9c736ae 100644
37681--- a/drivers/block/drbd/drbd_interval.c
37682+++ b/drivers/block/drbd/drbd_interval.c
37683@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37684 }
37685
37686 static const struct rb_augment_callbacks augment_callbacks = {
37687- augment_propagate,
37688- augment_copy,
37689- augment_rotate,
37690+ .propagate = augment_propagate,
37691+ .copy = augment_copy,
37692+ .rotate = augment_rotate,
37693 };
37694
37695 /**
37696diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37697index 929468e..7d934eb 100644
37698--- a/drivers/block/drbd/drbd_main.c
37699+++ b/drivers/block/drbd/drbd_main.c
37700@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37701 p->sector = sector;
37702 p->block_id = block_id;
37703 p->blksize = blksize;
37704- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37705+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37706 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37707 }
37708
37709@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37710 return -EIO;
37711 p->sector = cpu_to_be64(req->i.sector);
37712 p->block_id = (unsigned long)req;
37713- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37714+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37715 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37716 if (mdev->state.conn >= C_SYNC_SOURCE &&
37717 mdev->state.conn <= C_PAUSED_SYNC_T)
37718@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37719 {
37720 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37721
37722- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37723- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37724+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37725+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37726 kfree(tconn->current_epoch);
37727
37728 idr_destroy(&tconn->volumes);
37729diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37730index c706d50..5e1b472 100644
37731--- a/drivers/block/drbd/drbd_nl.c
37732+++ b/drivers/block/drbd/drbd_nl.c
37733@@ -3440,7 +3440,7 @@ out:
37734
37735 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37736 {
37737- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37738+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37739 struct sk_buff *msg;
37740 struct drbd_genlmsghdr *d_out;
37741 unsigned seq;
37742@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37743 return;
37744 }
37745
37746- seq = atomic_inc_return(&drbd_genl_seq);
37747+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37748 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37749 if (!msg)
37750 goto failed;
37751diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37752index d073305..4998fea 100644
37753--- a/drivers/block/drbd/drbd_receiver.c
37754+++ b/drivers/block/drbd/drbd_receiver.c
37755@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37756 {
37757 int err;
37758
37759- atomic_set(&mdev->packet_seq, 0);
37760+ atomic_set_unchecked(&mdev->packet_seq, 0);
37761 mdev->peer_seq = 0;
37762
37763 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37764@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37765 do {
37766 next_epoch = NULL;
37767
37768- epoch_size = atomic_read(&epoch->epoch_size);
37769+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37770
37771 switch (ev & ~EV_CLEANUP) {
37772 case EV_PUT:
37773@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37774 rv = FE_DESTROYED;
37775 } else {
37776 epoch->flags = 0;
37777- atomic_set(&epoch->epoch_size, 0);
37778+ atomic_set_unchecked(&epoch->epoch_size, 0);
37779 /* atomic_set(&epoch->active, 0); is already zero */
37780 if (rv == FE_STILL_LIVE)
37781 rv = FE_RECYCLED;
37782@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37783 conn_wait_active_ee_empty(tconn);
37784 drbd_flush(tconn);
37785
37786- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37787+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37788 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37789 if (epoch)
37790 break;
37791@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37792 }
37793
37794 epoch->flags = 0;
37795- atomic_set(&epoch->epoch_size, 0);
37796+ atomic_set_unchecked(&epoch->epoch_size, 0);
37797 atomic_set(&epoch->active, 0);
37798
37799 spin_lock(&tconn->epoch_lock);
37800- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37801+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37802 list_add(&epoch->list, &tconn->current_epoch->list);
37803 tconn->current_epoch = epoch;
37804 tconn->epochs++;
37805@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37806
37807 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37808 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37809- atomic_inc(&tconn->current_epoch->epoch_size);
37810+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37811 err2 = drbd_drain_block(mdev, pi->size);
37812 if (!err)
37813 err = err2;
37814@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37815
37816 spin_lock(&tconn->epoch_lock);
37817 peer_req->epoch = tconn->current_epoch;
37818- atomic_inc(&peer_req->epoch->epoch_size);
37819+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37820 atomic_inc(&peer_req->epoch->active);
37821 spin_unlock(&tconn->epoch_lock);
37822
37823@@ -4345,7 +4345,7 @@ struct data_cmd {
37824 int expect_payload;
37825 size_t pkt_size;
37826 int (*fn)(struct drbd_tconn *, struct packet_info *);
37827-};
37828+} __do_const;
37829
37830 static struct data_cmd drbd_cmd_handler[] = {
37831 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37832@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37833 if (!list_empty(&tconn->current_epoch->list))
37834 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37835 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37836- atomic_set(&tconn->current_epoch->epoch_size, 0);
37837+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37838 tconn->send.seen_any_write_yet = false;
37839
37840 conn_info(tconn, "Connection closed\n");
37841@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37842 struct asender_cmd {
37843 size_t pkt_size;
37844 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37845-};
37846+} __do_const;
37847
37848 static struct asender_cmd asender_tbl[] = {
37849 [P_PING] = { 0, got_Ping },
37850diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37851index 66e8c3b..9b68dd9 100644
37852--- a/drivers/block/loop.c
37853+++ b/drivers/block/loop.c
37854@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37855
37856 file_start_write(file);
37857 set_fs(get_ds());
37858- bw = file->f_op->write(file, buf, len, &pos);
37859+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37860 set_fs(old_fs);
37861 file_end_write(file);
37862 if (likely(bw == len))
37863diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37864index 091b9ea..f5428f8 100644
37865--- a/drivers/block/null_blk.c
37866+++ b/drivers/block/null_blk.c
37867@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37868 return 0;
37869 }
37870
37871-static struct blk_mq_ops null_mq_ops = {
37872- .queue_rq = null_queue_rq,
37873- .map_queue = blk_mq_map_queue,
37874+static struct blk_mq_ops null_mq_single_ops = {
37875+ .queue_rq = null_queue_rq,
37876+ .map_queue = blk_mq_map_queue,
37877 .init_hctx = null_init_hctx,
37878 .complete = null_softirq_done_fn,
37879+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37880+ .free_hctx = blk_mq_free_single_hw_queue,
37881+};
37882+
37883+static struct blk_mq_ops null_mq_per_node_ops = {
37884+ .queue_rq = null_queue_rq,
37885+ .map_queue = blk_mq_map_queue,
37886+ .init_hctx = null_init_hctx,
37887+ .alloc_hctx = null_alloc_hctx,
37888+ .free_hctx = null_free_hctx,
37889 };
37890
37891 static struct blk_mq_reg null_mq_reg = {
37892- .ops = &null_mq_ops,
37893+ .ops = &null_mq_single_ops,
37894 .queue_depth = 64,
37895 .cmd_size = sizeof(struct nullb_cmd),
37896 .flags = BLK_MQ_F_SHOULD_MERGE,
37897@@ -521,13 +531,8 @@ static int null_add_dev(void)
37898 null_mq_reg.queue_depth = hw_queue_depth;
37899 null_mq_reg.nr_hw_queues = submit_queues;
37900
37901- if (use_per_node_hctx) {
37902- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37903- null_mq_reg.ops->free_hctx = null_free_hctx;
37904- } else {
37905- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37906- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37907- }
37908+ if (use_per_node_hctx)
37909+ null_mq_reg.ops = &null_mq_per_node_ops;
37910
37911 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37912 } else if (queue_mode == NULL_Q_BIO) {
37913diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37914index a2af73d..c0b8f61 100644
37915--- a/drivers/block/pktcdvd.c
37916+++ b/drivers/block/pktcdvd.c
37917@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37918
37919 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37920 {
37921- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37922+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37923 }
37924
37925 /*
37926@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37927 return -EROFS;
37928 }
37929 pd->settings.fp = ti.fp;
37930- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37931+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37932
37933 if (ti.nwa_v) {
37934 pd->nwa = be32_to_cpu(ti.next_writable);
37935diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37936index e5565fb..71be10b4 100644
37937--- a/drivers/block/smart1,2.h
37938+++ b/drivers/block/smart1,2.h
37939@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37940 }
37941
37942 static struct access_method smart4_access = {
37943- smart4_submit_command,
37944- smart4_intr_mask,
37945- smart4_fifo_full,
37946- smart4_intr_pending,
37947- smart4_completed,
37948+ .submit_command = smart4_submit_command,
37949+ .set_intr_mask = smart4_intr_mask,
37950+ .fifo_full = smart4_fifo_full,
37951+ .intr_pending = smart4_intr_pending,
37952+ .command_completed = smart4_completed,
37953 };
37954
37955 /*
37956@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37957 }
37958
37959 static struct access_method smart2_access = {
37960- smart2_submit_command,
37961- smart2_intr_mask,
37962- smart2_fifo_full,
37963- smart2_intr_pending,
37964- smart2_completed,
37965+ .submit_command = smart2_submit_command,
37966+ .set_intr_mask = smart2_intr_mask,
37967+ .fifo_full = smart2_fifo_full,
37968+ .intr_pending = smart2_intr_pending,
37969+ .command_completed = smart2_completed,
37970 };
37971
37972 /*
37973@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37974 }
37975
37976 static struct access_method smart2e_access = {
37977- smart2e_submit_command,
37978- smart2e_intr_mask,
37979- smart2e_fifo_full,
37980- smart2e_intr_pending,
37981- smart2e_completed,
37982+ .submit_command = smart2e_submit_command,
37983+ .set_intr_mask = smart2e_intr_mask,
37984+ .fifo_full = smart2e_fifo_full,
37985+ .intr_pending = smart2e_intr_pending,
37986+ .command_completed = smart2e_completed,
37987 };
37988
37989 /*
37990@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37991 }
37992
37993 static struct access_method smart1_access = {
37994- smart1_submit_command,
37995- smart1_intr_mask,
37996- smart1_fifo_full,
37997- smart1_intr_pending,
37998- smart1_completed,
37999+ .submit_command = smart1_submit_command,
38000+ .set_intr_mask = smart1_intr_mask,
38001+ .fifo_full = smart1_fifo_full,
38002+ .intr_pending = smart1_intr_pending,
38003+ .command_completed = smart1_completed,
38004 };
38005diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38006index f038dba..bb74c08 100644
38007--- a/drivers/bluetooth/btwilink.c
38008+++ b/drivers/bluetooth/btwilink.c
38009@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38010
38011 static int bt_ti_probe(struct platform_device *pdev)
38012 {
38013- static struct ti_st *hst;
38014+ struct ti_st *hst;
38015 struct hci_dev *hdev;
38016 int err;
38017
38018diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38019index 8a3aff7..d7538c2 100644
38020--- a/drivers/cdrom/cdrom.c
38021+++ b/drivers/cdrom/cdrom.c
38022@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38023 ENSURE(reset, CDC_RESET);
38024 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38025 cdi->mc_flags = 0;
38026- cdo->n_minors = 0;
38027 cdi->options = CDO_USE_FFLAGS;
38028
38029 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38030@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38031 else
38032 cdi->cdda_method = CDDA_OLD;
38033
38034- if (!cdo->generic_packet)
38035- cdo->generic_packet = cdrom_dummy_generic_packet;
38036+ if (!cdo->generic_packet) {
38037+ pax_open_kernel();
38038+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38039+ pax_close_kernel();
38040+ }
38041
38042 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38043 mutex_lock(&cdrom_mutex);
38044@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38045 if (cdi->exit)
38046 cdi->exit(cdi);
38047
38048- cdi->ops->n_minors--;
38049 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38050 }
38051
38052@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38053 */
38054 nr = nframes;
38055 do {
38056- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38057+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38058 if (cgc.buffer)
38059 break;
38060
38061@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38062 struct cdrom_device_info *cdi;
38063 int ret;
38064
38065- ret = scnprintf(info + *pos, max_size - *pos, header);
38066+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38067 if (!ret)
38068 return 1;
38069
38070diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38071index 51e75ad..39c4c76 100644
38072--- a/drivers/cdrom/gdrom.c
38073+++ b/drivers/cdrom/gdrom.c
38074@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38075 .audio_ioctl = gdrom_audio_ioctl,
38076 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38077 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38078- .n_minors = 1,
38079 };
38080
38081 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38082diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38083index 1386749..5430258 100644
38084--- a/drivers/char/Kconfig
38085+++ b/drivers/char/Kconfig
38086@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38087
38088 config DEVKMEM
38089 bool "/dev/kmem virtual device support"
38090- default y
38091+ default n
38092+ depends on !GRKERNSEC_KMEM
38093 help
38094 Say Y here if you want to support the /dev/kmem device. The
38095 /dev/kmem device is rarely used, but can be used for certain
38096@@ -577,6 +578,7 @@ config DEVPORT
38097 bool
38098 depends on !M68K
38099 depends on ISA || PCI
38100+ depends on !GRKERNSEC_KMEM
38101 default y
38102
38103 source "drivers/s390/char/Kconfig"
38104diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38105index a48e05b..6bac831 100644
38106--- a/drivers/char/agp/compat_ioctl.c
38107+++ b/drivers/char/agp/compat_ioctl.c
38108@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38109 return -ENOMEM;
38110 }
38111
38112- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38113+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38114 sizeof(*usegment) * ureserve.seg_count)) {
38115 kfree(usegment);
38116 kfree(ksegment);
38117diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38118index 1b19239..b87b143 100644
38119--- a/drivers/char/agp/frontend.c
38120+++ b/drivers/char/agp/frontend.c
38121@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38122 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38123 return -EFAULT;
38124
38125- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38126+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38127 return -EFAULT;
38128
38129 client = agp_find_client_by_pid(reserve.pid);
38130@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38131 if (segment == NULL)
38132 return -ENOMEM;
38133
38134- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38135+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38136 sizeof(struct agp_segment) * reserve.seg_count)) {
38137 kfree(segment);
38138 return -EFAULT;
38139diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38140index 4f94375..413694e 100644
38141--- a/drivers/char/genrtc.c
38142+++ b/drivers/char/genrtc.c
38143@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38144 switch (cmd) {
38145
38146 case RTC_PLL_GET:
38147+ memset(&pll, 0, sizeof(pll));
38148 if (get_rtc_pll(&pll))
38149 return -EINVAL;
38150 else
38151diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38152index d5d4cd8..22d561d 100644
38153--- a/drivers/char/hpet.c
38154+++ b/drivers/char/hpet.c
38155@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38156 }
38157
38158 static int
38159-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38160+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38161 struct hpet_info *info)
38162 {
38163 struct hpet_timer __iomem *timer;
38164diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38165index 86fe45c..c0ea948 100644
38166--- a/drivers/char/hw_random/intel-rng.c
38167+++ b/drivers/char/hw_random/intel-rng.c
38168@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38169
38170 if (no_fwh_detect)
38171 return -ENODEV;
38172- printk(warning);
38173+ printk("%s", warning);
38174 return -EBUSY;
38175 }
38176
38177diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38178index ec4e10f..f2a763b 100644
38179--- a/drivers/char/ipmi/ipmi_msghandler.c
38180+++ b/drivers/char/ipmi/ipmi_msghandler.c
38181@@ -420,7 +420,7 @@ struct ipmi_smi {
38182 struct proc_dir_entry *proc_dir;
38183 char proc_dir_name[10];
38184
38185- atomic_t stats[IPMI_NUM_STATS];
38186+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38187
38188 /*
38189 * run_to_completion duplicate of smb_info, smi_info
38190@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38191
38192
38193 #define ipmi_inc_stat(intf, stat) \
38194- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38195+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38196 #define ipmi_get_stat(intf, stat) \
38197- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38198+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38199
38200 static int is_lan_addr(struct ipmi_addr *addr)
38201 {
38202@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38203 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38204 init_waitqueue_head(&intf->waitq);
38205 for (i = 0; i < IPMI_NUM_STATS; i++)
38206- atomic_set(&intf->stats[i], 0);
38207+ atomic_set_unchecked(&intf->stats[i], 0);
38208
38209 intf->proc_dir = NULL;
38210
38211diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38212index 03f4189..e79f5e0 100644
38213--- a/drivers/char/ipmi/ipmi_si_intf.c
38214+++ b/drivers/char/ipmi/ipmi_si_intf.c
38215@@ -280,7 +280,7 @@ struct smi_info {
38216 unsigned char slave_addr;
38217
38218 /* Counters and things for the proc filesystem. */
38219- atomic_t stats[SI_NUM_STATS];
38220+ atomic_unchecked_t stats[SI_NUM_STATS];
38221
38222 struct task_struct *thread;
38223
38224@@ -289,9 +289,9 @@ struct smi_info {
38225 };
38226
38227 #define smi_inc_stat(smi, stat) \
38228- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38229+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38230 #define smi_get_stat(smi, stat) \
38231- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38232+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38233
38234 #define SI_MAX_PARMS 4
38235
38236@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38237 atomic_set(&new_smi->req_events, 0);
38238 new_smi->run_to_completion = 0;
38239 for (i = 0; i < SI_NUM_STATS; i++)
38240- atomic_set(&new_smi->stats[i], 0);
38241+ atomic_set_unchecked(&new_smi->stats[i], 0);
38242
38243 new_smi->interrupt_disabled = 1;
38244 atomic_set(&new_smi->stop_operation, 0);
38245diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38246index 92c5937..1be4e4d 100644
38247--- a/drivers/char/mem.c
38248+++ b/drivers/char/mem.c
38249@@ -18,6 +18,7 @@
38250 #include <linux/raw.h>
38251 #include <linux/tty.h>
38252 #include <linux/capability.h>
38253+#include <linux/security.h>
38254 #include <linux/ptrace.h>
38255 #include <linux/device.h>
38256 #include <linux/highmem.h>
38257@@ -36,6 +37,10 @@
38258
38259 #define DEVPORT_MINOR 4
38260
38261+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38262+extern const struct file_operations grsec_fops;
38263+#endif
38264+
38265 static inline unsigned long size_inside_page(unsigned long start,
38266 unsigned long size)
38267 {
38268@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38269
38270 while (cursor < to) {
38271 if (!devmem_is_allowed(pfn)) {
38272+#ifdef CONFIG_GRKERNSEC_KMEM
38273+ gr_handle_mem_readwrite(from, to);
38274+#else
38275 printk(KERN_INFO
38276 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38277 current->comm, from, to);
38278+#endif
38279 return 0;
38280 }
38281 cursor += PAGE_SIZE;
38282@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38283 }
38284 return 1;
38285 }
38286+#elif defined(CONFIG_GRKERNSEC_KMEM)
38287+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38288+{
38289+ return 0;
38290+}
38291 #else
38292 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38293 {
38294@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38295
38296 while (count > 0) {
38297 unsigned long remaining;
38298+ char *temp;
38299
38300 sz = size_inside_page(p, count);
38301
38302@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38303 if (!ptr)
38304 return -EFAULT;
38305
38306- remaining = copy_to_user(buf, ptr, sz);
38307+#ifdef CONFIG_PAX_USERCOPY
38308+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38309+ if (!temp) {
38310+ unxlate_dev_mem_ptr(p, ptr);
38311+ return -ENOMEM;
38312+ }
38313+ memcpy(temp, ptr, sz);
38314+#else
38315+ temp = ptr;
38316+#endif
38317+
38318+ remaining = copy_to_user(buf, temp, sz);
38319+
38320+#ifdef CONFIG_PAX_USERCOPY
38321+ kfree(temp);
38322+#endif
38323+
38324 unxlate_dev_mem_ptr(p, ptr);
38325 if (remaining)
38326 return -EFAULT;
38327@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38328 size_t count, loff_t *ppos)
38329 {
38330 unsigned long p = *ppos;
38331- ssize_t low_count, read, sz;
38332+ ssize_t low_count, read, sz, err = 0;
38333 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38334- int err = 0;
38335
38336 read = 0;
38337 if (p < (unsigned long) high_memory) {
38338@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38339 }
38340 #endif
38341 while (low_count > 0) {
38342+ char *temp;
38343+
38344 sz = size_inside_page(p, low_count);
38345
38346 /*
38347@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38348 */
38349 kbuf = xlate_dev_kmem_ptr((char *)p);
38350
38351- if (copy_to_user(buf, kbuf, sz))
38352+#ifdef CONFIG_PAX_USERCOPY
38353+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38354+ if (!temp)
38355+ return -ENOMEM;
38356+ memcpy(temp, kbuf, sz);
38357+#else
38358+ temp = kbuf;
38359+#endif
38360+
38361+ err = copy_to_user(buf, temp, sz);
38362+
38363+#ifdef CONFIG_PAX_USERCOPY
38364+ kfree(temp);
38365+#endif
38366+
38367+ if (err)
38368 return -EFAULT;
38369 buf += sz;
38370 p += sz;
38371@@ -821,6 +868,9 @@ static const struct memdev {
38372 #ifdef CONFIG_PRINTK
38373 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38374 #endif
38375+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38376+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38377+#endif
38378 };
38379
38380 static int memory_open(struct inode *inode, struct file *filp)
38381@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38382 continue;
38383
38384 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38385- NULL, devlist[minor].name);
38386+ NULL, "%s", devlist[minor].name);
38387 }
38388
38389 return tty_init();
38390diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38391index 9df78e2..01ba9ae 100644
38392--- a/drivers/char/nvram.c
38393+++ b/drivers/char/nvram.c
38394@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38395
38396 spin_unlock_irq(&rtc_lock);
38397
38398- if (copy_to_user(buf, contents, tmp - contents))
38399+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38400 return -EFAULT;
38401
38402 *ppos = i;
38403diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38404index 8320abd..ec48108 100644
38405--- a/drivers/char/pcmcia/synclink_cs.c
38406+++ b/drivers/char/pcmcia/synclink_cs.c
38407@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38408
38409 if (debug_level >= DEBUG_LEVEL_INFO)
38410 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38411- __FILE__, __LINE__, info->device_name, port->count);
38412+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38413
38414- WARN_ON(!port->count);
38415+ WARN_ON(!atomic_read(&port->count));
38416
38417 if (tty_port_close_start(port, tty, filp) == 0)
38418 goto cleanup;
38419@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38420 cleanup:
38421 if (debug_level >= DEBUG_LEVEL_INFO)
38422 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38423- tty->driver->name, port->count);
38424+ tty->driver->name, atomic_read(&port->count));
38425 }
38426
38427 /* Wait until the transmitter is empty.
38428@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38429
38430 if (debug_level >= DEBUG_LEVEL_INFO)
38431 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38432- __FILE__, __LINE__, tty->driver->name, port->count);
38433+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38434
38435 /* If port is closing, signal caller to try again */
38436 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38437@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38438 goto cleanup;
38439 }
38440 spin_lock(&port->lock);
38441- port->count++;
38442+ atomic_inc(&port->count);
38443 spin_unlock(&port->lock);
38444 spin_unlock_irqrestore(&info->netlock, flags);
38445
38446- if (port->count == 1) {
38447+ if (atomic_read(&port->count) == 1) {
38448 /* 1st open on this device, init hardware */
38449 retval = startup(info, tty);
38450 if (retval < 0)
38451@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38452 unsigned short new_crctype;
38453
38454 /* return error if TTY interface open */
38455- if (info->port.count)
38456+ if (atomic_read(&info->port.count))
38457 return -EBUSY;
38458
38459 switch (encoding)
38460@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38461
38462 /* arbitrate between network and tty opens */
38463 spin_lock_irqsave(&info->netlock, flags);
38464- if (info->port.count != 0 || info->netcount != 0) {
38465+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38466 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38467 spin_unlock_irqrestore(&info->netlock, flags);
38468 return -EBUSY;
38469@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38470 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38471
38472 /* return error if TTY interface open */
38473- if (info->port.count)
38474+ if (atomic_read(&info->port.count))
38475 return -EBUSY;
38476
38477 if (cmd != SIOCWANDEV)
38478diff --git a/drivers/char/random.c b/drivers/char/random.c
38479index 429b75b..a7f4145 100644
38480--- a/drivers/char/random.c
38481+++ b/drivers/char/random.c
38482@@ -270,10 +270,17 @@
38483 /*
38484 * Configuration information
38485 */
38486+#ifdef CONFIG_GRKERNSEC_RANDNET
38487+#define INPUT_POOL_SHIFT 14
38488+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38489+#define OUTPUT_POOL_SHIFT 12
38490+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38491+#else
38492 #define INPUT_POOL_SHIFT 12
38493 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38494 #define OUTPUT_POOL_SHIFT 10
38495 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38496+#endif
38497 #define SEC_XFER_SIZE 512
38498 #define EXTRACT_SIZE 10
38499
38500@@ -284,9 +291,6 @@
38501 /*
38502 * To allow fractional bits to be tracked, the entropy_count field is
38503 * denominated in units of 1/8th bits.
38504- *
38505- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38506- * credit_entropy_bits() needs to be 64 bits wide.
38507 */
38508 #define ENTROPY_SHIFT 3
38509 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38510@@ -361,12 +365,19 @@ static struct poolinfo {
38511 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38512 int tap1, tap2, tap3, tap4, tap5;
38513 } poolinfo_table[] = {
38514+#ifdef CONFIG_GRKERNSEC_RANDNET
38515+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38516+ { S(512), 411, 308, 208, 104, 1 },
38517+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38518+ { S(128), 104, 76, 51, 25, 1 },
38519+#else
38520 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38521 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38522 { S(128), 104, 76, 51, 25, 1 },
38523 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38524 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38525 { S(32), 26, 19, 14, 7, 1 },
38526+#endif
38527 #if 0
38528 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38529 { S(2048), 1638, 1231, 819, 411, 1 },
38530@@ -433,9 +444,9 @@ struct entropy_store {
38531 };
38532
38533 static void push_to_pool(struct work_struct *work);
38534-static __u32 input_pool_data[INPUT_POOL_WORDS];
38535-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38536-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38537+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38538+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38539+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38540
38541 static struct entropy_store input_pool = {
38542 .poolinfo = &poolinfo_table[0],
38543@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38544 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38545 }
38546
38547- ACCESS_ONCE(r->input_rotate) = input_rotate;
38548- ACCESS_ONCE(r->add_ptr) = i;
38549+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38550+ ACCESS_ONCE_RW(r->add_ptr) = i;
38551 smp_wmb();
38552
38553 if (out)
38554@@ -632,7 +643,7 @@ retry:
38555 /* The +2 corresponds to the /4 in the denominator */
38556
38557 do {
38558- unsigned int anfrac = min(pnfrac, pool_size/2);
38559+ u64 anfrac = min(pnfrac, pool_size/2);
38560 unsigned int add =
38561 ((pool_size - entropy_count)*anfrac*3) >> s;
38562
38563@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38564
38565 extract_buf(r, tmp);
38566 i = min_t(int, nbytes, EXTRACT_SIZE);
38567- if (copy_to_user(buf, tmp, i)) {
38568+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38569 ret = -EFAULT;
38570 break;
38571 }
38572@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38573 #include <linux/sysctl.h>
38574
38575 static int min_read_thresh = 8, min_write_thresh;
38576-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38577+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38578 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38579 static char sysctl_bootid[16];
38580
38581@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38582 static int proc_do_uuid(struct ctl_table *table, int write,
38583 void __user *buffer, size_t *lenp, loff_t *ppos)
38584 {
38585- struct ctl_table fake_table;
38586+ ctl_table_no_const fake_table;
38587 unsigned char buf[64], tmp_uuid[16], *uuid;
38588
38589 uuid = table->data;
38590@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38591 static int proc_do_entropy(ctl_table *table, int write,
38592 void __user *buffer, size_t *lenp, loff_t *ppos)
38593 {
38594- ctl_table fake_table;
38595+ ctl_table_no_const fake_table;
38596 int entropy_count;
38597
38598 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38599diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38600index 7cc1fe22..b602d6b 100644
38601--- a/drivers/char/sonypi.c
38602+++ b/drivers/char/sonypi.c
38603@@ -54,6 +54,7 @@
38604
38605 #include <asm/uaccess.h>
38606 #include <asm/io.h>
38607+#include <asm/local.h>
38608
38609 #include <linux/sonypi.h>
38610
38611@@ -490,7 +491,7 @@ static struct sonypi_device {
38612 spinlock_t fifo_lock;
38613 wait_queue_head_t fifo_proc_list;
38614 struct fasync_struct *fifo_async;
38615- int open_count;
38616+ local_t open_count;
38617 int model;
38618 struct input_dev *input_jog_dev;
38619 struct input_dev *input_key_dev;
38620@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38621 static int sonypi_misc_release(struct inode *inode, struct file *file)
38622 {
38623 mutex_lock(&sonypi_device.lock);
38624- sonypi_device.open_count--;
38625+ local_dec(&sonypi_device.open_count);
38626 mutex_unlock(&sonypi_device.lock);
38627 return 0;
38628 }
38629@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38630 {
38631 mutex_lock(&sonypi_device.lock);
38632 /* Flush input queue on first open */
38633- if (!sonypi_device.open_count)
38634+ if (!local_read(&sonypi_device.open_count))
38635 kfifo_reset(&sonypi_device.fifo);
38636- sonypi_device.open_count++;
38637+ local_inc(&sonypi_device.open_count);
38638 mutex_unlock(&sonypi_device.lock);
38639
38640 return 0;
38641diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38642index b9a57fa..5bb9e38 100644
38643--- a/drivers/char/tpm/tpm_acpi.c
38644+++ b/drivers/char/tpm/tpm_acpi.c
38645@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38646 virt = acpi_os_map_memory(start, len);
38647 if (!virt) {
38648 kfree(log->bios_event_log);
38649+ log->bios_event_log = NULL;
38650 printk("%s: ERROR - Unable to map memory\n", __func__);
38651 return -EIO;
38652 }
38653
38654- memcpy_fromio(log->bios_event_log, virt, len);
38655+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38656
38657 acpi_os_unmap_memory(virt, len);
38658 return 0;
38659diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38660index 59f7cb2..bac8b6d 100644
38661--- a/drivers/char/tpm/tpm_eventlog.c
38662+++ b/drivers/char/tpm/tpm_eventlog.c
38663@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38664 event = addr;
38665
38666 if ((event->event_type == 0 && event->event_size == 0) ||
38667- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38668+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38669 return NULL;
38670
38671 return addr;
38672@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38673 return NULL;
38674
38675 if ((event->event_type == 0 && event->event_size == 0) ||
38676- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38677+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38678 return NULL;
38679
38680 (*pos)++;
38681@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38682 int i;
38683
38684 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38685- seq_putc(m, data[i]);
38686+ if (!seq_putc(m, data[i]))
38687+ return -EFAULT;
38688
38689 return 0;
38690 }
38691diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38692index 6928d09..ff6abe8 100644
38693--- a/drivers/char/virtio_console.c
38694+++ b/drivers/char/virtio_console.c
38695@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38696 if (to_user) {
38697 ssize_t ret;
38698
38699- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38700+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38701 if (ret)
38702 return -EFAULT;
38703 } else {
38704@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38705 if (!port_has_data(port) && !port->host_connected)
38706 return 0;
38707
38708- return fill_readbuf(port, ubuf, count, true);
38709+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38710 }
38711
38712 static int wait_port_writable(struct port *port, bool nonblock)
38713diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38714index 57a078e..c17cde8 100644
38715--- a/drivers/clk/clk-composite.c
38716+++ b/drivers/clk/clk-composite.c
38717@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38718 struct clk *clk;
38719 struct clk_init_data init;
38720 struct clk_composite *composite;
38721- struct clk_ops *clk_composite_ops;
38722+ clk_ops_no_const *clk_composite_ops;
38723
38724 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38725 if (!composite) {
38726diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38727index 5983a26..65d5f46 100644
38728--- a/drivers/clk/socfpga/clk.c
38729+++ b/drivers/clk/socfpga/clk.c
38730@@ -22,6 +22,7 @@
38731 #include <linux/clk-provider.h>
38732 #include <linux/io.h>
38733 #include <linux/of.h>
38734+#include <asm/pgtable.h>
38735
38736 /* Clock Manager offsets */
38737 #define CLKMGR_CTRL 0x0
38738@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38739 streq(clk_name, "periph_pll") ||
38740 streq(clk_name, "sdram_pll")) {
38741 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38742- clk_pll_ops.enable = clk_gate_ops.enable;
38743- clk_pll_ops.disable = clk_gate_ops.disable;
38744+ pax_open_kernel();
38745+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38746+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38747+ pax_close_kernel();
38748 }
38749
38750 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38751@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38752 return parent_rate / div;
38753 }
38754
38755-static struct clk_ops gateclk_ops = {
38756+static clk_ops_no_const gateclk_ops __read_only = {
38757 .recalc_rate = socfpga_clk_recalc_rate,
38758 .get_parent = socfpga_clk_get_parent,
38759 .set_parent = socfpga_clk_set_parent,
38760diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38761index 18448a7..d5fad43 100644
38762--- a/drivers/cpufreq/acpi-cpufreq.c
38763+++ b/drivers/cpufreq/acpi-cpufreq.c
38764@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38765 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38766 per_cpu(acfreq_data, cpu) = data;
38767
38768- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38769- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38770+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38771+ pax_open_kernel();
38772+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38773+ pax_close_kernel();
38774+ }
38775
38776 result = acpi_processor_register_performance(data->acpi_data, cpu);
38777 if (result)
38778@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38779 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38780 break;
38781 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38782- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38783+ pax_open_kernel();
38784+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38785+ pax_close_kernel();
38786 break;
38787 default:
38788 break;
38789@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38790 if (!msrs)
38791 return;
38792
38793- acpi_cpufreq_driver.boost_supported = true;
38794- acpi_cpufreq_driver.boost_enabled = boost_state(0);
38795+ pax_open_kernel();
38796+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38797+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38798+ pax_close_kernel();
38799 get_online_cpus();
38800
38801 /* Force all MSRs to the same value */
38802diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38803index 199b52b..e3503bb 100644
38804--- a/drivers/cpufreq/cpufreq.c
38805+++ b/drivers/cpufreq/cpufreq.c
38806@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38807 #endif
38808
38809 mutex_lock(&cpufreq_governor_mutex);
38810- list_del(&governor->governor_list);
38811+ pax_list_del(&governor->governor_list);
38812 mutex_unlock(&cpufreq_governor_mutex);
38813 return;
38814 }
38815@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38816 return NOTIFY_OK;
38817 }
38818
38819-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38820+static struct notifier_block cpufreq_cpu_notifier = {
38821 .notifier_call = cpufreq_cpu_callback,
38822 };
38823
38824@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38825 return 0;
38826
38827 write_lock_irqsave(&cpufreq_driver_lock, flags);
38828- cpufreq_driver->boost_enabled = state;
38829+ pax_open_kernel();
38830+ *(bool *)&cpufreq_driver->boost_enabled = state;
38831+ pax_close_kernel();
38832 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38833
38834 ret = cpufreq_driver->set_boost(state);
38835 if (ret) {
38836 write_lock_irqsave(&cpufreq_driver_lock, flags);
38837- cpufreq_driver->boost_enabled = !state;
38838+ pax_open_kernel();
38839+ *(bool *)&cpufreq_driver->boost_enabled = !state;
38840+ pax_close_kernel();
38841 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38842
38843 pr_err("%s: Cannot %s BOOST\n", __func__,
38844@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38845
38846 pr_debug("trying to register driver %s\n", driver_data->name);
38847
38848- if (driver_data->setpolicy)
38849- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38850+ if (driver_data->setpolicy) {
38851+ pax_open_kernel();
38852+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38853+ pax_close_kernel();
38854+ }
38855
38856 write_lock_irqsave(&cpufreq_driver_lock, flags);
38857 if (cpufreq_driver) {
38858@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38859 * Check if driver provides function to enable boost -
38860 * if not, use cpufreq_boost_set_sw as default
38861 */
38862- if (!cpufreq_driver->set_boost)
38863- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38864+ if (!cpufreq_driver->set_boost) {
38865+ pax_open_kernel();
38866+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38867+ pax_close_kernel();
38868+ }
38869
38870 ret = cpufreq_sysfs_create_file(&boost.attr);
38871 if (ret) {
38872diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38873index ba43991..23858ffb 100644
38874--- a/drivers/cpufreq/cpufreq_governor.c
38875+++ b/drivers/cpufreq/cpufreq_governor.c
38876@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38877 struct dbs_data *dbs_data;
38878 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38879 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38880- struct od_ops *od_ops = NULL;
38881+ const struct od_ops *od_ops = NULL;
38882 struct od_dbs_tuners *od_tuners = NULL;
38883 struct cs_dbs_tuners *cs_tuners = NULL;
38884 struct cpu_dbs_common_info *cpu_cdbs;
38885@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38886
38887 if ((cdata->governor == GOV_CONSERVATIVE) &&
38888 (!policy->governor->initialized)) {
38889- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38890+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38891
38892 cpufreq_register_notifier(cs_ops->notifier_block,
38893 CPUFREQ_TRANSITION_NOTIFIER);
38894@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38895
38896 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38897 (policy->governor->initialized == 1)) {
38898- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38899+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38900
38901 cpufreq_unregister_notifier(cs_ops->notifier_block,
38902 CPUFREQ_TRANSITION_NOTIFIER);
38903diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38904index bfb9ae1..e1d3a7e 100644
38905--- a/drivers/cpufreq/cpufreq_governor.h
38906+++ b/drivers/cpufreq/cpufreq_governor.h
38907@@ -205,7 +205,7 @@ struct common_dbs_data {
38908 void (*exit)(struct dbs_data *dbs_data);
38909
38910 /* Governor specific ops, see below */
38911- void *gov_ops;
38912+ const void *gov_ops;
38913 };
38914
38915 /* Governor Per policy data */
38916@@ -225,7 +225,7 @@ struct od_ops {
38917 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38918 unsigned int freq_next, unsigned int relation);
38919 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38920-};
38921+} __no_const;
38922
38923 struct cs_ops {
38924 struct notifier_block *notifier_block;
38925diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38926index 18d4091..434be15 100644
38927--- a/drivers/cpufreq/cpufreq_ondemand.c
38928+++ b/drivers/cpufreq/cpufreq_ondemand.c
38929@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38930
38931 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38932
38933-static struct od_ops od_ops = {
38934+static struct od_ops od_ops __read_only = {
38935 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38936 .powersave_bias_target = generic_powersave_bias_target,
38937 .freq_increase = dbs_freq_increase,
38938@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38939 (struct cpufreq_policy *, unsigned int, unsigned int),
38940 unsigned int powersave_bias)
38941 {
38942- od_ops.powersave_bias_target = f;
38943+ pax_open_kernel();
38944+ *(void **)&od_ops.powersave_bias_target = f;
38945+ pax_close_kernel();
38946 od_set_powersave_bias(powersave_bias);
38947 }
38948 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38949
38950 void od_unregister_powersave_bias_handler(void)
38951 {
38952- od_ops.powersave_bias_target = generic_powersave_bias_target;
38953+ pax_open_kernel();
38954+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38955+ pax_close_kernel();
38956 od_set_powersave_bias(0);
38957 }
38958 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38959diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38960index 2cd36b9..8f07fae 100644
38961--- a/drivers/cpufreq/intel_pstate.c
38962+++ b/drivers/cpufreq/intel_pstate.c
38963@@ -124,10 +124,10 @@ struct pstate_funcs {
38964 struct cpu_defaults {
38965 struct pstate_adjust_policy pid_policy;
38966 struct pstate_funcs funcs;
38967-};
38968+} __do_const;
38969
38970 static struct pstate_adjust_policy pid_params;
38971-static struct pstate_funcs pstate_funcs;
38972+static struct pstate_funcs *pstate_funcs;
38973
38974 struct perf_limits {
38975 int no_turbo;
38976@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38977
38978 cpu->pstate.current_pstate = pstate;
38979
38980- pstate_funcs.set(cpu, pstate);
38981+ pstate_funcs->set(cpu, pstate);
38982 }
38983
38984 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38985@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38986 {
38987 sprintf(cpu->name, "Intel 2nd generation core");
38988
38989- cpu->pstate.min_pstate = pstate_funcs.get_min();
38990- cpu->pstate.max_pstate = pstate_funcs.get_max();
38991- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38992+ cpu->pstate.min_pstate = pstate_funcs->get_min();
38993+ cpu->pstate.max_pstate = pstate_funcs->get_max();
38994+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38995
38996- if (pstate_funcs.get_vid)
38997- pstate_funcs.get_vid(cpu);
38998+ if (pstate_funcs->get_vid)
38999+ pstate_funcs->get_vid(cpu);
39000
39001 /*
39002 * goto max pstate so we don't slow up boot if we are built-in if we are
39003@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39004 rdmsrl(MSR_IA32_APERF, aperf);
39005 rdmsrl(MSR_IA32_MPERF, mperf);
39006
39007- if (!pstate_funcs.get_max() ||
39008- !pstate_funcs.get_min() ||
39009- !pstate_funcs.get_turbo())
39010+ if (!pstate_funcs->get_max() ||
39011+ !pstate_funcs->get_min() ||
39012+ !pstate_funcs->get_turbo())
39013 return -ENODEV;
39014
39015 rdmsrl(MSR_IA32_APERF, tmp);
39016@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39017 return 0;
39018 }
39019
39020-static void copy_pid_params(struct pstate_adjust_policy *policy)
39021+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39022 {
39023 pid_params.sample_rate_ms = policy->sample_rate_ms;
39024 pid_params.p_gain_pct = policy->p_gain_pct;
39025@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39026
39027 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39028 {
39029- pstate_funcs.get_max = funcs->get_max;
39030- pstate_funcs.get_min = funcs->get_min;
39031- pstate_funcs.get_turbo = funcs->get_turbo;
39032- pstate_funcs.set = funcs->set;
39033- pstate_funcs.get_vid = funcs->get_vid;
39034+ pstate_funcs = funcs;
39035 }
39036
39037 #if IS_ENABLED(CONFIG_ACPI)
39038diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39039index 3d1cba9..0ab21d2 100644
39040--- a/drivers/cpufreq/p4-clockmod.c
39041+++ b/drivers/cpufreq/p4-clockmod.c
39042@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39043 case 0x0F: /* Core Duo */
39044 case 0x16: /* Celeron Core */
39045 case 0x1C: /* Atom */
39046- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39047+ pax_open_kernel();
39048+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39049+ pax_close_kernel();
39050 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39051 case 0x0D: /* Pentium M (Dothan) */
39052- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39053+ pax_open_kernel();
39054+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39055+ pax_close_kernel();
39056 /* fall through */
39057 case 0x09: /* Pentium M (Banias) */
39058 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39059@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39060
39061 /* on P-4s, the TSC runs with constant frequency independent whether
39062 * throttling is active or not. */
39063- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39064+ pax_open_kernel();
39065+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39066+ pax_close_kernel();
39067
39068 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39069 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39070diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39071index 724ffbd..ad83692 100644
39072--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39073+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39074@@ -18,14 +18,12 @@
39075 #include <asm/head.h>
39076 #include <asm/timer.h>
39077
39078-static struct cpufreq_driver *cpufreq_us3_driver;
39079-
39080 struct us3_freq_percpu_info {
39081 struct cpufreq_frequency_table table[4];
39082 };
39083
39084 /* Indexed by cpu number. */
39085-static struct us3_freq_percpu_info *us3_freq_table;
39086+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39087
39088 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39089 * in the Safari config register.
39090@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39091
39092 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39093 {
39094- if (cpufreq_us3_driver) {
39095- cpufreq_frequency_table_put_attr(policy->cpu);
39096- us3_freq_target(policy, 0);
39097- }
39098+ cpufreq_frequency_table_put_attr(policy->cpu);
39099+ us3_freq_target(policy, 0);
39100
39101 return 0;
39102 }
39103
39104+static int __init us3_freq_init(void);
39105+static void __exit us3_freq_exit(void);
39106+
39107+static struct cpufreq_driver cpufreq_us3_driver = {
39108+ .init = us3_freq_cpu_init,
39109+ .verify = cpufreq_generic_frequency_table_verify,
39110+ .target_index = us3_freq_target,
39111+ .get = us3_freq_get,
39112+ .exit = us3_freq_cpu_exit,
39113+ .owner = THIS_MODULE,
39114+ .name = "UltraSPARC-III",
39115+
39116+};
39117+
39118 static int __init us3_freq_init(void)
39119 {
39120 unsigned long manuf, impl, ver;
39121@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39122 (impl == CHEETAH_IMPL ||
39123 impl == CHEETAH_PLUS_IMPL ||
39124 impl == JAGUAR_IMPL ||
39125- impl == PANTHER_IMPL)) {
39126- struct cpufreq_driver *driver;
39127-
39128- ret = -ENOMEM;
39129- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39130- if (!driver)
39131- goto err_out;
39132-
39133- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39134- GFP_KERNEL);
39135- if (!us3_freq_table)
39136- goto err_out;
39137-
39138- driver->init = us3_freq_cpu_init;
39139- driver->verify = cpufreq_generic_frequency_table_verify;
39140- driver->target_index = us3_freq_target;
39141- driver->get = us3_freq_get;
39142- driver->exit = us3_freq_cpu_exit;
39143- strcpy(driver->name, "UltraSPARC-III");
39144-
39145- cpufreq_us3_driver = driver;
39146- ret = cpufreq_register_driver(driver);
39147- if (ret)
39148- goto err_out;
39149-
39150- return 0;
39151-
39152-err_out:
39153- if (driver) {
39154- kfree(driver);
39155- cpufreq_us3_driver = NULL;
39156- }
39157- kfree(us3_freq_table);
39158- us3_freq_table = NULL;
39159- return ret;
39160- }
39161+ impl == PANTHER_IMPL))
39162+ return cpufreq_register_driver(&cpufreq_us3_driver);
39163
39164 return -ENODEV;
39165 }
39166
39167 static void __exit us3_freq_exit(void)
39168 {
39169- if (cpufreq_us3_driver) {
39170- cpufreq_unregister_driver(cpufreq_us3_driver);
39171- kfree(cpufreq_us3_driver);
39172- cpufreq_us3_driver = NULL;
39173- kfree(us3_freq_table);
39174- us3_freq_table = NULL;
39175- }
39176+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39177 }
39178
39179 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39180diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39181index 4e1daca..e707b61 100644
39182--- a/drivers/cpufreq/speedstep-centrino.c
39183+++ b/drivers/cpufreq/speedstep-centrino.c
39184@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39185 !cpu_has(cpu, X86_FEATURE_EST))
39186 return -ENODEV;
39187
39188- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39189- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39190+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39191+ pax_open_kernel();
39192+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39193+ pax_close_kernel();
39194+ }
39195
39196 if (policy->cpu != 0)
39197 return -ENODEV;
39198diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39199index 06dbe7c..c2c8671 100644
39200--- a/drivers/cpuidle/driver.c
39201+++ b/drivers/cpuidle/driver.c
39202@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39203
39204 static void poll_idle_init(struct cpuidle_driver *drv)
39205 {
39206- struct cpuidle_state *state = &drv->states[0];
39207+ cpuidle_state_no_const *state = &drv->states[0];
39208
39209 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39210 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39211diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39212index ca89412..a7b9c49 100644
39213--- a/drivers/cpuidle/governor.c
39214+++ b/drivers/cpuidle/governor.c
39215@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39216 mutex_lock(&cpuidle_lock);
39217 if (__cpuidle_find_governor(gov->name) == NULL) {
39218 ret = 0;
39219- list_add_tail(&gov->governor_list, &cpuidle_governors);
39220+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39221 if (!cpuidle_curr_governor ||
39222 cpuidle_curr_governor->rating < gov->rating)
39223 cpuidle_switch_governor(gov);
39224diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39225index e918b6d..f87ea80 100644
39226--- a/drivers/cpuidle/sysfs.c
39227+++ b/drivers/cpuidle/sysfs.c
39228@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39229 NULL
39230 };
39231
39232-static struct attribute_group cpuidle_attr_group = {
39233+static attribute_group_no_const cpuidle_attr_group = {
39234 .attrs = cpuidle_default_attrs,
39235 .name = "cpuidle",
39236 };
39237diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39238index 12fea3e..1e28f47 100644
39239--- a/drivers/crypto/hifn_795x.c
39240+++ b/drivers/crypto/hifn_795x.c
39241@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39242 MODULE_PARM_DESC(hifn_pll_ref,
39243 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39244
39245-static atomic_t hifn_dev_number;
39246+static atomic_unchecked_t hifn_dev_number;
39247
39248 #define ACRYPTO_OP_DECRYPT 0
39249 #define ACRYPTO_OP_ENCRYPT 1
39250@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39251 goto err_out_disable_pci_device;
39252
39253 snprintf(name, sizeof(name), "hifn%d",
39254- atomic_inc_return(&hifn_dev_number)-1);
39255+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39256
39257 err = pci_request_regions(pdev, name);
39258 if (err)
39259diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39260index a0b2f7e..1b6f028 100644
39261--- a/drivers/devfreq/devfreq.c
39262+++ b/drivers/devfreq/devfreq.c
39263@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39264 goto err_out;
39265 }
39266
39267- list_add(&governor->node, &devfreq_governor_list);
39268+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39269
39270 list_for_each_entry(devfreq, &devfreq_list, node) {
39271 int ret = 0;
39272@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39273 }
39274 }
39275
39276- list_del(&governor->node);
39277+ pax_list_del((struct list_head *)&governor->node);
39278 err_out:
39279 mutex_unlock(&devfreq_list_lock);
39280
39281diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39282index 2e7b394..1371a64 100644
39283--- a/drivers/dma/sh/shdma-base.c
39284+++ b/drivers/dma/sh/shdma-base.c
39285@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39286 schan->slave_id = -EINVAL;
39287 }
39288
39289- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39290- sdev->desc_size, GFP_KERNEL);
39291+ schan->desc = kcalloc(sdev->desc_size,
39292+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39293 if (!schan->desc) {
39294 ret = -ENOMEM;
39295 goto edescalloc;
39296diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39297index 0d765c0..60b7480 100644
39298--- a/drivers/dma/sh/shdmac.c
39299+++ b/drivers/dma/sh/shdmac.c
39300@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39301 return ret;
39302 }
39303
39304-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39305+static struct notifier_block sh_dmae_nmi_notifier = {
39306 .notifier_call = sh_dmae_nmi_handler,
39307
39308 /* Run before NMI debug handler and KGDB */
39309diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39310index 592af5f..bb1d583 100644
39311--- a/drivers/edac/edac_device.c
39312+++ b/drivers/edac/edac_device.c
39313@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39314 */
39315 int edac_device_alloc_index(void)
39316 {
39317- static atomic_t device_indexes = ATOMIC_INIT(0);
39318+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39319
39320- return atomic_inc_return(&device_indexes) - 1;
39321+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39322 }
39323 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39324
39325diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39326index b335c6a..db65b44 100644
39327--- a/drivers/edac/edac_mc_sysfs.c
39328+++ b/drivers/edac/edac_mc_sysfs.c
39329@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39330 struct dev_ch_attribute {
39331 struct device_attribute attr;
39332 int channel;
39333-};
39334+} __do_const;
39335
39336 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39337 struct dev_ch_attribute dev_attr_legacy_##_name = \
39338@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39339 }
39340
39341 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39342+ pax_open_kernel();
39343 if (mci->get_sdram_scrub_rate) {
39344- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39345- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39346+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39347+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39348 }
39349 if (mci->set_sdram_scrub_rate) {
39350- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39351- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39352+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39353+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39354 }
39355+ pax_close_kernel();
39356 err = device_create_file(&mci->dev,
39357 &dev_attr_sdram_scrub_rate);
39358 if (err) {
39359diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39360index 2cf44b4d..6dd2dc7 100644
39361--- a/drivers/edac/edac_pci.c
39362+++ b/drivers/edac/edac_pci.c
39363@@ -29,7 +29,7 @@
39364
39365 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39366 static LIST_HEAD(edac_pci_list);
39367-static atomic_t pci_indexes = ATOMIC_INIT(0);
39368+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39369
39370 /*
39371 * edac_pci_alloc_ctl_info
39372@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39373 */
39374 int edac_pci_alloc_index(void)
39375 {
39376- return atomic_inc_return(&pci_indexes) - 1;
39377+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39378 }
39379 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39380
39381diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39382index e8658e4..22746d6 100644
39383--- a/drivers/edac/edac_pci_sysfs.c
39384+++ b/drivers/edac/edac_pci_sysfs.c
39385@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39386 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39387 static int edac_pci_poll_msec = 1000; /* one second workq period */
39388
39389-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39390-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39391+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39392+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39393
39394 static struct kobject *edac_pci_top_main_kobj;
39395 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39396@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39397 void *value;
39398 ssize_t(*show) (void *, char *);
39399 ssize_t(*store) (void *, const char *, size_t);
39400-};
39401+} __do_const;
39402
39403 /* Set of show/store abstract level functions for PCI Parity object */
39404 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39405@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39406 edac_printk(KERN_CRIT, EDAC_PCI,
39407 "Signaled System Error on %s\n",
39408 pci_name(dev));
39409- atomic_inc(&pci_nonparity_count);
39410+ atomic_inc_unchecked(&pci_nonparity_count);
39411 }
39412
39413 if (status & (PCI_STATUS_PARITY)) {
39414@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39415 "Master Data Parity Error on %s\n",
39416 pci_name(dev));
39417
39418- atomic_inc(&pci_parity_count);
39419+ atomic_inc_unchecked(&pci_parity_count);
39420 }
39421
39422 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39423@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39424 "Detected Parity Error on %s\n",
39425 pci_name(dev));
39426
39427- atomic_inc(&pci_parity_count);
39428+ atomic_inc_unchecked(&pci_parity_count);
39429 }
39430 }
39431
39432@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39433 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39434 "Signaled System Error on %s\n",
39435 pci_name(dev));
39436- atomic_inc(&pci_nonparity_count);
39437+ atomic_inc_unchecked(&pci_nonparity_count);
39438 }
39439
39440 if (status & (PCI_STATUS_PARITY)) {
39441@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39442 "Master Data Parity Error on "
39443 "%s\n", pci_name(dev));
39444
39445- atomic_inc(&pci_parity_count);
39446+ atomic_inc_unchecked(&pci_parity_count);
39447 }
39448
39449 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39450@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39451 "Detected Parity Error on %s\n",
39452 pci_name(dev));
39453
39454- atomic_inc(&pci_parity_count);
39455+ atomic_inc_unchecked(&pci_parity_count);
39456 }
39457 }
39458 }
39459@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39460 if (!check_pci_errors)
39461 return;
39462
39463- before_count = atomic_read(&pci_parity_count);
39464+ before_count = atomic_read_unchecked(&pci_parity_count);
39465
39466 /* scan all PCI devices looking for a Parity Error on devices and
39467 * bridges.
39468@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39469 /* Only if operator has selected panic on PCI Error */
39470 if (edac_pci_get_panic_on_pe()) {
39471 /* If the count is different 'after' from 'before' */
39472- if (before_count != atomic_read(&pci_parity_count))
39473+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39474 panic("EDAC: PCI Parity Error");
39475 }
39476 }
39477diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39478index 51b7e3a..aa8a3e8 100644
39479--- a/drivers/edac/mce_amd.h
39480+++ b/drivers/edac/mce_amd.h
39481@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39482 bool (*mc0_mce)(u16, u8);
39483 bool (*mc1_mce)(u16, u8);
39484 bool (*mc2_mce)(u16, u8);
39485-};
39486+} __no_const;
39487
39488 void amd_report_gart_errors(bool);
39489 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39490diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39491index 57ea7f4..af06b76 100644
39492--- a/drivers/firewire/core-card.c
39493+++ b/drivers/firewire/core-card.c
39494@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39495 const struct fw_card_driver *driver,
39496 struct device *device)
39497 {
39498- static atomic_t index = ATOMIC_INIT(-1);
39499+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39500
39501- card->index = atomic_inc_return(&index);
39502+ card->index = atomic_inc_return_unchecked(&index);
39503 card->driver = driver;
39504 card->device = device;
39505 card->current_tlabel = 0;
39506@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39507
39508 void fw_core_remove_card(struct fw_card *card)
39509 {
39510- struct fw_card_driver dummy_driver = dummy_driver_template;
39511+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39512
39513 card->driver->update_phy_reg(card, 4,
39514 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39515diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39516index 2c6d5e1..a2cca6b 100644
39517--- a/drivers/firewire/core-device.c
39518+++ b/drivers/firewire/core-device.c
39519@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39520 struct config_rom_attribute {
39521 struct device_attribute attr;
39522 u32 key;
39523-};
39524+} __do_const;
39525
39526 static ssize_t show_immediate(struct device *dev,
39527 struct device_attribute *dattr, char *buf)
39528diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39529index eb6935c..3cc2bfa 100644
39530--- a/drivers/firewire/core-transaction.c
39531+++ b/drivers/firewire/core-transaction.c
39532@@ -38,6 +38,7 @@
39533 #include <linux/timer.h>
39534 #include <linux/types.h>
39535 #include <linux/workqueue.h>
39536+#include <linux/sched.h>
39537
39538 #include <asm/byteorder.h>
39539
39540diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39541index c98764a..551b520 100644
39542--- a/drivers/firewire/core.h
39543+++ b/drivers/firewire/core.h
39544@@ -111,6 +111,7 @@ struct fw_card_driver {
39545
39546 int (*stop_iso)(struct fw_iso_context *ctx);
39547 };
39548+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39549
39550 void fw_card_initialize(struct fw_card *card,
39551 const struct fw_card_driver *driver, struct device *device);
39552diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39553index 8db6632..9bbc8ca 100644
39554--- a/drivers/firewire/ohci.c
39555+++ b/drivers/firewire/ohci.c
39556@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39557 be32_to_cpu(ohci->next_header));
39558 }
39559
39560+#ifndef CONFIG_GRKERNSEC
39561 if (param_remote_dma) {
39562 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39563 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39564 }
39565+#endif
39566
39567 spin_unlock_irq(&ohci->lock);
39568
39569@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39570 unsigned long flags;
39571 int n, ret = 0;
39572
39573+#ifndef CONFIG_GRKERNSEC
39574 if (param_remote_dma)
39575 return 0;
39576+#endif
39577
39578 /*
39579 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39580diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39581index 94a58a0..f5eba42 100644
39582--- a/drivers/firmware/dmi-id.c
39583+++ b/drivers/firmware/dmi-id.c
39584@@ -16,7 +16,7 @@
39585 struct dmi_device_attribute{
39586 struct device_attribute dev_attr;
39587 int field;
39588-};
39589+} __do_const;
39590 #define to_dmi_dev_attr(_dev_attr) \
39591 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39592
39593diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39594index 17afc51..0ef90cd 100644
39595--- a/drivers/firmware/dmi_scan.c
39596+++ b/drivers/firmware/dmi_scan.c
39597@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39598 if (buf == NULL)
39599 return -1;
39600
39601- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39602+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39603
39604 dmi_unmap(buf);
39605 return 0;
39606diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39607index 1491dd4..aa910db 100644
39608--- a/drivers/firmware/efi/cper.c
39609+++ b/drivers/firmware/efi/cper.c
39610@@ -41,12 +41,12 @@
39611 */
39612 u64 cper_next_record_id(void)
39613 {
39614- static atomic64_t seq;
39615+ static atomic64_unchecked_t seq;
39616
39617- if (!atomic64_read(&seq))
39618- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39619+ if (!atomic64_read_unchecked(&seq))
39620+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39621
39622- return atomic64_inc_return(&seq);
39623+ return atomic64_inc_return_unchecked(&seq);
39624 }
39625 EXPORT_SYMBOL_GPL(cper_next_record_id);
39626
39627diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39628index 4753bac..02861a2 100644
39629--- a/drivers/firmware/efi/efi.c
39630+++ b/drivers/firmware/efi/efi.c
39631@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39632 };
39633
39634 static struct efivars generic_efivars;
39635-static struct efivar_operations generic_ops;
39636+static efivar_operations_no_const generic_ops __read_only;
39637
39638 static int generic_ops_register(void)
39639 {
39640- generic_ops.get_variable = efi.get_variable;
39641- generic_ops.set_variable = efi.set_variable;
39642- generic_ops.get_next_variable = efi.get_next_variable;
39643- generic_ops.query_variable_store = efi_query_variable_store;
39644+ pax_open_kernel();
39645+ *(void **)&generic_ops.get_variable = efi.get_variable;
39646+ *(void **)&generic_ops.set_variable = efi.set_variable;
39647+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39648+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39649+ pax_close_kernel();
39650
39651 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39652 }
39653diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39654index 3dc2482..7bd2f61 100644
39655--- a/drivers/firmware/efi/efivars.c
39656+++ b/drivers/firmware/efi/efivars.c
39657@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39658 static int
39659 create_efivars_bin_attributes(void)
39660 {
39661- struct bin_attribute *attr;
39662+ bin_attribute_no_const *attr;
39663 int error;
39664
39665 /* new_var */
39666diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39667index 2a90ba6..07f3733 100644
39668--- a/drivers/firmware/google/memconsole.c
39669+++ b/drivers/firmware/google/memconsole.c
39670@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39671 if (!found_memconsole())
39672 return -ENODEV;
39673
39674- memconsole_bin_attr.size = memconsole_length;
39675+ pax_open_kernel();
39676+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39677+ pax_close_kernel();
39678
39679 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39680
39681diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39682index 1e98a98..b444372 100644
39683--- a/drivers/gpio/gpio-em.c
39684+++ b/drivers/gpio/gpio-em.c
39685@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39686 struct em_gio_priv *p;
39687 struct resource *io[2], *irq[2];
39688 struct gpio_chip *gpio_chip;
39689- struct irq_chip *irq_chip;
39690+ irq_chip_no_const *irq_chip;
39691 const char *name = dev_name(&pdev->dev);
39692 int ret;
39693
39694diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39695index f5bf3c3..7baaa59 100644
39696--- a/drivers/gpio/gpio-ich.c
39697+++ b/drivers/gpio/gpio-ich.c
39698@@ -71,7 +71,7 @@ struct ichx_desc {
39699 /* Some chipsets have quirks, let these use their own request/get */
39700 int (*request)(struct gpio_chip *chip, unsigned offset);
39701 int (*get)(struct gpio_chip *chip, unsigned offset);
39702-};
39703+} __do_const;
39704
39705 static struct {
39706 spinlock_t lock;
39707diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39708index ca76ce7..68b384b 100644
39709--- a/drivers/gpio/gpio-rcar.c
39710+++ b/drivers/gpio/gpio-rcar.c
39711@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39712 struct gpio_rcar_priv *p;
39713 struct resource *io, *irq;
39714 struct gpio_chip *gpio_chip;
39715- struct irq_chip *irq_chip;
39716+ irq_chip_no_const *irq_chip;
39717 const char *name = dev_name(&pdev->dev);
39718 int ret;
39719
39720diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39721index 9902732..64b62dd 100644
39722--- a/drivers/gpio/gpio-vr41xx.c
39723+++ b/drivers/gpio/gpio-vr41xx.c
39724@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39725 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39726 maskl, pendl, maskh, pendh);
39727
39728- atomic_inc(&irq_err_count);
39729+ atomic_inc_unchecked(&irq_err_count);
39730
39731 return -EINVAL;
39732 }
39733diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39734index 3b7d32d..05c2f74 100644
39735--- a/drivers/gpu/drm/drm_crtc.c
39736+++ b/drivers/gpu/drm/drm_crtc.c
39737@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39738 goto done;
39739 }
39740
39741- if (copy_to_user(&enum_ptr[copied].name,
39742+ if (copy_to_user(enum_ptr[copied].name,
39743 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39744 ret = -EFAULT;
39745 goto done;
39746diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39747index 345be03..158368d 100644
39748--- a/drivers/gpu/drm/drm_drv.c
39749+++ b/drivers/gpu/drm/drm_drv.c
39750@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39751 /**
39752 * Copy and IOCTL return string to user space
39753 */
39754-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39755+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39756 {
39757 int len;
39758
39759@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39760 struct drm_file *file_priv = filp->private_data;
39761 struct drm_device *dev;
39762 const struct drm_ioctl_desc *ioctl = NULL;
39763- drm_ioctl_t *func;
39764+ drm_ioctl_no_const_t func;
39765 unsigned int nr = DRM_IOCTL_NR(cmd);
39766 int retcode = -EINVAL;
39767 char stack_kdata[128];
39768diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39769index 7f2af9a..1561914 100644
39770--- a/drivers/gpu/drm/drm_fops.c
39771+++ b/drivers/gpu/drm/drm_fops.c
39772@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39773 if (drm_device_is_unplugged(dev))
39774 return -ENODEV;
39775
39776- if (!dev->open_count++)
39777+ if (local_inc_return(&dev->open_count) == 1)
39778 need_setup = 1;
39779 mutex_lock(&dev->struct_mutex);
39780 old_imapping = inode->i_mapping;
39781@@ -127,7 +127,7 @@ err_undo:
39782 iput(container_of(dev->dev_mapping, struct inode, i_data));
39783 dev->dev_mapping = old_mapping;
39784 mutex_unlock(&dev->struct_mutex);
39785- dev->open_count--;
39786+ local_dec(&dev->open_count);
39787 return retcode;
39788 }
39789 EXPORT_SYMBOL(drm_open);
39790@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39791
39792 mutex_lock(&drm_global_mutex);
39793
39794- DRM_DEBUG("open_count = %d\n", dev->open_count);
39795+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39796
39797 if (dev->driver->preclose)
39798 dev->driver->preclose(dev, file_priv);
39799@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39800 * Begin inline drm_release
39801 */
39802
39803- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39804+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39805 task_pid_nr(current),
39806 (long)old_encode_dev(file_priv->minor->device),
39807- dev->open_count);
39808+ local_read(&dev->open_count));
39809
39810 /* Release any auth tokens that might point to this file_priv,
39811 (do that under the drm_global_mutex) */
39812@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39813 * End inline drm_release
39814 */
39815
39816- if (!--dev->open_count) {
39817+ if (local_dec_and_test(&dev->open_count)) {
39818 retcode = drm_lastclose(dev);
39819 if (drm_device_is_unplugged(dev))
39820 drm_put_dev(dev);
39821diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39822index 3d2e91c..d31c4c9 100644
39823--- a/drivers/gpu/drm/drm_global.c
39824+++ b/drivers/gpu/drm/drm_global.c
39825@@ -36,7 +36,7 @@
39826 struct drm_global_item {
39827 struct mutex mutex;
39828 void *object;
39829- int refcount;
39830+ atomic_t refcount;
39831 };
39832
39833 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39834@@ -49,7 +49,7 @@ void drm_global_init(void)
39835 struct drm_global_item *item = &glob[i];
39836 mutex_init(&item->mutex);
39837 item->object = NULL;
39838- item->refcount = 0;
39839+ atomic_set(&item->refcount, 0);
39840 }
39841 }
39842
39843@@ -59,7 +59,7 @@ void drm_global_release(void)
39844 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39845 struct drm_global_item *item = &glob[i];
39846 BUG_ON(item->object != NULL);
39847- BUG_ON(item->refcount != 0);
39848+ BUG_ON(atomic_read(&item->refcount) != 0);
39849 }
39850 }
39851
39852@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39853 struct drm_global_item *item = &glob[ref->global_type];
39854
39855 mutex_lock(&item->mutex);
39856- if (item->refcount == 0) {
39857+ if (atomic_read(&item->refcount) == 0) {
39858 item->object = kzalloc(ref->size, GFP_KERNEL);
39859 if (unlikely(item->object == NULL)) {
39860 ret = -ENOMEM;
39861@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39862 goto out_err;
39863
39864 }
39865- ++item->refcount;
39866+ atomic_inc(&item->refcount);
39867 ref->object = item->object;
39868 mutex_unlock(&item->mutex);
39869 return 0;
39870@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39871 struct drm_global_item *item = &glob[ref->global_type];
39872
39873 mutex_lock(&item->mutex);
39874- BUG_ON(item->refcount == 0);
39875+ BUG_ON(atomic_read(&item->refcount) == 0);
39876 BUG_ON(ref->object != item->object);
39877- if (--item->refcount == 0) {
39878+ if (atomic_dec_and_test(&item->refcount)) {
39879 ref->release(ref);
39880 item->object = NULL;
39881 }
39882diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39883index 7473035..a48b9c5 100644
39884--- a/drivers/gpu/drm/drm_info.c
39885+++ b/drivers/gpu/drm/drm_info.c
39886@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
39887 struct drm_local_map *map;
39888 struct drm_map_list *r_list;
39889
39890- /* Hardcoded from _DRM_FRAME_BUFFER,
39891- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39892- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39893- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39894+ static const char * const types[] = {
39895+ [_DRM_FRAME_BUFFER] = "FB",
39896+ [_DRM_REGISTERS] = "REG",
39897+ [_DRM_SHM] = "SHM",
39898+ [_DRM_AGP] = "AGP",
39899+ [_DRM_SCATTER_GATHER] = "SG",
39900+ [_DRM_CONSISTENT] = "PCI"};
39901 const char *type;
39902 int i;
39903
39904@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39905 map = r_list->map;
39906 if (!map)
39907 continue;
39908- if (map->type < 0 || map->type > 5)
39909+ if (map->type >= ARRAY_SIZE(types))
39910 type = "??";
39911 else
39912 type = types[map->type];
39913@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39914 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39915 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39916 vma->vm_flags & VM_IO ? 'i' : '-',
39917+#ifdef CONFIG_GRKERNSEC_HIDESYM
39918+ 0);
39919+#else
39920 vma->vm_pgoff);
39921+#endif
39922
39923 #if defined(__i386__)
39924 pgprot = pgprot_val(vma->vm_page_prot);
39925diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39926index 2f4c4343..dd12cd2 100644
39927--- a/drivers/gpu/drm/drm_ioc32.c
39928+++ b/drivers/gpu/drm/drm_ioc32.c
39929@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39930 request = compat_alloc_user_space(nbytes);
39931 if (!access_ok(VERIFY_WRITE, request, nbytes))
39932 return -EFAULT;
39933- list = (struct drm_buf_desc *) (request + 1);
39934+ list = (struct drm_buf_desc __user *) (request + 1);
39935
39936 if (__put_user(count, &request->count)
39937 || __put_user(list, &request->list))
39938@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39939 request = compat_alloc_user_space(nbytes);
39940 if (!access_ok(VERIFY_WRITE, request, nbytes))
39941 return -EFAULT;
39942- list = (struct drm_buf_pub *) (request + 1);
39943+ list = (struct drm_buf_pub __user *) (request + 1);
39944
39945 if (__put_user(count, &request->count)
39946 || __put_user(list, &request->list))
39947@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39948 return 0;
39949 }
39950
39951-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39952+drm_ioctl_compat_t drm_compat_ioctls[] = {
39953 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39954 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39955 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39956@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39957 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39958 {
39959 unsigned int nr = DRM_IOCTL_NR(cmd);
39960- drm_ioctl_compat_t *fn;
39961 int ret;
39962
39963 /* Assume that ioctls without an explicit compat routine will just
39964@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39965 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39966 return drm_ioctl(filp, cmd, arg);
39967
39968- fn = drm_compat_ioctls[nr];
39969-
39970- if (fn != NULL)
39971- ret = (*fn) (filp, cmd, arg);
39972+ if (drm_compat_ioctls[nr] != NULL)
39973+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39974 else
39975 ret = drm_ioctl(filp, cmd, arg);
39976
39977diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39978index 98a33c580..8fd1c2b 100644
39979--- a/drivers/gpu/drm/drm_stub.c
39980+++ b/drivers/gpu/drm/drm_stub.c
39981@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
39982
39983 drm_device_set_unplugged(dev);
39984
39985- if (dev->open_count == 0) {
39986+ if (local_read(&dev->open_count) == 0) {
39987 drm_put_dev(dev);
39988 }
39989 mutex_unlock(&drm_global_mutex);
39990diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39991index c22c309..ae758c3 100644
39992--- a/drivers/gpu/drm/drm_sysfs.c
39993+++ b/drivers/gpu/drm/drm_sysfs.c
39994@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39995 */
39996 int drm_sysfs_device_add(struct drm_minor *minor)
39997 {
39998- char *minor_str;
39999+ const char *minor_str;
40000 int r;
40001
40002 if (minor->type == DRM_MINOR_CONTROL)
40003diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40004index d4d16ed..8fb0b51 100644
40005--- a/drivers/gpu/drm/i810/i810_drv.h
40006+++ b/drivers/gpu/drm/i810/i810_drv.h
40007@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40008 int page_flipping;
40009
40010 wait_queue_head_t irq_queue;
40011- atomic_t irq_received;
40012- atomic_t irq_emitted;
40013+ atomic_unchecked_t irq_received;
40014+ atomic_unchecked_t irq_emitted;
40015
40016 int front_offset;
40017 } drm_i810_private_t;
40018diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40019index b2b46c5..feb9fe7 100644
40020--- a/drivers/gpu/drm/i915/i915_debugfs.c
40021+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40022@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40023 I915_READ(GTIMR));
40024 }
40025 seq_printf(m, "Interrupts received: %d\n",
40026- atomic_read(&dev_priv->irq_received));
40027+ atomic_read_unchecked(&dev_priv->irq_received));
40028 for_each_ring(ring, dev_priv, i) {
40029 if (INTEL_INFO(dev)->gen >= 6) {
40030 seq_printf(m,
40031diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40032index 15a74f9..4278889 100644
40033--- a/drivers/gpu/drm/i915/i915_dma.c
40034+++ b/drivers/gpu/drm/i915/i915_dma.c
40035@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40036 bool can_switch;
40037
40038 spin_lock(&dev->count_lock);
40039- can_switch = (dev->open_count == 0);
40040+ can_switch = (local_read(&dev->open_count) == 0);
40041 spin_unlock(&dev->count_lock);
40042 return can_switch;
40043 }
40044diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40045index df77e20..d3fda9f 100644
40046--- a/drivers/gpu/drm/i915/i915_drv.h
40047+++ b/drivers/gpu/drm/i915/i915_drv.h
40048@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40049 drm_dma_handle_t *status_page_dmah;
40050 struct resource mch_res;
40051
40052- atomic_t irq_received;
40053+ atomic_unchecked_t irq_received;
40054
40055 /* protects the irq masks */
40056 spinlock_t irq_lock;
40057diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40058index d269ecf..6d857bc 100644
40059--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40060+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40061@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40062
40063 static int
40064 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40065- int count)
40066+ unsigned int count)
40067 {
40068- int i;
40069+ unsigned int i;
40070 unsigned relocs_total = 0;
40071 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40072
40073diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40074index 3c59584..500f2e9 100644
40075--- a/drivers/gpu/drm/i915/i915_ioc32.c
40076+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40077@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40078 (unsigned long)request);
40079 }
40080
40081-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40082+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40083 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40084 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40085 [DRM_I915_GETPARAM] = compat_i915_getparam,
40086@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40087 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40088 {
40089 unsigned int nr = DRM_IOCTL_NR(cmd);
40090- drm_ioctl_compat_t *fn = NULL;
40091 int ret;
40092
40093 if (nr < DRM_COMMAND_BASE)
40094 return drm_compat_ioctl(filp, cmd, arg);
40095
40096- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40097- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40098-
40099- if (fn != NULL)
40100+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40101+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40102 ret = (*fn) (filp, cmd, arg);
40103- else
40104+ } else
40105 ret = drm_ioctl(filp, cmd, arg);
40106
40107 return ret;
40108diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40109index d554169..f4426bb 100644
40110--- a/drivers/gpu/drm/i915/i915_irq.c
40111+++ b/drivers/gpu/drm/i915/i915_irq.c
40112@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40113 int pipe;
40114 u32 pipe_stats[I915_MAX_PIPES];
40115
40116- atomic_inc(&dev_priv->irq_received);
40117+ atomic_inc_unchecked(&dev_priv->irq_received);
40118
40119 while (true) {
40120 iir = I915_READ(VLV_IIR);
40121@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40122 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40123 irqreturn_t ret = IRQ_NONE;
40124
40125- atomic_inc(&dev_priv->irq_received);
40126+ atomic_inc_unchecked(&dev_priv->irq_received);
40127
40128 /* We get interrupts on unclaimed registers, so check for this before we
40129 * do any I915_{READ,WRITE}. */
40130@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40131 uint32_t tmp = 0;
40132 enum pipe pipe;
40133
40134- atomic_inc(&dev_priv->irq_received);
40135+ atomic_inc_unchecked(&dev_priv->irq_received);
40136
40137 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40138 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40139@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40140 {
40141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40142
40143- atomic_set(&dev_priv->irq_received, 0);
40144+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40145
40146 I915_WRITE(HWSTAM, 0xeffe);
40147
40148@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40149 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40150 int pipe;
40151
40152- atomic_set(&dev_priv->irq_received, 0);
40153+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40154
40155 /* VLV magic */
40156 I915_WRITE(VLV_IMR, 0);
40157@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40158 struct drm_i915_private *dev_priv = dev->dev_private;
40159 int pipe;
40160
40161- atomic_set(&dev_priv->irq_received, 0);
40162+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40163
40164 I915_WRITE(GEN8_MASTER_IRQ, 0);
40165 POSTING_READ(GEN8_MASTER_IRQ);
40166@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40167 if (!dev_priv)
40168 return;
40169
40170- atomic_set(&dev_priv->irq_received, 0);
40171+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40172
40173 I915_WRITE(GEN8_MASTER_IRQ, 0);
40174
40175@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40176 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40177 int pipe;
40178
40179- atomic_set(&dev_priv->irq_received, 0);
40180+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40181
40182 for_each_pipe(pipe)
40183 I915_WRITE(PIPESTAT(pipe), 0);
40184@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40185 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40186 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40187
40188- atomic_inc(&dev_priv->irq_received);
40189+ atomic_inc_unchecked(&dev_priv->irq_received);
40190
40191 iir = I915_READ16(IIR);
40192 if (iir == 0)
40193@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40194 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40195 int pipe;
40196
40197- atomic_set(&dev_priv->irq_received, 0);
40198+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40199
40200 if (I915_HAS_HOTPLUG(dev)) {
40201 I915_WRITE(PORT_HOTPLUG_EN, 0);
40202@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40203 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40204 int pipe, ret = IRQ_NONE;
40205
40206- atomic_inc(&dev_priv->irq_received);
40207+ atomic_inc_unchecked(&dev_priv->irq_received);
40208
40209 iir = I915_READ(IIR);
40210 do {
40211@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40212 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40213 int pipe;
40214
40215- atomic_set(&dev_priv->irq_received, 0);
40216+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40217
40218 I915_WRITE(PORT_HOTPLUG_EN, 0);
40219 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40220@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40221 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40222 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40223
40224- atomic_inc(&dev_priv->irq_received);
40225+ atomic_inc_unchecked(&dev_priv->irq_received);
40226
40227 iir = I915_READ(IIR);
40228
40229diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40230index 9b8a7c7..60f6003 100644
40231--- a/drivers/gpu/drm/i915/intel_display.c
40232+++ b/drivers/gpu/drm/i915/intel_display.c
40233@@ -10776,13 +10776,13 @@ struct intel_quirk {
40234 int subsystem_vendor;
40235 int subsystem_device;
40236 void (*hook)(struct drm_device *dev);
40237-};
40238+} __do_const;
40239
40240 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40241 struct intel_dmi_quirk {
40242 void (*hook)(struct drm_device *dev);
40243 const struct dmi_system_id (*dmi_id_list)[];
40244-};
40245+} __do_const;
40246
40247 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40248 {
40249@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40250 return 1;
40251 }
40252
40253-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40254+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40255 {
40256- .dmi_id_list = &(const struct dmi_system_id[]) {
40257- {
40258- .callback = intel_dmi_reverse_brightness,
40259- .ident = "NCR Corporation",
40260- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40261- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40262- },
40263- },
40264- { } /* terminating entry */
40265+ .callback = intel_dmi_reverse_brightness,
40266+ .ident = "NCR Corporation",
40267+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40268+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40269 },
40270+ },
40271+ { } /* terminating entry */
40272+};
40273+
40274+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40275+ {
40276+ .dmi_id_list = &intel_dmi_quirks_table,
40277 .hook = quirk_invert_brightness,
40278 },
40279 };
40280diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40281index fe45321..836fdca 100644
40282--- a/drivers/gpu/drm/mga/mga_drv.h
40283+++ b/drivers/gpu/drm/mga/mga_drv.h
40284@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40285 u32 clear_cmd;
40286 u32 maccess;
40287
40288- atomic_t vbl_received; /**< Number of vblanks received. */
40289+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40290 wait_queue_head_t fence_queue;
40291- atomic_t last_fence_retired;
40292+ atomic_unchecked_t last_fence_retired;
40293 u32 next_fence_to_post;
40294
40295 unsigned int fb_cpp;
40296diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40297index 86b4bb8..ae237ad 100644
40298--- a/drivers/gpu/drm/mga/mga_ioc32.c
40299+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40300@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40301 return 0;
40302 }
40303
40304-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40305+drm_ioctl_compat_t mga_compat_ioctls[] = {
40306 [DRM_MGA_INIT] = compat_mga_init,
40307 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40308 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40309@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40310 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40311 {
40312 unsigned int nr = DRM_IOCTL_NR(cmd);
40313- drm_ioctl_compat_t *fn = NULL;
40314 int ret;
40315
40316 if (nr < DRM_COMMAND_BASE)
40317 return drm_compat_ioctl(filp, cmd, arg);
40318
40319- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40320- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40321-
40322- if (fn != NULL)
40323+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40324+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40325 ret = (*fn) (filp, cmd, arg);
40326- else
40327+ } else
40328 ret = drm_ioctl(filp, cmd, arg);
40329
40330 return ret;
40331diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40332index 1b071b8..de8601a 100644
40333--- a/drivers/gpu/drm/mga/mga_irq.c
40334+++ b/drivers/gpu/drm/mga/mga_irq.c
40335@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40336 if (crtc != 0)
40337 return 0;
40338
40339- return atomic_read(&dev_priv->vbl_received);
40340+ return atomic_read_unchecked(&dev_priv->vbl_received);
40341 }
40342
40343
40344@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40345 /* VBLANK interrupt */
40346 if (status & MGA_VLINEPEN) {
40347 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40348- atomic_inc(&dev_priv->vbl_received);
40349+ atomic_inc_unchecked(&dev_priv->vbl_received);
40350 drm_handle_vblank(dev, 0);
40351 handled = 1;
40352 }
40353@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40354 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40355 MGA_WRITE(MGA_PRIMEND, prim_end);
40356
40357- atomic_inc(&dev_priv->last_fence_retired);
40358+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40359 wake_up(&dev_priv->fence_queue);
40360 handled = 1;
40361 }
40362@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40363 * using fences.
40364 */
40365 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40366- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40367+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40368 - *sequence) <= (1 << 23)));
40369
40370 *sequence = cur_fence;
40371diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40372index 4c3feaa..26391ce 100644
40373--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40374+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40375@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40376 struct bit_table {
40377 const char id;
40378 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40379-};
40380+} __no_const;
40381
40382 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40383
40384diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40385index 23ca7a5..b6c955d 100644
40386--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40387+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40388@@ -97,7 +97,6 @@ struct nouveau_drm {
40389 struct drm_global_reference mem_global_ref;
40390 struct ttm_bo_global_ref bo_global_ref;
40391 struct ttm_bo_device bdev;
40392- atomic_t validate_sequence;
40393 int (*move)(struct nouveau_channel *,
40394 struct ttm_buffer_object *,
40395 struct ttm_mem_reg *, struct ttm_mem_reg *);
40396diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40397index c1a7e5a..38b8539 100644
40398--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40399+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40400@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40401 unsigned long arg)
40402 {
40403 unsigned int nr = DRM_IOCTL_NR(cmd);
40404- drm_ioctl_compat_t *fn = NULL;
40405+ drm_ioctl_compat_t fn = NULL;
40406 int ret;
40407
40408 if (nr < DRM_COMMAND_BASE)
40409diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40410index d45d50d..72a5dd2 100644
40411--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40412+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40413@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40414 }
40415
40416 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40417- nouveau_vram_manager_init,
40418- nouveau_vram_manager_fini,
40419- nouveau_vram_manager_new,
40420- nouveau_vram_manager_del,
40421- nouveau_vram_manager_debug
40422+ .init = nouveau_vram_manager_init,
40423+ .takedown = nouveau_vram_manager_fini,
40424+ .get_node = nouveau_vram_manager_new,
40425+ .put_node = nouveau_vram_manager_del,
40426+ .debug = nouveau_vram_manager_debug
40427 };
40428
40429 static int
40430@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40431 }
40432
40433 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40434- nouveau_gart_manager_init,
40435- nouveau_gart_manager_fini,
40436- nouveau_gart_manager_new,
40437- nouveau_gart_manager_del,
40438- nouveau_gart_manager_debug
40439+ .init = nouveau_gart_manager_init,
40440+ .takedown = nouveau_gart_manager_fini,
40441+ .get_node = nouveau_gart_manager_new,
40442+ .put_node = nouveau_gart_manager_del,
40443+ .debug = nouveau_gart_manager_debug
40444 };
40445
40446 #include <core/subdev/vm/nv04.h>
40447@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40448 }
40449
40450 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40451- nv04_gart_manager_init,
40452- nv04_gart_manager_fini,
40453- nv04_gart_manager_new,
40454- nv04_gart_manager_del,
40455- nv04_gart_manager_debug
40456+ .init = nv04_gart_manager_init,
40457+ .takedown = nv04_gart_manager_fini,
40458+ .get_node = nv04_gart_manager_new,
40459+ .put_node = nv04_gart_manager_del,
40460+ .debug = nv04_gart_manager_debug
40461 };
40462
40463 int
40464diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40465index 471347e..5adc6b9 100644
40466--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40467+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40468@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40469 bool can_switch;
40470
40471 spin_lock(&dev->count_lock);
40472- can_switch = (dev->open_count == 0);
40473+ can_switch = (local_read(&dev->open_count) == 0);
40474 spin_unlock(&dev->count_lock);
40475 return can_switch;
40476 }
40477diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40478index eb89653..613cf71 100644
40479--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40480+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40481@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40482 int ret;
40483
40484 mutex_lock(&qdev->async_io_mutex);
40485- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40486+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40487 if (qdev->last_sent_io_cmd > irq_num) {
40488 if (intr)
40489 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40490- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40491+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40492 else
40493 ret = wait_event_timeout(qdev->io_cmd_event,
40494- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40495+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40496 /* 0 is timeout, just bail the "hw" has gone away */
40497 if (ret <= 0)
40498 goto out;
40499- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40500+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40501 }
40502 outb(val, addr);
40503 qdev->last_sent_io_cmd = irq_num + 1;
40504 if (intr)
40505 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40506- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40507+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40508 else
40509 ret = wait_event_timeout(qdev->io_cmd_event,
40510- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40511+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40512 out:
40513 if (ret > 0)
40514 ret = 0;
40515diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40516index c3c2bbd..bc3c0fb 100644
40517--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40518+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40519@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40520 struct drm_info_node *node = (struct drm_info_node *) m->private;
40521 struct qxl_device *qdev = node->minor->dev->dev_private;
40522
40523- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40524- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40525- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40526- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40527+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40528+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40529+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40530+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40531 seq_printf(m, "%d\n", qdev->irq_received_error);
40532 return 0;
40533 }
40534diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40535index 36ed40b..0397633 100644
40536--- a/drivers/gpu/drm/qxl/qxl_drv.h
40537+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40538@@ -290,10 +290,10 @@ struct qxl_device {
40539 unsigned int last_sent_io_cmd;
40540
40541 /* interrupt handling */
40542- atomic_t irq_received;
40543- atomic_t irq_received_display;
40544- atomic_t irq_received_cursor;
40545- atomic_t irq_received_io_cmd;
40546+ atomic_unchecked_t irq_received;
40547+ atomic_unchecked_t irq_received_display;
40548+ atomic_unchecked_t irq_received_cursor;
40549+ atomic_unchecked_t irq_received_io_cmd;
40550 unsigned irq_received_error;
40551 wait_queue_head_t display_event;
40552 wait_queue_head_t cursor_event;
40553diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40554index 0bb86e6..d41416d 100644
40555--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40556+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40557@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40558
40559 /* TODO copy slow path code from i915 */
40560 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40561- 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);
40562+ 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);
40563
40564 {
40565 struct qxl_drawable *draw = fb_cmd;
40566@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40567 struct drm_qxl_reloc reloc;
40568
40569 if (copy_from_user(&reloc,
40570- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40571+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40572 sizeof(reloc))) {
40573 ret = -EFAULT;
40574 goto out_free_bos;
40575@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40576
40577 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40578
40579- struct drm_qxl_command *commands =
40580- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40581+ struct drm_qxl_command __user *commands =
40582+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40583
40584- if (copy_from_user(&user_cmd, &commands[cmd_num],
40585+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40586 sizeof(user_cmd)))
40587 return -EFAULT;
40588
40589diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40590index 28f84b4..fb3e224 100644
40591--- a/drivers/gpu/drm/qxl/qxl_irq.c
40592+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40593@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40594
40595 pending = xchg(&qdev->ram_header->int_pending, 0);
40596
40597- atomic_inc(&qdev->irq_received);
40598+ atomic_inc_unchecked(&qdev->irq_received);
40599
40600 if (pending & QXL_INTERRUPT_DISPLAY) {
40601- atomic_inc(&qdev->irq_received_display);
40602+ atomic_inc_unchecked(&qdev->irq_received_display);
40603 wake_up_all(&qdev->display_event);
40604 qxl_queue_garbage_collect(qdev, false);
40605 }
40606 if (pending & QXL_INTERRUPT_CURSOR) {
40607- atomic_inc(&qdev->irq_received_cursor);
40608+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40609 wake_up_all(&qdev->cursor_event);
40610 }
40611 if (pending & QXL_INTERRUPT_IO_CMD) {
40612- atomic_inc(&qdev->irq_received_io_cmd);
40613+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40614 wake_up_all(&qdev->io_cmd_event);
40615 }
40616 if (pending & QXL_INTERRUPT_ERROR) {
40617@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40618 init_waitqueue_head(&qdev->io_cmd_event);
40619 INIT_WORK(&qdev->client_monitors_config_work,
40620 qxl_client_monitors_config_work_func);
40621- atomic_set(&qdev->irq_received, 0);
40622- atomic_set(&qdev->irq_received_display, 0);
40623- atomic_set(&qdev->irq_received_cursor, 0);
40624- atomic_set(&qdev->irq_received_io_cmd, 0);
40625+ atomic_set_unchecked(&qdev->irq_received, 0);
40626+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40627+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40628+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40629 qdev->irq_received_error = 0;
40630 ret = drm_irq_install(qdev->ddev);
40631 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40632diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40633index c7e7e65..7dddd4d 100644
40634--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40635+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40636@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40637 }
40638 }
40639
40640-static struct vm_operations_struct qxl_ttm_vm_ops;
40641+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40642 static const struct vm_operations_struct *ttm_vm_ops;
40643
40644 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40645@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40646 return r;
40647 if (unlikely(ttm_vm_ops == NULL)) {
40648 ttm_vm_ops = vma->vm_ops;
40649+ pax_open_kernel();
40650 qxl_ttm_vm_ops = *ttm_vm_ops;
40651 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40652+ pax_close_kernel();
40653 }
40654 vma->vm_ops = &qxl_ttm_vm_ops;
40655 return 0;
40656@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40657 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40658 {
40659 #if defined(CONFIG_DEBUG_FS)
40660- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40661- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40662- unsigned i;
40663+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40664+ {
40665+ .name = "qxl_mem_mm",
40666+ .show = &qxl_mm_dump_table,
40667+ },
40668+ {
40669+ .name = "qxl_surf_mm",
40670+ .show = &qxl_mm_dump_table,
40671+ }
40672+ };
40673
40674- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40675- if (i == 0)
40676- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40677- else
40678- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40679- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40680- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40681- qxl_mem_types_list[i].driver_features = 0;
40682- if (i == 0)
40683- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40684- else
40685- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40686+ pax_open_kernel();
40687+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40688+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40689+ pax_close_kernel();
40690
40691- }
40692- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40693+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40694 #else
40695 return 0;
40696 #endif
40697diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40698index 59459fe..be26b31 100644
40699--- a/drivers/gpu/drm/r128/r128_cce.c
40700+++ b/drivers/gpu/drm/r128/r128_cce.c
40701@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40702
40703 /* GH: Simple idle check.
40704 */
40705- atomic_set(&dev_priv->idle_count, 0);
40706+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40707
40708 /* We don't support anything other than bus-mastering ring mode,
40709 * but the ring can be in either AGP or PCI space for the ring
40710diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40711index 5bf3f5f..7000661 100644
40712--- a/drivers/gpu/drm/r128/r128_drv.h
40713+++ b/drivers/gpu/drm/r128/r128_drv.h
40714@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40715 int is_pci;
40716 unsigned long cce_buffers_offset;
40717
40718- atomic_t idle_count;
40719+ atomic_unchecked_t idle_count;
40720
40721 int page_flipping;
40722 int current_page;
40723 u32 crtc_offset;
40724 u32 crtc_offset_cntl;
40725
40726- atomic_t vbl_received;
40727+ atomic_unchecked_t vbl_received;
40728
40729 u32 color_fmt;
40730 unsigned int front_offset;
40731diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40732index b0d0fd3..a6fbbe4 100644
40733--- a/drivers/gpu/drm/r128/r128_ioc32.c
40734+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40735@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40736 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40737 }
40738
40739-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40740+drm_ioctl_compat_t r128_compat_ioctls[] = {
40741 [DRM_R128_INIT] = compat_r128_init,
40742 [DRM_R128_DEPTH] = compat_r128_depth,
40743 [DRM_R128_STIPPLE] = compat_r128_stipple,
40744@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40745 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40746 {
40747 unsigned int nr = DRM_IOCTL_NR(cmd);
40748- drm_ioctl_compat_t *fn = NULL;
40749 int ret;
40750
40751 if (nr < DRM_COMMAND_BASE)
40752 return drm_compat_ioctl(filp, cmd, arg);
40753
40754- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40755- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40756-
40757- if (fn != NULL)
40758+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40759+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40760 ret = (*fn) (filp, cmd, arg);
40761- else
40762+ } else
40763 ret = drm_ioctl(filp, cmd, arg);
40764
40765 return ret;
40766diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40767index c2ae496..30b5993 100644
40768--- a/drivers/gpu/drm/r128/r128_irq.c
40769+++ b/drivers/gpu/drm/r128/r128_irq.c
40770@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40771 if (crtc != 0)
40772 return 0;
40773
40774- return atomic_read(&dev_priv->vbl_received);
40775+ return atomic_read_unchecked(&dev_priv->vbl_received);
40776 }
40777
40778 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40779@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40780 /* VBLANK interrupt */
40781 if (status & R128_CRTC_VBLANK_INT) {
40782 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40783- atomic_inc(&dev_priv->vbl_received);
40784+ atomic_inc_unchecked(&dev_priv->vbl_received);
40785 drm_handle_vblank(dev, 0);
40786 return IRQ_HANDLED;
40787 }
40788diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40789index e806dac..f81d32f 100644
40790--- a/drivers/gpu/drm/r128/r128_state.c
40791+++ b/drivers/gpu/drm/r128/r128_state.c
40792@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40793
40794 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40795 {
40796- if (atomic_read(&dev_priv->idle_count) == 0)
40797+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40798 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40799 else
40800- atomic_set(&dev_priv->idle_count, 0);
40801+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40802 }
40803
40804 #endif
40805diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40806index 4a85bb6..aaea819 100644
40807--- a/drivers/gpu/drm/radeon/mkregtable.c
40808+++ b/drivers/gpu/drm/radeon/mkregtable.c
40809@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40810 regex_t mask_rex;
40811 regmatch_t match[4];
40812 char buf[1024];
40813- size_t end;
40814+ long end;
40815 int len;
40816 int done = 0;
40817 int r;
40818 unsigned o;
40819 struct offset *offset;
40820 char last_reg_s[10];
40821- int last_reg;
40822+ unsigned long last_reg;
40823
40824 if (regcomp
40825 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40826diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40827index 044bc98..50ced9b 100644
40828--- a/drivers/gpu/drm/radeon/radeon_device.c
40829+++ b/drivers/gpu/drm/radeon/radeon_device.c
40830@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40831 bool can_switch;
40832
40833 spin_lock(&dev->count_lock);
40834- can_switch = (dev->open_count == 0);
40835+ can_switch = (local_read(&dev->open_count) == 0);
40836 spin_unlock(&dev->count_lock);
40837 return can_switch;
40838 }
40839diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40840index dafd812..1bf20c7 100644
40841--- a/drivers/gpu/drm/radeon/radeon_drv.h
40842+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40843@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40844
40845 /* SW interrupt */
40846 wait_queue_head_t swi_queue;
40847- atomic_t swi_emitted;
40848+ atomic_unchecked_t swi_emitted;
40849 int vblank_crtc;
40850 uint32_t irq_enable_reg;
40851 uint32_t r500_disp_irq_reg;
40852diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40853index bdb0f93..5ff558f 100644
40854--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40855+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40856@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40857 request = compat_alloc_user_space(sizeof(*request));
40858 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40859 || __put_user(req32.param, &request->param)
40860- || __put_user((void __user *)(unsigned long)req32.value,
40861+ || __put_user((unsigned long)req32.value,
40862 &request->value))
40863 return -EFAULT;
40864
40865@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40866 #define compat_radeon_cp_setparam NULL
40867 #endif /* X86_64 || IA64 */
40868
40869-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40870+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40871 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40872 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40873 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40874@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40875 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40876 {
40877 unsigned int nr = DRM_IOCTL_NR(cmd);
40878- drm_ioctl_compat_t *fn = NULL;
40879 int ret;
40880
40881 if (nr < DRM_COMMAND_BASE)
40882 return drm_compat_ioctl(filp, cmd, arg);
40883
40884- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40885- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40886-
40887- if (fn != NULL)
40888+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40889+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40890 ret = (*fn) (filp, cmd, arg);
40891- else
40892+ } else
40893 ret = drm_ioctl(filp, cmd, arg);
40894
40895 return ret;
40896diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40897index 244b19b..c19226d 100644
40898--- a/drivers/gpu/drm/radeon/radeon_irq.c
40899+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40900@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40901 unsigned int ret;
40902 RING_LOCALS;
40903
40904- atomic_inc(&dev_priv->swi_emitted);
40905- ret = atomic_read(&dev_priv->swi_emitted);
40906+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40907+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40908
40909 BEGIN_RING(4);
40910 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40911@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40912 drm_radeon_private_t *dev_priv =
40913 (drm_radeon_private_t *) dev->dev_private;
40914
40915- atomic_set(&dev_priv->swi_emitted, 0);
40916+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40917 init_waitqueue_head(&dev_priv->swi_queue);
40918
40919 dev->max_vblank_count = 0x001fffff;
40920diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40921index 956ab7f..fbd36d8 100644
40922--- a/drivers/gpu/drm/radeon/radeon_state.c
40923+++ b/drivers/gpu/drm/radeon/radeon_state.c
40924@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40925 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40926 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40927
40928- if (copy_from_user(&depth_boxes, clear->depth_boxes,
40929+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40930 sarea_priv->nbox * sizeof(depth_boxes[0])))
40931 return -EFAULT;
40932
40933@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40934 {
40935 drm_radeon_private_t *dev_priv = dev->dev_private;
40936 drm_radeon_getparam_t *param = data;
40937- int value;
40938+ int value = 0;
40939
40940 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40941
40942diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40943index 040a2a1..eae4e54 100644
40944--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40945+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40946@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40947 man->size = size >> PAGE_SHIFT;
40948 }
40949
40950-static struct vm_operations_struct radeon_ttm_vm_ops;
40951+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40952 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40953
40954 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40955@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40956 }
40957 if (unlikely(ttm_vm_ops == NULL)) {
40958 ttm_vm_ops = vma->vm_ops;
40959+ pax_open_kernel();
40960 radeon_ttm_vm_ops = *ttm_vm_ops;
40961 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40962+ pax_close_kernel();
40963 }
40964 vma->vm_ops = &radeon_ttm_vm_ops;
40965 return 0;
40966diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40967index 9336006..ce78aa7 100644
40968--- a/drivers/gpu/drm/tegra/dc.c
40969+++ b/drivers/gpu/drm/tegra/dc.c
40970@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40971 }
40972
40973 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40974- dc->debugfs_files[i].data = dc;
40975+ *(void **)&dc->debugfs_files[i].data = dc;
40976
40977 err = drm_debugfs_create_files(dc->debugfs_files,
40978 ARRAY_SIZE(debugfs_files),
40979diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
40980index d452faab..f8cbc6a 100644
40981--- a/drivers/gpu/drm/tegra/dsi.c
40982+++ b/drivers/gpu/drm/tegra/dsi.c
40983@@ -53,7 +53,7 @@ struct tegra_dsi {
40984 struct clk *clk_lp;
40985 struct clk *clk;
40986
40987- struct drm_info_list *debugfs_files;
40988+ drm_info_list_no_const *debugfs_files;
40989 struct drm_minor *minor;
40990 struct dentry *debugfs;
40991
40992diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40993index 6928015..c9853e7 100644
40994--- a/drivers/gpu/drm/tegra/hdmi.c
40995+++ b/drivers/gpu/drm/tegra/hdmi.c
40996@@ -59,7 +59,7 @@ struct tegra_hdmi {
40997 bool stereo;
40998 bool dvi;
40999
41000- struct drm_info_list *debugfs_files;
41001+ drm_info_list_no_const *debugfs_files;
41002 struct drm_minor *minor;
41003 struct dentry *debugfs;
41004 };
41005diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41006index c58eba33..83c2728 100644
41007--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41008+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41009@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41010 }
41011
41012 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41013- ttm_bo_man_init,
41014- ttm_bo_man_takedown,
41015- ttm_bo_man_get_node,
41016- ttm_bo_man_put_node,
41017- ttm_bo_man_debug
41018+ .init = ttm_bo_man_init,
41019+ .takedown = ttm_bo_man_takedown,
41020+ .get_node = ttm_bo_man_get_node,
41021+ .put_node = ttm_bo_man_put_node,
41022+ .debug = ttm_bo_man_debug
41023 };
41024 EXPORT_SYMBOL(ttm_bo_manager_func);
41025diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41026index dbc2def..0a9f710 100644
41027--- a/drivers/gpu/drm/ttm/ttm_memory.c
41028+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41029@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41030 zone->glob = glob;
41031 glob->zone_kernel = zone;
41032 ret = kobject_init_and_add(
41033- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41034+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41035 if (unlikely(ret != 0)) {
41036 kobject_put(&zone->kobj);
41037 return ret;
41038@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41039 zone->glob = glob;
41040 glob->zone_dma32 = zone;
41041 ret = kobject_init_and_add(
41042- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41043+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41044 if (unlikely(ret != 0)) {
41045 kobject_put(&zone->kobj);
41046 return ret;
41047diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41048index 863bef9..cba15cf 100644
41049--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41050+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41051@@ -391,9 +391,9 @@ out:
41052 static unsigned long
41053 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41054 {
41055- static atomic_t start_pool = ATOMIC_INIT(0);
41056+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41057 unsigned i;
41058- unsigned pool_offset = atomic_add_return(1, &start_pool);
41059+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41060 struct ttm_page_pool *pool;
41061 int shrink_pages = sc->nr_to_scan;
41062 unsigned long freed = 0;
41063diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41064index dbadd49..1b7457b 100644
41065--- a/drivers/gpu/drm/udl/udl_fb.c
41066+++ b/drivers/gpu/drm/udl/udl_fb.c
41067@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41068 fb_deferred_io_cleanup(info);
41069 kfree(info->fbdefio);
41070 info->fbdefio = NULL;
41071- info->fbops->fb_mmap = udl_fb_mmap;
41072 }
41073
41074 pr_warn("released /dev/fb%d user=%d count=%d\n",
41075diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41076index ad02732..144f5ed 100644
41077--- a/drivers/gpu/drm/via/via_drv.h
41078+++ b/drivers/gpu/drm/via/via_drv.h
41079@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41080 typedef uint32_t maskarray_t[5];
41081
41082 typedef struct drm_via_irq {
41083- atomic_t irq_received;
41084+ atomic_unchecked_t irq_received;
41085 uint32_t pending_mask;
41086 uint32_t enable_mask;
41087 wait_queue_head_t irq_queue;
41088@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41089 struct timeval last_vblank;
41090 int last_vblank_valid;
41091 unsigned usec_per_vblank;
41092- atomic_t vbl_received;
41093+ atomic_unchecked_t vbl_received;
41094 drm_via_state_t hc_state;
41095 char pci_buf[VIA_PCI_BUF_SIZE];
41096 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41097diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41098index 1319433..a993b0c 100644
41099--- a/drivers/gpu/drm/via/via_irq.c
41100+++ b/drivers/gpu/drm/via/via_irq.c
41101@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41102 if (crtc != 0)
41103 return 0;
41104
41105- return atomic_read(&dev_priv->vbl_received);
41106+ return atomic_read_unchecked(&dev_priv->vbl_received);
41107 }
41108
41109 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41110@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41111
41112 status = VIA_READ(VIA_REG_INTERRUPT);
41113 if (status & VIA_IRQ_VBLANK_PENDING) {
41114- atomic_inc(&dev_priv->vbl_received);
41115- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41116+ atomic_inc_unchecked(&dev_priv->vbl_received);
41117+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41118 do_gettimeofday(&cur_vblank);
41119 if (dev_priv->last_vblank_valid) {
41120 dev_priv->usec_per_vblank =
41121@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41122 dev_priv->last_vblank = cur_vblank;
41123 dev_priv->last_vblank_valid = 1;
41124 }
41125- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41126+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41127 DRM_DEBUG("US per vblank is: %u\n",
41128 dev_priv->usec_per_vblank);
41129 }
41130@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41131
41132 for (i = 0; i < dev_priv->num_irqs; ++i) {
41133 if (status & cur_irq->pending_mask) {
41134- atomic_inc(&cur_irq->irq_received);
41135+ atomic_inc_unchecked(&cur_irq->irq_received);
41136 wake_up(&cur_irq->irq_queue);
41137 handled = 1;
41138 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41139@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41140 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41141 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41142 masks[irq][4]));
41143- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41144+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41145 } else {
41146 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41147 (((cur_irq_sequence =
41148- atomic_read(&cur_irq->irq_received)) -
41149+ atomic_read_unchecked(&cur_irq->irq_received)) -
41150 *sequence) <= (1 << 23)));
41151 }
41152 *sequence = cur_irq_sequence;
41153@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41154 }
41155
41156 for (i = 0; i < dev_priv->num_irqs; ++i) {
41157- atomic_set(&cur_irq->irq_received, 0);
41158+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41159 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41160 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41161 init_waitqueue_head(&cur_irq->irq_queue);
41162@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41163 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41164 case VIA_IRQ_RELATIVE:
41165 irqwait->request.sequence +=
41166- atomic_read(&cur_irq->irq_received);
41167+ atomic_read_unchecked(&cur_irq->irq_received);
41168 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41169 case VIA_IRQ_ABSOLUTE:
41170 break;
41171diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41172index 0783155..b29e18e 100644
41173--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41174+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41175@@ -437,7 +437,7 @@ struct vmw_private {
41176 * Fencing and IRQs.
41177 */
41178
41179- atomic_t marker_seq;
41180+ atomic_unchecked_t marker_seq;
41181 wait_queue_head_t fence_queue;
41182 wait_queue_head_t fifo_queue;
41183 int fence_queue_waiters; /* Protected by hw_mutex */
41184diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41185index 6ccd993..618d592 100644
41186--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41187+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41188@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41189 (unsigned int) min,
41190 (unsigned int) fifo->capabilities);
41191
41192- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41193+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41194 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41195 vmw_marker_queue_init(&fifo->marker_queue);
41196 return vmw_fifo_send_fence(dev_priv, &dummy);
41197@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41198 if (reserveable)
41199 iowrite32(bytes, fifo_mem +
41200 SVGA_FIFO_RESERVED);
41201- return fifo_mem + (next_cmd >> 2);
41202+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41203 } else {
41204 need_bounce = true;
41205 }
41206@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41207
41208 fm = vmw_fifo_reserve(dev_priv, bytes);
41209 if (unlikely(fm == NULL)) {
41210- *seqno = atomic_read(&dev_priv->marker_seq);
41211+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41212 ret = -ENOMEM;
41213 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41214 false, 3*HZ);
41215@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41216 }
41217
41218 do {
41219- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41220+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41221 } while (*seqno == 0);
41222
41223 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41224diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41225index b1273e8..9c274fd 100644
41226--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41227+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41228@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41229 }
41230
41231 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41232- vmw_gmrid_man_init,
41233- vmw_gmrid_man_takedown,
41234- vmw_gmrid_man_get_node,
41235- vmw_gmrid_man_put_node,
41236- vmw_gmrid_man_debug
41237+ .init = vmw_gmrid_man_init,
41238+ .takedown = vmw_gmrid_man_takedown,
41239+ .get_node = vmw_gmrid_man_get_node,
41240+ .put_node = vmw_gmrid_man_put_node,
41241+ .debug = vmw_gmrid_man_debug
41242 };
41243diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41244index 47b7094..698ba09 100644
41245--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41246+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41247@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41248 int ret;
41249
41250 num_clips = arg->num_clips;
41251- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41252+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41253
41254 if (unlikely(num_clips == 0))
41255 return 0;
41256@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41257 int ret;
41258
41259 num_clips = arg->num_clips;
41260- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41261+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41262
41263 if (unlikely(num_clips == 0))
41264 return 0;
41265diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41266index 0c42376..6febe77 100644
41267--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41268+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41269@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41270 * emitted. Then the fence is stale and signaled.
41271 */
41272
41273- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41274+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41275 > VMW_FENCE_WRAP);
41276
41277 return ret;
41278@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41279
41280 if (fifo_idle)
41281 down_read(&fifo_state->rwsem);
41282- signal_seq = atomic_read(&dev_priv->marker_seq);
41283+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41284 ret = 0;
41285
41286 for (;;) {
41287diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41288index 8a8725c2..afed796 100644
41289--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41290+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41291@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41292 while (!vmw_lag_lt(queue, us)) {
41293 spin_lock(&queue->lock);
41294 if (list_empty(&queue->head))
41295- seqno = atomic_read(&dev_priv->marker_seq);
41296+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41297 else {
41298 marker = list_first_entry(&queue->head,
41299 struct vmw_marker, head);
41300diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41301index ec0ae2d..dc0780b 100644
41302--- a/drivers/gpu/vga/vga_switcheroo.c
41303+++ b/drivers/gpu/vga/vga_switcheroo.c
41304@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41305
41306 /* this version is for the case where the power switch is separate
41307 to the device being powered down. */
41308-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41309+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41310 {
41311 /* copy over all the bus versions */
41312 if (dev->bus && dev->bus->pm) {
41313@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41314 return ret;
41315 }
41316
41317-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41318+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41319 {
41320 /* copy over all the bus versions */
41321 if (dev->bus && dev->bus->pm) {
41322diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41323index cc32a6f..02a4b1c 100644
41324--- a/drivers/hid/hid-core.c
41325+++ b/drivers/hid/hid-core.c
41326@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41327
41328 int hid_add_device(struct hid_device *hdev)
41329 {
41330- static atomic_t id = ATOMIC_INIT(0);
41331+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41332 int ret;
41333
41334 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41335@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41336 /* XXX hack, any other cleaner solution after the driver core
41337 * is converted to allow more than 20 bytes as the device name? */
41338 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41339- hdev->vendor, hdev->product, atomic_inc_return(&id));
41340+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41341
41342 hid_debug_register(hdev, dev_name(&hdev->dev));
41343 ret = device_add(&hdev->dev);
41344diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41345index c13fb5b..55a3802 100644
41346--- a/drivers/hid/hid-wiimote-debug.c
41347+++ b/drivers/hid/hid-wiimote-debug.c
41348@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41349 else if (size == 0)
41350 return -EIO;
41351
41352- if (copy_to_user(u, buf, size))
41353+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41354 return -EFAULT;
41355
41356 *off += size;
41357diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41358index cedc6da..2c3da2a 100644
41359--- a/drivers/hid/uhid.c
41360+++ b/drivers/hid/uhid.c
41361@@ -47,7 +47,7 @@ struct uhid_device {
41362 struct mutex report_lock;
41363 wait_queue_head_t report_wait;
41364 atomic_t report_done;
41365- atomic_t report_id;
41366+ atomic_unchecked_t report_id;
41367 struct uhid_event report_buf;
41368 };
41369
41370@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41371
41372 spin_lock_irqsave(&uhid->qlock, flags);
41373 ev->type = UHID_FEATURE;
41374- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41375+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41376 ev->u.feature.rnum = rnum;
41377 ev->u.feature.rtype = report_type;
41378
41379@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41380 spin_lock_irqsave(&uhid->qlock, flags);
41381
41382 /* id for old report; drop it silently */
41383- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41384+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41385 goto unlock;
41386 if (atomic_read(&uhid->report_done))
41387 goto unlock;
41388diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41389index 69ea36f..8dbf4bb 100644
41390--- a/drivers/hv/channel.c
41391+++ b/drivers/hv/channel.c
41392@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41393 int ret = 0;
41394 int t;
41395
41396- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41397- atomic_inc(&vmbus_connection.next_gpadl_handle);
41398+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41399+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41400
41401 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41402 if (ret)
41403diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41404index bcb4950..61dba6c 100644
41405--- a/drivers/hv/hv.c
41406+++ b/drivers/hv/hv.c
41407@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41408 u64 output_address = (output) ? virt_to_phys(output) : 0;
41409 u32 output_address_hi = output_address >> 32;
41410 u32 output_address_lo = output_address & 0xFFFFFFFF;
41411- void *hypercall_page = hv_context.hypercall_page;
41412+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41413
41414 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41415 "=a"(hv_status_lo) : "d" (control_hi),
41416@@ -154,7 +154,7 @@ int hv_init(void)
41417 /* See if the hypercall page is already set */
41418 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41419
41420- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41421+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41422
41423 if (!virtaddr)
41424 goto cleanup;
41425diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41426index 7e17a54..a50a33d 100644
41427--- a/drivers/hv/hv_balloon.c
41428+++ b/drivers/hv/hv_balloon.c
41429@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41430
41431 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41432 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41433-static atomic_t trans_id = ATOMIC_INIT(0);
41434+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41435
41436 static int dm_ring_size = (5 * PAGE_SIZE);
41437
41438@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41439 pr_info("Memory hot add failed\n");
41440
41441 dm->state = DM_INITIALIZED;
41442- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41443+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41444 vmbus_sendpacket(dm->dev->channel, &resp,
41445 sizeof(struct dm_hot_add_response),
41446 (unsigned long)NULL,
41447@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41448 memset(&status, 0, sizeof(struct dm_status));
41449 status.hdr.type = DM_STATUS_REPORT;
41450 status.hdr.size = sizeof(struct dm_status);
41451- status.hdr.trans_id = atomic_inc_return(&trans_id);
41452+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41453
41454 /*
41455 * The host expects the guest to report free memory.
41456@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41457 * send the status. This can happen if we were interrupted
41458 * after we picked our transaction ID.
41459 */
41460- if (status.hdr.trans_id != atomic_read(&trans_id))
41461+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41462 return;
41463
41464 vmbus_sendpacket(dm->dev->channel, &status,
41465@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41466 */
41467
41468 do {
41469- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41470+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41471 ret = vmbus_sendpacket(dm_device.dev->channel,
41472 bl_resp,
41473 bl_resp->hdr.size,
41474@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41475
41476 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41477 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41478- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41479+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41480 resp.hdr.size = sizeof(struct dm_unballoon_response);
41481
41482 vmbus_sendpacket(dm_device.dev->channel, &resp,
41483@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41484 memset(&version_req, 0, sizeof(struct dm_version_request));
41485 version_req.hdr.type = DM_VERSION_REQUEST;
41486 version_req.hdr.size = sizeof(struct dm_version_request);
41487- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41488+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41489 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41490 version_req.is_last_attempt = 1;
41491
41492@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41493 memset(&version_req, 0, sizeof(struct dm_version_request));
41494 version_req.hdr.type = DM_VERSION_REQUEST;
41495 version_req.hdr.size = sizeof(struct dm_version_request);
41496- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41497+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41498 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41499 version_req.is_last_attempt = 0;
41500
41501@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41502 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41503 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41504 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41505- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41506+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41507
41508 cap_msg.caps.cap_bits.balloon = 1;
41509 cap_msg.caps.cap_bits.hot_add = 1;
41510diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41511index e055176..c22ff1f 100644
41512--- a/drivers/hv/hyperv_vmbus.h
41513+++ b/drivers/hv/hyperv_vmbus.h
41514@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41515 struct vmbus_connection {
41516 enum vmbus_connect_state conn_state;
41517
41518- atomic_t next_gpadl_handle;
41519+ atomic_unchecked_t next_gpadl_handle;
41520
41521 /*
41522 * Represents channel interrupts. Each bit position represents a
41523diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41524index 077bb1b..d433d74 100644
41525--- a/drivers/hv/vmbus_drv.c
41526+++ b/drivers/hv/vmbus_drv.c
41527@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41528 {
41529 int ret = 0;
41530
41531- static atomic_t device_num = ATOMIC_INIT(0);
41532+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41533
41534 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41535- atomic_inc_return(&device_num));
41536+ atomic_inc_return_unchecked(&device_num));
41537
41538 child_device_obj->device.bus = &hv_bus;
41539 child_device_obj->device.parent = &hv_acpi_dev->dev;
41540diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41541index 579bdf9..75118b5 100644
41542--- a/drivers/hwmon/acpi_power_meter.c
41543+++ b/drivers/hwmon/acpi_power_meter.c
41544@@ -116,7 +116,7 @@ struct sensor_template {
41545 struct device_attribute *devattr,
41546 const char *buf, size_t count);
41547 int index;
41548-};
41549+} __do_const;
41550
41551 /* Averaging interval */
41552 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41553@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41554 struct sensor_template *attrs)
41555 {
41556 struct device *dev = &resource->acpi_dev->dev;
41557- struct sensor_device_attribute *sensors =
41558+ sensor_device_attribute_no_const *sensors =
41559 &resource->sensors[resource->num_sensors];
41560 int res = 0;
41561
41562diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41563index 3288f13..71cfb4e 100644
41564--- a/drivers/hwmon/applesmc.c
41565+++ b/drivers/hwmon/applesmc.c
41566@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41567 {
41568 struct applesmc_node_group *grp;
41569 struct applesmc_dev_attr *node;
41570- struct attribute *attr;
41571+ attribute_no_const *attr;
41572 int ret, i;
41573
41574 for (grp = groups; grp->format; grp++) {
41575diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41576index ae208f6..48b6c5b 100644
41577--- a/drivers/hwmon/asus_atk0110.c
41578+++ b/drivers/hwmon/asus_atk0110.c
41579@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41580 struct atk_sensor_data {
41581 struct list_head list;
41582 struct atk_data *data;
41583- struct device_attribute label_attr;
41584- struct device_attribute input_attr;
41585- struct device_attribute limit1_attr;
41586- struct device_attribute limit2_attr;
41587+ device_attribute_no_const label_attr;
41588+ device_attribute_no_const input_attr;
41589+ device_attribute_no_const limit1_attr;
41590+ device_attribute_no_const limit2_attr;
41591 char label_attr_name[ATTR_NAME_SIZE];
41592 char input_attr_name[ATTR_NAME_SIZE];
41593 char limit1_attr_name[ATTR_NAME_SIZE];
41594@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41595 static struct device_attribute atk_name_attr =
41596 __ATTR(name, 0444, atk_name_show, NULL);
41597
41598-static void atk_init_attribute(struct device_attribute *attr, char *name,
41599+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41600 sysfs_show_func show)
41601 {
41602 sysfs_attr_init(&attr->attr);
41603diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41604index bbb0b0d..9fe1332 100644
41605--- a/drivers/hwmon/coretemp.c
41606+++ b/drivers/hwmon/coretemp.c
41607@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41608 return NOTIFY_OK;
41609 }
41610
41611-static struct notifier_block coretemp_cpu_notifier __refdata = {
41612+static struct notifier_block coretemp_cpu_notifier = {
41613 .notifier_call = coretemp_cpu_callback,
41614 };
41615
41616diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41617index 632f1dc..57e6a58 100644
41618--- a/drivers/hwmon/ibmaem.c
41619+++ b/drivers/hwmon/ibmaem.c
41620@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41621 struct aem_rw_sensor_template *rw)
41622 {
41623 struct device *dev = &data->pdev->dev;
41624- struct sensor_device_attribute *sensors = data->sensors;
41625+ sensor_device_attribute_no_const *sensors = data->sensors;
41626 int err;
41627
41628 /* Set up read-only sensors */
41629diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41630index 708081b..fe2d4ab 100644
41631--- a/drivers/hwmon/iio_hwmon.c
41632+++ b/drivers/hwmon/iio_hwmon.c
41633@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41634 {
41635 struct device *dev = &pdev->dev;
41636 struct iio_hwmon_state *st;
41637- struct sensor_device_attribute *a;
41638+ sensor_device_attribute_no_const *a;
41639 int ret, i;
41640 int in_i = 1, temp_i = 1, curr_i = 1;
41641 enum iio_chan_type type;
41642diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41643index 38d5a63..cf2c2ea 100644
41644--- a/drivers/hwmon/nct6775.c
41645+++ b/drivers/hwmon/nct6775.c
41646@@ -944,10 +944,10 @@ static struct attribute_group *
41647 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41648 int repeat)
41649 {
41650- struct attribute_group *group;
41651+ attribute_group_no_const *group;
41652 struct sensor_device_attr_u *su;
41653- struct sensor_device_attribute *a;
41654- struct sensor_device_attribute_2 *a2;
41655+ sensor_device_attribute_no_const *a;
41656+ sensor_device_attribute_2_no_const *a2;
41657 struct attribute **attrs;
41658 struct sensor_device_template **t;
41659 int i, count;
41660diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41661index 291d11f..3f0dbbd 100644
41662--- a/drivers/hwmon/pmbus/pmbus_core.c
41663+++ b/drivers/hwmon/pmbus/pmbus_core.c
41664@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41665 return 0;
41666 }
41667
41668-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41669+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41670 const char *name,
41671 umode_t mode,
41672 ssize_t (*show)(struct device *dev,
41673@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41674 dev_attr->store = store;
41675 }
41676
41677-static void pmbus_attr_init(struct sensor_device_attribute *a,
41678+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41679 const char *name,
41680 umode_t mode,
41681 ssize_t (*show)(struct device *dev,
41682@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41683 u16 reg, u8 mask)
41684 {
41685 struct pmbus_boolean *boolean;
41686- struct sensor_device_attribute *a;
41687+ sensor_device_attribute_no_const *a;
41688
41689 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41690 if (!boolean)
41691@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41692 bool update, bool readonly)
41693 {
41694 struct pmbus_sensor *sensor;
41695- struct device_attribute *a;
41696+ device_attribute_no_const *a;
41697
41698 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41699 if (!sensor)
41700@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41701 const char *lstring, int index)
41702 {
41703 struct pmbus_label *label;
41704- struct device_attribute *a;
41705+ device_attribute_no_const *a;
41706
41707 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41708 if (!label)
41709diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41710index 97cd45a..ac54d8b 100644
41711--- a/drivers/hwmon/sht15.c
41712+++ b/drivers/hwmon/sht15.c
41713@@ -169,7 +169,7 @@ struct sht15_data {
41714 int supply_uv;
41715 bool supply_uv_valid;
41716 struct work_struct update_supply_work;
41717- atomic_t interrupt_handled;
41718+ atomic_unchecked_t interrupt_handled;
41719 };
41720
41721 /**
41722@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41723 ret = gpio_direction_input(data->pdata->gpio_data);
41724 if (ret)
41725 return ret;
41726- atomic_set(&data->interrupt_handled, 0);
41727+ atomic_set_unchecked(&data->interrupt_handled, 0);
41728
41729 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41730 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41731 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41732 /* Only relevant if the interrupt hasn't occurred. */
41733- if (!atomic_read(&data->interrupt_handled))
41734+ if (!atomic_read_unchecked(&data->interrupt_handled))
41735 schedule_work(&data->read_work);
41736 }
41737 ret = wait_event_timeout(data->wait_queue,
41738@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41739
41740 /* First disable the interrupt */
41741 disable_irq_nosync(irq);
41742- atomic_inc(&data->interrupt_handled);
41743+ atomic_inc_unchecked(&data->interrupt_handled);
41744 /* Then schedule a reading work struct */
41745 if (data->state != SHT15_READING_NOTHING)
41746 schedule_work(&data->read_work);
41747@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41748 * If not, then start the interrupt again - care here as could
41749 * have gone low in meantime so verify it hasn't!
41750 */
41751- atomic_set(&data->interrupt_handled, 0);
41752+ atomic_set_unchecked(&data->interrupt_handled, 0);
41753 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41754 /* If still not occurred or another handler was scheduled */
41755 if (gpio_get_value(data->pdata->gpio_data)
41756- || atomic_read(&data->interrupt_handled))
41757+ || atomic_read_unchecked(&data->interrupt_handled))
41758 return;
41759 }
41760
41761diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41762index 38944e9..ae9e5ed 100644
41763--- a/drivers/hwmon/via-cputemp.c
41764+++ b/drivers/hwmon/via-cputemp.c
41765@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41766 return NOTIFY_OK;
41767 }
41768
41769-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41770+static struct notifier_block via_cputemp_cpu_notifier = {
41771 .notifier_call = via_cputemp_cpu_callback,
41772 };
41773
41774diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41775index 41fc683..a39cfea 100644
41776--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41777+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41778@@ -43,7 +43,7 @@
41779 extern struct i2c_adapter amd756_smbus;
41780
41781 static struct i2c_adapter *s4882_adapter;
41782-static struct i2c_algorithm *s4882_algo;
41783+static i2c_algorithm_no_const *s4882_algo;
41784
41785 /* Wrapper access functions for multiplexed SMBus */
41786 static DEFINE_MUTEX(amd756_lock);
41787diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41788index 721f7eb..0fd2a09 100644
41789--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41790+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41791@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41792 /* usb layer */
41793
41794 /* Send command to device, and get response. */
41795-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41796+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41797 {
41798 int ret = 0;
41799 int actual;
41800diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41801index b170bdf..3c76427 100644
41802--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41803+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41804@@ -41,7 +41,7 @@
41805 extern struct i2c_adapter *nforce2_smbus;
41806
41807 static struct i2c_adapter *s4985_adapter;
41808-static struct i2c_algorithm *s4985_algo;
41809+static i2c_algorithm_no_const *s4985_algo;
41810
41811 /* Wrapper access functions for multiplexed SMBus */
41812 static DEFINE_MUTEX(nforce2_lock);
41813diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41814index 80b47e8..1a6040d9 100644
41815--- a/drivers/i2c/i2c-dev.c
41816+++ b/drivers/i2c/i2c-dev.c
41817@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41818 break;
41819 }
41820
41821- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41822+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41823 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41824 if (IS_ERR(rdwr_pa[i].buf)) {
41825 res = PTR_ERR(rdwr_pa[i].buf);
41826diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41827index 0b510ba..4fbb5085 100644
41828--- a/drivers/ide/ide-cd.c
41829+++ b/drivers/ide/ide-cd.c
41830@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41831 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41832 if ((unsigned long)buf & alignment
41833 || blk_rq_bytes(rq) & q->dma_pad_mask
41834- || object_is_on_stack(buf))
41835+ || object_starts_on_stack(buf))
41836 drive->dma = 0;
41837 }
41838 }
41839diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41840index acc911a..8700c3c 100644
41841--- a/drivers/iio/industrialio-core.c
41842+++ b/drivers/iio/industrialio-core.c
41843@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41844 }
41845
41846 static
41847-int __iio_device_attr_init(struct device_attribute *dev_attr,
41848+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41849 const char *postfix,
41850 struct iio_chan_spec const *chan,
41851 ssize_t (*readfunc)(struct device *dev,
41852diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41853index c323917..6ddea8b 100644
41854--- a/drivers/infiniband/core/cm.c
41855+++ b/drivers/infiniband/core/cm.c
41856@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41857
41858 struct cm_counter_group {
41859 struct kobject obj;
41860- atomic_long_t counter[CM_ATTR_COUNT];
41861+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41862 };
41863
41864 struct cm_counter_attribute {
41865@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41866 struct ib_mad_send_buf *msg = NULL;
41867 int ret;
41868
41869- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41870+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41871 counter[CM_REQ_COUNTER]);
41872
41873 /* Quick state check to discard duplicate REQs. */
41874@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41875 if (!cm_id_priv)
41876 return;
41877
41878- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41879+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41880 counter[CM_REP_COUNTER]);
41881 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41882 if (ret)
41883@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41884 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41885 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41886 spin_unlock_irq(&cm_id_priv->lock);
41887- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41888+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41889 counter[CM_RTU_COUNTER]);
41890 goto out;
41891 }
41892@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
41893 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41894 dreq_msg->local_comm_id);
41895 if (!cm_id_priv) {
41896- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41897+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41898 counter[CM_DREQ_COUNTER]);
41899 cm_issue_drep(work->port, work->mad_recv_wc);
41900 return -EINVAL;
41901@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
41902 case IB_CM_MRA_REP_RCVD:
41903 break;
41904 case IB_CM_TIMEWAIT:
41905- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41906+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41907 counter[CM_DREQ_COUNTER]);
41908 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41909 goto unlock;
41910@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
41911 cm_free_msg(msg);
41912 goto deref;
41913 case IB_CM_DREQ_RCVD:
41914- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41915+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41916 counter[CM_DREQ_COUNTER]);
41917 goto unlock;
41918 default:
41919@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41920 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41921 cm_id_priv->msg, timeout)) {
41922 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41923- atomic_long_inc(&work->port->
41924+ atomic_long_inc_unchecked(&work->port->
41925 counter_group[CM_RECV_DUPLICATES].
41926 counter[CM_MRA_COUNTER]);
41927 goto out;
41928@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
41929 break;
41930 case IB_CM_MRA_REQ_RCVD:
41931 case IB_CM_MRA_REP_RCVD:
41932- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41933+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41934 counter[CM_MRA_COUNTER]);
41935 /* fall through */
41936 default:
41937@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
41938 case IB_CM_LAP_IDLE:
41939 break;
41940 case IB_CM_MRA_LAP_SENT:
41941- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41942+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41943 counter[CM_LAP_COUNTER]);
41944 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41945 goto unlock;
41946@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
41947 cm_free_msg(msg);
41948 goto deref;
41949 case IB_CM_LAP_RCVD:
41950- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41951+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41952 counter[CM_LAP_COUNTER]);
41953 goto unlock;
41954 default:
41955@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41956 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41957 if (cur_cm_id_priv) {
41958 spin_unlock_irq(&cm.lock);
41959- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41960+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41961 counter[CM_SIDR_REQ_COUNTER]);
41962 goto out; /* Duplicate message. */
41963 }
41964@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41965 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41966 msg->retries = 1;
41967
41968- atomic_long_add(1 + msg->retries,
41969+ atomic_long_add_unchecked(1 + msg->retries,
41970 &port->counter_group[CM_XMIT].counter[attr_index]);
41971 if (msg->retries)
41972- atomic_long_add(msg->retries,
41973+ atomic_long_add_unchecked(msg->retries,
41974 &port->counter_group[CM_XMIT_RETRIES].
41975 counter[attr_index]);
41976
41977@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41978 }
41979
41980 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41981- atomic_long_inc(&port->counter_group[CM_RECV].
41982+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41983 counter[attr_id - CM_ATTR_ID_OFFSET]);
41984
41985 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41986@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41987 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41988
41989 return sprintf(buf, "%ld\n",
41990- atomic_long_read(&group->counter[cm_attr->index]));
41991+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41992 }
41993
41994 static const struct sysfs_ops cm_counter_ops = {
41995diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41996index 9f5ad7c..588cd84 100644
41997--- a/drivers/infiniband/core/fmr_pool.c
41998+++ b/drivers/infiniband/core/fmr_pool.c
41999@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42000
42001 struct task_struct *thread;
42002
42003- atomic_t req_ser;
42004- atomic_t flush_ser;
42005+ atomic_unchecked_t req_ser;
42006+ atomic_unchecked_t flush_ser;
42007
42008 wait_queue_head_t force_wait;
42009 };
42010@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42011 struct ib_fmr_pool *pool = pool_ptr;
42012
42013 do {
42014- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42015+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42016 ib_fmr_batch_release(pool);
42017
42018- atomic_inc(&pool->flush_ser);
42019+ atomic_inc_unchecked(&pool->flush_ser);
42020 wake_up_interruptible(&pool->force_wait);
42021
42022 if (pool->flush_function)
42023@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42024 }
42025
42026 set_current_state(TASK_INTERRUPTIBLE);
42027- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42028+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42029 !kthread_should_stop())
42030 schedule();
42031 __set_current_state(TASK_RUNNING);
42032@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42033 pool->dirty_watermark = params->dirty_watermark;
42034 pool->dirty_len = 0;
42035 spin_lock_init(&pool->pool_lock);
42036- atomic_set(&pool->req_ser, 0);
42037- atomic_set(&pool->flush_ser, 0);
42038+ atomic_set_unchecked(&pool->req_ser, 0);
42039+ atomic_set_unchecked(&pool->flush_ser, 0);
42040 init_waitqueue_head(&pool->force_wait);
42041
42042 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42043@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42044 }
42045 spin_unlock_irq(&pool->pool_lock);
42046
42047- serial = atomic_inc_return(&pool->req_ser);
42048+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42049 wake_up_process(pool->thread);
42050
42051 if (wait_event_interruptible(pool->force_wait,
42052- atomic_read(&pool->flush_ser) - serial >= 0))
42053+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42054 return -EINTR;
42055
42056 return 0;
42057@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42058 } else {
42059 list_add_tail(&fmr->list, &pool->dirty_list);
42060 if (++pool->dirty_len >= pool->dirty_watermark) {
42061- atomic_inc(&pool->req_ser);
42062+ atomic_inc_unchecked(&pool->req_ser);
42063 wake_up_process(pool->thread);
42064 }
42065 }
42066diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42067index 41b1195..27971a0 100644
42068--- a/drivers/infiniband/hw/cxgb4/mem.c
42069+++ b/drivers/infiniband/hw/cxgb4/mem.c
42070@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42071 int err;
42072 struct fw_ri_tpte tpt;
42073 u32 stag_idx;
42074- static atomic_t key;
42075+ static atomic_unchecked_t key;
42076
42077 if (c4iw_fatal_error(rdev))
42078 return -EIO;
42079@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42080 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42081 rdev->stats.stag.max = rdev->stats.stag.cur;
42082 mutex_unlock(&rdev->stats.lock);
42083- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42084+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42085 }
42086 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42087 __func__, stag_state, type, pdid, stag_idx);
42088diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42089index 644c2c7..ecf0879 100644
42090--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42091+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42092@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42093 }
42094
42095 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42096- ipath_mapping_error,
42097- ipath_dma_map_single,
42098- ipath_dma_unmap_single,
42099- ipath_dma_map_page,
42100- ipath_dma_unmap_page,
42101- ipath_map_sg,
42102- ipath_unmap_sg,
42103- ipath_sg_dma_address,
42104- ipath_sg_dma_len,
42105- ipath_sync_single_for_cpu,
42106- ipath_sync_single_for_device,
42107- ipath_dma_alloc_coherent,
42108- ipath_dma_free_coherent
42109+ .mapping_error = ipath_mapping_error,
42110+ .map_single = ipath_dma_map_single,
42111+ .unmap_single = ipath_dma_unmap_single,
42112+ .map_page = ipath_dma_map_page,
42113+ .unmap_page = ipath_dma_unmap_page,
42114+ .map_sg = ipath_map_sg,
42115+ .unmap_sg = ipath_unmap_sg,
42116+ .dma_address = ipath_sg_dma_address,
42117+ .dma_len = ipath_sg_dma_len,
42118+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42119+ .sync_single_for_device = ipath_sync_single_for_device,
42120+ .alloc_coherent = ipath_dma_alloc_coherent,
42121+ .free_coherent = ipath_dma_free_coherent
42122 };
42123diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42124index 79b3dbc..96e5fcc 100644
42125--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42126+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42127@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42128 struct ib_atomic_eth *ateth;
42129 struct ipath_ack_entry *e;
42130 u64 vaddr;
42131- atomic64_t *maddr;
42132+ atomic64_unchecked_t *maddr;
42133 u64 sdata;
42134 u32 rkey;
42135 u8 next;
42136@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42137 IB_ACCESS_REMOTE_ATOMIC)))
42138 goto nack_acc_unlck;
42139 /* Perform atomic OP and save result. */
42140- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42141+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42142 sdata = be64_to_cpu(ateth->swap_data);
42143 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42144 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42145- (u64) atomic64_add_return(sdata, maddr) - sdata :
42146+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42147 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42148 be64_to_cpu(ateth->compare_data),
42149 sdata);
42150diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42151index 1f95bba..9530f87 100644
42152--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42153+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42154@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42155 unsigned long flags;
42156 struct ib_wc wc;
42157 u64 sdata;
42158- atomic64_t *maddr;
42159+ atomic64_unchecked_t *maddr;
42160 enum ib_wc_status send_status;
42161
42162 /*
42163@@ -382,11 +382,11 @@ again:
42164 IB_ACCESS_REMOTE_ATOMIC)))
42165 goto acc_err;
42166 /* Perform atomic OP and save result. */
42167- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42168+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42169 sdata = wqe->wr.wr.atomic.compare_add;
42170 *(u64 *) sqp->s_sge.sge.vaddr =
42171 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42172- (u64) atomic64_add_return(sdata, maddr) - sdata :
42173+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42174 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42175 sdata, wqe->wr.wr.atomic.swap);
42176 goto send_comp;
42177diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42178index f2a3f48..673ec79 100644
42179--- a/drivers/infiniband/hw/mlx4/mad.c
42180+++ b/drivers/infiniband/hw/mlx4/mad.c
42181@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42182
42183 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42184 {
42185- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42186+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42187 cpu_to_be64(0xff00000000000000LL);
42188 }
42189
42190diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42191index 25b2cdf..099ff97 100644
42192--- a/drivers/infiniband/hw/mlx4/mcg.c
42193+++ b/drivers/infiniband/hw/mlx4/mcg.c
42194@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42195 {
42196 char name[20];
42197
42198- atomic_set(&ctx->tid, 0);
42199+ atomic_set_unchecked(&ctx->tid, 0);
42200 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42201 ctx->mcg_wq = create_singlethread_workqueue(name);
42202 if (!ctx->mcg_wq)
42203diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42204index a230683..3723f2d 100644
42205--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42206+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42207@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42208 struct list_head mcg_mgid0_list;
42209 struct workqueue_struct *mcg_wq;
42210 struct mlx4_ib_demux_pv_ctx **tun;
42211- atomic_t tid;
42212+ atomic_unchecked_t tid;
42213 int flushing; /* flushing the work queue */
42214 };
42215
42216diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42217index 9d3e5c1..6f166df 100644
42218--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42219+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42220@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42221 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42222 }
42223
42224-int mthca_QUERY_FW(struct mthca_dev *dev)
42225+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42226 {
42227 struct mthca_mailbox *mailbox;
42228 u32 *outbox;
42229@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42230 CMD_TIME_CLASS_B);
42231 }
42232
42233-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42234+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42235 int num_mtt)
42236 {
42237 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42238@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42239 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42240 }
42241
42242-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42243+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42244 int eq_num)
42245 {
42246 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42247@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42248 CMD_TIME_CLASS_B);
42249 }
42250
42251-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42252+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42253 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42254 void *in_mad, void *response_mad)
42255 {
42256diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42257index 87897b9..7e79542 100644
42258--- a/drivers/infiniband/hw/mthca/mthca_main.c
42259+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42260@@ -692,7 +692,7 @@ err_close:
42261 return err;
42262 }
42263
42264-static int mthca_setup_hca(struct mthca_dev *dev)
42265+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42266 {
42267 int err;
42268
42269diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42270index ed9a989..6aa5dc2 100644
42271--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42272+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42273@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42274 * through the bitmaps)
42275 */
42276
42277-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42278+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42279 {
42280 int o;
42281 int m;
42282@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42283 return key;
42284 }
42285
42286-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42287+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42288 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42289 {
42290 struct mthca_mailbox *mailbox;
42291@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42292 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42293 }
42294
42295-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42296+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42297 u64 *buffer_list, int buffer_size_shift,
42298 int list_len, u64 iova, u64 total_size,
42299 u32 access, struct mthca_mr *mr)
42300diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42301index 42dde06..1257310 100644
42302--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42303+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42304@@ -764,7 +764,7 @@ unlock:
42305 return 0;
42306 }
42307
42308-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42309+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42310 {
42311 struct mthca_dev *dev = to_mdev(ibcq->device);
42312 struct mthca_cq *cq = to_mcq(ibcq);
42313diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42314index 353c7b0..c6ce921 100644
42315--- a/drivers/infiniband/hw/nes/nes.c
42316+++ b/drivers/infiniband/hw/nes/nes.c
42317@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42318 LIST_HEAD(nes_adapter_list);
42319 static LIST_HEAD(nes_dev_list);
42320
42321-atomic_t qps_destroyed;
42322+atomic_unchecked_t qps_destroyed;
42323
42324 static unsigned int ee_flsh_adapter;
42325 static unsigned int sysfs_nonidx_addr;
42326@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42327 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42328 struct nes_adapter *nesadapter = nesdev->nesadapter;
42329
42330- atomic_inc(&qps_destroyed);
42331+ atomic_inc_unchecked(&qps_destroyed);
42332
42333 /* Free the control structures */
42334
42335diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42336index 33cc589..3bd6538 100644
42337--- a/drivers/infiniband/hw/nes/nes.h
42338+++ b/drivers/infiniband/hw/nes/nes.h
42339@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42340 extern unsigned int wqm_quanta;
42341 extern struct list_head nes_adapter_list;
42342
42343-extern atomic_t cm_connects;
42344-extern atomic_t cm_accepts;
42345-extern atomic_t cm_disconnects;
42346-extern atomic_t cm_closes;
42347-extern atomic_t cm_connecteds;
42348-extern atomic_t cm_connect_reqs;
42349-extern atomic_t cm_rejects;
42350-extern atomic_t mod_qp_timouts;
42351-extern atomic_t qps_created;
42352-extern atomic_t qps_destroyed;
42353-extern atomic_t sw_qps_destroyed;
42354+extern atomic_unchecked_t cm_connects;
42355+extern atomic_unchecked_t cm_accepts;
42356+extern atomic_unchecked_t cm_disconnects;
42357+extern atomic_unchecked_t cm_closes;
42358+extern atomic_unchecked_t cm_connecteds;
42359+extern atomic_unchecked_t cm_connect_reqs;
42360+extern atomic_unchecked_t cm_rejects;
42361+extern atomic_unchecked_t mod_qp_timouts;
42362+extern atomic_unchecked_t qps_created;
42363+extern atomic_unchecked_t qps_destroyed;
42364+extern atomic_unchecked_t sw_qps_destroyed;
42365 extern u32 mh_detected;
42366 extern u32 mh_pauses_sent;
42367 extern u32 cm_packets_sent;
42368@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42369 extern u32 cm_packets_received;
42370 extern u32 cm_packets_dropped;
42371 extern u32 cm_packets_retrans;
42372-extern atomic_t cm_listens_created;
42373-extern atomic_t cm_listens_destroyed;
42374+extern atomic_unchecked_t cm_listens_created;
42375+extern atomic_unchecked_t cm_listens_destroyed;
42376 extern u32 cm_backlog_drops;
42377-extern atomic_t cm_loopbacks;
42378-extern atomic_t cm_nodes_created;
42379-extern atomic_t cm_nodes_destroyed;
42380-extern atomic_t cm_accel_dropped_pkts;
42381-extern atomic_t cm_resets_recvd;
42382-extern atomic_t pau_qps_created;
42383-extern atomic_t pau_qps_destroyed;
42384+extern atomic_unchecked_t cm_loopbacks;
42385+extern atomic_unchecked_t cm_nodes_created;
42386+extern atomic_unchecked_t cm_nodes_destroyed;
42387+extern atomic_unchecked_t cm_accel_dropped_pkts;
42388+extern atomic_unchecked_t cm_resets_recvd;
42389+extern atomic_unchecked_t pau_qps_created;
42390+extern atomic_unchecked_t pau_qps_destroyed;
42391
42392 extern u32 int_mod_timer_init;
42393 extern u32 int_mod_cq_depth_256;
42394diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42395index 9c9f2f5..2559190 100644
42396--- a/drivers/infiniband/hw/nes/nes_cm.c
42397+++ b/drivers/infiniband/hw/nes/nes_cm.c
42398@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42399 u32 cm_packets_retrans;
42400 u32 cm_packets_created;
42401 u32 cm_packets_received;
42402-atomic_t cm_listens_created;
42403-atomic_t cm_listens_destroyed;
42404+atomic_unchecked_t cm_listens_created;
42405+atomic_unchecked_t cm_listens_destroyed;
42406 u32 cm_backlog_drops;
42407-atomic_t cm_loopbacks;
42408-atomic_t cm_nodes_created;
42409-atomic_t cm_nodes_destroyed;
42410-atomic_t cm_accel_dropped_pkts;
42411-atomic_t cm_resets_recvd;
42412+atomic_unchecked_t cm_loopbacks;
42413+atomic_unchecked_t cm_nodes_created;
42414+atomic_unchecked_t cm_nodes_destroyed;
42415+atomic_unchecked_t cm_accel_dropped_pkts;
42416+atomic_unchecked_t cm_resets_recvd;
42417
42418 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42419 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42420@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42421 /* instance of function pointers for client API */
42422 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42423 static struct nes_cm_ops nes_cm_api = {
42424- mini_cm_accelerated,
42425- mini_cm_listen,
42426- mini_cm_del_listen,
42427- mini_cm_connect,
42428- mini_cm_close,
42429- mini_cm_accept,
42430- mini_cm_reject,
42431- mini_cm_recv_pkt,
42432- mini_cm_dealloc_core,
42433- mini_cm_get,
42434- mini_cm_set
42435+ .accelerated = mini_cm_accelerated,
42436+ .listen = mini_cm_listen,
42437+ .stop_listener = mini_cm_del_listen,
42438+ .connect = mini_cm_connect,
42439+ .close = mini_cm_close,
42440+ .accept = mini_cm_accept,
42441+ .reject = mini_cm_reject,
42442+ .recv_pkt = mini_cm_recv_pkt,
42443+ .destroy_cm_core = mini_cm_dealloc_core,
42444+ .get = mini_cm_get,
42445+ .set = mini_cm_set
42446 };
42447
42448 static struct nes_cm_core *g_cm_core;
42449
42450-atomic_t cm_connects;
42451-atomic_t cm_accepts;
42452-atomic_t cm_disconnects;
42453-atomic_t cm_closes;
42454-atomic_t cm_connecteds;
42455-atomic_t cm_connect_reqs;
42456-atomic_t cm_rejects;
42457+atomic_unchecked_t cm_connects;
42458+atomic_unchecked_t cm_accepts;
42459+atomic_unchecked_t cm_disconnects;
42460+atomic_unchecked_t cm_closes;
42461+atomic_unchecked_t cm_connecteds;
42462+atomic_unchecked_t cm_connect_reqs;
42463+atomic_unchecked_t cm_rejects;
42464
42465 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42466 {
42467@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42468 kfree(listener);
42469 listener = NULL;
42470 ret = 0;
42471- atomic_inc(&cm_listens_destroyed);
42472+ atomic_inc_unchecked(&cm_listens_destroyed);
42473 } else {
42474 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42475 }
42476@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42477 cm_node->rem_mac);
42478
42479 add_hte_node(cm_core, cm_node);
42480- atomic_inc(&cm_nodes_created);
42481+ atomic_inc_unchecked(&cm_nodes_created);
42482
42483 return cm_node;
42484 }
42485@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42486 }
42487
42488 atomic_dec(&cm_core->node_cnt);
42489- atomic_inc(&cm_nodes_destroyed);
42490+ atomic_inc_unchecked(&cm_nodes_destroyed);
42491 nesqp = cm_node->nesqp;
42492 if (nesqp) {
42493 nesqp->cm_node = NULL;
42494@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42495
42496 static void drop_packet(struct sk_buff *skb)
42497 {
42498- atomic_inc(&cm_accel_dropped_pkts);
42499+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42500 dev_kfree_skb_any(skb);
42501 }
42502
42503@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42504 {
42505
42506 int reset = 0; /* whether to send reset in case of err.. */
42507- atomic_inc(&cm_resets_recvd);
42508+ atomic_inc_unchecked(&cm_resets_recvd);
42509 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42510 " refcnt=%d\n", cm_node, cm_node->state,
42511 atomic_read(&cm_node->ref_count));
42512@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42513 rem_ref_cm_node(cm_node->cm_core, cm_node);
42514 return NULL;
42515 }
42516- atomic_inc(&cm_loopbacks);
42517+ atomic_inc_unchecked(&cm_loopbacks);
42518 loopbackremotenode->loopbackpartner = cm_node;
42519 loopbackremotenode->tcp_cntxt.rcv_wscale =
42520 NES_CM_DEFAULT_RCV_WND_SCALE;
42521@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42522 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42523 else {
42524 rem_ref_cm_node(cm_core, cm_node);
42525- atomic_inc(&cm_accel_dropped_pkts);
42526+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42527 dev_kfree_skb_any(skb);
42528 }
42529 break;
42530@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42531
42532 if ((cm_id) && (cm_id->event_handler)) {
42533 if (issue_disconn) {
42534- atomic_inc(&cm_disconnects);
42535+ atomic_inc_unchecked(&cm_disconnects);
42536 cm_event.event = IW_CM_EVENT_DISCONNECT;
42537 cm_event.status = disconn_status;
42538 cm_event.local_addr = cm_id->local_addr;
42539@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42540 }
42541
42542 if (issue_close) {
42543- atomic_inc(&cm_closes);
42544+ atomic_inc_unchecked(&cm_closes);
42545 nes_disconnect(nesqp, 1);
42546
42547 cm_id->provider_data = nesqp;
42548@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42549
42550 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42551 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42552- atomic_inc(&cm_accepts);
42553+ atomic_inc_unchecked(&cm_accepts);
42554
42555 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42556 netdev_refcnt_read(nesvnic->netdev));
42557@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42558 struct nes_cm_core *cm_core;
42559 u8 *start_buff;
42560
42561- atomic_inc(&cm_rejects);
42562+ atomic_inc_unchecked(&cm_rejects);
42563 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42564 loopback = cm_node->loopbackpartner;
42565 cm_core = cm_node->cm_core;
42566@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42567 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42568 ntohs(laddr->sin_port));
42569
42570- atomic_inc(&cm_connects);
42571+ atomic_inc_unchecked(&cm_connects);
42572 nesqp->active_conn = 1;
42573
42574 /* cache the cm_id in the qp */
42575@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42576 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42577 return err;
42578 }
42579- atomic_inc(&cm_listens_created);
42580+ atomic_inc_unchecked(&cm_listens_created);
42581 }
42582
42583 cm_id->add_ref(cm_id);
42584@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42585
42586 if (nesqp->destroyed)
42587 return;
42588- atomic_inc(&cm_connecteds);
42589+ atomic_inc_unchecked(&cm_connecteds);
42590 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42591 " local port 0x%04X. jiffies = %lu.\n",
42592 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42593@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42594
42595 cm_id->add_ref(cm_id);
42596 ret = cm_id->event_handler(cm_id, &cm_event);
42597- atomic_inc(&cm_closes);
42598+ atomic_inc_unchecked(&cm_closes);
42599 cm_event.event = IW_CM_EVENT_CLOSE;
42600 cm_event.status = 0;
42601 cm_event.provider_data = cm_id->provider_data;
42602@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42603 return;
42604 cm_id = cm_node->cm_id;
42605
42606- atomic_inc(&cm_connect_reqs);
42607+ atomic_inc_unchecked(&cm_connect_reqs);
42608 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42609 cm_node, cm_id, jiffies);
42610
42611@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42612 return;
42613 cm_id = cm_node->cm_id;
42614
42615- atomic_inc(&cm_connect_reqs);
42616+ atomic_inc_unchecked(&cm_connect_reqs);
42617 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42618 cm_node, cm_id, jiffies);
42619
42620diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42621index 4166452..fc952c3 100644
42622--- a/drivers/infiniband/hw/nes/nes_mgt.c
42623+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42624@@ -40,8 +40,8 @@
42625 #include "nes.h"
42626 #include "nes_mgt.h"
42627
42628-atomic_t pau_qps_created;
42629-atomic_t pau_qps_destroyed;
42630+atomic_unchecked_t pau_qps_created;
42631+atomic_unchecked_t pau_qps_destroyed;
42632
42633 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42634 {
42635@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42636 {
42637 struct sk_buff *skb;
42638 unsigned long flags;
42639- atomic_inc(&pau_qps_destroyed);
42640+ atomic_inc_unchecked(&pau_qps_destroyed);
42641
42642 /* Free packets that have not yet been forwarded */
42643 /* Lock is acquired by skb_dequeue when removing the skb */
42644@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42645 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42646 skb_queue_head_init(&nesqp->pau_list);
42647 spin_lock_init(&nesqp->pau_lock);
42648- atomic_inc(&pau_qps_created);
42649+ atomic_inc_unchecked(&pau_qps_created);
42650 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42651 }
42652
42653diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42654index 49eb511..a774366 100644
42655--- a/drivers/infiniband/hw/nes/nes_nic.c
42656+++ b/drivers/infiniband/hw/nes/nes_nic.c
42657@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42658 target_stat_values[++index] = mh_detected;
42659 target_stat_values[++index] = mh_pauses_sent;
42660 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42661- target_stat_values[++index] = atomic_read(&cm_connects);
42662- target_stat_values[++index] = atomic_read(&cm_accepts);
42663- target_stat_values[++index] = atomic_read(&cm_disconnects);
42664- target_stat_values[++index] = atomic_read(&cm_connecteds);
42665- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42666- target_stat_values[++index] = atomic_read(&cm_rejects);
42667- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42668- target_stat_values[++index] = atomic_read(&qps_created);
42669- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42670- target_stat_values[++index] = atomic_read(&qps_destroyed);
42671- target_stat_values[++index] = atomic_read(&cm_closes);
42672+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42673+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42674+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42675+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42676+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42677+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42678+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42679+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42680+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42681+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42682+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42683 target_stat_values[++index] = cm_packets_sent;
42684 target_stat_values[++index] = cm_packets_bounced;
42685 target_stat_values[++index] = cm_packets_created;
42686 target_stat_values[++index] = cm_packets_received;
42687 target_stat_values[++index] = cm_packets_dropped;
42688 target_stat_values[++index] = cm_packets_retrans;
42689- target_stat_values[++index] = atomic_read(&cm_listens_created);
42690- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42691+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42692+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42693 target_stat_values[++index] = cm_backlog_drops;
42694- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42695- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42696- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42697- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42698- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42699+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42700+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42701+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42702+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42703+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42704 target_stat_values[++index] = nesadapter->free_4kpbl;
42705 target_stat_values[++index] = nesadapter->free_256pbl;
42706 target_stat_values[++index] = int_mod_timer_init;
42707 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42708 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42709 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42710- target_stat_values[++index] = atomic_read(&pau_qps_created);
42711- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42712+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42713+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42714 }
42715
42716 /**
42717diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42718index eb62461..2b7fc71 100644
42719--- a/drivers/infiniband/hw/nes/nes_verbs.c
42720+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42721@@ -46,9 +46,9 @@
42722
42723 #include <rdma/ib_umem.h>
42724
42725-atomic_t mod_qp_timouts;
42726-atomic_t qps_created;
42727-atomic_t sw_qps_destroyed;
42728+atomic_unchecked_t mod_qp_timouts;
42729+atomic_unchecked_t qps_created;
42730+atomic_unchecked_t sw_qps_destroyed;
42731
42732 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42733
42734@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42735 if (init_attr->create_flags)
42736 return ERR_PTR(-EINVAL);
42737
42738- atomic_inc(&qps_created);
42739+ atomic_inc_unchecked(&qps_created);
42740 switch (init_attr->qp_type) {
42741 case IB_QPT_RC:
42742 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42743@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42744 struct iw_cm_event cm_event;
42745 int ret = 0;
42746
42747- atomic_inc(&sw_qps_destroyed);
42748+ atomic_inc_unchecked(&sw_qps_destroyed);
42749 nesqp->destroyed = 1;
42750
42751 /* Blow away the connection if it exists. */
42752diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42753index 1946101..09766d2 100644
42754--- a/drivers/infiniband/hw/qib/qib.h
42755+++ b/drivers/infiniband/hw/qib/qib.h
42756@@ -52,6 +52,7 @@
42757 #include <linux/kref.h>
42758 #include <linux/sched.h>
42759 #include <linux/kthread.h>
42760+#include <linux/slab.h>
42761
42762 #include "qib_common.h"
42763 #include "qib_verbs.h"
42764diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42765index 24c41ba..102d71f 100644
42766--- a/drivers/input/gameport/gameport.c
42767+++ b/drivers/input/gameport/gameport.c
42768@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42769 */
42770 static void gameport_init_port(struct gameport *gameport)
42771 {
42772- static atomic_t gameport_no = ATOMIC_INIT(0);
42773+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42774
42775 __module_get(THIS_MODULE);
42776
42777 mutex_init(&gameport->drv_mutex);
42778 device_initialize(&gameport->dev);
42779 dev_set_name(&gameport->dev, "gameport%lu",
42780- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42781+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42782 gameport->dev.bus = &gameport_bus;
42783 gameport->dev.release = gameport_release_port;
42784 if (gameport->parent)
42785diff --git a/drivers/input/input.c b/drivers/input/input.c
42786index 1c4c0db..6f7abe3 100644
42787--- a/drivers/input/input.c
42788+++ b/drivers/input/input.c
42789@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42790 */
42791 struct input_dev *input_allocate_device(void)
42792 {
42793- static atomic_t input_no = ATOMIC_INIT(0);
42794+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42795 struct input_dev *dev;
42796
42797 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42798@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42799 INIT_LIST_HEAD(&dev->node);
42800
42801 dev_set_name(&dev->dev, "input%ld",
42802- (unsigned long) atomic_inc_return(&input_no) - 1);
42803+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42804
42805 __module_get(THIS_MODULE);
42806 }
42807diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42808index 4a95b22..874c182 100644
42809--- a/drivers/input/joystick/sidewinder.c
42810+++ b/drivers/input/joystick/sidewinder.c
42811@@ -30,6 +30,7 @@
42812 #include <linux/kernel.h>
42813 #include <linux/module.h>
42814 #include <linux/slab.h>
42815+#include <linux/sched.h>
42816 #include <linux/input.h>
42817 #include <linux/gameport.h>
42818 #include <linux/jiffies.h>
42819diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42820index 603fe0d..f63decc 100644
42821--- a/drivers/input/joystick/xpad.c
42822+++ b/drivers/input/joystick/xpad.c
42823@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42824
42825 static int xpad_led_probe(struct usb_xpad *xpad)
42826 {
42827- static atomic_t led_seq = ATOMIC_INIT(0);
42828+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42829 long led_no;
42830 struct xpad_led *led;
42831 struct led_classdev *led_cdev;
42832@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42833 if (!led)
42834 return -ENOMEM;
42835
42836- led_no = (long)atomic_inc_return(&led_seq) - 1;
42837+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42838
42839 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42840 led->xpad = xpad;
42841diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42842index e204f26..8459f15 100644
42843--- a/drivers/input/misc/ims-pcu.c
42844+++ b/drivers/input/misc/ims-pcu.c
42845@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42846
42847 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42848 {
42849- static atomic_t device_no = ATOMIC_INIT(0);
42850+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42851
42852 const struct ims_pcu_device_info *info;
42853 u8 device_id;
42854@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42855 }
42856
42857 /* Device appears to be operable, complete initialization */
42858- pcu->device_no = atomic_inc_return(&device_no) - 1;
42859+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42860
42861 error = ims_pcu_setup_backlight(pcu);
42862 if (error)
42863diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42864index 2f0b39d..7370f13 100644
42865--- a/drivers/input/mouse/psmouse.h
42866+++ b/drivers/input/mouse/psmouse.h
42867@@ -116,7 +116,7 @@ struct psmouse_attribute {
42868 ssize_t (*set)(struct psmouse *psmouse, void *data,
42869 const char *buf, size_t count);
42870 bool protect;
42871-};
42872+} __do_const;
42873 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42874
42875 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42876diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42877index b604564..3f14ae4 100644
42878--- a/drivers/input/mousedev.c
42879+++ b/drivers/input/mousedev.c
42880@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42881
42882 spin_unlock_irq(&client->packet_lock);
42883
42884- if (copy_to_user(buffer, data, count))
42885+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42886 return -EFAULT;
42887
42888 return count;
42889diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42890index 8f4c4ab..5fc8a45 100644
42891--- a/drivers/input/serio/serio.c
42892+++ b/drivers/input/serio/serio.c
42893@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42894 */
42895 static void serio_init_port(struct serio *serio)
42896 {
42897- static atomic_t serio_no = ATOMIC_INIT(0);
42898+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42899
42900 __module_get(THIS_MODULE);
42901
42902@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42903 mutex_init(&serio->drv_mutex);
42904 device_initialize(&serio->dev);
42905 dev_set_name(&serio->dev, "serio%ld",
42906- (long)atomic_inc_return(&serio_no) - 1);
42907+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42908 serio->dev.bus = &serio_bus;
42909 serio->dev.release = serio_release_port;
42910 serio->dev.groups = serio_device_attr_groups;
42911diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42912index c9a02fe..0debc75 100644
42913--- a/drivers/input/serio/serio_raw.c
42914+++ b/drivers/input/serio/serio_raw.c
42915@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42916
42917 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42918 {
42919- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42920+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42921 struct serio_raw *serio_raw;
42922 int err;
42923
42924@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42925 }
42926
42927 snprintf(serio_raw->name, sizeof(serio_raw->name),
42928- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42929+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42930 kref_init(&serio_raw->kref);
42931 INIT_LIST_HEAD(&serio_raw->client_list);
42932 init_waitqueue_head(&serio_raw->wait);
42933diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42934index e5555fc..937986d 100644
42935--- a/drivers/iommu/iommu.c
42936+++ b/drivers/iommu/iommu.c
42937@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42938 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42939 {
42940 bus_register_notifier(bus, &iommu_bus_nb);
42941- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42942+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42943 }
42944
42945 /**
42946diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42947index 228632c9..edfe331 100644
42948--- a/drivers/iommu/irq_remapping.c
42949+++ b/drivers/iommu/irq_remapping.c
42950@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42951 void panic_if_irq_remap(const char *msg)
42952 {
42953 if (irq_remapping_enabled)
42954- panic(msg);
42955+ panic("%s", msg);
42956 }
42957
42958 static void ir_ack_apic_edge(struct irq_data *data)
42959@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42960
42961 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42962 {
42963- chip->irq_print_chip = ir_print_prefix;
42964- chip->irq_ack = ir_ack_apic_edge;
42965- chip->irq_eoi = ir_ack_apic_level;
42966- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42967+ pax_open_kernel();
42968+ *(void **)&chip->irq_print_chip = ir_print_prefix;
42969+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
42970+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
42971+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42972+ pax_close_kernel();
42973 }
42974
42975 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42976diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42977index 341c601..e5f407e 100644
42978--- a/drivers/irqchip/irq-gic.c
42979+++ b/drivers/irqchip/irq-gic.c
42980@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42981 * Supported arch specific GIC irq extension.
42982 * Default make them NULL.
42983 */
42984-struct irq_chip gic_arch_extn = {
42985+irq_chip_no_const gic_arch_extn = {
42986 .irq_eoi = NULL,
42987 .irq_mask = NULL,
42988 .irq_unmask = NULL,
42989@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42990 chained_irq_exit(chip, desc);
42991 }
42992
42993-static struct irq_chip gic_chip = {
42994+static irq_chip_no_const gic_chip __read_only = {
42995 .name = "GIC",
42996 .irq_mask = gic_mask_irq,
42997 .irq_unmask = gic_unmask_irq,
42998diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
42999index 8777065..a4a9967 100644
43000--- a/drivers/irqchip/irq-renesas-irqc.c
43001+++ b/drivers/irqchip/irq-renesas-irqc.c
43002@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43003 struct irqc_priv *p;
43004 struct resource *io;
43005 struct resource *irq;
43006- struct irq_chip *irq_chip;
43007+ irq_chip_no_const *irq_chip;
43008 const char *name = dev_name(&pdev->dev);
43009 int ret;
43010 int k;
43011diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43012index ac6f72b..81150f2 100644
43013--- a/drivers/isdn/capi/capi.c
43014+++ b/drivers/isdn/capi/capi.c
43015@@ -81,8 +81,8 @@ struct capiminor {
43016
43017 struct capi20_appl *ap;
43018 u32 ncci;
43019- atomic_t datahandle;
43020- atomic_t msgid;
43021+ atomic_unchecked_t datahandle;
43022+ atomic_unchecked_t msgid;
43023
43024 struct tty_port port;
43025 int ttyinstop;
43026@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43027 capimsg_setu16(s, 2, mp->ap->applid);
43028 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43029 capimsg_setu8 (s, 5, CAPI_RESP);
43030- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43031+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43032 capimsg_setu32(s, 8, mp->ncci);
43033 capimsg_setu16(s, 12, datahandle);
43034 }
43035@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43036 mp->outbytes -= len;
43037 spin_unlock_bh(&mp->outlock);
43038
43039- datahandle = atomic_inc_return(&mp->datahandle);
43040+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43041 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43042 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43043 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43044 capimsg_setu16(skb->data, 2, mp->ap->applid);
43045 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43046 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43047- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43048+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43049 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43050 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43051 capimsg_setu16(skb->data, 16, len); /* Data length */
43052diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43053index c44950d..10ac276 100644
43054--- a/drivers/isdn/gigaset/bas-gigaset.c
43055+++ b/drivers/isdn/gigaset/bas-gigaset.c
43056@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43057
43058
43059 static const struct gigaset_ops gigops = {
43060- gigaset_write_cmd,
43061- gigaset_write_room,
43062- gigaset_chars_in_buffer,
43063- gigaset_brkchars,
43064- gigaset_init_bchannel,
43065- gigaset_close_bchannel,
43066- gigaset_initbcshw,
43067- gigaset_freebcshw,
43068- gigaset_reinitbcshw,
43069- gigaset_initcshw,
43070- gigaset_freecshw,
43071- gigaset_set_modem_ctrl,
43072- gigaset_baud_rate,
43073- gigaset_set_line_ctrl,
43074- gigaset_isoc_send_skb,
43075- gigaset_isoc_input,
43076+ .write_cmd = gigaset_write_cmd,
43077+ .write_room = gigaset_write_room,
43078+ .chars_in_buffer = gigaset_chars_in_buffer,
43079+ .brkchars = gigaset_brkchars,
43080+ .init_bchannel = gigaset_init_bchannel,
43081+ .close_bchannel = gigaset_close_bchannel,
43082+ .initbcshw = gigaset_initbcshw,
43083+ .freebcshw = gigaset_freebcshw,
43084+ .reinitbcshw = gigaset_reinitbcshw,
43085+ .initcshw = gigaset_initcshw,
43086+ .freecshw = gigaset_freecshw,
43087+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43088+ .baud_rate = gigaset_baud_rate,
43089+ .set_line_ctrl = gigaset_set_line_ctrl,
43090+ .send_skb = gigaset_isoc_send_skb,
43091+ .handle_input = gigaset_isoc_input,
43092 };
43093
43094 /* bas_gigaset_init
43095diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43096index 600c79b..3752bab 100644
43097--- a/drivers/isdn/gigaset/interface.c
43098+++ b/drivers/isdn/gigaset/interface.c
43099@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43100 }
43101 tty->driver_data = cs;
43102
43103- ++cs->port.count;
43104+ atomic_inc(&cs->port.count);
43105
43106- if (cs->port.count == 1) {
43107+ if (atomic_read(&cs->port.count) == 1) {
43108 tty_port_tty_set(&cs->port, tty);
43109 cs->port.low_latency = 1;
43110 }
43111@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43112
43113 if (!cs->connected)
43114 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43115- else if (!cs->port.count)
43116+ else if (!atomic_read(&cs->port.count))
43117 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43118- else if (!--cs->port.count)
43119+ else if (!atomic_dec_return(&cs->port.count))
43120 tty_port_tty_set(&cs->port, NULL);
43121
43122 mutex_unlock(&cs->mutex);
43123diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43124index 8c91fd5..14f13ce 100644
43125--- a/drivers/isdn/gigaset/ser-gigaset.c
43126+++ b/drivers/isdn/gigaset/ser-gigaset.c
43127@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43128 }
43129
43130 static const struct gigaset_ops ops = {
43131- gigaset_write_cmd,
43132- gigaset_write_room,
43133- gigaset_chars_in_buffer,
43134- gigaset_brkchars,
43135- gigaset_init_bchannel,
43136- gigaset_close_bchannel,
43137- gigaset_initbcshw,
43138- gigaset_freebcshw,
43139- gigaset_reinitbcshw,
43140- gigaset_initcshw,
43141- gigaset_freecshw,
43142- gigaset_set_modem_ctrl,
43143- gigaset_baud_rate,
43144- gigaset_set_line_ctrl,
43145- gigaset_m10x_send_skb, /* asyncdata.c */
43146- gigaset_m10x_input, /* asyncdata.c */
43147+ .write_cmd = gigaset_write_cmd,
43148+ .write_room = gigaset_write_room,
43149+ .chars_in_buffer = gigaset_chars_in_buffer,
43150+ .brkchars = gigaset_brkchars,
43151+ .init_bchannel = gigaset_init_bchannel,
43152+ .close_bchannel = gigaset_close_bchannel,
43153+ .initbcshw = gigaset_initbcshw,
43154+ .freebcshw = gigaset_freebcshw,
43155+ .reinitbcshw = gigaset_reinitbcshw,
43156+ .initcshw = gigaset_initcshw,
43157+ .freecshw = gigaset_freecshw,
43158+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43159+ .baud_rate = gigaset_baud_rate,
43160+ .set_line_ctrl = gigaset_set_line_ctrl,
43161+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43162+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43163 };
43164
43165
43166diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43167index d0a41cb..b953e50 100644
43168--- a/drivers/isdn/gigaset/usb-gigaset.c
43169+++ b/drivers/isdn/gigaset/usb-gigaset.c
43170@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43171 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43172 memcpy(cs->hw.usb->bchars, buf, 6);
43173 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43174- 0, 0, &buf, 6, 2000);
43175+ 0, 0, buf, 6, 2000);
43176 }
43177
43178 static void gigaset_freebcshw(struct bc_state *bcs)
43179@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43180 }
43181
43182 static const struct gigaset_ops ops = {
43183- gigaset_write_cmd,
43184- gigaset_write_room,
43185- gigaset_chars_in_buffer,
43186- gigaset_brkchars,
43187- gigaset_init_bchannel,
43188- gigaset_close_bchannel,
43189- gigaset_initbcshw,
43190- gigaset_freebcshw,
43191- gigaset_reinitbcshw,
43192- gigaset_initcshw,
43193- gigaset_freecshw,
43194- gigaset_set_modem_ctrl,
43195- gigaset_baud_rate,
43196- gigaset_set_line_ctrl,
43197- gigaset_m10x_send_skb,
43198- gigaset_m10x_input,
43199+ .write_cmd = gigaset_write_cmd,
43200+ .write_room = gigaset_write_room,
43201+ .chars_in_buffer = gigaset_chars_in_buffer,
43202+ .brkchars = gigaset_brkchars,
43203+ .init_bchannel = gigaset_init_bchannel,
43204+ .close_bchannel = gigaset_close_bchannel,
43205+ .initbcshw = gigaset_initbcshw,
43206+ .freebcshw = gigaset_freebcshw,
43207+ .reinitbcshw = gigaset_reinitbcshw,
43208+ .initcshw = gigaset_initcshw,
43209+ .freecshw = gigaset_freecshw,
43210+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43211+ .baud_rate = gigaset_baud_rate,
43212+ .set_line_ctrl = gigaset_set_line_ctrl,
43213+ .send_skb = gigaset_m10x_send_skb,
43214+ .handle_input = gigaset_m10x_input,
43215 };
43216
43217 /*
43218diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43219index 4d9b195..455075c 100644
43220--- a/drivers/isdn/hardware/avm/b1.c
43221+++ b/drivers/isdn/hardware/avm/b1.c
43222@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43223 }
43224 if (left) {
43225 if (t4file->user) {
43226- if (copy_from_user(buf, dp, left))
43227+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43228 return -EFAULT;
43229 } else {
43230 memcpy(buf, dp, left);
43231@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43232 }
43233 if (left) {
43234 if (config->user) {
43235- if (copy_from_user(buf, dp, left))
43236+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43237 return -EFAULT;
43238 } else {
43239 memcpy(buf, dp, left);
43240diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43241index 9bb12ba..d4262f7 100644
43242--- a/drivers/isdn/i4l/isdn_common.c
43243+++ b/drivers/isdn/i4l/isdn_common.c
43244@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43245 } else
43246 return -EINVAL;
43247 case IIOCDBGVAR:
43248+ if (!capable(CAP_SYS_RAWIO))
43249+ return -EPERM;
43250 if (arg) {
43251 if (copy_to_user(argp, &dev, sizeof(ulong)))
43252 return -EFAULT;
43253diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43254index 91d5730..336523e 100644
43255--- a/drivers/isdn/i4l/isdn_concap.c
43256+++ b/drivers/isdn/i4l/isdn_concap.c
43257@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43258 }
43259
43260 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43261- &isdn_concap_dl_data_req,
43262- &isdn_concap_dl_connect_req,
43263- &isdn_concap_dl_disconn_req
43264+ .data_req = &isdn_concap_dl_data_req,
43265+ .connect_req = &isdn_concap_dl_connect_req,
43266+ .disconn_req = &isdn_concap_dl_disconn_req
43267 };
43268
43269 /* The following should better go into a dedicated source file such that
43270diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43271index 3c5f249..5fac4d0 100644
43272--- a/drivers/isdn/i4l/isdn_tty.c
43273+++ b/drivers/isdn/i4l/isdn_tty.c
43274@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43275
43276 #ifdef ISDN_DEBUG_MODEM_OPEN
43277 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43278- port->count);
43279+ atomic_read(&port->count));
43280 #endif
43281- port->count++;
43282+ atomic_inc(&port->count);
43283 port->tty = tty;
43284 /*
43285 * Start up serial port
43286@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43287 #endif
43288 return;
43289 }
43290- if ((tty->count == 1) && (port->count != 1)) {
43291+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43292 /*
43293 * Uh, oh. tty->count is 1, which means that the tty
43294 * structure will be freed. Info->count should always
43295@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43296 * serial port won't be shutdown.
43297 */
43298 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43299- "info->count is %d\n", port->count);
43300- port->count = 1;
43301+ "info->count is %d\n", atomic_read(&port->count));
43302+ atomic_set(&port->count, 1);
43303 }
43304- if (--port->count < 0) {
43305+ if (atomic_dec_return(&port->count) < 0) {
43306 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43307- info->line, port->count);
43308- port->count = 0;
43309+ info->line, atomic_read(&port->count));
43310+ atomic_set(&port->count, 0);
43311 }
43312- if (port->count) {
43313+ if (atomic_read(&port->count)) {
43314 #ifdef ISDN_DEBUG_MODEM_OPEN
43315 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43316 #endif
43317@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43318 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43319 return;
43320 isdn_tty_shutdown(info);
43321- port->count = 0;
43322+ atomic_set(&port->count, 0);
43323 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43324 port->tty = NULL;
43325 wake_up_interruptible(&port->open_wait);
43326@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43327 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43328 modem_info *info = &dev->mdm.info[i];
43329
43330- if (info->port.count == 0)
43331+ if (atomic_read(&info->port.count) == 0)
43332 continue;
43333 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43334 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43335diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43336index e2d4e58..40cd045 100644
43337--- a/drivers/isdn/i4l/isdn_x25iface.c
43338+++ b/drivers/isdn/i4l/isdn_x25iface.c
43339@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43340
43341
43342 static struct concap_proto_ops ix25_pops = {
43343- &isdn_x25iface_proto_new,
43344- &isdn_x25iface_proto_del,
43345- &isdn_x25iface_proto_restart,
43346- &isdn_x25iface_proto_close,
43347- &isdn_x25iface_xmit,
43348- &isdn_x25iface_receive,
43349- &isdn_x25iface_connect_ind,
43350- &isdn_x25iface_disconn_ind
43351+ .proto_new = &isdn_x25iface_proto_new,
43352+ .proto_del = &isdn_x25iface_proto_del,
43353+ .restart = &isdn_x25iface_proto_restart,
43354+ .close = &isdn_x25iface_proto_close,
43355+ .encap_and_xmit = &isdn_x25iface_xmit,
43356+ .data_ind = &isdn_x25iface_receive,
43357+ .connect_ind = &isdn_x25iface_connect_ind,
43358+ .disconn_ind = &isdn_x25iface_disconn_ind
43359 };
43360
43361 /* error message helper function */
43362diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43363index 53d487f..cae33fe 100644
43364--- a/drivers/isdn/icn/icn.c
43365+++ b/drivers/isdn/icn/icn.c
43366@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43367 if (count > len)
43368 count = len;
43369 if (user) {
43370- if (copy_from_user(msg, buf, count))
43371+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43372 return -EFAULT;
43373 } else
43374 memcpy(msg, buf, count);
43375@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43376 ulong a;
43377 ulong flags;
43378 int i;
43379- char cbuf[60];
43380+ char cbuf[80];
43381 isdn_ctrl cmd;
43382 icn_cdef cdef;
43383 char __user *arg;
43384@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43385 break;
43386 if ((c->arg & 255) < ICN_BCH) {
43387 char *p;
43388- char dial[50];
43389 char dcode[4];
43390
43391 a = c->arg;
43392@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43393 } else
43394 /* Normal Dial */
43395 strcpy(dcode, "CAL");
43396- strcpy(dial, p);
43397- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43398- dcode, dial, c->parm.setup.si1,
43399- c->parm.setup.si2, c->parm.setup.eazmsn);
43400+ snprintf(cbuf, sizeof(cbuf),
43401+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43402+ dcode, p, c->parm.setup.si1,
43403+ c->parm.setup.si2, c->parm.setup.eazmsn);
43404 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43405 }
43406 break;
43407diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43408index a4f05c5..1433bc5 100644
43409--- a/drivers/isdn/mISDN/dsp_cmx.c
43410+++ b/drivers/isdn/mISDN/dsp_cmx.c
43411@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43412 static u16 dsp_count; /* last sample count */
43413 static int dsp_count_valid; /* if we have last sample count */
43414
43415-void
43416+void __intentional_overflow(-1)
43417 dsp_cmx_send(void *arg)
43418 {
43419 struct dsp_conf *conf;
43420diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43421index d93e245..e7ece6b 100644
43422--- a/drivers/leds/leds-clevo-mail.c
43423+++ b/drivers/leds/leds-clevo-mail.c
43424@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43425 * detected as working, but in reality it is not) as low as
43426 * possible.
43427 */
43428-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43429+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43430 {
43431 .callback = clevo_mail_led_dmi_callback,
43432 .ident = "Clevo D410J",
43433diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43434index 5b8f938..b73d657 100644
43435--- a/drivers/leds/leds-ss4200.c
43436+++ b/drivers/leds/leds-ss4200.c
43437@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43438 * detected as working, but in reality it is not) as low as
43439 * possible.
43440 */
43441-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43442+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43443 {
43444 .callback = ss4200_led_dmi_callback,
43445 .ident = "Intel SS4200-E",
43446diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43447index 0bf1e4e..b4bf44e 100644
43448--- a/drivers/lguest/core.c
43449+++ b/drivers/lguest/core.c
43450@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43451 * The end address needs +1 because __get_vm_area allocates an
43452 * extra guard page, so we need space for that.
43453 */
43454+
43455+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43456+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43457+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43458+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43459+#else
43460 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43461 VM_ALLOC, switcher_addr, switcher_addr
43462 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43463+#endif
43464+
43465 if (!switcher_vma) {
43466 err = -ENOMEM;
43467 printk("lguest: could not map switcher pages high\n");
43468@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43469 * Now the Switcher is mapped at the right address, we can't fail!
43470 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43471 */
43472- memcpy(switcher_vma->addr, start_switcher_text,
43473+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43474 end_switcher_text - start_switcher_text);
43475
43476 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43477diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43478index bfb39bb..08a603b 100644
43479--- a/drivers/lguest/page_tables.c
43480+++ b/drivers/lguest/page_tables.c
43481@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43482 /*:*/
43483
43484 #ifdef CONFIG_X86_PAE
43485-static void release_pmd(pmd_t *spmd)
43486+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43487 {
43488 /* If the entry's not present, there's nothing to release. */
43489 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43490diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43491index 922a1ac..9dd0c2a 100644
43492--- a/drivers/lguest/x86/core.c
43493+++ b/drivers/lguest/x86/core.c
43494@@ -59,7 +59,7 @@ static struct {
43495 /* Offset from where switcher.S was compiled to where we've copied it */
43496 static unsigned long switcher_offset(void)
43497 {
43498- return switcher_addr - (unsigned long)start_switcher_text;
43499+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43500 }
43501
43502 /* This cpu's struct lguest_pages (after the Switcher text page) */
43503@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43504 * These copies are pretty cheap, so we do them unconditionally: */
43505 /* Save the current Host top-level page directory.
43506 */
43507+
43508+#ifdef CONFIG_PAX_PER_CPU_PGD
43509+ pages->state.host_cr3 = read_cr3();
43510+#else
43511 pages->state.host_cr3 = __pa(current->mm->pgd);
43512+#endif
43513+
43514 /*
43515 * Set up the Guest's page tables to see this CPU's pages (and no
43516 * other CPU's pages).
43517@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43518 * compiled-in switcher code and the high-mapped copy we just made.
43519 */
43520 for (i = 0; i < IDT_ENTRIES; i++)
43521- default_idt_entries[i] += switcher_offset();
43522+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43523
43524 /*
43525 * Set up the Switcher's per-cpu areas.
43526@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43527 * it will be undisturbed when we switch. To change %cs and jump we
43528 * need this structure to feed to Intel's "lcall" instruction.
43529 */
43530- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43531+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43532 lguest_entry.segment = LGUEST_CS;
43533
43534 /*
43535diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43536index 40634b0..4f5855e 100644
43537--- a/drivers/lguest/x86/switcher_32.S
43538+++ b/drivers/lguest/x86/switcher_32.S
43539@@ -87,6 +87,7 @@
43540 #include <asm/page.h>
43541 #include <asm/segment.h>
43542 #include <asm/lguest.h>
43543+#include <asm/processor-flags.h>
43544
43545 // We mark the start of the code to copy
43546 // It's placed in .text tho it's never run here
43547@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43548 // Changes type when we load it: damn Intel!
43549 // For after we switch over our page tables
43550 // That entry will be read-only: we'd crash.
43551+
43552+#ifdef CONFIG_PAX_KERNEXEC
43553+ mov %cr0, %edx
43554+ xor $X86_CR0_WP, %edx
43555+ mov %edx, %cr0
43556+#endif
43557+
43558 movl $(GDT_ENTRY_TSS*8), %edx
43559 ltr %dx
43560
43561@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43562 // Let's clear it again for our return.
43563 // The GDT descriptor of the Host
43564 // Points to the table after two "size" bytes
43565- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43566+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43567 // Clear "used" from type field (byte 5, bit 2)
43568- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43569+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43570+
43571+#ifdef CONFIG_PAX_KERNEXEC
43572+ mov %cr0, %eax
43573+ xor $X86_CR0_WP, %eax
43574+ mov %eax, %cr0
43575+#endif
43576
43577 // Once our page table's switched, the Guest is live!
43578 // The Host fades as we run this final step.
43579@@ -295,13 +309,12 @@ deliver_to_host:
43580 // I consulted gcc, and it gave
43581 // These instructions, which I gladly credit:
43582 leal (%edx,%ebx,8), %eax
43583- movzwl (%eax),%edx
43584- movl 4(%eax), %eax
43585- xorw %ax, %ax
43586- orl %eax, %edx
43587+ movl 4(%eax), %edx
43588+ movw (%eax), %dx
43589 // Now the address of the handler's in %edx
43590 // We call it now: its "iret" drops us home.
43591- jmp *%edx
43592+ ljmp $__KERNEL_CS, $1f
43593+1: jmp *%edx
43594
43595 // Every interrupt can come to us here
43596 // But we must truly tell each apart.
43597diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43598index 7ef7461..5a09dac 100644
43599--- a/drivers/md/bcache/closure.h
43600+++ b/drivers/md/bcache/closure.h
43601@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43602 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43603 struct workqueue_struct *wq)
43604 {
43605- BUG_ON(object_is_on_stack(cl));
43606+ BUG_ON(object_starts_on_stack(cl));
43607 closure_set_ip(cl);
43608 cl->fn = fn;
43609 cl->wq = wq;
43610diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43611index 4195a01..42527ac 100644
43612--- a/drivers/md/bitmap.c
43613+++ b/drivers/md/bitmap.c
43614@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43615 chunk_kb ? "KB" : "B");
43616 if (bitmap->storage.file) {
43617 seq_printf(seq, ", file: ");
43618- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43619+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43620 }
43621
43622 seq_printf(seq, "\n");
43623diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43624index 5152142..623d141 100644
43625--- a/drivers/md/dm-ioctl.c
43626+++ b/drivers/md/dm-ioctl.c
43627@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43628 cmd == DM_LIST_VERSIONS_CMD)
43629 return 0;
43630
43631- if ((cmd == DM_DEV_CREATE_CMD)) {
43632+ if (cmd == DM_DEV_CREATE_CMD) {
43633 if (!*param->name) {
43634 DMWARN("name not supplied when creating device");
43635 return -EINVAL;
43636diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43637index 7dfdb5c..4caada6 100644
43638--- a/drivers/md/dm-raid1.c
43639+++ b/drivers/md/dm-raid1.c
43640@@ -40,7 +40,7 @@ enum dm_raid1_error {
43641
43642 struct mirror {
43643 struct mirror_set *ms;
43644- atomic_t error_count;
43645+ atomic_unchecked_t error_count;
43646 unsigned long error_type;
43647 struct dm_dev *dev;
43648 sector_t offset;
43649@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43650 struct mirror *m;
43651
43652 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43653- if (!atomic_read(&m->error_count))
43654+ if (!atomic_read_unchecked(&m->error_count))
43655 return m;
43656
43657 return NULL;
43658@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43659 * simple way to tell if a device has encountered
43660 * errors.
43661 */
43662- atomic_inc(&m->error_count);
43663+ atomic_inc_unchecked(&m->error_count);
43664
43665 if (test_and_set_bit(error_type, &m->error_type))
43666 return;
43667@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43668 struct mirror *m = get_default_mirror(ms);
43669
43670 do {
43671- if (likely(!atomic_read(&m->error_count)))
43672+ if (likely(!atomic_read_unchecked(&m->error_count)))
43673 return m;
43674
43675 if (m-- == ms->mirror)
43676@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43677 {
43678 struct mirror *default_mirror = get_default_mirror(m->ms);
43679
43680- return !atomic_read(&default_mirror->error_count);
43681+ return !atomic_read_unchecked(&default_mirror->error_count);
43682 }
43683
43684 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43685@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43686 */
43687 if (likely(region_in_sync(ms, region, 1)))
43688 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43689- else if (m && atomic_read(&m->error_count))
43690+ else if (m && atomic_read_unchecked(&m->error_count))
43691 m = NULL;
43692
43693 if (likely(m))
43694@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43695 }
43696
43697 ms->mirror[mirror].ms = ms;
43698- atomic_set(&(ms->mirror[mirror].error_count), 0);
43699+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43700 ms->mirror[mirror].error_type = 0;
43701 ms->mirror[mirror].offset = offset;
43702
43703@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43704 */
43705 static char device_status_char(struct mirror *m)
43706 {
43707- if (!atomic_read(&(m->error_count)))
43708+ if (!atomic_read_unchecked(&(m->error_count)))
43709 return 'A';
43710
43711 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43712diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43713index 28a9012..9c0f6a5 100644
43714--- a/drivers/md/dm-stats.c
43715+++ b/drivers/md/dm-stats.c
43716@@ -382,7 +382,7 @@ do_sync_free:
43717 synchronize_rcu_expedited();
43718 dm_stat_free(&s->rcu_head);
43719 } else {
43720- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43721+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43722 call_rcu(&s->rcu_head, dm_stat_free);
43723 }
43724 return 0;
43725@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43726 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43727 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43728 ));
43729- ACCESS_ONCE(last->last_sector) = end_sector;
43730- ACCESS_ONCE(last->last_rw) = bi_rw;
43731+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43732+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43733 }
43734
43735 rcu_read_lock();
43736diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43737index d1600d2..4c3af3a 100644
43738--- a/drivers/md/dm-stripe.c
43739+++ b/drivers/md/dm-stripe.c
43740@@ -21,7 +21,7 @@ struct stripe {
43741 struct dm_dev *dev;
43742 sector_t physical_start;
43743
43744- atomic_t error_count;
43745+ atomic_unchecked_t error_count;
43746 };
43747
43748 struct stripe_c {
43749@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43750 kfree(sc);
43751 return r;
43752 }
43753- atomic_set(&(sc->stripe[i].error_count), 0);
43754+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43755 }
43756
43757 ti->private = sc;
43758@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43759 DMEMIT("%d ", sc->stripes);
43760 for (i = 0; i < sc->stripes; i++) {
43761 DMEMIT("%s ", sc->stripe[i].dev->name);
43762- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43763+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43764 'D' : 'A';
43765 }
43766 buffer[i] = '\0';
43767@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43768 */
43769 for (i = 0; i < sc->stripes; i++)
43770 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43771- atomic_inc(&(sc->stripe[i].error_count));
43772- if (atomic_read(&(sc->stripe[i].error_count)) <
43773+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43774+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43775 DM_IO_ERROR_THRESHOLD)
43776 schedule_work(&sc->trigger_event);
43777 }
43778diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43779index 6a7f2b8..fea0bde 100644
43780--- a/drivers/md/dm-table.c
43781+++ b/drivers/md/dm-table.c
43782@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43783 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43784 struct mapped_device *md)
43785 {
43786- static char *_claim_ptr = "I belong to device-mapper";
43787+ static char _claim_ptr[] = "I belong to device-mapper";
43788 struct block_device *bdev;
43789
43790 int r;
43791@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43792 if (!dev_size)
43793 return 0;
43794
43795- if ((start >= dev_size) || (start + len > dev_size)) {
43796+ if ((start >= dev_size) || (len > dev_size - start)) {
43797 DMWARN("%s: %s too small for target: "
43798 "start=%llu, len=%llu, dev_size=%llu",
43799 dm_device_name(ti->table->md), bdevname(bdev, b),
43800diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43801index fb9efc8..81e8986 100644
43802--- a/drivers/md/dm-thin-metadata.c
43803+++ b/drivers/md/dm-thin-metadata.c
43804@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43805 {
43806 pmd->info.tm = pmd->tm;
43807 pmd->info.levels = 2;
43808- pmd->info.value_type.context = pmd->data_sm;
43809+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43810 pmd->info.value_type.size = sizeof(__le64);
43811 pmd->info.value_type.inc = data_block_inc;
43812 pmd->info.value_type.dec = data_block_dec;
43813@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43814
43815 pmd->bl_info.tm = pmd->tm;
43816 pmd->bl_info.levels = 1;
43817- pmd->bl_info.value_type.context = pmd->data_sm;
43818+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43819 pmd->bl_info.value_type.size = sizeof(__le64);
43820 pmd->bl_info.value_type.inc = data_block_inc;
43821 pmd->bl_info.value_type.dec = data_block_dec;
43822diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43823index 8c53b09..f1fb2b0 100644
43824--- a/drivers/md/dm.c
43825+++ b/drivers/md/dm.c
43826@@ -185,9 +185,9 @@ struct mapped_device {
43827 /*
43828 * Event handling.
43829 */
43830- atomic_t event_nr;
43831+ atomic_unchecked_t event_nr;
43832 wait_queue_head_t eventq;
43833- atomic_t uevent_seq;
43834+ atomic_unchecked_t uevent_seq;
43835 struct list_head uevent_list;
43836 spinlock_t uevent_lock; /* Protect access to uevent_list */
43837
43838@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43839 spin_lock_init(&md->deferred_lock);
43840 atomic_set(&md->holders, 1);
43841 atomic_set(&md->open_count, 0);
43842- atomic_set(&md->event_nr, 0);
43843- atomic_set(&md->uevent_seq, 0);
43844+ atomic_set_unchecked(&md->event_nr, 0);
43845+ atomic_set_unchecked(&md->uevent_seq, 0);
43846 INIT_LIST_HEAD(&md->uevent_list);
43847 spin_lock_init(&md->uevent_lock);
43848
43849@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43850
43851 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43852
43853- atomic_inc(&md->event_nr);
43854+ atomic_inc_unchecked(&md->event_nr);
43855 wake_up(&md->eventq);
43856 }
43857
43858@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43859
43860 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43861 {
43862- return atomic_add_return(1, &md->uevent_seq);
43863+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43864 }
43865
43866 uint32_t dm_get_event_nr(struct mapped_device *md)
43867 {
43868- return atomic_read(&md->event_nr);
43869+ return atomic_read_unchecked(&md->event_nr);
43870 }
43871
43872 int dm_wait_event(struct mapped_device *md, int event_nr)
43873 {
43874 return wait_event_interruptible(md->eventq,
43875- (event_nr != atomic_read(&md->event_nr)));
43876+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43877 }
43878
43879 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43880diff --git a/drivers/md/md.c b/drivers/md/md.c
43881index 4ad5cc4..0f19664 100644
43882--- a/drivers/md/md.c
43883+++ b/drivers/md/md.c
43884@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43885 * start build, activate spare
43886 */
43887 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43888-static atomic_t md_event_count;
43889+static atomic_unchecked_t md_event_count;
43890 void md_new_event(struct mddev *mddev)
43891 {
43892- atomic_inc(&md_event_count);
43893+ atomic_inc_unchecked(&md_event_count);
43894 wake_up(&md_event_waiters);
43895 }
43896 EXPORT_SYMBOL_GPL(md_new_event);
43897@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43898 */
43899 static void md_new_event_inintr(struct mddev *mddev)
43900 {
43901- atomic_inc(&md_event_count);
43902+ atomic_inc_unchecked(&md_event_count);
43903 wake_up(&md_event_waiters);
43904 }
43905
43906@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43907 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43908 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43909 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43910- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43911+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43912
43913 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43914 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43915@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43916 else
43917 sb->resync_offset = cpu_to_le64(0);
43918
43919- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43920+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43921
43922 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43923 sb->size = cpu_to_le64(mddev->dev_sectors);
43924@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43925 static ssize_t
43926 errors_show(struct md_rdev *rdev, char *page)
43927 {
43928- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43929+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43930 }
43931
43932 static ssize_t
43933@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43934 char *e;
43935 unsigned long n = simple_strtoul(buf, &e, 10);
43936 if (*buf && (*e == 0 || *e == '\n')) {
43937- atomic_set(&rdev->corrected_errors, n);
43938+ atomic_set_unchecked(&rdev->corrected_errors, n);
43939 return len;
43940 }
43941 return -EINVAL;
43942@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43943 rdev->sb_loaded = 0;
43944 rdev->bb_page = NULL;
43945 atomic_set(&rdev->nr_pending, 0);
43946- atomic_set(&rdev->read_errors, 0);
43947- atomic_set(&rdev->corrected_errors, 0);
43948+ atomic_set_unchecked(&rdev->read_errors, 0);
43949+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43950
43951 INIT_LIST_HEAD(&rdev->same_set);
43952 init_waitqueue_head(&rdev->blocked_wait);
43953@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43954
43955 spin_unlock(&pers_lock);
43956 seq_printf(seq, "\n");
43957- seq->poll_event = atomic_read(&md_event_count);
43958+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43959 return 0;
43960 }
43961 if (v == (void*)2) {
43962@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43963 return error;
43964
43965 seq = file->private_data;
43966- seq->poll_event = atomic_read(&md_event_count);
43967+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43968 return error;
43969 }
43970
43971@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43972 /* always allow read */
43973 mask = POLLIN | POLLRDNORM;
43974
43975- if (seq->poll_event != atomic_read(&md_event_count))
43976+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43977 mask |= POLLERR | POLLPRI;
43978 return mask;
43979 }
43980@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43981 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43982 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43983 (int)part_stat_read(&disk->part0, sectors[1]) -
43984- atomic_read(&disk->sync_io);
43985+ atomic_read_unchecked(&disk->sync_io);
43986 /* sync IO will cause sync_io to increase before the disk_stats
43987 * as sync_io is counted when a request starts, and
43988 * disk_stats is counted when it completes.
43989diff --git a/drivers/md/md.h b/drivers/md/md.h
43990index 07bba96..2d6788c 100644
43991--- a/drivers/md/md.h
43992+++ b/drivers/md/md.h
43993@@ -94,13 +94,13 @@ struct md_rdev {
43994 * only maintained for arrays that
43995 * support hot removal
43996 */
43997- atomic_t read_errors; /* number of consecutive read errors that
43998+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43999 * we have tried to ignore.
44000 */
44001 struct timespec last_read_error; /* monotonic time since our
44002 * last read error
44003 */
44004- atomic_t corrected_errors; /* number of corrected read errors,
44005+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44006 * for reporting to userspace and storing
44007 * in superblock.
44008 */
44009@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44010
44011 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44012 {
44013- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44014+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44015 }
44016
44017 struct md_personality
44018diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44019index 786b689..ea8c956 100644
44020--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44021+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44022@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44023 * Flick into a mode where all blocks get allocated in the new area.
44024 */
44025 smm->begin = old_len;
44026- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44027+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44028
44029 /*
44030 * Extend.
44031@@ -710,7 +710,7 @@ out:
44032 /*
44033 * Switch back to normal behaviour.
44034 */
44035- memcpy(sm, &ops, sizeof(*sm));
44036+ memcpy((void *)sm, &ops, sizeof(*sm));
44037 return r;
44038 }
44039
44040diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44041index 3e6d115..ffecdeb 100644
44042--- a/drivers/md/persistent-data/dm-space-map.h
44043+++ b/drivers/md/persistent-data/dm-space-map.h
44044@@ -71,6 +71,7 @@ struct dm_space_map {
44045 dm_sm_threshold_fn fn,
44046 void *context);
44047 };
44048+typedef struct dm_space_map __no_const dm_space_map_no_const;
44049
44050 /*----------------------------------------------------------------*/
44051
44052diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44053index 4a6ca1c..e952750 100644
44054--- a/drivers/md/raid1.c
44055+++ b/drivers/md/raid1.c
44056@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44057 if (r1_sync_page_io(rdev, sect, s,
44058 bio->bi_io_vec[idx].bv_page,
44059 READ) != 0)
44060- atomic_add(s, &rdev->corrected_errors);
44061+ atomic_add_unchecked(s, &rdev->corrected_errors);
44062 }
44063 sectors -= s;
44064 sect += s;
44065@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44066 test_bit(In_sync, &rdev->flags)) {
44067 if (r1_sync_page_io(rdev, sect, s,
44068 conf->tmppage, READ)) {
44069- atomic_add(s, &rdev->corrected_errors);
44070+ atomic_add_unchecked(s, &rdev->corrected_errors);
44071 printk(KERN_INFO
44072 "md/raid1:%s: read error corrected "
44073 "(%d sectors at %llu on %s)\n",
44074diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44075index 33fc408..fc61709 100644
44076--- a/drivers/md/raid10.c
44077+++ b/drivers/md/raid10.c
44078@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44079 /* The write handler will notice the lack of
44080 * R10BIO_Uptodate and record any errors etc
44081 */
44082- atomic_add(r10_bio->sectors,
44083+ atomic_add_unchecked(r10_bio->sectors,
44084 &conf->mirrors[d].rdev->corrected_errors);
44085
44086 /* for reconstruct, we always reschedule after a read.
44087@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44088 {
44089 struct timespec cur_time_mon;
44090 unsigned long hours_since_last;
44091- unsigned int read_errors = atomic_read(&rdev->read_errors);
44092+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44093
44094 ktime_get_ts(&cur_time_mon);
44095
44096@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44097 * overflowing the shift of read_errors by hours_since_last.
44098 */
44099 if (hours_since_last >= 8 * sizeof(read_errors))
44100- atomic_set(&rdev->read_errors, 0);
44101+ atomic_set_unchecked(&rdev->read_errors, 0);
44102 else
44103- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44104+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44105 }
44106
44107 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44108@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44109 return;
44110
44111 check_decay_read_errors(mddev, rdev);
44112- atomic_inc(&rdev->read_errors);
44113- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44114+ atomic_inc_unchecked(&rdev->read_errors);
44115+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44116 char b[BDEVNAME_SIZE];
44117 bdevname(rdev->bdev, b);
44118
44119@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44120 "md/raid10:%s: %s: Raid device exceeded "
44121 "read_error threshold [cur %d:max %d]\n",
44122 mdname(mddev), b,
44123- atomic_read(&rdev->read_errors), max_read_errors);
44124+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44125 printk(KERN_NOTICE
44126 "md/raid10:%s: %s: Failing raid device\n",
44127 mdname(mddev), b);
44128@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44129 sect +
44130 choose_data_offset(r10_bio, rdev)),
44131 bdevname(rdev->bdev, b));
44132- atomic_add(s, &rdev->corrected_errors);
44133+ atomic_add_unchecked(s, &rdev->corrected_errors);
44134 }
44135
44136 rdev_dec_pending(rdev, mddev);
44137diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44138index 16f5c21..4df20dc 100644
44139--- a/drivers/md/raid5.c
44140+++ b/drivers/md/raid5.c
44141@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44142 mdname(conf->mddev), STRIPE_SECTORS,
44143 (unsigned long long)s,
44144 bdevname(rdev->bdev, b));
44145- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44146+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44147 clear_bit(R5_ReadError, &sh->dev[i].flags);
44148 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44149 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44150 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44151
44152- if (atomic_read(&rdev->read_errors))
44153- atomic_set(&rdev->read_errors, 0);
44154+ if (atomic_read_unchecked(&rdev->read_errors))
44155+ atomic_set_unchecked(&rdev->read_errors, 0);
44156 } else {
44157 const char *bdn = bdevname(rdev->bdev, b);
44158 int retry = 0;
44159 int set_bad = 0;
44160
44161 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44162- atomic_inc(&rdev->read_errors);
44163+ atomic_inc_unchecked(&rdev->read_errors);
44164 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44165 printk_ratelimited(
44166 KERN_WARNING
44167@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44168 mdname(conf->mddev),
44169 (unsigned long long)s,
44170 bdn);
44171- } else if (atomic_read(&rdev->read_errors)
44172+ } else if (atomic_read_unchecked(&rdev->read_errors)
44173 > conf->max_nr_stripes)
44174 printk(KERN_WARNING
44175 "md/raid:%s: Too many read errors, failing device %s.\n",
44176diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44177index 983db75..ef9248c 100644
44178--- a/drivers/media/dvb-core/dvbdev.c
44179+++ b/drivers/media/dvb-core/dvbdev.c
44180@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44181 const struct dvb_device *template, void *priv, int type)
44182 {
44183 struct dvb_device *dvbdev;
44184- struct file_operations *dvbdevfops;
44185+ file_operations_no_const *dvbdevfops;
44186 struct device *clsdev;
44187 int minor;
44188 int id;
44189diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44190index 9b6c3bb..baeb5c7 100644
44191--- a/drivers/media/dvb-frontends/dib3000.h
44192+++ b/drivers/media/dvb-frontends/dib3000.h
44193@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44194 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44195 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44196 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44197-};
44198+} __no_const;
44199
44200 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44201 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44202diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44203index d5a7a13..703560f 100644
44204--- a/drivers/media/media-device.c
44205+++ b/drivers/media/media-device.c
44206@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44207 struct media_entity *ent;
44208 struct media_entity_desc u_ent;
44209
44210+ memset(&u_ent, 0, sizeof(u_ent));
44211 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44212 return -EFAULT;
44213
44214diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44215index ed8cb90..5ef7f79 100644
44216--- a/drivers/media/pci/cx88/cx88-video.c
44217+++ b/drivers/media/pci/cx88/cx88-video.c
44218@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44219
44220 /* ------------------------------------------------------------------ */
44221
44222-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44223-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44224-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44225+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44226+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44227+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44228
44229 module_param_array(video_nr, int, NULL, 0444);
44230 module_param_array(vbi_nr, int, NULL, 0444);
44231diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44232index 802642d..5534900 100644
44233--- a/drivers/media/pci/ivtv/ivtv-driver.c
44234+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44235@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44236 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44237
44238 /* ivtv instance counter */
44239-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44240+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44241
44242 /* Parameter declarations */
44243 static int cardtype[IVTV_MAX_CARDS];
44244diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44245index dfd0a21..6bbb465 100644
44246--- a/drivers/media/platform/omap/omap_vout.c
44247+++ b/drivers/media/platform/omap/omap_vout.c
44248@@ -63,7 +63,6 @@ enum omap_vout_channels {
44249 OMAP_VIDEO2,
44250 };
44251
44252-static struct videobuf_queue_ops video_vbq_ops;
44253 /* Variables configurable through module params*/
44254 static u32 video1_numbuffers = 3;
44255 static u32 video2_numbuffers = 3;
44256@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44257 {
44258 struct videobuf_queue *q;
44259 struct omap_vout_device *vout = NULL;
44260+ static struct videobuf_queue_ops video_vbq_ops = {
44261+ .buf_setup = omap_vout_buffer_setup,
44262+ .buf_prepare = omap_vout_buffer_prepare,
44263+ .buf_release = omap_vout_buffer_release,
44264+ .buf_queue = omap_vout_buffer_queue,
44265+ };
44266
44267 vout = video_drvdata(file);
44268 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44269@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44270 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44271
44272 q = &vout->vbq;
44273- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44274- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44275- video_vbq_ops.buf_release = omap_vout_buffer_release;
44276- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44277 spin_lock_init(&vout->vbq_lock);
44278
44279 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44280diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44281index fb2acc5..a2fcbdc4 100644
44282--- a/drivers/media/platform/s5p-tv/mixer.h
44283+++ b/drivers/media/platform/s5p-tv/mixer.h
44284@@ -156,7 +156,7 @@ struct mxr_layer {
44285 /** layer index (unique identifier) */
44286 int idx;
44287 /** callbacks for layer methods */
44288- struct mxr_layer_ops ops;
44289+ struct mxr_layer_ops *ops;
44290 /** format array */
44291 const struct mxr_format **fmt_array;
44292 /** size of format array */
44293diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44294index 74344c7..a39e70e 100644
44295--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44296+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44297@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44298 {
44299 struct mxr_layer *layer;
44300 int ret;
44301- struct mxr_layer_ops ops = {
44302+ static struct mxr_layer_ops ops = {
44303 .release = mxr_graph_layer_release,
44304 .buffer_set = mxr_graph_buffer_set,
44305 .stream_set = mxr_graph_stream_set,
44306diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44307index b713403..53cb5ad 100644
44308--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44309+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44310@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44311 layer->update_buf = next;
44312 }
44313
44314- layer->ops.buffer_set(layer, layer->update_buf);
44315+ layer->ops->buffer_set(layer, layer->update_buf);
44316
44317 if (done && done != layer->shadow_buf)
44318 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44319diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44320index c5059ba..2649f28 100644
44321--- a/drivers/media/platform/s5p-tv/mixer_video.c
44322+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44323@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44324 layer->geo.src.height = layer->geo.src.full_height;
44325
44326 mxr_geometry_dump(mdev, &layer->geo);
44327- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44328+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44329 mxr_geometry_dump(mdev, &layer->geo);
44330 }
44331
44332@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44333 layer->geo.dst.full_width = mbus_fmt.width;
44334 layer->geo.dst.full_height = mbus_fmt.height;
44335 layer->geo.dst.field = mbus_fmt.field;
44336- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44337+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44338
44339 mxr_geometry_dump(mdev, &layer->geo);
44340 }
44341@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44342 /* set source size to highest accepted value */
44343 geo->src.full_width = max(geo->dst.full_width, pix->width);
44344 geo->src.full_height = max(geo->dst.full_height, pix->height);
44345- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44346+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44347 mxr_geometry_dump(mdev, &layer->geo);
44348 /* set cropping to total visible screen */
44349 geo->src.width = pix->width;
44350@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44351 geo->src.x_offset = 0;
44352 geo->src.y_offset = 0;
44353 /* assure consistency of geometry */
44354- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44355+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44356 mxr_geometry_dump(mdev, &layer->geo);
44357 /* set full size to lowest possible value */
44358 geo->src.full_width = 0;
44359 geo->src.full_height = 0;
44360- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44361+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44362 mxr_geometry_dump(mdev, &layer->geo);
44363
44364 /* returning results */
44365@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44366 target->width = s->r.width;
44367 target->height = s->r.height;
44368
44369- layer->ops.fix_geometry(layer, stage, s->flags);
44370+ layer->ops->fix_geometry(layer, stage, s->flags);
44371
44372 /* retrieve update selection rectangle */
44373 res.left = target->x_offset;
44374@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44375 mxr_output_get(mdev);
44376
44377 mxr_layer_update_output(layer);
44378- layer->ops.format_set(layer);
44379+ layer->ops->format_set(layer);
44380 /* enabling layer in hardware */
44381 spin_lock_irqsave(&layer->enq_slock, flags);
44382 layer->state = MXR_LAYER_STREAMING;
44383 spin_unlock_irqrestore(&layer->enq_slock, flags);
44384
44385- layer->ops.stream_set(layer, MXR_ENABLE);
44386+ layer->ops->stream_set(layer, MXR_ENABLE);
44387 mxr_streamer_get(mdev);
44388
44389 return 0;
44390@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44391 spin_unlock_irqrestore(&layer->enq_slock, flags);
44392
44393 /* disabling layer in hardware */
44394- layer->ops.stream_set(layer, MXR_DISABLE);
44395+ layer->ops->stream_set(layer, MXR_DISABLE);
44396 /* remove one streamer */
44397 mxr_streamer_put(mdev);
44398 /* allow changes in output configuration */
44399@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44400
44401 void mxr_layer_release(struct mxr_layer *layer)
44402 {
44403- if (layer->ops.release)
44404- layer->ops.release(layer);
44405+ if (layer->ops->release)
44406+ layer->ops->release(layer);
44407 }
44408
44409 void mxr_base_layer_release(struct mxr_layer *layer)
44410@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44411
44412 layer->mdev = mdev;
44413 layer->idx = idx;
44414- layer->ops = *ops;
44415+ layer->ops = ops;
44416
44417 spin_lock_init(&layer->enq_slock);
44418 INIT_LIST_HEAD(&layer->enq_list);
44419diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44420index c9388c4..ce71ece 100644
44421--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44422+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44423@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44424 {
44425 struct mxr_layer *layer;
44426 int ret;
44427- struct mxr_layer_ops ops = {
44428+ static struct mxr_layer_ops ops = {
44429 .release = mxr_vp_layer_release,
44430 .buffer_set = mxr_vp_buffer_set,
44431 .stream_set = mxr_vp_stream_set,
44432diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44433index 2d4e73b..8b4d5b6 100644
44434--- a/drivers/media/platform/vivi.c
44435+++ b/drivers/media/platform/vivi.c
44436@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44437 MODULE_LICENSE("Dual BSD/GPL");
44438 MODULE_VERSION(VIVI_VERSION);
44439
44440-static unsigned video_nr = -1;
44441-module_param(video_nr, uint, 0644);
44442+static int video_nr = -1;
44443+module_param(video_nr, int, 0644);
44444 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44445
44446 static unsigned n_devs = 1;
44447diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44448index 545c04c..a14bded 100644
44449--- a/drivers/media/radio/radio-cadet.c
44450+++ b/drivers/media/radio/radio-cadet.c
44451@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44452 unsigned char readbuf[RDS_BUFFER];
44453 int i = 0;
44454
44455+ if (count > RDS_BUFFER)
44456+ return -EFAULT;
44457 mutex_lock(&dev->lock);
44458 if (dev->rdsstat == 0)
44459 cadet_start_rds(dev);
44460@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44461 while (i < count && dev->rdsin != dev->rdsout)
44462 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44463
44464- if (i && copy_to_user(data, readbuf, i))
44465+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44466 i = -EFAULT;
44467 unlock:
44468 mutex_unlock(&dev->lock);
44469diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44470index 5236035..c622c74 100644
44471--- a/drivers/media/radio/radio-maxiradio.c
44472+++ b/drivers/media/radio/radio-maxiradio.c
44473@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44474 /* TEA5757 pin mappings */
44475 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44476
44477-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44478+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44479
44480 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44481 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44482diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44483index 050b3bb..79f62b9 100644
44484--- a/drivers/media/radio/radio-shark.c
44485+++ b/drivers/media/radio/radio-shark.c
44486@@ -79,7 +79,7 @@ struct shark_device {
44487 u32 last_val;
44488 };
44489
44490-static atomic_t shark_instance = ATOMIC_INIT(0);
44491+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44492
44493 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44494 {
44495diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44496index 8654e0d..0608a64 100644
44497--- a/drivers/media/radio/radio-shark2.c
44498+++ b/drivers/media/radio/radio-shark2.c
44499@@ -74,7 +74,7 @@ struct shark_device {
44500 u8 *transfer_buffer;
44501 };
44502
44503-static atomic_t shark_instance = ATOMIC_INIT(0);
44504+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44505
44506 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44507 {
44508diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44509index 2fd9009..278cc1e 100644
44510--- a/drivers/media/radio/radio-si476x.c
44511+++ b/drivers/media/radio/radio-si476x.c
44512@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44513 struct si476x_radio *radio;
44514 struct v4l2_ctrl *ctrl;
44515
44516- static atomic_t instance = ATOMIC_INIT(0);
44517+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44518
44519 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44520 if (!radio)
44521diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44522index a1c641e..3007da9 100644
44523--- a/drivers/media/usb/dvb-usb/cxusb.c
44524+++ b/drivers/media/usb/dvb-usb/cxusb.c
44525@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44526
44527 struct dib0700_adapter_state {
44528 int (*set_param_save) (struct dvb_frontend *);
44529-};
44530+} __no_const;
44531
44532 static int dib7070_set_param_override(struct dvb_frontend *fe)
44533 {
44534diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44535index ae0f56a..ec71784 100644
44536--- a/drivers/media/usb/dvb-usb/dw2102.c
44537+++ b/drivers/media/usb/dvb-usb/dw2102.c
44538@@ -118,7 +118,7 @@ struct su3000_state {
44539
44540 struct s6x0_state {
44541 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44542-};
44543+} __no_const;
44544
44545 /* debug */
44546 static int dvb_usb_dw2102_debug;
44547diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44548index b63a5e5..b16a062 100644
44549--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44550+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44551@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44552 __u32 reserved;
44553 };
44554
44555-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44556+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44557 enum v4l2_memory memory)
44558 {
44559 void __user *up_pln;
44560@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44561 return 0;
44562 }
44563
44564-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44565+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44566 enum v4l2_memory memory)
44567 {
44568 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44569@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44570 * by passing a very big num_planes value */
44571 uplane = compat_alloc_user_space(num_planes *
44572 sizeof(struct v4l2_plane));
44573- kp->m.planes = uplane;
44574+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44575
44576 while (--num_planes >= 0) {
44577 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44578@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44579 if (num_planes == 0)
44580 return 0;
44581
44582- uplane = kp->m.planes;
44583+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44584 if (get_user(p, &up->m.planes))
44585 return -EFAULT;
44586 uplane32 = compat_ptr(p);
44587@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44588 get_user(kp->capability, &up->capability) ||
44589 get_user(kp->flags, &up->flags))
44590 return -EFAULT;
44591- kp->base = compat_ptr(tmp);
44592+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44593 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44594 return 0;
44595 }
44596@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44597 n * sizeof(struct v4l2_ext_control32)))
44598 return -EFAULT;
44599 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44600- kp->controls = kcontrols;
44601+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44602 while (--n >= 0) {
44603 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44604 return -EFAULT;
44605@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44606 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44607 {
44608 struct v4l2_ext_control32 __user *ucontrols;
44609- struct v4l2_ext_control __user *kcontrols = kp->controls;
44610+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44611 int n = kp->count;
44612 compat_caddr_t p;
44613
44614@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44615 put_user(kp->start_block, &up->start_block) ||
44616 put_user(kp->blocks, &up->blocks) ||
44617 put_user(tmp, &up->edid) ||
44618- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44619+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44620 return -EFAULT;
44621 return 0;
44622 }
44623diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44624index 6ff002b..6b9316b 100644
44625--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44626+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44627@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44628 return 0;
44629
44630 case V4L2_CTRL_TYPE_STRING:
44631- len = strlen(c->string);
44632- if (len < ctrl->minimum)
44633+ len = strlen_user(c->string);
44634+ if (!len || len < ctrl->minimum)
44635 return -ERANGE;
44636 if ((len - ctrl->minimum) % ctrl->step)
44637 return -ERANGE;
44638diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44639index 02d1b63..5fd6b16 100644
44640--- a/drivers/media/v4l2-core/v4l2-device.c
44641+++ b/drivers/media/v4l2-core/v4l2-device.c
44642@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44643 EXPORT_SYMBOL_GPL(v4l2_device_put);
44644
44645 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44646- atomic_t *instance)
44647+ atomic_unchecked_t *instance)
44648 {
44649- int num = atomic_inc_return(instance) - 1;
44650+ int num = atomic_inc_return_unchecked(instance) - 1;
44651 int len = strlen(basename);
44652
44653 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44654diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44655index 707aef7..93b8ac0 100644
44656--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44657+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44658@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44659 struct file *file, void *fh, void *p);
44660 } u;
44661 void (*debug)(const void *arg, bool write_only);
44662-};
44663+} __do_const;
44664+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44665
44666 /* This control needs a priority check */
44667 #define INFO_FL_PRIO (1 << 0)
44668@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44669 struct video_device *vfd = video_devdata(file);
44670 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44671 bool write_only = false;
44672- struct v4l2_ioctl_info default_info;
44673+ v4l2_ioctl_info_no_const default_info;
44674 const struct v4l2_ioctl_info *info;
44675 void *fh = file->private_data;
44676 struct v4l2_fh *vfh = NULL;
44677@@ -2197,7 +2198,7 @@ done:
44678 }
44679
44680 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44681- void * __user *user_ptr, void ***kernel_ptr)
44682+ void __user **user_ptr, void ***kernel_ptr)
44683 {
44684 int ret = 0;
44685
44686@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44687 ret = -EINVAL;
44688 break;
44689 }
44690- *user_ptr = (void __user *)buf->m.planes;
44691+ *user_ptr = (void __force_user *)buf->m.planes;
44692 *kernel_ptr = (void *)&buf->m.planes;
44693 *array_size = sizeof(struct v4l2_plane) * buf->length;
44694 ret = 1;
44695@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44696 ret = -EINVAL;
44697 break;
44698 }
44699- *user_ptr = (void __user *)ctrls->controls;
44700+ *user_ptr = (void __force_user *)ctrls->controls;
44701 *kernel_ptr = (void *)&ctrls->controls;
44702 *array_size = sizeof(struct v4l2_ext_control)
44703 * ctrls->count;
44704@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44705 }
44706
44707 if (has_array_args) {
44708- *kernel_ptr = user_ptr;
44709+ *kernel_ptr = (void __force_kernel *)user_ptr;
44710 if (copy_to_user(user_ptr, mbuf, array_size))
44711 err = -EFAULT;
44712 goto out_array_args;
44713diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44714index 570b18a..f880314 100644
44715--- a/drivers/message/fusion/mptbase.c
44716+++ b/drivers/message/fusion/mptbase.c
44717@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44718 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44719 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44720
44721+#ifdef CONFIG_GRKERNSEC_HIDESYM
44722+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44723+#else
44724 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44725 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44726+#endif
44727+
44728 /*
44729 * Rounding UP to nearest 4-kB boundary here...
44730 */
44731@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44732 ioc->facts.GlobalCredits);
44733
44734 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44735+#ifdef CONFIG_GRKERNSEC_HIDESYM
44736+ NULL, NULL);
44737+#else
44738 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44739+#endif
44740 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44741 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44742 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44743diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44744index 00d339c..2ea899d 100644
44745--- a/drivers/message/fusion/mptsas.c
44746+++ b/drivers/message/fusion/mptsas.c
44747@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44748 return 0;
44749 }
44750
44751+static inline void
44752+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44753+{
44754+ if (phy_info->port_details) {
44755+ phy_info->port_details->rphy = rphy;
44756+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44757+ ioc->name, rphy));
44758+ }
44759+
44760+ if (rphy) {
44761+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44762+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44763+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44764+ ioc->name, rphy, rphy->dev.release));
44765+ }
44766+}
44767+
44768 /* no mutex */
44769 static void
44770 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44771@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44772 return NULL;
44773 }
44774
44775-static inline void
44776-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44777-{
44778- if (phy_info->port_details) {
44779- phy_info->port_details->rphy = rphy;
44780- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44781- ioc->name, rphy));
44782- }
44783-
44784- if (rphy) {
44785- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44786- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44787- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44788- ioc->name, rphy, rphy->dev.release));
44789- }
44790-}
44791-
44792 static inline struct sas_port *
44793 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44794 {
44795diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44796index 727819c..ad74694 100644
44797--- a/drivers/message/fusion/mptscsih.c
44798+++ b/drivers/message/fusion/mptscsih.c
44799@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44800
44801 h = shost_priv(SChost);
44802
44803- if (h) {
44804- if (h->info_kbuf == NULL)
44805- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44806- return h->info_kbuf;
44807- h->info_kbuf[0] = '\0';
44808+ if (!h)
44809+ return NULL;
44810
44811- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44812- h->info_kbuf[size-1] = '\0';
44813- }
44814+ if (h->info_kbuf == NULL)
44815+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44816+ return h->info_kbuf;
44817+ h->info_kbuf[0] = '\0';
44818+
44819+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44820+ h->info_kbuf[size-1] = '\0';
44821
44822 return h->info_kbuf;
44823 }
44824diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44825index b7d87cd..3fb36da 100644
44826--- a/drivers/message/i2o/i2o_proc.c
44827+++ b/drivers/message/i2o/i2o_proc.c
44828@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44829 "Array Controller Device"
44830 };
44831
44832-static char *chtostr(char *tmp, u8 *chars, int n)
44833-{
44834- tmp[0] = 0;
44835- return strncat(tmp, (char *)chars, n);
44836-}
44837-
44838 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44839 char *group)
44840 {
44841@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44842 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44843 {
44844 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44845- static u32 work32[5];
44846- static u8 *work8 = (u8 *) work32;
44847- static u16 *work16 = (u16 *) work32;
44848+ u32 work32[5];
44849+ u8 *work8 = (u8 *) work32;
44850+ u16 *work16 = (u16 *) work32;
44851 int token;
44852 u32 hwcap;
44853
44854@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44855 } *result;
44856
44857 i2o_exec_execute_ddm_table ddm_table;
44858- char tmp[28 + 1];
44859
44860 result = kmalloc(sizeof(*result), GFP_KERNEL);
44861 if (!result)
44862@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44863
44864 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44865 seq_printf(seq, "%-#8x", ddm_table.module_id);
44866- seq_printf(seq, "%-29s",
44867- chtostr(tmp, ddm_table.module_name_version, 28));
44868+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44869 seq_printf(seq, "%9d ", ddm_table.data_size);
44870 seq_printf(seq, "%8d", ddm_table.code_size);
44871
44872@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44873
44874 i2o_driver_result_table *result;
44875 i2o_driver_store_table *dst;
44876- char tmp[28 + 1];
44877
44878 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44879 if (result == NULL)
44880@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44881
44882 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44883 seq_printf(seq, "%-#8x", dst->module_id);
44884- seq_printf(seq, "%-29s",
44885- chtostr(tmp, dst->module_name_version, 28));
44886- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44887+ seq_printf(seq, "%-.28s", dst->module_name_version);
44888+ seq_printf(seq, "%-.8s", dst->date);
44889 seq_printf(seq, "%8d ", dst->module_size);
44890 seq_printf(seq, "%8d ", dst->mpb_size);
44891 seq_printf(seq, "0x%04x", dst->module_flags);
44892@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44893 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44894 {
44895 struct i2o_device *d = (struct i2o_device *)seq->private;
44896- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44897+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44898 // == (allow) 512d bytes (max)
44899- static u16 *work16 = (u16 *) work32;
44900+ u16 *work16 = (u16 *) work32;
44901 int token;
44902- char tmp[16 + 1];
44903
44904 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44905
44906@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44907 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44908 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44909 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44910- seq_printf(seq, "Vendor info : %s\n",
44911- chtostr(tmp, (u8 *) (work32 + 2), 16));
44912- seq_printf(seq, "Product info : %s\n",
44913- chtostr(tmp, (u8 *) (work32 + 6), 16));
44914- seq_printf(seq, "Description : %s\n",
44915- chtostr(tmp, (u8 *) (work32 + 10), 16));
44916- seq_printf(seq, "Product rev. : %s\n",
44917- chtostr(tmp, (u8 *) (work32 + 14), 8));
44918+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44919+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44920+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44921+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44922
44923 seq_printf(seq, "Serial number : ");
44924 print_serial_number(seq, (u8 *) (work32 + 16),
44925@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44926 u8 pad[256]; // allow up to 256 byte (max) serial number
44927 } result;
44928
44929- char tmp[24 + 1];
44930-
44931 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44932
44933 if (token < 0) {
44934@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44935 }
44936
44937 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44938- seq_printf(seq, "Module name : %s\n",
44939- chtostr(tmp, result.module_name, 24));
44940- seq_printf(seq, "Module revision : %s\n",
44941- chtostr(tmp, result.module_rev, 8));
44942+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44943+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44944
44945 seq_printf(seq, "Serial number : ");
44946 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44947@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44948 u8 instance_number[4];
44949 } result;
44950
44951- char tmp[64 + 1];
44952-
44953 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44954
44955 if (token < 0) {
44956@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44957 return 0;
44958 }
44959
44960- seq_printf(seq, "Device name : %s\n",
44961- chtostr(tmp, result.device_name, 64));
44962- seq_printf(seq, "Service name : %s\n",
44963- chtostr(tmp, result.service_name, 64));
44964- seq_printf(seq, "Physical name : %s\n",
44965- chtostr(tmp, result.physical_location, 64));
44966- seq_printf(seq, "Instance number : %s\n",
44967- chtostr(tmp, result.instance_number, 4));
44968+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44969+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44970+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44971+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44972
44973 return 0;
44974 }
44975@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44976 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44977 {
44978 struct i2o_device *d = (struct i2o_device *)seq->private;
44979- static u32 work32[12];
44980- static u16 *work16 = (u16 *) work32;
44981- static u8 *work8 = (u8 *) work32;
44982+ u32 work32[12];
44983+ u16 *work16 = (u16 *) work32;
44984+ u8 *work8 = (u8 *) work32;
44985 int token;
44986
44987 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44988diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44989index a8c08f3..155fe3d 100644
44990--- a/drivers/message/i2o/iop.c
44991+++ b/drivers/message/i2o/iop.c
44992@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44993
44994 spin_lock_irqsave(&c->context_list_lock, flags);
44995
44996- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44997- atomic_inc(&c->context_list_counter);
44998+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44999+ atomic_inc_unchecked(&c->context_list_counter);
45000
45001- entry->context = atomic_read(&c->context_list_counter);
45002+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45003
45004 list_add(&entry->list, &c->context_list);
45005
45006@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45007
45008 #if BITS_PER_LONG == 64
45009 spin_lock_init(&c->context_list_lock);
45010- atomic_set(&c->context_list_counter, 0);
45011+ atomic_set_unchecked(&c->context_list_counter, 0);
45012 INIT_LIST_HEAD(&c->context_list);
45013 #endif
45014
45015diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45016index d1a22aa..d0f7bf7 100644
45017--- a/drivers/mfd/ab8500-debugfs.c
45018+++ b/drivers/mfd/ab8500-debugfs.c
45019@@ -100,7 +100,7 @@ static int irq_last;
45020 static u32 *irq_count;
45021 static int num_irqs;
45022
45023-static struct device_attribute **dev_attr;
45024+static device_attribute_no_const **dev_attr;
45025 static char **event_name;
45026
45027 static u8 avg_sample = SAMPLE_16;
45028diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45029index 81b7d88..95ae998 100644
45030--- a/drivers/mfd/janz-cmodio.c
45031+++ b/drivers/mfd/janz-cmodio.c
45032@@ -13,6 +13,7 @@
45033
45034 #include <linux/kernel.h>
45035 #include <linux/module.h>
45036+#include <linux/slab.h>
45037 #include <linux/init.h>
45038 #include <linux/pci.h>
45039 #include <linux/interrupt.h>
45040diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45041index a83eed5..62a58a9 100644
45042--- a/drivers/mfd/max8925-i2c.c
45043+++ b/drivers/mfd/max8925-i2c.c
45044@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45045 const struct i2c_device_id *id)
45046 {
45047 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45048- static struct max8925_chip *chip;
45049+ struct max8925_chip *chip;
45050 struct device_node *node = client->dev.of_node;
45051
45052 if (node && !pdata) {
45053diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45054index d657331..0d9a80f 100644
45055--- a/drivers/mfd/tps65910.c
45056+++ b/drivers/mfd/tps65910.c
45057@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45058 struct tps65910_platform_data *pdata)
45059 {
45060 int ret = 0;
45061- static struct regmap_irq_chip *tps6591x_irqs_chip;
45062+ struct regmap_irq_chip *tps6591x_irqs_chip;
45063
45064 if (!irq) {
45065 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45066diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45067index 9aa6d1e..1631bfc 100644
45068--- a/drivers/mfd/twl4030-irq.c
45069+++ b/drivers/mfd/twl4030-irq.c
45070@@ -35,6 +35,7 @@
45071 #include <linux/of.h>
45072 #include <linux/irqdomain.h>
45073 #include <linux/i2c/twl.h>
45074+#include <asm/pgtable.h>
45075
45076 #include "twl-core.h"
45077
45078@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45079 * Install an irq handler for each of the SIH modules;
45080 * clone dummy irq_chip since PIH can't *do* anything
45081 */
45082- twl4030_irq_chip = dummy_irq_chip;
45083- twl4030_irq_chip.name = "twl4030";
45084+ pax_open_kernel();
45085+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45086+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45087
45088- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45089+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45090+ pax_close_kernel();
45091
45092 for (i = irq_base; i < irq_end; i++) {
45093 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45094diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45095index 464419b..64bae8d 100644
45096--- a/drivers/misc/c2port/core.c
45097+++ b/drivers/misc/c2port/core.c
45098@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45099 goto error_idr_alloc;
45100 c2dev->id = ret;
45101
45102- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45103+ pax_open_kernel();
45104+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45105+ pax_close_kernel();
45106
45107 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45108 "c2port%d", c2dev->id);
45109diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45110index 9c34e57..b981cda 100644
45111--- a/drivers/misc/eeprom/sunxi_sid.c
45112+++ b/drivers/misc/eeprom/sunxi_sid.c
45113@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45114
45115 platform_set_drvdata(pdev, sid_data);
45116
45117- sid_bin_attr.size = sid_data->keysize;
45118+ pax_open_kernel();
45119+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45120+ pax_close_kernel();
45121 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45122 return -ENODEV;
45123
45124diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45125index 36f5d52..32311c3 100644
45126--- a/drivers/misc/kgdbts.c
45127+++ b/drivers/misc/kgdbts.c
45128@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45129 char before[BREAK_INSTR_SIZE];
45130 char after[BREAK_INSTR_SIZE];
45131
45132- probe_kernel_read(before, (char *)kgdbts_break_test,
45133+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45134 BREAK_INSTR_SIZE);
45135 init_simple_test();
45136 ts.tst = plant_and_detach_test;
45137@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45138 /* Activate test with initial breakpoint */
45139 if (!is_early)
45140 kgdb_breakpoint();
45141- probe_kernel_read(after, (char *)kgdbts_break_test,
45142+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45143 BREAK_INSTR_SIZE);
45144 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45145 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45146diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45147index 036effe..b3a6336 100644
45148--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45149+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45150@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45151 * the lid is closed. This leads to interrupts as soon as a little move
45152 * is done.
45153 */
45154- atomic_inc(&lis3->count);
45155+ atomic_inc_unchecked(&lis3->count);
45156
45157 wake_up_interruptible(&lis3->misc_wait);
45158 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45159@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45160 if (lis3->pm_dev)
45161 pm_runtime_get_sync(lis3->pm_dev);
45162
45163- atomic_set(&lis3->count, 0);
45164+ atomic_set_unchecked(&lis3->count, 0);
45165 return 0;
45166 }
45167
45168@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45169 add_wait_queue(&lis3->misc_wait, &wait);
45170 while (true) {
45171 set_current_state(TASK_INTERRUPTIBLE);
45172- data = atomic_xchg(&lis3->count, 0);
45173+ data = atomic_xchg_unchecked(&lis3->count, 0);
45174 if (data)
45175 break;
45176
45177@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45178 struct lis3lv02d, miscdev);
45179
45180 poll_wait(file, &lis3->misc_wait, wait);
45181- if (atomic_read(&lis3->count))
45182+ if (atomic_read_unchecked(&lis3->count))
45183 return POLLIN | POLLRDNORM;
45184 return 0;
45185 }
45186diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45187index c439c82..1f20f57 100644
45188--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45189+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45190@@ -297,7 +297,7 @@ struct lis3lv02d {
45191 struct input_polled_dev *idev; /* input device */
45192 struct platform_device *pdev; /* platform device */
45193 struct regulator_bulk_data regulators[2];
45194- atomic_t count; /* interrupt count after last read */
45195+ atomic_unchecked_t count; /* interrupt count after last read */
45196 union axis_conversion ac; /* hw -> logical axis */
45197 int mapped_btns[3];
45198
45199diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45200index 2f30bad..c4c13d0 100644
45201--- a/drivers/misc/sgi-gru/gruhandles.c
45202+++ b/drivers/misc/sgi-gru/gruhandles.c
45203@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45204 unsigned long nsec;
45205
45206 nsec = CLKS2NSEC(clks);
45207- atomic_long_inc(&mcs_op_statistics[op].count);
45208- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45209+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45210+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45211 if (mcs_op_statistics[op].max < nsec)
45212 mcs_op_statistics[op].max = nsec;
45213 }
45214diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45215index 4f76359..cdfcb2e 100644
45216--- a/drivers/misc/sgi-gru/gruprocfs.c
45217+++ b/drivers/misc/sgi-gru/gruprocfs.c
45218@@ -32,9 +32,9 @@
45219
45220 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45221
45222-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45223+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45224 {
45225- unsigned long val = atomic_long_read(v);
45226+ unsigned long val = atomic_long_read_unchecked(v);
45227
45228 seq_printf(s, "%16lu %s\n", val, id);
45229 }
45230@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45231
45232 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45233 for (op = 0; op < mcsop_last; op++) {
45234- count = atomic_long_read(&mcs_op_statistics[op].count);
45235- total = atomic_long_read(&mcs_op_statistics[op].total);
45236+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45237+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45238 max = mcs_op_statistics[op].max;
45239 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45240 count ? total / count : 0, max);
45241diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45242index 5c3ce24..4915ccb 100644
45243--- a/drivers/misc/sgi-gru/grutables.h
45244+++ b/drivers/misc/sgi-gru/grutables.h
45245@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45246 * GRU statistics.
45247 */
45248 struct gru_stats_s {
45249- atomic_long_t vdata_alloc;
45250- atomic_long_t vdata_free;
45251- atomic_long_t gts_alloc;
45252- atomic_long_t gts_free;
45253- atomic_long_t gms_alloc;
45254- atomic_long_t gms_free;
45255- atomic_long_t gts_double_allocate;
45256- atomic_long_t assign_context;
45257- atomic_long_t assign_context_failed;
45258- atomic_long_t free_context;
45259- atomic_long_t load_user_context;
45260- atomic_long_t load_kernel_context;
45261- atomic_long_t lock_kernel_context;
45262- atomic_long_t unlock_kernel_context;
45263- atomic_long_t steal_user_context;
45264- atomic_long_t steal_kernel_context;
45265- atomic_long_t steal_context_failed;
45266- atomic_long_t nopfn;
45267- atomic_long_t asid_new;
45268- atomic_long_t asid_next;
45269- atomic_long_t asid_wrap;
45270- atomic_long_t asid_reuse;
45271- atomic_long_t intr;
45272- atomic_long_t intr_cbr;
45273- atomic_long_t intr_tfh;
45274- atomic_long_t intr_spurious;
45275- atomic_long_t intr_mm_lock_failed;
45276- atomic_long_t call_os;
45277- atomic_long_t call_os_wait_queue;
45278- atomic_long_t user_flush_tlb;
45279- atomic_long_t user_unload_context;
45280- atomic_long_t user_exception;
45281- atomic_long_t set_context_option;
45282- atomic_long_t check_context_retarget_intr;
45283- atomic_long_t check_context_unload;
45284- atomic_long_t tlb_dropin;
45285- atomic_long_t tlb_preload_page;
45286- atomic_long_t tlb_dropin_fail_no_asid;
45287- atomic_long_t tlb_dropin_fail_upm;
45288- atomic_long_t tlb_dropin_fail_invalid;
45289- atomic_long_t tlb_dropin_fail_range_active;
45290- atomic_long_t tlb_dropin_fail_idle;
45291- atomic_long_t tlb_dropin_fail_fmm;
45292- atomic_long_t tlb_dropin_fail_no_exception;
45293- atomic_long_t tfh_stale_on_fault;
45294- atomic_long_t mmu_invalidate_range;
45295- atomic_long_t mmu_invalidate_page;
45296- atomic_long_t flush_tlb;
45297- atomic_long_t flush_tlb_gru;
45298- atomic_long_t flush_tlb_gru_tgh;
45299- atomic_long_t flush_tlb_gru_zero_asid;
45300+ atomic_long_unchecked_t vdata_alloc;
45301+ atomic_long_unchecked_t vdata_free;
45302+ atomic_long_unchecked_t gts_alloc;
45303+ atomic_long_unchecked_t gts_free;
45304+ atomic_long_unchecked_t gms_alloc;
45305+ atomic_long_unchecked_t gms_free;
45306+ atomic_long_unchecked_t gts_double_allocate;
45307+ atomic_long_unchecked_t assign_context;
45308+ atomic_long_unchecked_t assign_context_failed;
45309+ atomic_long_unchecked_t free_context;
45310+ atomic_long_unchecked_t load_user_context;
45311+ atomic_long_unchecked_t load_kernel_context;
45312+ atomic_long_unchecked_t lock_kernel_context;
45313+ atomic_long_unchecked_t unlock_kernel_context;
45314+ atomic_long_unchecked_t steal_user_context;
45315+ atomic_long_unchecked_t steal_kernel_context;
45316+ atomic_long_unchecked_t steal_context_failed;
45317+ atomic_long_unchecked_t nopfn;
45318+ atomic_long_unchecked_t asid_new;
45319+ atomic_long_unchecked_t asid_next;
45320+ atomic_long_unchecked_t asid_wrap;
45321+ atomic_long_unchecked_t asid_reuse;
45322+ atomic_long_unchecked_t intr;
45323+ atomic_long_unchecked_t intr_cbr;
45324+ atomic_long_unchecked_t intr_tfh;
45325+ atomic_long_unchecked_t intr_spurious;
45326+ atomic_long_unchecked_t intr_mm_lock_failed;
45327+ atomic_long_unchecked_t call_os;
45328+ atomic_long_unchecked_t call_os_wait_queue;
45329+ atomic_long_unchecked_t user_flush_tlb;
45330+ atomic_long_unchecked_t user_unload_context;
45331+ atomic_long_unchecked_t user_exception;
45332+ atomic_long_unchecked_t set_context_option;
45333+ atomic_long_unchecked_t check_context_retarget_intr;
45334+ atomic_long_unchecked_t check_context_unload;
45335+ atomic_long_unchecked_t tlb_dropin;
45336+ atomic_long_unchecked_t tlb_preload_page;
45337+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45338+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45339+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45340+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45341+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45342+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45343+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45344+ atomic_long_unchecked_t tfh_stale_on_fault;
45345+ atomic_long_unchecked_t mmu_invalidate_range;
45346+ atomic_long_unchecked_t mmu_invalidate_page;
45347+ atomic_long_unchecked_t flush_tlb;
45348+ atomic_long_unchecked_t flush_tlb_gru;
45349+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45350+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45351
45352- atomic_long_t copy_gpa;
45353- atomic_long_t read_gpa;
45354+ atomic_long_unchecked_t copy_gpa;
45355+ atomic_long_unchecked_t read_gpa;
45356
45357- atomic_long_t mesq_receive;
45358- atomic_long_t mesq_receive_none;
45359- atomic_long_t mesq_send;
45360- atomic_long_t mesq_send_failed;
45361- atomic_long_t mesq_noop;
45362- atomic_long_t mesq_send_unexpected_error;
45363- atomic_long_t mesq_send_lb_overflow;
45364- atomic_long_t mesq_send_qlimit_reached;
45365- atomic_long_t mesq_send_amo_nacked;
45366- atomic_long_t mesq_send_put_nacked;
45367- atomic_long_t mesq_page_overflow;
45368- atomic_long_t mesq_qf_locked;
45369- atomic_long_t mesq_qf_noop_not_full;
45370- atomic_long_t mesq_qf_switch_head_failed;
45371- atomic_long_t mesq_qf_unexpected_error;
45372- atomic_long_t mesq_noop_unexpected_error;
45373- atomic_long_t mesq_noop_lb_overflow;
45374- atomic_long_t mesq_noop_qlimit_reached;
45375- atomic_long_t mesq_noop_amo_nacked;
45376- atomic_long_t mesq_noop_put_nacked;
45377- atomic_long_t mesq_noop_page_overflow;
45378+ atomic_long_unchecked_t mesq_receive;
45379+ atomic_long_unchecked_t mesq_receive_none;
45380+ atomic_long_unchecked_t mesq_send;
45381+ atomic_long_unchecked_t mesq_send_failed;
45382+ atomic_long_unchecked_t mesq_noop;
45383+ atomic_long_unchecked_t mesq_send_unexpected_error;
45384+ atomic_long_unchecked_t mesq_send_lb_overflow;
45385+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45386+ atomic_long_unchecked_t mesq_send_amo_nacked;
45387+ atomic_long_unchecked_t mesq_send_put_nacked;
45388+ atomic_long_unchecked_t mesq_page_overflow;
45389+ atomic_long_unchecked_t mesq_qf_locked;
45390+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45391+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45392+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45393+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45394+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45395+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45396+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45397+ atomic_long_unchecked_t mesq_noop_put_nacked;
45398+ atomic_long_unchecked_t mesq_noop_page_overflow;
45399
45400 };
45401
45402@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45403 tghop_invalidate, mcsop_last};
45404
45405 struct mcs_op_statistic {
45406- atomic_long_t count;
45407- atomic_long_t total;
45408+ atomic_long_unchecked_t count;
45409+ atomic_long_unchecked_t total;
45410 unsigned long max;
45411 };
45412
45413@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45414
45415 #define STAT(id) do { \
45416 if (gru_options & OPT_STATS) \
45417- atomic_long_inc(&gru_stats.id); \
45418+ atomic_long_inc_unchecked(&gru_stats.id); \
45419 } while (0)
45420
45421 #ifdef CONFIG_SGI_GRU_DEBUG
45422diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45423index c862cd4..0d176fe 100644
45424--- a/drivers/misc/sgi-xp/xp.h
45425+++ b/drivers/misc/sgi-xp/xp.h
45426@@ -288,7 +288,7 @@ struct xpc_interface {
45427 xpc_notify_func, void *);
45428 void (*received) (short, int, void *);
45429 enum xp_retval (*partid_to_nasids) (short, void *);
45430-};
45431+} __no_const;
45432
45433 extern struct xpc_interface xpc_interface;
45434
45435diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45436index 01be66d..e3a0c7e 100644
45437--- a/drivers/misc/sgi-xp/xp_main.c
45438+++ b/drivers/misc/sgi-xp/xp_main.c
45439@@ -78,13 +78,13 @@ xpc_notloaded(void)
45440 }
45441
45442 struct xpc_interface xpc_interface = {
45443- (void (*)(int))xpc_notloaded,
45444- (void (*)(int))xpc_notloaded,
45445- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45446- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45447+ .connect = (void (*)(int))xpc_notloaded,
45448+ .disconnect = (void (*)(int))xpc_notloaded,
45449+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45450+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45451 void *))xpc_notloaded,
45452- (void (*)(short, int, void *))xpc_notloaded,
45453- (enum xp_retval(*)(short, void *))xpc_notloaded
45454+ .received = (void (*)(short, int, void *))xpc_notloaded,
45455+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45456 };
45457 EXPORT_SYMBOL_GPL(xpc_interface);
45458
45459diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45460index b94d5f7..7f494c5 100644
45461--- a/drivers/misc/sgi-xp/xpc.h
45462+++ b/drivers/misc/sgi-xp/xpc.h
45463@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45464 void (*received_payload) (struct xpc_channel *, void *);
45465 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45466 };
45467+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45468
45469 /* struct xpc_partition act_state values (for XPC HB) */
45470
45471@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45472 /* found in xpc_main.c */
45473 extern struct device *xpc_part;
45474 extern struct device *xpc_chan;
45475-extern struct xpc_arch_operations xpc_arch_ops;
45476+extern xpc_arch_operations_no_const xpc_arch_ops;
45477 extern int xpc_disengage_timelimit;
45478 extern int xpc_disengage_timedout;
45479 extern int xpc_activate_IRQ_rcvd;
45480diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45481index 82dc574..8539ab2 100644
45482--- a/drivers/misc/sgi-xp/xpc_main.c
45483+++ b/drivers/misc/sgi-xp/xpc_main.c
45484@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45485 .notifier_call = xpc_system_die,
45486 };
45487
45488-struct xpc_arch_operations xpc_arch_ops;
45489+xpc_arch_operations_no_const xpc_arch_ops;
45490
45491 /*
45492 * Timer function to enforce the timelimit on the partition disengage.
45493@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45494
45495 if (((die_args->trapnr == X86_TRAP_MF) ||
45496 (die_args->trapnr == X86_TRAP_XF)) &&
45497- !user_mode_vm(die_args->regs))
45498+ !user_mode(die_args->regs))
45499 xpc_die_deactivate();
45500
45501 break;
45502diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45503index 7b5424f..ed1d6ac 100644
45504--- a/drivers/mmc/card/block.c
45505+++ b/drivers/mmc/card/block.c
45506@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45507 if (idata->ic.postsleep_min_us)
45508 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45509
45510- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45511+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45512 err = -EFAULT;
45513 goto cmd_rel_host;
45514 }
45515diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45516index e5b5eeb..7bf2212 100644
45517--- a/drivers/mmc/core/mmc_ops.c
45518+++ b/drivers/mmc/core/mmc_ops.c
45519@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45520 void *data_buf;
45521 int is_on_stack;
45522
45523- is_on_stack = object_is_on_stack(buf);
45524+ is_on_stack = object_starts_on_stack(buf);
45525 if (is_on_stack) {
45526 /*
45527 * dma onto stack is unsafe/nonportable, but callers to this
45528diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45529index 6bf24ab..13d0293b 100644
45530--- a/drivers/mmc/host/dw_mmc.h
45531+++ b/drivers/mmc/host/dw_mmc.h
45532@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45533 int (*parse_dt)(struct dw_mci *host);
45534 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45535 struct dw_mci_tuning_data *tuning_data);
45536-};
45537+} __do_const;
45538 #endif /* _DW_MMC_H_ */
45539diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45540index b931226..df6a085 100644
45541--- a/drivers/mmc/host/mmci.c
45542+++ b/drivers/mmc/host/mmci.c
45543@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45544 }
45545
45546 if (variant->busy_detect) {
45547- mmci_ops.card_busy = mmci_card_busy;
45548+ pax_open_kernel();
45549+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45550+ pax_close_kernel();
45551 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45552 }
45553
45554diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45555index b841bb7..d82712f5 100644
45556--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45557+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45558@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45559 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45560 }
45561
45562- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45563- sdhci_esdhc_ops.platform_execute_tuning =
45564+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45565+ pax_open_kernel();
45566+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45567 esdhc_executing_tuning;
45568+ pax_close_kernel();
45569+ }
45570
45571 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45572 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45573diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45574index 6debda9..2ba7427 100644
45575--- a/drivers/mmc/host/sdhci-s3c.c
45576+++ b/drivers/mmc/host/sdhci-s3c.c
45577@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45578 * we can use overriding functions instead of default.
45579 */
45580 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45581- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45582- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45583- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45584+ pax_open_kernel();
45585+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45586+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45587+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45588+ pax_close_kernel();
45589 }
45590
45591 /* It supports additional host capabilities if needed */
45592diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45593index 096993f..f02c23b 100644
45594--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45595+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45596@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45597 size_t totlen = 0, thislen;
45598 int ret = 0;
45599 size_t buflen = 0;
45600- static char *buffer;
45601+ char *buffer;
45602
45603 if (!ECCBUF_SIZE) {
45604 /* We should fall back to a general writev implementation.
45605diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45606index c07cd57..61c4fbd 100644
45607--- a/drivers/mtd/nand/denali.c
45608+++ b/drivers/mtd/nand/denali.c
45609@@ -24,6 +24,7 @@
45610 #include <linux/slab.h>
45611 #include <linux/mtd/mtd.h>
45612 #include <linux/module.h>
45613+#include <linux/slab.h>
45614
45615 #include "denali.h"
45616
45617diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45618index ca6369f..0ce9fed 100644
45619--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45620+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45621@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45622
45623 /* first try to map the upper buffer directly */
45624 if (virt_addr_valid(this->upper_buf) &&
45625- !object_is_on_stack(this->upper_buf)) {
45626+ !object_starts_on_stack(this->upper_buf)) {
45627 sg_init_one(sgl, this->upper_buf, this->upper_len);
45628 ret = dma_map_sg(this->dev, sgl, 1, dr);
45629 if (ret == 0)
45630diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45631index 51b9d6a..52af9a7 100644
45632--- a/drivers/mtd/nftlmount.c
45633+++ b/drivers/mtd/nftlmount.c
45634@@ -24,6 +24,7 @@
45635 #include <asm/errno.h>
45636 #include <linux/delay.h>
45637 #include <linux/slab.h>
45638+#include <linux/sched.h>
45639 #include <linux/mtd/mtd.h>
45640 #include <linux/mtd/nand.h>
45641 #include <linux/mtd/nftl.h>
45642diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45643index 4b8e895..6b3c498 100644
45644--- a/drivers/mtd/sm_ftl.c
45645+++ b/drivers/mtd/sm_ftl.c
45646@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45647 #define SM_CIS_VENDOR_OFFSET 0x59
45648 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45649 {
45650- struct attribute_group *attr_group;
45651+ attribute_group_no_const *attr_group;
45652 struct attribute **attributes;
45653 struct sm_sysfs_attribute *vendor_attribute;
45654
45655diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45656index e5628fc..ffe54d1 100644
45657--- a/drivers/net/bonding/bond_main.c
45658+++ b/drivers/net/bonding/bond_main.c
45659@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45660
45661 bond_netlink_fini();
45662 unregister_pernet_subsys(&bond_net_ops);
45663+ rtnl_link_unregister(&bond_link_ops);
45664
45665 #ifdef CONFIG_NET_POLL_CONTROLLER
45666 /*
45667diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45668index 70651f8..7eb1bdf 100644
45669--- a/drivers/net/bonding/bond_netlink.c
45670+++ b/drivers/net/bonding/bond_netlink.c
45671@@ -542,7 +542,7 @@ nla_put_failure:
45672 return -EMSGSIZE;
45673 }
45674
45675-struct rtnl_link_ops bond_link_ops __read_mostly = {
45676+struct rtnl_link_ops bond_link_ops = {
45677 .kind = "bond",
45678 .priv_size = sizeof(struct bonding),
45679 .setup = bond_setup,
45680diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45681index 9e7d95d..d447b88 100644
45682--- a/drivers/net/can/Kconfig
45683+++ b/drivers/net/can/Kconfig
45684@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45685
45686 config CAN_FLEXCAN
45687 tristate "Support for Freescale FLEXCAN based chips"
45688- depends on ARM || PPC
45689+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45690 ---help---
45691 Say Y here if you want to support for Freescale FlexCAN.
45692
45693diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45694index 455d4c3..3353ee7 100644
45695--- a/drivers/net/ethernet/8390/ax88796.c
45696+++ b/drivers/net/ethernet/8390/ax88796.c
45697@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45698 if (ax->plat->reg_offsets)
45699 ei_local->reg_offset = ax->plat->reg_offsets;
45700 else {
45701+ resource_size_t _mem_size = mem_size;
45702+ do_div(_mem_size, 0x18);
45703 ei_local->reg_offset = ax->reg_offsets;
45704 for (ret = 0; ret < 0x18; ret++)
45705- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45706+ ax->reg_offsets[ret] = _mem_size * ret;
45707 }
45708
45709 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45710diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45711index a89a40f..5a8a2ac 100644
45712--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45713+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45714@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45715 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45716 {
45717 /* RX_MODE controlling object */
45718- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45719+ bnx2x_init_rx_mode_obj(bp);
45720
45721 /* multicast configuration controlling object */
45722 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45723diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45724index 0fb6ff2..78fd55c 100644
45725--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45726+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45727@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45728 return rc;
45729 }
45730
45731-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45732- struct bnx2x_rx_mode_obj *o)
45733+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45734 {
45735 if (CHIP_IS_E1x(bp)) {
45736- o->wait_comp = bnx2x_empty_rx_mode_wait;
45737- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45738+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45739+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45740 } else {
45741- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45742- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45743+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45744+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45745 }
45746 }
45747
45748diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45749index 00d7f21..2cddec4 100644
45750--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45751+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45752@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45753
45754 /********************* RX MODE ****************/
45755
45756-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45757- struct bnx2x_rx_mode_obj *o);
45758+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45759
45760 /**
45761 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45762diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45763index 04321e5..b51cdc4 100644
45764--- a/drivers/net/ethernet/broadcom/tg3.h
45765+++ b/drivers/net/ethernet/broadcom/tg3.h
45766@@ -150,6 +150,7 @@
45767 #define CHIPREV_ID_5750_A0 0x4000
45768 #define CHIPREV_ID_5750_A1 0x4001
45769 #define CHIPREV_ID_5750_A3 0x4003
45770+#define CHIPREV_ID_5750_C1 0x4201
45771 #define CHIPREV_ID_5750_C2 0x4202
45772 #define CHIPREV_ID_5752_A0_HW 0x5000
45773 #define CHIPREV_ID_5752_A0 0x6000
45774diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45775index 13f9636..228040f 100644
45776--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45777+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45778@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45779 }
45780
45781 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45782- bna_cb_ioceth_enable,
45783- bna_cb_ioceth_disable,
45784- bna_cb_ioceth_hbfail,
45785- bna_cb_ioceth_reset
45786+ .enable_cbfn = bna_cb_ioceth_enable,
45787+ .disable_cbfn = bna_cb_ioceth_disable,
45788+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45789+ .reset_cbfn = bna_cb_ioceth_reset
45790 };
45791
45792 static void bna_attr_init(struct bna_ioceth *ioceth)
45793diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45794index 8cffcdf..aadf043 100644
45795--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45796+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45797@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45798 */
45799 struct l2t_skb_cb {
45800 arp_failure_handler_func arp_failure_handler;
45801-};
45802+} __no_const;
45803
45804 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45805
45806diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45807index 34e2488..07e2079 100644
45808--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45809+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45810@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45811
45812 int i;
45813 struct adapter *ap = netdev2adap(dev);
45814- static const unsigned int *reg_ranges;
45815+ const unsigned int *reg_ranges;
45816 int arr_size = 0, buf_size = 0;
45817
45818 if (is_t4(ap->params.chip)) {
45819diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45820index c05b66d..ed69872 100644
45821--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45822+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45823@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45824 for (i=0; i<ETH_ALEN; i++) {
45825 tmp.addr[i] = dev->dev_addr[i];
45826 }
45827- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45828+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45829 break;
45830
45831 case DE4X5_SET_HWADDR: /* Set the hardware address */
45832@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45833 spin_lock_irqsave(&lp->lock, flags);
45834 memcpy(&statbuf, &lp->pktStats, ioc->len);
45835 spin_unlock_irqrestore(&lp->lock, flags);
45836- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45837+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45838 return -EFAULT;
45839 break;
45840 }
45841diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45842index 36c8061..ca5e1e0 100644
45843--- a/drivers/net/ethernet/emulex/benet/be_main.c
45844+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45845@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45846
45847 if (wrapped)
45848 newacc += 65536;
45849- ACCESS_ONCE(*acc) = newacc;
45850+ ACCESS_ONCE_RW(*acc) = newacc;
45851 }
45852
45853 static void populate_erx_stats(struct be_adapter *adapter,
45854diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45855index c11ecbc..13bb299 100644
45856--- a/drivers/net/ethernet/faraday/ftgmac100.c
45857+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45858@@ -30,6 +30,8 @@
45859 #include <linux/netdevice.h>
45860 #include <linux/phy.h>
45861 #include <linux/platform_device.h>
45862+#include <linux/interrupt.h>
45863+#include <linux/irqreturn.h>
45864 #include <net/ip.h>
45865
45866 #include "ftgmac100.h"
45867diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45868index 8be5b40..081bc1b 100644
45869--- a/drivers/net/ethernet/faraday/ftmac100.c
45870+++ b/drivers/net/ethernet/faraday/ftmac100.c
45871@@ -31,6 +31,8 @@
45872 #include <linux/module.h>
45873 #include <linux/netdevice.h>
45874 #include <linux/platform_device.h>
45875+#include <linux/interrupt.h>
45876+#include <linux/irqreturn.h>
45877
45878 #include "ftmac100.h"
45879
45880diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45881index e33ec6c..f54cfe7 100644
45882--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45883+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45884@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45885 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45886
45887 /* Update the base adjustement value. */
45888- ACCESS_ONCE(pf->ptp_base_adj) = incval;
45889+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45890 smp_mb(); /* Force the above update. */
45891 }
45892
45893diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45894index 5184e2a..acb28c3 100644
45895--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45896+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45897@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45898 }
45899
45900 /* update the base incval used to calculate frequency adjustment */
45901- ACCESS_ONCE(adapter->base_incval) = incval;
45902+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45903 smp_mb();
45904
45905 /* need lock to prevent incorrect read while modifying cyclecounter */
45906diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45907index 089b713..28d87ae 100644
45908--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45909+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45910@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45911 struct __vxge_hw_fifo *fifo;
45912 struct vxge_hw_fifo_config *config;
45913 u32 txdl_size, txdl_per_memblock;
45914- struct vxge_hw_mempool_cbs fifo_mp_callback;
45915+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45916+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45917+ };
45918+
45919 struct __vxge_hw_virtualpath *vpath;
45920
45921 if ((vp == NULL) || (attr == NULL)) {
45922@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45923 goto exit;
45924 }
45925
45926- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45927-
45928 fifo->mempool =
45929 __vxge_hw_mempool_create(vpath->hldev,
45930 fifo->config->memblock_size,
45931diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45932index 90a2dda..47e620e 100644
45933--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45934+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45935@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45936 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45937 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45938 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45939- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45940+ pax_open_kernel();
45941+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45942+ pax_close_kernel();
45943 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45944 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45945 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45946diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45947index be7d7a6..a8983f8 100644
45948--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45949+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45950@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45951 case QLCNIC_NON_PRIV_FUNC:
45952 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45953 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45954- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45955+ pax_open_kernel();
45956+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45957+ pax_close_kernel();
45958 break;
45959 case QLCNIC_PRIV_FUNC:
45960 ahw->op_mode = QLCNIC_PRIV_FUNC;
45961 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45962- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45963+ pax_open_kernel();
45964+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45965+ pax_close_kernel();
45966 break;
45967 case QLCNIC_MGMT_FUNC:
45968 ahw->op_mode = QLCNIC_MGMT_FUNC;
45969 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45970- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45971+ pax_open_kernel();
45972+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45973+ pax_close_kernel();
45974 break;
45975 default:
45976 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45977diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45978index 7763962..c3499a7 100644
45979--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45980+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45981@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45982 struct qlcnic_dump_entry *entry;
45983 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45984 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45985- static const struct qlcnic_dump_operations *fw_dump_ops;
45986+ const struct qlcnic_dump_operations *fw_dump_ops;
45987 struct device *dev = &adapter->pdev->dev;
45988 struct qlcnic_hardware_context *ahw;
45989 void *temp_buffer;
45990diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45991index 3ff7bc3..366091b 100644
45992--- a/drivers/net/ethernet/realtek/r8169.c
45993+++ b/drivers/net/ethernet/realtek/r8169.c
45994@@ -758,22 +758,22 @@ struct rtl8169_private {
45995 struct mdio_ops {
45996 void (*write)(struct rtl8169_private *, int, int);
45997 int (*read)(struct rtl8169_private *, int);
45998- } mdio_ops;
45999+ } __no_const mdio_ops;
46000
46001 struct pll_power_ops {
46002 void (*down)(struct rtl8169_private *);
46003 void (*up)(struct rtl8169_private *);
46004- } pll_power_ops;
46005+ } __no_const pll_power_ops;
46006
46007 struct jumbo_ops {
46008 void (*enable)(struct rtl8169_private *);
46009 void (*disable)(struct rtl8169_private *);
46010- } jumbo_ops;
46011+ } __no_const jumbo_ops;
46012
46013 struct csi_ops {
46014 void (*write)(struct rtl8169_private *, int, int);
46015 u32 (*read)(struct rtl8169_private *, int);
46016- } csi_ops;
46017+ } __no_const csi_ops;
46018
46019 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46020 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46021diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46022index d7a3682..9ce272a 100644
46023--- a/drivers/net/ethernet/sfc/ptp.c
46024+++ b/drivers/net/ethernet/sfc/ptp.c
46025@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46026 ptp->start.dma_addr);
46027
46028 /* Clear flag that signals MC ready */
46029- ACCESS_ONCE(*start) = 0;
46030+ ACCESS_ONCE_RW(*start) = 0;
46031 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46032 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46033 EFX_BUG_ON_PARANOID(rc);
46034diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46035index 50617c5..b13724c 100644
46036--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46037+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46038@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46039
46040 writel(value, ioaddr + MMC_CNTRL);
46041
46042- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46043- MMC_CNTRL, value);
46044+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46045+// MMC_CNTRL, value);
46046 }
46047
46048 /* To mask all all interrupts.*/
46049diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46050index 7b594ce..1f6c5708 100644
46051--- a/drivers/net/hyperv/hyperv_net.h
46052+++ b/drivers/net/hyperv/hyperv_net.h
46053@@ -100,7 +100,7 @@ struct rndis_device {
46054
46055 enum rndis_device_state state;
46056 bool link_state;
46057- atomic_t new_req_id;
46058+ atomic_unchecked_t new_req_id;
46059
46060 spinlock_t request_lock;
46061 struct list_head req_list;
46062diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46063index b54fd25..9bd2bae 100644
46064--- a/drivers/net/hyperv/rndis_filter.c
46065+++ b/drivers/net/hyperv/rndis_filter.c
46066@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46067 * template
46068 */
46069 set = &rndis_msg->msg.set_req;
46070- set->req_id = atomic_inc_return(&dev->new_req_id);
46071+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46072
46073 /* Add to the request list */
46074 spin_lock_irqsave(&dev->request_lock, flags);
46075@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46076
46077 /* Setup the rndis set */
46078 halt = &request->request_msg.msg.halt_req;
46079- halt->req_id = atomic_inc_return(&dev->new_req_id);
46080+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46081
46082 /* Ignore return since this msg is optional. */
46083 rndis_filter_send_request(dev, request);
46084diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46085index bf0d55e..82bcfbd1 100644
46086--- a/drivers/net/ieee802154/fakehard.c
46087+++ b/drivers/net/ieee802154/fakehard.c
46088@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46089 phy->transmit_power = 0xbf;
46090
46091 dev->netdev_ops = &fake_ops;
46092- dev->ml_priv = &fake_mlme;
46093+ dev->ml_priv = (void *)&fake_mlme;
46094
46095 priv = netdev_priv(dev);
46096 priv->phy = phy;
46097diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46098index 1831fb7..9c24bca 100644
46099--- a/drivers/net/macvlan.c
46100+++ b/drivers/net/macvlan.c
46101@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46102 int macvlan_link_register(struct rtnl_link_ops *ops)
46103 {
46104 /* common fields */
46105- ops->priv_size = sizeof(struct macvlan_dev);
46106- ops->validate = macvlan_validate;
46107- ops->maxtype = IFLA_MACVLAN_MAX;
46108- ops->policy = macvlan_policy;
46109- ops->changelink = macvlan_changelink;
46110- ops->get_size = macvlan_get_size;
46111- ops->fill_info = macvlan_fill_info;
46112+ pax_open_kernel();
46113+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46114+ *(void **)&ops->validate = macvlan_validate;
46115+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46116+ *(const void **)&ops->policy = macvlan_policy;
46117+ *(void **)&ops->changelink = macvlan_changelink;
46118+ *(void **)&ops->get_size = macvlan_get_size;
46119+ *(void **)&ops->fill_info = macvlan_fill_info;
46120+ pax_close_kernel();
46121
46122 return rtnl_link_register(ops);
46123 };
46124@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46125 return NOTIFY_DONE;
46126 }
46127
46128-static struct notifier_block macvlan_notifier_block __read_mostly = {
46129+static struct notifier_block macvlan_notifier_block = {
46130 .notifier_call = macvlan_device_event,
46131 };
46132
46133diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46134index ff111a8..c4c3ac4 100644
46135--- a/drivers/net/macvtap.c
46136+++ b/drivers/net/macvtap.c
46137@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46138 }
46139
46140 ret = 0;
46141- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46142+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46143 put_user(q->flags, &ifr->ifr_flags))
46144 ret = -EFAULT;
46145 macvtap_put_vlan(vlan);
46146@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46147 return NOTIFY_DONE;
46148 }
46149
46150-static struct notifier_block macvtap_notifier_block __read_mostly = {
46151+static struct notifier_block macvtap_notifier_block = {
46152 .notifier_call = macvtap_device_event,
46153 };
46154
46155diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46156index daec9b0..6428fcb 100644
46157--- a/drivers/net/phy/mdio-bitbang.c
46158+++ b/drivers/net/phy/mdio-bitbang.c
46159@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46160 struct mdiobb_ctrl *ctrl = bus->priv;
46161
46162 module_put(ctrl->ops->owner);
46163+ mdiobus_unregister(bus);
46164 mdiobus_free(bus);
46165 }
46166 EXPORT_SYMBOL(free_mdio_bitbang);
46167diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46168index 72ff14b..11d442d 100644
46169--- a/drivers/net/ppp/ppp_generic.c
46170+++ b/drivers/net/ppp/ppp_generic.c
46171@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46172 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46173 struct ppp_stats stats;
46174 struct ppp_comp_stats cstats;
46175- char *vers;
46176
46177 switch (cmd) {
46178 case SIOCGPPPSTATS:
46179@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46180 break;
46181
46182 case SIOCGPPPVER:
46183- vers = PPP_VERSION;
46184- if (copy_to_user(addr, vers, strlen(vers) + 1))
46185+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46186 break;
46187 err = 0;
46188 break;
46189diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46190index 1252d9c..80e660b 100644
46191--- a/drivers/net/slip/slhc.c
46192+++ b/drivers/net/slip/slhc.c
46193@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46194 register struct tcphdr *thp;
46195 register struct iphdr *ip;
46196 register struct cstate *cs;
46197- int len, hdrlen;
46198+ long len, hdrlen;
46199 unsigned char *cp = icp;
46200
46201 /* We've got a compressed packet; read the change byte */
46202diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46203index c8624a8..f0a4f6a 100644
46204--- a/drivers/net/team/team.c
46205+++ b/drivers/net/team/team.c
46206@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46207 return NOTIFY_DONE;
46208 }
46209
46210-static struct notifier_block team_notifier_block __read_mostly = {
46211+static struct notifier_block team_notifier_block = {
46212 .notifier_call = team_device_event,
46213 };
46214
46215diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46216index 26f8635..c237839 100644
46217--- a/drivers/net/tun.c
46218+++ b/drivers/net/tun.c
46219@@ -1876,7 +1876,7 @@ unlock:
46220 }
46221
46222 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46223- unsigned long arg, int ifreq_len)
46224+ unsigned long arg, size_t ifreq_len)
46225 {
46226 struct tun_file *tfile = file->private_data;
46227 struct tun_struct *tun;
46228@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46229 unsigned int ifindex;
46230 int ret;
46231
46232+ if (ifreq_len > sizeof ifr)
46233+ return -EFAULT;
46234+
46235 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46236 if (copy_from_user(&ifr, argp, ifreq_len))
46237 return -EFAULT;
46238diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46239index 660bd5e..ac59452 100644
46240--- a/drivers/net/usb/hso.c
46241+++ b/drivers/net/usb/hso.c
46242@@ -71,7 +71,7 @@
46243 #include <asm/byteorder.h>
46244 #include <linux/serial_core.h>
46245 #include <linux/serial.h>
46246-
46247+#include <asm/local.h>
46248
46249 #define MOD_AUTHOR "Option Wireless"
46250 #define MOD_DESCRIPTION "USB High Speed Option driver"
46251@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46252 struct urb *urb;
46253
46254 urb = serial->rx_urb[0];
46255- if (serial->port.count > 0) {
46256+ if (atomic_read(&serial->port.count) > 0) {
46257 count = put_rxbuf_data(urb, serial);
46258 if (count == -1)
46259 return;
46260@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46261 DUMP1(urb->transfer_buffer, urb->actual_length);
46262
46263 /* Anyone listening? */
46264- if (serial->port.count == 0)
46265+ if (atomic_read(&serial->port.count) == 0)
46266 return;
46267
46268 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46269@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46270 tty_port_tty_set(&serial->port, tty);
46271
46272 /* check for port already opened, if not set the termios */
46273- serial->port.count++;
46274- if (serial->port.count == 1) {
46275+ if (atomic_inc_return(&serial->port.count) == 1) {
46276 serial->rx_state = RX_IDLE;
46277 /* Force default termio settings */
46278 _hso_serial_set_termios(tty, NULL);
46279@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46280 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46281 if (result) {
46282 hso_stop_serial_device(serial->parent);
46283- serial->port.count--;
46284+ atomic_dec(&serial->port.count);
46285 kref_put(&serial->parent->ref, hso_serial_ref_free);
46286 }
46287 } else {
46288@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46289
46290 /* reset the rts and dtr */
46291 /* do the actual close */
46292- serial->port.count--;
46293+ atomic_dec(&serial->port.count);
46294
46295- if (serial->port.count <= 0) {
46296- serial->port.count = 0;
46297+ if (atomic_read(&serial->port.count) <= 0) {
46298+ atomic_set(&serial->port.count, 0);
46299 tty_port_tty_set(&serial->port, NULL);
46300 if (!usb_gone)
46301 hso_stop_serial_device(serial->parent);
46302@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46303
46304 /* the actual setup */
46305 spin_lock_irqsave(&serial->serial_lock, flags);
46306- if (serial->port.count)
46307+ if (atomic_read(&serial->port.count))
46308 _hso_serial_set_termios(tty, old);
46309 else
46310 tty->termios = *old;
46311@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46312 D1("Pending read interrupt on port %d\n", i);
46313 spin_lock(&serial->serial_lock);
46314 if (serial->rx_state == RX_IDLE &&
46315- serial->port.count > 0) {
46316+ atomic_read(&serial->port.count) > 0) {
46317 /* Setup and send a ctrl req read on
46318 * port i */
46319 if (!serial->rx_urb_filled[0]) {
46320@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46321 /* Start all serial ports */
46322 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46323 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46324- if (dev2ser(serial_table[i])->port.count) {
46325+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46326 result =
46327 hso_start_serial_device(serial_table[i], GFP_NOIO);
46328 hso_kick_transmit(dev2ser(serial_table[i]));
46329diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46330index adb12f3..48005ab 100644
46331--- a/drivers/net/usb/r8152.c
46332+++ b/drivers/net/usb/r8152.c
46333@@ -513,7 +513,7 @@ struct r8152 {
46334 void (*disable)(struct r8152 *);
46335 void (*down)(struct r8152 *);
46336 void (*unload)(struct r8152 *);
46337- } rtl_ops;
46338+ } __no_const rtl_ops;
46339
46340 int intr_interval;
46341 u32 msg_enable;
46342diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46343index a2515887..6d13233 100644
46344--- a/drivers/net/usb/sierra_net.c
46345+++ b/drivers/net/usb/sierra_net.c
46346@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46347 /* atomic counter partially included in MAC address to make sure 2 devices
46348 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46349 */
46350-static atomic_t iface_counter = ATOMIC_INIT(0);
46351+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46352
46353 /*
46354 * SYNC Timer Delay definition used to set the expiry time
46355@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46356 dev->net->netdev_ops = &sierra_net_device_ops;
46357
46358 /* change MAC addr to include, ifacenum, and to be unique */
46359- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46360+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46361 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46362
46363 /* we will have to manufacture ethernet headers, prepare template */
46364diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46365index d091e52..568bb179 100644
46366--- a/drivers/net/vxlan.c
46367+++ b/drivers/net/vxlan.c
46368@@ -2847,7 +2847,7 @@ nla_put_failure:
46369 return -EMSGSIZE;
46370 }
46371
46372-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46373+static struct rtnl_link_ops vxlan_link_ops = {
46374 .kind = "vxlan",
46375 .maxtype = IFLA_VXLAN_MAX,
46376 .policy = vxlan_policy,
46377@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46378 return NOTIFY_DONE;
46379 }
46380
46381-static struct notifier_block vxlan_notifier_block __read_mostly = {
46382+static struct notifier_block vxlan_notifier_block = {
46383 .notifier_call = vxlan_lowerdev_event,
46384 };
46385
46386diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46387index 5920c99..ff2e4a5 100644
46388--- a/drivers/net/wan/lmc/lmc_media.c
46389+++ b/drivers/net/wan/lmc/lmc_media.c
46390@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46391 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46392
46393 lmc_media_t lmc_ds3_media = {
46394- lmc_ds3_init, /* special media init stuff */
46395- lmc_ds3_default, /* reset to default state */
46396- lmc_ds3_set_status, /* reset status to state provided */
46397- lmc_dummy_set_1, /* set clock source */
46398- lmc_dummy_set2_1, /* set line speed */
46399- lmc_ds3_set_100ft, /* set cable length */
46400- lmc_ds3_set_scram, /* set scrambler */
46401- lmc_ds3_get_link_status, /* get link status */
46402- lmc_dummy_set_1, /* set link status */
46403- lmc_ds3_set_crc_length, /* set CRC length */
46404- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46405- lmc_ds3_watchdog
46406+ .init = lmc_ds3_init, /* special media init stuff */
46407+ .defaults = lmc_ds3_default, /* reset to default state */
46408+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46409+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46410+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46411+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46412+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46413+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46414+ .set_link_status = lmc_dummy_set_1, /* set link status */
46415+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46416+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46417+ .watchdog = lmc_ds3_watchdog
46418 };
46419
46420 lmc_media_t lmc_hssi_media = {
46421- lmc_hssi_init, /* special media init stuff */
46422- lmc_hssi_default, /* reset to default state */
46423- lmc_hssi_set_status, /* reset status to state provided */
46424- lmc_hssi_set_clock, /* set clock source */
46425- lmc_dummy_set2_1, /* set line speed */
46426- lmc_dummy_set_1, /* set cable length */
46427- lmc_dummy_set_1, /* set scrambler */
46428- lmc_hssi_get_link_status, /* get link status */
46429- lmc_hssi_set_link_status, /* set link status */
46430- lmc_hssi_set_crc_length, /* set CRC length */
46431- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46432- lmc_hssi_watchdog
46433+ .init = lmc_hssi_init, /* special media init stuff */
46434+ .defaults = lmc_hssi_default, /* reset to default state */
46435+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46436+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46437+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46438+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46439+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46440+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46441+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46442+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46443+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46444+ .watchdog = lmc_hssi_watchdog
46445 };
46446
46447-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46448- lmc_ssi_default, /* reset to default state */
46449- lmc_ssi_set_status, /* reset status to state provided */
46450- lmc_ssi_set_clock, /* set clock source */
46451- lmc_ssi_set_speed, /* set line speed */
46452- lmc_dummy_set_1, /* set cable length */
46453- lmc_dummy_set_1, /* set scrambler */
46454- lmc_ssi_get_link_status, /* get link status */
46455- lmc_ssi_set_link_status, /* set link status */
46456- lmc_ssi_set_crc_length, /* set CRC length */
46457- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46458- lmc_ssi_watchdog
46459+lmc_media_t lmc_ssi_media = {
46460+ .init = lmc_ssi_init, /* special media init stuff */
46461+ .defaults = lmc_ssi_default, /* reset to default state */
46462+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46463+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46464+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46465+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46466+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46467+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46468+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46469+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46470+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46471+ .watchdog = lmc_ssi_watchdog
46472 };
46473
46474 lmc_media_t lmc_t1_media = {
46475- lmc_t1_init, /* special media init stuff */
46476- lmc_t1_default, /* reset to default state */
46477- lmc_t1_set_status, /* reset status to state provided */
46478- lmc_t1_set_clock, /* set clock source */
46479- lmc_dummy_set2_1, /* set line speed */
46480- lmc_dummy_set_1, /* set cable length */
46481- lmc_dummy_set_1, /* set scrambler */
46482- lmc_t1_get_link_status, /* get link status */
46483- lmc_dummy_set_1, /* set link status */
46484- lmc_t1_set_crc_length, /* set CRC length */
46485- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46486- lmc_t1_watchdog
46487+ .init = lmc_t1_init, /* special media init stuff */
46488+ .defaults = lmc_t1_default, /* reset to default state */
46489+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46490+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46491+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46492+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46493+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46494+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46495+ .set_link_status = lmc_dummy_set_1, /* set link status */
46496+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46497+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46498+ .watchdog = lmc_t1_watchdog
46499 };
46500
46501 static void
46502diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46503index feacc3b..5bac0de 100644
46504--- a/drivers/net/wan/z85230.c
46505+++ b/drivers/net/wan/z85230.c
46506@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46507
46508 struct z8530_irqhandler z8530_sync =
46509 {
46510- z8530_rx,
46511- z8530_tx,
46512- z8530_status
46513+ .rx = z8530_rx,
46514+ .tx = z8530_tx,
46515+ .status = z8530_status
46516 };
46517
46518 EXPORT_SYMBOL(z8530_sync);
46519@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46520 }
46521
46522 static struct z8530_irqhandler z8530_dma_sync = {
46523- z8530_dma_rx,
46524- z8530_dma_tx,
46525- z8530_dma_status
46526+ .rx = z8530_dma_rx,
46527+ .tx = z8530_dma_tx,
46528+ .status = z8530_dma_status
46529 };
46530
46531 static struct z8530_irqhandler z8530_txdma_sync = {
46532- z8530_rx,
46533- z8530_dma_tx,
46534- z8530_dma_status
46535+ .rx = z8530_rx,
46536+ .tx = z8530_dma_tx,
46537+ .status = z8530_dma_status
46538 };
46539
46540 /**
46541@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46542
46543 struct z8530_irqhandler z8530_nop=
46544 {
46545- z8530_rx_clear,
46546- z8530_tx_clear,
46547- z8530_status_clear
46548+ .rx = z8530_rx_clear,
46549+ .tx = z8530_tx_clear,
46550+ .status = z8530_status_clear
46551 };
46552
46553
46554diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46555index 0b60295..b8bfa5b 100644
46556--- a/drivers/net/wimax/i2400m/rx.c
46557+++ b/drivers/net/wimax/i2400m/rx.c
46558@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46559 if (i2400m->rx_roq == NULL)
46560 goto error_roq_alloc;
46561
46562- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46563+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46564 GFP_KERNEL);
46565 if (rd == NULL) {
46566 result = -ENOMEM;
46567diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46568index edf4b57..68b51c0 100644
46569--- a/drivers/net/wireless/airo.c
46570+++ b/drivers/net/wireless/airo.c
46571@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46572 struct airo_info *ai = dev->ml_priv;
46573 int ridcode;
46574 int enabled;
46575- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46576+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46577 unsigned char *iobuf;
46578
46579 /* Only super-user can write RIDs */
46580diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46581index 99b3bfa..9559372 100644
46582--- a/drivers/net/wireless/at76c50x-usb.c
46583+++ b/drivers/net/wireless/at76c50x-usb.c
46584@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46585 }
46586
46587 /* Convert timeout from the DFU status to jiffies */
46588-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46589+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46590 {
46591 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46592 | (s->poll_timeout[1] << 8)
46593diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46594index edc57ab..ff49e0a 100644
46595--- a/drivers/net/wireless/ath/ath10k/htc.c
46596+++ b/drivers/net/wireless/ath/ath10k/htc.c
46597@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46598 /* registered target arrival callback from the HIF layer */
46599 int ath10k_htc_init(struct ath10k *ar)
46600 {
46601- struct ath10k_hif_cb htc_callbacks;
46602+ static struct ath10k_hif_cb htc_callbacks = {
46603+ .rx_completion = ath10k_htc_rx_completion_handler,
46604+ .tx_completion = ath10k_htc_tx_completion_handler,
46605+ };
46606 struct ath10k_htc_ep *ep = NULL;
46607 struct ath10k_htc *htc = &ar->htc;
46608
46609@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46610 ath10k_htc_reset_endpoint_states(htc);
46611
46612 /* setup HIF layer callbacks */
46613- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46614- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46615 htc->ar = ar;
46616
46617 /* Get HIF default pipe for HTC message exchange */
46618diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46619index 4716d33..a688310 100644
46620--- a/drivers/net/wireless/ath/ath10k/htc.h
46621+++ b/drivers/net/wireless/ath/ath10k/htc.h
46622@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46623
46624 struct ath10k_htc_ops {
46625 void (*target_send_suspend_complete)(struct ath10k *ar);
46626-};
46627+} __no_const;
46628
46629 struct ath10k_htc_ep_ops {
46630 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46631 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46632 void (*ep_tx_credits)(struct ath10k *);
46633-};
46634+} __no_const;
46635
46636 /* service connection information */
46637 struct ath10k_htc_svc_conn_req {
46638diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46639index 741b38d..b7ae41b 100644
46640--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46641+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46642@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46643 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46644 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46645
46646- ACCESS_ONCE(ads->ds_link) = i->link;
46647- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46648+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46649+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46650
46651 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46652 ctl6 = SM(i->keytype, AR_EncrType);
46653@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46654
46655 if ((i->is_first || i->is_last) &&
46656 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46657- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46658+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46659 | set11nTries(i->rates, 1)
46660 | set11nTries(i->rates, 2)
46661 | set11nTries(i->rates, 3)
46662 | (i->dur_update ? AR_DurUpdateEna : 0)
46663 | SM(0, AR_BurstDur);
46664
46665- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46666+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46667 | set11nRate(i->rates, 1)
46668 | set11nRate(i->rates, 2)
46669 | set11nRate(i->rates, 3);
46670 } else {
46671- ACCESS_ONCE(ads->ds_ctl2) = 0;
46672- ACCESS_ONCE(ads->ds_ctl3) = 0;
46673+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46674+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46675 }
46676
46677 if (!i->is_first) {
46678- ACCESS_ONCE(ads->ds_ctl0) = 0;
46679- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46680- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46681+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46682+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46683+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46684 return;
46685 }
46686
46687@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46688 break;
46689 }
46690
46691- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46692+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46693 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46694 | SM(i->txpower, AR_XmitPower)
46695 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46696@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46697 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46698 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46699
46700- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46701- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46702+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46703+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46704
46705 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46706 return;
46707
46708- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46709+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46710 | set11nPktDurRTSCTS(i->rates, 1);
46711
46712- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46713+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46714 | set11nPktDurRTSCTS(i->rates, 3);
46715
46716- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46717+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46718 | set11nRateFlags(i->rates, 1)
46719 | set11nRateFlags(i->rates, 2)
46720 | set11nRateFlags(i->rates, 3)
46721diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46722index 729ffbf..49f50e3 100644
46723--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46724+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46725@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46726 (i->qcu << AR_TxQcuNum_S) | desc_len;
46727
46728 checksum += val;
46729- ACCESS_ONCE(ads->info) = val;
46730+ ACCESS_ONCE_RW(ads->info) = val;
46731
46732 checksum += i->link;
46733- ACCESS_ONCE(ads->link) = i->link;
46734+ ACCESS_ONCE_RW(ads->link) = i->link;
46735
46736 checksum += i->buf_addr[0];
46737- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46738+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46739 checksum += i->buf_addr[1];
46740- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46741+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46742 checksum += i->buf_addr[2];
46743- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46744+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46745 checksum += i->buf_addr[3];
46746- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46747+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46748
46749 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46750- ACCESS_ONCE(ads->ctl3) = val;
46751+ ACCESS_ONCE_RW(ads->ctl3) = val;
46752 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46753- ACCESS_ONCE(ads->ctl5) = val;
46754+ ACCESS_ONCE_RW(ads->ctl5) = val;
46755 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46756- ACCESS_ONCE(ads->ctl7) = val;
46757+ ACCESS_ONCE_RW(ads->ctl7) = val;
46758 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46759- ACCESS_ONCE(ads->ctl9) = val;
46760+ ACCESS_ONCE_RW(ads->ctl9) = val;
46761
46762 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46763- ACCESS_ONCE(ads->ctl10) = checksum;
46764+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46765
46766 if (i->is_first || i->is_last) {
46767- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46768+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46769 | set11nTries(i->rates, 1)
46770 | set11nTries(i->rates, 2)
46771 | set11nTries(i->rates, 3)
46772 | (i->dur_update ? AR_DurUpdateEna : 0)
46773 | SM(0, AR_BurstDur);
46774
46775- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46776+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46777 | set11nRate(i->rates, 1)
46778 | set11nRate(i->rates, 2)
46779 | set11nRate(i->rates, 3);
46780 } else {
46781- ACCESS_ONCE(ads->ctl13) = 0;
46782- ACCESS_ONCE(ads->ctl14) = 0;
46783+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46784+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46785 }
46786
46787 ads->ctl20 = 0;
46788@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46789
46790 ctl17 = SM(i->keytype, AR_EncrType);
46791 if (!i->is_first) {
46792- ACCESS_ONCE(ads->ctl11) = 0;
46793- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46794- ACCESS_ONCE(ads->ctl15) = 0;
46795- ACCESS_ONCE(ads->ctl16) = 0;
46796- ACCESS_ONCE(ads->ctl17) = ctl17;
46797- ACCESS_ONCE(ads->ctl18) = 0;
46798- ACCESS_ONCE(ads->ctl19) = 0;
46799+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46800+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46801+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46802+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46803+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46804+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46805+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46806 return;
46807 }
46808
46809- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46810+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46811 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46812 | SM(i->txpower, AR_XmitPower)
46813 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46814@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46815 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46816 ctl12 |= SM(val, AR_PAPRDChainMask);
46817
46818- ACCESS_ONCE(ads->ctl12) = ctl12;
46819- ACCESS_ONCE(ads->ctl17) = ctl17;
46820+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46821+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46822
46823- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46824+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46825 | set11nPktDurRTSCTS(i->rates, 1);
46826
46827- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46828+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46829 | set11nPktDurRTSCTS(i->rates, 3);
46830
46831- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46832+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46833 | set11nRateFlags(i->rates, 1)
46834 | set11nRateFlags(i->rates, 2)
46835 | set11nRateFlags(i->rates, 3)
46836 | SM(i->rtscts_rate, AR_RTSCTSRate);
46837
46838- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46839+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46840 }
46841
46842 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46843diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46844index 0acd4b5..0591c91 100644
46845--- a/drivers/net/wireless/ath/ath9k/hw.h
46846+++ b/drivers/net/wireless/ath/ath9k/hw.h
46847@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46848
46849 /* ANI */
46850 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46851-};
46852+} __no_const;
46853
46854 /**
46855 * struct ath_spec_scan - parameters for Atheros spectral scan
46856@@ -706,7 +706,7 @@ struct ath_hw_ops {
46857 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46858 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46859 #endif
46860-};
46861+} __no_const;
46862
46863 struct ath_nf_limits {
46864 s16 max;
46865diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46866index 92190da..f3a4c4c 100644
46867--- a/drivers/net/wireless/b43/phy_lp.c
46868+++ b/drivers/net/wireless/b43/phy_lp.c
46869@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46870 {
46871 struct ssb_bus *bus = dev->dev->sdev->bus;
46872
46873- static const struct b206x_channel *chandata = NULL;
46874+ const struct b206x_channel *chandata = NULL;
46875 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46876 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46877 u16 old_comm15, scale;
46878diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46879index 0487461..fd9e84a 100644
46880--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46881+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46882@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46883 */
46884 if (il3945_mod_params.disable_hw_scan) {
46885 D_INFO("Disabling hw_scan\n");
46886- il3945_mac_ops.hw_scan = NULL;
46887+ pax_open_kernel();
46888+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46889+ pax_close_kernel();
46890 }
46891
46892 D_INFO("*** LOAD DRIVER ***\n");
46893diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46894index d2fe259..0c4c682 100644
46895--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46896+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46897@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46898 {
46899 struct iwl_priv *priv = file->private_data;
46900 char buf[64];
46901- int buf_size;
46902+ size_t buf_size;
46903 u32 offset, len;
46904
46905 memset(buf, 0, sizeof(buf));
46906@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46907 struct iwl_priv *priv = file->private_data;
46908
46909 char buf[8];
46910- int buf_size;
46911+ size_t buf_size;
46912 u32 reset_flag;
46913
46914 memset(buf, 0, sizeof(buf));
46915@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46916 {
46917 struct iwl_priv *priv = file->private_data;
46918 char buf[8];
46919- int buf_size;
46920+ size_t buf_size;
46921 int ht40;
46922
46923 memset(buf, 0, sizeof(buf));
46924@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46925 {
46926 struct iwl_priv *priv = file->private_data;
46927 char buf[8];
46928- int buf_size;
46929+ size_t buf_size;
46930 int value;
46931
46932 memset(buf, 0, sizeof(buf));
46933@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46934 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46935 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46936
46937-static const char *fmt_value = " %-30s %10u\n";
46938-static const char *fmt_hex = " %-30s 0x%02X\n";
46939-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46940-static const char *fmt_header =
46941+static const char fmt_value[] = " %-30s %10u\n";
46942+static const char fmt_hex[] = " %-30s 0x%02X\n";
46943+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46944+static const char fmt_header[] =
46945 "%-32s current cumulative delta max\n";
46946
46947 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46948@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46949 {
46950 struct iwl_priv *priv = file->private_data;
46951 char buf[8];
46952- int buf_size;
46953+ size_t buf_size;
46954 int clear;
46955
46956 memset(buf, 0, sizeof(buf));
46957@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46958 {
46959 struct iwl_priv *priv = file->private_data;
46960 char buf[8];
46961- int buf_size;
46962+ size_t buf_size;
46963 int trace;
46964
46965 memset(buf, 0, sizeof(buf));
46966@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46967 {
46968 struct iwl_priv *priv = file->private_data;
46969 char buf[8];
46970- int buf_size;
46971+ size_t buf_size;
46972 int missed;
46973
46974 memset(buf, 0, sizeof(buf));
46975@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46976
46977 struct iwl_priv *priv = file->private_data;
46978 char buf[8];
46979- int buf_size;
46980+ size_t buf_size;
46981 int plcp;
46982
46983 memset(buf, 0, sizeof(buf));
46984@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46985
46986 struct iwl_priv *priv = file->private_data;
46987 char buf[8];
46988- int buf_size;
46989+ size_t buf_size;
46990 int flush;
46991
46992 memset(buf, 0, sizeof(buf));
46993@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46994
46995 struct iwl_priv *priv = file->private_data;
46996 char buf[8];
46997- int buf_size;
46998+ size_t buf_size;
46999 int rts;
47000
47001 if (!priv->cfg->ht_params)
47002@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47003 {
47004 struct iwl_priv *priv = file->private_data;
47005 char buf[8];
47006- int buf_size;
47007+ size_t buf_size;
47008
47009 memset(buf, 0, sizeof(buf));
47010 buf_size = min(count, sizeof(buf) - 1);
47011@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47012 struct iwl_priv *priv = file->private_data;
47013 u32 event_log_flag;
47014 char buf[8];
47015- int buf_size;
47016+ size_t buf_size;
47017
47018 /* check that the interface is up */
47019 if (!iwl_is_ready(priv))
47020@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47021 struct iwl_priv *priv = file->private_data;
47022 char buf[8];
47023 u32 calib_disabled;
47024- int buf_size;
47025+ size_t buf_size;
47026
47027 memset(buf, 0, sizeof(buf));
47028 buf_size = min(count, sizeof(buf) - 1);
47029diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47030index ba1b1ea..0ff7e98 100644
47031--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47032+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47033@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47034 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47035 {
47036 struct iwl_nvm_data *data = priv->nvm_data;
47037- char *debug_msg;
47038+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47039
47040 if (data->sku_cap_11n_enable &&
47041 !priv->cfg->ht_params) {
47042@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47043 return -EINVAL;
47044 }
47045
47046- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47047 IWL_DEBUG_INFO(priv, debug_msg,
47048 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47049 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47050diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47051index f950780..be9df93 100644
47052--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47053+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47054@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47055 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47056
47057 char buf[8];
47058- int buf_size;
47059+ size_t buf_size;
47060 u32 reset_flag;
47061
47062 memset(buf, 0, sizeof(buf));
47063@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47064 {
47065 struct iwl_trans *trans = file->private_data;
47066 char buf[8];
47067- int buf_size;
47068+ size_t buf_size;
47069 int csr;
47070
47071 memset(buf, 0, sizeof(buf));
47072diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47073index 69d4c31..bd0b316 100644
47074--- a/drivers/net/wireless/mac80211_hwsim.c
47075+++ b/drivers/net/wireless/mac80211_hwsim.c
47076@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47077 if (channels < 1)
47078 return -EINVAL;
47079
47080- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47081- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47082- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47083- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47084- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47085- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47086- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47087- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47088- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47089- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47090- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47091- mac80211_hwsim_assign_vif_chanctx;
47092- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47093- mac80211_hwsim_unassign_vif_chanctx;
47094+ pax_open_kernel();
47095+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47096+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47097+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47098+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47099+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47100+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47101+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47102+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47103+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47104+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47105+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47106+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47107+ pax_close_kernel();
47108
47109 spin_lock_init(&hwsim_radio_lock);
47110 INIT_LIST_HEAD(&hwsim_radios);
47111diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47112index 5028557..91cf394 100644
47113--- a/drivers/net/wireless/rndis_wlan.c
47114+++ b/drivers/net/wireless/rndis_wlan.c
47115@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47116
47117 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47118
47119- if (rts_threshold < 0 || rts_threshold > 2347)
47120+ if (rts_threshold > 2347)
47121 rts_threshold = 2347;
47122
47123 tmp = cpu_to_le32(rts_threshold);
47124diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47125index e3b885d..7a7de2f 100644
47126--- a/drivers/net/wireless/rt2x00/rt2x00.h
47127+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47128@@ -375,7 +375,7 @@ struct rt2x00_intf {
47129 * for hardware which doesn't support hardware
47130 * sequence counting.
47131 */
47132- atomic_t seqno;
47133+ atomic_unchecked_t seqno;
47134 };
47135
47136 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47137diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47138index 5642ccc..01f03eb 100644
47139--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47140+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47141@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47142 * sequence counter given by mac80211.
47143 */
47144 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47145- seqno = atomic_add_return(0x10, &intf->seqno);
47146+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47147 else
47148- seqno = atomic_read(&intf->seqno);
47149+ seqno = atomic_read_unchecked(&intf->seqno);
47150
47151 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47152 hdr->seq_ctrl |= cpu_to_le16(seqno);
47153diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47154index e2b3d9c..67a5184 100644
47155--- a/drivers/net/wireless/ti/wl1251/sdio.c
47156+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47157@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47158
47159 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47160
47161- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47162- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47163+ pax_open_kernel();
47164+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47165+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47166+ pax_close_kernel();
47167
47168 wl1251_info("using dedicated interrupt line");
47169 } else {
47170- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47171- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47172+ pax_open_kernel();
47173+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47174+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47175+ pax_close_kernel();
47176
47177 wl1251_info("using SDIO interrupt");
47178 }
47179diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47180index be7129b..4161356 100644
47181--- a/drivers/net/wireless/ti/wl12xx/main.c
47182+++ b/drivers/net/wireless/ti/wl12xx/main.c
47183@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47184 sizeof(wl->conf.mem));
47185
47186 /* read data preparation is only needed by wl127x */
47187- wl->ops->prepare_read = wl127x_prepare_read;
47188+ pax_open_kernel();
47189+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47190+ pax_close_kernel();
47191
47192 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47193 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47194@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47195 sizeof(wl->conf.mem));
47196
47197 /* read data preparation is only needed by wl127x */
47198- wl->ops->prepare_read = wl127x_prepare_read;
47199+ pax_open_kernel();
47200+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47201+ pax_close_kernel();
47202
47203 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47204 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47205diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47206index ec37b16..7e34d66 100644
47207--- a/drivers/net/wireless/ti/wl18xx/main.c
47208+++ b/drivers/net/wireless/ti/wl18xx/main.c
47209@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47210 }
47211
47212 if (!checksum_param) {
47213- wl18xx_ops.set_rx_csum = NULL;
47214- wl18xx_ops.init_vif = NULL;
47215+ pax_open_kernel();
47216+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47217+ *(void **)&wl18xx_ops.init_vif = NULL;
47218+ pax_close_kernel();
47219 }
47220
47221 /* Enable 11a Band only if we have 5G antennas */
47222diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47223index a912dc0..a8225ba 100644
47224--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47225+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47226@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47227 {
47228 struct zd_usb *usb = urb->context;
47229 struct zd_usb_interrupt *intr = &usb->intr;
47230- int len;
47231+ unsigned int len;
47232 u16 int_num;
47233
47234 ZD_ASSERT(in_interrupt());
47235diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47236index 683671a..4519fc2 100644
47237--- a/drivers/nfc/nfcwilink.c
47238+++ b/drivers/nfc/nfcwilink.c
47239@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47240
47241 static int nfcwilink_probe(struct platform_device *pdev)
47242 {
47243- static struct nfcwilink *drv;
47244+ struct nfcwilink *drv;
47245 int rc;
47246 __u32 protocols;
47247
47248diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47249index d93b2b6..ae50401 100644
47250--- a/drivers/oprofile/buffer_sync.c
47251+++ b/drivers/oprofile/buffer_sync.c
47252@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47253 if (cookie == NO_COOKIE)
47254 offset = pc;
47255 if (cookie == INVALID_COOKIE) {
47256- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47257+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47258 offset = pc;
47259 }
47260 if (cookie != last_cookie) {
47261@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47262 /* add userspace sample */
47263
47264 if (!mm) {
47265- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47266+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47267 return 0;
47268 }
47269
47270 cookie = lookup_dcookie(mm, s->eip, &offset);
47271
47272 if (cookie == INVALID_COOKIE) {
47273- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47274+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47275 return 0;
47276 }
47277
47278@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47279 /* ignore backtraces if failed to add a sample */
47280 if (state == sb_bt_start) {
47281 state = sb_bt_ignore;
47282- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47283+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47284 }
47285 }
47286 release_mm(mm);
47287diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47288index c0cc4e7..44d4e54 100644
47289--- a/drivers/oprofile/event_buffer.c
47290+++ b/drivers/oprofile/event_buffer.c
47291@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47292 }
47293
47294 if (buffer_pos == buffer_size) {
47295- atomic_inc(&oprofile_stats.event_lost_overflow);
47296+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47297 return;
47298 }
47299
47300diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47301index ed2c3ec..deda85a 100644
47302--- a/drivers/oprofile/oprof.c
47303+++ b/drivers/oprofile/oprof.c
47304@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47305 if (oprofile_ops.switch_events())
47306 return;
47307
47308- atomic_inc(&oprofile_stats.multiplex_counter);
47309+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47310 start_switch_worker();
47311 }
47312
47313diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47314index ee2cfce..7f8f699 100644
47315--- a/drivers/oprofile/oprofile_files.c
47316+++ b/drivers/oprofile/oprofile_files.c
47317@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47318
47319 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47320
47321-static ssize_t timeout_read(struct file *file, char __user *buf,
47322+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47323 size_t count, loff_t *offset)
47324 {
47325 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47326diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47327index 59659ce..6c860a0 100644
47328--- a/drivers/oprofile/oprofile_stats.c
47329+++ b/drivers/oprofile/oprofile_stats.c
47330@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47331 cpu_buf->sample_invalid_eip = 0;
47332 }
47333
47334- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47335- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47336- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47337- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47338- atomic_set(&oprofile_stats.multiplex_counter, 0);
47339+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47340+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47341+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47342+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47343+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47344 }
47345
47346
47347diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47348index 1fc622b..8c48fc3 100644
47349--- a/drivers/oprofile/oprofile_stats.h
47350+++ b/drivers/oprofile/oprofile_stats.h
47351@@ -13,11 +13,11 @@
47352 #include <linux/atomic.h>
47353
47354 struct oprofile_stat_struct {
47355- atomic_t sample_lost_no_mm;
47356- atomic_t sample_lost_no_mapping;
47357- atomic_t bt_lost_no_mapping;
47358- atomic_t event_lost_overflow;
47359- atomic_t multiplex_counter;
47360+ atomic_unchecked_t sample_lost_no_mm;
47361+ atomic_unchecked_t sample_lost_no_mapping;
47362+ atomic_unchecked_t bt_lost_no_mapping;
47363+ atomic_unchecked_t event_lost_overflow;
47364+ atomic_unchecked_t multiplex_counter;
47365 };
47366
47367 extern struct oprofile_stat_struct oprofile_stats;
47368diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47369index 3f49345..c750d0b 100644
47370--- a/drivers/oprofile/oprofilefs.c
47371+++ b/drivers/oprofile/oprofilefs.c
47372@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47373
47374 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47375 {
47376- atomic_t *val = file->private_data;
47377- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47378+ atomic_unchecked_t *val = file->private_data;
47379+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47380 }
47381
47382
47383@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47384
47385
47386 int oprofilefs_create_ro_atomic(struct dentry *root,
47387- char const *name, atomic_t *val)
47388+ char const *name, atomic_unchecked_t *val)
47389 {
47390 return __oprofilefs_create_file(root, name,
47391 &atomic_ro_fops, 0444, val);
47392diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47393index 61be1d9..dec05d7 100644
47394--- a/drivers/oprofile/timer_int.c
47395+++ b/drivers/oprofile/timer_int.c
47396@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47397 return NOTIFY_OK;
47398 }
47399
47400-static struct notifier_block __refdata oprofile_cpu_notifier = {
47401+static struct notifier_block oprofile_cpu_notifier = {
47402 .notifier_call = oprofile_cpu_notify,
47403 };
47404
47405diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47406index 92ed045..62d39bd7 100644
47407--- a/drivers/parport/procfs.c
47408+++ b/drivers/parport/procfs.c
47409@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47410
47411 *ppos += len;
47412
47413- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47414+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47415 }
47416
47417 #ifdef CONFIG_PARPORT_1284
47418@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47419
47420 *ppos += len;
47421
47422- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47423+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47424 }
47425 #endif /* IEEE1284.3 support. */
47426
47427diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47428index 8dcccff..35d701d 100644
47429--- a/drivers/pci/hotplug/acpiphp_ibm.c
47430+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47431@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47432 goto init_cleanup;
47433 }
47434
47435- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47436+ pax_open_kernel();
47437+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47438+ pax_close_kernel();
47439 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47440
47441 return retval;
47442diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47443index 7536eef..52dc8fa 100644
47444--- a/drivers/pci/hotplug/cpcihp_generic.c
47445+++ b/drivers/pci/hotplug/cpcihp_generic.c
47446@@ -73,7 +73,6 @@ static u16 port;
47447 static unsigned int enum_bit;
47448 static u8 enum_mask;
47449
47450-static struct cpci_hp_controller_ops generic_hpc_ops;
47451 static struct cpci_hp_controller generic_hpc;
47452
47453 static int __init validate_parameters(void)
47454@@ -139,6 +138,10 @@ static int query_enum(void)
47455 return ((value & enum_mask) == enum_mask);
47456 }
47457
47458+static struct cpci_hp_controller_ops generic_hpc_ops = {
47459+ .query_enum = query_enum,
47460+};
47461+
47462 static int __init cpcihp_generic_init(void)
47463 {
47464 int status;
47465@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47466 pci_dev_put(dev);
47467
47468 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47469- generic_hpc_ops.query_enum = query_enum;
47470 generic_hpc.ops = &generic_hpc_ops;
47471
47472 status = cpci_hp_register_controller(&generic_hpc);
47473diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47474index e8c4a7c..7046f5c 100644
47475--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47476+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47477@@ -59,7 +59,6 @@
47478 /* local variables */
47479 static bool debug;
47480 static bool poll;
47481-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47482 static struct cpci_hp_controller zt5550_hpc;
47483
47484 /* Primary cPCI bus bridge device */
47485@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47486 return 0;
47487 }
47488
47489+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47490+ .query_enum = zt5550_hc_query_enum,
47491+};
47492+
47493 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47494 {
47495 int status;
47496@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47497 dbg("returned from zt5550_hc_config");
47498
47499 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47500- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47501 zt5550_hpc.ops = &zt5550_hpc_ops;
47502 if(!poll) {
47503 zt5550_hpc.irq = hc_dev->irq;
47504 zt5550_hpc.irq_flags = IRQF_SHARED;
47505 zt5550_hpc.dev_id = hc_dev;
47506
47507- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47508- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47509- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47510+ pax_open_kernel();
47511+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47512+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47513+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47514+ pax_open_kernel();
47515 } else {
47516 info("using ENUM# polling mode");
47517 }
47518diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47519index 76ba8a1..20ca857 100644
47520--- a/drivers/pci/hotplug/cpqphp_nvram.c
47521+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47522@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47523
47524 void compaq_nvram_init (void __iomem *rom_start)
47525 {
47526+
47527+#ifndef CONFIG_PAX_KERNEXEC
47528 if (rom_start) {
47529 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47530 }
47531+#endif
47532+
47533 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47534
47535 /* initialize our int15 lock */
47536diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47537index cfa92a9..29539c5 100644
47538--- a/drivers/pci/hotplug/pci_hotplug_core.c
47539+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47540@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47541 return -EINVAL;
47542 }
47543
47544- slot->ops->owner = owner;
47545- slot->ops->mod_name = mod_name;
47546+ pax_open_kernel();
47547+ *(struct module **)&slot->ops->owner = owner;
47548+ *(const char **)&slot->ops->mod_name = mod_name;
47549+ pax_close_kernel();
47550
47551 mutex_lock(&pci_hp_mutex);
47552 /*
47553diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47554index 53b58de..4479896 100644
47555--- a/drivers/pci/hotplug/pciehp_core.c
47556+++ b/drivers/pci/hotplug/pciehp_core.c
47557@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47558 struct slot *slot = ctrl->slot;
47559 struct hotplug_slot *hotplug = NULL;
47560 struct hotplug_slot_info *info = NULL;
47561- struct hotplug_slot_ops *ops = NULL;
47562+ hotplug_slot_ops_no_const *ops = NULL;
47563 char name[SLOT_NAME_SIZE];
47564 int retval = -ENOMEM;
47565
47566diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47567index 955ab79..d1df9c7 100644
47568--- a/drivers/pci/msi.c
47569+++ b/drivers/pci/msi.c
47570@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47571 {
47572 struct attribute **msi_attrs;
47573 struct attribute *msi_attr;
47574- struct device_attribute *msi_dev_attr;
47575- struct attribute_group *msi_irq_group;
47576+ device_attribute_no_const *msi_dev_attr;
47577+ attribute_group_no_const *msi_irq_group;
47578 const struct attribute_group **msi_irq_groups;
47579 struct msi_desc *entry;
47580 int ret = -ENOMEM;
47581@@ -589,7 +589,7 @@ error_attrs:
47582 count = 0;
47583 msi_attr = msi_attrs[count];
47584 while (msi_attr) {
47585- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47586+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47587 kfree(msi_attr->name);
47588 kfree(msi_dev_attr);
47589 ++count;
47590diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47591index 276ef9c..1d33a36 100644
47592--- a/drivers/pci/pci-sysfs.c
47593+++ b/drivers/pci/pci-sysfs.c
47594@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47595 {
47596 /* allocate attribute structure, piggyback attribute name */
47597 int name_len = write_combine ? 13 : 10;
47598- struct bin_attribute *res_attr;
47599+ bin_attribute_no_const *res_attr;
47600 int retval;
47601
47602 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47603@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47604 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47605 {
47606 int retval;
47607- struct bin_attribute *attr;
47608+ bin_attribute_no_const *attr;
47609
47610 /* If the device has VPD, try to expose it in sysfs. */
47611 if (dev->vpd) {
47612@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47613 {
47614 int retval;
47615 int rom_size = 0;
47616- struct bin_attribute *attr;
47617+ bin_attribute_no_const *attr;
47618
47619 if (!sysfs_initialized)
47620 return -EACCES;
47621diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47622index 4df38df..b6bb7fe 100644
47623--- a/drivers/pci/pci.h
47624+++ b/drivers/pci/pci.h
47625@@ -93,7 +93,7 @@ struct pci_vpd_ops {
47626 struct pci_vpd {
47627 unsigned int len;
47628 const struct pci_vpd_ops *ops;
47629- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47630+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47631 };
47632
47633 int pci_vpd_pci22_init(struct pci_dev *dev);
47634diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47635index e1e7026..d28dd33 100644
47636--- a/drivers/pci/pcie/aspm.c
47637+++ b/drivers/pci/pcie/aspm.c
47638@@ -27,9 +27,9 @@
47639 #define MODULE_PARAM_PREFIX "pcie_aspm."
47640
47641 /* Note: those are not register definitions */
47642-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47643-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47644-#define ASPM_STATE_L1 (4) /* L1 state */
47645+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47646+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47647+#define ASPM_STATE_L1 (4U) /* L1 state */
47648 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47649 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47650
47651diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47652index 6e34498..9911975 100644
47653--- a/drivers/pci/probe.c
47654+++ b/drivers/pci/probe.c
47655@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47656 struct pci_bus_region region, inverted_region;
47657 bool bar_too_big = false, bar_disabled = false;
47658
47659- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47660+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47661
47662 /* No printks while decoding is disabled! */
47663 if (!dev->mmio_always_on) {
47664diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47665index 46d1378..30e452b 100644
47666--- a/drivers/pci/proc.c
47667+++ b/drivers/pci/proc.c
47668@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47669 static int __init pci_proc_init(void)
47670 {
47671 struct pci_dev *dev = NULL;
47672+
47673+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47674+#ifdef CONFIG_GRKERNSEC_PROC_USER
47675+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47676+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47677+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47678+#endif
47679+#else
47680 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47681+#endif
47682 proc_create("devices", 0, proc_bus_pci_dir,
47683 &proc_bus_pci_dev_operations);
47684 proc_initialized = 1;
47685diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47686index 7f3aad0..7d604bb 100644
47687--- a/drivers/platform/chrome/chromeos_laptop.c
47688+++ b/drivers/platform/chrome/chromeos_laptop.c
47689@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47690 .callback = chromeos_laptop_dmi_matched, \
47691 .driver_data = (void *)&board_
47692
47693-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47694+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47695 {
47696 .ident = "Samsung Series 5 550",
47697 .matches = {
47698diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47699index c5e082f..d6307a0 100644
47700--- a/drivers/platform/x86/asus-wmi.c
47701+++ b/drivers/platform/x86/asus-wmi.c
47702@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47703 int err;
47704 u32 retval = -1;
47705
47706+#ifdef CONFIG_GRKERNSEC_KMEM
47707+ return -EPERM;
47708+#endif
47709+
47710 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47711
47712 if (err < 0)
47713@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47714 int err;
47715 u32 retval = -1;
47716
47717+#ifdef CONFIG_GRKERNSEC_KMEM
47718+ return -EPERM;
47719+#endif
47720+
47721 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47722 &retval);
47723
47724@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47725 union acpi_object *obj;
47726 acpi_status status;
47727
47728+#ifdef CONFIG_GRKERNSEC_KMEM
47729+ return -EPERM;
47730+#endif
47731+
47732 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47733 1, asus->debug.method_id,
47734 &input, &output);
47735diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47736index 62f8030..c7f2a45 100644
47737--- a/drivers/platform/x86/msi-laptop.c
47738+++ b/drivers/platform/x86/msi-laptop.c
47739@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47740
47741 if (!quirks->ec_read_only) {
47742 /* allow userland write sysfs file */
47743- dev_attr_bluetooth.store = store_bluetooth;
47744- dev_attr_wlan.store = store_wlan;
47745- dev_attr_threeg.store = store_threeg;
47746- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47747- dev_attr_wlan.attr.mode |= S_IWUSR;
47748- dev_attr_threeg.attr.mode |= S_IWUSR;
47749+ pax_open_kernel();
47750+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47751+ *(void **)&dev_attr_wlan.store = store_wlan;
47752+ *(void **)&dev_attr_threeg.store = store_threeg;
47753+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47754+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47755+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47756+ pax_close_kernel();
47757 }
47758
47759 /* disable hardware control by fn key */
47760diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47761index 70222f2..8c8ce66 100644
47762--- a/drivers/platform/x86/msi-wmi.c
47763+++ b/drivers/platform/x86/msi-wmi.c
47764@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47765 static void msi_wmi_notify(u32 value, void *context)
47766 {
47767 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47768- static struct key_entry *key;
47769+ struct key_entry *key;
47770 union acpi_object *obj;
47771 acpi_status status;
47772
47773diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47774index 8f8551a..3ace3ca 100644
47775--- a/drivers/platform/x86/sony-laptop.c
47776+++ b/drivers/platform/x86/sony-laptop.c
47777@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47778 }
47779
47780 /* High speed charging function */
47781-static struct device_attribute *hsc_handle;
47782+static device_attribute_no_const *hsc_handle;
47783
47784 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47785 struct device_attribute *attr,
47786diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47787index defb6af..7a5d3d1 100644
47788--- a/drivers/platform/x86/thinkpad_acpi.c
47789+++ b/drivers/platform/x86/thinkpad_acpi.c
47790@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47791 return 0;
47792 }
47793
47794-void static hotkey_mask_warn_incomplete_mask(void)
47795+static void hotkey_mask_warn_incomplete_mask(void)
47796 {
47797 /* log only what the user can fix... */
47798 const u32 wantedmask = hotkey_driver_mask &
47799@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47800 }
47801 }
47802
47803-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47804- struct tp_nvram_state *newn,
47805- const u32 event_mask)
47806-{
47807-
47808 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47809 do { \
47810 if ((event_mask & (1 << __scancode)) && \
47811@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47812 tpacpi_hotkey_send_key(__scancode); \
47813 } while (0)
47814
47815- void issue_volchange(const unsigned int oldvol,
47816- const unsigned int newvol)
47817- {
47818- unsigned int i = oldvol;
47819+static void issue_volchange(const unsigned int oldvol,
47820+ const unsigned int newvol,
47821+ const u32 event_mask)
47822+{
47823+ unsigned int i = oldvol;
47824
47825- while (i > newvol) {
47826- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47827- i--;
47828- }
47829- while (i < newvol) {
47830- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47831- i++;
47832- }
47833+ while (i > newvol) {
47834+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47835+ i--;
47836 }
47837+ while (i < newvol) {
47838+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47839+ i++;
47840+ }
47841+}
47842
47843- void issue_brightnesschange(const unsigned int oldbrt,
47844- const unsigned int newbrt)
47845- {
47846- unsigned int i = oldbrt;
47847+static void issue_brightnesschange(const unsigned int oldbrt,
47848+ const unsigned int newbrt,
47849+ const u32 event_mask)
47850+{
47851+ unsigned int i = oldbrt;
47852
47853- while (i > newbrt) {
47854- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47855- i--;
47856- }
47857- while (i < newbrt) {
47858- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47859- i++;
47860- }
47861+ while (i > newbrt) {
47862+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47863+ i--;
47864+ }
47865+ while (i < newbrt) {
47866+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47867+ i++;
47868 }
47869+}
47870
47871+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47872+ struct tp_nvram_state *newn,
47873+ const u32 event_mask)
47874+{
47875 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47876 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47877 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47878@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47879 oldn->volume_level != newn->volume_level) {
47880 /* recently muted, or repeated mute keypress, or
47881 * multiple presses ending in mute */
47882- issue_volchange(oldn->volume_level, newn->volume_level);
47883+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47884 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47885 }
47886 } else {
47887@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47888 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47889 }
47890 if (oldn->volume_level != newn->volume_level) {
47891- issue_volchange(oldn->volume_level, newn->volume_level);
47892+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47893 } else if (oldn->volume_toggle != newn->volume_toggle) {
47894 /* repeated vol up/down keypress at end of scale ? */
47895 if (newn->volume_level == 0)
47896@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47897 /* handle brightness */
47898 if (oldn->brightness_level != newn->brightness_level) {
47899 issue_brightnesschange(oldn->brightness_level,
47900- newn->brightness_level);
47901+ newn->brightness_level,
47902+ event_mask);
47903 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47904 /* repeated key presses that didn't change state */
47905 if (newn->brightness_level == 0)
47906@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47907 && !tp_features.bright_unkfw)
47908 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47909 }
47910+}
47911
47912 #undef TPACPI_COMPARE_KEY
47913 #undef TPACPI_MAY_SEND_KEY
47914-}
47915
47916 /*
47917 * Polling driver
47918diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47919index 769d265..a3a05ca 100644
47920--- a/drivers/pnp/pnpbios/bioscalls.c
47921+++ b/drivers/pnp/pnpbios/bioscalls.c
47922@@ -58,7 +58,7 @@ do { \
47923 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47924 } while(0)
47925
47926-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47927+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47928 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47929
47930 /*
47931@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47932
47933 cpu = get_cpu();
47934 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47935+
47936+ pax_open_kernel();
47937 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47938+ pax_close_kernel();
47939
47940 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47941 spin_lock_irqsave(&pnp_bios_lock, flags);
47942@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47943 :"memory");
47944 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47945
47946+ pax_open_kernel();
47947 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47948+ pax_close_kernel();
47949+
47950 put_cpu();
47951
47952 /* If we get here and this is set then the PnP BIOS faulted on us. */
47953@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47954 return status;
47955 }
47956
47957-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47958+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47959 {
47960 int i;
47961
47962@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47963 pnp_bios_callpoint.offset = header->fields.pm16offset;
47964 pnp_bios_callpoint.segment = PNP_CS16;
47965
47966+ pax_open_kernel();
47967+
47968 for_each_possible_cpu(i) {
47969 struct desc_struct *gdt = get_cpu_gdt_table(i);
47970 if (!gdt)
47971@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47972 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47973 (unsigned long)__va(header->fields.pm16dseg));
47974 }
47975+
47976+ pax_close_kernel();
47977 }
47978diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47979index bacddd1..65ea100 100644
47980--- a/drivers/pnp/resource.c
47981+++ b/drivers/pnp/resource.c
47982@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47983 return 1;
47984
47985 /* check if the resource is valid */
47986- if (*irq < 0 || *irq > 15)
47987+ if (*irq > 15)
47988 return 0;
47989
47990 /* check if the resource is reserved */
47991@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47992 return 1;
47993
47994 /* check if the resource is valid */
47995- if (*dma < 0 || *dma == 4 || *dma > 7)
47996+ if (*dma == 4 || *dma > 7)
47997 return 0;
47998
47999 /* check if the resource is reserved */
48000diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48001index 0c52e2a..3421ab7 100644
48002--- a/drivers/power/pda_power.c
48003+++ b/drivers/power/pda_power.c
48004@@ -37,7 +37,11 @@ static int polling;
48005
48006 #if IS_ENABLED(CONFIG_USB_PHY)
48007 static struct usb_phy *transceiver;
48008-static struct notifier_block otg_nb;
48009+static int otg_handle_notification(struct notifier_block *nb,
48010+ unsigned long event, void *unused);
48011+static struct notifier_block otg_nb = {
48012+ .notifier_call = otg_handle_notification
48013+};
48014 #endif
48015
48016 static struct regulator *ac_draw;
48017@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48018
48019 #if IS_ENABLED(CONFIG_USB_PHY)
48020 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48021- otg_nb.notifier_call = otg_handle_notification;
48022 ret = usb_register_notifier(transceiver, &otg_nb);
48023 if (ret) {
48024 dev_err(dev, "failure to register otg notifier\n");
48025diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48026index cc439fd..8fa30df 100644
48027--- a/drivers/power/power_supply.h
48028+++ b/drivers/power/power_supply.h
48029@@ -16,12 +16,12 @@ struct power_supply;
48030
48031 #ifdef CONFIG_SYSFS
48032
48033-extern void power_supply_init_attrs(struct device_type *dev_type);
48034+extern void power_supply_init_attrs(void);
48035 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48036
48037 #else
48038
48039-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48040+static inline void power_supply_init_attrs(void) {}
48041 #define power_supply_uevent NULL
48042
48043 #endif /* CONFIG_SYSFS */
48044diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48045index 2660664..75fcb04 100644
48046--- a/drivers/power/power_supply_core.c
48047+++ b/drivers/power/power_supply_core.c
48048@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48049 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48050 EXPORT_SYMBOL_GPL(power_supply_notifier);
48051
48052-static struct device_type power_supply_dev_type;
48053+extern const struct attribute_group *power_supply_attr_groups[];
48054+static struct device_type power_supply_dev_type = {
48055+ .groups = power_supply_attr_groups,
48056+};
48057
48058 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48059 struct power_supply *supply)
48060@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48061 return PTR_ERR(power_supply_class);
48062
48063 power_supply_class->dev_uevent = power_supply_uevent;
48064- power_supply_init_attrs(&power_supply_dev_type);
48065+ power_supply_init_attrs();
48066
48067 return 0;
48068 }
48069diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48070index 44420d1..967126e 100644
48071--- a/drivers/power/power_supply_sysfs.c
48072+++ b/drivers/power/power_supply_sysfs.c
48073@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48074 .is_visible = power_supply_attr_is_visible,
48075 };
48076
48077-static const struct attribute_group *power_supply_attr_groups[] = {
48078+const struct attribute_group *power_supply_attr_groups[] = {
48079 &power_supply_attr_group,
48080 NULL,
48081 };
48082
48083-void power_supply_init_attrs(struct device_type *dev_type)
48084+void power_supply_init_attrs(void)
48085 {
48086 int i;
48087
48088- dev_type->groups = power_supply_attr_groups;
48089-
48090 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48091 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48092 }
48093diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48094index 84419af..268ede8 100644
48095--- a/drivers/powercap/powercap_sys.c
48096+++ b/drivers/powercap/powercap_sys.c
48097@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48098 struct device_attribute name_attr;
48099 };
48100
48101+static ssize_t show_constraint_name(struct device *dev,
48102+ struct device_attribute *dev_attr,
48103+ char *buf);
48104+
48105 static struct powercap_constraint_attr
48106- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48107+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48108+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48109+ .power_limit_attr = {
48110+ .attr = {
48111+ .name = NULL,
48112+ .mode = S_IWUSR | S_IRUGO
48113+ },
48114+ .show = show_constraint_power_limit_uw,
48115+ .store = store_constraint_power_limit_uw
48116+ },
48117+
48118+ .time_window_attr = {
48119+ .attr = {
48120+ .name = NULL,
48121+ .mode = S_IWUSR | S_IRUGO
48122+ },
48123+ .show = show_constraint_time_window_us,
48124+ .store = store_constraint_time_window_us
48125+ },
48126+
48127+ .max_power_attr = {
48128+ .attr = {
48129+ .name = NULL,
48130+ .mode = S_IRUGO
48131+ },
48132+ .show = show_constraint_max_power_uw,
48133+ .store = NULL
48134+ },
48135+
48136+ .min_power_attr = {
48137+ .attr = {
48138+ .name = NULL,
48139+ .mode = S_IRUGO
48140+ },
48141+ .show = show_constraint_min_power_uw,
48142+ .store = NULL
48143+ },
48144+
48145+ .max_time_window_attr = {
48146+ .attr = {
48147+ .name = NULL,
48148+ .mode = S_IRUGO
48149+ },
48150+ .show = show_constraint_max_time_window_us,
48151+ .store = NULL
48152+ },
48153+
48154+ .min_time_window_attr = {
48155+ .attr = {
48156+ .name = NULL,
48157+ .mode = S_IRUGO
48158+ },
48159+ .show = show_constraint_min_time_window_us,
48160+ .store = NULL
48161+ },
48162+
48163+ .name_attr = {
48164+ .attr = {
48165+ .name = NULL,
48166+ .mode = S_IRUGO
48167+ },
48168+ .show = show_constraint_name,
48169+ .store = NULL
48170+ }
48171+ }
48172+};
48173
48174 /* A list of powercap control_types */
48175 static LIST_HEAD(powercap_cntrl_list);
48176@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48177 }
48178
48179 static int create_constraint_attribute(int id, const char *name,
48180- int mode,
48181- struct device_attribute *dev_attr,
48182- ssize_t (*show)(struct device *,
48183- struct device_attribute *, char *),
48184- ssize_t (*store)(struct device *,
48185- struct device_attribute *,
48186- const char *, size_t)
48187- )
48188+ struct device_attribute *dev_attr)
48189 {
48190+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48191
48192- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48193- id, name);
48194- if (!dev_attr->attr.name)
48195+ if (!name)
48196 return -ENOMEM;
48197- dev_attr->attr.mode = mode;
48198- dev_attr->show = show;
48199- dev_attr->store = store;
48200+
48201+ pax_open_kernel();
48202+ *(const char **)&dev_attr->attr.name = name;
48203+ pax_close_kernel();
48204
48205 return 0;
48206 }
48207@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48208
48209 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48210 ret = create_constraint_attribute(i, "power_limit_uw",
48211- S_IWUSR | S_IRUGO,
48212- &constraint_attrs[i].power_limit_attr,
48213- show_constraint_power_limit_uw,
48214- store_constraint_power_limit_uw);
48215+ &constraint_attrs[i].power_limit_attr);
48216 if (ret)
48217 goto err_alloc;
48218 ret = create_constraint_attribute(i, "time_window_us",
48219- S_IWUSR | S_IRUGO,
48220- &constraint_attrs[i].time_window_attr,
48221- show_constraint_time_window_us,
48222- store_constraint_time_window_us);
48223+ &constraint_attrs[i].time_window_attr);
48224 if (ret)
48225 goto err_alloc;
48226- ret = create_constraint_attribute(i, "name", S_IRUGO,
48227- &constraint_attrs[i].name_attr,
48228- show_constraint_name,
48229- NULL);
48230+ ret = create_constraint_attribute(i, "name",
48231+ &constraint_attrs[i].name_attr);
48232 if (ret)
48233 goto err_alloc;
48234- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48235- &constraint_attrs[i].max_power_attr,
48236- show_constraint_max_power_uw,
48237- NULL);
48238+ ret = create_constraint_attribute(i, "max_power_uw",
48239+ &constraint_attrs[i].max_power_attr);
48240 if (ret)
48241 goto err_alloc;
48242- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48243- &constraint_attrs[i].min_power_attr,
48244- show_constraint_min_power_uw,
48245- NULL);
48246+ ret = create_constraint_attribute(i, "min_power_uw",
48247+ &constraint_attrs[i].min_power_attr);
48248 if (ret)
48249 goto err_alloc;
48250 ret = create_constraint_attribute(i, "max_time_window_us",
48251- S_IRUGO,
48252- &constraint_attrs[i].max_time_window_attr,
48253- show_constraint_max_time_window_us,
48254- NULL);
48255+ &constraint_attrs[i].max_time_window_attr);
48256 if (ret)
48257 goto err_alloc;
48258 ret = create_constraint_attribute(i, "min_time_window_us",
48259- S_IRUGO,
48260- &constraint_attrs[i].min_time_window_attr,
48261- show_constraint_min_time_window_us,
48262- NULL);
48263+ &constraint_attrs[i].min_time_window_attr);
48264 if (ret)
48265 goto err_alloc;
48266
48267@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48268 power_zone->zone_dev_attrs[count++] =
48269 &dev_attr_max_energy_range_uj.attr;
48270 if (power_zone->ops->get_energy_uj) {
48271+ pax_open_kernel();
48272 if (power_zone->ops->reset_energy_uj)
48273- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48274+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48275 else
48276- dev_attr_energy_uj.attr.mode = S_IRUGO;
48277+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48278+ pax_close_kernel();
48279 power_zone->zone_dev_attrs[count++] =
48280 &dev_attr_energy_uj.attr;
48281 }
48282diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48283index afca1bc..86840b8 100644
48284--- a/drivers/regulator/core.c
48285+++ b/drivers/regulator/core.c
48286@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48287 {
48288 const struct regulation_constraints *constraints = NULL;
48289 const struct regulator_init_data *init_data;
48290- static atomic_t regulator_no = ATOMIC_INIT(0);
48291+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48292 struct regulator_dev *rdev;
48293 struct device *dev;
48294 int ret, i;
48295@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48296 rdev->dev.of_node = config->of_node;
48297 rdev->dev.parent = dev;
48298 dev_set_name(&rdev->dev, "regulator.%d",
48299- atomic_inc_return(&regulator_no) - 1);
48300+ atomic_inc_return_unchecked(&regulator_no) - 1);
48301 ret = device_register(&rdev->dev);
48302 if (ret != 0) {
48303 put_device(&rdev->dev);
48304diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48305index 8d94d3d..653b623 100644
48306--- a/drivers/regulator/max8660.c
48307+++ b/drivers/regulator/max8660.c
48308@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48309 max8660->shadow_regs[MAX8660_OVER1] = 5;
48310 } else {
48311 /* Otherwise devices can be toggled via software */
48312- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48313- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48314+ pax_open_kernel();
48315+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48316+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48317+ pax_close_kernel();
48318 }
48319
48320 /*
48321diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48322index 892aa1e..ebd1b9c 100644
48323--- a/drivers/regulator/max8973-regulator.c
48324+++ b/drivers/regulator/max8973-regulator.c
48325@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48326 if (!pdata || !pdata->enable_ext_control) {
48327 max->desc.enable_reg = MAX8973_VOUT;
48328 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48329- max->ops.enable = regulator_enable_regmap;
48330- max->ops.disable = regulator_disable_regmap;
48331- max->ops.is_enabled = regulator_is_enabled_regmap;
48332+ pax_open_kernel();
48333+ *(void **)&max->ops.enable = regulator_enable_regmap;
48334+ *(void **)&max->ops.disable = regulator_disable_regmap;
48335+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48336+ pax_close_kernel();
48337 }
48338
48339 if (pdata) {
48340diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48341index f374fa5..26f0683 100644
48342--- a/drivers/regulator/mc13892-regulator.c
48343+++ b/drivers/regulator/mc13892-regulator.c
48344@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48345 }
48346 mc13xxx_unlock(mc13892);
48347
48348- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48349+ pax_open_kernel();
48350+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48351 = mc13892_vcam_set_mode;
48352- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48353+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48354 = mc13892_vcam_get_mode;
48355+ pax_close_kernel();
48356
48357 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48358 ARRAY_SIZE(mc13892_regulators));
48359diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48360index cae212f..58a3980 100644
48361--- a/drivers/rtc/rtc-cmos.c
48362+++ b/drivers/rtc/rtc-cmos.c
48363@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48364 hpet_rtc_timer_init();
48365
48366 /* export at least the first block of NVRAM */
48367- nvram.size = address_space - NVRAM_OFFSET;
48368+ pax_open_kernel();
48369+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48370+ pax_close_kernel();
48371 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48372 if (retval < 0) {
48373 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48374diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48375index d049393..bb20be0 100644
48376--- a/drivers/rtc/rtc-dev.c
48377+++ b/drivers/rtc/rtc-dev.c
48378@@ -16,6 +16,7 @@
48379 #include <linux/module.h>
48380 #include <linux/rtc.h>
48381 #include <linux/sched.h>
48382+#include <linux/grsecurity.h>
48383 #include "rtc-core.h"
48384
48385 static dev_t rtc_devt;
48386@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48387 if (copy_from_user(&tm, uarg, sizeof(tm)))
48388 return -EFAULT;
48389
48390+ gr_log_timechange();
48391+
48392 return rtc_set_time(rtc, &tm);
48393
48394 case RTC_PIE_ON:
48395diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48396index 4e75345..09f8663 100644
48397--- a/drivers/rtc/rtc-ds1307.c
48398+++ b/drivers/rtc/rtc-ds1307.c
48399@@ -107,7 +107,7 @@ struct ds1307 {
48400 u8 offset; /* register's offset */
48401 u8 regs[11];
48402 u16 nvram_offset;
48403- struct bin_attribute *nvram;
48404+ bin_attribute_no_const *nvram;
48405 enum ds_type type;
48406 unsigned long flags;
48407 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48408diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48409index 11880c1..b823aa4 100644
48410--- a/drivers/rtc/rtc-m48t59.c
48411+++ b/drivers/rtc/rtc-m48t59.c
48412@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48413 if (IS_ERR(m48t59->rtc))
48414 return PTR_ERR(m48t59->rtc);
48415
48416- m48t59_nvram_attr.size = pdata->offset;
48417+ pax_open_kernel();
48418+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48419+ pax_close_kernel();
48420
48421 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48422 if (ret)
48423diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48424index 14b5f8d..cc9bd26 100644
48425--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48426+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48427@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48428 for (bit = 0; bit < 8; bit++) {
48429
48430 if ((pci_status[i] & (0x1 << bit)) != 0) {
48431- static const char *s;
48432+ const char *s;
48433
48434 s = pci_status_strings[bit];
48435 if (i == 7/*TARG*/ && bit == 3)
48436@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48437
48438 for (bit = 0; bit < 8; bit++) {
48439
48440- if ((split_status[i] & (0x1 << bit)) != 0) {
48441- static const char *s;
48442-
48443- s = split_status_strings[bit];
48444- printk(s, ahd_name(ahd),
48445+ if ((split_status[i] & (0x1 << bit)) != 0)
48446+ printk(split_status_strings[bit], ahd_name(ahd),
48447 split_status_source[i]);
48448- }
48449
48450 if (i > 1)
48451 continue;
48452
48453- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48454- static const char *s;
48455-
48456- s = split_status_strings[bit];
48457- printk(s, ahd_name(ahd), "SG");
48458- }
48459+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48460+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48461 }
48462 }
48463 /*
48464diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48465index e693af6..2e525b6 100644
48466--- a/drivers/scsi/bfa/bfa_fcpim.h
48467+++ b/drivers/scsi/bfa/bfa_fcpim.h
48468@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48469
48470 struct bfa_itn_s {
48471 bfa_isr_func_t isr;
48472-};
48473+} __no_const;
48474
48475 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48476 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48477diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48478index a3ab5cc..8143622 100644
48479--- a/drivers/scsi/bfa/bfa_fcs.c
48480+++ b/drivers/scsi/bfa/bfa_fcs.c
48481@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48482 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48483
48484 static struct bfa_fcs_mod_s fcs_modules[] = {
48485- { bfa_fcs_port_attach, NULL, NULL },
48486- { bfa_fcs_uf_attach, NULL, NULL },
48487- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48488- bfa_fcs_fabric_modexit },
48489+ {
48490+ .attach = bfa_fcs_port_attach,
48491+ .modinit = NULL,
48492+ .modexit = NULL
48493+ },
48494+ {
48495+ .attach = bfa_fcs_uf_attach,
48496+ .modinit = NULL,
48497+ .modexit = NULL
48498+ },
48499+ {
48500+ .attach = bfa_fcs_fabric_attach,
48501+ .modinit = bfa_fcs_fabric_modinit,
48502+ .modexit = bfa_fcs_fabric_modexit
48503+ },
48504 };
48505
48506 /*
48507diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48508index ff75ef8..2dfe00a 100644
48509--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48510+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48511@@ -89,15 +89,26 @@ static struct {
48512 void (*offline) (struct bfa_fcs_lport_s *port);
48513 } __port_action[] = {
48514 {
48515- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48516- bfa_fcs_lport_unknown_offline}, {
48517- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48518- bfa_fcs_lport_fab_offline}, {
48519- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48520- bfa_fcs_lport_n2n_offline}, {
48521- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48522- bfa_fcs_lport_loop_offline},
48523- };
48524+ .init = bfa_fcs_lport_unknown_init,
48525+ .online = bfa_fcs_lport_unknown_online,
48526+ .offline = bfa_fcs_lport_unknown_offline
48527+ },
48528+ {
48529+ .init = bfa_fcs_lport_fab_init,
48530+ .online = bfa_fcs_lport_fab_online,
48531+ .offline = bfa_fcs_lport_fab_offline
48532+ },
48533+ {
48534+ .init = bfa_fcs_lport_n2n_init,
48535+ .online = bfa_fcs_lport_n2n_online,
48536+ .offline = bfa_fcs_lport_n2n_offline
48537+ },
48538+ {
48539+ .init = bfa_fcs_lport_loop_init,
48540+ .online = bfa_fcs_lport_loop_online,
48541+ .offline = bfa_fcs_lport_loop_offline
48542+ },
48543+};
48544
48545 /*
48546 * fcs_port_sm FCS logical port state machine
48547diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48548index 2e28392..9d865b6 100644
48549--- a/drivers/scsi/bfa/bfa_ioc.h
48550+++ b/drivers/scsi/bfa/bfa_ioc.h
48551@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48552 bfa_ioc_disable_cbfn_t disable_cbfn;
48553 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48554 bfa_ioc_reset_cbfn_t reset_cbfn;
48555-};
48556+} __no_const;
48557
48558 /*
48559 * IOC event notification mechanism.
48560@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48561 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48562 enum bfi_ioc_state fwstate);
48563 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48564-};
48565+} __no_const;
48566
48567 /*
48568 * Queue element to wait for room in request queue. FIFO order is
48569diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48570index a14c784..6de6790 100644
48571--- a/drivers/scsi/bfa/bfa_modules.h
48572+++ b/drivers/scsi/bfa/bfa_modules.h
48573@@ -78,12 +78,12 @@ enum {
48574 \
48575 extern struct bfa_module_s hal_mod_ ## __mod; \
48576 struct bfa_module_s hal_mod_ ## __mod = { \
48577- bfa_ ## __mod ## _meminfo, \
48578- bfa_ ## __mod ## _attach, \
48579- bfa_ ## __mod ## _detach, \
48580- bfa_ ## __mod ## _start, \
48581- bfa_ ## __mod ## _stop, \
48582- bfa_ ## __mod ## _iocdisable, \
48583+ .meminfo = bfa_ ## __mod ## _meminfo, \
48584+ .attach = bfa_ ## __mod ## _attach, \
48585+ .detach = bfa_ ## __mod ## _detach, \
48586+ .start = bfa_ ## __mod ## _start, \
48587+ .stop = bfa_ ## __mod ## _stop, \
48588+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48589 }
48590
48591 #define BFA_CACHELINE_SZ (256)
48592diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48593index 045c4e1..13de803 100644
48594--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48595+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48596@@ -33,8 +33,8 @@
48597 */
48598 #include "libfcoe.h"
48599
48600-static atomic_t ctlr_num;
48601-static atomic_t fcf_num;
48602+static atomic_unchecked_t ctlr_num;
48603+static atomic_unchecked_t fcf_num;
48604
48605 /*
48606 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48607@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48608 if (!ctlr)
48609 goto out;
48610
48611- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48612+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48613 ctlr->f = f;
48614 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48615 INIT_LIST_HEAD(&ctlr->fcfs);
48616@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48617 fcf->dev.parent = &ctlr->dev;
48618 fcf->dev.bus = &fcoe_bus_type;
48619 fcf->dev.type = &fcoe_fcf_device_type;
48620- fcf->id = atomic_inc_return(&fcf_num) - 1;
48621+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48622 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48623
48624 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48625@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48626 {
48627 int error;
48628
48629- atomic_set(&ctlr_num, 0);
48630- atomic_set(&fcf_num, 0);
48631+ atomic_set_unchecked(&ctlr_num, 0);
48632+ atomic_set_unchecked(&fcf_num, 0);
48633
48634 error = bus_register(&fcoe_bus_type);
48635 if (error)
48636diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48637index f28ea07..34b16d3 100644
48638--- a/drivers/scsi/hosts.c
48639+++ b/drivers/scsi/hosts.c
48640@@ -42,7 +42,7 @@
48641 #include "scsi_logging.h"
48642
48643
48644-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48645+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48646
48647
48648 static void scsi_host_cls_release(struct device *dev)
48649@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48650 * subtract one because we increment first then return, but we need to
48651 * know what the next host number was before increment
48652 */
48653- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48654+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48655 shost->dma_channel = 0xff;
48656
48657 /* These three are default values which can be overridden */
48658diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48659index 868318a..e07ef3b 100644
48660--- a/drivers/scsi/hpsa.c
48661+++ b/drivers/scsi/hpsa.c
48662@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48663 unsigned long flags;
48664
48665 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48666- return h->access.command_completed(h, q);
48667+ return h->access->command_completed(h, q);
48668
48669 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48670 a = rq->head[rq->current_entry];
48671@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48672 while (!list_empty(&h->reqQ)) {
48673 c = list_entry(h->reqQ.next, struct CommandList, list);
48674 /* can't do anything if fifo is full */
48675- if ((h->access.fifo_full(h))) {
48676+ if ((h->access->fifo_full(h))) {
48677 h->fifo_recently_full = 1;
48678 dev_warn(&h->pdev->dev, "fifo full\n");
48679 break;
48680@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48681
48682 /* Tell the controller execute command */
48683 spin_unlock_irqrestore(&h->lock, flags);
48684- h->access.submit_command(h, c);
48685+ h->access->submit_command(h, c);
48686 spin_lock_irqsave(&h->lock, flags);
48687 }
48688 spin_unlock_irqrestore(&h->lock, flags);
48689@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48690
48691 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48692 {
48693- return h->access.command_completed(h, q);
48694+ return h->access->command_completed(h, q);
48695 }
48696
48697 static inline bool interrupt_pending(struct ctlr_info *h)
48698 {
48699- return h->access.intr_pending(h);
48700+ return h->access->intr_pending(h);
48701 }
48702
48703 static inline long interrupt_not_for_us(struct ctlr_info *h)
48704 {
48705- return (h->access.intr_pending(h) == 0) ||
48706+ return (h->access->intr_pending(h) == 0) ||
48707 (h->interrupts_enabled == 0);
48708 }
48709
48710@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48711 if (prod_index < 0)
48712 return -ENODEV;
48713 h->product_name = products[prod_index].product_name;
48714- h->access = *(products[prod_index].access);
48715+ h->access = products[prod_index].access;
48716
48717 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48718 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48719@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48720 {
48721 unsigned long flags;
48722
48723- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48724+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48725 spin_lock_irqsave(&h->lock, flags);
48726 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48727 spin_unlock_irqrestore(&h->lock, flags);
48728@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48729 }
48730
48731 /* make sure the board interrupts are off */
48732- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48733+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48734
48735 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48736 goto clean2;
48737@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48738 * fake ones to scoop up any residual completions.
48739 */
48740 spin_lock_irqsave(&h->lock, flags);
48741- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48742+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48743 spin_unlock_irqrestore(&h->lock, flags);
48744 free_irqs(h);
48745 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48746@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48747 dev_info(&h->pdev->dev, "Board READY.\n");
48748 dev_info(&h->pdev->dev,
48749 "Waiting for stale completions to drain.\n");
48750- h->access.set_intr_mask(h, HPSA_INTR_ON);
48751+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48752 msleep(10000);
48753- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48754+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48755
48756 rc = controller_reset_failed(h->cfgtable);
48757 if (rc)
48758@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48759 }
48760
48761 /* Turn the interrupts on so we can service requests */
48762- h->access.set_intr_mask(h, HPSA_INTR_ON);
48763+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48764
48765 hpsa_hba_inquiry(h);
48766 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48767@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48768 * To write all data in the battery backed cache to disks
48769 */
48770 hpsa_flush_cache(h);
48771- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48772+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48773 hpsa_free_irqs_and_disable_msix(h);
48774 }
48775
48776@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48777 return;
48778 }
48779 /* Change the access methods to the performant access methods */
48780- h->access = SA5_performant_access;
48781+ h->access = &SA5_performant_access;
48782 h->transMethod = CFGTBL_Trans_Performant;
48783 }
48784
48785diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48786index 01c3283..4655219 100644
48787--- a/drivers/scsi/hpsa.h
48788+++ b/drivers/scsi/hpsa.h
48789@@ -79,7 +79,7 @@ struct ctlr_info {
48790 unsigned int msix_vector;
48791 unsigned int msi_vector;
48792 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48793- struct access_method access;
48794+ struct access_method *access;
48795
48796 /* queue and queue Info */
48797 struct list_head reqQ;
48798@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48799 }
48800
48801 static struct access_method SA5_access = {
48802- SA5_submit_command,
48803- SA5_intr_mask,
48804- SA5_fifo_full,
48805- SA5_intr_pending,
48806- SA5_completed,
48807+ .submit_command = SA5_submit_command,
48808+ .set_intr_mask = SA5_intr_mask,
48809+ .fifo_full = SA5_fifo_full,
48810+ .intr_pending = SA5_intr_pending,
48811+ .command_completed = SA5_completed,
48812 };
48813
48814 static struct access_method SA5_performant_access = {
48815- SA5_submit_command,
48816- SA5_performant_intr_mask,
48817- SA5_fifo_full,
48818- SA5_performant_intr_pending,
48819- SA5_performant_completed,
48820+ .submit_command = SA5_submit_command,
48821+ .set_intr_mask = SA5_performant_intr_mask,
48822+ .fifo_full = SA5_fifo_full,
48823+ .intr_pending = SA5_performant_intr_pending,
48824+ .command_completed = SA5_performant_completed,
48825 };
48826
48827 struct board_type {
48828diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48829index 1b3a094..068e683 100644
48830--- a/drivers/scsi/libfc/fc_exch.c
48831+++ b/drivers/scsi/libfc/fc_exch.c
48832@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48833 u16 pool_max_index;
48834
48835 struct {
48836- atomic_t no_free_exch;
48837- atomic_t no_free_exch_xid;
48838- atomic_t xid_not_found;
48839- atomic_t xid_busy;
48840- atomic_t seq_not_found;
48841- atomic_t non_bls_resp;
48842+ atomic_unchecked_t no_free_exch;
48843+ atomic_unchecked_t no_free_exch_xid;
48844+ atomic_unchecked_t xid_not_found;
48845+ atomic_unchecked_t xid_busy;
48846+ atomic_unchecked_t seq_not_found;
48847+ atomic_unchecked_t non_bls_resp;
48848 } stats;
48849 };
48850
48851@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48852 /* allocate memory for exchange */
48853 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48854 if (!ep) {
48855- atomic_inc(&mp->stats.no_free_exch);
48856+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48857 goto out;
48858 }
48859 memset(ep, 0, sizeof(*ep));
48860@@ -874,7 +874,7 @@ out:
48861 return ep;
48862 err:
48863 spin_unlock_bh(&pool->lock);
48864- atomic_inc(&mp->stats.no_free_exch_xid);
48865+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48866 mempool_free(ep, mp->ep_pool);
48867 return NULL;
48868 }
48869@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48870 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48871 ep = fc_exch_find(mp, xid);
48872 if (!ep) {
48873- atomic_inc(&mp->stats.xid_not_found);
48874+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48875 reject = FC_RJT_OX_ID;
48876 goto out;
48877 }
48878@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48879 ep = fc_exch_find(mp, xid);
48880 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48881 if (ep) {
48882- atomic_inc(&mp->stats.xid_busy);
48883+ atomic_inc_unchecked(&mp->stats.xid_busy);
48884 reject = FC_RJT_RX_ID;
48885 goto rel;
48886 }
48887@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48888 }
48889 xid = ep->xid; /* get our XID */
48890 } else if (!ep) {
48891- atomic_inc(&mp->stats.xid_not_found);
48892+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48893 reject = FC_RJT_RX_ID; /* XID not found */
48894 goto out;
48895 }
48896@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48897 } else {
48898 sp = &ep->seq;
48899 if (sp->id != fh->fh_seq_id) {
48900- atomic_inc(&mp->stats.seq_not_found);
48901+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48902 if (f_ctl & FC_FC_END_SEQ) {
48903 /*
48904 * Update sequence_id based on incoming last
48905@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48906
48907 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48908 if (!ep) {
48909- atomic_inc(&mp->stats.xid_not_found);
48910+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48911 goto out;
48912 }
48913 if (ep->esb_stat & ESB_ST_COMPLETE) {
48914- atomic_inc(&mp->stats.xid_not_found);
48915+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48916 goto rel;
48917 }
48918 if (ep->rxid == FC_XID_UNKNOWN)
48919 ep->rxid = ntohs(fh->fh_rx_id);
48920 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48921- atomic_inc(&mp->stats.xid_not_found);
48922+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48923 goto rel;
48924 }
48925 if (ep->did != ntoh24(fh->fh_s_id) &&
48926 ep->did != FC_FID_FLOGI) {
48927- atomic_inc(&mp->stats.xid_not_found);
48928+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48929 goto rel;
48930 }
48931 sof = fr_sof(fp);
48932@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48933 sp->ssb_stat |= SSB_ST_RESP;
48934 sp->id = fh->fh_seq_id;
48935 } else if (sp->id != fh->fh_seq_id) {
48936- atomic_inc(&mp->stats.seq_not_found);
48937+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48938 goto rel;
48939 }
48940
48941@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48942 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48943
48944 if (!sp)
48945- atomic_inc(&mp->stats.xid_not_found);
48946+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48947 else
48948- atomic_inc(&mp->stats.non_bls_resp);
48949+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48950
48951 fc_frame_free(fp);
48952 }
48953@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48954
48955 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48956 mp = ema->mp;
48957- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48958+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48959 st->fc_no_free_exch_xid +=
48960- atomic_read(&mp->stats.no_free_exch_xid);
48961- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48962- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48963- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48964- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48965+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48966+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48967+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48968+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48969+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48970 }
48971 }
48972 EXPORT_SYMBOL(fc_exch_update_stats);
48973diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48974index d289583..b745eec 100644
48975--- a/drivers/scsi/libsas/sas_ata.c
48976+++ b/drivers/scsi/libsas/sas_ata.c
48977@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48978 .postreset = ata_std_postreset,
48979 .error_handler = ata_std_error_handler,
48980 .post_internal_cmd = sas_ata_post_internal,
48981- .qc_defer = ata_std_qc_defer,
48982+ .qc_defer = ata_std_qc_defer,
48983 .qc_prep = ata_noop_qc_prep,
48984 .qc_issue = sas_ata_qc_issue,
48985 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48986diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48987index 4e1b75c..0bbdfa9 100644
48988--- a/drivers/scsi/lpfc/lpfc.h
48989+++ b/drivers/scsi/lpfc/lpfc.h
48990@@ -432,7 +432,7 @@ struct lpfc_vport {
48991 struct dentry *debug_nodelist;
48992 struct dentry *vport_debugfs_root;
48993 struct lpfc_debugfs_trc *disc_trc;
48994- atomic_t disc_trc_cnt;
48995+ atomic_unchecked_t disc_trc_cnt;
48996 #endif
48997 uint8_t stat_data_enabled;
48998 uint8_t stat_data_blocked;
48999@@ -865,8 +865,8 @@ struct lpfc_hba {
49000 struct timer_list fabric_block_timer;
49001 unsigned long bit_flags;
49002 #define FABRIC_COMANDS_BLOCKED 0
49003- atomic_t num_rsrc_err;
49004- atomic_t num_cmd_success;
49005+ atomic_unchecked_t num_rsrc_err;
49006+ atomic_unchecked_t num_cmd_success;
49007 unsigned long last_rsrc_error_time;
49008 unsigned long last_ramp_down_time;
49009 unsigned long last_ramp_up_time;
49010@@ -902,7 +902,7 @@ struct lpfc_hba {
49011
49012 struct dentry *debug_slow_ring_trc;
49013 struct lpfc_debugfs_trc *slow_ring_trc;
49014- atomic_t slow_ring_trc_cnt;
49015+ atomic_unchecked_t slow_ring_trc_cnt;
49016 /* iDiag debugfs sub-directory */
49017 struct dentry *idiag_root;
49018 struct dentry *idiag_pci_cfg;
49019diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49020index b800cc9..16b6a91 100644
49021--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49022+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49023@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49024
49025 #include <linux/debugfs.h>
49026
49027-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49028+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49029 static unsigned long lpfc_debugfs_start_time = 0L;
49030
49031 /* iDiag */
49032@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49033 lpfc_debugfs_enable = 0;
49034
49035 len = 0;
49036- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49037+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49038 (lpfc_debugfs_max_disc_trc - 1);
49039 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49040 dtp = vport->disc_trc + i;
49041@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49042 lpfc_debugfs_enable = 0;
49043
49044 len = 0;
49045- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49046+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49047 (lpfc_debugfs_max_slow_ring_trc - 1);
49048 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49049 dtp = phba->slow_ring_trc + i;
49050@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49051 !vport || !vport->disc_trc)
49052 return;
49053
49054- index = atomic_inc_return(&vport->disc_trc_cnt) &
49055+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49056 (lpfc_debugfs_max_disc_trc - 1);
49057 dtp = vport->disc_trc + index;
49058 dtp->fmt = fmt;
49059 dtp->data1 = data1;
49060 dtp->data2 = data2;
49061 dtp->data3 = data3;
49062- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49063+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49064 dtp->jif = jiffies;
49065 #endif
49066 return;
49067@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49068 !phba || !phba->slow_ring_trc)
49069 return;
49070
49071- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49072+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49073 (lpfc_debugfs_max_slow_ring_trc - 1);
49074 dtp = phba->slow_ring_trc + index;
49075 dtp->fmt = fmt;
49076 dtp->data1 = data1;
49077 dtp->data2 = data2;
49078 dtp->data3 = data3;
49079- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49080+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49081 dtp->jif = jiffies;
49082 #endif
49083 return;
49084@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49085 "slow_ring buffer\n");
49086 goto debug_failed;
49087 }
49088- atomic_set(&phba->slow_ring_trc_cnt, 0);
49089+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49090 memset(phba->slow_ring_trc, 0,
49091 (sizeof(struct lpfc_debugfs_trc) *
49092 lpfc_debugfs_max_slow_ring_trc));
49093@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49094 "buffer\n");
49095 goto debug_failed;
49096 }
49097- atomic_set(&vport->disc_trc_cnt, 0);
49098+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49099
49100 snprintf(name, sizeof(name), "discovery_trace");
49101 vport->debug_disc_trc =
49102diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49103index 68c94cc..8c27be5 100644
49104--- a/drivers/scsi/lpfc/lpfc_init.c
49105+++ b/drivers/scsi/lpfc/lpfc_init.c
49106@@ -10949,8 +10949,10 @@ lpfc_init(void)
49107 "misc_register returned with status %d", error);
49108
49109 if (lpfc_enable_npiv) {
49110- lpfc_transport_functions.vport_create = lpfc_vport_create;
49111- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49112+ pax_open_kernel();
49113+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49114+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49115+ pax_close_kernel();
49116 }
49117 lpfc_transport_template =
49118 fc_attach_transport(&lpfc_transport_functions);
49119diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49120index b2ede05..aaf482ca 100644
49121--- a/drivers/scsi/lpfc/lpfc_scsi.c
49122+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49123@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49124 uint32_t evt_posted;
49125
49126 spin_lock_irqsave(&phba->hbalock, flags);
49127- atomic_inc(&phba->num_rsrc_err);
49128+ atomic_inc_unchecked(&phba->num_rsrc_err);
49129 phba->last_rsrc_error_time = jiffies;
49130
49131 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49132@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49133 unsigned long flags;
49134 struct lpfc_hba *phba = vport->phba;
49135 uint32_t evt_posted;
49136- atomic_inc(&phba->num_cmd_success);
49137+ atomic_inc_unchecked(&phba->num_cmd_success);
49138
49139 if (vport->cfg_lun_queue_depth <= queue_depth)
49140 return;
49141@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49142 unsigned long num_rsrc_err, num_cmd_success;
49143 int i;
49144
49145- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49146- num_cmd_success = atomic_read(&phba->num_cmd_success);
49147+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49148+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49149
49150 /*
49151 * The error and success command counters are global per
49152@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49153 }
49154 }
49155 lpfc_destroy_vport_work_array(phba, vports);
49156- atomic_set(&phba->num_rsrc_err, 0);
49157- atomic_set(&phba->num_cmd_success, 0);
49158+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49159+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49160 }
49161
49162 /**
49163@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49164 }
49165 }
49166 lpfc_destroy_vport_work_array(phba, vports);
49167- atomic_set(&phba->num_rsrc_err, 0);
49168- atomic_set(&phba->num_cmd_success, 0);
49169+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49170+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49171 }
49172
49173 /**
49174diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49175index 7f0af4f..193ac3e 100644
49176--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49177+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49178@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49179 {
49180 struct scsi_device *sdev = to_scsi_device(dev);
49181 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49182- static struct _raid_device *raid_device;
49183+ struct _raid_device *raid_device;
49184 unsigned long flags;
49185 Mpi2RaidVolPage0_t vol_pg0;
49186 Mpi2ConfigReply_t mpi_reply;
49187@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49188 {
49189 struct scsi_device *sdev = to_scsi_device(dev);
49190 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49191- static struct _raid_device *raid_device;
49192+ struct _raid_device *raid_device;
49193 unsigned long flags;
49194 Mpi2RaidVolPage0_t vol_pg0;
49195 Mpi2ConfigReply_t mpi_reply;
49196@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49197 struct fw_event_work *fw_event)
49198 {
49199 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49200- static struct _raid_device *raid_device;
49201+ struct _raid_device *raid_device;
49202 unsigned long flags;
49203 u16 handle;
49204
49205@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49206 u64 sas_address;
49207 struct _sas_device *sas_device;
49208 struct _sas_node *expander_device;
49209- static struct _raid_device *raid_device;
49210+ struct _raid_device *raid_device;
49211 u8 retry_count;
49212 unsigned long flags;
49213
49214diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49215index be8ce54..94ed33a 100644
49216--- a/drivers/scsi/pmcraid.c
49217+++ b/drivers/scsi/pmcraid.c
49218@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49219 res->scsi_dev = scsi_dev;
49220 scsi_dev->hostdata = res;
49221 res->change_detected = 0;
49222- atomic_set(&res->read_failures, 0);
49223- atomic_set(&res->write_failures, 0);
49224+ atomic_set_unchecked(&res->read_failures, 0);
49225+ atomic_set_unchecked(&res->write_failures, 0);
49226 rc = 0;
49227 }
49228 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49229@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49230
49231 /* If this was a SCSI read/write command keep count of errors */
49232 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49233- atomic_inc(&res->read_failures);
49234+ atomic_inc_unchecked(&res->read_failures);
49235 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49236- atomic_inc(&res->write_failures);
49237+ atomic_inc_unchecked(&res->write_failures);
49238
49239 if (!RES_IS_GSCSI(res->cfg_entry) &&
49240 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49241@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49242 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49243 * hrrq_id assigned here in queuecommand
49244 */
49245- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49246+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49247 pinstance->num_hrrq;
49248 cmd->cmd_done = pmcraid_io_done;
49249
49250@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49251 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49252 * hrrq_id assigned here in queuecommand
49253 */
49254- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49255+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49256 pinstance->num_hrrq;
49257
49258 if (request_size) {
49259@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49260
49261 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49262 /* add resources only after host is added into system */
49263- if (!atomic_read(&pinstance->expose_resources))
49264+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49265 return;
49266
49267 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49268@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49269 init_waitqueue_head(&pinstance->reset_wait_q);
49270
49271 atomic_set(&pinstance->outstanding_cmds, 0);
49272- atomic_set(&pinstance->last_message_id, 0);
49273- atomic_set(&pinstance->expose_resources, 0);
49274+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49275+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49276
49277 INIT_LIST_HEAD(&pinstance->free_res_q);
49278 INIT_LIST_HEAD(&pinstance->used_res_q);
49279@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49280 /* Schedule worker thread to handle CCN and take care of adding and
49281 * removing devices to OS
49282 */
49283- atomic_set(&pinstance->expose_resources, 1);
49284+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49285 schedule_work(&pinstance->worker_q);
49286 return rc;
49287
49288diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49289index e1d150f..6c6df44 100644
49290--- a/drivers/scsi/pmcraid.h
49291+++ b/drivers/scsi/pmcraid.h
49292@@ -748,7 +748,7 @@ struct pmcraid_instance {
49293 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49294
49295 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49296- atomic_t last_message_id;
49297+ atomic_unchecked_t last_message_id;
49298
49299 /* configuration table */
49300 struct pmcraid_config_table *cfg_table;
49301@@ -777,7 +777,7 @@ struct pmcraid_instance {
49302 atomic_t outstanding_cmds;
49303
49304 /* should add/delete resources to mid-layer now ?*/
49305- atomic_t expose_resources;
49306+ atomic_unchecked_t expose_resources;
49307
49308
49309
49310@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49311 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49312 };
49313 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49314- atomic_t read_failures; /* count of failed READ commands */
49315- atomic_t write_failures; /* count of failed WRITE commands */
49316+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49317+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49318
49319 /* To indicate add/delete/modify during CCN */
49320 u8 change_detected;
49321diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49322index 4a0d7c9..3d658d7 100644
49323--- a/drivers/scsi/qla2xxx/qla_attr.c
49324+++ b/drivers/scsi/qla2xxx/qla_attr.c
49325@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49326 return 0;
49327 }
49328
49329-struct fc_function_template qla2xxx_transport_functions = {
49330+fc_function_template_no_const qla2xxx_transport_functions = {
49331
49332 .show_host_node_name = 1,
49333 .show_host_port_name = 1,
49334@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49335 .bsg_timeout = qla24xx_bsg_timeout,
49336 };
49337
49338-struct fc_function_template qla2xxx_transport_vport_functions = {
49339+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49340
49341 .show_host_node_name = 1,
49342 .show_host_port_name = 1,
49343diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49344index 1f42662..bf9836c 100644
49345--- a/drivers/scsi/qla2xxx/qla_gbl.h
49346+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49347@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49348 struct device_attribute;
49349 extern struct device_attribute *qla2x00_host_attrs[];
49350 struct fc_function_template;
49351-extern struct fc_function_template qla2xxx_transport_functions;
49352-extern struct fc_function_template qla2xxx_transport_vport_functions;
49353+extern fc_function_template_no_const qla2xxx_transport_functions;
49354+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49355 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49356 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49357 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49358diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49359index 83cb612..9b7b08c 100644
49360--- a/drivers/scsi/qla2xxx/qla_os.c
49361+++ b/drivers/scsi/qla2xxx/qla_os.c
49362@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49363 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49364 /* Ok, a 64bit DMA mask is applicable. */
49365 ha->flags.enable_64bit_addressing = 1;
49366- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49367- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49368+ pax_open_kernel();
49369+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49370+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49371+ pax_close_kernel();
49372 return;
49373 }
49374 }
49375diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49376index aa67bb9..06d0e2a 100644
49377--- a/drivers/scsi/qla4xxx/ql4_def.h
49378+++ b/drivers/scsi/qla4xxx/ql4_def.h
49379@@ -303,7 +303,7 @@ struct ddb_entry {
49380 * (4000 only) */
49381 atomic_t relogin_timer; /* Max Time to wait for
49382 * relogin to complete */
49383- atomic_t relogin_retry_count; /* Num of times relogin has been
49384+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49385 * retried */
49386 uint32_t default_time2wait; /* Default Min time between
49387 * relogins (+aens) */
49388diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49389index c21adc3..1b4155f 100644
49390--- a/drivers/scsi/qla4xxx/ql4_os.c
49391+++ b/drivers/scsi/qla4xxx/ql4_os.c
49392@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49393 */
49394 if (!iscsi_is_session_online(cls_sess)) {
49395 /* Reset retry relogin timer */
49396- atomic_inc(&ddb_entry->relogin_retry_count);
49397+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49398 DEBUG2(ql4_printk(KERN_INFO, ha,
49399 "%s: index[%d] relogin timed out-retrying"
49400 " relogin (%d), retry (%d)\n", __func__,
49401 ddb_entry->fw_ddb_index,
49402- atomic_read(&ddb_entry->relogin_retry_count),
49403+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49404 ddb_entry->default_time2wait + 4));
49405 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49406 atomic_set(&ddb_entry->retry_relogin_timer,
49407@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49408
49409 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49410 atomic_set(&ddb_entry->relogin_timer, 0);
49411- atomic_set(&ddb_entry->relogin_retry_count, 0);
49412+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49413 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49414 ddb_entry->default_relogin_timeout =
49415 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49416diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49417index d8afec8..3ec7152 100644
49418--- a/drivers/scsi/scsi.c
49419+++ b/drivers/scsi/scsi.c
49420@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49421 struct Scsi_Host *host = cmd->device->host;
49422 int rtn = 0;
49423
49424- atomic_inc(&cmd->device->iorequest_cnt);
49425+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49426
49427 /* check if the device is still usable */
49428 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49429diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49430index 62ec84b..93159d8 100644
49431--- a/drivers/scsi/scsi_lib.c
49432+++ b/drivers/scsi/scsi_lib.c
49433@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49434 shost = sdev->host;
49435 scsi_init_cmd_errh(cmd);
49436 cmd->result = DID_NO_CONNECT << 16;
49437- atomic_inc(&cmd->device->iorequest_cnt);
49438+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49439
49440 /*
49441 * SCSI request completion path will do scsi_device_unbusy(),
49442@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49443
49444 INIT_LIST_HEAD(&cmd->eh_entry);
49445
49446- atomic_inc(&cmd->device->iodone_cnt);
49447+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49448 if (cmd->result)
49449- atomic_inc(&cmd->device->ioerr_cnt);
49450+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49451
49452 disposition = scsi_decide_disposition(cmd);
49453 if (disposition != SUCCESS &&
49454diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49455index 9117d0b..d289a7a 100644
49456--- a/drivers/scsi/scsi_sysfs.c
49457+++ b/drivers/scsi/scsi_sysfs.c
49458@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49459 char *buf) \
49460 { \
49461 struct scsi_device *sdev = to_scsi_device(dev); \
49462- unsigned long long count = atomic_read(&sdev->field); \
49463+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49464 return snprintf(buf, 20, "0x%llx\n", count); \
49465 } \
49466 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49467diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49468index 84a1fdf..693b0d6 100644
49469--- a/drivers/scsi/scsi_tgt_lib.c
49470+++ b/drivers/scsi/scsi_tgt_lib.c
49471@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49472 int err;
49473
49474 dprintk("%lx %u\n", uaddr, len);
49475- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49476+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49477 if (err) {
49478 /*
49479 * TODO: need to fixup sg_tablesize, max_segment_size,
49480diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49481index 4628fd5..a94a1c2 100644
49482--- a/drivers/scsi/scsi_transport_fc.c
49483+++ b/drivers/scsi/scsi_transport_fc.c
49484@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49485 * Netlink Infrastructure
49486 */
49487
49488-static atomic_t fc_event_seq;
49489+static atomic_unchecked_t fc_event_seq;
49490
49491 /**
49492 * fc_get_event_number - Obtain the next sequential FC event number
49493@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49494 u32
49495 fc_get_event_number(void)
49496 {
49497- return atomic_add_return(1, &fc_event_seq);
49498+ return atomic_add_return_unchecked(1, &fc_event_seq);
49499 }
49500 EXPORT_SYMBOL(fc_get_event_number);
49501
49502@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49503 {
49504 int error;
49505
49506- atomic_set(&fc_event_seq, 0);
49507+ atomic_set_unchecked(&fc_event_seq, 0);
49508
49509 error = transport_class_register(&fc_host_class);
49510 if (error)
49511@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49512 char *cp;
49513
49514 *val = simple_strtoul(buf, &cp, 0);
49515- if ((*cp && (*cp != '\n')) || (*val < 0))
49516+ if (*cp && (*cp != '\n'))
49517 return -EINVAL;
49518 /*
49519 * Check for overflow; dev_loss_tmo is u32
49520diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49521index fd8ffe6..fd0bebf 100644
49522--- a/drivers/scsi/scsi_transport_iscsi.c
49523+++ b/drivers/scsi/scsi_transport_iscsi.c
49524@@ -79,7 +79,7 @@ struct iscsi_internal {
49525 struct transport_container session_cont;
49526 };
49527
49528-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49529+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49530 static struct workqueue_struct *iscsi_eh_timer_workq;
49531
49532 static DEFINE_IDA(iscsi_sess_ida);
49533@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49534 int err;
49535
49536 ihost = shost->shost_data;
49537- session->sid = atomic_add_return(1, &iscsi_session_nr);
49538+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49539
49540 if (target_id == ISCSI_MAX_TARGET) {
49541 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49542@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49543 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49544 ISCSI_TRANSPORT_VERSION);
49545
49546- atomic_set(&iscsi_session_nr, 0);
49547+ atomic_set_unchecked(&iscsi_session_nr, 0);
49548
49549 err = class_register(&iscsi_transport_class);
49550 if (err)
49551diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49552index d47ffc8..30f46a9 100644
49553--- a/drivers/scsi/scsi_transport_srp.c
49554+++ b/drivers/scsi/scsi_transport_srp.c
49555@@ -36,7 +36,7 @@
49556 #include "scsi_transport_srp_internal.h"
49557
49558 struct srp_host_attrs {
49559- atomic_t next_port_id;
49560+ atomic_unchecked_t next_port_id;
49561 };
49562 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49563
49564@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49565 struct Scsi_Host *shost = dev_to_shost(dev);
49566 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49567
49568- atomic_set(&srp_host->next_port_id, 0);
49569+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49570 return 0;
49571 }
49572
49573@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49574 rport_fast_io_fail_timedout);
49575 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49576
49577- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49578+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49579 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49580
49581 transport_setup_device(&rport->dev);
49582diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49583index 36d1a23..3f33303 100644
49584--- a/drivers/scsi/sd.c
49585+++ b/drivers/scsi/sd.c
49586@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49587 sdkp->disk = gd;
49588 sdkp->index = index;
49589 atomic_set(&sdkp->openers, 0);
49590- atomic_set(&sdkp->device->ioerr_cnt, 0);
49591+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49592
49593 if (!sdp->request_queue->rq_timeout) {
49594 if (sdp->type != TYPE_MOD)
49595diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49596index df5e961..df6b97f 100644
49597--- a/drivers/scsi/sg.c
49598+++ b/drivers/scsi/sg.c
49599@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49600 sdp->disk->disk_name,
49601 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49602 NULL,
49603- (char *)arg);
49604+ (char __user *)arg);
49605 case BLKTRACESTART:
49606 return blk_trace_startstop(sdp->device->request_queue, 1);
49607 case BLKTRACESTOP:
49608diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49609index d0b28bb..a263613 100644
49610--- a/drivers/spi/spi.c
49611+++ b/drivers/spi/spi.c
49612@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49613 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49614
49615 /* portable code must never pass more than 32 bytes */
49616-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49617+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49618
49619 static u8 *buf;
49620
49621diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49622index 2c61783..4d49e4e 100644
49623--- a/drivers/staging/android/timed_output.c
49624+++ b/drivers/staging/android/timed_output.c
49625@@ -25,7 +25,7 @@
49626 #include "timed_output.h"
49627
49628 static struct class *timed_output_class;
49629-static atomic_t device_count;
49630+static atomic_unchecked_t device_count;
49631
49632 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49633 char *buf)
49634@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49635 timed_output_class = class_create(THIS_MODULE, "timed_output");
49636 if (IS_ERR(timed_output_class))
49637 return PTR_ERR(timed_output_class);
49638- atomic_set(&device_count, 0);
49639+ atomic_set_unchecked(&device_count, 0);
49640 timed_output_class->dev_groups = timed_output_groups;
49641 }
49642
49643@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49644 if (ret < 0)
49645 return ret;
49646
49647- tdev->index = atomic_inc_return(&device_count);
49648+ tdev->index = atomic_inc_return_unchecked(&device_count);
49649 tdev->dev = device_create(timed_output_class, NULL,
49650 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49651 if (IS_ERR(tdev->dev))
49652diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49653index fe47cd3..19a1bd1 100644
49654--- a/drivers/staging/gdm724x/gdm_tty.c
49655+++ b/drivers/staging/gdm724x/gdm_tty.c
49656@@ -44,7 +44,7 @@
49657 #define gdm_tty_send_control(n, r, v, d, l) (\
49658 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49659
49660-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49661+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49662
49663 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49664 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49665diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49666index 236ed66..dd9cd74 100644
49667--- a/drivers/staging/imx-drm/imx-drm-core.c
49668+++ b/drivers/staging/imx-drm/imx-drm-core.c
49669@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49670 goto err_busy;
49671 }
49672
49673- if (imxdrm->drm->open_count) {
49674+ if (local_read(&imxdrm->drm->open_count)) {
49675 ret = -EBUSY;
49676 goto err_busy;
49677 }
49678@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49679
49680 mutex_lock(&imxdrm->mutex);
49681
49682- if (imxdrm->drm->open_count) {
49683+ if (local_read(&imxdrm->drm->open_count)) {
49684 ret = -EBUSY;
49685 goto err_busy;
49686 }
49687@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49688
49689 mutex_lock(&imxdrm->mutex);
49690
49691- if (imxdrm->drm->open_count) {
49692+ if (local_read(&imxdrm->drm->open_count)) {
49693 ret = -EBUSY;
49694 goto err_busy;
49695 }
49696diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49697index 3f8020c..649fded 100644
49698--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49699+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49700@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49701 return 0;
49702 }
49703
49704-sfw_test_client_ops_t brw_test_client;
49705-void brw_init_test_client(void)
49706-{
49707- brw_test_client.tso_init = brw_client_init;
49708- brw_test_client.tso_fini = brw_client_fini;
49709- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49710- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49711+sfw_test_client_ops_t brw_test_client = {
49712+ .tso_init = brw_client_init,
49713+ .tso_fini = brw_client_fini,
49714+ .tso_prep_rpc = brw_client_prep_rpc,
49715+ .tso_done_rpc = brw_client_done_rpc,
49716 };
49717
49718 srpc_service_t brw_test_service;
49719diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49720index 050723a..fa6fdf1 100644
49721--- a/drivers/staging/lustre/lnet/selftest/framework.c
49722+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49723@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49724
49725 extern sfw_test_client_ops_t ping_test_client;
49726 extern srpc_service_t ping_test_service;
49727-extern void ping_init_test_client(void);
49728 extern void ping_init_test_service(void);
49729
49730 extern sfw_test_client_ops_t brw_test_client;
49731 extern srpc_service_t brw_test_service;
49732-extern void brw_init_test_client(void);
49733 extern void brw_init_test_service(void);
49734
49735
49736@@ -1684,12 +1682,10 @@ sfw_startup (void)
49737 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49738 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49739
49740- brw_init_test_client();
49741 brw_init_test_service();
49742 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49743 LASSERT (rc == 0);
49744
49745- ping_init_test_client();
49746 ping_init_test_service();
49747 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49748 LASSERT (rc == 0);
49749diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49750index 750cac4..e4d751f 100644
49751--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49752+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49753@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49754 return 0;
49755 }
49756
49757-sfw_test_client_ops_t ping_test_client;
49758-void ping_init_test_client(void)
49759-{
49760- ping_test_client.tso_init = ping_client_init;
49761- ping_test_client.tso_fini = ping_client_fini;
49762- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49763- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49764-}
49765+sfw_test_client_ops_t ping_test_client = {
49766+ .tso_init = ping_client_init,
49767+ .tso_fini = ping_client_fini,
49768+ .tso_prep_rpc = ping_client_prep_rpc,
49769+ .tso_done_rpc = ping_client_done_rpc,
49770+};
49771
49772 srpc_service_t ping_test_service;
49773 void ping_init_test_service(void)
49774diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49775index ec4bb5e..740c6dd 100644
49776--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49777+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49778@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49779 ldlm_completion_callback lcs_completion;
49780 ldlm_blocking_callback lcs_blocking;
49781 ldlm_glimpse_callback lcs_glimpse;
49782-};
49783+} __no_const;
49784
49785 /* ldlm_lockd.c */
49786 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49787diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49788index c3470ce..2bef527 100644
49789--- a/drivers/staging/lustre/lustre/include/obd.h
49790+++ b/drivers/staging/lustre/lustre/include/obd.h
49791@@ -1426,7 +1426,7 @@ struct md_ops {
49792 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49793 * wrapper function in include/linux/obd_class.h.
49794 */
49795-};
49796+} __no_const;
49797
49798 struct lsm_operations {
49799 void (*lsm_free)(struct lov_stripe_md *);
49800diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49801index c9aae13..60ea292 100644
49802--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49803+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49804@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49805 int added = (mode == LCK_NL);
49806 int overlaps = 0;
49807 int splitted = 0;
49808- const struct ldlm_callback_suite null_cbs = { NULL };
49809+ const struct ldlm_callback_suite null_cbs = { };
49810
49811 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49812 LPU64" end "LPU64"\n", *flags,
49813diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49814index e947b91..f408990 100644
49815--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49816+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49817@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49818 int LL_PROC_PROTO(proc_console_max_delay_cs)
49819 {
49820 int rc, max_delay_cs;
49821- ctl_table_t dummy = *table;
49822+ ctl_table_no_const dummy = *table;
49823 cfs_duration_t d;
49824
49825 dummy.data = &max_delay_cs;
49826@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49827 int LL_PROC_PROTO(proc_console_min_delay_cs)
49828 {
49829 int rc, min_delay_cs;
49830- ctl_table_t dummy = *table;
49831+ ctl_table_no_const dummy = *table;
49832 cfs_duration_t d;
49833
49834 dummy.data = &min_delay_cs;
49835@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49836 int LL_PROC_PROTO(proc_console_backoff)
49837 {
49838 int rc, backoff;
49839- ctl_table_t dummy = *table;
49840+ ctl_table_no_const dummy = *table;
49841
49842 dummy.data = &backoff;
49843 dummy.proc_handler = &proc_dointvec;
49844diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49845index 24ae26d..9d09cab 100644
49846--- a/drivers/staging/lustre/lustre/libcfs/module.c
49847+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49848@@ -313,11 +313,11 @@ out:
49849
49850
49851 struct cfs_psdev_ops libcfs_psdev_ops = {
49852- libcfs_psdev_open,
49853- libcfs_psdev_release,
49854- NULL,
49855- NULL,
49856- libcfs_ioctl
49857+ .p_open = libcfs_psdev_open,
49858+ .p_close = libcfs_psdev_release,
49859+ .p_read = NULL,
49860+ .p_write = NULL,
49861+ .p_ioctl = libcfs_ioctl
49862 };
49863
49864 extern int insert_proc(void);
49865diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49866index 52b7731..d604da0 100644
49867--- a/drivers/staging/lustre/lustre/llite/dir.c
49868+++ b/drivers/staging/lustre/lustre/llite/dir.c
49869@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49870 int mode;
49871 int err;
49872
49873- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49874+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49875 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49876 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49877 lump);
49878diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49879index 480b7c4..6846324 100644
49880--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49881+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49882@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49883
49884 static int solo_sysfs_init(struct solo_dev *solo_dev)
49885 {
49886- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49887+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49888 struct device *dev = &solo_dev->dev;
49889 const char *driver;
49890 int i;
49891diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49892index 1db18c7..35e6afc 100644
49893--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49894+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49895@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49896
49897 int solo_g723_init(struct solo_dev *solo_dev)
49898 {
49899- static struct snd_device_ops ops = { NULL };
49900+ static struct snd_device_ops ops = { };
49901 struct snd_card *card;
49902 struct snd_kcontrol_new kctl;
49903 char name[32];
49904diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49905index 7f2f247..d999137 100644
49906--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49907+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49908@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49909
49910 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49911 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49912- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49913+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49914 if (p2m_id < 0)
49915 p2m_id = -p2m_id;
49916 }
49917diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49918index 8964f8b..36eb087 100644
49919--- a/drivers/staging/media/solo6x10/solo6x10.h
49920+++ b/drivers/staging/media/solo6x10/solo6x10.h
49921@@ -237,7 +237,7 @@ struct solo_dev {
49922
49923 /* P2M DMA Engine */
49924 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49925- atomic_t p2m_count;
49926+ atomic_unchecked_t p2m_count;
49927 int p2m_jiffies;
49928 unsigned int p2m_timeouts;
49929
49930diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49931index a0f4868..139f1fb 100644
49932--- a/drivers/staging/octeon/ethernet-rx.c
49933+++ b/drivers/staging/octeon/ethernet-rx.c
49934@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49935 /* Increment RX stats for virtual ports */
49936 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49937 #ifdef CONFIG_64BIT
49938- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49939- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49940+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49941+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49942 #else
49943- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49944- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49945+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49946+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49947 #endif
49948 }
49949 netif_receive_skb(skb);
49950@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49951 dev->name);
49952 */
49953 #ifdef CONFIG_64BIT
49954- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49955+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49956 #else
49957- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49958+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49959 #endif
49960 dev_kfree_skb_irq(skb);
49961 }
49962diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49963index 089dc4b..c9a687e 100644
49964--- a/drivers/staging/octeon/ethernet.c
49965+++ b/drivers/staging/octeon/ethernet.c
49966@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49967 * since the RX tasklet also increments it.
49968 */
49969 #ifdef CONFIG_64BIT
49970- atomic64_add(rx_status.dropped_packets,
49971- (atomic64_t *)&priv->stats.rx_dropped);
49972+ atomic64_add_unchecked(rx_status.dropped_packets,
49973+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49974 #else
49975- atomic_add(rx_status.dropped_packets,
49976- (atomic_t *)&priv->stats.rx_dropped);
49977+ atomic_add_unchecked(rx_status.dropped_packets,
49978+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49979 #endif
49980 }
49981
49982diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49983index c274b34..f84de76 100644
49984--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49985+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49986@@ -271,7 +271,7 @@ struct hal_ops {
49987 s32 (*c2h_handler)(struct adapter *padapter,
49988 struct c2h_evt_hdr *c2h_evt);
49989 c2h_id_filter c2h_id_filter_ccx;
49990-};
49991+} __no_const;
49992
49993 enum rt_eeprom_type {
49994 EEPROM_93C46,
49995diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49996index 3d1dfcc..ff5620a 100644
49997--- a/drivers/staging/rtl8188eu/include/rtw_io.h
49998+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49999@@ -126,7 +126,7 @@ struct _io_ops {
50000 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50001 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50002 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50003-};
50004+} __no_const;
50005
50006 struct io_req {
50007 struct list_head list;
50008diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50009index dc23395..cf7e9b1 100644
50010--- a/drivers/staging/rtl8712/rtl871x_io.h
50011+++ b/drivers/staging/rtl8712/rtl871x_io.h
50012@@ -108,7 +108,7 @@ struct _io_ops {
50013 u8 *pmem);
50014 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50015 u8 *pmem);
50016-};
50017+} __no_const;
50018
50019 struct io_req {
50020 struct list_head list;
50021diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50022index 1f5088b..0e59820 100644
50023--- a/drivers/staging/sbe-2t3e3/netdev.c
50024+++ b/drivers/staging/sbe-2t3e3/netdev.c
50025@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50026 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50027
50028 if (rlen)
50029- if (copy_to_user(data, &resp, rlen))
50030+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50031 return -EFAULT;
50032
50033 return 0;
50034diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50035index a863a98..d272795 100644
50036--- a/drivers/staging/usbip/vhci.h
50037+++ b/drivers/staging/usbip/vhci.h
50038@@ -83,7 +83,7 @@ struct vhci_hcd {
50039 unsigned resuming:1;
50040 unsigned long re_timeout;
50041
50042- atomic_t seqnum;
50043+ atomic_unchecked_t seqnum;
50044
50045 /*
50046 * NOTE:
50047diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50048index 72391ef..7c6717a 100644
50049--- a/drivers/staging/usbip/vhci_hcd.c
50050+++ b/drivers/staging/usbip/vhci_hcd.c
50051@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50052
50053 spin_lock(&vdev->priv_lock);
50054
50055- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50056+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50057 if (priv->seqnum == 0xffff)
50058 dev_info(&urb->dev->dev, "seqnum max\n");
50059
50060@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50061 return -ENOMEM;
50062 }
50063
50064- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50065+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50066 if (unlink->seqnum == 0xffff)
50067 pr_info("seqnum max\n");
50068
50069@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50070 vdev->rhport = rhport;
50071 }
50072
50073- atomic_set(&vhci->seqnum, 0);
50074+ atomic_set_unchecked(&vhci->seqnum, 0);
50075 spin_lock_init(&vhci->lock);
50076
50077 hcd->power_budget = 0; /* no limit */
50078diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50079index d07fcb5..358e1e1 100644
50080--- a/drivers/staging/usbip/vhci_rx.c
50081+++ b/drivers/staging/usbip/vhci_rx.c
50082@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50083 if (!urb) {
50084 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50085 pr_info("max seqnum %d\n",
50086- atomic_read(&the_controller->seqnum));
50087+ atomic_read_unchecked(&the_controller->seqnum));
50088 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50089 return;
50090 }
50091diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50092index 6eecd53..29317c6 100644
50093--- a/drivers/staging/vt6655/hostap.c
50094+++ b/drivers/staging/vt6655/hostap.c
50095@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50096 *
50097 */
50098
50099+static net_device_ops_no_const apdev_netdev_ops;
50100+
50101 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50102 {
50103 PSDevice apdev_priv;
50104 struct net_device *dev = pDevice->dev;
50105 int ret;
50106- const struct net_device_ops apdev_netdev_ops = {
50107- .ndo_start_xmit = pDevice->tx_80211,
50108- };
50109
50110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50111
50112@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50113 *apdev_priv = *pDevice;
50114 eth_hw_addr_inherit(pDevice->apdev, dev);
50115
50116+ /* only half broken now */
50117+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50118 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50119
50120 pDevice->apdev->type = ARPHRD_IEEE80211;
50121diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50122index 67ba48b..24e602f 100644
50123--- a/drivers/staging/vt6656/hostap.c
50124+++ b/drivers/staging/vt6656/hostap.c
50125@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50126 *
50127 */
50128
50129+static net_device_ops_no_const apdev_netdev_ops;
50130+
50131 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50132 {
50133 struct vnt_private *apdev_priv;
50134 struct net_device *dev = pDevice->dev;
50135 int ret;
50136- const struct net_device_ops apdev_netdev_ops = {
50137- .ndo_start_xmit = pDevice->tx_80211,
50138- };
50139
50140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50141
50142@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50143 *apdev_priv = *pDevice;
50144 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50145
50146+ /* only half broken now */
50147+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50148 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50149
50150 pDevice->apdev->type = ARPHRD_IEEE80211;
50151diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50152index 24884ca..26c8220 100644
50153--- a/drivers/target/sbp/sbp_target.c
50154+++ b/drivers/target/sbp/sbp_target.c
50155@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50156
50157 #define SESSION_MAINTENANCE_INTERVAL HZ
50158
50159-static atomic_t login_id = ATOMIC_INIT(0);
50160+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50161
50162 static void session_maintenance_work(struct work_struct *);
50163 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50164@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50165 login->lun = se_lun;
50166 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50167 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50168- login->login_id = atomic_inc_return(&login_id);
50169+ login->login_id = atomic_inc_return_unchecked(&login_id);
50170
50171 login->tgt_agt = sbp_target_agent_register(login);
50172 if (IS_ERR(login->tgt_agt)) {
50173diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50174index 65001e1..2ebfbb9 100644
50175--- a/drivers/target/target_core_device.c
50176+++ b/drivers/target/target_core_device.c
50177@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50178 spin_lock_init(&dev->se_tmr_lock);
50179 spin_lock_init(&dev->qf_cmd_lock);
50180 sema_init(&dev->caw_sem, 1);
50181- atomic_set(&dev->dev_ordered_id, 0);
50182+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50183 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50184 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50185 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50186diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50187index 2956250..b10f722 100644
50188--- a/drivers/target/target_core_transport.c
50189+++ b/drivers/target/target_core_transport.c
50190@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50191 * Used to determine when ORDERED commands should go from
50192 * Dormant to Active status.
50193 */
50194- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50195+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50196 smp_mb__after_atomic_inc();
50197 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50198 cmd->se_ordered_id, cmd->sam_task_attr,
50199diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50200index 04b1be7..5eff86d 100644
50201--- a/drivers/thermal/of-thermal.c
50202+++ b/drivers/thermal/of-thermal.c
50203@@ -30,6 +30,7 @@
50204 #include <linux/err.h>
50205 #include <linux/export.h>
50206 #include <linux/string.h>
50207+#include <linux/mm.h>
50208
50209 #include "thermal_core.h"
50210
50211@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50212 tz->get_trend = get_trend;
50213 tz->sensor_data = data;
50214
50215- tzd->ops->get_temp = of_thermal_get_temp;
50216- tzd->ops->get_trend = of_thermal_get_trend;
50217+ pax_open_kernel();
50218+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50219+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50220+ pax_close_kernel();
50221 mutex_unlock(&tzd->lock);
50222
50223 return tzd;
50224@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50225 return;
50226
50227 mutex_lock(&tzd->lock);
50228- tzd->ops->get_temp = NULL;
50229- tzd->ops->get_trend = NULL;
50230+ pax_open_kernel();
50231+ *(void **)&tzd->ops->get_temp = NULL;
50232+ *(void **)&tzd->ops->get_trend = NULL;
50233+ pax_close_kernel();
50234
50235 tz->get_temp = NULL;
50236 tz->get_trend = NULL;
50237diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50238index a57bb5a..1f727d33 100644
50239--- a/drivers/tty/cyclades.c
50240+++ b/drivers/tty/cyclades.c
50241@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50242 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50243 info->port.count);
50244 #endif
50245- info->port.count++;
50246+ atomic_inc(&info->port.count);
50247 #ifdef CY_DEBUG_COUNT
50248 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50249- current->pid, info->port.count);
50250+ current->pid, atomic_read(&info->port.count));
50251 #endif
50252
50253 /*
50254@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50255 for (j = 0; j < cy_card[i].nports; j++) {
50256 info = &cy_card[i].ports[j];
50257
50258- if (info->port.count) {
50259+ if (atomic_read(&info->port.count)) {
50260 /* XXX is the ldisc num worth this? */
50261 struct tty_struct *tty;
50262 struct tty_ldisc *ld;
50263diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50264index 94f9e3a..4c8afa8 100644
50265--- a/drivers/tty/hvc/hvc_console.c
50266+++ b/drivers/tty/hvc/hvc_console.c
50267@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50268
50269 spin_lock_irqsave(&hp->port.lock, flags);
50270 /* Check and then increment for fast path open. */
50271- if (hp->port.count++ > 0) {
50272+ if (atomic_inc_return(&hp->port.count) > 1) {
50273 spin_unlock_irqrestore(&hp->port.lock, flags);
50274 hvc_kick();
50275 return 0;
50276@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50277
50278 spin_lock_irqsave(&hp->port.lock, flags);
50279
50280- if (--hp->port.count == 0) {
50281+ if (atomic_dec_return(&hp->port.count) == 0) {
50282 spin_unlock_irqrestore(&hp->port.lock, flags);
50283 /* We are done with the tty pointer now. */
50284 tty_port_tty_set(&hp->port, NULL);
50285@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50286 */
50287 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50288 } else {
50289- if (hp->port.count < 0)
50290+ if (atomic_read(&hp->port.count) < 0)
50291 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50292- hp->vtermno, hp->port.count);
50293+ hp->vtermno, atomic_read(&hp->port.count));
50294 spin_unlock_irqrestore(&hp->port.lock, flags);
50295 }
50296 }
50297@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50298 * open->hangup case this can be called after the final close so prevent
50299 * that from happening for now.
50300 */
50301- if (hp->port.count <= 0) {
50302+ if (atomic_read(&hp->port.count) <= 0) {
50303 spin_unlock_irqrestore(&hp->port.lock, flags);
50304 return;
50305 }
50306
50307- hp->port.count = 0;
50308+ atomic_set(&hp->port.count, 0);
50309 spin_unlock_irqrestore(&hp->port.lock, flags);
50310 tty_port_tty_set(&hp->port, NULL);
50311
50312@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50313 return -EPIPE;
50314
50315 /* FIXME what's this (unprotected) check for? */
50316- if (hp->port.count <= 0)
50317+ if (atomic_read(&hp->port.count) <= 0)
50318 return -EIO;
50319
50320 spin_lock_irqsave(&hp->lock, flags);
50321diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50322index 81e939e..95ead10 100644
50323--- a/drivers/tty/hvc/hvcs.c
50324+++ b/drivers/tty/hvc/hvcs.c
50325@@ -83,6 +83,7 @@
50326 #include <asm/hvcserver.h>
50327 #include <asm/uaccess.h>
50328 #include <asm/vio.h>
50329+#include <asm/local.h>
50330
50331 /*
50332 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50333@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50334
50335 spin_lock_irqsave(&hvcsd->lock, flags);
50336
50337- if (hvcsd->port.count > 0) {
50338+ if (atomic_read(&hvcsd->port.count) > 0) {
50339 spin_unlock_irqrestore(&hvcsd->lock, flags);
50340 printk(KERN_INFO "HVCS: vterm state unchanged. "
50341 "The hvcs device node is still in use.\n");
50342@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50343 }
50344 }
50345
50346- hvcsd->port.count = 0;
50347+ atomic_set(&hvcsd->port.count, 0);
50348 hvcsd->port.tty = tty;
50349 tty->driver_data = hvcsd;
50350
50351@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50352 unsigned long flags;
50353
50354 spin_lock_irqsave(&hvcsd->lock, flags);
50355- hvcsd->port.count++;
50356+ atomic_inc(&hvcsd->port.count);
50357 hvcsd->todo_mask |= HVCS_SCHED_READ;
50358 spin_unlock_irqrestore(&hvcsd->lock, flags);
50359
50360@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50361 hvcsd = tty->driver_data;
50362
50363 spin_lock_irqsave(&hvcsd->lock, flags);
50364- if (--hvcsd->port.count == 0) {
50365+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50366
50367 vio_disable_interrupts(hvcsd->vdev);
50368
50369@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50370
50371 free_irq(irq, hvcsd);
50372 return;
50373- } else if (hvcsd->port.count < 0) {
50374+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50375 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50376 " is missmanaged.\n",
50377- hvcsd->vdev->unit_address, hvcsd->port.count);
50378+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50379 }
50380
50381 spin_unlock_irqrestore(&hvcsd->lock, flags);
50382@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50383
50384 spin_lock_irqsave(&hvcsd->lock, flags);
50385 /* Preserve this so that we know how many kref refs to put */
50386- temp_open_count = hvcsd->port.count;
50387+ temp_open_count = atomic_read(&hvcsd->port.count);
50388
50389 /*
50390 * Don't kref put inside the spinlock because the destruction
50391@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50392 tty->driver_data = NULL;
50393 hvcsd->port.tty = NULL;
50394
50395- hvcsd->port.count = 0;
50396+ atomic_set(&hvcsd->port.count, 0);
50397
50398 /* This will drop any buffered data on the floor which is OK in a hangup
50399 * scenario. */
50400@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50401 * the middle of a write operation? This is a crummy place to do this
50402 * but we want to keep it all in the spinlock.
50403 */
50404- if (hvcsd->port.count <= 0) {
50405+ if (atomic_read(&hvcsd->port.count) <= 0) {
50406 spin_unlock_irqrestore(&hvcsd->lock, flags);
50407 return -ENODEV;
50408 }
50409@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50410 {
50411 struct hvcs_struct *hvcsd = tty->driver_data;
50412
50413- if (!hvcsd || hvcsd->port.count <= 0)
50414+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50415 return 0;
50416
50417 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50418diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50419index 4190199..06d5bfa 100644
50420--- a/drivers/tty/hvc/hvsi.c
50421+++ b/drivers/tty/hvc/hvsi.c
50422@@ -85,7 +85,7 @@ struct hvsi_struct {
50423 int n_outbuf;
50424 uint32_t vtermno;
50425 uint32_t virq;
50426- atomic_t seqno; /* HVSI packet sequence number */
50427+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50428 uint16_t mctrl;
50429 uint8_t state; /* HVSI protocol state */
50430 uint8_t flags;
50431@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50432
50433 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50434 packet.hdr.len = sizeof(struct hvsi_query_response);
50435- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50436+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50437 packet.verb = VSV_SEND_VERSION_NUMBER;
50438 packet.u.version = HVSI_VERSION;
50439 packet.query_seqno = query_seqno+1;
50440@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50441
50442 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50443 packet.hdr.len = sizeof(struct hvsi_query);
50444- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50445+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50446 packet.verb = verb;
50447
50448 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50449@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50450 int wrote;
50451
50452 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50453- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50454+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50455 packet.hdr.len = sizeof(struct hvsi_control);
50456 packet.verb = VSV_SET_MODEM_CTL;
50457 packet.mask = HVSI_TSDTR;
50458@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50459 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50460
50461 packet.hdr.type = VS_DATA_PACKET_HEADER;
50462- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50463+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50464 packet.hdr.len = count + sizeof(struct hvsi_header);
50465 memcpy(&packet.data, buf, count);
50466
50467@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50468 struct hvsi_control packet __ALIGNED__;
50469
50470 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50471- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50472+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50473 packet.hdr.len = 6;
50474 packet.verb = VSV_CLOSE_PROTOCOL;
50475
50476@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50477
50478 tty_port_tty_set(&hp->port, tty);
50479 spin_lock_irqsave(&hp->lock, flags);
50480- hp->port.count++;
50481+ atomic_inc(&hp->port.count);
50482 atomic_set(&hp->seqno, 0);
50483 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50484 spin_unlock_irqrestore(&hp->lock, flags);
50485@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50486
50487 spin_lock_irqsave(&hp->lock, flags);
50488
50489- if (--hp->port.count == 0) {
50490+ if (atomic_dec_return(&hp->port.count) == 0) {
50491 tty_port_tty_set(&hp->port, NULL);
50492 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50493
50494@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50495
50496 spin_lock_irqsave(&hp->lock, flags);
50497 }
50498- } else if (hp->port.count < 0)
50499+ } else if (atomic_read(&hp->port.count) < 0)
50500 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50501- hp - hvsi_ports, hp->port.count);
50502+ hp - hvsi_ports, atomic_read(&hp->port.count));
50503
50504 spin_unlock_irqrestore(&hp->lock, flags);
50505 }
50506@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50507 tty_port_tty_set(&hp->port, NULL);
50508
50509 spin_lock_irqsave(&hp->lock, flags);
50510- hp->port.count = 0;
50511+ atomic_set(&hp->port.count, 0);
50512 hp->n_outbuf = 0;
50513 spin_unlock_irqrestore(&hp->lock, flags);
50514 }
50515diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50516index 7ae6c29..05c6dba 100644
50517--- a/drivers/tty/hvc/hvsi_lib.c
50518+++ b/drivers/tty/hvc/hvsi_lib.c
50519@@ -8,7 +8,7 @@
50520
50521 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50522 {
50523- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50524+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50525
50526 /* Assumes that always succeeds, works in practice */
50527 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50528@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50529
50530 /* Reset state */
50531 pv->established = 0;
50532- atomic_set(&pv->seqno, 0);
50533+ atomic_set_unchecked(&pv->seqno, 0);
50534
50535 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50536
50537diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50538index 17ee3bf..8d2520d 100644
50539--- a/drivers/tty/ipwireless/tty.c
50540+++ b/drivers/tty/ipwireless/tty.c
50541@@ -28,6 +28,7 @@
50542 #include <linux/tty_driver.h>
50543 #include <linux/tty_flip.h>
50544 #include <linux/uaccess.h>
50545+#include <asm/local.h>
50546
50547 #include "tty.h"
50548 #include "network.h"
50549@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50550 mutex_unlock(&tty->ipw_tty_mutex);
50551 return -ENODEV;
50552 }
50553- if (tty->port.count == 0)
50554+ if (atomic_read(&tty->port.count) == 0)
50555 tty->tx_bytes_queued = 0;
50556
50557- tty->port.count++;
50558+ atomic_inc(&tty->port.count);
50559
50560 tty->port.tty = linux_tty;
50561 linux_tty->driver_data = tty;
50562@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50563
50564 static void do_ipw_close(struct ipw_tty *tty)
50565 {
50566- tty->port.count--;
50567-
50568- if (tty->port.count == 0) {
50569+ if (atomic_dec_return(&tty->port.count) == 0) {
50570 struct tty_struct *linux_tty = tty->port.tty;
50571
50572 if (linux_tty != NULL) {
50573@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50574 return;
50575
50576 mutex_lock(&tty->ipw_tty_mutex);
50577- if (tty->port.count == 0) {
50578+ if (atomic_read(&tty->port.count) == 0) {
50579 mutex_unlock(&tty->ipw_tty_mutex);
50580 return;
50581 }
50582@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50583
50584 mutex_lock(&tty->ipw_tty_mutex);
50585
50586- if (!tty->port.count) {
50587+ if (!atomic_read(&tty->port.count)) {
50588 mutex_unlock(&tty->ipw_tty_mutex);
50589 return;
50590 }
50591@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50592 return -ENODEV;
50593
50594 mutex_lock(&tty->ipw_tty_mutex);
50595- if (!tty->port.count) {
50596+ if (!atomic_read(&tty->port.count)) {
50597 mutex_unlock(&tty->ipw_tty_mutex);
50598 return -EINVAL;
50599 }
50600@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50601 if (!tty)
50602 return -ENODEV;
50603
50604- if (!tty->port.count)
50605+ if (!atomic_read(&tty->port.count))
50606 return -EINVAL;
50607
50608 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50609@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50610 if (!tty)
50611 return 0;
50612
50613- if (!tty->port.count)
50614+ if (!atomic_read(&tty->port.count))
50615 return 0;
50616
50617 return tty->tx_bytes_queued;
50618@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50619 if (!tty)
50620 return -ENODEV;
50621
50622- if (!tty->port.count)
50623+ if (!atomic_read(&tty->port.count))
50624 return -EINVAL;
50625
50626 return get_control_lines(tty);
50627@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50628 if (!tty)
50629 return -ENODEV;
50630
50631- if (!tty->port.count)
50632+ if (!atomic_read(&tty->port.count))
50633 return -EINVAL;
50634
50635 return set_control_lines(tty, set, clear);
50636@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50637 if (!tty)
50638 return -ENODEV;
50639
50640- if (!tty->port.count)
50641+ if (!atomic_read(&tty->port.count))
50642 return -EINVAL;
50643
50644 /* FIXME: Exactly how is the tty object locked here .. */
50645@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50646 * are gone */
50647 mutex_lock(&ttyj->ipw_tty_mutex);
50648 }
50649- while (ttyj->port.count)
50650+ while (atomic_read(&ttyj->port.count))
50651 do_ipw_close(ttyj);
50652 ipwireless_disassociate_network_ttys(network,
50653 ttyj->channel_idx);
50654diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50655index 1deaca4..c8582d4 100644
50656--- a/drivers/tty/moxa.c
50657+++ b/drivers/tty/moxa.c
50658@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50659 }
50660
50661 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50662- ch->port.count++;
50663+ atomic_inc(&ch->port.count);
50664 tty->driver_data = ch;
50665 tty_port_tty_set(&ch->port, tty);
50666 mutex_lock(&ch->port.mutex);
50667diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50668index 2ebe47b..3205833 100644
50669--- a/drivers/tty/n_gsm.c
50670+++ b/drivers/tty/n_gsm.c
50671@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50672 spin_lock_init(&dlci->lock);
50673 mutex_init(&dlci->mutex);
50674 dlci->fifo = &dlci->_fifo;
50675- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50676+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50677 kfree(dlci);
50678 return NULL;
50679 }
50680@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50681 struct gsm_dlci *dlci = tty->driver_data;
50682 struct tty_port *port = &dlci->port;
50683
50684- port->count++;
50685+ atomic_inc(&port->count);
50686 tty_port_tty_set(port, tty);
50687
50688 dlci->modem_rx = 0;
50689diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50690index d15624c..bd628c6 100644
50691--- a/drivers/tty/n_tty.c
50692+++ b/drivers/tty/n_tty.c
50693@@ -115,7 +115,7 @@ struct n_tty_data {
50694 int minimum_to_wake;
50695
50696 /* consumer-published */
50697- size_t read_tail;
50698+ size_t read_tail __intentional_overflow(-1);
50699 size_t line_start;
50700
50701 /* protected by output lock */
50702@@ -2356,10 +2356,18 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50703 if (tty->ops->flush_chars)
50704 tty->ops->flush_chars(tty);
50705 } else {
50706+ struct n_tty_data *ldata = tty->disc_data;
50707+ bool lock;
50708+
50709+ lock = L_ECHO(tty) || (ldata->icanon & L_ECHONL(tty));
50710+ if (lock)
50711+ mutex_lock(&ldata->output_lock);
50712 while (nr > 0) {
50713 c = tty->ops->write(tty, b, nr);
50714 if (c < 0) {
50715 retval = c;
50716+ if (lock)
50717+ mutex_unlock(&ldata->output_lock);
50718 goto break_out;
50719 }
50720 if (!c)
50721@@ -2367,6 +2375,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50722 b += c;
50723 nr -= c;
50724 }
50725+ if (lock)
50726+ mutex_unlock(&ldata->output_lock);
50727 }
50728 if (!nr)
50729 break;
50730@@ -2515,6 +2525,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50731 {
50732 *ops = tty_ldisc_N_TTY;
50733 ops->owner = NULL;
50734- ops->refcount = ops->flags = 0;
50735+ atomic_set(&ops->refcount, 0);
50736+ ops->flags = 0;
50737 }
50738 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50739diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50740index 25c9bc7..24077b7 100644
50741--- a/drivers/tty/pty.c
50742+++ b/drivers/tty/pty.c
50743@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50744 panic("Couldn't register Unix98 pts driver");
50745
50746 /* Now create the /dev/ptmx special device */
50747+ pax_open_kernel();
50748 tty_default_fops(&ptmx_fops);
50749- ptmx_fops.open = ptmx_open;
50750+ *(void **)&ptmx_fops.open = ptmx_open;
50751+ pax_close_kernel();
50752
50753 cdev_init(&ptmx_cdev, &ptmx_fops);
50754 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50755diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50756index 383c4c7..d408e21 100644
50757--- a/drivers/tty/rocket.c
50758+++ b/drivers/tty/rocket.c
50759@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50760 tty->driver_data = info;
50761 tty_port_tty_set(port, tty);
50762
50763- if (port->count++ == 0) {
50764+ if (atomic_inc_return(&port->count) == 1) {
50765 atomic_inc(&rp_num_ports_open);
50766
50767 #ifdef ROCKET_DEBUG_OPEN
50768@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50769 #endif
50770 }
50771 #ifdef ROCKET_DEBUG_OPEN
50772- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50773+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50774 #endif
50775
50776 /*
50777@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50778 spin_unlock_irqrestore(&info->port.lock, flags);
50779 return;
50780 }
50781- if (info->port.count)
50782+ if (atomic_read(&info->port.count))
50783 atomic_dec(&rp_num_ports_open);
50784 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50785 spin_unlock_irqrestore(&info->port.lock, flags);
50786diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50787index 1274499..f541382 100644
50788--- a/drivers/tty/serial/ioc4_serial.c
50789+++ b/drivers/tty/serial/ioc4_serial.c
50790@@ -437,7 +437,7 @@ struct ioc4_soft {
50791 } is_intr_info[MAX_IOC4_INTR_ENTS];
50792
50793 /* Number of entries active in the above array */
50794- atomic_t is_num_intrs;
50795+ atomic_unchecked_t is_num_intrs;
50796 } is_intr_type[IOC4_NUM_INTR_TYPES];
50797
50798 /* is_ir_lock must be held while
50799@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50800 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50801 || (type == IOC4_OTHER_INTR_TYPE)));
50802
50803- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50804+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50805 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50806
50807 /* Save off the lower level interrupt handler */
50808@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50809
50810 soft = arg;
50811 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50812- num_intrs = (int)atomic_read(
50813+ num_intrs = (int)atomic_read_unchecked(
50814 &soft->is_intr_type[intr_type].is_num_intrs);
50815
50816 this_mir = this_ir = pending_intrs(soft, intr_type);
50817diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50818index a260cde..6b2b5ce 100644
50819--- a/drivers/tty/serial/kgdboc.c
50820+++ b/drivers/tty/serial/kgdboc.c
50821@@ -24,8 +24,9 @@
50822 #define MAX_CONFIG_LEN 40
50823
50824 static struct kgdb_io kgdboc_io_ops;
50825+static struct kgdb_io kgdboc_io_ops_console;
50826
50827-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50828+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50829 static int configured = -1;
50830
50831 static char config[MAX_CONFIG_LEN];
50832@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50833 kgdboc_unregister_kbd();
50834 if (configured == 1)
50835 kgdb_unregister_io_module(&kgdboc_io_ops);
50836+ else if (configured == 2)
50837+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50838 }
50839
50840 static int configure_kgdboc(void)
50841@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50842 int err;
50843 char *cptr = config;
50844 struct console *cons;
50845+ int is_console = 0;
50846
50847 err = kgdboc_option_setup(config);
50848 if (err || !strlen(config) || isspace(config[0]))
50849 goto noconfig;
50850
50851 err = -ENODEV;
50852- kgdboc_io_ops.is_console = 0;
50853 kgdb_tty_driver = NULL;
50854
50855 kgdboc_use_kms = 0;
50856@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50857 int idx;
50858 if (cons->device && cons->device(cons, &idx) == p &&
50859 idx == tty_line) {
50860- kgdboc_io_ops.is_console = 1;
50861+ is_console = 1;
50862 break;
50863 }
50864 cons = cons->next;
50865@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50866 kgdb_tty_line = tty_line;
50867
50868 do_register:
50869- err = kgdb_register_io_module(&kgdboc_io_ops);
50870+ if (is_console) {
50871+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50872+ configured = 2;
50873+ } else {
50874+ err = kgdb_register_io_module(&kgdboc_io_ops);
50875+ configured = 1;
50876+ }
50877 if (err)
50878 goto noconfig;
50879
50880@@ -205,8 +214,6 @@ do_register:
50881 if (err)
50882 goto nmi_con_failed;
50883
50884- configured = 1;
50885-
50886 return 0;
50887
50888 nmi_con_failed:
50889@@ -223,7 +230,7 @@ noconfig:
50890 static int __init init_kgdboc(void)
50891 {
50892 /* Already configured? */
50893- if (configured == 1)
50894+ if (configured >= 1)
50895 return 0;
50896
50897 return configure_kgdboc();
50898@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50899 if (config[len - 1] == '\n')
50900 config[len - 1] = '\0';
50901
50902- if (configured == 1)
50903+ if (configured >= 1)
50904 cleanup_kgdboc();
50905
50906 /* Go and configure with the new params. */
50907@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50908 .post_exception = kgdboc_post_exp_handler,
50909 };
50910
50911+static struct kgdb_io kgdboc_io_ops_console = {
50912+ .name = "kgdboc",
50913+ .read_char = kgdboc_get_char,
50914+ .write_char = kgdboc_put_char,
50915+ .pre_exception = kgdboc_pre_exp_handler,
50916+ .post_exception = kgdboc_post_exp_handler,
50917+ .is_console = 1
50918+};
50919+
50920 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50921 /* This is only available if kgdboc is a built in for early debugging */
50922 static int __init kgdboc_early_init(char *opt)
50923diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50924index b5d779c..3622cfe 100644
50925--- a/drivers/tty/serial/msm_serial.c
50926+++ b/drivers/tty/serial/msm_serial.c
50927@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50928 .cons = MSM_CONSOLE,
50929 };
50930
50931-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50932+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50933
50934 static const struct of_device_id msm_uartdm_table[] = {
50935 { .compatible = "qcom,msm-uartdm" },
50936@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50937 int irq;
50938
50939 if (pdev->id == -1)
50940- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50941+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50942
50943 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50944 return -ENXIO;
50945diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50946index 9cd706d..6ff2de7 100644
50947--- a/drivers/tty/serial/samsung.c
50948+++ b/drivers/tty/serial/samsung.c
50949@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50950 }
50951 }
50952
50953+static int s3c64xx_serial_startup(struct uart_port *port);
50954 static int s3c24xx_serial_startup(struct uart_port *port)
50955 {
50956 struct s3c24xx_uart_port *ourport = to_ourport(port);
50957 int ret;
50958
50959+ /* Startup sequence is different for s3c64xx and higher SoC's */
50960+ if (s3c24xx_serial_has_interrupt_mask(port))
50961+ return s3c64xx_serial_startup(port);
50962+
50963 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50964 port->mapbase, port->membase);
50965
50966@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50967 /* setup info for port */
50968 port->dev = &platdev->dev;
50969
50970- /* Startup sequence is different for s3c64xx and higher SoC's */
50971- if (s3c24xx_serial_has_interrupt_mask(port))
50972- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50973-
50974 port->uartclk = 1;
50975
50976 if (cfg->uart_flags & UPF_CONS_FLOW) {
50977diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50978index ece2049..fba2524 100644
50979--- a/drivers/tty/serial/serial_core.c
50980+++ b/drivers/tty/serial/serial_core.c
50981@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50982 uart_flush_buffer(tty);
50983 uart_shutdown(tty, state);
50984 spin_lock_irqsave(&port->lock, flags);
50985- port->count = 0;
50986+ atomic_set(&port->count, 0);
50987 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50988 spin_unlock_irqrestore(&port->lock, flags);
50989 tty_port_tty_set(port, NULL);
50990@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50991 goto end;
50992 }
50993
50994- port->count++;
50995+ atomic_inc(&port->count);
50996 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50997 retval = -ENXIO;
50998 goto err_dec_count;
50999@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51000 /*
51001 * Make sure the device is in D0 state.
51002 */
51003- if (port->count == 1)
51004+ if (atomic_read(&port->count) == 1)
51005 uart_change_pm(state, UART_PM_STATE_ON);
51006
51007 /*
51008@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51009 end:
51010 return retval;
51011 err_dec_count:
51012- port->count--;
51013+ atomic_inc(&port->count);
51014 mutex_unlock(&port->mutex);
51015 goto end;
51016 }
51017diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51018index 5ae14b4..2c1288f 100644
51019--- a/drivers/tty/synclink.c
51020+++ b/drivers/tty/synclink.c
51021@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51022
51023 if (debug_level >= DEBUG_LEVEL_INFO)
51024 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51025- __FILE__,__LINE__, info->device_name, info->port.count);
51026+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51027
51028 if (tty_port_close_start(&info->port, tty, filp) == 0)
51029 goto cleanup;
51030@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51031 cleanup:
51032 if (debug_level >= DEBUG_LEVEL_INFO)
51033 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51034- tty->driver->name, info->port.count);
51035+ tty->driver->name, atomic_read(&info->port.count));
51036
51037 } /* end of mgsl_close() */
51038
51039@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51040
51041 mgsl_flush_buffer(tty);
51042 shutdown(info);
51043-
51044- info->port.count = 0;
51045+
51046+ atomic_set(&info->port.count, 0);
51047 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51048 info->port.tty = NULL;
51049
51050@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51051
51052 if (debug_level >= DEBUG_LEVEL_INFO)
51053 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51054- __FILE__,__LINE__, tty->driver->name, port->count );
51055+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51056
51057 spin_lock_irqsave(&info->irq_spinlock, flags);
51058 if (!tty_hung_up_p(filp)) {
51059 extra_count = true;
51060- port->count--;
51061+ atomic_dec(&port->count);
51062 }
51063 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51064 port->blocked_open++;
51065@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51066
51067 if (debug_level >= DEBUG_LEVEL_INFO)
51068 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51069- __FILE__,__LINE__, tty->driver->name, port->count );
51070+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51071
51072 tty_unlock(tty);
51073 schedule();
51074@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51075
51076 /* FIXME: Racy on hangup during close wait */
51077 if (extra_count)
51078- port->count++;
51079+ atomic_inc(&port->count);
51080 port->blocked_open--;
51081
51082 if (debug_level >= DEBUG_LEVEL_INFO)
51083 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51084- __FILE__,__LINE__, tty->driver->name, port->count );
51085+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51086
51087 if (!retval)
51088 port->flags |= ASYNC_NORMAL_ACTIVE;
51089@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51090
51091 if (debug_level >= DEBUG_LEVEL_INFO)
51092 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51093- __FILE__,__LINE__,tty->driver->name, info->port.count);
51094+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51095
51096 /* If port is closing, signal caller to try again */
51097 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51098@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51099 spin_unlock_irqrestore(&info->netlock, flags);
51100 goto cleanup;
51101 }
51102- info->port.count++;
51103+ atomic_inc(&info->port.count);
51104 spin_unlock_irqrestore(&info->netlock, flags);
51105
51106- if (info->port.count == 1) {
51107+ if (atomic_read(&info->port.count) == 1) {
51108 /* 1st open on this device, init hardware */
51109 retval = startup(info);
51110 if (retval < 0)
51111@@ -3446,8 +3446,8 @@ cleanup:
51112 if (retval) {
51113 if (tty->count == 1)
51114 info->port.tty = NULL; /* tty layer will release tty struct */
51115- if(info->port.count)
51116- info->port.count--;
51117+ if (atomic_read(&info->port.count))
51118+ atomic_dec(&info->port.count);
51119 }
51120
51121 return retval;
51122@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51123 unsigned short new_crctype;
51124
51125 /* return error if TTY interface open */
51126- if (info->port.count)
51127+ if (atomic_read(&info->port.count))
51128 return -EBUSY;
51129
51130 switch (encoding)
51131@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51132
51133 /* arbitrate between network and tty opens */
51134 spin_lock_irqsave(&info->netlock, flags);
51135- if (info->port.count != 0 || info->netcount != 0) {
51136+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51137 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51138 spin_unlock_irqrestore(&info->netlock, flags);
51139 return -EBUSY;
51140@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51141 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51142
51143 /* return error if TTY interface open */
51144- if (info->port.count)
51145+ if (atomic_read(&info->port.count))
51146 return -EBUSY;
51147
51148 if (cmd != SIOCWANDEV)
51149diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51150index c359a91..959fc26 100644
51151--- a/drivers/tty/synclink_gt.c
51152+++ b/drivers/tty/synclink_gt.c
51153@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51154 tty->driver_data = info;
51155 info->port.tty = tty;
51156
51157- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51158+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51159
51160 /* If port is closing, signal caller to try again */
51161 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51162@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51163 mutex_unlock(&info->port.mutex);
51164 goto cleanup;
51165 }
51166- info->port.count++;
51167+ atomic_inc(&info->port.count);
51168 spin_unlock_irqrestore(&info->netlock, flags);
51169
51170- if (info->port.count == 1) {
51171+ if (atomic_read(&info->port.count) == 1) {
51172 /* 1st open on this device, init hardware */
51173 retval = startup(info);
51174 if (retval < 0) {
51175@@ -715,8 +715,8 @@ cleanup:
51176 if (retval) {
51177 if (tty->count == 1)
51178 info->port.tty = NULL; /* tty layer will release tty struct */
51179- if(info->port.count)
51180- info->port.count--;
51181+ if(atomic_read(&info->port.count))
51182+ atomic_dec(&info->port.count);
51183 }
51184
51185 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51186@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51187
51188 if (sanity_check(info, tty->name, "close"))
51189 return;
51190- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51191+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51192
51193 if (tty_port_close_start(&info->port, tty, filp) == 0)
51194 goto cleanup;
51195@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51196 tty_port_close_end(&info->port, tty);
51197 info->port.tty = NULL;
51198 cleanup:
51199- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51200+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51201 }
51202
51203 static void hangup(struct tty_struct *tty)
51204@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51205 shutdown(info);
51206
51207 spin_lock_irqsave(&info->port.lock, flags);
51208- info->port.count = 0;
51209+ atomic_set(&info->port.count, 0);
51210 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51211 info->port.tty = NULL;
51212 spin_unlock_irqrestore(&info->port.lock, flags);
51213@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51214 unsigned short new_crctype;
51215
51216 /* return error if TTY interface open */
51217- if (info->port.count)
51218+ if (atomic_read(&info->port.count))
51219 return -EBUSY;
51220
51221 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51222@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51223
51224 /* arbitrate between network and tty opens */
51225 spin_lock_irqsave(&info->netlock, flags);
51226- if (info->port.count != 0 || info->netcount != 0) {
51227+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51228 DBGINFO(("%s hdlc_open busy\n", dev->name));
51229 spin_unlock_irqrestore(&info->netlock, flags);
51230 return -EBUSY;
51231@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51232 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51233
51234 /* return error if TTY interface open */
51235- if (info->port.count)
51236+ if (atomic_read(&info->port.count))
51237 return -EBUSY;
51238
51239 if (cmd != SIOCWANDEV)
51240@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51241 if (port == NULL)
51242 continue;
51243 spin_lock(&port->lock);
51244- if ((port->port.count || port->netcount) &&
51245+ if ((atomic_read(&port->port.count) || port->netcount) &&
51246 port->pending_bh && !port->bh_running &&
51247 !port->bh_requested) {
51248 DBGISR(("%s bh queued\n", port->device_name));
51249@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51250 spin_lock_irqsave(&info->lock, flags);
51251 if (!tty_hung_up_p(filp)) {
51252 extra_count = true;
51253- port->count--;
51254+ atomic_dec(&port->count);
51255 }
51256 spin_unlock_irqrestore(&info->lock, flags);
51257 port->blocked_open++;
51258@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51259 remove_wait_queue(&port->open_wait, &wait);
51260
51261 if (extra_count)
51262- port->count++;
51263+ atomic_inc(&port->count);
51264 port->blocked_open--;
51265
51266 if (!retval)
51267diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51268index 144202e..4ccb07d 100644
51269--- a/drivers/tty/synclinkmp.c
51270+++ b/drivers/tty/synclinkmp.c
51271@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51272
51273 if (debug_level >= DEBUG_LEVEL_INFO)
51274 printk("%s(%d):%s open(), old ref count = %d\n",
51275- __FILE__,__LINE__,tty->driver->name, info->port.count);
51276+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51277
51278 /* If port is closing, signal caller to try again */
51279 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51280@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51281 spin_unlock_irqrestore(&info->netlock, flags);
51282 goto cleanup;
51283 }
51284- info->port.count++;
51285+ atomic_inc(&info->port.count);
51286 spin_unlock_irqrestore(&info->netlock, flags);
51287
51288- if (info->port.count == 1) {
51289+ if (atomic_read(&info->port.count) == 1) {
51290 /* 1st open on this device, init hardware */
51291 retval = startup(info);
51292 if (retval < 0)
51293@@ -796,8 +796,8 @@ cleanup:
51294 if (retval) {
51295 if (tty->count == 1)
51296 info->port.tty = NULL; /* tty layer will release tty struct */
51297- if(info->port.count)
51298- info->port.count--;
51299+ if(atomic_read(&info->port.count))
51300+ atomic_dec(&info->port.count);
51301 }
51302
51303 return retval;
51304@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51305
51306 if (debug_level >= DEBUG_LEVEL_INFO)
51307 printk("%s(%d):%s close() entry, count=%d\n",
51308- __FILE__,__LINE__, info->device_name, info->port.count);
51309+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51310
51311 if (tty_port_close_start(&info->port, tty, filp) == 0)
51312 goto cleanup;
51313@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51314 cleanup:
51315 if (debug_level >= DEBUG_LEVEL_INFO)
51316 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51317- tty->driver->name, info->port.count);
51318+ tty->driver->name, atomic_read(&info->port.count));
51319 }
51320
51321 /* Called by tty_hangup() when a hangup is signaled.
51322@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51323 shutdown(info);
51324
51325 spin_lock_irqsave(&info->port.lock, flags);
51326- info->port.count = 0;
51327+ atomic_set(&info->port.count, 0);
51328 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51329 info->port.tty = NULL;
51330 spin_unlock_irqrestore(&info->port.lock, flags);
51331@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51332 unsigned short new_crctype;
51333
51334 /* return error if TTY interface open */
51335- if (info->port.count)
51336+ if (atomic_read(&info->port.count))
51337 return -EBUSY;
51338
51339 switch (encoding)
51340@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51341
51342 /* arbitrate between network and tty opens */
51343 spin_lock_irqsave(&info->netlock, flags);
51344- if (info->port.count != 0 || info->netcount != 0) {
51345+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51346 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51347 spin_unlock_irqrestore(&info->netlock, flags);
51348 return -EBUSY;
51349@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51350 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51351
51352 /* return error if TTY interface open */
51353- if (info->port.count)
51354+ if (atomic_read(&info->port.count))
51355 return -EBUSY;
51356
51357 if (cmd != SIOCWANDEV)
51358@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51359 * do not request bottom half processing if the
51360 * device is not open in a normal mode.
51361 */
51362- if ( port && (port->port.count || port->netcount) &&
51363+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51364 port->pending_bh && !port->bh_running &&
51365 !port->bh_requested ) {
51366 if ( debug_level >= DEBUG_LEVEL_ISR )
51367@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51368
51369 if (debug_level >= DEBUG_LEVEL_INFO)
51370 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51371- __FILE__,__LINE__, tty->driver->name, port->count );
51372+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51373
51374 spin_lock_irqsave(&info->lock, flags);
51375 if (!tty_hung_up_p(filp)) {
51376 extra_count = true;
51377- port->count--;
51378+ atomic_dec(&port->count);
51379 }
51380 spin_unlock_irqrestore(&info->lock, flags);
51381 port->blocked_open++;
51382@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51383
51384 if (debug_level >= DEBUG_LEVEL_INFO)
51385 printk("%s(%d):%s block_til_ready() count=%d\n",
51386- __FILE__,__LINE__, tty->driver->name, port->count );
51387+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51388
51389 tty_unlock(tty);
51390 schedule();
51391@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51392 remove_wait_queue(&port->open_wait, &wait);
51393
51394 if (extra_count)
51395- port->count++;
51396+ atomic_inc(&port->count);
51397 port->blocked_open--;
51398
51399 if (debug_level >= DEBUG_LEVEL_INFO)
51400 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51401- __FILE__,__LINE__, tty->driver->name, port->count );
51402+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51403
51404 if (!retval)
51405 port->flags |= ASYNC_NORMAL_ACTIVE;
51406diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51407index ce396ec..04a37be 100644
51408--- a/drivers/tty/sysrq.c
51409+++ b/drivers/tty/sysrq.c
51410@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51411 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51412 size_t count, loff_t *ppos)
51413 {
51414- if (count) {
51415+ if (count && capable(CAP_SYS_ADMIN)) {
51416 char c;
51417
51418 if (get_user(c, buf))
51419diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51420index d3448a9..28e8db0 100644
51421--- a/drivers/tty/tty_io.c
51422+++ b/drivers/tty/tty_io.c
51423@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51424
51425 void tty_default_fops(struct file_operations *fops)
51426 {
51427- *fops = tty_fops;
51428+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51429 }
51430
51431 /*
51432diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51433index 2d822aa..a566234 100644
51434--- a/drivers/tty/tty_ldisc.c
51435+++ b/drivers/tty/tty_ldisc.c
51436@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51437 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51438 tty_ldiscs[disc] = new_ldisc;
51439 new_ldisc->num = disc;
51440- new_ldisc->refcount = 0;
51441+ atomic_set(&new_ldisc->refcount, 0);
51442 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51443
51444 return ret;
51445@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51446 return -EINVAL;
51447
51448 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51449- if (tty_ldiscs[disc]->refcount)
51450+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51451 ret = -EBUSY;
51452 else
51453 tty_ldiscs[disc] = NULL;
51454@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51455 if (ldops) {
51456 ret = ERR_PTR(-EAGAIN);
51457 if (try_module_get(ldops->owner)) {
51458- ldops->refcount++;
51459+ atomic_inc(&ldops->refcount);
51460 ret = ldops;
51461 }
51462 }
51463@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51464 unsigned long flags;
51465
51466 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51467- ldops->refcount--;
51468+ atomic_dec(&ldops->refcount);
51469 module_put(ldops->owner);
51470 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51471 }
51472diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51473index 3f746c8..2f2fcaa 100644
51474--- a/drivers/tty/tty_port.c
51475+++ b/drivers/tty/tty_port.c
51476@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51477 unsigned long flags;
51478
51479 spin_lock_irqsave(&port->lock, flags);
51480- port->count = 0;
51481+ atomic_set(&port->count, 0);
51482 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51483 tty = port->tty;
51484 if (tty)
51485@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51486 /* The port lock protects the port counts */
51487 spin_lock_irqsave(&port->lock, flags);
51488 if (!tty_hung_up_p(filp))
51489- port->count--;
51490+ atomic_dec(&port->count);
51491 port->blocked_open++;
51492 spin_unlock_irqrestore(&port->lock, flags);
51493
51494@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51495 we must not mess that up further */
51496 spin_lock_irqsave(&port->lock, flags);
51497 if (!tty_hung_up_p(filp))
51498- port->count++;
51499+ atomic_inc(&port->count);
51500 port->blocked_open--;
51501 if (retval == 0)
51502 port->flags |= ASYNC_NORMAL_ACTIVE;
51503@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51504 return 0;
51505 }
51506
51507- if (tty->count == 1 && port->count != 1) {
51508+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51509 printk(KERN_WARNING
51510 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51511- port->count);
51512- port->count = 1;
51513+ atomic_read(&port->count));
51514+ atomic_set(&port->count, 1);
51515 }
51516- if (--port->count < 0) {
51517+ if (atomic_dec_return(&port->count) < 0) {
51518 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51519- port->count);
51520- port->count = 0;
51521+ atomic_read(&port->count));
51522+ atomic_set(&port->count, 0);
51523 }
51524
51525- if (port->count) {
51526+ if (atomic_read(&port->count)) {
51527 spin_unlock_irqrestore(&port->lock, flags);
51528 return 0;
51529 }
51530@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51531 {
51532 spin_lock_irq(&port->lock);
51533 if (!tty_hung_up_p(filp))
51534- ++port->count;
51535+ atomic_inc(&port->count);
51536 spin_unlock_irq(&port->lock);
51537 tty_port_tty_set(port, tty);
51538
51539diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51540index d0e3a44..5f8b754 100644
51541--- a/drivers/tty/vt/keyboard.c
51542+++ b/drivers/tty/vt/keyboard.c
51543@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51544 kbd->kbdmode == VC_OFF) &&
51545 value != KVAL(K_SAK))
51546 return; /* SAK is allowed even in raw mode */
51547+
51548+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51549+ {
51550+ void *func = fn_handler[value];
51551+ if (func == fn_show_state || func == fn_show_ptregs ||
51552+ func == fn_show_mem)
51553+ return;
51554+ }
51555+#endif
51556+
51557 fn_handler[value](vc);
51558 }
51559
51560@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51561 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51562 return -EFAULT;
51563
51564- if (!capable(CAP_SYS_TTY_CONFIG))
51565- perm = 0;
51566-
51567 switch (cmd) {
51568 case KDGKBENT:
51569 /* Ensure another thread doesn't free it under us */
51570@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51571 spin_unlock_irqrestore(&kbd_event_lock, flags);
51572 return put_user(val, &user_kbe->kb_value);
51573 case KDSKBENT:
51574+ if (!capable(CAP_SYS_TTY_CONFIG))
51575+ perm = 0;
51576+
51577 if (!perm)
51578 return -EPERM;
51579 if (!i && v == K_NOSUCHMAP) {
51580@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51581 int i, j, k;
51582 int ret;
51583
51584- if (!capable(CAP_SYS_TTY_CONFIG))
51585- perm = 0;
51586-
51587 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51588 if (!kbs) {
51589 ret = -ENOMEM;
51590@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51591 kfree(kbs);
51592 return ((p && *p) ? -EOVERFLOW : 0);
51593 case KDSKBSENT:
51594+ if (!capable(CAP_SYS_TTY_CONFIG))
51595+ perm = 0;
51596+
51597 if (!perm) {
51598 ret = -EPERM;
51599 goto reterr;
51600diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51601index a673e5b..36e5d32 100644
51602--- a/drivers/uio/uio.c
51603+++ b/drivers/uio/uio.c
51604@@ -25,6 +25,7 @@
51605 #include <linux/kobject.h>
51606 #include <linux/cdev.h>
51607 #include <linux/uio_driver.h>
51608+#include <asm/local.h>
51609
51610 #define UIO_MAX_DEVICES (1U << MINORBITS)
51611
51612@@ -32,7 +33,7 @@ struct uio_device {
51613 struct module *owner;
51614 struct device *dev;
51615 int minor;
51616- atomic_t event;
51617+ atomic_unchecked_t event;
51618 struct fasync_struct *async_queue;
51619 wait_queue_head_t wait;
51620 struct uio_info *info;
51621@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51622 struct device_attribute *attr, char *buf)
51623 {
51624 struct uio_device *idev = dev_get_drvdata(dev);
51625- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51626+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51627 }
51628 static DEVICE_ATTR_RO(event);
51629
51630@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51631 {
51632 struct uio_device *idev = info->uio_dev;
51633
51634- atomic_inc(&idev->event);
51635+ atomic_inc_unchecked(&idev->event);
51636 wake_up_interruptible(&idev->wait);
51637 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51638 }
51639@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51640 }
51641
51642 listener->dev = idev;
51643- listener->event_count = atomic_read(&idev->event);
51644+ listener->event_count = atomic_read_unchecked(&idev->event);
51645 filep->private_data = listener;
51646
51647 if (idev->info->open) {
51648@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51649 return -EIO;
51650
51651 poll_wait(filep, &idev->wait, wait);
51652- if (listener->event_count != atomic_read(&idev->event))
51653+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51654 return POLLIN | POLLRDNORM;
51655 return 0;
51656 }
51657@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51658 do {
51659 set_current_state(TASK_INTERRUPTIBLE);
51660
51661- event_count = atomic_read(&idev->event);
51662+ event_count = atomic_read_unchecked(&idev->event);
51663 if (event_count != listener->event_count) {
51664 if (copy_to_user(buf, &event_count, count))
51665 retval = -EFAULT;
51666@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51667 static int uio_find_mem_index(struct vm_area_struct *vma)
51668 {
51669 struct uio_device *idev = vma->vm_private_data;
51670+ unsigned long size;
51671
51672 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51673- if (idev->info->mem[vma->vm_pgoff].size == 0)
51674+ size = idev->info->mem[vma->vm_pgoff].size;
51675+ if (size == 0)
51676+ return -1;
51677+ if (vma->vm_end - vma->vm_start > size)
51678 return -1;
51679 return (int)vma->vm_pgoff;
51680 }
51681@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51682 idev->owner = owner;
51683 idev->info = info;
51684 init_waitqueue_head(&idev->wait);
51685- atomic_set(&idev->event, 0);
51686+ atomic_set_unchecked(&idev->event, 0);
51687
51688 ret = uio_get_minor(idev);
51689 if (ret)
51690diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51691index 813d4d3..a71934f 100644
51692--- a/drivers/usb/atm/cxacru.c
51693+++ b/drivers/usb/atm/cxacru.c
51694@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51695 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51696 if (ret < 2)
51697 return -EINVAL;
51698- if (index < 0 || index > 0x7f)
51699+ if (index > 0x7f)
51700 return -EINVAL;
51701 pos += tmp;
51702
51703diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51704index dada014..1d0d517 100644
51705--- a/drivers/usb/atm/usbatm.c
51706+++ b/drivers/usb/atm/usbatm.c
51707@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51708 if (printk_ratelimit())
51709 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51710 __func__, vpi, vci);
51711- atomic_inc(&vcc->stats->rx_err);
51712+ atomic_inc_unchecked(&vcc->stats->rx_err);
51713 return;
51714 }
51715
51716@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51717 if (length > ATM_MAX_AAL5_PDU) {
51718 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51719 __func__, length, vcc);
51720- atomic_inc(&vcc->stats->rx_err);
51721+ atomic_inc_unchecked(&vcc->stats->rx_err);
51722 goto out;
51723 }
51724
51725@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51726 if (sarb->len < pdu_length) {
51727 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51728 __func__, pdu_length, sarb->len, vcc);
51729- atomic_inc(&vcc->stats->rx_err);
51730+ atomic_inc_unchecked(&vcc->stats->rx_err);
51731 goto out;
51732 }
51733
51734 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51735 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51736 __func__, vcc);
51737- atomic_inc(&vcc->stats->rx_err);
51738+ atomic_inc_unchecked(&vcc->stats->rx_err);
51739 goto out;
51740 }
51741
51742@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51743 if (printk_ratelimit())
51744 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51745 __func__, length);
51746- atomic_inc(&vcc->stats->rx_drop);
51747+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51748 goto out;
51749 }
51750
51751@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51752
51753 vcc->push(vcc, skb);
51754
51755- atomic_inc(&vcc->stats->rx);
51756+ atomic_inc_unchecked(&vcc->stats->rx);
51757 out:
51758 skb_trim(sarb, 0);
51759 }
51760@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51761 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51762
51763 usbatm_pop(vcc, skb);
51764- atomic_inc(&vcc->stats->tx);
51765+ atomic_inc_unchecked(&vcc->stats->tx);
51766
51767 skb = skb_dequeue(&instance->sndqueue);
51768 }
51769@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51770 if (!left--)
51771 return sprintf(page,
51772 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51773- atomic_read(&atm_dev->stats.aal5.tx),
51774- atomic_read(&atm_dev->stats.aal5.tx_err),
51775- atomic_read(&atm_dev->stats.aal5.rx),
51776- atomic_read(&atm_dev->stats.aal5.rx_err),
51777- atomic_read(&atm_dev->stats.aal5.rx_drop));
51778+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51779+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51780+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51781+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51782+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51783
51784 if (!left--) {
51785 if (instance->disconnected)
51786diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51787index 2a3bbdf..91d72cf 100644
51788--- a/drivers/usb/core/devices.c
51789+++ b/drivers/usb/core/devices.c
51790@@ -126,7 +126,7 @@ static const char format_endpt[] =
51791 * time it gets called.
51792 */
51793 static struct device_connect_event {
51794- atomic_t count;
51795+ atomic_unchecked_t count;
51796 wait_queue_head_t wait;
51797 } device_event = {
51798 .count = ATOMIC_INIT(1),
51799@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51800
51801 void usbfs_conn_disc_event(void)
51802 {
51803- atomic_add(2, &device_event.count);
51804+ atomic_add_unchecked(2, &device_event.count);
51805 wake_up(&device_event.wait);
51806 }
51807
51808@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51809
51810 poll_wait(file, &device_event.wait, wait);
51811
51812- event_count = atomic_read(&device_event.count);
51813+ event_count = atomic_read_unchecked(&device_event.count);
51814 if (file->f_version != event_count) {
51815 file->f_version = event_count;
51816 return POLLIN | POLLRDNORM;
51817diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51818index 90e18f6..5eeda46 100644
51819--- a/drivers/usb/core/devio.c
51820+++ b/drivers/usb/core/devio.c
51821@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51822 struct dev_state *ps = file->private_data;
51823 struct usb_device *dev = ps->dev;
51824 ssize_t ret = 0;
51825- unsigned len;
51826+ size_t len;
51827 loff_t pos;
51828 int i;
51829
51830@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51831 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51832 struct usb_config_descriptor *config =
51833 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51834- unsigned int length = le16_to_cpu(config->wTotalLength);
51835+ size_t length = le16_to_cpu(config->wTotalLength);
51836
51837 if (*ppos < pos + length) {
51838
51839 /* The descriptor may claim to be longer than it
51840 * really is. Here is the actual allocated length. */
51841- unsigned alloclen =
51842+ size_t alloclen =
51843 le16_to_cpu(dev->config[i].desc.wTotalLength);
51844
51845- len = length - (*ppos - pos);
51846+ len = length + pos - *ppos;
51847 if (len > nbytes)
51848 len = nbytes;
51849
51850 /* Simply don't write (skip over) unallocated parts */
51851 if (alloclen > (*ppos - pos)) {
51852- alloclen -= (*ppos - pos);
51853+ alloclen = alloclen + pos - *ppos;
51854 if (copy_to_user(buf,
51855 dev->rawdescriptors[i] + (*ppos - pos),
51856 min(len, alloclen))) {
51857diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51858index 2518c32..1c201bb 100644
51859--- a/drivers/usb/core/hcd.c
51860+++ b/drivers/usb/core/hcd.c
51861@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51862 */
51863 usb_get_urb(urb);
51864 atomic_inc(&urb->use_count);
51865- atomic_inc(&urb->dev->urbnum);
51866+ atomic_inc_unchecked(&urb->dev->urbnum);
51867 usbmon_urb_submit(&hcd->self, urb);
51868
51869 /* NOTE requirements on root-hub callers (usbfs and the hub
51870@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51871 urb->hcpriv = NULL;
51872 INIT_LIST_HEAD(&urb->urb_list);
51873 atomic_dec(&urb->use_count);
51874- atomic_dec(&urb->dev->urbnum);
51875+ atomic_dec_unchecked(&urb->dev->urbnum);
51876 if (atomic_read(&urb->reject))
51877 wake_up(&usb_kill_urb_queue);
51878 usb_put_urb(urb);
51879diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51880index d498d03..e26f959 100644
51881--- a/drivers/usb/core/hub.c
51882+++ b/drivers/usb/core/hub.c
51883@@ -27,6 +27,7 @@
51884 #include <linux/freezer.h>
51885 #include <linux/random.h>
51886 #include <linux/pm_qos.h>
51887+#include <linux/grsecurity.h>
51888
51889 #include <asm/uaccess.h>
51890 #include <asm/byteorder.h>
51891@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51892 goto done;
51893 return;
51894 }
51895+
51896+ if (gr_handle_new_usb())
51897+ goto done;
51898+
51899 if (hub_is_superspeed(hub->hdev))
51900 unit_load = 150;
51901 else
51902diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51903index f829a1a..e6c334a 100644
51904--- a/drivers/usb/core/message.c
51905+++ b/drivers/usb/core/message.c
51906@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51907 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51908 * error number.
51909 */
51910-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51911+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51912 __u8 requesttype, __u16 value, __u16 index, void *data,
51913 __u16 size, int timeout)
51914 {
51915@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51916 * If successful, 0. Otherwise a negative error number. The number of actual
51917 * bytes transferred will be stored in the @actual_length paramater.
51918 */
51919-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51920+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51921 void *data, int len, int *actual_length, int timeout)
51922 {
51923 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51924@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51925 * bytes transferred will be stored in the @actual_length parameter.
51926 *
51927 */
51928-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51929+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51930 void *data, int len, int *actual_length, int timeout)
51931 {
51932 struct urb *urb;
51933diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51934index 1236c60..d47a51c 100644
51935--- a/drivers/usb/core/sysfs.c
51936+++ b/drivers/usb/core/sysfs.c
51937@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51938 struct usb_device *udev;
51939
51940 udev = to_usb_device(dev);
51941- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51942+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51943 }
51944 static DEVICE_ATTR_RO(urbnum);
51945
51946diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51947index 4d11449..f4ccabf 100644
51948--- a/drivers/usb/core/usb.c
51949+++ b/drivers/usb/core/usb.c
51950@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51951 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51952 dev->state = USB_STATE_ATTACHED;
51953 dev->lpm_disable_count = 1;
51954- atomic_set(&dev->urbnum, 0);
51955+ atomic_set_unchecked(&dev->urbnum, 0);
51956
51957 INIT_LIST_HEAD(&dev->ep0.urb_list);
51958 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51959diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51960index 2da0a5a..4870e09 100644
51961--- a/drivers/usb/dwc3/gadget.c
51962+++ b/drivers/usb/dwc3/gadget.c
51963@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51964 if (!usb_endpoint_xfer_isoc(desc))
51965 return 0;
51966
51967- memset(&trb_link, 0, sizeof(trb_link));
51968-
51969 /* Link TRB for ISOC. The HWO bit is never reset */
51970 trb_st_hw = &dep->trb_pool[0];
51971
51972diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51973index 8cfc319..4868255 100644
51974--- a/drivers/usb/early/ehci-dbgp.c
51975+++ b/drivers/usb/early/ehci-dbgp.c
51976@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51977
51978 #ifdef CONFIG_KGDB
51979 static struct kgdb_io kgdbdbgp_io_ops;
51980-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51981+static struct kgdb_io kgdbdbgp_io_ops_console;
51982+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51983 #else
51984 #define dbgp_kgdb_mode (0)
51985 #endif
51986@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51987 .write_char = kgdbdbgp_write_char,
51988 };
51989
51990+static struct kgdb_io kgdbdbgp_io_ops_console = {
51991+ .name = "kgdbdbgp",
51992+ .read_char = kgdbdbgp_read_char,
51993+ .write_char = kgdbdbgp_write_char,
51994+ .is_console = 1
51995+};
51996+
51997 static int kgdbdbgp_wait_time;
51998
51999 static int __init kgdbdbgp_parse_config(char *str)
52000@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52001 ptr++;
52002 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52003 }
52004- kgdb_register_io_module(&kgdbdbgp_io_ops);
52005- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52006+ if (early_dbgp_console.index != -1)
52007+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52008+ else
52009+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52010
52011 return 0;
52012 }
52013diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52014index 2b4c82d..06a8ee6 100644
52015--- a/drivers/usb/gadget/f_uac1.c
52016+++ b/drivers/usb/gadget/f_uac1.c
52017@@ -13,6 +13,7 @@
52018 #include <linux/kernel.h>
52019 #include <linux/device.h>
52020 #include <linux/atomic.h>
52021+#include <linux/module.h>
52022
52023 #include "u_uac1.h"
52024
52025diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52026index ad0aca8..8ff84865 100644
52027--- a/drivers/usb/gadget/u_serial.c
52028+++ b/drivers/usb/gadget/u_serial.c
52029@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52030 spin_lock_irq(&port->port_lock);
52031
52032 /* already open? Great. */
52033- if (port->port.count) {
52034+ if (atomic_read(&port->port.count)) {
52035 status = 0;
52036- port->port.count++;
52037+ atomic_inc(&port->port.count);
52038
52039 /* currently opening/closing? wait ... */
52040 } else if (port->openclose) {
52041@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52042 tty->driver_data = port;
52043 port->port.tty = tty;
52044
52045- port->port.count = 1;
52046+ atomic_set(&port->port.count, 1);
52047 port->openclose = false;
52048
52049 /* if connected, start the I/O stream */
52050@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52051
52052 spin_lock_irq(&port->port_lock);
52053
52054- if (port->port.count != 1) {
52055- if (port->port.count == 0)
52056+ if (atomic_read(&port->port.count) != 1) {
52057+ if (atomic_read(&port->port.count) == 0)
52058 WARN_ON(1);
52059 else
52060- --port->port.count;
52061+ atomic_dec(&port->port.count);
52062 goto exit;
52063 }
52064
52065@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52066 * and sleep if necessary
52067 */
52068 port->openclose = true;
52069- port->port.count = 0;
52070+ atomic_set(&port->port.count, 0);
52071
52072 gser = port->port_usb;
52073 if (gser && gser->disconnect)
52074@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52075 int cond;
52076
52077 spin_lock_irq(&port->port_lock);
52078- cond = (port->port.count == 0) && !port->openclose;
52079+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52080 spin_unlock_irq(&port->port_lock);
52081 return cond;
52082 }
52083@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52084 /* if it's already open, start I/O ... and notify the serial
52085 * protocol about open/close status (connect/disconnect).
52086 */
52087- if (port->port.count) {
52088+ if (atomic_read(&port->port.count)) {
52089 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52090 gs_start_io(port);
52091 if (gser->connect)
52092@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52093
52094 port->port_usb = NULL;
52095 gser->ioport = NULL;
52096- if (port->port.count > 0 || port->openclose) {
52097+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52098 wake_up_interruptible(&port->drain_wait);
52099 if (port->port.tty)
52100 tty_hangup(port->port.tty);
52101@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52102
52103 /* finally, free any unused/unusable I/O buffers */
52104 spin_lock_irqsave(&port->port_lock, flags);
52105- if (port->port.count == 0 && !port->openclose)
52106+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52107 gs_buf_free(&port->port_write_buf);
52108 gs_free_requests(gser->out, &port->read_pool, NULL);
52109 gs_free_requests(gser->out, &port->read_queue, NULL);
52110diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52111index 7a55fea..cc0ed4f 100644
52112--- a/drivers/usb/gadget/u_uac1.c
52113+++ b/drivers/usb/gadget/u_uac1.c
52114@@ -16,6 +16,7 @@
52115 #include <linux/ctype.h>
52116 #include <linux/random.h>
52117 #include <linux/syscalls.h>
52118+#include <linux/module.h>
52119
52120 #include "u_uac1.h"
52121
52122diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52123index 7ae0c4d..35521b7 100644
52124--- a/drivers/usb/host/ehci-hub.c
52125+++ b/drivers/usb/host/ehci-hub.c
52126@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52127 urb->transfer_flags = URB_DIR_IN;
52128 usb_get_urb(urb);
52129 atomic_inc(&urb->use_count);
52130- atomic_inc(&urb->dev->urbnum);
52131+ atomic_inc_unchecked(&urb->dev->urbnum);
52132 urb->setup_dma = dma_map_single(
52133 hcd->self.controller,
52134 urb->setup_packet,
52135@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52136 urb->status = -EINPROGRESS;
52137 usb_get_urb(urb);
52138 atomic_inc(&urb->use_count);
52139- atomic_inc(&urb->dev->urbnum);
52140+ atomic_inc_unchecked(&urb->dev->urbnum);
52141 retval = submit_single_step_set_feature(hcd, urb, 0);
52142 if (!retval && !wait_for_completion_timeout(&done,
52143 msecs_to_jiffies(2000))) {
52144diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52145index ba6a5d6..f88f7f3 100644
52146--- a/drivers/usb/misc/appledisplay.c
52147+++ b/drivers/usb/misc/appledisplay.c
52148@@ -83,7 +83,7 @@ struct appledisplay {
52149 spinlock_t lock;
52150 };
52151
52152-static atomic_t count_displays = ATOMIC_INIT(0);
52153+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52154 static struct workqueue_struct *wq;
52155
52156 static void appledisplay_complete(struct urb *urb)
52157@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52158
52159 /* Register backlight device */
52160 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52161- atomic_inc_return(&count_displays) - 1);
52162+ atomic_inc_return_unchecked(&count_displays) - 1);
52163 memset(&props, 0, sizeof(struct backlight_properties));
52164 props.type = BACKLIGHT_RAW;
52165 props.max_brightness = 0xff;
52166diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52167index 8d7fc48..01c4986 100644
52168--- a/drivers/usb/serial/console.c
52169+++ b/drivers/usb/serial/console.c
52170@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52171
52172 info->port = port;
52173
52174- ++port->port.count;
52175+ atomic_inc(&port->port.count);
52176 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52177 if (serial->type->set_termios) {
52178 /*
52179@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52180 }
52181 /* Now that any required fake tty operations are completed restore
52182 * the tty port count */
52183- --port->port.count;
52184+ atomic_dec(&port->port.count);
52185 /* The console is special in terms of closing the device so
52186 * indicate this port is now acting as a system console. */
52187 port->port.console = 1;
52188@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52189 free_tty:
52190 kfree(tty);
52191 reset_open_count:
52192- port->port.count = 0;
52193+ atomic_set(&port->port.count, 0);
52194 usb_autopm_put_interface(serial->interface);
52195 error_get_interface:
52196 usb_serial_put(serial);
52197@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52198 static void usb_console_write(struct console *co,
52199 const char *buf, unsigned count)
52200 {
52201- static struct usbcons_info *info = &usbcons_info;
52202+ struct usbcons_info *info = &usbcons_info;
52203 struct usb_serial_port *port = info->port;
52204 struct usb_serial *serial;
52205 int retval = -ENODEV;
52206diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52207index 75f70f0..d467e1a 100644
52208--- a/drivers/usb/storage/usb.h
52209+++ b/drivers/usb/storage/usb.h
52210@@ -63,7 +63,7 @@ struct us_unusual_dev {
52211 __u8 useProtocol;
52212 __u8 useTransport;
52213 int (*initFunction)(struct us_data *);
52214-};
52215+} __do_const;
52216
52217
52218 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52219diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52220index a2ef84b..aa7c2b8 100644
52221--- a/drivers/usb/wusbcore/wa-hc.h
52222+++ b/drivers/usb/wusbcore/wa-hc.h
52223@@ -225,7 +225,7 @@ struct wahc {
52224 spinlock_t xfer_list_lock;
52225 struct work_struct xfer_enqueue_work;
52226 struct work_struct xfer_error_work;
52227- atomic_t xfer_id_count;
52228+ atomic_unchecked_t xfer_id_count;
52229
52230 kernel_ulong_t quirks;
52231 };
52232@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52233 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52234 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52235 wa->dto_in_use = 0;
52236- atomic_set(&wa->xfer_id_count, 1);
52237+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52238 }
52239
52240 /**
52241diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52242index 3cd96e9..bd7c58d 100644
52243--- a/drivers/usb/wusbcore/wa-xfer.c
52244+++ b/drivers/usb/wusbcore/wa-xfer.c
52245@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52246 */
52247 static void wa_xfer_id_init(struct wa_xfer *xfer)
52248 {
52249- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52250+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52251 }
52252
52253 /* Return the xfer's ID. */
52254diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52255index 21271d8..45b55a0 100644
52256--- a/drivers/vfio/vfio.c
52257+++ b/drivers/vfio/vfio.c
52258@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52259 return 0;
52260
52261 /* TODO Prevent device auto probing */
52262- WARN("Device %s added to live group %d!\n", dev_name(dev),
52263+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52264 iommu_group_id(group->iommu_group));
52265
52266 return 0;
52267diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52268index 5174eba..451e6bc 100644
52269--- a/drivers/vhost/vringh.c
52270+++ b/drivers/vhost/vringh.c
52271@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52272 /* Userspace access helpers: in this case, addresses are really userspace. */
52273 static inline int getu16_user(u16 *val, const u16 *p)
52274 {
52275- return get_user(*val, (__force u16 __user *)p);
52276+ return get_user(*val, (u16 __force_user *)p);
52277 }
52278
52279 static inline int putu16_user(u16 *p, u16 val)
52280 {
52281- return put_user(val, (__force u16 __user *)p);
52282+ return put_user(val, (u16 __force_user *)p);
52283 }
52284
52285 static inline int copydesc_user(void *dst, const void *src, size_t len)
52286 {
52287- return copy_from_user(dst, (__force void __user *)src, len) ?
52288+ return copy_from_user(dst, (void __force_user *)src, len) ?
52289 -EFAULT : 0;
52290 }
52291
52292@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52293 const struct vring_used_elem *src,
52294 unsigned int num)
52295 {
52296- return copy_to_user((__force void __user *)dst, src,
52297+ return copy_to_user((void __force_user *)dst, src,
52298 sizeof(*dst) * num) ? -EFAULT : 0;
52299 }
52300
52301 static inline int xfer_from_user(void *src, void *dst, size_t len)
52302 {
52303- return copy_from_user(dst, (__force void __user *)src, len) ?
52304+ return copy_from_user(dst, (void __force_user *)src, len) ?
52305 -EFAULT : 0;
52306 }
52307
52308 static inline int xfer_to_user(void *dst, void *src, size_t len)
52309 {
52310- return copy_to_user((__force void __user *)dst, src, len) ?
52311+ return copy_to_user((void __force_user *)dst, src, len) ?
52312 -EFAULT : 0;
52313 }
52314
52315@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52316 vrh->last_used_idx = 0;
52317 vrh->vring.num = num;
52318 /* vring expects kernel addresses, but only used via accessors. */
52319- vrh->vring.desc = (__force struct vring_desc *)desc;
52320- vrh->vring.avail = (__force struct vring_avail *)avail;
52321- vrh->vring.used = (__force struct vring_used *)used;
52322+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52323+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52324+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52325 return 0;
52326 }
52327 EXPORT_SYMBOL(vringh_init_user);
52328@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52329
52330 static inline int putu16_kern(u16 *p, u16 val)
52331 {
52332- ACCESS_ONCE(*p) = val;
52333+ ACCESS_ONCE_RW(*p) = val;
52334 return 0;
52335 }
52336
52337diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52338index 1b0b233..6f34c2c 100644
52339--- a/drivers/video/arcfb.c
52340+++ b/drivers/video/arcfb.c
52341@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52342 return -ENOSPC;
52343
52344 err = 0;
52345- if ((count + p) > fbmemlength) {
52346+ if (count > (fbmemlength - p)) {
52347 count = fbmemlength - p;
52348 err = -ENOSPC;
52349 }
52350diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52351index 52108be..c7c110d 100644
52352--- a/drivers/video/aty/aty128fb.c
52353+++ b/drivers/video/aty/aty128fb.c
52354@@ -149,7 +149,7 @@ enum {
52355 };
52356
52357 /* Must match above enum */
52358-static char * const r128_family[] = {
52359+static const char * const r128_family[] = {
52360 "AGP",
52361 "PCI",
52362 "PRO AGP",
52363diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52364index 28fafbf..ae91651 100644
52365--- a/drivers/video/aty/atyfb_base.c
52366+++ b/drivers/video/aty/atyfb_base.c
52367@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52368 par->accel_flags = var->accel_flags; /* hack */
52369
52370 if (var->accel_flags) {
52371- info->fbops->fb_sync = atyfb_sync;
52372+ pax_open_kernel();
52373+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52374+ pax_close_kernel();
52375 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52376 } else {
52377- info->fbops->fb_sync = NULL;
52378+ pax_open_kernel();
52379+ *(void **)&info->fbops->fb_sync = NULL;
52380+ pax_close_kernel();
52381 info->flags |= FBINFO_HWACCEL_DISABLED;
52382 }
52383
52384diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52385index 95ec042..e6affdd 100644
52386--- a/drivers/video/aty/mach64_cursor.c
52387+++ b/drivers/video/aty/mach64_cursor.c
52388@@ -7,6 +7,7 @@
52389 #include <linux/string.h>
52390
52391 #include <asm/io.h>
52392+#include <asm/pgtable.h>
52393
52394 #ifdef __sparc__
52395 #include <asm/fbio.h>
52396@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52397 info->sprite.buf_align = 16; /* and 64 lines tall. */
52398 info->sprite.flags = FB_PIXMAP_IO;
52399
52400- info->fbops->fb_cursor = atyfb_cursor;
52401+ pax_open_kernel();
52402+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52403+ pax_close_kernel();
52404
52405 return 0;
52406 }
52407diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52408index 84a110a..96312c3 100644
52409--- a/drivers/video/backlight/kb3886_bl.c
52410+++ b/drivers/video/backlight/kb3886_bl.c
52411@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52412 static unsigned long kb3886bl_flags;
52413 #define KB3886BL_SUSPENDED 0x01
52414
52415-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52416+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52417 {
52418 .ident = "Sahara Touch-iT",
52419 .matches = {
52420diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52421index 900aa4e..6d49418 100644
52422--- a/drivers/video/fb_defio.c
52423+++ b/drivers/video/fb_defio.c
52424@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52425
52426 BUG_ON(!fbdefio);
52427 mutex_init(&fbdefio->lock);
52428- info->fbops->fb_mmap = fb_deferred_io_mmap;
52429+ pax_open_kernel();
52430+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52431+ pax_close_kernel();
52432 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52433 INIT_LIST_HEAD(&fbdefio->pagelist);
52434 if (fbdefio->delay == 0) /* set a default of 1 s */
52435@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52436 page->mapping = NULL;
52437 }
52438
52439- info->fbops->fb_mmap = NULL;
52440+ *(void **)&info->fbops->fb_mmap = NULL;
52441 mutex_destroy(&fbdefio->lock);
52442 }
52443 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52444diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52445index 7309ac7..be3c49c 100644
52446--- a/drivers/video/fbmem.c
52447+++ b/drivers/video/fbmem.c
52448@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52449 image->dx += image->width + 8;
52450 }
52451 } else if (rotate == FB_ROTATE_UD) {
52452- for (x = 0; x < num && image->dx >= 0; x++) {
52453+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52454 info->fbops->fb_imageblit(info, image);
52455 image->dx -= image->width + 8;
52456 }
52457@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52458 image->dy += image->height + 8;
52459 }
52460 } else if (rotate == FB_ROTATE_CCW) {
52461- for (x = 0; x < num && image->dy >= 0; x++) {
52462+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52463 info->fbops->fb_imageblit(info, image);
52464 image->dy -= image->height + 8;
52465 }
52466@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52467 return -EFAULT;
52468 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52469 return -EINVAL;
52470- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52471+ if (con2fb.framebuffer >= FB_MAX)
52472 return -EINVAL;
52473 if (!registered_fb[con2fb.framebuffer])
52474 request_module("fb%d", con2fb.framebuffer);
52475@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52476 __u32 data;
52477 int err;
52478
52479- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52480+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52481
52482 data = (__u32) (unsigned long) fix->smem_start;
52483 err |= put_user(data, &fix32->smem_start);
52484diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52485index 130708f..cdac1a9 100644
52486--- a/drivers/video/hyperv_fb.c
52487+++ b/drivers/video/hyperv_fb.c
52488@@ -233,7 +233,7 @@ static uint screen_fb_size;
52489 static inline int synthvid_send(struct hv_device *hdev,
52490 struct synthvid_msg *msg)
52491 {
52492- static atomic64_t request_id = ATOMIC64_INIT(0);
52493+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52494 int ret;
52495
52496 msg->pipe_hdr.type = PIPE_MSG_DATA;
52497@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52498
52499 ret = vmbus_sendpacket(hdev->channel, msg,
52500 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52501- atomic64_inc_return(&request_id),
52502+ atomic64_inc_return_unchecked(&request_id),
52503 VM_PKT_DATA_INBAND, 0);
52504
52505 if (ret)
52506diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52507index 7672d2e..b56437f 100644
52508--- a/drivers/video/i810/i810_accel.c
52509+++ b/drivers/video/i810/i810_accel.c
52510@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52511 }
52512 }
52513 printk("ringbuffer lockup!!!\n");
52514+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52515 i810_report_error(mmio);
52516 par->dev_flags |= LOCKUP;
52517 info->pixmap.scan_align = 1;
52518diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52519index 3c14e43..2630570 100644
52520--- a/drivers/video/logo/logo_linux_clut224.ppm
52521+++ b/drivers/video/logo/logo_linux_clut224.ppm
52522@@ -2,1603 +2,1123 @@ P3
52523 # Standard 224-color Linux logo
52524 80 80
52525 255
52526- 0 0 0 0 0 0 0 0 0 0 0 0
52527- 0 0 0 0 0 0 0 0 0 0 0 0
52528- 0 0 0 0 0 0 0 0 0 0 0 0
52529- 0 0 0 0 0 0 0 0 0 0 0 0
52530- 0 0 0 0 0 0 0 0 0 0 0 0
52531- 0 0 0 0 0 0 0 0 0 0 0 0
52532- 0 0 0 0 0 0 0 0 0 0 0 0
52533- 0 0 0 0 0 0 0 0 0 0 0 0
52534- 0 0 0 0 0 0 0 0 0 0 0 0
52535- 6 6 6 6 6 6 10 10 10 10 10 10
52536- 10 10 10 6 6 6 6 6 6 6 6 6
52537- 0 0 0 0 0 0 0 0 0 0 0 0
52538- 0 0 0 0 0 0 0 0 0 0 0 0
52539- 0 0 0 0 0 0 0 0 0 0 0 0
52540- 0 0 0 0 0 0 0 0 0 0 0 0
52541- 0 0 0 0 0 0 0 0 0 0 0 0
52542- 0 0 0 0 0 0 0 0 0 0 0 0
52543- 0 0 0 0 0 0 0 0 0 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 0 0 0 0 0 0 0 0 0
52546- 0 0 0 0 0 0 0 0 0 0 0 0
52547- 0 0 0 0 0 0 0 0 0 0 0 0
52548- 0 0 0 0 0 0 0 0 0 0 0 0
52549- 0 0 0 0 0 0 0 0 0 0 0 0
52550- 0 0 0 0 0 0 0 0 0 0 0 0
52551- 0 0 0 0 0 0 0 0 0 0 0 0
52552- 0 0 0 0 0 0 0 0 0 0 0 0
52553- 0 0 0 0 0 0 0 0 0 0 0 0
52554- 0 0 0 6 6 6 10 10 10 14 14 14
52555- 22 22 22 26 26 26 30 30 30 34 34 34
52556- 30 30 30 30 30 30 26 26 26 18 18 18
52557- 14 14 14 10 10 10 6 6 6 0 0 0
52558- 0 0 0 0 0 0 0 0 0 0 0 0
52559- 0 0 0 0 0 0 0 0 0 0 0 0
52560- 0 0 0 0 0 0 0 0 0 0 0 0
52561- 0 0 0 0 0 0 0 0 0 0 0 0
52562- 0 0 0 0 0 0 0 0 0 0 0 0
52563- 0 0 0 0 0 0 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 0 0 0 0 0 0 0 0 0 0 0 0
52566- 0 0 0 0 0 0 0 0 0 0 0 0
52567- 0 0 0 0 0 1 0 0 1 0 0 0
52568- 0 0 0 0 0 0 0 0 0 0 0 0
52569- 0 0 0 0 0 0 0 0 0 0 0 0
52570- 0 0 0 0 0 0 0 0 0 0 0 0
52571- 0 0 0 0 0 0 0 0 0 0 0 0
52572- 0 0 0 0 0 0 0 0 0 0 0 0
52573- 0 0 0 0 0 0 0 0 0 0 0 0
52574- 6 6 6 14 14 14 26 26 26 42 42 42
52575- 54 54 54 66 66 66 78 78 78 78 78 78
52576- 78 78 78 74 74 74 66 66 66 54 54 54
52577- 42 42 42 26 26 26 18 18 18 10 10 10
52578- 6 6 6 0 0 0 0 0 0 0 0 0
52579- 0 0 0 0 0 0 0 0 0 0 0 0
52580- 0 0 0 0 0 0 0 0 0 0 0 0
52581- 0 0 0 0 0 0 0 0 0 0 0 0
52582- 0 0 0 0 0 0 0 0 0 0 0 0
52583- 0 0 0 0 0 0 0 0 0 0 0 0
52584- 0 0 0 0 0 0 0 0 0 0 0 0
52585- 0 0 0 0 0 0 0 0 0 0 0 0
52586- 0 0 0 0 0 0 0 0 0 0 0 0
52587- 0 0 1 0 0 0 0 0 0 0 0 0
52588- 0 0 0 0 0 0 0 0 0 0 0 0
52589- 0 0 0 0 0 0 0 0 0 0 0 0
52590- 0 0 0 0 0 0 0 0 0 0 0 0
52591- 0 0 0 0 0 0 0 0 0 0 0 0
52592- 0 0 0 0 0 0 0 0 0 0 0 0
52593- 0 0 0 0 0 0 0 0 0 10 10 10
52594- 22 22 22 42 42 42 66 66 66 86 86 86
52595- 66 66 66 38 38 38 38 38 38 22 22 22
52596- 26 26 26 34 34 34 54 54 54 66 66 66
52597- 86 86 86 70 70 70 46 46 46 26 26 26
52598- 14 14 14 6 6 6 0 0 0 0 0 0
52599- 0 0 0 0 0 0 0 0 0 0 0 0
52600- 0 0 0 0 0 0 0 0 0 0 0 0
52601- 0 0 0 0 0 0 0 0 0 0 0 0
52602- 0 0 0 0 0 0 0 0 0 0 0 0
52603- 0 0 0 0 0 0 0 0 0 0 0 0
52604- 0 0 0 0 0 0 0 0 0 0 0 0
52605- 0 0 0 0 0 0 0 0 0 0 0 0
52606- 0 0 0 0 0 0 0 0 0 0 0 0
52607- 0 0 1 0 0 1 0 0 1 0 0 0
52608- 0 0 0 0 0 0 0 0 0 0 0 0
52609- 0 0 0 0 0 0 0 0 0 0 0 0
52610- 0 0 0 0 0 0 0 0 0 0 0 0
52611- 0 0 0 0 0 0 0 0 0 0 0 0
52612- 0 0 0 0 0 0 0 0 0 0 0 0
52613- 0 0 0 0 0 0 10 10 10 26 26 26
52614- 50 50 50 82 82 82 58 58 58 6 6 6
52615- 2 2 6 2 2 6 2 2 6 2 2 6
52616- 2 2 6 2 2 6 2 2 6 2 2 6
52617- 6 6 6 54 54 54 86 86 86 66 66 66
52618- 38 38 38 18 18 18 6 6 6 0 0 0
52619- 0 0 0 0 0 0 0 0 0 0 0 0
52620- 0 0 0 0 0 0 0 0 0 0 0 0
52621- 0 0 0 0 0 0 0 0 0 0 0 0
52622- 0 0 0 0 0 0 0 0 0 0 0 0
52623- 0 0 0 0 0 0 0 0 0 0 0 0
52624- 0 0 0 0 0 0 0 0 0 0 0 0
52625- 0 0 0 0 0 0 0 0 0 0 0 0
52626- 0 0 0 0 0 0 0 0 0 0 0 0
52627- 0 0 0 0 0 0 0 0 0 0 0 0
52628- 0 0 0 0 0 0 0 0 0 0 0 0
52629- 0 0 0 0 0 0 0 0 0 0 0 0
52630- 0 0 0 0 0 0 0 0 0 0 0 0
52631- 0 0 0 0 0 0 0 0 0 0 0 0
52632- 0 0 0 0 0 0 0 0 0 0 0 0
52633- 0 0 0 6 6 6 22 22 22 50 50 50
52634- 78 78 78 34 34 34 2 2 6 2 2 6
52635- 2 2 6 2 2 6 2 2 6 2 2 6
52636- 2 2 6 2 2 6 2 2 6 2 2 6
52637- 2 2 6 2 2 6 6 6 6 70 70 70
52638- 78 78 78 46 46 46 22 22 22 6 6 6
52639- 0 0 0 0 0 0 0 0 0 0 0 0
52640- 0 0 0 0 0 0 0 0 0 0 0 0
52641- 0 0 0 0 0 0 0 0 0 0 0 0
52642- 0 0 0 0 0 0 0 0 0 0 0 0
52643- 0 0 0 0 0 0 0 0 0 0 0 0
52644- 0 0 0 0 0 0 0 0 0 0 0 0
52645- 0 0 0 0 0 0 0 0 0 0 0 0
52646- 0 0 0 0 0 0 0 0 0 0 0 0
52647- 0 0 1 0 0 1 0 0 1 0 0 0
52648- 0 0 0 0 0 0 0 0 0 0 0 0
52649- 0 0 0 0 0 0 0 0 0 0 0 0
52650- 0 0 0 0 0 0 0 0 0 0 0 0
52651- 0 0 0 0 0 0 0 0 0 0 0 0
52652- 0 0 0 0 0 0 0 0 0 0 0 0
52653- 6 6 6 18 18 18 42 42 42 82 82 82
52654- 26 26 26 2 2 6 2 2 6 2 2 6
52655- 2 2 6 2 2 6 2 2 6 2 2 6
52656- 2 2 6 2 2 6 2 2 6 14 14 14
52657- 46 46 46 34 34 34 6 6 6 2 2 6
52658- 42 42 42 78 78 78 42 42 42 18 18 18
52659- 6 6 6 0 0 0 0 0 0 0 0 0
52660- 0 0 0 0 0 0 0 0 0 0 0 0
52661- 0 0 0 0 0 0 0 0 0 0 0 0
52662- 0 0 0 0 0 0 0 0 0 0 0 0
52663- 0 0 0 0 0 0 0 0 0 0 0 0
52664- 0 0 0 0 0 0 0 0 0 0 0 0
52665- 0 0 0 0 0 0 0 0 0 0 0 0
52666- 0 0 0 0 0 0 0 0 0 0 0 0
52667- 0 0 1 0 0 0 0 0 1 0 0 0
52668- 0 0 0 0 0 0 0 0 0 0 0 0
52669- 0 0 0 0 0 0 0 0 0 0 0 0
52670- 0 0 0 0 0 0 0 0 0 0 0 0
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- 10 10 10 30 30 30 66 66 66 58 58 58
52674- 2 2 6 2 2 6 2 2 6 2 2 6
52675- 2 2 6 2 2 6 2 2 6 2 2 6
52676- 2 2 6 2 2 6 2 2 6 26 26 26
52677- 86 86 86 101 101 101 46 46 46 10 10 10
52678- 2 2 6 58 58 58 70 70 70 34 34 34
52679- 10 10 10 0 0 0 0 0 0 0 0 0
52680- 0 0 0 0 0 0 0 0 0 0 0 0
52681- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
52694- 2 2 6 2 2 6 2 2 6 2 2 6
52695- 2 2 6 2 2 6 2 2 6 2 2 6
52696- 2 2 6 2 2 6 2 2 6 30 30 30
52697- 94 94 94 94 94 94 58 58 58 26 26 26
52698- 2 2 6 6 6 6 78 78 78 54 54 54
52699- 22 22 22 6 6 6 0 0 0 0 0 0
52700- 0 0 0 0 0 0 0 0 0 0 0 0
52701- 0 0 0 0 0 0 0 0 0 0 0 0
52702- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 6 6 6
52713- 22 22 22 62 62 62 62 62 62 2 2 6
52714- 2 2 6 2 2 6 2 2 6 2 2 6
52715- 2 2 6 2 2 6 2 2 6 2 2 6
52716- 2 2 6 2 2 6 2 2 6 26 26 26
52717- 54 54 54 38 38 38 18 18 18 10 10 10
52718- 2 2 6 2 2 6 34 34 34 82 82 82
52719- 38 38 38 14 14 14 0 0 0 0 0 0
52720- 0 0 0 0 0 0 0 0 0 0 0 0
52721- 0 0 0 0 0 0 0 0 0 0 0 0
52722- 0 0 0 0 0 0 0 0 0 0 0 0
52723- 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0 0 6 6 6
52733- 30 30 30 78 78 78 30 30 30 2 2 6
52734- 2 2 6 2 2 6 2 2 6 2 2 6
52735- 2 2 6 2 2 6 2 2 6 2 2 6
52736- 2 2 6 2 2 6 2 2 6 10 10 10
52737- 10 10 10 2 2 6 2 2 6 2 2 6
52738- 2 2 6 2 2 6 2 2 6 78 78 78
52739- 50 50 50 18 18 18 6 6 6 0 0 0
52740- 0 0 0 0 0 0 0 0 0 0 0 0
52741- 0 0 0 0 0 0 0 0 0 0 0 0
52742- 0 0 0 0 0 0 0 0 0 0 0 0
52743- 0 0 0 0 0 0 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 1 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 0 0 0 0 0 0 0 10 10 10
52753- 38 38 38 86 86 86 14 14 14 2 2 6
52754- 2 2 6 2 2 6 2 2 6 2 2 6
52755- 2 2 6 2 2 6 2 2 6 2 2 6
52756- 2 2 6 2 2 6 2 2 6 2 2 6
52757- 2 2 6 2 2 6 2 2 6 2 2 6
52758- 2 2 6 2 2 6 2 2 6 54 54 54
52759- 66 66 66 26 26 26 6 6 6 0 0 0
52760- 0 0 0 0 0 0 0 0 0 0 0 0
52761- 0 0 0 0 0 0 0 0 0 0 0 0
52762- 0 0 0 0 0 0 0 0 0 0 0 0
52763- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 14 14 14
52773- 42 42 42 82 82 82 2 2 6 2 2 6
52774- 2 2 6 6 6 6 10 10 10 2 2 6
52775- 2 2 6 2 2 6 2 2 6 2 2 6
52776- 2 2 6 2 2 6 2 2 6 6 6 6
52777- 14 14 14 10 10 10 2 2 6 2 2 6
52778- 2 2 6 2 2 6 2 2 6 18 18 18
52779- 82 82 82 34 34 34 10 10 10 0 0 0
52780- 0 0 0 0 0 0 0 0 0 0 0 0
52781- 0 0 0 0 0 0 0 0 0 0 0 0
52782- 0 0 0 0 0 0 0 0 0 0 0 0
52783- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 0 0 0 0 0 0 0 14 14 14
52793- 46 46 46 86 86 86 2 2 6 2 2 6
52794- 6 6 6 6 6 6 22 22 22 34 34 34
52795- 6 6 6 2 2 6 2 2 6 2 2 6
52796- 2 2 6 2 2 6 18 18 18 34 34 34
52797- 10 10 10 50 50 50 22 22 22 2 2 6
52798- 2 2 6 2 2 6 2 2 6 10 10 10
52799- 86 86 86 42 42 42 14 14 14 0 0 0
52800- 0 0 0 0 0 0 0 0 0 0 0 0
52801- 0 0 0 0 0 0 0 0 0 0 0 0
52802- 0 0 0 0 0 0 0 0 0 0 0 0
52803- 0 0 0 0 0 0 0 0 0 0 0 0
52804- 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 14 14 14
52813- 46 46 46 86 86 86 2 2 6 2 2 6
52814- 38 38 38 116 116 116 94 94 94 22 22 22
52815- 22 22 22 2 2 6 2 2 6 2 2 6
52816- 14 14 14 86 86 86 138 138 138 162 162 162
52817-154 154 154 38 38 38 26 26 26 6 6 6
52818- 2 2 6 2 2 6 2 2 6 2 2 6
52819- 86 86 86 46 46 46 14 14 14 0 0 0
52820- 0 0 0 0 0 0 0 0 0 0 0 0
52821- 0 0 0 0 0 0 0 0 0 0 0 0
52822- 0 0 0 0 0 0 0 0 0 0 0 0
52823- 0 0 0 0 0 0 0 0 0 0 0 0
52824- 0 0 0 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 0 0 0 0 0 0 0 14 14 14
52833- 46 46 46 86 86 86 2 2 6 14 14 14
52834-134 134 134 198 198 198 195 195 195 116 116 116
52835- 10 10 10 2 2 6 2 2 6 6 6 6
52836-101 98 89 187 187 187 210 210 210 218 218 218
52837-214 214 214 134 134 134 14 14 14 6 6 6
52838- 2 2 6 2 2 6 2 2 6 2 2 6
52839- 86 86 86 50 50 50 18 18 18 6 6 6
52840- 0 0 0 0 0 0 0 0 0 0 0 0
52841- 0 0 0 0 0 0 0 0 0 0 0 0
52842- 0 0 0 0 0 0 0 0 0 0 0 0
52843- 0 0 0 0 0 0 0 0 0 0 0 0
52844- 0 0 0 0 0 0 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 1 0 0 0
52847- 0 0 1 0 0 1 0 0 1 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 14 14 14
52853- 46 46 46 86 86 86 2 2 6 54 54 54
52854-218 218 218 195 195 195 226 226 226 246 246 246
52855- 58 58 58 2 2 6 2 2 6 30 30 30
52856-210 210 210 253 253 253 174 174 174 123 123 123
52857-221 221 221 234 234 234 74 74 74 2 2 6
52858- 2 2 6 2 2 6 2 2 6 2 2 6
52859- 70 70 70 58 58 58 22 22 22 6 6 6
52860- 0 0 0 0 0 0 0 0 0 0 0 0
52861- 0 0 0 0 0 0 0 0 0 0 0 0
52862- 0 0 0 0 0 0 0 0 0 0 0 0
52863- 0 0 0 0 0 0 0 0 0 0 0 0
52864- 0 0 0 0 0 0 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 0 0 0 0 14 14 14
52873- 46 46 46 82 82 82 2 2 6 106 106 106
52874-170 170 170 26 26 26 86 86 86 226 226 226
52875-123 123 123 10 10 10 14 14 14 46 46 46
52876-231 231 231 190 190 190 6 6 6 70 70 70
52877- 90 90 90 238 238 238 158 158 158 2 2 6
52878- 2 2 6 2 2 6 2 2 6 2 2 6
52879- 70 70 70 58 58 58 22 22 22 6 6 6
52880- 0 0 0 0 0 0 0 0 0 0 0 0
52881- 0 0 0 0 0 0 0 0 0 0 0 0
52882- 0 0 0 0 0 0 0 0 0 0 0 0
52883- 0 0 0 0 0 0 0 0 0 0 0 0
52884- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
52887- 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 14 14 14
52893- 42 42 42 86 86 86 6 6 6 116 116 116
52894-106 106 106 6 6 6 70 70 70 149 149 149
52895-128 128 128 18 18 18 38 38 38 54 54 54
52896-221 221 221 106 106 106 2 2 6 14 14 14
52897- 46 46 46 190 190 190 198 198 198 2 2 6
52898- 2 2 6 2 2 6 2 2 6 2 2 6
52899- 74 74 74 62 62 62 22 22 22 6 6 6
52900- 0 0 0 0 0 0 0 0 0 0 0 0
52901- 0 0 0 0 0 0 0 0 0 0 0 0
52902- 0 0 0 0 0 0 0 0 0 0 0 0
52903- 0 0 0 0 0 0 0 0 0 0 0 0
52904- 0 0 0 0 0 0 0 0 0 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 1 0 0 0
52907- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 14 14 14
52913- 42 42 42 94 94 94 14 14 14 101 101 101
52914-128 128 128 2 2 6 18 18 18 116 116 116
52915-118 98 46 121 92 8 121 92 8 98 78 10
52916-162 162 162 106 106 106 2 2 6 2 2 6
52917- 2 2 6 195 195 195 195 195 195 6 6 6
52918- 2 2 6 2 2 6 2 2 6 2 2 6
52919- 74 74 74 62 62 62 22 22 22 6 6 6
52920- 0 0 0 0 0 0 0 0 0 0 0 0
52921- 0 0 0 0 0 0 0 0 0 0 0 0
52922- 0 0 0 0 0 0 0 0 0 0 0 0
52923- 0 0 0 0 0 0 0 0 0 0 0 0
52924- 0 0 0 0 0 0 0 0 0 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 1 0 0 1
52927- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 10 10 10
52933- 38 38 38 90 90 90 14 14 14 58 58 58
52934-210 210 210 26 26 26 54 38 6 154 114 10
52935-226 170 11 236 186 11 225 175 15 184 144 12
52936-215 174 15 175 146 61 37 26 9 2 2 6
52937- 70 70 70 246 246 246 138 138 138 2 2 6
52938- 2 2 6 2 2 6 2 2 6 2 2 6
52939- 70 70 70 66 66 66 26 26 26 6 6 6
52940- 0 0 0 0 0 0 0 0 0 0 0 0
52941- 0 0 0 0 0 0 0 0 0 0 0 0
52942- 0 0 0 0 0 0 0 0 0 0 0 0
52943- 0 0 0 0 0 0 0 0 0 0 0 0
52944- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 10 10 10
52953- 38 38 38 86 86 86 14 14 14 10 10 10
52954-195 195 195 188 164 115 192 133 9 225 175 15
52955-239 182 13 234 190 10 232 195 16 232 200 30
52956-245 207 45 241 208 19 232 195 16 184 144 12
52957-218 194 134 211 206 186 42 42 42 2 2 6
52958- 2 2 6 2 2 6 2 2 6 2 2 6
52959- 50 50 50 74 74 74 30 30 30 6 6 6
52960- 0 0 0 0 0 0 0 0 0 0 0 0
52961- 0 0 0 0 0 0 0 0 0 0 0 0
52962- 0 0 0 0 0 0 0 0 0 0 0 0
52963- 0 0 0 0 0 0 0 0 0 0 0 0
52964- 0 0 0 0 0 0 0 0 0 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 10 10 10
52973- 34 34 34 86 86 86 14 14 14 2 2 6
52974-121 87 25 192 133 9 219 162 10 239 182 13
52975-236 186 11 232 195 16 241 208 19 244 214 54
52976-246 218 60 246 218 38 246 215 20 241 208 19
52977-241 208 19 226 184 13 121 87 25 2 2 6
52978- 2 2 6 2 2 6 2 2 6 2 2 6
52979- 50 50 50 82 82 82 34 34 34 10 10 10
52980- 0 0 0 0 0 0 0 0 0 0 0 0
52981- 0 0 0 0 0 0 0 0 0 0 0 0
52982- 0 0 0 0 0 0 0 0 0 0 0 0
52983- 0 0 0 0 0 0 0 0 0 0 0 0
52984- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
52992- 0 0 0 0 0 0 0 0 0 10 10 10
52993- 34 34 34 82 82 82 30 30 30 61 42 6
52994-180 123 7 206 145 10 230 174 11 239 182 13
52995-234 190 10 238 202 15 241 208 19 246 218 74
52996-246 218 38 246 215 20 246 215 20 246 215 20
52997-226 184 13 215 174 15 184 144 12 6 6 6
52998- 2 2 6 2 2 6 2 2 6 2 2 6
52999- 26 26 26 94 94 94 42 42 42 14 14 14
53000- 0 0 0 0 0 0 0 0 0 0 0 0
53001- 0 0 0 0 0 0 0 0 0 0 0 0
53002- 0 0 0 0 0 0 0 0 0 0 0 0
53003- 0 0 0 0 0 0 0 0 0 0 0 0
53004- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
53013- 30 30 30 78 78 78 50 50 50 104 69 6
53014-192 133 9 216 158 10 236 178 12 236 186 11
53015-232 195 16 241 208 19 244 214 54 245 215 43
53016-246 215 20 246 215 20 241 208 19 198 155 10
53017-200 144 11 216 158 10 156 118 10 2 2 6
53018- 2 2 6 2 2 6 2 2 6 2 2 6
53019- 6 6 6 90 90 90 54 54 54 18 18 18
53020- 6 6 6 0 0 0 0 0 0 0 0 0
53021- 0 0 0 0 0 0 0 0 0 0 0 0
53022- 0 0 0 0 0 0 0 0 0 0 0 0
53023- 0 0 0 0 0 0 0 0 0 0 0 0
53024- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53032- 0 0 0 0 0 0 0 0 0 10 10 10
53033- 30 30 30 78 78 78 46 46 46 22 22 22
53034-137 92 6 210 162 10 239 182 13 238 190 10
53035-238 202 15 241 208 19 246 215 20 246 215 20
53036-241 208 19 203 166 17 185 133 11 210 150 10
53037-216 158 10 210 150 10 102 78 10 2 2 6
53038- 6 6 6 54 54 54 14 14 14 2 2 6
53039- 2 2 6 62 62 62 74 74 74 30 30 30
53040- 10 10 10 0 0 0 0 0 0 0 0 0
53041- 0 0 0 0 0 0 0 0 0 0 0 0
53042- 0 0 0 0 0 0 0 0 0 0 0 0
53043- 0 0 0 0 0 0 0 0 0 0 0 0
53044- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53052- 0 0 0 0 0 0 0 0 0 10 10 10
53053- 34 34 34 78 78 78 50 50 50 6 6 6
53054- 94 70 30 139 102 15 190 146 13 226 184 13
53055-232 200 30 232 195 16 215 174 15 190 146 13
53056-168 122 10 192 133 9 210 150 10 213 154 11
53057-202 150 34 182 157 106 101 98 89 2 2 6
53058- 2 2 6 78 78 78 116 116 116 58 58 58
53059- 2 2 6 22 22 22 90 90 90 46 46 46
53060- 18 18 18 6 6 6 0 0 0 0 0 0
53061- 0 0 0 0 0 0 0 0 0 0 0 0
53062- 0 0 0 0 0 0 0 0 0 0 0 0
53063- 0 0 0 0 0 0 0 0 0 0 0 0
53064- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53072- 0 0 0 0 0 0 0 0 0 10 10 10
53073- 38 38 38 86 86 86 50 50 50 6 6 6
53074-128 128 128 174 154 114 156 107 11 168 122 10
53075-198 155 10 184 144 12 197 138 11 200 144 11
53076-206 145 10 206 145 10 197 138 11 188 164 115
53077-195 195 195 198 198 198 174 174 174 14 14 14
53078- 2 2 6 22 22 22 116 116 116 116 116 116
53079- 22 22 22 2 2 6 74 74 74 70 70 70
53080- 30 30 30 10 10 10 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 0 0 0
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
53093- 50 50 50 101 101 101 26 26 26 10 10 10
53094-138 138 138 190 190 190 174 154 114 156 107 11
53095-197 138 11 200 144 11 197 138 11 192 133 9
53096-180 123 7 190 142 34 190 178 144 187 187 187
53097-202 202 202 221 221 221 214 214 214 66 66 66
53098- 2 2 6 2 2 6 50 50 50 62 62 62
53099- 6 6 6 2 2 6 10 10 10 90 90 90
53100- 50 50 50 18 18 18 6 6 6 0 0 0
53101- 0 0 0 0 0 0 0 0 0 0 0 0
53102- 0 0 0 0 0 0 0 0 0 0 0 0
53103- 0 0 0 0 0 0 0 0 0 0 0 0
53104- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
53113- 74 74 74 74 74 74 2 2 6 6 6 6
53114-144 144 144 198 198 198 190 190 190 178 166 146
53115-154 121 60 156 107 11 156 107 11 168 124 44
53116-174 154 114 187 187 187 190 190 190 210 210 210
53117-246 246 246 253 253 253 253 253 253 182 182 182
53118- 6 6 6 2 2 6 2 2 6 2 2 6
53119- 2 2 6 2 2 6 2 2 6 62 62 62
53120- 74 74 74 34 34 34 14 14 14 0 0 0
53121- 0 0 0 0 0 0 0 0 0 0 0 0
53122- 0 0 0 0 0 0 0 0 0 0 0 0
53123- 0 0 0 0 0 0 0 0 0 0 0 0
53124- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 22 22 22 54 54 54
53133- 94 94 94 18 18 18 2 2 6 46 46 46
53134-234 234 234 221 221 221 190 190 190 190 190 190
53135-190 190 190 187 187 187 187 187 187 190 190 190
53136-190 190 190 195 195 195 214 214 214 242 242 242
53137-253 253 253 253 253 253 253 253 253 253 253 253
53138- 82 82 82 2 2 6 2 2 6 2 2 6
53139- 2 2 6 2 2 6 2 2 6 14 14 14
53140- 86 86 86 54 54 54 22 22 22 6 6 6
53141- 0 0 0 0 0 0 0 0 0 0 0 0
53142- 0 0 0 0 0 0 0 0 0 0 0 0
53143- 0 0 0 0 0 0 0 0 0 0 0 0
53144- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 18 18 18 46 46 46 90 90 90
53153- 46 46 46 18 18 18 6 6 6 182 182 182
53154-253 253 253 246 246 246 206 206 206 190 190 190
53155-190 190 190 190 190 190 190 190 190 190 190 190
53156-206 206 206 231 231 231 250 250 250 253 253 253
53157-253 253 253 253 253 253 253 253 253 253 253 253
53158-202 202 202 14 14 14 2 2 6 2 2 6
53159- 2 2 6 2 2 6 2 2 6 2 2 6
53160- 42 42 42 86 86 86 42 42 42 18 18 18
53161- 6 6 6 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 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 6 6 6
53172- 14 14 14 38 38 38 74 74 74 66 66 66
53173- 2 2 6 6 6 6 90 90 90 250 250 250
53174-253 253 253 253 253 253 238 238 238 198 198 198
53175-190 190 190 190 190 190 195 195 195 221 221 221
53176-246 246 246 253 253 253 253 253 253 253 253 253
53177-253 253 253 253 253 253 253 253 253 253 253 253
53178-253 253 253 82 82 82 2 2 6 2 2 6
53179- 2 2 6 2 2 6 2 2 6 2 2 6
53180- 2 2 6 78 78 78 70 70 70 34 34 34
53181- 14 14 14 6 6 6 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 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 14 14 14
53192- 34 34 34 66 66 66 78 78 78 6 6 6
53193- 2 2 6 18 18 18 218 218 218 253 253 253
53194-253 253 253 253 253 253 253 253 253 246 246 246
53195-226 226 226 231 231 231 246 246 246 253 253 253
53196-253 253 253 253 253 253 253 253 253 253 253 253
53197-253 253 253 253 253 253 253 253 253 253 253 253
53198-253 253 253 178 178 178 2 2 6 2 2 6
53199- 2 2 6 2 2 6 2 2 6 2 2 6
53200- 2 2 6 18 18 18 90 90 90 62 62 62
53201- 30 30 30 10 10 10 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 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 10 10 10 26 26 26
53212- 58 58 58 90 90 90 18 18 18 2 2 6
53213- 2 2 6 110 110 110 253 253 253 253 253 253
53214-253 253 253 253 253 253 253 253 253 253 253 253
53215-250 250 250 253 253 253 253 253 253 253 253 253
53216-253 253 253 253 253 253 253 253 253 253 253 253
53217-253 253 253 253 253 253 253 253 253 253 253 253
53218-253 253 253 231 231 231 18 18 18 2 2 6
53219- 2 2 6 2 2 6 2 2 6 2 2 6
53220- 2 2 6 2 2 6 18 18 18 94 94 94
53221- 54 54 54 26 26 26 10 10 10 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
53232- 90 90 90 26 26 26 2 2 6 2 2 6
53233- 14 14 14 195 195 195 250 250 250 253 253 253
53234-253 253 253 253 253 253 253 253 253 253 253 253
53235-253 253 253 253 253 253 253 253 253 253 253 253
53236-253 253 253 253 253 253 253 253 253 253 253 253
53237-253 253 253 253 253 253 253 253 253 253 253 253
53238-250 250 250 242 242 242 54 54 54 2 2 6
53239- 2 2 6 2 2 6 2 2 6 2 2 6
53240- 2 2 6 2 2 6 2 2 6 38 38 38
53241- 86 86 86 50 50 50 22 22 22 6 6 6
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
53252- 34 34 34 2 2 6 2 2 6 2 2 6
53253- 42 42 42 195 195 195 246 246 246 253 253 253
53254-253 253 253 253 253 253 253 253 253 250 250 250
53255-242 242 242 242 242 242 250 250 250 253 253 253
53256-253 253 253 253 253 253 253 253 253 253 253 253
53257-253 253 253 250 250 250 246 246 246 238 238 238
53258-226 226 226 231 231 231 101 101 101 6 6 6
53259- 2 2 6 2 2 6 2 2 6 2 2 6
53260- 2 2 6 2 2 6 2 2 6 2 2 6
53261- 38 38 38 82 82 82 42 42 42 14 14 14
53262- 6 6 6 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 0 0 0
53265- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
53272- 2 2 6 2 2 6 2 2 6 6 6 6
53273- 70 70 70 170 170 170 206 206 206 234 234 234
53274-246 246 246 250 250 250 250 250 250 238 238 238
53275-226 226 226 231 231 231 238 238 238 250 250 250
53276-250 250 250 250 250 250 246 246 246 231 231 231
53277-214 214 214 206 206 206 202 202 202 202 202 202
53278-198 198 198 202 202 202 182 182 182 18 18 18
53279- 2 2 6 2 2 6 2 2 6 2 2 6
53280- 2 2 6 2 2 6 2 2 6 2 2 6
53281- 2 2 6 62 62 62 66 66 66 30 30 30
53282- 10 10 10 0 0 0 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 0 0 0
53285- 0 0 0 0 0 0 0 0 0 0 0 0
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- 14 14 14 42 42 42 82 82 82 18 18 18
53292- 2 2 6 2 2 6 2 2 6 10 10 10
53293- 94 94 94 182 182 182 218 218 218 242 242 242
53294-250 250 250 253 253 253 253 253 253 250 250 250
53295-234 234 234 253 253 253 253 253 253 253 253 253
53296-253 253 253 253 253 253 253 253 253 246 246 246
53297-238 238 238 226 226 226 210 210 210 202 202 202
53298-195 195 195 195 195 195 210 210 210 158 158 158
53299- 6 6 6 14 14 14 50 50 50 14 14 14
53300- 2 2 6 2 2 6 2 2 6 2 2 6
53301- 2 2 6 6 6 6 86 86 86 46 46 46
53302- 18 18 18 6 6 6 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 0 0 0
53305- 0 0 0 0 0 0 0 0 0 0 0 0
53306- 0 0 0 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 6 6 6
53311- 22 22 22 54 54 54 70 70 70 2 2 6
53312- 2 2 6 10 10 10 2 2 6 22 22 22
53313-166 166 166 231 231 231 250 250 250 253 253 253
53314-253 253 253 253 253 253 253 253 253 250 250 250
53315-242 242 242 253 253 253 253 253 253 253 253 253
53316-253 253 253 253 253 253 253 253 253 253 253 253
53317-253 253 253 253 253 253 253 253 253 246 246 246
53318-231 231 231 206 206 206 198 198 198 226 226 226
53319- 94 94 94 2 2 6 6 6 6 38 38 38
53320- 30 30 30 2 2 6 2 2 6 2 2 6
53321- 2 2 6 2 2 6 62 62 62 66 66 66
53322- 26 26 26 10 10 10 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 0 0 0
53325- 0 0 0 0 0 0 0 0 0 0 0 0
53326- 0 0 0 0 0 0 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 10 10 10
53331- 30 30 30 74 74 74 50 50 50 2 2 6
53332- 26 26 26 26 26 26 2 2 6 106 106 106
53333-238 238 238 253 253 253 253 253 253 253 253 253
53334-253 253 253 253 253 253 253 253 253 253 253 253
53335-253 253 253 253 253 253 253 253 253 253 253 253
53336-253 253 253 253 253 253 253 253 253 253 253 253
53337-253 253 253 253 253 253 253 253 253 253 253 253
53338-253 253 253 246 246 246 218 218 218 202 202 202
53339-210 210 210 14 14 14 2 2 6 2 2 6
53340- 30 30 30 22 22 22 2 2 6 2 2 6
53341- 2 2 6 2 2 6 18 18 18 86 86 86
53342- 42 42 42 14 14 14 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 0 0 0
53345- 0 0 0 0 0 0 0 0 0 0 0 0
53346- 0 0 0 0 0 0 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 14 14 14
53351- 42 42 42 90 90 90 22 22 22 2 2 6
53352- 42 42 42 2 2 6 18 18 18 218 218 218
53353-253 253 253 253 253 253 253 253 253 253 253 253
53354-253 253 253 253 253 253 253 253 253 253 253 253
53355-253 253 253 253 253 253 253 253 253 253 253 253
53356-253 253 253 253 253 253 253 253 253 253 253 253
53357-253 253 253 253 253 253 253 253 253 253 253 253
53358-253 253 253 253 253 253 250 250 250 221 221 221
53359-218 218 218 101 101 101 2 2 6 14 14 14
53360- 18 18 18 38 38 38 10 10 10 2 2 6
53361- 2 2 6 2 2 6 2 2 6 78 78 78
53362- 58 58 58 22 22 22 6 6 6 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 0 0 0
53365- 0 0 0 0 0 0 0 0 0 0 0 0
53366- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
53371- 54 54 54 82 82 82 2 2 6 26 26 26
53372- 22 22 22 2 2 6 123 123 123 253 253 253
53373-253 253 253 253 253 253 253 253 253 253 253 253
53374-253 253 253 253 253 253 253 253 253 253 253 253
53375-253 253 253 253 253 253 253 253 253 253 253 253
53376-253 253 253 253 253 253 253 253 253 253 253 253
53377-253 253 253 253 253 253 253 253 253 253 253 253
53378-253 253 253 253 253 253 253 253 253 250 250 250
53379-238 238 238 198 198 198 6 6 6 38 38 38
53380- 58 58 58 26 26 26 38 38 38 2 2 6
53381- 2 2 6 2 2 6 2 2 6 46 46 46
53382- 78 78 78 30 30 30 10 10 10 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 0 0 0
53385- 0 0 0 0 0 0 0 0 0 0 0 0
53386- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 30 30 30
53391- 74 74 74 58 58 58 2 2 6 42 42 42
53392- 2 2 6 22 22 22 231 231 231 253 253 253
53393-253 253 253 253 253 253 253 253 253 253 253 253
53394-253 253 253 253 253 253 253 253 253 250 250 250
53395-253 253 253 253 253 253 253 253 253 253 253 253
53396-253 253 253 253 253 253 253 253 253 253 253 253
53397-253 253 253 253 253 253 253 253 253 253 253 253
53398-253 253 253 253 253 253 253 253 253 253 253 253
53399-253 253 253 246 246 246 46 46 46 38 38 38
53400- 42 42 42 14 14 14 38 38 38 14 14 14
53401- 2 2 6 2 2 6 2 2 6 6 6 6
53402- 86 86 86 46 46 46 14 14 14 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 0 0 0
53405- 0 0 0 0 0 0 0 0 0 0 0 0
53406- 0 0 0 0 0 0 0 0 0 0 0 0
53407- 0 0 0 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 6 6 6 14 14 14 42 42 42
53411- 90 90 90 18 18 18 18 18 18 26 26 26
53412- 2 2 6 116 116 116 253 253 253 253 253 253
53413-253 253 253 253 253 253 253 253 253 253 253 253
53414-253 253 253 253 253 253 250 250 250 238 238 238
53415-253 253 253 253 253 253 253 253 253 253 253 253
53416-253 253 253 253 253 253 253 253 253 253 253 253
53417-253 253 253 253 253 253 253 253 253 253 253 253
53418-253 253 253 253 253 253 253 253 253 253 253 253
53419-253 253 253 253 253 253 94 94 94 6 6 6
53420- 2 2 6 2 2 6 10 10 10 34 34 34
53421- 2 2 6 2 2 6 2 2 6 2 2 6
53422- 74 74 74 58 58 58 22 22 22 6 6 6
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 0 0 0
53425- 0 0 0 0 0 0 0 0 0 0 0 0
53426- 0 0 0 0 0 0 0 0 0 0 0 0
53427- 0 0 0 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 10 10 10 26 26 26 66 66 66
53431- 82 82 82 2 2 6 38 38 38 6 6 6
53432- 14 14 14 210 210 210 253 253 253 253 253 253
53433-253 253 253 253 253 253 253 253 253 253 253 253
53434-253 253 253 253 253 253 246 246 246 242 242 242
53435-253 253 253 253 253 253 253 253 253 253 253 253
53436-253 253 253 253 253 253 253 253 253 253 253 253
53437-253 253 253 253 253 253 253 253 253 253 253 253
53438-253 253 253 253 253 253 253 253 253 253 253 253
53439-253 253 253 253 253 253 144 144 144 2 2 6
53440- 2 2 6 2 2 6 2 2 6 46 46 46
53441- 2 2 6 2 2 6 2 2 6 2 2 6
53442- 42 42 42 74 74 74 30 30 30 10 10 10
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 0 0 0
53445- 0 0 0 0 0 0 0 0 0 0 0 0
53446- 0 0 0 0 0 0 0 0 0 0 0 0
53447- 0 0 0 0 0 0 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- 6 6 6 14 14 14 42 42 42 90 90 90
53451- 26 26 26 6 6 6 42 42 42 2 2 6
53452- 74 74 74 250 250 250 253 253 253 253 253 253
53453-253 253 253 253 253 253 253 253 253 253 253 253
53454-253 253 253 253 253 253 242 242 242 242 242 242
53455-253 253 253 253 253 253 253 253 253 253 253 253
53456-253 253 253 253 253 253 253 253 253 253 253 253
53457-253 253 253 253 253 253 253 253 253 253 253 253
53458-253 253 253 253 253 253 253 253 253 253 253 253
53459-253 253 253 253 253 253 182 182 182 2 2 6
53460- 2 2 6 2 2 6 2 2 6 46 46 46
53461- 2 2 6 2 2 6 2 2 6 2 2 6
53462- 10 10 10 86 86 86 38 38 38 10 10 10
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 0 0 0
53465- 0 0 0 0 0 0 0 0 0 0 0 0
53466- 0 0 0 0 0 0 0 0 0 0 0 0
53467- 0 0 0 0 0 0 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- 10 10 10 26 26 26 66 66 66 82 82 82
53471- 2 2 6 22 22 22 18 18 18 2 2 6
53472-149 149 149 253 253 253 253 253 253 253 253 253
53473-253 253 253 253 253 253 253 253 253 253 253 253
53474-253 253 253 253 253 253 234 234 234 242 242 242
53475-253 253 253 253 253 253 253 253 253 253 253 253
53476-253 253 253 253 253 253 253 253 253 253 253 253
53477-253 253 253 253 253 253 253 253 253 253 253 253
53478-253 253 253 253 253 253 253 253 253 253 253 253
53479-253 253 253 253 253 253 206 206 206 2 2 6
53480- 2 2 6 2 2 6 2 2 6 38 38 38
53481- 2 2 6 2 2 6 2 2 6 2 2 6
53482- 6 6 6 86 86 86 46 46 46 14 14 14
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 0 0 0
53485- 0 0 0 0 0 0 0 0 0 0 0 0
53486- 0 0 0 0 0 0 0 0 0 0 0 0
53487- 0 0 0 0 0 0 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 6 6 6
53490- 18 18 18 46 46 46 86 86 86 18 18 18
53491- 2 2 6 34 34 34 10 10 10 6 6 6
53492-210 210 210 253 253 253 253 253 253 253 253 253
53493-253 253 253 253 253 253 253 253 253 253 253 253
53494-253 253 253 253 253 253 234 234 234 242 242 242
53495-253 253 253 253 253 253 253 253 253 253 253 253
53496-253 253 253 253 253 253 253 253 253 253 253 253
53497-253 253 253 253 253 253 253 253 253 253 253 253
53498-253 253 253 253 253 253 253 253 253 253 253 253
53499-253 253 253 253 253 253 221 221 221 6 6 6
53500- 2 2 6 2 2 6 6 6 6 30 30 30
53501- 2 2 6 2 2 6 2 2 6 2 2 6
53502- 2 2 6 82 82 82 54 54 54 18 18 18
53503- 6 6 6 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 0 0 0
53505- 0 0 0 0 0 0 0 0 0 0 0 0
53506- 0 0 0 0 0 0 0 0 0 0 0 0
53507- 0 0 0 0 0 0 0 0 0 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 10 10 10
53510- 26 26 26 66 66 66 62 62 62 2 2 6
53511- 2 2 6 38 38 38 10 10 10 26 26 26
53512-238 238 238 253 253 253 253 253 253 253 253 253
53513-253 253 253 253 253 253 253 253 253 253 253 253
53514-253 253 253 253 253 253 231 231 231 238 238 238
53515-253 253 253 253 253 253 253 253 253 253 253 253
53516-253 253 253 253 253 253 253 253 253 253 253 253
53517-253 253 253 253 253 253 253 253 253 253 253 253
53518-253 253 253 253 253 253 253 253 253 253 253 253
53519-253 253 253 253 253 253 231 231 231 6 6 6
53520- 2 2 6 2 2 6 10 10 10 30 30 30
53521- 2 2 6 2 2 6 2 2 6 2 2 6
53522- 2 2 6 66 66 66 58 58 58 22 22 22
53523- 6 6 6 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 0 0 0
53525- 0 0 0 0 0 0 0 0 0 0 0 0
53526- 0 0 0 0 0 0 0 0 0 0 0 0
53527- 0 0 0 0 0 0 0 0 0 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 10 10 10
53530- 38 38 38 78 78 78 6 6 6 2 2 6
53531- 2 2 6 46 46 46 14 14 14 42 42 42
53532-246 246 246 253 253 253 253 253 253 253 253 253
53533-253 253 253 253 253 253 253 253 253 253 253 253
53534-253 253 253 253 253 253 231 231 231 242 242 242
53535-253 253 253 253 253 253 253 253 253 253 253 253
53536-253 253 253 253 253 253 253 253 253 253 253 253
53537-253 253 253 253 253 253 253 253 253 253 253 253
53538-253 253 253 253 253 253 253 253 253 253 253 253
53539-253 253 253 253 253 253 234 234 234 10 10 10
53540- 2 2 6 2 2 6 22 22 22 14 14 14
53541- 2 2 6 2 2 6 2 2 6 2 2 6
53542- 2 2 6 66 66 66 62 62 62 22 22 22
53543- 6 6 6 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 0 0 0
53545- 0 0 0 0 0 0 0 0 0 0 0 0
53546- 0 0 0 0 0 0 0 0 0 0 0 0
53547- 0 0 0 0 0 0 0 0 0 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 6 6 6 18 18 18
53550- 50 50 50 74 74 74 2 2 6 2 2 6
53551- 14 14 14 70 70 70 34 34 34 62 62 62
53552-250 250 250 253 253 253 253 253 253 253 253 253
53553-253 253 253 253 253 253 253 253 253 253 253 253
53554-253 253 253 253 253 253 231 231 231 246 246 246
53555-253 253 253 253 253 253 253 253 253 253 253 253
53556-253 253 253 253 253 253 253 253 253 253 253 253
53557-253 253 253 253 253 253 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 234 234 234 14 14 14
53560- 2 2 6 2 2 6 30 30 30 2 2 6
53561- 2 2 6 2 2 6 2 2 6 2 2 6
53562- 2 2 6 66 66 66 62 62 62 22 22 22
53563- 6 6 6 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 0 0 0
53565- 0 0 0 0 0 0 0 0 0 0 0 0
53566- 0 0 0 0 0 0 0 0 0 0 0 0
53567- 0 0 0 0 0 0 0 0 0 0 0 0
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 6 6 6 18 18 18
53570- 54 54 54 62 62 62 2 2 6 2 2 6
53571- 2 2 6 30 30 30 46 46 46 70 70 70
53572-250 250 250 253 253 253 253 253 253 253 253 253
53573-253 253 253 253 253 253 253 253 253 253 253 253
53574-253 253 253 253 253 253 231 231 231 246 246 246
53575-253 253 253 253 253 253 253 253 253 253 253 253
53576-253 253 253 253 253 253 253 253 253 253 253 253
53577-253 253 253 253 253 253 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 226 226 226 10 10 10
53580- 2 2 6 6 6 6 30 30 30 2 2 6
53581- 2 2 6 2 2 6 2 2 6 2 2 6
53582- 2 2 6 66 66 66 58 58 58 22 22 22
53583- 6 6 6 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 0 0 0
53585- 0 0 0 0 0 0 0 0 0 0 0 0
53586- 0 0 0 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 6 6 6 22 22 22
53590- 58 58 58 62 62 62 2 2 6 2 2 6
53591- 2 2 6 2 2 6 30 30 30 78 78 78
53592-250 250 250 253 253 253 253 253 253 253 253 253
53593-253 253 253 253 253 253 253 253 253 253 253 253
53594-253 253 253 253 253 253 231 231 231 246 246 246
53595-253 253 253 253 253 253 253 253 253 253 253 253
53596-253 253 253 253 253 253 253 253 253 253 253 253
53597-253 253 253 253 253 253 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 206 206 206 2 2 6
53600- 22 22 22 34 34 34 18 14 6 22 22 22
53601- 26 26 26 18 18 18 6 6 6 2 2 6
53602- 2 2 6 82 82 82 54 54 54 18 18 18
53603- 6 6 6 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 0 0 0
53605- 0 0 0 0 0 0 0 0 0 0 0 0
53606- 0 0 0 0 0 0 0 0 0 0 0 0
53607- 0 0 0 0 0 0 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 6 6 6 26 26 26
53610- 62 62 62 106 106 106 74 54 14 185 133 11
53611-210 162 10 121 92 8 6 6 6 62 62 62
53612-238 238 238 253 253 253 253 253 253 253 253 253
53613-253 253 253 253 253 253 253 253 253 253 253 253
53614-253 253 253 253 253 253 231 231 231 246 246 246
53615-253 253 253 253 253 253 253 253 253 253 253 253
53616-253 253 253 253 253 253 253 253 253 253 253 253
53617-253 253 253 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 158 158 158 18 18 18
53620- 14 14 14 2 2 6 2 2 6 2 2 6
53621- 6 6 6 18 18 18 66 66 66 38 38 38
53622- 6 6 6 94 94 94 50 50 50 18 18 18
53623- 6 6 6 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 0 0 0
53625- 0 0 0 0 0 0 0 0 0 0 0 0
53626- 0 0 0 0 0 0 0 0 0 0 0 0
53627- 0 0 0 0 0 0 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 6 6 6
53629- 10 10 10 10 10 10 18 18 18 38 38 38
53630- 78 78 78 142 134 106 216 158 10 242 186 14
53631-246 190 14 246 190 14 156 118 10 10 10 10
53632- 90 90 90 238 238 238 253 253 253 253 253 253
53633-253 253 253 253 253 253 253 253 253 253 253 253
53634-253 253 253 253 253 253 231 231 231 250 250 250
53635-253 253 253 253 253 253 253 253 253 253 253 253
53636-253 253 253 253 253 253 253 253 253 253 253 253
53637-253 253 253 253 253 253 253 253 253 253 253 253
53638-253 253 253 253 253 253 253 253 253 246 230 190
53639-238 204 91 238 204 91 181 142 44 37 26 9
53640- 2 2 6 2 2 6 2 2 6 2 2 6
53641- 2 2 6 2 2 6 38 38 38 46 46 46
53642- 26 26 26 106 106 106 54 54 54 18 18 18
53643- 6 6 6 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 0 0 0 0 0 0
53645- 0 0 0 0 0 0 0 0 0 0 0 0
53646- 0 0 0 0 0 0 0 0 0 0 0 0
53647- 0 0 0 0 0 0 0 0 0 0 0 0
53648- 0 0 0 6 6 6 14 14 14 22 22 22
53649- 30 30 30 38 38 38 50 50 50 70 70 70
53650-106 106 106 190 142 34 226 170 11 242 186 14
53651-246 190 14 246 190 14 246 190 14 154 114 10
53652- 6 6 6 74 74 74 226 226 226 253 253 253
53653-253 253 253 253 253 253 253 253 253 253 253 253
53654-253 253 253 253 253 253 231 231 231 250 250 250
53655-253 253 253 253 253 253 253 253 253 253 253 253
53656-253 253 253 253 253 253 253 253 253 253 253 253
53657-253 253 253 253 253 253 253 253 253 253 253 253
53658-253 253 253 253 253 253 253 253 253 228 184 62
53659-241 196 14 241 208 19 232 195 16 38 30 10
53660- 2 2 6 2 2 6 2 2 6 2 2 6
53661- 2 2 6 6 6 6 30 30 30 26 26 26
53662-203 166 17 154 142 90 66 66 66 26 26 26
53663- 6 6 6 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 0 0 0 0 0 0 0 0 0 0 0 0
53667- 0 0 0 0 0 0 0 0 0 0 0 0
53668- 6 6 6 18 18 18 38 38 38 58 58 58
53669- 78 78 78 86 86 86 101 101 101 123 123 123
53670-175 146 61 210 150 10 234 174 13 246 186 14
53671-246 190 14 246 190 14 246 190 14 238 190 10
53672-102 78 10 2 2 6 46 46 46 198 198 198
53673-253 253 253 253 253 253 253 253 253 253 253 253
53674-253 253 253 253 253 253 234 234 234 242 242 242
53675-253 253 253 253 253 253 253 253 253 253 253 253
53676-253 253 253 253 253 253 253 253 253 253 253 253
53677-253 253 253 253 253 253 253 253 253 253 253 253
53678-253 253 253 253 253 253 253 253 253 224 178 62
53679-242 186 14 241 196 14 210 166 10 22 18 6
53680- 2 2 6 2 2 6 2 2 6 2 2 6
53681- 2 2 6 2 2 6 6 6 6 121 92 8
53682-238 202 15 232 195 16 82 82 82 34 34 34
53683- 10 10 10 0 0 0 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 0 0 0
53685- 0 0 0 0 0 0 0 0 0 0 0 0
53686- 0 0 0 0 0 0 0 0 0 0 0 0
53687- 0 0 0 0 0 0 0 0 0 0 0 0
53688- 14 14 14 38 38 38 70 70 70 154 122 46
53689-190 142 34 200 144 11 197 138 11 197 138 11
53690-213 154 11 226 170 11 242 186 14 246 190 14
53691-246 190 14 246 190 14 246 190 14 246 190 14
53692-225 175 15 46 32 6 2 2 6 22 22 22
53693-158 158 158 250 250 250 253 253 253 253 253 253
53694-253 253 253 253 253 253 253 253 253 253 253 253
53695-253 253 253 253 253 253 253 253 253 253 253 253
53696-253 253 253 253 253 253 253 253 253 253 253 253
53697-253 253 253 253 253 253 253 253 253 253 253 253
53698-253 253 253 250 250 250 242 242 242 224 178 62
53699-239 182 13 236 186 11 213 154 11 46 32 6
53700- 2 2 6 2 2 6 2 2 6 2 2 6
53701- 2 2 6 2 2 6 61 42 6 225 175 15
53702-238 190 10 236 186 11 112 100 78 42 42 42
53703- 14 14 14 0 0 0 0 0 0 0 0 0
53704- 0 0 0 0 0 0 0 0 0 0 0 0
53705- 0 0 0 0 0 0 0 0 0 0 0 0
53706- 0 0 0 0 0 0 0 0 0 0 0 0
53707- 0 0 0 0 0 0 0 0 0 6 6 6
53708- 22 22 22 54 54 54 154 122 46 213 154 11
53709-226 170 11 230 174 11 226 170 11 226 170 11
53710-236 178 12 242 186 14 246 190 14 246 190 14
53711-246 190 14 246 190 14 246 190 14 246 190 14
53712-241 196 14 184 144 12 10 10 10 2 2 6
53713- 6 6 6 116 116 116 242 242 242 253 253 253
53714-253 253 253 253 253 253 253 253 253 253 253 253
53715-253 253 253 253 253 253 253 253 253 253 253 253
53716-253 253 253 253 253 253 253 253 253 253 253 253
53717-253 253 253 253 253 253 253 253 253 253 253 253
53718-253 253 253 231 231 231 198 198 198 214 170 54
53719-236 178 12 236 178 12 210 150 10 137 92 6
53720- 18 14 6 2 2 6 2 2 6 2 2 6
53721- 6 6 6 70 47 6 200 144 11 236 178 12
53722-239 182 13 239 182 13 124 112 88 58 58 58
53723- 22 22 22 6 6 6 0 0 0 0 0 0
53724- 0 0 0 0 0 0 0 0 0 0 0 0
53725- 0 0 0 0 0 0 0 0 0 0 0 0
53726- 0 0 0 0 0 0 0 0 0 0 0 0
53727- 0 0 0 0 0 0 0 0 0 10 10 10
53728- 30 30 30 70 70 70 180 133 36 226 170 11
53729-239 182 13 242 186 14 242 186 14 246 186 14
53730-246 190 14 246 190 14 246 190 14 246 190 14
53731-246 190 14 246 190 14 246 190 14 246 190 14
53732-246 190 14 232 195 16 98 70 6 2 2 6
53733- 2 2 6 2 2 6 66 66 66 221 221 221
53734-253 253 253 253 253 253 253 253 253 253 253 253
53735-253 253 253 253 253 253 253 253 253 253 253 253
53736-253 253 253 253 253 253 253 253 253 253 253 253
53737-253 253 253 253 253 253 253 253 253 253 253 253
53738-253 253 253 206 206 206 198 198 198 214 166 58
53739-230 174 11 230 174 11 216 158 10 192 133 9
53740-163 110 8 116 81 8 102 78 10 116 81 8
53741-167 114 7 197 138 11 226 170 11 239 182 13
53742-242 186 14 242 186 14 162 146 94 78 78 78
53743- 34 34 34 14 14 14 6 6 6 0 0 0
53744- 0 0 0 0 0 0 0 0 0 0 0 0
53745- 0 0 0 0 0 0 0 0 0 0 0 0
53746- 0 0 0 0 0 0 0 0 0 0 0 0
53747- 0 0 0 0 0 0 0 0 0 6 6 6
53748- 30 30 30 78 78 78 190 142 34 226 170 11
53749-239 182 13 246 190 14 246 190 14 246 190 14
53750-246 190 14 246 190 14 246 190 14 246 190 14
53751-246 190 14 246 190 14 246 190 14 246 190 14
53752-246 190 14 241 196 14 203 166 17 22 18 6
53753- 2 2 6 2 2 6 2 2 6 38 38 38
53754-218 218 218 253 253 253 253 253 253 253 253 253
53755-253 253 253 253 253 253 253 253 253 253 253 253
53756-253 253 253 253 253 253 253 253 253 253 253 253
53757-253 253 253 253 253 253 253 253 253 253 253 253
53758-250 250 250 206 206 206 198 198 198 202 162 69
53759-226 170 11 236 178 12 224 166 10 210 150 10
53760-200 144 11 197 138 11 192 133 9 197 138 11
53761-210 150 10 226 170 11 242 186 14 246 190 14
53762-246 190 14 246 186 14 225 175 15 124 112 88
53763- 62 62 62 30 30 30 14 14 14 6 6 6
53764- 0 0 0 0 0 0 0 0 0 0 0 0
53765- 0 0 0 0 0 0 0 0 0 0 0 0
53766- 0 0 0 0 0 0 0 0 0 0 0 0
53767- 0 0 0 0 0 0 0 0 0 10 10 10
53768- 30 30 30 78 78 78 174 135 50 224 166 10
53769-239 182 13 246 190 14 246 190 14 246 190 14
53770-246 190 14 246 190 14 246 190 14 246 190 14
53771-246 190 14 246 190 14 246 190 14 246 190 14
53772-246 190 14 246 190 14 241 196 14 139 102 15
53773- 2 2 6 2 2 6 2 2 6 2 2 6
53774- 78 78 78 250 250 250 253 253 253 253 253 253
53775-253 253 253 253 253 253 253 253 253 253 253 253
53776-253 253 253 253 253 253 253 253 253 253 253 253
53777-253 253 253 253 253 253 253 253 253 253 253 253
53778-250 250 250 214 214 214 198 198 198 190 150 46
53779-219 162 10 236 178 12 234 174 13 224 166 10
53780-216 158 10 213 154 11 213 154 11 216 158 10
53781-226 170 11 239 182 13 246 190 14 246 190 14
53782-246 190 14 246 190 14 242 186 14 206 162 42
53783-101 101 101 58 58 58 30 30 30 14 14 14
53784- 6 6 6 0 0 0 0 0 0 0 0 0
53785- 0 0 0 0 0 0 0 0 0 0 0 0
53786- 0 0 0 0 0 0 0 0 0 0 0 0
53787- 0 0 0 0 0 0 0 0 0 10 10 10
53788- 30 30 30 74 74 74 174 135 50 216 158 10
53789-236 178 12 246 190 14 246 190 14 246 190 14
53790-246 190 14 246 190 14 246 190 14 246 190 14
53791-246 190 14 246 190 14 246 190 14 246 190 14
53792-246 190 14 246 190 14 241 196 14 226 184 13
53793- 61 42 6 2 2 6 2 2 6 2 2 6
53794- 22 22 22 238 238 238 253 253 253 253 253 253
53795-253 253 253 253 253 253 253 253 253 253 253 253
53796-253 253 253 253 253 253 253 253 253 253 253 253
53797-253 253 253 253 253 253 253 253 253 253 253 253
53798-253 253 253 226 226 226 187 187 187 180 133 36
53799-216 158 10 236 178 12 239 182 13 236 178 12
53800-230 174 11 226 170 11 226 170 11 230 174 11
53801-236 178 12 242 186 14 246 190 14 246 190 14
53802-246 190 14 246 190 14 246 186 14 239 182 13
53803-206 162 42 106 106 106 66 66 66 34 34 34
53804- 14 14 14 6 6 6 0 0 0 0 0 0
53805- 0 0 0 0 0 0 0 0 0 0 0 0
53806- 0 0 0 0 0 0 0 0 0 0 0 0
53807- 0 0 0 0 0 0 0 0 0 6 6 6
53808- 26 26 26 70 70 70 163 133 67 213 154 11
53809-236 178 12 246 190 14 246 190 14 246 190 14
53810-246 190 14 246 190 14 246 190 14 246 190 14
53811-246 190 14 246 190 14 246 190 14 246 190 14
53812-246 190 14 246 190 14 246 190 14 241 196 14
53813-190 146 13 18 14 6 2 2 6 2 2 6
53814- 46 46 46 246 246 246 253 253 253 253 253 253
53815-253 253 253 253 253 253 253 253 253 253 253 253
53816-253 253 253 253 253 253 253 253 253 253 253 253
53817-253 253 253 253 253 253 253 253 253 253 253 253
53818-253 253 253 221 221 221 86 86 86 156 107 11
53819-216 158 10 236 178 12 242 186 14 246 186 14
53820-242 186 14 239 182 13 239 182 13 242 186 14
53821-242 186 14 246 186 14 246 190 14 246 190 14
53822-246 190 14 246 190 14 246 190 14 246 190 14
53823-242 186 14 225 175 15 142 122 72 66 66 66
53824- 30 30 30 10 10 10 0 0 0 0 0 0
53825- 0 0 0 0 0 0 0 0 0 0 0 0
53826- 0 0 0 0 0 0 0 0 0 0 0 0
53827- 0 0 0 0 0 0 0 0 0 6 6 6
53828- 26 26 26 70 70 70 163 133 67 210 150 10
53829-236 178 12 246 190 14 246 190 14 246 190 14
53830-246 190 14 246 190 14 246 190 14 246 190 14
53831-246 190 14 246 190 14 246 190 14 246 190 14
53832-246 190 14 246 190 14 246 190 14 246 190 14
53833-232 195 16 121 92 8 34 34 34 106 106 106
53834-221 221 221 253 253 253 253 253 253 253 253 253
53835-253 253 253 253 253 253 253 253 253 253 253 253
53836-253 253 253 253 253 253 253 253 253 253 253 253
53837-253 253 253 253 253 253 253 253 253 253 253 253
53838-242 242 242 82 82 82 18 14 6 163 110 8
53839-216 158 10 236 178 12 242 186 14 246 190 14
53840-246 190 14 246 190 14 246 190 14 246 190 14
53841-246 190 14 246 190 14 246 190 14 246 190 14
53842-246 190 14 246 190 14 246 190 14 246 190 14
53843-246 190 14 246 190 14 242 186 14 163 133 67
53844- 46 46 46 18 18 18 6 6 6 0 0 0
53845- 0 0 0 0 0 0 0 0 0 0 0 0
53846- 0 0 0 0 0 0 0 0 0 0 0 0
53847- 0 0 0 0 0 0 0 0 0 10 10 10
53848- 30 30 30 78 78 78 163 133 67 210 150 10
53849-236 178 12 246 186 14 246 190 14 246 190 14
53850-246 190 14 246 190 14 246 190 14 246 190 14
53851-246 190 14 246 190 14 246 190 14 246 190 14
53852-246 190 14 246 190 14 246 190 14 246 190 14
53853-241 196 14 215 174 15 190 178 144 253 253 253
53854-253 253 253 253 253 253 253 253 253 253 253 253
53855-253 253 253 253 253 253 253 253 253 253 253 253
53856-253 253 253 253 253 253 253 253 253 253 253 253
53857-253 253 253 253 253 253 253 253 253 218 218 218
53858- 58 58 58 2 2 6 22 18 6 167 114 7
53859-216 158 10 236 178 12 246 186 14 246 190 14
53860-246 190 14 246 190 14 246 190 14 246 190 14
53861-246 190 14 246 190 14 246 190 14 246 190 14
53862-246 190 14 246 190 14 246 190 14 246 190 14
53863-246 190 14 246 186 14 242 186 14 190 150 46
53864- 54 54 54 22 22 22 6 6 6 0 0 0
53865- 0 0 0 0 0 0 0 0 0 0 0 0
53866- 0 0 0 0 0 0 0 0 0 0 0 0
53867- 0 0 0 0 0 0 0 0 0 14 14 14
53868- 38 38 38 86 86 86 180 133 36 213 154 11
53869-236 178 12 246 186 14 246 190 14 246 190 14
53870-246 190 14 246 190 14 246 190 14 246 190 14
53871-246 190 14 246 190 14 246 190 14 246 190 14
53872-246 190 14 246 190 14 246 190 14 246 190 14
53873-246 190 14 232 195 16 190 146 13 214 214 214
53874-253 253 253 253 253 253 253 253 253 253 253 253
53875-253 253 253 253 253 253 253 253 253 253 253 253
53876-253 253 253 253 253 253 253 253 253 253 253 253
53877-253 253 253 250 250 250 170 170 170 26 26 26
53878- 2 2 6 2 2 6 37 26 9 163 110 8
53879-219 162 10 239 182 13 246 186 14 246 190 14
53880-246 190 14 246 190 14 246 190 14 246 190 14
53881-246 190 14 246 190 14 246 190 14 246 190 14
53882-246 190 14 246 190 14 246 190 14 246 190 14
53883-246 186 14 236 178 12 224 166 10 142 122 72
53884- 46 46 46 18 18 18 6 6 6 0 0 0
53885- 0 0 0 0 0 0 0 0 0 0 0 0
53886- 0 0 0 0 0 0 0 0 0 0 0 0
53887- 0 0 0 0 0 0 6 6 6 18 18 18
53888- 50 50 50 109 106 95 192 133 9 224 166 10
53889-242 186 14 246 190 14 246 190 14 246 190 14
53890-246 190 14 246 190 14 246 190 14 246 190 14
53891-246 190 14 246 190 14 246 190 14 246 190 14
53892-246 190 14 246 190 14 246 190 14 246 190 14
53893-242 186 14 226 184 13 210 162 10 142 110 46
53894-226 226 226 253 253 253 253 253 253 253 253 253
53895-253 253 253 253 253 253 253 253 253 253 253 253
53896-253 253 253 253 253 253 253 253 253 253 253 253
53897-198 198 198 66 66 66 2 2 6 2 2 6
53898- 2 2 6 2 2 6 50 34 6 156 107 11
53899-219 162 10 239 182 13 246 186 14 246 190 14
53900-246 190 14 246 190 14 246 190 14 246 190 14
53901-246 190 14 246 190 14 246 190 14 246 190 14
53902-246 190 14 246 190 14 246 190 14 242 186 14
53903-234 174 13 213 154 11 154 122 46 66 66 66
53904- 30 30 30 10 10 10 0 0 0 0 0 0
53905- 0 0 0 0 0 0 0 0 0 0 0 0
53906- 0 0 0 0 0 0 0 0 0 0 0 0
53907- 0 0 0 0 0 0 6 6 6 22 22 22
53908- 58 58 58 154 121 60 206 145 10 234 174 13
53909-242 186 14 246 186 14 246 190 14 246 190 14
53910-246 190 14 246 190 14 246 190 14 246 190 14
53911-246 190 14 246 190 14 246 190 14 246 190 14
53912-246 190 14 246 190 14 246 190 14 246 190 14
53913-246 186 14 236 178 12 210 162 10 163 110 8
53914- 61 42 6 138 138 138 218 218 218 250 250 250
53915-253 253 253 253 253 253 253 253 253 250 250 250
53916-242 242 242 210 210 210 144 144 144 66 66 66
53917- 6 6 6 2 2 6 2 2 6 2 2 6
53918- 2 2 6 2 2 6 61 42 6 163 110 8
53919-216 158 10 236 178 12 246 190 14 246 190 14
53920-246 190 14 246 190 14 246 190 14 246 190 14
53921-246 190 14 246 190 14 246 190 14 246 190 14
53922-246 190 14 239 182 13 230 174 11 216 158 10
53923-190 142 34 124 112 88 70 70 70 38 38 38
53924- 18 18 18 6 6 6 0 0 0 0 0 0
53925- 0 0 0 0 0 0 0 0 0 0 0 0
53926- 0 0 0 0 0 0 0 0 0 0 0 0
53927- 0 0 0 0 0 0 6 6 6 22 22 22
53928- 62 62 62 168 124 44 206 145 10 224 166 10
53929-236 178 12 239 182 13 242 186 14 242 186 14
53930-246 186 14 246 190 14 246 190 14 246 190 14
53931-246 190 14 246 190 14 246 190 14 246 190 14
53932-246 190 14 246 190 14 246 190 14 246 190 14
53933-246 190 14 236 178 12 216 158 10 175 118 6
53934- 80 54 7 2 2 6 6 6 6 30 30 30
53935- 54 54 54 62 62 62 50 50 50 38 38 38
53936- 14 14 14 2 2 6 2 2 6 2 2 6
53937- 2 2 6 2 2 6 2 2 6 2 2 6
53938- 2 2 6 6 6 6 80 54 7 167 114 7
53939-213 154 11 236 178 12 246 190 14 246 190 14
53940-246 190 14 246 190 14 246 190 14 246 190 14
53941-246 190 14 242 186 14 239 182 13 239 182 13
53942-230 174 11 210 150 10 174 135 50 124 112 88
53943- 82 82 82 54 54 54 34 34 34 18 18 18
53944- 6 6 6 0 0 0 0 0 0 0 0 0
53945- 0 0 0 0 0 0 0 0 0 0 0 0
53946- 0 0 0 0 0 0 0 0 0 0 0 0
53947- 0 0 0 0 0 0 6 6 6 18 18 18
53948- 50 50 50 158 118 36 192 133 9 200 144 11
53949-216 158 10 219 162 10 224 166 10 226 170 11
53950-230 174 11 236 178 12 239 182 13 239 182 13
53951-242 186 14 246 186 14 246 190 14 246 190 14
53952-246 190 14 246 190 14 246 190 14 246 190 14
53953-246 186 14 230 174 11 210 150 10 163 110 8
53954-104 69 6 10 10 10 2 2 6 2 2 6
53955- 2 2 6 2 2 6 2 2 6 2 2 6
53956- 2 2 6 2 2 6 2 2 6 2 2 6
53957- 2 2 6 2 2 6 2 2 6 2 2 6
53958- 2 2 6 6 6 6 91 60 6 167 114 7
53959-206 145 10 230 174 11 242 186 14 246 190 14
53960-246 190 14 246 190 14 246 186 14 242 186 14
53961-239 182 13 230 174 11 224 166 10 213 154 11
53962-180 133 36 124 112 88 86 86 86 58 58 58
53963- 38 38 38 22 22 22 10 10 10 6 6 6
53964- 0 0 0 0 0 0 0 0 0 0 0 0
53965- 0 0 0 0 0 0 0 0 0 0 0 0
53966- 0 0 0 0 0 0 0 0 0 0 0 0
53967- 0 0 0 0 0 0 0 0 0 14 14 14
53968- 34 34 34 70 70 70 138 110 50 158 118 36
53969-167 114 7 180 123 7 192 133 9 197 138 11
53970-200 144 11 206 145 10 213 154 11 219 162 10
53971-224 166 10 230 174 11 239 182 13 242 186 14
53972-246 186 14 246 186 14 246 186 14 246 186 14
53973-239 182 13 216 158 10 185 133 11 152 99 6
53974-104 69 6 18 14 6 2 2 6 2 2 6
53975- 2 2 6 2 2 6 2 2 6 2 2 6
53976- 2 2 6 2 2 6 2 2 6 2 2 6
53977- 2 2 6 2 2 6 2 2 6 2 2 6
53978- 2 2 6 6 6 6 80 54 7 152 99 6
53979-192 133 9 219 162 10 236 178 12 239 182 13
53980-246 186 14 242 186 14 239 182 13 236 178 12
53981-224 166 10 206 145 10 192 133 9 154 121 60
53982- 94 94 94 62 62 62 42 42 42 22 22 22
53983- 14 14 14 6 6 6 0 0 0 0 0 0
53984- 0 0 0 0 0 0 0 0 0 0 0 0
53985- 0 0 0 0 0 0 0 0 0 0 0 0
53986- 0 0 0 0 0 0 0 0 0 0 0 0
53987- 0 0 0 0 0 0 0 0 0 6 6 6
53988- 18 18 18 34 34 34 58 58 58 78 78 78
53989-101 98 89 124 112 88 142 110 46 156 107 11
53990-163 110 8 167 114 7 175 118 6 180 123 7
53991-185 133 11 197 138 11 210 150 10 219 162 10
53992-226 170 11 236 178 12 236 178 12 234 174 13
53993-219 162 10 197 138 11 163 110 8 130 83 6
53994- 91 60 6 10 10 10 2 2 6 2 2 6
53995- 18 18 18 38 38 38 38 38 38 38 38 38
53996- 38 38 38 38 38 38 38 38 38 38 38 38
53997- 38 38 38 38 38 38 26 26 26 2 2 6
53998- 2 2 6 6 6 6 70 47 6 137 92 6
53999-175 118 6 200 144 11 219 162 10 230 174 11
54000-234 174 13 230 174 11 219 162 10 210 150 10
54001-192 133 9 163 110 8 124 112 88 82 82 82
54002- 50 50 50 30 30 30 14 14 14 6 6 6
54003- 0 0 0 0 0 0 0 0 0 0 0 0
54004- 0 0 0 0 0 0 0 0 0 0 0 0
54005- 0 0 0 0 0 0 0 0 0 0 0 0
54006- 0 0 0 0 0 0 0 0 0 0 0 0
54007- 0 0 0 0 0 0 0 0 0 0 0 0
54008- 6 6 6 14 14 14 22 22 22 34 34 34
54009- 42 42 42 58 58 58 74 74 74 86 86 86
54010-101 98 89 122 102 70 130 98 46 121 87 25
54011-137 92 6 152 99 6 163 110 8 180 123 7
54012-185 133 11 197 138 11 206 145 10 200 144 11
54013-180 123 7 156 107 11 130 83 6 104 69 6
54014- 50 34 6 54 54 54 110 110 110 101 98 89
54015- 86 86 86 82 82 82 78 78 78 78 78 78
54016- 78 78 78 78 78 78 78 78 78 78 78 78
54017- 78 78 78 82 82 82 86 86 86 94 94 94
54018-106 106 106 101 101 101 86 66 34 124 80 6
54019-156 107 11 180 123 7 192 133 9 200 144 11
54020-206 145 10 200 144 11 192 133 9 175 118 6
54021-139 102 15 109 106 95 70 70 70 42 42 42
54022- 22 22 22 10 10 10 0 0 0 0 0 0
54023- 0 0 0 0 0 0 0 0 0 0 0 0
54024- 0 0 0 0 0 0 0 0 0 0 0 0
54025- 0 0 0 0 0 0 0 0 0 0 0 0
54026- 0 0 0 0 0 0 0 0 0 0 0 0
54027- 0 0 0 0 0 0 0 0 0 0 0 0
54028- 0 0 0 0 0 0 6 6 6 10 10 10
54029- 14 14 14 22 22 22 30 30 30 38 38 38
54030- 50 50 50 62 62 62 74 74 74 90 90 90
54031-101 98 89 112 100 78 121 87 25 124 80 6
54032-137 92 6 152 99 6 152 99 6 152 99 6
54033-138 86 6 124 80 6 98 70 6 86 66 30
54034-101 98 89 82 82 82 58 58 58 46 46 46
54035- 38 38 38 34 34 34 34 34 34 34 34 34
54036- 34 34 34 34 34 34 34 34 34 34 34 34
54037- 34 34 34 34 34 34 38 38 38 42 42 42
54038- 54 54 54 82 82 82 94 86 76 91 60 6
54039-134 86 6 156 107 11 167 114 7 175 118 6
54040-175 118 6 167 114 7 152 99 6 121 87 25
54041-101 98 89 62 62 62 34 34 34 18 18 18
54042- 6 6 6 0 0 0 0 0 0 0 0 0
54043- 0 0 0 0 0 0 0 0 0 0 0 0
54044- 0 0 0 0 0 0 0 0 0 0 0 0
54045- 0 0 0 0 0 0 0 0 0 0 0 0
54046- 0 0 0 0 0 0 0 0 0 0 0 0
54047- 0 0 0 0 0 0 0 0 0 0 0 0
54048- 0 0 0 0 0 0 0 0 0 0 0 0
54049- 0 0 0 6 6 6 6 6 6 10 10 10
54050- 18 18 18 22 22 22 30 30 30 42 42 42
54051- 50 50 50 66 66 66 86 86 86 101 98 89
54052-106 86 58 98 70 6 104 69 6 104 69 6
54053-104 69 6 91 60 6 82 62 34 90 90 90
54054- 62 62 62 38 38 38 22 22 22 14 14 14
54055- 10 10 10 10 10 10 10 10 10 10 10 10
54056- 10 10 10 10 10 10 6 6 6 10 10 10
54057- 10 10 10 10 10 10 10 10 10 14 14 14
54058- 22 22 22 42 42 42 70 70 70 89 81 66
54059- 80 54 7 104 69 6 124 80 6 137 92 6
54060-134 86 6 116 81 8 100 82 52 86 86 86
54061- 58 58 58 30 30 30 14 14 14 6 6 6
54062- 0 0 0 0 0 0 0 0 0 0 0 0
54063- 0 0 0 0 0 0 0 0 0 0 0 0
54064- 0 0 0 0 0 0 0 0 0 0 0 0
54065- 0 0 0 0 0 0 0 0 0 0 0 0
54066- 0 0 0 0 0 0 0 0 0 0 0 0
54067- 0 0 0 0 0 0 0 0 0 0 0 0
54068- 0 0 0 0 0 0 0 0 0 0 0 0
54069- 0 0 0 0 0 0 0 0 0 0 0 0
54070- 0 0 0 6 6 6 10 10 10 14 14 14
54071- 18 18 18 26 26 26 38 38 38 54 54 54
54072- 70 70 70 86 86 86 94 86 76 89 81 66
54073- 89 81 66 86 86 86 74 74 74 50 50 50
54074- 30 30 30 14 14 14 6 6 6 0 0 0
54075- 0 0 0 0 0 0 0 0 0 0 0 0
54076- 0 0 0 0 0 0 0 0 0 0 0 0
54077- 0 0 0 0 0 0 0 0 0 0 0 0
54078- 6 6 6 18 18 18 34 34 34 58 58 58
54079- 82 82 82 89 81 66 89 81 66 89 81 66
54080- 94 86 66 94 86 76 74 74 74 50 50 50
54081- 26 26 26 14 14 14 6 6 6 0 0 0
54082- 0 0 0 0 0 0 0 0 0 0 0 0
54083- 0 0 0 0 0 0 0 0 0 0 0 0
54084- 0 0 0 0 0 0 0 0 0 0 0 0
54085- 0 0 0 0 0 0 0 0 0 0 0 0
54086- 0 0 0 0 0 0 0 0 0 0 0 0
54087- 0 0 0 0 0 0 0 0 0 0 0 0
54088- 0 0 0 0 0 0 0 0 0 0 0 0
54089- 0 0 0 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 6 6 6 6 6 6 14 14 14 18 18 18
54092- 30 30 30 38 38 38 46 46 46 54 54 54
54093- 50 50 50 42 42 42 30 30 30 18 18 18
54094- 10 10 10 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 0 0 0 0 0 0
54096- 0 0 0 0 0 0 0 0 0 0 0 0
54097- 0 0 0 0 0 0 0 0 0 0 0 0
54098- 0 0 0 6 6 6 14 14 14 26 26 26
54099- 38 38 38 50 50 50 58 58 58 58 58 58
54100- 54 54 54 42 42 42 30 30 30 18 18 18
54101- 10 10 10 0 0 0 0 0 0 0 0 0
54102- 0 0 0 0 0 0 0 0 0 0 0 0
54103- 0 0 0 0 0 0 0 0 0 0 0 0
54104- 0 0 0 0 0 0 0 0 0 0 0 0
54105- 0 0 0 0 0 0 0 0 0 0 0 0
54106- 0 0 0 0 0 0 0 0 0 0 0 0
54107- 0 0 0 0 0 0 0 0 0 0 0 0
54108- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
54112- 6 6 6 10 10 10 14 14 14 18 18 18
54113- 18 18 18 14 14 14 10 10 10 6 6 6
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 0 0 0 0 0 0
54116- 0 0 0 0 0 0 0 0 0 0 0 0
54117- 0 0 0 0 0 0 0 0 0 0 0 0
54118- 0 0 0 0 0 0 0 0 0 6 6 6
54119- 14 14 14 18 18 18 22 22 22 22 22 22
54120- 18 18 18 14 14 14 10 10 10 6 6 6
54121- 0 0 0 0 0 0 0 0 0 0 0 0
54122- 0 0 0 0 0 0 0 0 0 0 0 0
54123- 0 0 0 0 0 0 0 0 0 0 0 0
54124- 0 0 0 0 0 0 0 0 0 0 0 0
54125- 0 0 0 0 0 0 0 0 0 0 0 0
54126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54139+4 4 4 4 4 4
54140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54153+4 4 4 4 4 4
54154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54167+4 4 4 4 4 4
54168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54181+4 4 4 4 4 4
54182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54195+4 4 4 4 4 4
54196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54209+4 4 4 4 4 4
54210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54214+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54215+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54220+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54221+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54223+4 4 4 4 4 4
54224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54228+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54229+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54230+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54233+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54234+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54235+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54236+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54237+4 4 4 4 4 4
54238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54242+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54243+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54244+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54247+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54248+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54249+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54250+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54251+4 4 4 4 4 4
54252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54255+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54256+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54257+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54258+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54260+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54261+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54262+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54263+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54264+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54265+4 4 4 4 4 4
54266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54269+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54270+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54271+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54272+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54273+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54274+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54275+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54276+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54277+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54278+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54279+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 5 5 5
54283+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54284+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54285+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54286+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54287+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54288+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54289+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54290+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54291+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54292+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54293+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 5 5 5 3 3 3
54297+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54298+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54299+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54300+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54301+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54302+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54303+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54304+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54305+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54306+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54307+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 2 2 2 0 0 0 4 0 0
54311+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54312+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54313+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54314+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54315+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54316+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54317+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54318+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54319+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54320+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54321+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54325+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54326+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54327+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54328+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54329+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54330+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54331+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54332+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54333+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54334+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54335+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54339+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54340+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54341+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54342+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54343+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54344+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54345+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54346+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54347+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54348+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54349+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 3 3 3 0 0 0
54352+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54353+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54354+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54355+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54356+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54357+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54358+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54359+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54360+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54361+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54362+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54363+4 4 4 4 4 4
54364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54365+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54366+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54367+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54368+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54369+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54370+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54371+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54372+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54373+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54374+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54375+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54376+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54377+0 0 0 4 4 4
54378+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54379+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54380+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54381+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54382+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54383+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54384+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54385+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54386+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54387+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54388+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54389+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54390+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54391+2 0 0 0 0 0
54392+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54393+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54394+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54395+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54396+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54397+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54398+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54399+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54400+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54401+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54402+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54403+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54404+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54405+37 38 37 0 0 0
54406+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54407+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54408+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54409+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54410+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54411+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54412+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54413+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54414+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54415+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54416+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54417+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54418+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54419+85 115 134 4 0 0
54420+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54421+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54422+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54423+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54424+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54425+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54426+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54427+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54428+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54429+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54430+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54431+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54432+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54433+60 73 81 4 0 0
54434+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54435+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54436+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54437+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54438+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54439+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54440+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54441+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54442+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54443+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54444+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54445+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54446+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54447+16 19 21 4 0 0
54448+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54449+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54450+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54451+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54452+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54453+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54454+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54455+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54456+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54457+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54458+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54459+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54460+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54461+4 0 0 4 3 3
54462+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54463+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54464+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54466+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54467+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54468+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54469+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54470+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54471+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54472+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54473+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54474+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54475+3 2 2 4 4 4
54476+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54477+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54478+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54479+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54480+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54481+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54482+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54483+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54484+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54485+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54486+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54487+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54488+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54489+4 4 4 4 4 4
54490+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54491+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54492+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54493+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54494+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54495+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54496+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54497+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54498+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54499+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54500+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54501+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54502+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54503+4 4 4 4 4 4
54504+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54505+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54506+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54507+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54508+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54509+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54510+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54511+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54512+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54513+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54514+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54515+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54516+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54517+5 5 5 5 5 5
54518+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54519+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54520+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54521+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54522+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54523+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54524+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54525+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54526+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54527+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54528+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54529+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54530+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54531+5 5 5 4 4 4
54532+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54533+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54534+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54535+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54536+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54537+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54538+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54539+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54540+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54541+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54542+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54543+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54545+4 4 4 4 4 4
54546+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54547+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54548+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54549+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54550+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54551+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54552+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54553+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54554+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54555+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54556+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54557+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54559+4 4 4 4 4 4
54560+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54561+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54562+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54563+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54564+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54565+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54566+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54567+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54568+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54569+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54570+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54573+4 4 4 4 4 4
54574+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54575+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54576+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54577+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54578+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54579+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54580+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54581+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54582+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54583+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54584+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54587+4 4 4 4 4 4
54588+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54589+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54590+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54591+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54592+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54593+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54594+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54595+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54596+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54597+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54598+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54601+4 4 4 4 4 4
54602+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54603+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54604+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54605+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54606+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54607+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54608+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54609+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54610+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54611+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54612+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54615+4 4 4 4 4 4
54616+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54617+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54618+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54619+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54620+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54621+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54622+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54623+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54624+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54625+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54626+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54629+4 4 4 4 4 4
54630+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54631+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54632+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54633+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54634+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54635+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54636+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54637+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54638+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54639+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54640+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54643+4 4 4 4 4 4
54644+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54645+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54646+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54647+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54648+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54649+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54650+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54651+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54652+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54653+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54654+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54657+4 4 4 4 4 4
54658+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54659+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54660+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54661+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54662+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54663+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54664+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54665+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54666+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54667+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54668+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671+4 4 4 4 4 4
54672+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54673+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54674+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54675+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54676+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54677+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54678+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54679+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54680+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54681+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54682+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685+4 4 4 4 4 4
54686+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54687+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54688+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54689+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54690+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54691+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54692+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54693+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54694+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54695+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54696+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699+4 4 4 4 4 4
54700+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54701+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54702+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54703+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54704+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54705+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54706+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54707+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54708+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54709+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54710+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713+4 4 4 4 4 4
54714+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54715+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54716+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54717+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54718+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54719+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54720+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54721+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54722+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54723+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54724+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727+4 4 4 4 4 4
54728+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54729+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54730+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54731+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54732+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54733+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54734+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54735+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54736+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54737+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54738+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741+4 4 4 4 4 4
54742+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54743+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54744+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54745+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54746+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54747+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54748+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54749+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54750+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54751+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54752+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4
54756+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54757+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54758+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54759+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54760+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54761+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54762+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54763+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54764+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54765+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54766+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769+4 4 4 4 4 4
54770+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54771+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54772+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54773+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54774+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54775+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54776+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54777+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54778+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54779+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54780+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4
54784+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54785+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54786+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54787+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54788+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54789+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54790+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54791+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54792+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54793+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54794+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4
54798+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54799+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54800+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54801+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54802+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54803+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54804+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54805+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54806+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54807+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54808+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811+4 4 4 4 4 4
54812+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54813+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54814+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54815+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54816+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54817+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54818+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54819+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54820+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54821+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54822+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825+4 4 4 4 4 4
54826+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54827+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54828+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54829+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54830+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54831+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54832+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54833+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54834+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54835+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54836+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839+4 4 4 4 4 4
54840+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54841+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54842+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54843+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54844+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54845+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54846+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54847+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54848+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54849+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54850+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54853+4 4 4 4 4 4
54854+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54855+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54856+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54857+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54858+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54859+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54860+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54861+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54862+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54863+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54864+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54867+4 4 4 4 4 4
54868+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54869+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54870+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54871+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54872+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54873+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54874+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54875+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54876+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54877+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54878+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54881+4 4 4 4 4 4
54882+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54883+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54884+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54885+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54886+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54887+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54888+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54889+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54890+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54891+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54892+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54895+4 4 4 4 4 4
54896+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54897+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54898+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54899+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54900+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54901+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54902+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54903+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54904+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54905+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54906+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54909+4 4 4 4 4 4
54910+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54911+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54912+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54913+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54914+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54915+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54916+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54918+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54919+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54920+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923+4 4 4 4 4 4
54924+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54925+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54926+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54927+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54928+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54929+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54930+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54931+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54932+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54933+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54934+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937+4 4 4 4 4 4
54938+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54939+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54940+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54941+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54942+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54943+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54944+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54945+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54946+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54947+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951+4 4 4 4 4 4
54952+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54953+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54954+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54955+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54956+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54957+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54958+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54959+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54960+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54961+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965+4 4 4 4 4 4
54966+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54967+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54968+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54969+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54970+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54971+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54972+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54973+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54974+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54975+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979+4 4 4 4 4 4
54980+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54981+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54982+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54983+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54984+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54985+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54986+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54987+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54988+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54989+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993+4 4 4 4 4 4
54994+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54995+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54996+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54997+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54998+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54999+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55000+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55001+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55002+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55007+4 4 4 4 4 4
55008+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55009+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55010+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55011+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55012+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55013+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55014+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55015+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55016+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55021+4 4 4 4 4 4
55022+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55023+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55024+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55025+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55026+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55027+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55028+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55029+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55030+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55035+4 4 4 4 4 4
55036+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55037+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55038+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55039+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55040+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55041+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55042+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55043+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55049+4 4 4 4 4 4
55050+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55051+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55052+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55053+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55054+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55055+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55056+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55057+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55063+4 4 4 4 4 4
55064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55065+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55066+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55067+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55068+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55069+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55070+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55071+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55077+4 4 4 4 4 4
55078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55079+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55080+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55081+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55082+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55083+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55084+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55085+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55091+4 4 4 4 4 4
55092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55093+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55094+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55095+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55096+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55097+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55098+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55099+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55105+4 4 4 4 4 4
55106+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55109+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55110+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55111+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55112+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55113+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119+4 4 4 4 4 4
55120+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
55123+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55124+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55125+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55126+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55133+4 4 4 4 4 4
55134+4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55138+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55139+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55140+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55147+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
55152+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55153+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55154+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55161+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 5 5 5 4 3 3 5 5 5
55166+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55167+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55168+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175+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 5 5 5
55180+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55181+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55182+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189+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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55195+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55196+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203+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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55209+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55210+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217+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 4 4 4 5 5 5 4 3 3 6 6 6
55223+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231+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 4 4 4 4 4 4 5 5 5 4 3 3
55237+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4
55246diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55247index a01147f..5d896f8 100644
55248--- a/drivers/video/matrox/matroxfb_DAC1064.c
55249+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55250@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55251
55252 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55253 struct matrox_switch matrox_mystique = {
55254- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55255+ .preinit = MGA1064_preinit,
55256+ .reset = MGA1064_reset,
55257+ .init = MGA1064_init,
55258+ .restore = MGA1064_restore,
55259 };
55260 EXPORT_SYMBOL(matrox_mystique);
55261 #endif
55262
55263 #ifdef CONFIG_FB_MATROX_G
55264 struct matrox_switch matrox_G100 = {
55265- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55266+ .preinit = MGAG100_preinit,
55267+ .reset = MGAG100_reset,
55268+ .init = MGAG100_init,
55269+ .restore = MGAG100_restore,
55270 };
55271 EXPORT_SYMBOL(matrox_G100);
55272 #endif
55273diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55274index 195ad7c..09743fc 100644
55275--- a/drivers/video/matrox/matroxfb_Ti3026.c
55276+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55277@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55278 }
55279
55280 struct matrox_switch matrox_millennium = {
55281- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55282+ .preinit = Ti3026_preinit,
55283+ .reset = Ti3026_reset,
55284+ .init = Ti3026_init,
55285+ .restore = Ti3026_restore
55286 };
55287 EXPORT_SYMBOL(matrox_millennium);
55288 #endif
55289diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55290index fe92eed..106e085 100644
55291--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55292+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55293@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55294 struct mb862xxfb_par *par = info->par;
55295
55296 if (info->var.bits_per_pixel == 32) {
55297- info->fbops->fb_fillrect = cfb_fillrect;
55298- info->fbops->fb_copyarea = cfb_copyarea;
55299- info->fbops->fb_imageblit = cfb_imageblit;
55300+ pax_open_kernel();
55301+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55302+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55303+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55304+ pax_close_kernel();
55305 } else {
55306 outreg(disp, GC_L0EM, 3);
55307- info->fbops->fb_fillrect = mb86290fb_fillrect;
55308- info->fbops->fb_copyarea = mb86290fb_copyarea;
55309- info->fbops->fb_imageblit = mb86290fb_imageblit;
55310+ pax_open_kernel();
55311+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55312+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55313+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55314+ pax_close_kernel();
55315 }
55316 outreg(draw, GDC_REG_DRAW_BASE, 0);
55317 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55318diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55319index def0412..fed6529 100644
55320--- a/drivers/video/nvidia/nvidia.c
55321+++ b/drivers/video/nvidia/nvidia.c
55322@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55323 info->fix.line_length = (info->var.xres_virtual *
55324 info->var.bits_per_pixel) >> 3;
55325 if (info->var.accel_flags) {
55326- info->fbops->fb_imageblit = nvidiafb_imageblit;
55327- info->fbops->fb_fillrect = nvidiafb_fillrect;
55328- info->fbops->fb_copyarea = nvidiafb_copyarea;
55329- info->fbops->fb_sync = nvidiafb_sync;
55330+ pax_open_kernel();
55331+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55332+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55333+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55334+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55335+ pax_close_kernel();
55336 info->pixmap.scan_align = 4;
55337 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55338 info->flags |= FBINFO_READS_FAST;
55339 NVResetGraphics(info);
55340 } else {
55341- info->fbops->fb_imageblit = cfb_imageblit;
55342- info->fbops->fb_fillrect = cfb_fillrect;
55343- info->fbops->fb_copyarea = cfb_copyarea;
55344- info->fbops->fb_sync = NULL;
55345+ pax_open_kernel();
55346+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55347+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55348+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55349+ *(void **)&info->fbops->fb_sync = NULL;
55350+ pax_close_kernel();
55351 info->pixmap.scan_align = 1;
55352 info->flags |= FBINFO_HWACCEL_DISABLED;
55353 info->flags &= ~FBINFO_READS_FAST;
55354@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55355 info->pixmap.size = 8 * 1024;
55356 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55357
55358- if (!hwcur)
55359- info->fbops->fb_cursor = NULL;
55360+ if (!hwcur) {
55361+ pax_open_kernel();
55362+ *(void **)&info->fbops->fb_cursor = NULL;
55363+ pax_close_kernel();
55364+ }
55365
55366 info->var.accel_flags = (!noaccel);
55367
55368diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55369index 669a81f..e216d76 100644
55370--- a/drivers/video/omap2/dss/display.c
55371+++ b/drivers/video/omap2/dss/display.c
55372@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55373 snprintf(dssdev->alias, sizeof(dssdev->alias),
55374 "display%d", disp_num_counter++);
55375
55376+ pax_open_kernel();
55377 if (drv && drv->get_resolution == NULL)
55378- drv->get_resolution = omapdss_default_get_resolution;
55379+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55380 if (drv && drv->get_recommended_bpp == NULL)
55381- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55382+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55383 if (drv && drv->get_timings == NULL)
55384- drv->get_timings = omapdss_default_get_timings;
55385+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55386+ pax_close_kernel();
55387
55388 mutex_lock(&panel_list_mutex);
55389 list_add_tail(&dssdev->panel_list, &panel_list);
55390diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55391index 83433cb..71e9b98 100644
55392--- a/drivers/video/s1d13xxxfb.c
55393+++ b/drivers/video/s1d13xxxfb.c
55394@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55395
55396 switch(prod_id) {
55397 case S1D13506_PROD_ID: /* activate acceleration */
55398- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55399- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55400+ pax_open_kernel();
55401+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55402+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55403+ pax_close_kernel();
55404 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55405 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55406 break;
55407diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55408index 2bcc84a..29dd1ea 100644
55409--- a/drivers/video/sh_mobile_lcdcfb.c
55410+++ b/drivers/video/sh_mobile_lcdcfb.c
55411@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55412 }
55413
55414 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55415- lcdc_sys_write_index,
55416- lcdc_sys_write_data,
55417- lcdc_sys_read_data,
55418+ .write_index = lcdc_sys_write_index,
55419+ .write_data = lcdc_sys_write_data,
55420+ .read_data = lcdc_sys_read_data,
55421 };
55422
55423 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55424diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55425index d513ed6..90b0de9 100644
55426--- a/drivers/video/smscufx.c
55427+++ b/drivers/video/smscufx.c
55428@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55429 fb_deferred_io_cleanup(info);
55430 kfree(info->fbdefio);
55431 info->fbdefio = NULL;
55432- info->fbops->fb_mmap = ufx_ops_mmap;
55433+ pax_open_kernel();
55434+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55435+ pax_close_kernel();
55436 }
55437
55438 pr_debug("released /dev/fb%d user=%d count=%d",
55439diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55440index 77b890e..458e666 100644
55441--- a/drivers/video/udlfb.c
55442+++ b/drivers/video/udlfb.c
55443@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55444 dlfb_urb_completion(urb);
55445
55446 error:
55447- atomic_add(bytes_sent, &dev->bytes_sent);
55448- atomic_add(bytes_identical, &dev->bytes_identical);
55449- atomic_add(width*height*2, &dev->bytes_rendered);
55450+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55451+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55452+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55453 end_cycles = get_cycles();
55454- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55455+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55456 >> 10)), /* Kcycles */
55457 &dev->cpu_kcycles_used);
55458
55459@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55460 dlfb_urb_completion(urb);
55461
55462 error:
55463- atomic_add(bytes_sent, &dev->bytes_sent);
55464- atomic_add(bytes_identical, &dev->bytes_identical);
55465- atomic_add(bytes_rendered, &dev->bytes_rendered);
55466+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55467+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55468+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55469 end_cycles = get_cycles();
55470- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55471+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55472 >> 10)), /* Kcycles */
55473 &dev->cpu_kcycles_used);
55474 }
55475@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55476 fb_deferred_io_cleanup(info);
55477 kfree(info->fbdefio);
55478 info->fbdefio = NULL;
55479- info->fbops->fb_mmap = dlfb_ops_mmap;
55480+ pax_open_kernel();
55481+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55482+ pax_close_kernel();
55483 }
55484
55485 pr_warn("released /dev/fb%d user=%d count=%d\n",
55486@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55487 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55488 struct dlfb_data *dev = fb_info->par;
55489 return snprintf(buf, PAGE_SIZE, "%u\n",
55490- atomic_read(&dev->bytes_rendered));
55491+ atomic_read_unchecked(&dev->bytes_rendered));
55492 }
55493
55494 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55495@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55496 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55497 struct dlfb_data *dev = fb_info->par;
55498 return snprintf(buf, PAGE_SIZE, "%u\n",
55499- atomic_read(&dev->bytes_identical));
55500+ atomic_read_unchecked(&dev->bytes_identical));
55501 }
55502
55503 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55504@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55505 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55506 struct dlfb_data *dev = fb_info->par;
55507 return snprintf(buf, PAGE_SIZE, "%u\n",
55508- atomic_read(&dev->bytes_sent));
55509+ atomic_read_unchecked(&dev->bytes_sent));
55510 }
55511
55512 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55513@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55514 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55515 struct dlfb_data *dev = fb_info->par;
55516 return snprintf(buf, PAGE_SIZE, "%u\n",
55517- atomic_read(&dev->cpu_kcycles_used));
55518+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55519 }
55520
55521 static ssize_t edid_show(
55522@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55523 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55524 struct dlfb_data *dev = fb_info->par;
55525
55526- atomic_set(&dev->bytes_rendered, 0);
55527- atomic_set(&dev->bytes_identical, 0);
55528- atomic_set(&dev->bytes_sent, 0);
55529- atomic_set(&dev->cpu_kcycles_used, 0);
55530+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55531+ atomic_set_unchecked(&dev->bytes_identical, 0);
55532+ atomic_set_unchecked(&dev->bytes_sent, 0);
55533+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55534
55535 return count;
55536 }
55537diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55538index 256fba7..6e75516 100644
55539--- a/drivers/video/uvesafb.c
55540+++ b/drivers/video/uvesafb.c
55541@@ -19,6 +19,7 @@
55542 #include <linux/io.h>
55543 #include <linux/mutex.h>
55544 #include <linux/slab.h>
55545+#include <linux/moduleloader.h>
55546 #include <video/edid.h>
55547 #include <video/uvesafb.h>
55548 #ifdef CONFIG_X86
55549@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55550 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55551 par->pmi_setpal = par->ypan = 0;
55552 } else {
55553+
55554+#ifdef CONFIG_PAX_KERNEXEC
55555+#ifdef CONFIG_MODULES
55556+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55557+#endif
55558+ if (!par->pmi_code) {
55559+ par->pmi_setpal = par->ypan = 0;
55560+ return 0;
55561+ }
55562+#endif
55563+
55564 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55565 + task->t.regs.edi);
55566+
55567+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55568+ pax_open_kernel();
55569+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55570+ pax_close_kernel();
55571+
55572+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55573+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55574+#else
55575 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55576 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55577+#endif
55578+
55579 printk(KERN_INFO "uvesafb: protected mode interface info at "
55580 "%04x:%04x\n",
55581 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55582@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55583 par->ypan = ypan;
55584
55585 if (par->pmi_setpal || par->ypan) {
55586+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55587 if (__supported_pte_mask & _PAGE_NX) {
55588 par->pmi_setpal = par->ypan = 0;
55589 printk(KERN_WARNING "uvesafb: NX protection is active, "
55590 "better not use the PMI.\n");
55591- } else {
55592+ } else
55593+#endif
55594 uvesafb_vbe_getpmi(task, par);
55595- }
55596 }
55597 #else
55598 /* The protected mode interface is not available on non-x86. */
55599@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55600 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55601
55602 /* Disable blanking if the user requested so. */
55603- if (!blank)
55604- info->fbops->fb_blank = NULL;
55605+ if (!blank) {
55606+ pax_open_kernel();
55607+ *(void **)&info->fbops->fb_blank = NULL;
55608+ pax_close_kernel();
55609+ }
55610
55611 /*
55612 * Find out how much IO memory is required for the mode with
55613@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55614 info->flags = FBINFO_FLAG_DEFAULT |
55615 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55616
55617- if (!par->ypan)
55618- info->fbops->fb_pan_display = NULL;
55619+ if (!par->ypan) {
55620+ pax_open_kernel();
55621+ *(void **)&info->fbops->fb_pan_display = NULL;
55622+ pax_close_kernel();
55623+ }
55624 }
55625
55626 static void uvesafb_init_mtrr(struct fb_info *info)
55627@@ -1792,6 +1822,11 @@ out_mode:
55628 out:
55629 kfree(par->vbe_modes);
55630
55631+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55632+ if (par->pmi_code)
55633+ module_free_exec(NULL, par->pmi_code);
55634+#endif
55635+
55636 framebuffer_release(info);
55637 return err;
55638 }
55639@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55640 kfree(par->vbe_modes);
55641 kfree(par->vbe_state_orig);
55642 kfree(par->vbe_state_saved);
55643+
55644+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55645+ if (par->pmi_code)
55646+ module_free_exec(NULL, par->pmi_code);
55647+#endif
55648+
55649 }
55650
55651 framebuffer_release(info);
55652diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55653index 1c7da3b..56ea0bd 100644
55654--- a/drivers/video/vesafb.c
55655+++ b/drivers/video/vesafb.c
55656@@ -9,6 +9,7 @@
55657 */
55658
55659 #include <linux/module.h>
55660+#include <linux/moduleloader.h>
55661 #include <linux/kernel.h>
55662 #include <linux/errno.h>
55663 #include <linux/string.h>
55664@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55665 static int vram_total; /* Set total amount of memory */
55666 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55667 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55668-static void (*pmi_start)(void) __read_mostly;
55669-static void (*pmi_pal) (void) __read_mostly;
55670+static void (*pmi_start)(void) __read_only;
55671+static void (*pmi_pal) (void) __read_only;
55672 static int depth __read_mostly;
55673 static int vga_compat __read_mostly;
55674 /* --------------------------------------------------------------------- */
55675@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55676 unsigned int size_remap;
55677 unsigned int size_total;
55678 char *option = NULL;
55679+ void *pmi_code = NULL;
55680
55681 /* ignore error return of fb_get_options */
55682 fb_get_options("vesafb", &option);
55683@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55684 size_remap = size_total;
55685 vesafb_fix.smem_len = size_remap;
55686
55687-#ifndef __i386__
55688- screen_info.vesapm_seg = 0;
55689-#endif
55690-
55691 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55692 printk(KERN_WARNING
55693 "vesafb: cannot reserve video memory at 0x%lx\n",
55694@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55695 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55696 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55697
55698+#ifdef __i386__
55699+
55700+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55701+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55702+ if (!pmi_code)
55703+#elif !defined(CONFIG_PAX_KERNEXEC)
55704+ if (0)
55705+#endif
55706+
55707+#endif
55708+ screen_info.vesapm_seg = 0;
55709+
55710 if (screen_info.vesapm_seg) {
55711- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55712- screen_info.vesapm_seg,screen_info.vesapm_off);
55713+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55714+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55715 }
55716
55717 if (screen_info.vesapm_seg < 0xc000)
55718@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55719
55720 if (ypan || pmi_setpal) {
55721 unsigned short *pmi_base;
55722+
55723 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55724- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55725- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55726+
55727+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55728+ pax_open_kernel();
55729+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55730+#else
55731+ pmi_code = pmi_base;
55732+#endif
55733+
55734+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55735+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55736+
55737+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55738+ pmi_start = ktva_ktla(pmi_start);
55739+ pmi_pal = ktva_ktla(pmi_pal);
55740+ pax_close_kernel();
55741+#endif
55742+
55743 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55744 if (pmi_base[3]) {
55745 printk(KERN_INFO "vesafb: pmi: ports = ");
55746@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55747 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55748 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55749
55750- if (!ypan)
55751- info->fbops->fb_pan_display = NULL;
55752+ if (!ypan) {
55753+ pax_open_kernel();
55754+ *(void **)&info->fbops->fb_pan_display = NULL;
55755+ pax_close_kernel();
55756+ }
55757
55758 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55759 err = -ENOMEM;
55760@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55761 fb_info(info, "%s frame buffer device\n", info->fix.id);
55762 return 0;
55763 err:
55764+
55765+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55766+ module_free_exec(NULL, pmi_code);
55767+#endif
55768+
55769 if (info->screen_base)
55770 iounmap(info->screen_base);
55771 framebuffer_release(info);
55772diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55773index 88714ae..16c2e11 100644
55774--- a/drivers/video/via/via_clock.h
55775+++ b/drivers/video/via/via_clock.h
55776@@ -56,7 +56,7 @@ struct via_clock {
55777
55778 void (*set_engine_pll_state)(u8 state);
55779 void (*set_engine_pll)(struct via_pll_config config);
55780-};
55781+} __no_const;
55782
55783
55784 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55785diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55786index fef20db..d28b1ab 100644
55787--- a/drivers/xen/xenfs/xenstored.c
55788+++ b/drivers/xen/xenfs/xenstored.c
55789@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55790 static int xsd_kva_open(struct inode *inode, struct file *file)
55791 {
55792 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55793+#ifdef CONFIG_GRKERNSEC_HIDESYM
55794+ NULL);
55795+#else
55796 xen_store_interface);
55797+#endif
55798+
55799 if (!file->private_data)
55800 return -ENOMEM;
55801 return 0;
55802diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55803index c71e886..61d3d44b 100644
55804--- a/fs/9p/vfs_addr.c
55805+++ b/fs/9p/vfs_addr.c
55806@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55807
55808 retval = v9fs_file_write_internal(inode,
55809 v9inode->writeback_fid,
55810- (__force const char __user *)buffer,
55811+ (const char __force_user *)buffer,
55812 len, &offset, 0);
55813 if (retval > 0)
55814 retval = 0;
55815diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55816index bb7991c..481e21a 100644
55817--- a/fs/9p/vfs_inode.c
55818+++ b/fs/9p/vfs_inode.c
55819@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55820 void
55821 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55822 {
55823- char *s = nd_get_link(nd);
55824+ const char *s = nd_get_link(nd);
55825
55826 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55827 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55828diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55829index 370b24c..ff0be7b 100644
55830--- a/fs/Kconfig.binfmt
55831+++ b/fs/Kconfig.binfmt
55832@@ -103,7 +103,7 @@ config HAVE_AOUT
55833
55834 config BINFMT_AOUT
55835 tristate "Kernel support for a.out and ECOFF binaries"
55836- depends on HAVE_AOUT
55837+ depends on HAVE_AOUT && BROKEN
55838 ---help---
55839 A.out (Assembler.OUTput) is a set of formats for libraries and
55840 executables used in the earliest versions of UNIX. Linux used
55841diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55842index ce25d75..dc09eeb 100644
55843--- a/fs/afs/inode.c
55844+++ b/fs/afs/inode.c
55845@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55846 struct afs_vnode *vnode;
55847 struct super_block *sb;
55848 struct inode *inode;
55849- static atomic_t afs_autocell_ino;
55850+ static atomic_unchecked_t afs_autocell_ino;
55851
55852 _enter("{%x:%u},%*.*s,",
55853 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55854@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55855 data.fid.unique = 0;
55856 data.fid.vnode = 0;
55857
55858- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55859+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55860 afs_iget5_autocell_test, afs_iget5_set,
55861 &data);
55862 if (!inode) {
55863diff --git a/fs/aio.c b/fs/aio.c
55864index 062a5f6..e5618e0 100644
55865--- a/fs/aio.c
55866+++ b/fs/aio.c
55867@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55868 size += sizeof(struct io_event) * nr_events;
55869
55870 nr_pages = PFN_UP(size);
55871- if (nr_pages < 0)
55872+ if (nr_pages <= 0)
55873 return -EINVAL;
55874
55875 file = aio_private_file(ctx, nr_pages);
55876diff --git a/fs/attr.c b/fs/attr.c
55877index 5d4e59d..fd02418 100644
55878--- a/fs/attr.c
55879+++ b/fs/attr.c
55880@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55881 unsigned long limit;
55882
55883 limit = rlimit(RLIMIT_FSIZE);
55884+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55885 if (limit != RLIM_INFINITY && offset > limit)
55886 goto out_sig;
55887 if (offset > inode->i_sb->s_maxbytes)
55888diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55889index 116fd38..c04182da 100644
55890--- a/fs/autofs4/waitq.c
55891+++ b/fs/autofs4/waitq.c
55892@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55893 {
55894 unsigned long sigpipe, flags;
55895 mm_segment_t fs;
55896- const char *data = (const char *)addr;
55897+ const char __user *data = (const char __force_user *)addr;
55898 ssize_t wr = 0;
55899
55900 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55901@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55902 return 1;
55903 }
55904
55905+#ifdef CONFIG_GRKERNSEC_HIDESYM
55906+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55907+#endif
55908+
55909 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55910 enum autofs_notify notify)
55911 {
55912@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55913
55914 /* If this is a direct mount request create a dummy name */
55915 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55916+#ifdef CONFIG_GRKERNSEC_HIDESYM
55917+ /* this name does get written to userland via autofs4_write() */
55918+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55919+#else
55920 qstr.len = sprintf(name, "%p", dentry);
55921+#endif
55922 else {
55923 qstr.len = autofs4_getpath(sbi, dentry, &name);
55924 if (!qstr.len) {
55925diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55926index 2722387..56059b5 100644
55927--- a/fs/befs/endian.h
55928+++ b/fs/befs/endian.h
55929@@ -11,7 +11,7 @@
55930
55931 #include <asm/byteorder.h>
55932
55933-static inline u64
55934+static inline u64 __intentional_overflow(-1)
55935 fs64_to_cpu(const struct super_block *sb, fs64 n)
55936 {
55937 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55938@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55939 return (__force fs64)cpu_to_be64(n);
55940 }
55941
55942-static inline u32
55943+static inline u32 __intentional_overflow(-1)
55944 fs32_to_cpu(const struct super_block *sb, fs32 n)
55945 {
55946 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55947@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55948 return (__force fs32)cpu_to_be32(n);
55949 }
55950
55951-static inline u16
55952+static inline u16 __intentional_overflow(-1)
55953 fs16_to_cpu(const struct super_block *sb, fs16 n)
55954 {
55955 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55956diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55957index ca0ba15..0fa3257 100644
55958--- a/fs/binfmt_aout.c
55959+++ b/fs/binfmt_aout.c
55960@@ -16,6 +16,7 @@
55961 #include <linux/string.h>
55962 #include <linux/fs.h>
55963 #include <linux/file.h>
55964+#include <linux/security.h>
55965 #include <linux/stat.h>
55966 #include <linux/fcntl.h>
55967 #include <linux/ptrace.h>
55968@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55969 #endif
55970 # define START_STACK(u) ((void __user *)u.start_stack)
55971
55972+ memset(&dump, 0, sizeof(dump));
55973+
55974 fs = get_fs();
55975 set_fs(KERNEL_DS);
55976 has_dumped = 1;
55977@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55978
55979 /* If the size of the dump file exceeds the rlimit, then see what would happen
55980 if we wrote the stack, but not the data area. */
55981+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55982 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55983 dump.u_dsize = 0;
55984
55985 /* Make sure we have enough room to write the stack and data areas. */
55986+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55987 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55988 dump.u_ssize = 0;
55989
55990@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55991 rlim = rlimit(RLIMIT_DATA);
55992 if (rlim >= RLIM_INFINITY)
55993 rlim = ~0;
55994+
55995+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55996 if (ex.a_data + ex.a_bss > rlim)
55997 return -ENOMEM;
55998
55999@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56000
56001 install_exec_creds(bprm);
56002
56003+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56004+ current->mm->pax_flags = 0UL;
56005+#endif
56006+
56007+#ifdef CONFIG_PAX_PAGEEXEC
56008+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56009+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56010+
56011+#ifdef CONFIG_PAX_EMUTRAMP
56012+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56013+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56014+#endif
56015+
56016+#ifdef CONFIG_PAX_MPROTECT
56017+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56018+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56019+#endif
56020+
56021+ }
56022+#endif
56023+
56024 if (N_MAGIC(ex) == OMAGIC) {
56025 unsigned long text_addr, map_size;
56026 loff_t pos;
56027@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56028 }
56029
56030 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56031- PROT_READ | PROT_WRITE | PROT_EXEC,
56032+ PROT_READ | PROT_WRITE,
56033 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56034 fd_offset + ex.a_text);
56035 if (error != N_DATADDR(ex)) {
56036diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56037index 67be295..83e2f86 100644
56038--- a/fs/binfmt_elf.c
56039+++ b/fs/binfmt_elf.c
56040@@ -34,6 +34,7 @@
56041 #include <linux/utsname.h>
56042 #include <linux/coredump.h>
56043 #include <linux/sched.h>
56044+#include <linux/xattr.h>
56045 #include <asm/uaccess.h>
56046 #include <asm/param.h>
56047 #include <asm/page.h>
56048@@ -48,7 +49,7 @@
56049 static int load_elf_binary(struct linux_binprm *bprm);
56050 static int load_elf_library(struct file *);
56051 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56052- int, int, unsigned long);
56053+ int, int, unsigned long) __intentional_overflow(-1);
56054
56055 /*
56056 * If we don't support core dumping, then supply a NULL so we
56057@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56058 #define elf_core_dump NULL
56059 #endif
56060
56061+#ifdef CONFIG_PAX_MPROTECT
56062+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56063+#endif
56064+
56065+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56066+static void elf_handle_mmap(struct file *file);
56067+#endif
56068+
56069 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56070 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56071 #else
56072@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56073 .load_binary = load_elf_binary,
56074 .load_shlib = load_elf_library,
56075 .core_dump = elf_core_dump,
56076+
56077+#ifdef CONFIG_PAX_MPROTECT
56078+ .handle_mprotect= elf_handle_mprotect,
56079+#endif
56080+
56081+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56082+ .handle_mmap = elf_handle_mmap,
56083+#endif
56084+
56085 .min_coredump = ELF_EXEC_PAGESIZE,
56086 };
56087
56088@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56089
56090 static int set_brk(unsigned long start, unsigned long end)
56091 {
56092+ unsigned long e = end;
56093+
56094 start = ELF_PAGEALIGN(start);
56095 end = ELF_PAGEALIGN(end);
56096 if (end > start) {
56097@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56098 if (BAD_ADDR(addr))
56099 return addr;
56100 }
56101- current->mm->start_brk = current->mm->brk = end;
56102+ current->mm->start_brk = current->mm->brk = e;
56103 return 0;
56104 }
56105
56106@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56107 elf_addr_t __user *u_rand_bytes;
56108 const char *k_platform = ELF_PLATFORM;
56109 const char *k_base_platform = ELF_BASE_PLATFORM;
56110- unsigned char k_rand_bytes[16];
56111+ u32 k_rand_bytes[4];
56112 int items;
56113 elf_addr_t *elf_info;
56114 int ei_index = 0;
56115 const struct cred *cred = current_cred();
56116 struct vm_area_struct *vma;
56117+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56118
56119 /*
56120 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56121@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56122 * Generate 16 random bytes for userspace PRNG seeding.
56123 */
56124 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56125- u_rand_bytes = (elf_addr_t __user *)
56126- STACK_ALLOC(p, sizeof(k_rand_bytes));
56127+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56128+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56129+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56130+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56131+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56132+ u_rand_bytes = (elf_addr_t __user *) p;
56133 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56134 return -EFAULT;
56135
56136@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56137 return -EFAULT;
56138 current->mm->env_end = p;
56139
56140+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56141+
56142 /* Put the elf_info on the stack in the right place. */
56143 sp = (elf_addr_t __user *)envp + 1;
56144- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56145+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56146 return -EFAULT;
56147 return 0;
56148 }
56149@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56150 an ELF header */
56151
56152 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56153- struct file *interpreter, unsigned long *interp_map_addr,
56154- unsigned long no_base)
56155+ struct file *interpreter, unsigned long no_base)
56156 {
56157 struct elf_phdr *elf_phdata;
56158 struct elf_phdr *eppnt;
56159- unsigned long load_addr = 0;
56160+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56161 int load_addr_set = 0;
56162 unsigned long last_bss = 0, elf_bss = 0;
56163- unsigned long error = ~0UL;
56164+ unsigned long error = -EINVAL;
56165 unsigned long total_size;
56166 int retval, i, size;
56167
56168@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56169 goto out_close;
56170 }
56171
56172+#ifdef CONFIG_PAX_SEGMEXEC
56173+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56174+ pax_task_size = SEGMEXEC_TASK_SIZE;
56175+#endif
56176+
56177 eppnt = elf_phdata;
56178 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56179 if (eppnt->p_type == PT_LOAD) {
56180@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56181 map_addr = elf_map(interpreter, load_addr + vaddr,
56182 eppnt, elf_prot, elf_type, total_size);
56183 total_size = 0;
56184- if (!*interp_map_addr)
56185- *interp_map_addr = map_addr;
56186 error = map_addr;
56187 if (BAD_ADDR(map_addr))
56188 goto out_close;
56189@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56190 k = load_addr + eppnt->p_vaddr;
56191 if (BAD_ADDR(k) ||
56192 eppnt->p_filesz > eppnt->p_memsz ||
56193- eppnt->p_memsz > TASK_SIZE ||
56194- TASK_SIZE - eppnt->p_memsz < k) {
56195+ eppnt->p_memsz > pax_task_size ||
56196+ pax_task_size - eppnt->p_memsz < k) {
56197 error = -ENOMEM;
56198 goto out_close;
56199 }
56200@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56201 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56202
56203 /* Map the last of the bss segment */
56204- error = vm_brk(elf_bss, last_bss - elf_bss);
56205- if (BAD_ADDR(error))
56206- goto out_close;
56207+ if (last_bss > elf_bss) {
56208+ error = vm_brk(elf_bss, last_bss - elf_bss);
56209+ if (BAD_ADDR(error))
56210+ goto out_close;
56211+ }
56212 }
56213
56214 error = load_addr;
56215@@ -538,6 +569,336 @@ out:
56216 return error;
56217 }
56218
56219+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56220+#ifdef CONFIG_PAX_SOFTMODE
56221+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56222+{
56223+ unsigned long pax_flags = 0UL;
56224+
56225+#ifdef CONFIG_PAX_PAGEEXEC
56226+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56227+ pax_flags |= MF_PAX_PAGEEXEC;
56228+#endif
56229+
56230+#ifdef CONFIG_PAX_SEGMEXEC
56231+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56232+ pax_flags |= MF_PAX_SEGMEXEC;
56233+#endif
56234+
56235+#ifdef CONFIG_PAX_EMUTRAMP
56236+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56237+ pax_flags |= MF_PAX_EMUTRAMP;
56238+#endif
56239+
56240+#ifdef CONFIG_PAX_MPROTECT
56241+ if (elf_phdata->p_flags & PF_MPROTECT)
56242+ pax_flags |= MF_PAX_MPROTECT;
56243+#endif
56244+
56245+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56246+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56247+ pax_flags |= MF_PAX_RANDMMAP;
56248+#endif
56249+
56250+ return pax_flags;
56251+}
56252+#endif
56253+
56254+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56255+{
56256+ unsigned long pax_flags = 0UL;
56257+
56258+#ifdef CONFIG_PAX_PAGEEXEC
56259+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56260+ pax_flags |= MF_PAX_PAGEEXEC;
56261+#endif
56262+
56263+#ifdef CONFIG_PAX_SEGMEXEC
56264+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56265+ pax_flags |= MF_PAX_SEGMEXEC;
56266+#endif
56267+
56268+#ifdef CONFIG_PAX_EMUTRAMP
56269+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56270+ pax_flags |= MF_PAX_EMUTRAMP;
56271+#endif
56272+
56273+#ifdef CONFIG_PAX_MPROTECT
56274+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56275+ pax_flags |= MF_PAX_MPROTECT;
56276+#endif
56277+
56278+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56279+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56280+ pax_flags |= MF_PAX_RANDMMAP;
56281+#endif
56282+
56283+ return pax_flags;
56284+}
56285+#endif
56286+
56287+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56288+#ifdef CONFIG_PAX_SOFTMODE
56289+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56290+{
56291+ unsigned long pax_flags = 0UL;
56292+
56293+#ifdef CONFIG_PAX_PAGEEXEC
56294+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56295+ pax_flags |= MF_PAX_PAGEEXEC;
56296+#endif
56297+
56298+#ifdef CONFIG_PAX_SEGMEXEC
56299+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56300+ pax_flags |= MF_PAX_SEGMEXEC;
56301+#endif
56302+
56303+#ifdef CONFIG_PAX_EMUTRAMP
56304+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56305+ pax_flags |= MF_PAX_EMUTRAMP;
56306+#endif
56307+
56308+#ifdef CONFIG_PAX_MPROTECT
56309+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56310+ pax_flags |= MF_PAX_MPROTECT;
56311+#endif
56312+
56313+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56314+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56315+ pax_flags |= MF_PAX_RANDMMAP;
56316+#endif
56317+
56318+ return pax_flags;
56319+}
56320+#endif
56321+
56322+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56323+{
56324+ unsigned long pax_flags = 0UL;
56325+
56326+#ifdef CONFIG_PAX_PAGEEXEC
56327+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56328+ pax_flags |= MF_PAX_PAGEEXEC;
56329+#endif
56330+
56331+#ifdef CONFIG_PAX_SEGMEXEC
56332+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56333+ pax_flags |= MF_PAX_SEGMEXEC;
56334+#endif
56335+
56336+#ifdef CONFIG_PAX_EMUTRAMP
56337+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56338+ pax_flags |= MF_PAX_EMUTRAMP;
56339+#endif
56340+
56341+#ifdef CONFIG_PAX_MPROTECT
56342+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56343+ pax_flags |= MF_PAX_MPROTECT;
56344+#endif
56345+
56346+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56347+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56348+ pax_flags |= MF_PAX_RANDMMAP;
56349+#endif
56350+
56351+ return pax_flags;
56352+}
56353+#endif
56354+
56355+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56356+static unsigned long pax_parse_defaults(void)
56357+{
56358+ unsigned long pax_flags = 0UL;
56359+
56360+#ifdef CONFIG_PAX_SOFTMODE
56361+ if (pax_softmode)
56362+ return pax_flags;
56363+#endif
56364+
56365+#ifdef CONFIG_PAX_PAGEEXEC
56366+ pax_flags |= MF_PAX_PAGEEXEC;
56367+#endif
56368+
56369+#ifdef CONFIG_PAX_SEGMEXEC
56370+ pax_flags |= MF_PAX_SEGMEXEC;
56371+#endif
56372+
56373+#ifdef CONFIG_PAX_MPROTECT
56374+ pax_flags |= MF_PAX_MPROTECT;
56375+#endif
56376+
56377+#ifdef CONFIG_PAX_RANDMMAP
56378+ if (randomize_va_space)
56379+ pax_flags |= MF_PAX_RANDMMAP;
56380+#endif
56381+
56382+ return pax_flags;
56383+}
56384+
56385+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56386+{
56387+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56388+
56389+#ifdef CONFIG_PAX_EI_PAX
56390+
56391+#ifdef CONFIG_PAX_SOFTMODE
56392+ if (pax_softmode)
56393+ return pax_flags;
56394+#endif
56395+
56396+ pax_flags = 0UL;
56397+
56398+#ifdef CONFIG_PAX_PAGEEXEC
56399+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56400+ pax_flags |= MF_PAX_PAGEEXEC;
56401+#endif
56402+
56403+#ifdef CONFIG_PAX_SEGMEXEC
56404+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56405+ pax_flags |= MF_PAX_SEGMEXEC;
56406+#endif
56407+
56408+#ifdef CONFIG_PAX_EMUTRAMP
56409+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56410+ pax_flags |= MF_PAX_EMUTRAMP;
56411+#endif
56412+
56413+#ifdef CONFIG_PAX_MPROTECT
56414+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56415+ pax_flags |= MF_PAX_MPROTECT;
56416+#endif
56417+
56418+#ifdef CONFIG_PAX_ASLR
56419+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56420+ pax_flags |= MF_PAX_RANDMMAP;
56421+#endif
56422+
56423+#endif
56424+
56425+ return pax_flags;
56426+
56427+}
56428+
56429+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56430+{
56431+
56432+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56433+ unsigned long i;
56434+
56435+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56436+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56437+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56438+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56439+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56440+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56441+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56442+ return PAX_PARSE_FLAGS_FALLBACK;
56443+
56444+#ifdef CONFIG_PAX_SOFTMODE
56445+ if (pax_softmode)
56446+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56447+ else
56448+#endif
56449+
56450+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56451+ break;
56452+ }
56453+#endif
56454+
56455+ return PAX_PARSE_FLAGS_FALLBACK;
56456+}
56457+
56458+static unsigned long pax_parse_xattr_pax(struct file * const file)
56459+{
56460+
56461+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56462+ ssize_t xattr_size, i;
56463+ unsigned char xattr_value[sizeof("pemrs") - 1];
56464+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56465+
56466+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56467+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56468+ return PAX_PARSE_FLAGS_FALLBACK;
56469+
56470+ for (i = 0; i < xattr_size; i++)
56471+ switch (xattr_value[i]) {
56472+ default:
56473+ return PAX_PARSE_FLAGS_FALLBACK;
56474+
56475+#define parse_flag(option1, option2, flag) \
56476+ case option1: \
56477+ if (pax_flags_hardmode & MF_PAX_##flag) \
56478+ return PAX_PARSE_FLAGS_FALLBACK;\
56479+ pax_flags_hardmode |= MF_PAX_##flag; \
56480+ break; \
56481+ case option2: \
56482+ if (pax_flags_softmode & MF_PAX_##flag) \
56483+ return PAX_PARSE_FLAGS_FALLBACK;\
56484+ pax_flags_softmode |= MF_PAX_##flag; \
56485+ break;
56486+
56487+ parse_flag('p', 'P', PAGEEXEC);
56488+ parse_flag('e', 'E', EMUTRAMP);
56489+ parse_flag('m', 'M', MPROTECT);
56490+ parse_flag('r', 'R', RANDMMAP);
56491+ parse_flag('s', 'S', SEGMEXEC);
56492+
56493+#undef parse_flag
56494+ }
56495+
56496+ if (pax_flags_hardmode & pax_flags_softmode)
56497+ return PAX_PARSE_FLAGS_FALLBACK;
56498+
56499+#ifdef CONFIG_PAX_SOFTMODE
56500+ if (pax_softmode)
56501+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56502+ else
56503+#endif
56504+
56505+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56506+#else
56507+ return PAX_PARSE_FLAGS_FALLBACK;
56508+#endif
56509+
56510+}
56511+
56512+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56513+{
56514+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56515+
56516+ pax_flags = pax_parse_defaults();
56517+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56518+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56519+ xattr_pax_flags = pax_parse_xattr_pax(file);
56520+
56521+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56522+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56523+ pt_pax_flags != xattr_pax_flags)
56524+ return -EINVAL;
56525+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56526+ pax_flags = xattr_pax_flags;
56527+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56528+ pax_flags = pt_pax_flags;
56529+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56530+ pax_flags = ei_pax_flags;
56531+
56532+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56533+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56534+ if ((__supported_pte_mask & _PAGE_NX))
56535+ pax_flags &= ~MF_PAX_SEGMEXEC;
56536+ else
56537+ pax_flags &= ~MF_PAX_PAGEEXEC;
56538+ }
56539+#endif
56540+
56541+ if (0 > pax_check_flags(&pax_flags))
56542+ return -EINVAL;
56543+
56544+ current->mm->pax_flags = pax_flags;
56545+ return 0;
56546+}
56547+#endif
56548+
56549 /*
56550 * These are the functions used to load ELF style executables and shared
56551 * libraries. There is no binary dependent code anywhere else.
56552@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56553 {
56554 unsigned int random_variable = 0;
56555
56556+#ifdef CONFIG_PAX_RANDUSTACK
56557+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56558+ return stack_top - current->mm->delta_stack;
56559+#endif
56560+
56561 if ((current->flags & PF_RANDOMIZE) &&
56562 !(current->personality & ADDR_NO_RANDOMIZE)) {
56563 random_variable = get_random_int() & STACK_RND_MASK;
56564@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56565 unsigned long load_addr = 0, load_bias = 0;
56566 int load_addr_set = 0;
56567 char * elf_interpreter = NULL;
56568- unsigned long error;
56569+ unsigned long error = 0;
56570 struct elf_phdr *elf_ppnt, *elf_phdata;
56571 unsigned long elf_bss, elf_brk;
56572 int retval, i;
56573@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56574 unsigned long start_code, end_code, start_data, end_data;
56575 unsigned long reloc_func_desc __maybe_unused = 0;
56576 int executable_stack = EXSTACK_DEFAULT;
56577- unsigned long def_flags = 0;
56578 struct pt_regs *regs = current_pt_regs();
56579 struct {
56580 struct elfhdr elf_ex;
56581 struct elfhdr interp_elf_ex;
56582 } *loc;
56583+ unsigned long pax_task_size;
56584
56585 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56586 if (!loc) {
56587@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56588 goto out_free_dentry;
56589
56590 /* OK, This is the point of no return */
56591- current->mm->def_flags = def_flags;
56592+ current->mm->def_flags = 0;
56593
56594 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56595 may depend on the personality. */
56596 SET_PERSONALITY(loc->elf_ex);
56597+
56598+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56599+ current->mm->pax_flags = 0UL;
56600+#endif
56601+
56602+#ifdef CONFIG_PAX_DLRESOLVE
56603+ current->mm->call_dl_resolve = 0UL;
56604+#endif
56605+
56606+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56607+ current->mm->call_syscall = 0UL;
56608+#endif
56609+
56610+#ifdef CONFIG_PAX_ASLR
56611+ current->mm->delta_mmap = 0UL;
56612+ current->mm->delta_stack = 0UL;
56613+#endif
56614+
56615+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56616+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56617+ send_sig(SIGKILL, current, 0);
56618+ goto out_free_dentry;
56619+ }
56620+#endif
56621+
56622+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56623+ pax_set_initial_flags(bprm);
56624+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56625+ if (pax_set_initial_flags_func)
56626+ (pax_set_initial_flags_func)(bprm);
56627+#endif
56628+
56629+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56630+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56631+ current->mm->context.user_cs_limit = PAGE_SIZE;
56632+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56633+ }
56634+#endif
56635+
56636+#ifdef CONFIG_PAX_SEGMEXEC
56637+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56638+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56639+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56640+ pax_task_size = SEGMEXEC_TASK_SIZE;
56641+ current->mm->def_flags |= VM_NOHUGEPAGE;
56642+ } else
56643+#endif
56644+
56645+ pax_task_size = TASK_SIZE;
56646+
56647+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56648+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56649+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56650+ put_cpu();
56651+ }
56652+#endif
56653+
56654+#ifdef CONFIG_PAX_ASLR
56655+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56656+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56657+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56658+ }
56659+#endif
56660+
56661+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56662+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56663+ executable_stack = EXSTACK_DISABLE_X;
56664+ current->personality &= ~READ_IMPLIES_EXEC;
56665+ } else
56666+#endif
56667+
56668 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56669 current->personality |= READ_IMPLIES_EXEC;
56670
56671@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56672 #else
56673 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56674 #endif
56675+
56676+#ifdef CONFIG_PAX_RANDMMAP
56677+ /* PaX: randomize base address at the default exe base if requested */
56678+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56679+#ifdef CONFIG_SPARC64
56680+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56681+#else
56682+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56683+#endif
56684+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56685+ elf_flags |= MAP_FIXED;
56686+ }
56687+#endif
56688+
56689 }
56690
56691 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56692@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56693 * allowed task size. Note that p_filesz must always be
56694 * <= p_memsz so it is only necessary to check p_memsz.
56695 */
56696- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56697- elf_ppnt->p_memsz > TASK_SIZE ||
56698- TASK_SIZE - elf_ppnt->p_memsz < k) {
56699+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56700+ elf_ppnt->p_memsz > pax_task_size ||
56701+ pax_task_size - elf_ppnt->p_memsz < k) {
56702 /* set_brk can never work. Avoid overflows. */
56703 send_sig(SIGKILL, current, 0);
56704 retval = -EINVAL;
56705@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56706 goto out_free_dentry;
56707 }
56708 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56709- send_sig(SIGSEGV, current, 0);
56710- retval = -EFAULT; /* Nobody gets to see this, but.. */
56711- goto out_free_dentry;
56712+ /*
56713+ * This bss-zeroing can fail if the ELF
56714+ * file specifies odd protections. So
56715+ * we don't check the return value
56716+ */
56717 }
56718
56719+#ifdef CONFIG_PAX_RANDMMAP
56720+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56721+ unsigned long start, size, flags;
56722+ vm_flags_t vm_flags;
56723+
56724+ start = ELF_PAGEALIGN(elf_brk);
56725+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56726+ flags = MAP_FIXED | MAP_PRIVATE;
56727+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56728+
56729+ down_write(&current->mm->mmap_sem);
56730+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56731+ retval = -ENOMEM;
56732+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56733+// if (current->personality & ADDR_NO_RANDOMIZE)
56734+// vm_flags |= VM_READ | VM_MAYREAD;
56735+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56736+ retval = IS_ERR_VALUE(start) ? start : 0;
56737+ }
56738+ up_write(&current->mm->mmap_sem);
56739+ if (retval == 0)
56740+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56741+ if (retval < 0) {
56742+ send_sig(SIGKILL, current, 0);
56743+ goto out_free_dentry;
56744+ }
56745+ }
56746+#endif
56747+
56748 if (elf_interpreter) {
56749- unsigned long interp_map_addr = 0;
56750-
56751 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56752 interpreter,
56753- &interp_map_addr,
56754 load_bias);
56755 if (!IS_ERR((void *)elf_entry)) {
56756 /*
56757@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56758 * Decide what to dump of a segment, part, all or none.
56759 */
56760 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56761- unsigned long mm_flags)
56762+ unsigned long mm_flags, long signr)
56763 {
56764 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56765
56766@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56767 if (vma->vm_file == NULL)
56768 return 0;
56769
56770- if (FILTER(MAPPED_PRIVATE))
56771+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56772 goto whole;
56773
56774 /*
56775@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56776 {
56777 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56778 int i = 0;
56779- do
56780+ do {
56781 i += 2;
56782- while (auxv[i - 2] != AT_NULL);
56783+ } while (auxv[i - 2] != AT_NULL);
56784 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56785 }
56786
56787@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56788 {
56789 mm_segment_t old_fs = get_fs();
56790 set_fs(KERNEL_DS);
56791- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56792+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56793 set_fs(old_fs);
56794 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56795 }
56796@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56797 }
56798
56799 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56800- unsigned long mm_flags)
56801+ struct coredump_params *cprm)
56802 {
56803 struct vm_area_struct *vma;
56804 size_t size = 0;
56805
56806 for (vma = first_vma(current, gate_vma); vma != NULL;
56807 vma = next_vma(vma, gate_vma))
56808- size += vma_dump_size(vma, mm_flags);
56809+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56810 return size;
56811 }
56812
56813@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56814
56815 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56816
56817- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56818+ offset += elf_core_vma_data_size(gate_vma, cprm);
56819 offset += elf_core_extra_data_size();
56820 e_shoff = offset;
56821
56822@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56823 phdr.p_offset = offset;
56824 phdr.p_vaddr = vma->vm_start;
56825 phdr.p_paddr = 0;
56826- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56827+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56828 phdr.p_memsz = vma->vm_end - vma->vm_start;
56829 offset += phdr.p_filesz;
56830 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56831@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56832 unsigned long addr;
56833 unsigned long end;
56834
56835- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56836+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56837
56838 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56839 struct page *page;
56840@@ -2199,6 +2678,167 @@ out:
56841
56842 #endif /* CONFIG_ELF_CORE */
56843
56844+#ifdef CONFIG_PAX_MPROTECT
56845+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56846+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56847+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56848+ *
56849+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56850+ * basis because we want to allow the common case and not the special ones.
56851+ */
56852+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56853+{
56854+ struct elfhdr elf_h;
56855+ struct elf_phdr elf_p;
56856+ unsigned long i;
56857+ unsigned long oldflags;
56858+ bool is_textrel_rw, is_textrel_rx, is_relro;
56859+
56860+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56861+ return;
56862+
56863+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56864+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56865+
56866+#ifdef CONFIG_PAX_ELFRELOCS
56867+ /* possible TEXTREL */
56868+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56869+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56870+#else
56871+ is_textrel_rw = false;
56872+ is_textrel_rx = false;
56873+#endif
56874+
56875+ /* possible RELRO */
56876+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56877+
56878+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56879+ return;
56880+
56881+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56882+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56883+
56884+#ifdef CONFIG_PAX_ETEXECRELOCS
56885+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56886+#else
56887+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56888+#endif
56889+
56890+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56891+ !elf_check_arch(&elf_h) ||
56892+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56893+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56894+ return;
56895+
56896+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56897+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56898+ return;
56899+ switch (elf_p.p_type) {
56900+ case PT_DYNAMIC:
56901+ if (!is_textrel_rw && !is_textrel_rx)
56902+ continue;
56903+ i = 0UL;
56904+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56905+ elf_dyn dyn;
56906+
56907+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56908+ break;
56909+ if (dyn.d_tag == DT_NULL)
56910+ break;
56911+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56912+ gr_log_textrel(vma);
56913+ if (is_textrel_rw)
56914+ vma->vm_flags |= VM_MAYWRITE;
56915+ else
56916+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56917+ vma->vm_flags &= ~VM_MAYWRITE;
56918+ break;
56919+ }
56920+ i++;
56921+ }
56922+ is_textrel_rw = false;
56923+ is_textrel_rx = false;
56924+ continue;
56925+
56926+ case PT_GNU_RELRO:
56927+ if (!is_relro)
56928+ continue;
56929+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56930+ vma->vm_flags &= ~VM_MAYWRITE;
56931+ is_relro = false;
56932+ continue;
56933+
56934+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56935+ case PT_PAX_FLAGS: {
56936+ const char *msg_mprotect = "", *msg_emutramp = "";
56937+ char *buffer_lib, *buffer_exe;
56938+
56939+ if (elf_p.p_flags & PF_NOMPROTECT)
56940+ msg_mprotect = "MPROTECT disabled";
56941+
56942+#ifdef CONFIG_PAX_EMUTRAMP
56943+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56944+ msg_emutramp = "EMUTRAMP enabled";
56945+#endif
56946+
56947+ if (!msg_mprotect[0] && !msg_emutramp[0])
56948+ continue;
56949+
56950+ if (!printk_ratelimit())
56951+ continue;
56952+
56953+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56954+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56955+ if (buffer_lib && buffer_exe) {
56956+ char *path_lib, *path_exe;
56957+
56958+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56959+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56960+
56961+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56962+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56963+
56964+ }
56965+ free_page((unsigned long)buffer_exe);
56966+ free_page((unsigned long)buffer_lib);
56967+ continue;
56968+ }
56969+#endif
56970+
56971+ }
56972+ }
56973+}
56974+#endif
56975+
56976+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56977+
56978+extern int grsec_enable_log_rwxmaps;
56979+
56980+static void elf_handle_mmap(struct file *file)
56981+{
56982+ struct elfhdr elf_h;
56983+ struct elf_phdr elf_p;
56984+ unsigned long i;
56985+
56986+ if (!grsec_enable_log_rwxmaps)
56987+ return;
56988+
56989+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56990+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56991+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56992+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56993+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56994+ return;
56995+
56996+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56997+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56998+ return;
56999+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57000+ gr_log_ptgnustack(file);
57001+ }
57002+}
57003+#endif
57004+
57005 static int __init init_elf_binfmt(void)
57006 {
57007 register_binfmt(&elf_format);
57008diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
57009index d50bbe5..af3b649 100644
57010--- a/fs/binfmt_flat.c
57011+++ b/fs/binfmt_flat.c
57012@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
57013 realdatastart = (unsigned long) -ENOMEM;
57014 printk("Unable to allocate RAM for process data, errno %d\n",
57015 (int)-realdatastart);
57016+ down_write(&current->mm->mmap_sem);
57017 vm_munmap(textpos, text_len);
57018+ up_write(&current->mm->mmap_sem);
57019 ret = realdatastart;
57020 goto err;
57021 }
57022@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57023 }
57024 if (IS_ERR_VALUE(result)) {
57025 printk("Unable to read data+bss, errno %d\n", (int)-result);
57026+ down_write(&current->mm->mmap_sem);
57027 vm_munmap(textpos, text_len);
57028 vm_munmap(realdatastart, len);
57029+ up_write(&current->mm->mmap_sem);
57030 ret = result;
57031 goto err;
57032 }
57033@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57034 }
57035 if (IS_ERR_VALUE(result)) {
57036 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57037+ down_write(&current->mm->mmap_sem);
57038 vm_munmap(textpos, text_len + data_len + extra +
57039 MAX_SHARED_LIBS * sizeof(unsigned long));
57040+ up_write(&current->mm->mmap_sem);
57041 ret = result;
57042 goto err;
57043 }
57044diff --git a/fs/bio.c b/fs/bio.c
57045index 8754e7b..0669094 100644
57046--- a/fs/bio.c
57047+++ b/fs/bio.c
57048@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57049 /*
57050 * Overflow, abort
57051 */
57052- if (end < start)
57053+ if (end < start || end - start > INT_MAX - nr_pages)
57054 return ERR_PTR(-EINVAL);
57055
57056 nr_pages += end - start;
57057@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57058 /*
57059 * Overflow, abort
57060 */
57061- if (end < start)
57062+ if (end < start || end - start > INT_MAX - nr_pages)
57063 return ERR_PTR(-EINVAL);
57064
57065 nr_pages += end - start;
57066@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57067 const int read = bio_data_dir(bio) == READ;
57068 struct bio_map_data *bmd = bio->bi_private;
57069 int i;
57070- char *p = bmd->sgvecs[0].iov_base;
57071+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57072
57073 bio_for_each_segment_all(bvec, bio, i) {
57074 char *addr = page_address(bvec->bv_page);
57075diff --git a/fs/block_dev.c b/fs/block_dev.c
57076index 1e86823..8e34695 100644
57077--- a/fs/block_dev.c
57078+++ b/fs/block_dev.c
57079@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57080 else if (bdev->bd_contains == bdev)
57081 return true; /* is a whole device which isn't held */
57082
57083- else if (whole->bd_holder == bd_may_claim)
57084+ else if (whole->bd_holder == (void *)bd_may_claim)
57085 return true; /* is a partition of a device that is being partitioned */
57086 else if (whole->bd_holder != NULL)
57087 return false; /* is a partition of a held device */
57088diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57089index cbd3a7d..c6a2881 100644
57090--- a/fs/btrfs/ctree.c
57091+++ b/fs/btrfs/ctree.c
57092@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57093 free_extent_buffer(buf);
57094 add_root_to_dirty_list(root);
57095 } else {
57096- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57097- parent_start = parent->start;
57098- else
57099+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57100+ if (parent)
57101+ parent_start = parent->start;
57102+ else
57103+ parent_start = 0;
57104+ } else
57105 parent_start = 0;
57106
57107 WARN_ON(trans->transid != btrfs_header_generation(parent));
57108diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57109index 451b00c..a2cccee 100644
57110--- a/fs/btrfs/delayed-inode.c
57111+++ b/fs/btrfs/delayed-inode.c
57112@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57113
57114 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57115 {
57116- int seq = atomic_inc_return(&delayed_root->items_seq);
57117+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57118 if ((atomic_dec_return(&delayed_root->items) <
57119 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57120 waitqueue_active(&delayed_root->wait))
57121@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57122
57123 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57124 {
57125- int val = atomic_read(&delayed_root->items_seq);
57126+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57127
57128 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57129 return 1;
57130@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57131 int seq;
57132 int ret;
57133
57134- seq = atomic_read(&delayed_root->items_seq);
57135+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57136
57137 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57138 if (ret)
57139diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57140index f70119f..ab5894d 100644
57141--- a/fs/btrfs/delayed-inode.h
57142+++ b/fs/btrfs/delayed-inode.h
57143@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57144 */
57145 struct list_head prepare_list;
57146 atomic_t items; /* for delayed items */
57147- atomic_t items_seq; /* for delayed items */
57148+ atomic_unchecked_t items_seq; /* for delayed items */
57149 int nodes; /* for delayed nodes */
57150 wait_queue_head_t wait;
57151 };
57152@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57153 struct btrfs_delayed_root *delayed_root)
57154 {
57155 atomic_set(&delayed_root->items, 0);
57156- atomic_set(&delayed_root->items_seq, 0);
57157+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57158 delayed_root->nodes = 0;
57159 spin_lock_init(&delayed_root->lock);
57160 init_waitqueue_head(&delayed_root->wait);
57161diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57162index a6d8efa..2f062cf 100644
57163--- a/fs/btrfs/ioctl.c
57164+++ b/fs/btrfs/ioctl.c
57165@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57166 for (i = 0; i < num_types; i++) {
57167 struct btrfs_space_info *tmp;
57168
57169+ /* Don't copy in more than we allocated */
57170 if (!slot_count)
57171 break;
57172
57173+ slot_count--;
57174+
57175 info = NULL;
57176 rcu_read_lock();
57177 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57178@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57179 memcpy(dest, &space, sizeof(space));
57180 dest++;
57181 space_args.total_spaces++;
57182- slot_count--;
57183 }
57184- if (!slot_count)
57185- break;
57186 }
57187 up_read(&info->groups_sem);
57188 }
57189diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57190index d04db81..96e54f1 100644
57191--- a/fs/btrfs/super.c
57192+++ b/fs/btrfs/super.c
57193@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57194 function, line, errstr);
57195 return;
57196 }
57197- ACCESS_ONCE(trans->transaction->aborted) = errno;
57198+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57199 /* Wake up anybody who may be waiting on this transaction */
57200 wake_up(&root->fs_info->transaction_wait);
57201 wake_up(&root->fs_info->transaction_blocked_wait);
57202diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57203index 865f4cf..f321e86 100644
57204--- a/fs/btrfs/sysfs.c
57205+++ b/fs/btrfs/sysfs.c
57206@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57207 for (set = 0; set < FEAT_MAX; set++) {
57208 int i;
57209 struct attribute *attrs[2];
57210- struct attribute_group agroup = {
57211+ attribute_group_no_const agroup = {
57212 .name = "features",
57213 .attrs = attrs,
57214 };
57215diff --git a/fs/buffer.c b/fs/buffer.c
57216index 27265a8..289f488 100644
57217--- a/fs/buffer.c
57218+++ b/fs/buffer.c
57219@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57220 bh_cachep = kmem_cache_create("buffer_head",
57221 sizeof(struct buffer_head), 0,
57222 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57223- SLAB_MEM_SPREAD),
57224+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57225 NULL);
57226
57227 /*
57228diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57229index 622f469..e8d2d55 100644
57230--- a/fs/cachefiles/bind.c
57231+++ b/fs/cachefiles/bind.c
57232@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57233 args);
57234
57235 /* start by checking things over */
57236- ASSERT(cache->fstop_percent >= 0 &&
57237- cache->fstop_percent < cache->fcull_percent &&
57238+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57239 cache->fcull_percent < cache->frun_percent &&
57240 cache->frun_percent < 100);
57241
57242- ASSERT(cache->bstop_percent >= 0 &&
57243- cache->bstop_percent < cache->bcull_percent &&
57244+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57245 cache->bcull_percent < cache->brun_percent &&
57246 cache->brun_percent < 100);
57247
57248diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57249index 0a1467b..6a53245 100644
57250--- a/fs/cachefiles/daemon.c
57251+++ b/fs/cachefiles/daemon.c
57252@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57253 if (n > buflen)
57254 return -EMSGSIZE;
57255
57256- if (copy_to_user(_buffer, buffer, n) != 0)
57257+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57258 return -EFAULT;
57259
57260 return n;
57261@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57262 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57263 return -EIO;
57264
57265- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57266+ if (datalen > PAGE_SIZE - 1)
57267 return -EOPNOTSUPP;
57268
57269 /* drag the command string into the kernel so we can parse it */
57270@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57271 if (args[0] != '%' || args[1] != '\0')
57272 return -EINVAL;
57273
57274- if (fstop < 0 || fstop >= cache->fcull_percent)
57275+ if (fstop >= cache->fcull_percent)
57276 return cachefiles_daemon_range_error(cache, args);
57277
57278 cache->fstop_percent = fstop;
57279@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57280 if (args[0] != '%' || args[1] != '\0')
57281 return -EINVAL;
57282
57283- if (bstop < 0 || bstop >= cache->bcull_percent)
57284+ if (bstop >= cache->bcull_percent)
57285 return cachefiles_daemon_range_error(cache, args);
57286
57287 cache->bstop_percent = bstop;
57288diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57289index 5349473..d6c0b93 100644
57290--- a/fs/cachefiles/internal.h
57291+++ b/fs/cachefiles/internal.h
57292@@ -59,7 +59,7 @@ struct cachefiles_cache {
57293 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57294 struct rb_root active_nodes; /* active nodes (can't be culled) */
57295 rwlock_t active_lock; /* lock for active_nodes */
57296- atomic_t gravecounter; /* graveyard uniquifier */
57297+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57298 unsigned frun_percent; /* when to stop culling (% files) */
57299 unsigned fcull_percent; /* when to start culling (% files) */
57300 unsigned fstop_percent; /* when to stop allocating (% files) */
57301@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57302 * proc.c
57303 */
57304 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57305-extern atomic_t cachefiles_lookup_histogram[HZ];
57306-extern atomic_t cachefiles_mkdir_histogram[HZ];
57307-extern atomic_t cachefiles_create_histogram[HZ];
57308+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57309+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57310+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57311
57312 extern int __init cachefiles_proc_init(void);
57313 extern void cachefiles_proc_cleanup(void);
57314 static inline
57315-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57316+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57317 {
57318 unsigned long jif = jiffies - start_jif;
57319 if (jif >= HZ)
57320 jif = HZ - 1;
57321- atomic_inc(&histogram[jif]);
57322+ atomic_inc_unchecked(&histogram[jif]);
57323 }
57324
57325 #else
57326diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57327index ca65f39..48921e3 100644
57328--- a/fs/cachefiles/namei.c
57329+++ b/fs/cachefiles/namei.c
57330@@ -317,7 +317,7 @@ try_again:
57331 /* first step is to make up a grave dentry in the graveyard */
57332 sprintf(nbuffer, "%08x%08x",
57333 (uint32_t) get_seconds(),
57334- (uint32_t) atomic_inc_return(&cache->gravecounter));
57335+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57336
57337 /* do the multiway lock magic */
57338 trap = lock_rename(cache->graveyard, dir);
57339diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57340index eccd339..4c1d995 100644
57341--- a/fs/cachefiles/proc.c
57342+++ b/fs/cachefiles/proc.c
57343@@ -14,9 +14,9 @@
57344 #include <linux/seq_file.h>
57345 #include "internal.h"
57346
57347-atomic_t cachefiles_lookup_histogram[HZ];
57348-atomic_t cachefiles_mkdir_histogram[HZ];
57349-atomic_t cachefiles_create_histogram[HZ];
57350+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57351+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57352+atomic_unchecked_t cachefiles_create_histogram[HZ];
57353
57354 /*
57355 * display the latency histogram
57356@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57357 return 0;
57358 default:
57359 index = (unsigned long) v - 3;
57360- x = atomic_read(&cachefiles_lookup_histogram[index]);
57361- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57362- z = atomic_read(&cachefiles_create_histogram[index]);
57363+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57364+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57365+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57366 if (x == 0 && y == 0 && z == 0)
57367 return 0;
57368
57369diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57370index ebaff36..7e3ea26 100644
57371--- a/fs/cachefiles/rdwr.c
57372+++ b/fs/cachefiles/rdwr.c
57373@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57374 old_fs = get_fs();
57375 set_fs(KERNEL_DS);
57376 ret = file->f_op->write(
57377- file, (const void __user *) data, len, &pos);
57378+ file, (const void __force_user *) data, len, &pos);
57379 set_fs(old_fs);
57380 kunmap(page);
57381 file_end_write(file);
57382diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57383index 45eda6d..9126f7f 100644
57384--- a/fs/ceph/dir.c
57385+++ b/fs/ceph/dir.c
57386@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57387 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57388 struct ceph_mds_client *mdsc = fsc->mdsc;
57389 unsigned frag = fpos_frag(ctx->pos);
57390- int off = fpos_off(ctx->pos);
57391+ unsigned int off = fpos_off(ctx->pos);
57392 int err;
57393 u32 ftype;
57394 struct ceph_mds_reply_info_parsed *rinfo;
57395diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57396index 10a4ccb..92dbc5e 100644
57397--- a/fs/ceph/super.c
57398+++ b/fs/ceph/super.c
57399@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57400 /*
57401 * construct our own bdi so we can control readahead, etc.
57402 */
57403-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57404+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57405
57406 static int ceph_register_bdi(struct super_block *sb,
57407 struct ceph_fs_client *fsc)
57408@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57409 default_backing_dev_info.ra_pages;
57410
57411 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57412- atomic_long_inc_return(&bdi_seq));
57413+ atomic_long_inc_return_unchecked(&bdi_seq));
57414 if (!err)
57415 sb->s_bdi = &fsc->backing_dev_info;
57416 return err;
57417diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57418index f3ac415..3d2420c 100644
57419--- a/fs/cifs/cifs_debug.c
57420+++ b/fs/cifs/cifs_debug.c
57421@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57422
57423 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57424 #ifdef CONFIG_CIFS_STATS2
57425- atomic_set(&totBufAllocCount, 0);
57426- atomic_set(&totSmBufAllocCount, 0);
57427+ atomic_set_unchecked(&totBufAllocCount, 0);
57428+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57429 #endif /* CONFIG_CIFS_STATS2 */
57430 spin_lock(&cifs_tcp_ses_lock);
57431 list_for_each(tmp1, &cifs_tcp_ses_list) {
57432@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57433 tcon = list_entry(tmp3,
57434 struct cifs_tcon,
57435 tcon_list);
57436- atomic_set(&tcon->num_smbs_sent, 0);
57437+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57438 if (server->ops->clear_stats)
57439 server->ops->clear_stats(tcon);
57440 }
57441@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57442 smBufAllocCount.counter, cifs_min_small);
57443 #ifdef CONFIG_CIFS_STATS2
57444 seq_printf(m, "Total Large %d Small %d Allocations\n",
57445- atomic_read(&totBufAllocCount),
57446- atomic_read(&totSmBufAllocCount));
57447+ atomic_read_unchecked(&totBufAllocCount),
57448+ atomic_read_unchecked(&totSmBufAllocCount));
57449 #endif /* CONFIG_CIFS_STATS2 */
57450
57451 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57452@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57453 if (tcon->need_reconnect)
57454 seq_puts(m, "\tDISCONNECTED ");
57455 seq_printf(m, "\nSMBs: %d",
57456- atomic_read(&tcon->num_smbs_sent));
57457+ atomic_read_unchecked(&tcon->num_smbs_sent));
57458 if (server->ops->print_stats)
57459 server->ops->print_stats(m, tcon);
57460 }
57461diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57462index 849f613..eae6dec 100644
57463--- a/fs/cifs/cifsfs.c
57464+++ b/fs/cifs/cifsfs.c
57465@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57466 */
57467 cifs_req_cachep = kmem_cache_create("cifs_request",
57468 CIFSMaxBufSize + max_hdr_size, 0,
57469- SLAB_HWCACHE_ALIGN, NULL);
57470+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57471 if (cifs_req_cachep == NULL)
57472 return -ENOMEM;
57473
57474@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57475 efficient to alloc 1 per page off the slab compared to 17K (5page)
57476 alloc of large cifs buffers even when page debugging is on */
57477 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57478- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57479+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57480 NULL);
57481 if (cifs_sm_req_cachep == NULL) {
57482 mempool_destroy(cifs_req_poolp);
57483@@ -1168,8 +1168,8 @@ init_cifs(void)
57484 atomic_set(&bufAllocCount, 0);
57485 atomic_set(&smBufAllocCount, 0);
57486 #ifdef CONFIG_CIFS_STATS2
57487- atomic_set(&totBufAllocCount, 0);
57488- atomic_set(&totSmBufAllocCount, 0);
57489+ atomic_set_unchecked(&totBufAllocCount, 0);
57490+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57491 #endif /* CONFIG_CIFS_STATS2 */
57492
57493 atomic_set(&midCount, 0);
57494diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57495index c0f3718..6afed7d 100644
57496--- a/fs/cifs/cifsglob.h
57497+++ b/fs/cifs/cifsglob.h
57498@@ -804,35 +804,35 @@ struct cifs_tcon {
57499 __u16 Flags; /* optional support bits */
57500 enum statusEnum tidStatus;
57501 #ifdef CONFIG_CIFS_STATS
57502- atomic_t num_smbs_sent;
57503+ atomic_unchecked_t num_smbs_sent;
57504 union {
57505 struct {
57506- atomic_t num_writes;
57507- atomic_t num_reads;
57508- atomic_t num_flushes;
57509- atomic_t num_oplock_brks;
57510- atomic_t num_opens;
57511- atomic_t num_closes;
57512- atomic_t num_deletes;
57513- atomic_t num_mkdirs;
57514- atomic_t num_posixopens;
57515- atomic_t num_posixmkdirs;
57516- atomic_t num_rmdirs;
57517- atomic_t num_renames;
57518- atomic_t num_t2renames;
57519- atomic_t num_ffirst;
57520- atomic_t num_fnext;
57521- atomic_t num_fclose;
57522- atomic_t num_hardlinks;
57523- atomic_t num_symlinks;
57524- atomic_t num_locks;
57525- atomic_t num_acl_get;
57526- atomic_t num_acl_set;
57527+ atomic_unchecked_t num_writes;
57528+ atomic_unchecked_t num_reads;
57529+ atomic_unchecked_t num_flushes;
57530+ atomic_unchecked_t num_oplock_brks;
57531+ atomic_unchecked_t num_opens;
57532+ atomic_unchecked_t num_closes;
57533+ atomic_unchecked_t num_deletes;
57534+ atomic_unchecked_t num_mkdirs;
57535+ atomic_unchecked_t num_posixopens;
57536+ atomic_unchecked_t num_posixmkdirs;
57537+ atomic_unchecked_t num_rmdirs;
57538+ atomic_unchecked_t num_renames;
57539+ atomic_unchecked_t num_t2renames;
57540+ atomic_unchecked_t num_ffirst;
57541+ atomic_unchecked_t num_fnext;
57542+ atomic_unchecked_t num_fclose;
57543+ atomic_unchecked_t num_hardlinks;
57544+ atomic_unchecked_t num_symlinks;
57545+ atomic_unchecked_t num_locks;
57546+ atomic_unchecked_t num_acl_get;
57547+ atomic_unchecked_t num_acl_set;
57548 } cifs_stats;
57549 #ifdef CONFIG_CIFS_SMB2
57550 struct {
57551- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57552- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57553+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57554+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57555 } smb2_stats;
57556 #endif /* CONFIG_CIFS_SMB2 */
57557 } stats;
57558@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57559 }
57560
57561 #ifdef CONFIG_CIFS_STATS
57562-#define cifs_stats_inc atomic_inc
57563+#define cifs_stats_inc atomic_inc_unchecked
57564
57565 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57566 unsigned int bytes)
57567@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57568 /* Various Debug counters */
57569 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57570 #ifdef CONFIG_CIFS_STATS2
57571-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57572-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57573+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57574+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57575 #endif
57576 GLOBAL_EXTERN atomic_t smBufAllocCount;
57577 GLOBAL_EXTERN atomic_t midCount;
57578diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57579index 834fce7..8a314b5 100644
57580--- a/fs/cifs/file.c
57581+++ b/fs/cifs/file.c
57582@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57583 index = mapping->writeback_index; /* Start from prev offset */
57584 end = -1;
57585 } else {
57586- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57587- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57588- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57589+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57590 range_whole = true;
57591+ index = 0;
57592+ end = ULONG_MAX;
57593+ } else {
57594+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57595+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57596+ }
57597 scanned = true;
57598 }
57599 retry:
57600diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57601index 2f9f379..43f8025 100644
57602--- a/fs/cifs/misc.c
57603+++ b/fs/cifs/misc.c
57604@@ -170,7 +170,7 @@ cifs_buf_get(void)
57605 memset(ret_buf, 0, buf_size + 3);
57606 atomic_inc(&bufAllocCount);
57607 #ifdef CONFIG_CIFS_STATS2
57608- atomic_inc(&totBufAllocCount);
57609+ atomic_inc_unchecked(&totBufAllocCount);
57610 #endif /* CONFIG_CIFS_STATS2 */
57611 }
57612
57613@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57614 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57615 atomic_inc(&smBufAllocCount);
57616 #ifdef CONFIG_CIFS_STATS2
57617- atomic_inc(&totSmBufAllocCount);
57618+ atomic_inc_unchecked(&totSmBufAllocCount);
57619 #endif /* CONFIG_CIFS_STATS2 */
57620
57621 }
57622diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57623index 526fb89..ecdbf5a 100644
57624--- a/fs/cifs/smb1ops.c
57625+++ b/fs/cifs/smb1ops.c
57626@@ -616,27 +616,27 @@ static void
57627 cifs_clear_stats(struct cifs_tcon *tcon)
57628 {
57629 #ifdef CONFIG_CIFS_STATS
57630- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57631- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57632- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57633- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57634- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57635- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57636- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57637- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57638- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57639- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57640- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57641- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57642- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57643- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57644- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57645- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57646- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57647- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57648- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57649- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57650- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57651+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57652+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57653+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57654+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57655+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57656+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57657+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57658+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57659+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57660+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57661+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57662+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57663+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57664+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57665+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57666+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57667+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57668+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57669+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57670+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57671+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57672 #endif
57673 }
57674
57675@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57676 {
57677 #ifdef CONFIG_CIFS_STATS
57678 seq_printf(m, " Oplocks breaks: %d",
57679- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57680+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57681 seq_printf(m, "\nReads: %d Bytes: %llu",
57682- atomic_read(&tcon->stats.cifs_stats.num_reads),
57683+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57684 (long long)(tcon->bytes_read));
57685 seq_printf(m, "\nWrites: %d Bytes: %llu",
57686- atomic_read(&tcon->stats.cifs_stats.num_writes),
57687+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57688 (long long)(tcon->bytes_written));
57689 seq_printf(m, "\nFlushes: %d",
57690- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57691+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57692 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57693- atomic_read(&tcon->stats.cifs_stats.num_locks),
57694- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57695- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57696+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57697+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57698+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57699 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57700- atomic_read(&tcon->stats.cifs_stats.num_opens),
57701- atomic_read(&tcon->stats.cifs_stats.num_closes),
57702- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57703+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57704+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57705+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57706 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57707- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57708- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57709+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57710+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57711 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57712- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57713- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57714+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57715+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57716 seq_printf(m, "\nRenames: %d T2 Renames %d",
57717- atomic_read(&tcon->stats.cifs_stats.num_renames),
57718- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57719+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57720+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57721 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57722- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57723- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57724- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57725+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57726+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57727+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57728 #endif
57729 }
57730
57731diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57732index 192f51a..539307e 100644
57733--- a/fs/cifs/smb2ops.c
57734+++ b/fs/cifs/smb2ops.c
57735@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57736 #ifdef CONFIG_CIFS_STATS
57737 int i;
57738 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57739- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57740- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57741+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57742+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57743 }
57744 #endif
57745 }
57746@@ -405,65 +405,65 @@ static void
57747 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57748 {
57749 #ifdef CONFIG_CIFS_STATS
57750- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57751- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57752+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57753+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57754 seq_printf(m, "\nNegotiates: %d sent %d failed",
57755- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57756- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57757+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57758+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57759 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57760- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57761- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57762+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57763+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57764 seq_printf(m, "\nLogoffs: %d sent %d failed",
57765- atomic_read(&sent[SMB2_LOGOFF_HE]),
57766- atomic_read(&failed[SMB2_LOGOFF_HE]));
57767+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57768+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57769 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57770- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57771- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57772+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57773+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57774 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57775- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57776- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57777+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57778+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57779 seq_printf(m, "\nCreates: %d sent %d failed",
57780- atomic_read(&sent[SMB2_CREATE_HE]),
57781- atomic_read(&failed[SMB2_CREATE_HE]));
57782+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57783+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57784 seq_printf(m, "\nCloses: %d sent %d failed",
57785- atomic_read(&sent[SMB2_CLOSE_HE]),
57786- atomic_read(&failed[SMB2_CLOSE_HE]));
57787+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57788+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57789 seq_printf(m, "\nFlushes: %d sent %d failed",
57790- atomic_read(&sent[SMB2_FLUSH_HE]),
57791- atomic_read(&failed[SMB2_FLUSH_HE]));
57792+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57793+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57794 seq_printf(m, "\nReads: %d sent %d failed",
57795- atomic_read(&sent[SMB2_READ_HE]),
57796- atomic_read(&failed[SMB2_READ_HE]));
57797+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57798+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57799 seq_printf(m, "\nWrites: %d sent %d failed",
57800- atomic_read(&sent[SMB2_WRITE_HE]),
57801- atomic_read(&failed[SMB2_WRITE_HE]));
57802+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57803+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57804 seq_printf(m, "\nLocks: %d sent %d failed",
57805- atomic_read(&sent[SMB2_LOCK_HE]),
57806- atomic_read(&failed[SMB2_LOCK_HE]));
57807+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57808+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57809 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57810- atomic_read(&sent[SMB2_IOCTL_HE]),
57811- atomic_read(&failed[SMB2_IOCTL_HE]));
57812+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57813+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57814 seq_printf(m, "\nCancels: %d sent %d failed",
57815- atomic_read(&sent[SMB2_CANCEL_HE]),
57816- atomic_read(&failed[SMB2_CANCEL_HE]));
57817+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57818+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57819 seq_printf(m, "\nEchos: %d sent %d failed",
57820- atomic_read(&sent[SMB2_ECHO_HE]),
57821- atomic_read(&failed[SMB2_ECHO_HE]));
57822+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57823+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57824 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57825- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57826- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57827+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57828+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57829 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57830- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57831- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57832+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57833+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57834 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57835- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57836- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57837+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57838+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57839 seq_printf(m, "\nSetInfos: %d sent %d failed",
57840- atomic_read(&sent[SMB2_SET_INFO_HE]),
57841- atomic_read(&failed[SMB2_SET_INFO_HE]));
57842+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57843+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57844 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57845- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57846- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57847+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57848+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57849 #endif
57850 }
57851
57852diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57853index 8603447..f9caeee 100644
57854--- a/fs/cifs/smb2pdu.c
57855+++ b/fs/cifs/smb2pdu.c
57856@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57857 default:
57858 cifs_dbg(VFS, "info level %u isn't supported\n",
57859 srch_inf->info_level);
57860- rc = -EINVAL;
57861- goto qdir_exit;
57862+ return -EINVAL;
57863 }
57864
57865 req->FileIndex = cpu_to_le32(index);
57866diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57867index 1da168c..8bc7ff6 100644
57868--- a/fs/coda/cache.c
57869+++ b/fs/coda/cache.c
57870@@ -24,7 +24,7 @@
57871 #include "coda_linux.h"
57872 #include "coda_cache.h"
57873
57874-static atomic_t permission_epoch = ATOMIC_INIT(0);
57875+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57876
57877 /* replace or extend an acl cache hit */
57878 void coda_cache_enter(struct inode *inode, int mask)
57879@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57880 struct coda_inode_info *cii = ITOC(inode);
57881
57882 spin_lock(&cii->c_lock);
57883- cii->c_cached_epoch = atomic_read(&permission_epoch);
57884+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57885 if (!uid_eq(cii->c_uid, current_fsuid())) {
57886 cii->c_uid = current_fsuid();
57887 cii->c_cached_perm = mask;
57888@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57889 {
57890 struct coda_inode_info *cii = ITOC(inode);
57891 spin_lock(&cii->c_lock);
57892- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57893+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57894 spin_unlock(&cii->c_lock);
57895 }
57896
57897 /* remove all acl caches */
57898 void coda_cache_clear_all(struct super_block *sb)
57899 {
57900- atomic_inc(&permission_epoch);
57901+ atomic_inc_unchecked(&permission_epoch);
57902 }
57903
57904
57905@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57906 spin_lock(&cii->c_lock);
57907 hit = (mask & cii->c_cached_perm) == mask &&
57908 uid_eq(cii->c_uid, current_fsuid()) &&
57909- cii->c_cached_epoch == atomic_read(&permission_epoch);
57910+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57911 spin_unlock(&cii->c_lock);
57912
57913 return hit;
57914diff --git a/fs/compat.c b/fs/compat.c
57915index 6af20de..fec3fbb 100644
57916--- a/fs/compat.c
57917+++ b/fs/compat.c
57918@@ -54,7 +54,7 @@
57919 #include <asm/ioctls.h>
57920 #include "internal.h"
57921
57922-int compat_log = 1;
57923+int compat_log = 0;
57924
57925 int compat_printk(const char *fmt, ...)
57926 {
57927@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57928
57929 set_fs(KERNEL_DS);
57930 /* The __user pointer cast is valid because of the set_fs() */
57931- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57932+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57933 set_fs(oldfs);
57934 /* truncating is ok because it's a user address */
57935 if (!ret)
57936@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57937 goto out;
57938
57939 ret = -EINVAL;
57940- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57941+ if (nr_segs > UIO_MAXIOV)
57942 goto out;
57943 if (nr_segs > fast_segs) {
57944 ret = -ENOMEM;
57945@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57946 struct compat_readdir_callback {
57947 struct dir_context ctx;
57948 struct compat_old_linux_dirent __user *dirent;
57949+ struct file * file;
57950 int result;
57951 };
57952
57953@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57954 buf->result = -EOVERFLOW;
57955 return -EOVERFLOW;
57956 }
57957+
57958+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57959+ return 0;
57960+
57961 buf->result++;
57962 dirent = buf->dirent;
57963 if (!access_ok(VERIFY_WRITE, dirent,
57964@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57965 if (!f.file)
57966 return -EBADF;
57967
57968+ buf.file = f.file;
57969 error = iterate_dir(f.file, &buf.ctx);
57970 if (buf.result)
57971 error = buf.result;
57972@@ -901,6 +907,7 @@ struct compat_getdents_callback {
57973 struct dir_context ctx;
57974 struct compat_linux_dirent __user *current_dir;
57975 struct compat_linux_dirent __user *previous;
57976+ struct file * file;
57977 int count;
57978 int error;
57979 };
57980@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57981 buf->error = -EOVERFLOW;
57982 return -EOVERFLOW;
57983 }
57984+
57985+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57986+ return 0;
57987+
57988 dirent = buf->previous;
57989 if (dirent) {
57990 if (__put_user(offset, &dirent->d_off))
57991@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57992 if (!f.file)
57993 return -EBADF;
57994
57995+ buf.file = f.file;
57996 error = iterate_dir(f.file, &buf.ctx);
57997 if (error >= 0)
57998 error = buf.error;
57999@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58000 struct dir_context ctx;
58001 struct linux_dirent64 __user *current_dir;
58002 struct linux_dirent64 __user *previous;
58003+ struct file * file;
58004 int count;
58005 int error;
58006 };
58007@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58008 buf->error = -EINVAL; /* only used if we fail.. */
58009 if (reclen > buf->count)
58010 return -EINVAL;
58011+
58012+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58013+ return 0;
58014+
58015 dirent = buf->previous;
58016
58017 if (dirent) {
58018@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58019 if (!f.file)
58020 return -EBADF;
58021
58022+ buf.file = f.file;
58023 error = iterate_dir(f.file, &buf.ctx);
58024 if (error >= 0)
58025 error = buf.error;
58026diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58027index a81147e..20bf2b5 100644
58028--- a/fs/compat_binfmt_elf.c
58029+++ b/fs/compat_binfmt_elf.c
58030@@ -30,11 +30,13 @@
58031 #undef elf_phdr
58032 #undef elf_shdr
58033 #undef elf_note
58034+#undef elf_dyn
58035 #undef elf_addr_t
58036 #define elfhdr elf32_hdr
58037 #define elf_phdr elf32_phdr
58038 #define elf_shdr elf32_shdr
58039 #define elf_note elf32_note
58040+#define elf_dyn Elf32_Dyn
58041 #define elf_addr_t Elf32_Addr
58042
58043 /*
58044diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58045index 3881610..ab3df0b 100644
58046--- a/fs/compat_ioctl.c
58047+++ b/fs/compat_ioctl.c
58048@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58049 return -EFAULT;
58050 if (__get_user(udata, &ss32->iomem_base))
58051 return -EFAULT;
58052- ss.iomem_base = compat_ptr(udata);
58053+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58054 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58055 __get_user(ss.port_high, &ss32->port_high))
58056 return -EFAULT;
58057@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58058 for (i = 0; i < nmsgs; i++) {
58059 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58060 return -EFAULT;
58061- if (get_user(datap, &umsgs[i].buf) ||
58062- put_user(compat_ptr(datap), &tmsgs[i].buf))
58063+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58064+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58065 return -EFAULT;
58066 }
58067 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58068@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58069 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58070 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58071 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58072- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58073+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58074 return -EFAULT;
58075
58076 return ioctl_preallocate(file, p);
58077@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58078 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58079 {
58080 unsigned int a, b;
58081- a = *(unsigned int *)p;
58082- b = *(unsigned int *)q;
58083+ a = *(const unsigned int *)p;
58084+ b = *(const unsigned int *)q;
58085 if (a > b)
58086 return 1;
58087 if (a < b)
58088diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58089index e081acb..911df21 100644
58090--- a/fs/configfs/dir.c
58091+++ b/fs/configfs/dir.c
58092@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58093 }
58094 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58095 struct configfs_dirent *next;
58096- const char *name;
58097+ const unsigned char * name;
58098+ char d_name[sizeof(next->s_dentry->d_iname)];
58099 int len;
58100 struct inode *inode = NULL;
58101
58102@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58103 continue;
58104
58105 name = configfs_get_name(next);
58106- len = strlen(name);
58107+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58108+ len = next->s_dentry->d_name.len;
58109+ memcpy(d_name, name, len);
58110+ name = d_name;
58111+ } else
58112+ len = strlen(name);
58113
58114 /*
58115 * We'll have a dentry and an inode for
58116diff --git a/fs/coredump.c b/fs/coredump.c
58117index e3ad709..836c55f 100644
58118--- a/fs/coredump.c
58119+++ b/fs/coredump.c
58120@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58121 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58122 {
58123 int free, need;
58124+ va_list arg_copy;
58125
58126 again:
58127 free = cn->size - cn->used;
58128- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58129+
58130+ va_copy(arg_copy, arg);
58131+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58132+ va_end(arg_copy);
58133+
58134 if (need < free) {
58135 cn->used += need;
58136 return 0;
58137@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58138 struct pipe_inode_info *pipe = file->private_data;
58139
58140 pipe_lock(pipe);
58141- pipe->readers++;
58142- pipe->writers--;
58143+ atomic_inc(&pipe->readers);
58144+ atomic_dec(&pipe->writers);
58145 wake_up_interruptible_sync(&pipe->wait);
58146 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58147 pipe_unlock(pipe);
58148@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58149 * We actually want wait_event_freezable() but then we need
58150 * to clear TIF_SIGPENDING and improve dump_interrupted().
58151 */
58152- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58153+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58154
58155 pipe_lock(pipe);
58156- pipe->readers--;
58157- pipe->writers++;
58158+ atomic_dec(&pipe->readers);
58159+ atomic_inc(&pipe->writers);
58160 pipe_unlock(pipe);
58161 }
58162
58163@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58164 struct files_struct *displaced;
58165 bool need_nonrelative = false;
58166 bool core_dumped = false;
58167- static atomic_t core_dump_count = ATOMIC_INIT(0);
58168+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58169+ long signr = siginfo->si_signo;
58170+ int dumpable;
58171 struct coredump_params cprm = {
58172 .siginfo = siginfo,
58173 .regs = signal_pt_regs(),
58174@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58175 .mm_flags = mm->flags,
58176 };
58177
58178- audit_core_dumps(siginfo->si_signo);
58179+ audit_core_dumps(signr);
58180+
58181+ dumpable = __get_dumpable(cprm.mm_flags);
58182+
58183+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58184+ gr_handle_brute_attach(dumpable);
58185
58186 binfmt = mm->binfmt;
58187 if (!binfmt || !binfmt->core_dump)
58188 goto fail;
58189- if (!__get_dumpable(cprm.mm_flags))
58190+ if (!dumpable)
58191 goto fail;
58192
58193 cred = prepare_creds();
58194@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58195 need_nonrelative = true;
58196 }
58197
58198- retval = coredump_wait(siginfo->si_signo, &core_state);
58199+ retval = coredump_wait(signr, &core_state);
58200 if (retval < 0)
58201 goto fail_creds;
58202
58203@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58204 }
58205 cprm.limit = RLIM_INFINITY;
58206
58207- dump_count = atomic_inc_return(&core_dump_count);
58208+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58209 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58210 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58211 task_tgid_vnr(current), current->comm);
58212@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58213 } else {
58214 struct inode *inode;
58215
58216+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58217+
58218 if (cprm.limit < binfmt->min_coredump)
58219 goto fail_unlock;
58220
58221@@ -668,7 +682,7 @@ close_fail:
58222 filp_close(cprm.file, NULL);
58223 fail_dropcount:
58224 if (ispipe)
58225- atomic_dec(&core_dump_count);
58226+ atomic_dec_unchecked(&core_dump_count);
58227 fail_unlock:
58228 kfree(cn.corename);
58229 coredump_finish(mm, core_dumped);
58230@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58231 struct file *file = cprm->file;
58232 loff_t pos = file->f_pos;
58233 ssize_t n;
58234+
58235+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58236 if (cprm->written + nr > cprm->limit)
58237 return 0;
58238 while (nr) {
58239diff --git a/fs/dcache.c b/fs/dcache.c
58240index ca02c13..7e2b581 100644
58241--- a/fs/dcache.c
58242+++ b/fs/dcache.c
58243@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58244 */
58245 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58246 if (name->len > DNAME_INLINE_LEN-1) {
58247- dname = kmalloc(name->len + 1, GFP_KERNEL);
58248+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58249 if (!dname) {
58250 kmem_cache_free(dentry_cache, dentry);
58251 return NULL;
58252@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58253 mempages -= reserve;
58254
58255 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58256- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58257+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58258+ SLAB_NO_SANITIZE, NULL);
58259
58260 dcache_init();
58261 inode_init();
58262diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58263index 9c0444c..628490c 100644
58264--- a/fs/debugfs/inode.c
58265+++ b/fs/debugfs/inode.c
58266@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58267 */
58268 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58269 {
58270+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58271+ return __create_file(name, S_IFDIR | S_IRWXU,
58272+#else
58273 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58274+#endif
58275 parent, NULL, NULL);
58276 }
58277 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58278diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58279index b167ca4..a224e19 100644
58280--- a/fs/ecryptfs/inode.c
58281+++ b/fs/ecryptfs/inode.c
58282@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58283 old_fs = get_fs();
58284 set_fs(get_ds());
58285 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58286- (char __user *)lower_buf,
58287+ (char __force_user *)lower_buf,
58288 PATH_MAX);
58289 set_fs(old_fs);
58290 if (rc < 0)
58291diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58292index e4141f2..d8263e8 100644
58293--- a/fs/ecryptfs/miscdev.c
58294+++ b/fs/ecryptfs/miscdev.c
58295@@ -304,7 +304,7 @@ check_list:
58296 goto out_unlock_msg_ctx;
58297 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58298 if (msg_ctx->msg) {
58299- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58300+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58301 goto out_unlock_msg_ctx;
58302 i += packet_length_size;
58303 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58304diff --git a/fs/exec.c b/fs/exec.c
58305index 3d78fcc..5a38b6b 100644
58306--- a/fs/exec.c
58307+++ b/fs/exec.c
58308@@ -55,8 +55,20 @@
58309 #include <linux/pipe_fs_i.h>
58310 #include <linux/oom.h>
58311 #include <linux/compat.h>
58312+#include <linux/random.h>
58313+#include <linux/seq_file.h>
58314+#include <linux/coredump.h>
58315+#include <linux/mman.h>
58316+
58317+#ifdef CONFIG_PAX_REFCOUNT
58318+#include <linux/kallsyms.h>
58319+#include <linux/kdebug.h>
58320+#endif
58321+
58322+#include <trace/events/fs.h>
58323
58324 #include <asm/uaccess.h>
58325+#include <asm/sections.h>
58326 #include <asm/mmu_context.h>
58327 #include <asm/tlb.h>
58328
58329@@ -65,19 +77,34 @@
58330
58331 #include <trace/events/sched.h>
58332
58333+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58334+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58335+{
58336+ 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");
58337+}
58338+#endif
58339+
58340+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58341+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58342+EXPORT_SYMBOL(pax_set_initial_flags_func);
58343+#endif
58344+
58345 int suid_dumpable = 0;
58346
58347 static LIST_HEAD(formats);
58348 static DEFINE_RWLOCK(binfmt_lock);
58349
58350+extern int gr_process_kernel_exec_ban(void);
58351+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58352+
58353 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58354 {
58355 BUG_ON(!fmt);
58356 if (WARN_ON(!fmt->load_binary))
58357 return;
58358 write_lock(&binfmt_lock);
58359- insert ? list_add(&fmt->lh, &formats) :
58360- list_add_tail(&fmt->lh, &formats);
58361+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58362+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58363 write_unlock(&binfmt_lock);
58364 }
58365
58366@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58367 void unregister_binfmt(struct linux_binfmt * fmt)
58368 {
58369 write_lock(&binfmt_lock);
58370- list_del(&fmt->lh);
58371+ pax_list_del((struct list_head *)&fmt->lh);
58372 write_unlock(&binfmt_lock);
58373 }
58374
58375@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58376 int write)
58377 {
58378 struct page *page;
58379- int ret;
58380
58381-#ifdef CONFIG_STACK_GROWSUP
58382- if (write) {
58383- ret = expand_downwards(bprm->vma, pos);
58384- if (ret < 0)
58385- return NULL;
58386- }
58387-#endif
58388- ret = get_user_pages(current, bprm->mm, pos,
58389- 1, write, 1, &page, NULL);
58390- if (ret <= 0)
58391+ if (0 > expand_downwards(bprm->vma, pos))
58392+ return NULL;
58393+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58394 return NULL;
58395
58396 if (write) {
58397@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58398 if (size <= ARG_MAX)
58399 return page;
58400
58401+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58402+ // only allow 512KB for argv+env on suid/sgid binaries
58403+ // to prevent easy ASLR exhaustion
58404+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58405+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58406+ (size > (512 * 1024))) {
58407+ put_page(page);
58408+ return NULL;
58409+ }
58410+#endif
58411+
58412 /*
58413 * Limit to 1/4-th the stack size for the argv+env strings.
58414 * This ensures that:
58415@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58416 vma->vm_end = STACK_TOP_MAX;
58417 vma->vm_start = vma->vm_end - PAGE_SIZE;
58418 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58419+
58420+#ifdef CONFIG_PAX_SEGMEXEC
58421+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58422+#endif
58423+
58424 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58425 INIT_LIST_HEAD(&vma->anon_vma_chain);
58426
58427@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58428 mm->stack_vm = mm->total_vm = 1;
58429 up_write(&mm->mmap_sem);
58430 bprm->p = vma->vm_end - sizeof(void *);
58431+
58432+#ifdef CONFIG_PAX_RANDUSTACK
58433+ if (randomize_va_space)
58434+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58435+#endif
58436+
58437 return 0;
58438 err:
58439 up_write(&mm->mmap_sem);
58440@@ -396,7 +437,7 @@ struct user_arg_ptr {
58441 } ptr;
58442 };
58443
58444-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58445+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58446 {
58447 const char __user *native;
58448
58449@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58450 compat_uptr_t compat;
58451
58452 if (get_user(compat, argv.ptr.compat + nr))
58453- return ERR_PTR(-EFAULT);
58454+ return (const char __force_user *)ERR_PTR(-EFAULT);
58455
58456 return compat_ptr(compat);
58457 }
58458 #endif
58459
58460 if (get_user(native, argv.ptr.native + nr))
58461- return ERR_PTR(-EFAULT);
58462+ return (const char __force_user *)ERR_PTR(-EFAULT);
58463
58464 return native;
58465 }
58466@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58467 if (!p)
58468 break;
58469
58470- if (IS_ERR(p))
58471+ if (IS_ERR((const char __force_kernel *)p))
58472 return -EFAULT;
58473
58474 if (i >= max)
58475@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58476
58477 ret = -EFAULT;
58478 str = get_user_arg_ptr(argv, argc);
58479- if (IS_ERR(str))
58480+ if (IS_ERR((const char __force_kernel *)str))
58481 goto out;
58482
58483 len = strnlen_user(str, MAX_ARG_STRLEN);
58484@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58485 int r;
58486 mm_segment_t oldfs = get_fs();
58487 struct user_arg_ptr argv = {
58488- .ptr.native = (const char __user *const __user *)__argv,
58489+ .ptr.native = (const char __user * const __force_user *)__argv,
58490 };
58491
58492 set_fs(KERNEL_DS);
58493@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58494 unsigned long new_end = old_end - shift;
58495 struct mmu_gather tlb;
58496
58497- BUG_ON(new_start > new_end);
58498+ if (new_start >= new_end || new_start < mmap_min_addr)
58499+ return -ENOMEM;
58500
58501 /*
58502 * ensure there are no vmas between where we want to go
58503@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58504 if (vma != find_vma(mm, new_start))
58505 return -EFAULT;
58506
58507+#ifdef CONFIG_PAX_SEGMEXEC
58508+ BUG_ON(pax_find_mirror_vma(vma));
58509+#endif
58510+
58511 /*
58512 * cover the whole range: [new_start, old_end)
58513 */
58514@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58515 stack_top = arch_align_stack(stack_top);
58516 stack_top = PAGE_ALIGN(stack_top);
58517
58518- if (unlikely(stack_top < mmap_min_addr) ||
58519- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58520- return -ENOMEM;
58521-
58522 stack_shift = vma->vm_end - stack_top;
58523
58524 bprm->p -= stack_shift;
58525@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58526 bprm->exec -= stack_shift;
58527
58528 down_write(&mm->mmap_sem);
58529+
58530+ /* Move stack pages down in memory. */
58531+ if (stack_shift) {
58532+ ret = shift_arg_pages(vma, stack_shift);
58533+ if (ret)
58534+ goto out_unlock;
58535+ }
58536+
58537 vm_flags = VM_STACK_FLAGS;
58538
58539+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58540+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58541+ vm_flags &= ~VM_EXEC;
58542+
58543+#ifdef CONFIG_PAX_MPROTECT
58544+ if (mm->pax_flags & MF_PAX_MPROTECT)
58545+ vm_flags &= ~VM_MAYEXEC;
58546+#endif
58547+
58548+ }
58549+#endif
58550+
58551 /*
58552 * Adjust stack execute permissions; explicitly enable for
58553 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58554@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58555 goto out_unlock;
58556 BUG_ON(prev != vma);
58557
58558- /* Move stack pages down in memory. */
58559- if (stack_shift) {
58560- ret = shift_arg_pages(vma, stack_shift);
58561- if (ret)
58562- goto out_unlock;
58563- }
58564-
58565 /* mprotect_fixup is overkill to remove the temporary stack flags */
58566 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58567
58568@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58569 #endif
58570 current->mm->start_stack = bprm->p;
58571 ret = expand_stack(vma, stack_base);
58572+
58573+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58574+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58575+ unsigned long size;
58576+ vm_flags_t vm_flags;
58577+
58578+ size = STACK_TOP - vma->vm_end;
58579+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58580+
58581+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58582+
58583+#ifdef CONFIG_X86
58584+ if (!ret) {
58585+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58586+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58587+ }
58588+#endif
58589+
58590+ }
58591+#endif
58592+
58593 if (ret)
58594 ret = -EFAULT;
58595
58596@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58597
58598 fsnotify_open(file);
58599
58600+ trace_open_exec(name->name);
58601+
58602 err = deny_write_access(file);
58603 if (err)
58604 goto exit;
58605@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58606 old_fs = get_fs();
58607 set_fs(get_ds());
58608 /* The cast to a user pointer is valid due to the set_fs() */
58609- result = vfs_read(file, (void __user *)addr, count, &pos);
58610+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58611 set_fs(old_fs);
58612 return result;
58613 }
58614@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58615 }
58616 rcu_read_unlock();
58617
58618- if (p->fs->users > n_fs)
58619+ if (atomic_read(&p->fs->users) > n_fs)
58620 bprm->unsafe |= LSM_UNSAFE_SHARE;
58621 else
58622 p->fs->in_exec = 1;
58623@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58624 return ret;
58625 }
58626
58627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58628+static DEFINE_PER_CPU(u64, exec_counter);
58629+static int __init init_exec_counters(void)
58630+{
58631+ unsigned int cpu;
58632+
58633+ for_each_possible_cpu(cpu) {
58634+ per_cpu(exec_counter, cpu) = (u64)cpu;
58635+ }
58636+
58637+ return 0;
58638+}
58639+early_initcall(init_exec_counters);
58640+static inline void increment_exec_counter(void)
58641+{
58642+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58643+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58644+}
58645+#else
58646+static inline void increment_exec_counter(void) {}
58647+#endif
58648+
58649+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58650+ struct user_arg_ptr argv);
58651+
58652 /*
58653 * sys_execve() executes a new program.
58654 */
58655@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58656 struct user_arg_ptr argv,
58657 struct user_arg_ptr envp)
58658 {
58659+#ifdef CONFIG_GRKERNSEC
58660+ struct file *old_exec_file;
58661+ struct acl_subject_label *old_acl;
58662+ struct rlimit old_rlim[RLIM_NLIMITS];
58663+#endif
58664 struct linux_binprm *bprm;
58665 struct file *file;
58666 struct files_struct *displaced;
58667@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58668 if (IS_ERR(filename))
58669 return PTR_ERR(filename);
58670
58671+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58672+
58673 /*
58674 * We move the actual failure in case of RLIMIT_NPROC excess from
58675 * set*uid() to execve() because too many poorly written programs
58676@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58677 if (IS_ERR(file))
58678 goto out_unmark;
58679
58680+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58681+ retval = -EPERM;
58682+ goto out_unmark;
58683+ }
58684+
58685 sched_exec();
58686
58687 bprm->file = file;
58688 bprm->filename = bprm->interp = filename->name;
58689
58690+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58691+ retval = -EACCES;
58692+ goto out_unmark;
58693+ }
58694+
58695 retval = bprm_mm_init(bprm);
58696 if (retval)
58697 goto out_unmark;
58698@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58699 if (retval < 0)
58700 goto out;
58701
58702+#ifdef CONFIG_GRKERNSEC
58703+ old_acl = current->acl;
58704+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58705+ old_exec_file = current->exec_file;
58706+ get_file(file);
58707+ current->exec_file = file;
58708+#endif
58709+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58710+ /* limit suid stack to 8MB
58711+ * we saved the old limits above and will restore them if this exec fails
58712+ */
58713+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58714+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58715+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58716+#endif
58717+
58718+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58719+ retval = -EPERM;
58720+ goto out_fail;
58721+ }
58722+
58723+ if (!gr_tpe_allow(file)) {
58724+ retval = -EACCES;
58725+ goto out_fail;
58726+ }
58727+
58728+ if (gr_check_crash_exec(file)) {
58729+ retval = -EACCES;
58730+ goto out_fail;
58731+ }
58732+
58733+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58734+ bprm->unsafe);
58735+ if (retval < 0)
58736+ goto out_fail;
58737+
58738 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58739 if (retval < 0)
58740- goto out;
58741+ goto out_fail;
58742
58743 bprm->exec = bprm->p;
58744 retval = copy_strings(bprm->envc, envp, bprm);
58745 if (retval < 0)
58746- goto out;
58747+ goto out_fail;
58748
58749 retval = copy_strings(bprm->argc, argv, bprm);
58750 if (retval < 0)
58751- goto out;
58752+ goto out_fail;
58753+
58754+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58755+
58756+ gr_handle_exec_args(bprm, argv);
58757
58758 retval = exec_binprm(bprm);
58759 if (retval < 0)
58760- goto out;
58761+ goto out_fail;
58762+#ifdef CONFIG_GRKERNSEC
58763+ if (old_exec_file)
58764+ fput(old_exec_file);
58765+#endif
58766
58767 /* execve succeeded */
58768+
58769+ increment_exec_counter();
58770 current->fs->in_exec = 0;
58771 current->in_execve = 0;
58772 acct_update_integrals(current);
58773@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58774 put_files_struct(displaced);
58775 return retval;
58776
58777+out_fail:
58778+#ifdef CONFIG_GRKERNSEC
58779+ current->acl = old_acl;
58780+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58781+ fput(current->exec_file);
58782+ current->exec_file = old_exec_file;
58783+#endif
58784+
58785 out:
58786 if (bprm->mm) {
58787 acct_arg_size(bprm, 0);
58788@@ -1626,3 +1800,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58789 return compat_do_execve(getname(filename), argv, envp);
58790 }
58791 #endif
58792+
58793+int pax_check_flags(unsigned long *flags)
58794+{
58795+ int retval = 0;
58796+
58797+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58798+ if (*flags & MF_PAX_SEGMEXEC)
58799+ {
58800+ *flags &= ~MF_PAX_SEGMEXEC;
58801+ retval = -EINVAL;
58802+ }
58803+#endif
58804+
58805+ if ((*flags & MF_PAX_PAGEEXEC)
58806+
58807+#ifdef CONFIG_PAX_PAGEEXEC
58808+ && (*flags & MF_PAX_SEGMEXEC)
58809+#endif
58810+
58811+ )
58812+ {
58813+ *flags &= ~MF_PAX_PAGEEXEC;
58814+ retval = -EINVAL;
58815+ }
58816+
58817+ if ((*flags & MF_PAX_MPROTECT)
58818+
58819+#ifdef CONFIG_PAX_MPROTECT
58820+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58821+#endif
58822+
58823+ )
58824+ {
58825+ *flags &= ~MF_PAX_MPROTECT;
58826+ retval = -EINVAL;
58827+ }
58828+
58829+ if ((*flags & MF_PAX_EMUTRAMP)
58830+
58831+#ifdef CONFIG_PAX_EMUTRAMP
58832+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58833+#endif
58834+
58835+ )
58836+ {
58837+ *flags &= ~MF_PAX_EMUTRAMP;
58838+ retval = -EINVAL;
58839+ }
58840+
58841+ return retval;
58842+}
58843+
58844+EXPORT_SYMBOL(pax_check_flags);
58845+
58846+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58847+char *pax_get_path(const struct path *path, char *buf, int buflen)
58848+{
58849+ char *pathname = d_path(path, buf, buflen);
58850+
58851+ if (IS_ERR(pathname))
58852+ goto toolong;
58853+
58854+ pathname = mangle_path(buf, pathname, "\t\n\\");
58855+ if (!pathname)
58856+ goto toolong;
58857+
58858+ *pathname = 0;
58859+ return buf;
58860+
58861+toolong:
58862+ return "<path too long>";
58863+}
58864+EXPORT_SYMBOL(pax_get_path);
58865+
58866+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58867+{
58868+ struct task_struct *tsk = current;
58869+ struct mm_struct *mm = current->mm;
58870+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58871+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58872+ char *path_exec = NULL;
58873+ char *path_fault = NULL;
58874+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58875+ siginfo_t info = { };
58876+
58877+ if (buffer_exec && buffer_fault) {
58878+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58879+
58880+ down_read(&mm->mmap_sem);
58881+ vma = mm->mmap;
58882+ while (vma && (!vma_exec || !vma_fault)) {
58883+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58884+ vma_exec = vma;
58885+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58886+ vma_fault = vma;
58887+ vma = vma->vm_next;
58888+ }
58889+ if (vma_exec)
58890+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58891+ if (vma_fault) {
58892+ start = vma_fault->vm_start;
58893+ end = vma_fault->vm_end;
58894+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58895+ if (vma_fault->vm_file)
58896+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58897+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58898+ path_fault = "<heap>";
58899+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58900+ path_fault = "<stack>";
58901+ else
58902+ path_fault = "<anonymous mapping>";
58903+ }
58904+ up_read(&mm->mmap_sem);
58905+ }
58906+ if (tsk->signal->curr_ip)
58907+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58908+ else
58909+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58910+ 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),
58911+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58912+ free_page((unsigned long)buffer_exec);
58913+ free_page((unsigned long)buffer_fault);
58914+ pax_report_insns(regs, pc, sp);
58915+ info.si_signo = SIGKILL;
58916+ info.si_errno = 0;
58917+ info.si_code = SI_KERNEL;
58918+ info.si_pid = 0;
58919+ info.si_uid = 0;
58920+ do_coredump(&info);
58921+}
58922+#endif
58923+
58924+#ifdef CONFIG_PAX_REFCOUNT
58925+void pax_report_refcount_overflow(struct pt_regs *regs)
58926+{
58927+ if (current->signal->curr_ip)
58928+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58929+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58930+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58931+ else
58932+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58933+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58934+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58935+ preempt_disable();
58936+ show_regs(regs);
58937+ preempt_enable();
58938+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58939+}
58940+#endif
58941+
58942+#ifdef CONFIG_PAX_USERCOPY
58943+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58944+static noinline int check_stack_object(const void *obj, unsigned long len)
58945+{
58946+ const void * const stack = task_stack_page(current);
58947+ const void * const stackend = stack + THREAD_SIZE;
58948+
58949+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58950+ const void *frame = NULL;
58951+ const void *oldframe;
58952+#endif
58953+
58954+ if (obj + len < obj)
58955+ return -1;
58956+
58957+ if (obj + len <= stack || stackend <= obj)
58958+ return 0;
58959+
58960+ if (obj < stack || stackend < obj + len)
58961+ return -1;
58962+
58963+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58964+ oldframe = __builtin_frame_address(1);
58965+ if (oldframe)
58966+ frame = __builtin_frame_address(2);
58967+ /*
58968+ low ----------------------------------------------> high
58969+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58970+ ^----------------^
58971+ allow copies only within here
58972+ */
58973+ while (stack <= frame && frame < stackend) {
58974+ /* if obj + len extends past the last frame, this
58975+ check won't pass and the next frame will be 0,
58976+ causing us to bail out and correctly report
58977+ the copy as invalid
58978+ */
58979+ if (obj + len <= frame)
58980+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58981+ oldframe = frame;
58982+ frame = *(const void * const *)frame;
58983+ }
58984+ return -1;
58985+#else
58986+ return 1;
58987+#endif
58988+}
58989+
58990+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58991+{
58992+ if (current->signal->curr_ip)
58993+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58994+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58995+ else
58996+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58997+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58998+ dump_stack();
58999+ gr_handle_kernel_exploit();
59000+ do_group_exit(SIGKILL);
59001+}
59002+#endif
59003+
59004+#ifdef CONFIG_PAX_USERCOPY
59005+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59006+{
59007+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59008+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59009+#ifdef CONFIG_MODULES
59010+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59011+#else
59012+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59013+#endif
59014+
59015+#else
59016+ unsigned long textlow = (unsigned long)_stext;
59017+ unsigned long texthigh = (unsigned long)_etext;
59018+
59019+#ifdef CONFIG_X86_64
59020+ /* check against linear mapping as well */
59021+ if (high > (unsigned long)__va(__pa(textlow)) &&
59022+ low < (unsigned long)__va(__pa(texthigh)))
59023+ return true;
59024+#endif
59025+
59026+#endif
59027+
59028+ if (high <= textlow || low >= texthigh)
59029+ return false;
59030+ else
59031+ return true;
59032+}
59033+#endif
59034+
59035+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59036+{
59037+
59038+#ifdef CONFIG_PAX_USERCOPY
59039+ const char *type;
59040+
59041+ if (!n)
59042+ return;
59043+
59044+ type = check_heap_object(ptr, n);
59045+ if (!type) {
59046+ int ret = check_stack_object(ptr, n);
59047+ if (ret == 1 || ret == 2)
59048+ return;
59049+ if (ret == 0) {
59050+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59051+ type = "<kernel text>";
59052+ else
59053+ return;
59054+ } else
59055+ type = "<process stack>";
59056+ }
59057+
59058+ pax_report_usercopy(ptr, n, to_user, type);
59059+#endif
59060+
59061+}
59062+EXPORT_SYMBOL(__check_object_size);
59063+
59064+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59065+void pax_track_stack(void)
59066+{
59067+ unsigned long sp = (unsigned long)&sp;
59068+ if (sp < current_thread_info()->lowest_stack &&
59069+ sp > (unsigned long)task_stack_page(current))
59070+ current_thread_info()->lowest_stack = sp;
59071+}
59072+EXPORT_SYMBOL(pax_track_stack);
59073+#endif
59074+
59075+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59076+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59077+{
59078+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59079+ dump_stack();
59080+ do_group_exit(SIGKILL);
59081+}
59082+EXPORT_SYMBOL(report_size_overflow);
59083+#endif
59084diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59085index 9f9992b..8b59411 100644
59086--- a/fs/ext2/balloc.c
59087+++ b/fs/ext2/balloc.c
59088@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59089
59090 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59091 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59092- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59093+ if (free_blocks < root_blocks + 1 &&
59094 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59095 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59096- !in_group_p (sbi->s_resgid))) {
59097+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59098 return 0;
59099 }
59100 return 1;
59101diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59102index 9142614..97484fa 100644
59103--- a/fs/ext2/xattr.c
59104+++ b/fs/ext2/xattr.c
59105@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59106 struct buffer_head *bh = NULL;
59107 struct ext2_xattr_entry *entry;
59108 char *end;
59109- size_t rest = buffer_size;
59110+ size_t rest = buffer_size, total_size = 0;
59111 int error;
59112
59113 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59114@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59115 buffer += size;
59116 }
59117 rest -= size;
59118+ total_size += size;
59119 }
59120 }
59121- error = buffer_size - rest; /* total size */
59122+ error = total_size;
59123
59124 cleanup:
59125 brelse(bh);
59126diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59127index 22548f5..41521d8 100644
59128--- a/fs/ext3/balloc.c
59129+++ b/fs/ext3/balloc.c
59130@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59131
59132 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59133 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59134- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59135+ if (free_blocks < root_blocks + 1 &&
59136 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59137 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59138- !in_group_p (sbi->s_resgid))) {
59139+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59140 return 0;
59141 }
59142 return 1;
59143diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59144index c6874be..f8a6ae8 100644
59145--- a/fs/ext3/xattr.c
59146+++ b/fs/ext3/xattr.c
59147@@ -330,7 +330,7 @@ static int
59148 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59149 char *buffer, size_t buffer_size)
59150 {
59151- size_t rest = buffer_size;
59152+ size_t rest = buffer_size, total_size = 0;
59153
59154 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59155 const struct xattr_handler *handler =
59156@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59157 buffer += size;
59158 }
59159 rest -= size;
59160+ total_size += size;
59161 }
59162 }
59163- return buffer_size - rest;
59164+ return total_size;
59165 }
59166
59167 static int
59168diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59169index 6ea7b14..8fa16d9 100644
59170--- a/fs/ext4/balloc.c
59171+++ b/fs/ext4/balloc.c
59172@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59173 /* Hm, nope. Are (enough) root reserved clusters available? */
59174 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59175 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59176- capable(CAP_SYS_RESOURCE) ||
59177- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59178+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59179+ capable_nolog(CAP_SYS_RESOURCE)) {
59180
59181 if (free_clusters >= (nclusters + dirty_clusters +
59182 resv_clusters))
59183diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59184index 3a603a8..9b868ba 100644
59185--- a/fs/ext4/ext4.h
59186+++ b/fs/ext4/ext4.h
59187@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59188 unsigned long s_mb_last_start;
59189
59190 /* stats for buddy allocator */
59191- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59192- atomic_t s_bal_success; /* we found long enough chunks */
59193- atomic_t s_bal_allocated; /* in blocks */
59194- atomic_t s_bal_ex_scanned; /* total extents scanned */
59195- atomic_t s_bal_goals; /* goal hits */
59196- atomic_t s_bal_breaks; /* too long searches */
59197- atomic_t s_bal_2orders; /* 2^order hits */
59198+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59199+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59200+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59201+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59202+ atomic_unchecked_t s_bal_goals; /* goal hits */
59203+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59204+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59205 spinlock_t s_bal_lock;
59206 unsigned long s_mb_buddies_generated;
59207 unsigned long long s_mb_generation_time;
59208- atomic_t s_mb_lost_chunks;
59209- atomic_t s_mb_preallocated;
59210- atomic_t s_mb_discarded;
59211+ atomic_unchecked_t s_mb_lost_chunks;
59212+ atomic_unchecked_t s_mb_preallocated;
59213+ atomic_unchecked_t s_mb_discarded;
59214 atomic_t s_lock_busy;
59215
59216 /* locality groups */
59217diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59218index 04a5c75..09894fa 100644
59219--- a/fs/ext4/mballoc.c
59220+++ b/fs/ext4/mballoc.c
59221@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59222 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59223
59224 if (EXT4_SB(sb)->s_mb_stats)
59225- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59226+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59227
59228 break;
59229 }
59230@@ -2189,7 +2189,7 @@ repeat:
59231 ac->ac_status = AC_STATUS_CONTINUE;
59232 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59233 cr = 3;
59234- atomic_inc(&sbi->s_mb_lost_chunks);
59235+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59236 goto repeat;
59237 }
59238 }
59239@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59240 if (sbi->s_mb_stats) {
59241 ext4_msg(sb, KERN_INFO,
59242 "mballoc: %u blocks %u reqs (%u success)",
59243- atomic_read(&sbi->s_bal_allocated),
59244- atomic_read(&sbi->s_bal_reqs),
59245- atomic_read(&sbi->s_bal_success));
59246+ atomic_read_unchecked(&sbi->s_bal_allocated),
59247+ atomic_read_unchecked(&sbi->s_bal_reqs),
59248+ atomic_read_unchecked(&sbi->s_bal_success));
59249 ext4_msg(sb, KERN_INFO,
59250 "mballoc: %u extents scanned, %u goal hits, "
59251 "%u 2^N hits, %u breaks, %u lost",
59252- atomic_read(&sbi->s_bal_ex_scanned),
59253- atomic_read(&sbi->s_bal_goals),
59254- atomic_read(&sbi->s_bal_2orders),
59255- atomic_read(&sbi->s_bal_breaks),
59256- atomic_read(&sbi->s_mb_lost_chunks));
59257+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59258+ atomic_read_unchecked(&sbi->s_bal_goals),
59259+ atomic_read_unchecked(&sbi->s_bal_2orders),
59260+ atomic_read_unchecked(&sbi->s_bal_breaks),
59261+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59262 ext4_msg(sb, KERN_INFO,
59263 "mballoc: %lu generated and it took %Lu",
59264 sbi->s_mb_buddies_generated,
59265 sbi->s_mb_generation_time);
59266 ext4_msg(sb, KERN_INFO,
59267 "mballoc: %u preallocated, %u discarded",
59268- atomic_read(&sbi->s_mb_preallocated),
59269- atomic_read(&sbi->s_mb_discarded));
59270+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59271+ atomic_read_unchecked(&sbi->s_mb_discarded));
59272 }
59273
59274 free_percpu(sbi->s_locality_groups);
59275@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59276 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59277
59278 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59279- atomic_inc(&sbi->s_bal_reqs);
59280- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59281+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59282+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59283 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59284- atomic_inc(&sbi->s_bal_success);
59285- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59286+ atomic_inc_unchecked(&sbi->s_bal_success);
59287+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59288 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59289 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59290- atomic_inc(&sbi->s_bal_goals);
59291+ atomic_inc_unchecked(&sbi->s_bal_goals);
59292 if (ac->ac_found > sbi->s_mb_max_to_scan)
59293- atomic_inc(&sbi->s_bal_breaks);
59294+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59295 }
59296
59297 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59298@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59299 trace_ext4_mb_new_inode_pa(ac, pa);
59300
59301 ext4_mb_use_inode_pa(ac, pa);
59302- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59303+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59304
59305 ei = EXT4_I(ac->ac_inode);
59306 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59307@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59308 trace_ext4_mb_new_group_pa(ac, pa);
59309
59310 ext4_mb_use_group_pa(ac, pa);
59311- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59312+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59313
59314 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59315 lg = ac->ac_lg;
59316@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59317 * from the bitmap and continue.
59318 */
59319 }
59320- atomic_add(free, &sbi->s_mb_discarded);
59321+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59322
59323 return err;
59324 }
59325@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59326 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59327 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59328 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59329- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59330+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59331 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59332
59333 return 0;
59334diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59335index 04434ad..6404663 100644
59336--- a/fs/ext4/mmp.c
59337+++ b/fs/ext4/mmp.c
59338@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59339 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59340 const char *function, unsigned int line, const char *msg)
59341 {
59342- __ext4_warning(sb, function, line, msg);
59343+ __ext4_warning(sb, function, line, "%s", msg);
59344 __ext4_warning(sb, function, line,
59345 "MMP failure info: last update time: %llu, last update "
59346 "node: %s, last update device: %s\n",
59347diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59348index 710fed2..a82e4e8 100644
59349--- a/fs/ext4/super.c
59350+++ b/fs/ext4/super.c
59351@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59352 }
59353
59354 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59355-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59356+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59357 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59358
59359 #ifdef CONFIG_QUOTA
59360@@ -2450,7 +2450,7 @@ struct ext4_attr {
59361 int offset;
59362 int deprecated_val;
59363 } u;
59364-};
59365+} __do_const;
59366
59367 static int parse_strtoull(const char *buf,
59368 unsigned long long max, unsigned long long *value)
59369diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59370index 55e611c..cfad16d 100644
59371--- a/fs/ext4/xattr.c
59372+++ b/fs/ext4/xattr.c
59373@@ -381,7 +381,7 @@ static int
59374 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59375 char *buffer, size_t buffer_size)
59376 {
59377- size_t rest = buffer_size;
59378+ size_t rest = buffer_size, total_size = 0;
59379
59380 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59381 const struct xattr_handler *handler =
59382@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59383 buffer += size;
59384 }
59385 rest -= size;
59386+ total_size += size;
59387 }
59388 }
59389- return buffer_size - rest;
59390+ return total_size;
59391 }
59392
59393 static int
59394diff --git a/fs/fcntl.c b/fs/fcntl.c
59395index ef68665..5deacdc 100644
59396--- a/fs/fcntl.c
59397+++ b/fs/fcntl.c
59398@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59399 if (err)
59400 return err;
59401
59402+ if (gr_handle_chroot_fowner(pid, type))
59403+ return -ENOENT;
59404+ if (gr_check_protected_task_fowner(pid, type))
59405+ return -EACCES;
59406+
59407 f_modown(filp, pid, type, force);
59408 return 0;
59409 }
59410diff --git a/fs/fhandle.c b/fs/fhandle.c
59411index 999ff5c..41f4109 100644
59412--- a/fs/fhandle.c
59413+++ b/fs/fhandle.c
59414@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59415 } else
59416 retval = 0;
59417 /* copy the mount id */
59418- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59419- sizeof(*mnt_id)) ||
59420+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59421 copy_to_user(ufh, handle,
59422 sizeof(struct file_handle) + handle_bytes))
59423 retval = -EFAULT;
59424diff --git a/fs/file.c b/fs/file.c
59425index eb56a13..ccee850 100644
59426--- a/fs/file.c
59427+++ b/fs/file.c
59428@@ -16,6 +16,7 @@
59429 #include <linux/slab.h>
59430 #include <linux/vmalloc.h>
59431 #include <linux/file.h>
59432+#include <linux/security.h>
59433 #include <linux/fdtable.h>
59434 #include <linux/bitops.h>
59435 #include <linux/interrupt.h>
59436@@ -141,7 +142,7 @@ out:
59437 * Return <0 error code on error; 1 on successful completion.
59438 * The files->file_lock should be held on entry, and will be held on exit.
59439 */
59440-static int expand_fdtable(struct files_struct *files, int nr)
59441+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59442 __releases(files->file_lock)
59443 __acquires(files->file_lock)
59444 {
59445@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59446 * expanded and execution may have blocked.
59447 * The files->file_lock should be held on entry, and will be held on exit.
59448 */
59449-static int expand_files(struct files_struct *files, int nr)
59450+static int expand_files(struct files_struct *files, unsigned int nr)
59451 {
59452 struct fdtable *fdt;
59453
59454@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59455 if (!file)
59456 return __close_fd(files, fd);
59457
59458+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59459 if (fd >= rlimit(RLIMIT_NOFILE))
59460 return -EBADF;
59461
59462@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59463 if (unlikely(oldfd == newfd))
59464 return -EINVAL;
59465
59466+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59467 if (newfd >= rlimit(RLIMIT_NOFILE))
59468 return -EBADF;
59469
59470@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59471 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59472 {
59473 int err;
59474+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59475 if (from >= rlimit(RLIMIT_NOFILE))
59476 return -EINVAL;
59477 err = alloc_fd(from, flags);
59478diff --git a/fs/filesystems.c b/fs/filesystems.c
59479index 92567d9..fcd8cbf 100644
59480--- a/fs/filesystems.c
59481+++ b/fs/filesystems.c
59482@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59483 int len = dot ? dot - name : strlen(name);
59484
59485 fs = __get_fs_type(name, len);
59486+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59487+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59488+#else
59489 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59490+#endif
59491 fs = __get_fs_type(name, len);
59492
59493 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59494diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59495index 7dca743..543d620 100644
59496--- a/fs/fs_struct.c
59497+++ b/fs/fs_struct.c
59498@@ -4,6 +4,7 @@
59499 #include <linux/path.h>
59500 #include <linux/slab.h>
59501 #include <linux/fs_struct.h>
59502+#include <linux/grsecurity.h>
59503 #include "internal.h"
59504
59505 /*
59506@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59507 write_seqcount_begin(&fs->seq);
59508 old_root = fs->root;
59509 fs->root = *path;
59510+ gr_set_chroot_entries(current, path);
59511 write_seqcount_end(&fs->seq);
59512 spin_unlock(&fs->lock);
59513 if (old_root.dentry)
59514@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59515 int hits = 0;
59516 spin_lock(&fs->lock);
59517 write_seqcount_begin(&fs->seq);
59518+ /* this root replacement is only done by pivot_root,
59519+ leave grsec's chroot tagging alone for this task
59520+ so that a pivoted root isn't treated as a chroot
59521+ */
59522 hits += replace_path(&fs->root, old_root, new_root);
59523 hits += replace_path(&fs->pwd, old_root, new_root);
59524 write_seqcount_end(&fs->seq);
59525@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59526 task_lock(tsk);
59527 spin_lock(&fs->lock);
59528 tsk->fs = NULL;
59529- kill = !--fs->users;
59530+ gr_clear_chroot_entries(tsk);
59531+ kill = !atomic_dec_return(&fs->users);
59532 spin_unlock(&fs->lock);
59533 task_unlock(tsk);
59534 if (kill)
59535@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59536 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59537 /* We don't need to lock fs - think why ;-) */
59538 if (fs) {
59539- fs->users = 1;
59540+ atomic_set(&fs->users, 1);
59541 fs->in_exec = 0;
59542 spin_lock_init(&fs->lock);
59543 seqcount_init(&fs->seq);
59544@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59545 spin_lock(&old->lock);
59546 fs->root = old->root;
59547 path_get(&fs->root);
59548+ /* instead of calling gr_set_chroot_entries here,
59549+ we call it from every caller of this function
59550+ */
59551 fs->pwd = old->pwd;
59552 path_get(&fs->pwd);
59553 spin_unlock(&old->lock);
59554@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59555
59556 task_lock(current);
59557 spin_lock(&fs->lock);
59558- kill = !--fs->users;
59559+ kill = !atomic_dec_return(&fs->users);
59560 current->fs = new_fs;
59561+ gr_set_chroot_entries(current, &new_fs->root);
59562 spin_unlock(&fs->lock);
59563 task_unlock(current);
59564
59565@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59566
59567 int current_umask(void)
59568 {
59569- return current->fs->umask;
59570+ return current->fs->umask | gr_acl_umask();
59571 }
59572 EXPORT_SYMBOL(current_umask);
59573
59574 /* to be mentioned only in INIT_TASK */
59575 struct fs_struct init_fs = {
59576- .users = 1,
59577+ .users = ATOMIC_INIT(1),
59578 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59579 .seq = SEQCNT_ZERO(init_fs.seq),
59580 .umask = 0022,
59581diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59582index 29d7feb..303644d 100644
59583--- a/fs/fscache/cookie.c
59584+++ b/fs/fscache/cookie.c
59585@@ -19,7 +19,7 @@
59586
59587 struct kmem_cache *fscache_cookie_jar;
59588
59589-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59590+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59591
59592 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59593 static int fscache_alloc_object(struct fscache_cache *cache,
59594@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59595 parent ? (char *) parent->def->name : "<no-parent>",
59596 def->name, netfs_data, enable);
59597
59598- fscache_stat(&fscache_n_acquires);
59599+ fscache_stat_unchecked(&fscache_n_acquires);
59600
59601 /* if there's no parent cookie, then we don't create one here either */
59602 if (!parent) {
59603- fscache_stat(&fscache_n_acquires_null);
59604+ fscache_stat_unchecked(&fscache_n_acquires_null);
59605 _leave(" [no parent]");
59606 return NULL;
59607 }
59608@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59609 /* allocate and initialise a cookie */
59610 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59611 if (!cookie) {
59612- fscache_stat(&fscache_n_acquires_oom);
59613+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59614 _leave(" [ENOMEM]");
59615 return NULL;
59616 }
59617@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59618
59619 switch (cookie->def->type) {
59620 case FSCACHE_COOKIE_TYPE_INDEX:
59621- fscache_stat(&fscache_n_cookie_index);
59622+ fscache_stat_unchecked(&fscache_n_cookie_index);
59623 break;
59624 case FSCACHE_COOKIE_TYPE_DATAFILE:
59625- fscache_stat(&fscache_n_cookie_data);
59626+ fscache_stat_unchecked(&fscache_n_cookie_data);
59627 break;
59628 default:
59629- fscache_stat(&fscache_n_cookie_special);
59630+ fscache_stat_unchecked(&fscache_n_cookie_special);
59631 break;
59632 }
59633
59634@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59635 } else {
59636 atomic_dec(&parent->n_children);
59637 __fscache_cookie_put(cookie);
59638- fscache_stat(&fscache_n_acquires_nobufs);
59639+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59640 _leave(" = NULL");
59641 return NULL;
59642 }
59643@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59644 }
59645 }
59646
59647- fscache_stat(&fscache_n_acquires_ok);
59648+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59649 _leave(" = %p", cookie);
59650 return cookie;
59651 }
59652@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59653 cache = fscache_select_cache_for_object(cookie->parent);
59654 if (!cache) {
59655 up_read(&fscache_addremove_sem);
59656- fscache_stat(&fscache_n_acquires_no_cache);
59657+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59658 _leave(" = -ENOMEDIUM [no cache]");
59659 return -ENOMEDIUM;
59660 }
59661@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59662 object = cache->ops->alloc_object(cache, cookie);
59663 fscache_stat_d(&fscache_n_cop_alloc_object);
59664 if (IS_ERR(object)) {
59665- fscache_stat(&fscache_n_object_no_alloc);
59666+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59667 ret = PTR_ERR(object);
59668 goto error;
59669 }
59670
59671- fscache_stat(&fscache_n_object_alloc);
59672+ fscache_stat_unchecked(&fscache_n_object_alloc);
59673
59674- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59675+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59676
59677 _debug("ALLOC OBJ%x: %s {%lx}",
59678 object->debug_id, cookie->def->name, object->events);
59679@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59680
59681 _enter("{%s}", cookie->def->name);
59682
59683- fscache_stat(&fscache_n_invalidates);
59684+ fscache_stat_unchecked(&fscache_n_invalidates);
59685
59686 /* Only permit invalidation of data files. Invalidating an index will
59687 * require the caller to release all its attachments to the tree rooted
59688@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59689 {
59690 struct fscache_object *object;
59691
59692- fscache_stat(&fscache_n_updates);
59693+ fscache_stat_unchecked(&fscache_n_updates);
59694
59695 if (!cookie) {
59696- fscache_stat(&fscache_n_updates_null);
59697+ fscache_stat_unchecked(&fscache_n_updates_null);
59698 _leave(" [no cookie]");
59699 return;
59700 }
59701@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59702 */
59703 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59704 {
59705- fscache_stat(&fscache_n_relinquishes);
59706+ fscache_stat_unchecked(&fscache_n_relinquishes);
59707 if (retire)
59708- fscache_stat(&fscache_n_relinquishes_retire);
59709+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59710
59711 if (!cookie) {
59712- fscache_stat(&fscache_n_relinquishes_null);
59713+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59714 _leave(" [no cookie]");
59715 return;
59716 }
59717@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59718 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59719 goto inconsistent;
59720
59721- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59722+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59723
59724 __fscache_use_cookie(cookie);
59725 if (fscache_submit_op(object, op) < 0)
59726diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59727index 4226f66..0fb3f45 100644
59728--- a/fs/fscache/internal.h
59729+++ b/fs/fscache/internal.h
59730@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59731 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59732 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59733 struct fscache_operation *,
59734- atomic_t *,
59735- atomic_t *,
59736+ atomic_unchecked_t *,
59737+ atomic_unchecked_t *,
59738 void (*)(struct fscache_operation *));
59739 extern void fscache_invalidate_writes(struct fscache_cookie *);
59740
59741@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59742 * stats.c
59743 */
59744 #ifdef CONFIG_FSCACHE_STATS
59745-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59746-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59747+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59748+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59749
59750-extern atomic_t fscache_n_op_pend;
59751-extern atomic_t fscache_n_op_run;
59752-extern atomic_t fscache_n_op_enqueue;
59753-extern atomic_t fscache_n_op_deferred_release;
59754-extern atomic_t fscache_n_op_release;
59755-extern atomic_t fscache_n_op_gc;
59756-extern atomic_t fscache_n_op_cancelled;
59757-extern atomic_t fscache_n_op_rejected;
59758+extern atomic_unchecked_t fscache_n_op_pend;
59759+extern atomic_unchecked_t fscache_n_op_run;
59760+extern atomic_unchecked_t fscache_n_op_enqueue;
59761+extern atomic_unchecked_t fscache_n_op_deferred_release;
59762+extern atomic_unchecked_t fscache_n_op_release;
59763+extern atomic_unchecked_t fscache_n_op_gc;
59764+extern atomic_unchecked_t fscache_n_op_cancelled;
59765+extern atomic_unchecked_t fscache_n_op_rejected;
59766
59767-extern atomic_t fscache_n_attr_changed;
59768-extern atomic_t fscache_n_attr_changed_ok;
59769-extern atomic_t fscache_n_attr_changed_nobufs;
59770-extern atomic_t fscache_n_attr_changed_nomem;
59771-extern atomic_t fscache_n_attr_changed_calls;
59772+extern atomic_unchecked_t fscache_n_attr_changed;
59773+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59774+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59775+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59776+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59777
59778-extern atomic_t fscache_n_allocs;
59779-extern atomic_t fscache_n_allocs_ok;
59780-extern atomic_t fscache_n_allocs_wait;
59781-extern atomic_t fscache_n_allocs_nobufs;
59782-extern atomic_t fscache_n_allocs_intr;
59783-extern atomic_t fscache_n_allocs_object_dead;
59784-extern atomic_t fscache_n_alloc_ops;
59785-extern atomic_t fscache_n_alloc_op_waits;
59786+extern atomic_unchecked_t fscache_n_allocs;
59787+extern atomic_unchecked_t fscache_n_allocs_ok;
59788+extern atomic_unchecked_t fscache_n_allocs_wait;
59789+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59790+extern atomic_unchecked_t fscache_n_allocs_intr;
59791+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59792+extern atomic_unchecked_t fscache_n_alloc_ops;
59793+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59794
59795-extern atomic_t fscache_n_retrievals;
59796-extern atomic_t fscache_n_retrievals_ok;
59797-extern atomic_t fscache_n_retrievals_wait;
59798-extern atomic_t fscache_n_retrievals_nodata;
59799-extern atomic_t fscache_n_retrievals_nobufs;
59800-extern atomic_t fscache_n_retrievals_intr;
59801-extern atomic_t fscache_n_retrievals_nomem;
59802-extern atomic_t fscache_n_retrievals_object_dead;
59803-extern atomic_t fscache_n_retrieval_ops;
59804-extern atomic_t fscache_n_retrieval_op_waits;
59805+extern atomic_unchecked_t fscache_n_retrievals;
59806+extern atomic_unchecked_t fscache_n_retrievals_ok;
59807+extern atomic_unchecked_t fscache_n_retrievals_wait;
59808+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59809+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59810+extern atomic_unchecked_t fscache_n_retrievals_intr;
59811+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59812+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59813+extern atomic_unchecked_t fscache_n_retrieval_ops;
59814+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59815
59816-extern atomic_t fscache_n_stores;
59817-extern atomic_t fscache_n_stores_ok;
59818-extern atomic_t fscache_n_stores_again;
59819-extern atomic_t fscache_n_stores_nobufs;
59820-extern atomic_t fscache_n_stores_oom;
59821-extern atomic_t fscache_n_store_ops;
59822-extern atomic_t fscache_n_store_calls;
59823-extern atomic_t fscache_n_store_pages;
59824-extern atomic_t fscache_n_store_radix_deletes;
59825-extern atomic_t fscache_n_store_pages_over_limit;
59826+extern atomic_unchecked_t fscache_n_stores;
59827+extern atomic_unchecked_t fscache_n_stores_ok;
59828+extern atomic_unchecked_t fscache_n_stores_again;
59829+extern atomic_unchecked_t fscache_n_stores_nobufs;
59830+extern atomic_unchecked_t fscache_n_stores_oom;
59831+extern atomic_unchecked_t fscache_n_store_ops;
59832+extern atomic_unchecked_t fscache_n_store_calls;
59833+extern atomic_unchecked_t fscache_n_store_pages;
59834+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59835+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59836
59837-extern atomic_t fscache_n_store_vmscan_not_storing;
59838-extern atomic_t fscache_n_store_vmscan_gone;
59839-extern atomic_t fscache_n_store_vmscan_busy;
59840-extern atomic_t fscache_n_store_vmscan_cancelled;
59841-extern atomic_t fscache_n_store_vmscan_wait;
59842+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59843+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59844+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59845+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59846+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59847
59848-extern atomic_t fscache_n_marks;
59849-extern atomic_t fscache_n_uncaches;
59850+extern atomic_unchecked_t fscache_n_marks;
59851+extern atomic_unchecked_t fscache_n_uncaches;
59852
59853-extern atomic_t fscache_n_acquires;
59854-extern atomic_t fscache_n_acquires_null;
59855-extern atomic_t fscache_n_acquires_no_cache;
59856-extern atomic_t fscache_n_acquires_ok;
59857-extern atomic_t fscache_n_acquires_nobufs;
59858-extern atomic_t fscache_n_acquires_oom;
59859+extern atomic_unchecked_t fscache_n_acquires;
59860+extern atomic_unchecked_t fscache_n_acquires_null;
59861+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59862+extern atomic_unchecked_t fscache_n_acquires_ok;
59863+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59864+extern atomic_unchecked_t fscache_n_acquires_oom;
59865
59866-extern atomic_t fscache_n_invalidates;
59867-extern atomic_t fscache_n_invalidates_run;
59868+extern atomic_unchecked_t fscache_n_invalidates;
59869+extern atomic_unchecked_t fscache_n_invalidates_run;
59870
59871-extern atomic_t fscache_n_updates;
59872-extern atomic_t fscache_n_updates_null;
59873-extern atomic_t fscache_n_updates_run;
59874+extern atomic_unchecked_t fscache_n_updates;
59875+extern atomic_unchecked_t fscache_n_updates_null;
59876+extern atomic_unchecked_t fscache_n_updates_run;
59877
59878-extern atomic_t fscache_n_relinquishes;
59879-extern atomic_t fscache_n_relinquishes_null;
59880-extern atomic_t fscache_n_relinquishes_waitcrt;
59881-extern atomic_t fscache_n_relinquishes_retire;
59882+extern atomic_unchecked_t fscache_n_relinquishes;
59883+extern atomic_unchecked_t fscache_n_relinquishes_null;
59884+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59885+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59886
59887-extern atomic_t fscache_n_cookie_index;
59888-extern atomic_t fscache_n_cookie_data;
59889-extern atomic_t fscache_n_cookie_special;
59890+extern atomic_unchecked_t fscache_n_cookie_index;
59891+extern atomic_unchecked_t fscache_n_cookie_data;
59892+extern atomic_unchecked_t fscache_n_cookie_special;
59893
59894-extern atomic_t fscache_n_object_alloc;
59895-extern atomic_t fscache_n_object_no_alloc;
59896-extern atomic_t fscache_n_object_lookups;
59897-extern atomic_t fscache_n_object_lookups_negative;
59898-extern atomic_t fscache_n_object_lookups_positive;
59899-extern atomic_t fscache_n_object_lookups_timed_out;
59900-extern atomic_t fscache_n_object_created;
59901-extern atomic_t fscache_n_object_avail;
59902-extern atomic_t fscache_n_object_dead;
59903+extern atomic_unchecked_t fscache_n_object_alloc;
59904+extern atomic_unchecked_t fscache_n_object_no_alloc;
59905+extern atomic_unchecked_t fscache_n_object_lookups;
59906+extern atomic_unchecked_t fscache_n_object_lookups_negative;
59907+extern atomic_unchecked_t fscache_n_object_lookups_positive;
59908+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59909+extern atomic_unchecked_t fscache_n_object_created;
59910+extern atomic_unchecked_t fscache_n_object_avail;
59911+extern atomic_unchecked_t fscache_n_object_dead;
59912
59913-extern atomic_t fscache_n_checkaux_none;
59914-extern atomic_t fscache_n_checkaux_okay;
59915-extern atomic_t fscache_n_checkaux_update;
59916-extern atomic_t fscache_n_checkaux_obsolete;
59917+extern atomic_unchecked_t fscache_n_checkaux_none;
59918+extern atomic_unchecked_t fscache_n_checkaux_okay;
59919+extern atomic_unchecked_t fscache_n_checkaux_update;
59920+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59921
59922 extern atomic_t fscache_n_cop_alloc_object;
59923 extern atomic_t fscache_n_cop_lookup_object;
59924@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59925 atomic_inc(stat);
59926 }
59927
59928+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59929+{
59930+ atomic_inc_unchecked(stat);
59931+}
59932+
59933 static inline void fscache_stat_d(atomic_t *stat)
59934 {
59935 atomic_dec(stat);
59936@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59937
59938 #define __fscache_stat(stat) (NULL)
59939 #define fscache_stat(stat) do {} while (0)
59940+#define fscache_stat_unchecked(stat) do {} while (0)
59941 #define fscache_stat_d(stat) do {} while (0)
59942 #endif
59943
59944diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59945index d3b4539..ed0c659 100644
59946--- a/fs/fscache/object.c
59947+++ b/fs/fscache/object.c
59948@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59949 _debug("LOOKUP \"%s\" in \"%s\"",
59950 cookie->def->name, object->cache->tag->name);
59951
59952- fscache_stat(&fscache_n_object_lookups);
59953+ fscache_stat_unchecked(&fscache_n_object_lookups);
59954 fscache_stat(&fscache_n_cop_lookup_object);
59955 ret = object->cache->ops->lookup_object(object);
59956 fscache_stat_d(&fscache_n_cop_lookup_object);
59957@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59958 if (ret == -ETIMEDOUT) {
59959 /* probably stuck behind another object, so move this one to
59960 * the back of the queue */
59961- fscache_stat(&fscache_n_object_lookups_timed_out);
59962+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59963 _leave(" [timeout]");
59964 return NO_TRANSIT;
59965 }
59966@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59967 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59968
59969 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59970- fscache_stat(&fscache_n_object_lookups_negative);
59971+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59972
59973 /* Allow write requests to begin stacking up and read requests to begin
59974 * returning ENODATA.
59975@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
59976 /* if we were still looking up, then we must have a positive lookup
59977 * result, in which case there may be data available */
59978 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59979- fscache_stat(&fscache_n_object_lookups_positive);
59980+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59981
59982 /* We do (presumably) have data */
59983 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59984@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
59985 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59986 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59987 } else {
59988- fscache_stat(&fscache_n_object_created);
59989+ fscache_stat_unchecked(&fscache_n_object_created);
59990 }
59991
59992 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59993@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59994 fscache_stat_d(&fscache_n_cop_lookup_complete);
59995
59996 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59997- fscache_stat(&fscache_n_object_avail);
59998+ fscache_stat_unchecked(&fscache_n_object_avail);
59999
60000 _leave("");
60001 return transit_to(JUMPSTART_DEPS);
60002@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60003
60004 /* this just shifts the object release to the work processor */
60005 fscache_put_object(object);
60006- fscache_stat(&fscache_n_object_dead);
60007+ fscache_stat_unchecked(&fscache_n_object_dead);
60008
60009 _leave("");
60010 return transit_to(OBJECT_DEAD);
60011@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60012 enum fscache_checkaux result;
60013
60014 if (!object->cookie->def->check_aux) {
60015- fscache_stat(&fscache_n_checkaux_none);
60016+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60017 return FSCACHE_CHECKAUX_OKAY;
60018 }
60019
60020@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60021 switch (result) {
60022 /* entry okay as is */
60023 case FSCACHE_CHECKAUX_OKAY:
60024- fscache_stat(&fscache_n_checkaux_okay);
60025+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60026 break;
60027
60028 /* entry requires update */
60029 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60030- fscache_stat(&fscache_n_checkaux_update);
60031+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60032 break;
60033
60034 /* entry requires deletion */
60035 case FSCACHE_CHECKAUX_OBSOLETE:
60036- fscache_stat(&fscache_n_checkaux_obsolete);
60037+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60038 break;
60039
60040 default:
60041@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60042 {
60043 const struct fscache_state *s;
60044
60045- fscache_stat(&fscache_n_invalidates_run);
60046+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60047 fscache_stat(&fscache_n_cop_invalidate_object);
60048 s = _fscache_invalidate_object(object, event);
60049 fscache_stat_d(&fscache_n_cop_invalidate_object);
60050@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60051 {
60052 _enter("{OBJ%x},%d", object->debug_id, event);
60053
60054- fscache_stat(&fscache_n_updates_run);
60055+ fscache_stat_unchecked(&fscache_n_updates_run);
60056 fscache_stat(&fscache_n_cop_update_object);
60057 object->cache->ops->update_object(object);
60058 fscache_stat_d(&fscache_n_cop_update_object);
60059diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60060index 318071a..379938b 100644
60061--- a/fs/fscache/operation.c
60062+++ b/fs/fscache/operation.c
60063@@ -17,7 +17,7 @@
60064 #include <linux/slab.h>
60065 #include "internal.h"
60066
60067-atomic_t fscache_op_debug_id;
60068+atomic_unchecked_t fscache_op_debug_id;
60069 EXPORT_SYMBOL(fscache_op_debug_id);
60070
60071 /**
60072@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60073 ASSERTCMP(atomic_read(&op->usage), >, 0);
60074 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60075
60076- fscache_stat(&fscache_n_op_enqueue);
60077+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60078 switch (op->flags & FSCACHE_OP_TYPE) {
60079 case FSCACHE_OP_ASYNC:
60080 _debug("queue async");
60081@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60082 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60083 if (op->processor)
60084 fscache_enqueue_operation(op);
60085- fscache_stat(&fscache_n_op_run);
60086+ fscache_stat_unchecked(&fscache_n_op_run);
60087 }
60088
60089 /*
60090@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60091 if (object->n_in_progress > 0) {
60092 atomic_inc(&op->usage);
60093 list_add_tail(&op->pend_link, &object->pending_ops);
60094- fscache_stat(&fscache_n_op_pend);
60095+ fscache_stat_unchecked(&fscache_n_op_pend);
60096 } else if (!list_empty(&object->pending_ops)) {
60097 atomic_inc(&op->usage);
60098 list_add_tail(&op->pend_link, &object->pending_ops);
60099- fscache_stat(&fscache_n_op_pend);
60100+ fscache_stat_unchecked(&fscache_n_op_pend);
60101 fscache_start_operations(object);
60102 } else {
60103 ASSERTCMP(object->n_in_progress, ==, 0);
60104@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60105 object->n_exclusive++; /* reads and writes must wait */
60106 atomic_inc(&op->usage);
60107 list_add_tail(&op->pend_link, &object->pending_ops);
60108- fscache_stat(&fscache_n_op_pend);
60109+ fscache_stat_unchecked(&fscache_n_op_pend);
60110 ret = 0;
60111 } else {
60112 /* If we're in any other state, there must have been an I/O
60113@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60114 if (object->n_exclusive > 0) {
60115 atomic_inc(&op->usage);
60116 list_add_tail(&op->pend_link, &object->pending_ops);
60117- fscache_stat(&fscache_n_op_pend);
60118+ fscache_stat_unchecked(&fscache_n_op_pend);
60119 } else if (!list_empty(&object->pending_ops)) {
60120 atomic_inc(&op->usage);
60121 list_add_tail(&op->pend_link, &object->pending_ops);
60122- fscache_stat(&fscache_n_op_pend);
60123+ fscache_stat_unchecked(&fscache_n_op_pend);
60124 fscache_start_operations(object);
60125 } else {
60126 ASSERTCMP(object->n_exclusive, ==, 0);
60127@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60128 object->n_ops++;
60129 atomic_inc(&op->usage);
60130 list_add_tail(&op->pend_link, &object->pending_ops);
60131- fscache_stat(&fscache_n_op_pend);
60132+ fscache_stat_unchecked(&fscache_n_op_pend);
60133 ret = 0;
60134 } else if (fscache_object_is_dying(object)) {
60135- fscache_stat(&fscache_n_op_rejected);
60136+ fscache_stat_unchecked(&fscache_n_op_rejected);
60137 op->state = FSCACHE_OP_ST_CANCELLED;
60138 ret = -ENOBUFS;
60139 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60140@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60141 ret = -EBUSY;
60142 if (op->state == FSCACHE_OP_ST_PENDING) {
60143 ASSERT(!list_empty(&op->pend_link));
60144- fscache_stat(&fscache_n_op_cancelled);
60145+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60146 list_del_init(&op->pend_link);
60147 if (do_cancel)
60148 do_cancel(op);
60149@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60150 while (!list_empty(&object->pending_ops)) {
60151 op = list_entry(object->pending_ops.next,
60152 struct fscache_operation, pend_link);
60153- fscache_stat(&fscache_n_op_cancelled);
60154+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60155 list_del_init(&op->pend_link);
60156
60157 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60158@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60159 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60160 op->state = FSCACHE_OP_ST_DEAD;
60161
60162- fscache_stat(&fscache_n_op_release);
60163+ fscache_stat_unchecked(&fscache_n_op_release);
60164
60165 if (op->release) {
60166 op->release(op);
60167@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60168 * lock, and defer it otherwise */
60169 if (!spin_trylock(&object->lock)) {
60170 _debug("defer put");
60171- fscache_stat(&fscache_n_op_deferred_release);
60172+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60173
60174 cache = object->cache;
60175 spin_lock(&cache->op_gc_list_lock);
60176@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60177
60178 _debug("GC DEFERRED REL OBJ%x OP%x",
60179 object->debug_id, op->debug_id);
60180- fscache_stat(&fscache_n_op_gc);
60181+ fscache_stat_unchecked(&fscache_n_op_gc);
60182
60183 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60184 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60185diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60186index 7f5c658..6c1e164 100644
60187--- a/fs/fscache/page.c
60188+++ b/fs/fscache/page.c
60189@@ -61,7 +61,7 @@ try_again:
60190 val = radix_tree_lookup(&cookie->stores, page->index);
60191 if (!val) {
60192 rcu_read_unlock();
60193- fscache_stat(&fscache_n_store_vmscan_not_storing);
60194+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60195 __fscache_uncache_page(cookie, page);
60196 return true;
60197 }
60198@@ -91,11 +91,11 @@ try_again:
60199 spin_unlock(&cookie->stores_lock);
60200
60201 if (xpage) {
60202- fscache_stat(&fscache_n_store_vmscan_cancelled);
60203- fscache_stat(&fscache_n_store_radix_deletes);
60204+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60205+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60206 ASSERTCMP(xpage, ==, page);
60207 } else {
60208- fscache_stat(&fscache_n_store_vmscan_gone);
60209+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60210 }
60211
60212 wake_up_bit(&cookie->flags, 0);
60213@@ -110,11 +110,11 @@ page_busy:
60214 * sleeping on memory allocation, so we may need to impose a timeout
60215 * too. */
60216 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60217- fscache_stat(&fscache_n_store_vmscan_busy);
60218+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60219 return false;
60220 }
60221
60222- fscache_stat(&fscache_n_store_vmscan_wait);
60223+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60224 __fscache_wait_on_page_write(cookie, page);
60225 gfp &= ~__GFP_WAIT;
60226 goto try_again;
60227@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60228 FSCACHE_COOKIE_STORING_TAG);
60229 if (!radix_tree_tag_get(&cookie->stores, page->index,
60230 FSCACHE_COOKIE_PENDING_TAG)) {
60231- fscache_stat(&fscache_n_store_radix_deletes);
60232+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60233 xpage = radix_tree_delete(&cookie->stores, page->index);
60234 }
60235 spin_unlock(&cookie->stores_lock);
60236@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60237
60238 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60239
60240- fscache_stat(&fscache_n_attr_changed_calls);
60241+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60242
60243 if (fscache_object_is_active(object)) {
60244 fscache_stat(&fscache_n_cop_attr_changed);
60245@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60246
60247 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60248
60249- fscache_stat(&fscache_n_attr_changed);
60250+ fscache_stat_unchecked(&fscache_n_attr_changed);
60251
60252 op = kzalloc(sizeof(*op), GFP_KERNEL);
60253 if (!op) {
60254- fscache_stat(&fscache_n_attr_changed_nomem);
60255+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60256 _leave(" = -ENOMEM");
60257 return -ENOMEM;
60258 }
60259@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60260 if (fscache_submit_exclusive_op(object, op) < 0)
60261 goto nobufs;
60262 spin_unlock(&cookie->lock);
60263- fscache_stat(&fscache_n_attr_changed_ok);
60264+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60265 fscache_put_operation(op);
60266 _leave(" = 0");
60267 return 0;
60268@@ -225,7 +225,7 @@ nobufs:
60269 kfree(op);
60270 if (wake_cookie)
60271 __fscache_wake_unused_cookie(cookie);
60272- fscache_stat(&fscache_n_attr_changed_nobufs);
60273+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60274 _leave(" = %d", -ENOBUFS);
60275 return -ENOBUFS;
60276 }
60277@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60278 /* allocate a retrieval operation and attempt to submit it */
60279 op = kzalloc(sizeof(*op), GFP_NOIO);
60280 if (!op) {
60281- fscache_stat(&fscache_n_retrievals_nomem);
60282+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60283 return NULL;
60284 }
60285
60286@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60287 return 0;
60288 }
60289
60290- fscache_stat(&fscache_n_retrievals_wait);
60291+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60292
60293 jif = jiffies;
60294 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60295 fscache_wait_bit_interruptible,
60296 TASK_INTERRUPTIBLE) != 0) {
60297- fscache_stat(&fscache_n_retrievals_intr);
60298+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60299 _leave(" = -ERESTARTSYS");
60300 return -ERESTARTSYS;
60301 }
60302@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60303 */
60304 int fscache_wait_for_operation_activation(struct fscache_object *object,
60305 struct fscache_operation *op,
60306- atomic_t *stat_op_waits,
60307- atomic_t *stat_object_dead,
60308+ atomic_unchecked_t *stat_op_waits,
60309+ atomic_unchecked_t *stat_object_dead,
60310 void (*do_cancel)(struct fscache_operation *))
60311 {
60312 int ret;
60313@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60314
60315 _debug(">>> WT");
60316 if (stat_op_waits)
60317- fscache_stat(stat_op_waits);
60318+ fscache_stat_unchecked(stat_op_waits);
60319 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60320 fscache_wait_bit_interruptible,
60321 TASK_INTERRUPTIBLE) != 0) {
60322@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60323 check_if_dead:
60324 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60325 if (stat_object_dead)
60326- fscache_stat(stat_object_dead);
60327+ fscache_stat_unchecked(stat_object_dead);
60328 _leave(" = -ENOBUFS [cancelled]");
60329 return -ENOBUFS;
60330 }
60331@@ -366,7 +366,7 @@ check_if_dead:
60332 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60333 fscache_cancel_op(op, do_cancel);
60334 if (stat_object_dead)
60335- fscache_stat(stat_object_dead);
60336+ fscache_stat_unchecked(stat_object_dead);
60337 return -ENOBUFS;
60338 }
60339 return 0;
60340@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60341
60342 _enter("%p,%p,,,", cookie, page);
60343
60344- fscache_stat(&fscache_n_retrievals);
60345+ fscache_stat_unchecked(&fscache_n_retrievals);
60346
60347 if (hlist_empty(&cookie->backing_objects))
60348 goto nobufs;
60349@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60350 goto nobufs_unlock_dec;
60351 spin_unlock(&cookie->lock);
60352
60353- fscache_stat(&fscache_n_retrieval_ops);
60354+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60355
60356 /* pin the netfs read context in case we need to do the actual netfs
60357 * read because we've encountered a cache read failure */
60358@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60359
60360 error:
60361 if (ret == -ENOMEM)
60362- fscache_stat(&fscache_n_retrievals_nomem);
60363+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60364 else if (ret == -ERESTARTSYS)
60365- fscache_stat(&fscache_n_retrievals_intr);
60366+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60367 else if (ret == -ENODATA)
60368- fscache_stat(&fscache_n_retrievals_nodata);
60369+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60370 else if (ret < 0)
60371- fscache_stat(&fscache_n_retrievals_nobufs);
60372+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60373 else
60374- fscache_stat(&fscache_n_retrievals_ok);
60375+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60376
60377 fscache_put_retrieval(op);
60378 _leave(" = %d", ret);
60379@@ -490,7 +490,7 @@ nobufs_unlock:
60380 __fscache_wake_unused_cookie(cookie);
60381 kfree(op);
60382 nobufs:
60383- fscache_stat(&fscache_n_retrievals_nobufs);
60384+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60385 _leave(" = -ENOBUFS");
60386 return -ENOBUFS;
60387 }
60388@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60389
60390 _enter("%p,,%d,,,", cookie, *nr_pages);
60391
60392- fscache_stat(&fscache_n_retrievals);
60393+ fscache_stat_unchecked(&fscache_n_retrievals);
60394
60395 if (hlist_empty(&cookie->backing_objects))
60396 goto nobufs;
60397@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60398 goto nobufs_unlock_dec;
60399 spin_unlock(&cookie->lock);
60400
60401- fscache_stat(&fscache_n_retrieval_ops);
60402+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60403
60404 /* pin the netfs read context in case we need to do the actual netfs
60405 * read because we've encountered a cache read failure */
60406@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60407
60408 error:
60409 if (ret == -ENOMEM)
60410- fscache_stat(&fscache_n_retrievals_nomem);
60411+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60412 else if (ret == -ERESTARTSYS)
60413- fscache_stat(&fscache_n_retrievals_intr);
60414+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60415 else if (ret == -ENODATA)
60416- fscache_stat(&fscache_n_retrievals_nodata);
60417+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60418 else if (ret < 0)
60419- fscache_stat(&fscache_n_retrievals_nobufs);
60420+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60421 else
60422- fscache_stat(&fscache_n_retrievals_ok);
60423+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60424
60425 fscache_put_retrieval(op);
60426 _leave(" = %d", ret);
60427@@ -621,7 +621,7 @@ nobufs_unlock:
60428 if (wake_cookie)
60429 __fscache_wake_unused_cookie(cookie);
60430 nobufs:
60431- fscache_stat(&fscache_n_retrievals_nobufs);
60432+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60433 _leave(" = -ENOBUFS");
60434 return -ENOBUFS;
60435 }
60436@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60437
60438 _enter("%p,%p,,,", cookie, page);
60439
60440- fscache_stat(&fscache_n_allocs);
60441+ fscache_stat_unchecked(&fscache_n_allocs);
60442
60443 if (hlist_empty(&cookie->backing_objects))
60444 goto nobufs;
60445@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60446 goto nobufs_unlock_dec;
60447 spin_unlock(&cookie->lock);
60448
60449- fscache_stat(&fscache_n_alloc_ops);
60450+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60451
60452 ret = fscache_wait_for_operation_activation(
60453 object, &op->op,
60454@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60455
60456 error:
60457 if (ret == -ERESTARTSYS)
60458- fscache_stat(&fscache_n_allocs_intr);
60459+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60460 else if (ret < 0)
60461- fscache_stat(&fscache_n_allocs_nobufs);
60462+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60463 else
60464- fscache_stat(&fscache_n_allocs_ok);
60465+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60466
60467 fscache_put_retrieval(op);
60468 _leave(" = %d", ret);
60469@@ -715,7 +715,7 @@ nobufs_unlock:
60470 if (wake_cookie)
60471 __fscache_wake_unused_cookie(cookie);
60472 nobufs:
60473- fscache_stat(&fscache_n_allocs_nobufs);
60474+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60475 _leave(" = -ENOBUFS");
60476 return -ENOBUFS;
60477 }
60478@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60479
60480 spin_lock(&cookie->stores_lock);
60481
60482- fscache_stat(&fscache_n_store_calls);
60483+ fscache_stat_unchecked(&fscache_n_store_calls);
60484
60485 /* find a page to store */
60486 page = NULL;
60487@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60488 page = results[0];
60489 _debug("gang %d [%lx]", n, page->index);
60490 if (page->index > op->store_limit) {
60491- fscache_stat(&fscache_n_store_pages_over_limit);
60492+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60493 goto superseded;
60494 }
60495
60496@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60497 spin_unlock(&cookie->stores_lock);
60498 spin_unlock(&object->lock);
60499
60500- fscache_stat(&fscache_n_store_pages);
60501+ fscache_stat_unchecked(&fscache_n_store_pages);
60502 fscache_stat(&fscache_n_cop_write_page);
60503 ret = object->cache->ops->write_page(op, page);
60504 fscache_stat_d(&fscache_n_cop_write_page);
60505@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60506 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60507 ASSERT(PageFsCache(page));
60508
60509- fscache_stat(&fscache_n_stores);
60510+ fscache_stat_unchecked(&fscache_n_stores);
60511
60512 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60513 _leave(" = -ENOBUFS [invalidating]");
60514@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60515 spin_unlock(&cookie->stores_lock);
60516 spin_unlock(&object->lock);
60517
60518- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60519+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60520 op->store_limit = object->store_limit;
60521
60522 __fscache_use_cookie(cookie);
60523@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60524
60525 spin_unlock(&cookie->lock);
60526 radix_tree_preload_end();
60527- fscache_stat(&fscache_n_store_ops);
60528- fscache_stat(&fscache_n_stores_ok);
60529+ fscache_stat_unchecked(&fscache_n_store_ops);
60530+ fscache_stat_unchecked(&fscache_n_stores_ok);
60531
60532 /* the work queue now carries its own ref on the object */
60533 fscache_put_operation(&op->op);
60534@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60535 return 0;
60536
60537 already_queued:
60538- fscache_stat(&fscache_n_stores_again);
60539+ fscache_stat_unchecked(&fscache_n_stores_again);
60540 already_pending:
60541 spin_unlock(&cookie->stores_lock);
60542 spin_unlock(&object->lock);
60543 spin_unlock(&cookie->lock);
60544 radix_tree_preload_end();
60545 kfree(op);
60546- fscache_stat(&fscache_n_stores_ok);
60547+ fscache_stat_unchecked(&fscache_n_stores_ok);
60548 _leave(" = 0");
60549 return 0;
60550
60551@@ -1024,14 +1024,14 @@ nobufs:
60552 kfree(op);
60553 if (wake_cookie)
60554 __fscache_wake_unused_cookie(cookie);
60555- fscache_stat(&fscache_n_stores_nobufs);
60556+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60557 _leave(" = -ENOBUFS");
60558 return -ENOBUFS;
60559
60560 nomem_free:
60561 kfree(op);
60562 nomem:
60563- fscache_stat(&fscache_n_stores_oom);
60564+ fscache_stat_unchecked(&fscache_n_stores_oom);
60565 _leave(" = -ENOMEM");
60566 return -ENOMEM;
60567 }
60568@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60569 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60570 ASSERTCMP(page, !=, NULL);
60571
60572- fscache_stat(&fscache_n_uncaches);
60573+ fscache_stat_unchecked(&fscache_n_uncaches);
60574
60575 /* cache withdrawal may beat us to it */
60576 if (!PageFsCache(page))
60577@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60578 struct fscache_cookie *cookie = op->op.object->cookie;
60579
60580 #ifdef CONFIG_FSCACHE_STATS
60581- atomic_inc(&fscache_n_marks);
60582+ atomic_inc_unchecked(&fscache_n_marks);
60583 #endif
60584
60585 _debug("- mark %p{%lx}", page, page->index);
60586diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60587index 40d13c7..ddf52b9 100644
60588--- a/fs/fscache/stats.c
60589+++ b/fs/fscache/stats.c
60590@@ -18,99 +18,99 @@
60591 /*
60592 * operation counters
60593 */
60594-atomic_t fscache_n_op_pend;
60595-atomic_t fscache_n_op_run;
60596-atomic_t fscache_n_op_enqueue;
60597-atomic_t fscache_n_op_requeue;
60598-atomic_t fscache_n_op_deferred_release;
60599-atomic_t fscache_n_op_release;
60600-atomic_t fscache_n_op_gc;
60601-atomic_t fscache_n_op_cancelled;
60602-atomic_t fscache_n_op_rejected;
60603+atomic_unchecked_t fscache_n_op_pend;
60604+atomic_unchecked_t fscache_n_op_run;
60605+atomic_unchecked_t fscache_n_op_enqueue;
60606+atomic_unchecked_t fscache_n_op_requeue;
60607+atomic_unchecked_t fscache_n_op_deferred_release;
60608+atomic_unchecked_t fscache_n_op_release;
60609+atomic_unchecked_t fscache_n_op_gc;
60610+atomic_unchecked_t fscache_n_op_cancelled;
60611+atomic_unchecked_t fscache_n_op_rejected;
60612
60613-atomic_t fscache_n_attr_changed;
60614-atomic_t fscache_n_attr_changed_ok;
60615-atomic_t fscache_n_attr_changed_nobufs;
60616-atomic_t fscache_n_attr_changed_nomem;
60617-atomic_t fscache_n_attr_changed_calls;
60618+atomic_unchecked_t fscache_n_attr_changed;
60619+atomic_unchecked_t fscache_n_attr_changed_ok;
60620+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60621+atomic_unchecked_t fscache_n_attr_changed_nomem;
60622+atomic_unchecked_t fscache_n_attr_changed_calls;
60623
60624-atomic_t fscache_n_allocs;
60625-atomic_t fscache_n_allocs_ok;
60626-atomic_t fscache_n_allocs_wait;
60627-atomic_t fscache_n_allocs_nobufs;
60628-atomic_t fscache_n_allocs_intr;
60629-atomic_t fscache_n_allocs_object_dead;
60630-atomic_t fscache_n_alloc_ops;
60631-atomic_t fscache_n_alloc_op_waits;
60632+atomic_unchecked_t fscache_n_allocs;
60633+atomic_unchecked_t fscache_n_allocs_ok;
60634+atomic_unchecked_t fscache_n_allocs_wait;
60635+atomic_unchecked_t fscache_n_allocs_nobufs;
60636+atomic_unchecked_t fscache_n_allocs_intr;
60637+atomic_unchecked_t fscache_n_allocs_object_dead;
60638+atomic_unchecked_t fscache_n_alloc_ops;
60639+atomic_unchecked_t fscache_n_alloc_op_waits;
60640
60641-atomic_t fscache_n_retrievals;
60642-atomic_t fscache_n_retrievals_ok;
60643-atomic_t fscache_n_retrievals_wait;
60644-atomic_t fscache_n_retrievals_nodata;
60645-atomic_t fscache_n_retrievals_nobufs;
60646-atomic_t fscache_n_retrievals_intr;
60647-atomic_t fscache_n_retrievals_nomem;
60648-atomic_t fscache_n_retrievals_object_dead;
60649-atomic_t fscache_n_retrieval_ops;
60650-atomic_t fscache_n_retrieval_op_waits;
60651+atomic_unchecked_t fscache_n_retrievals;
60652+atomic_unchecked_t fscache_n_retrievals_ok;
60653+atomic_unchecked_t fscache_n_retrievals_wait;
60654+atomic_unchecked_t fscache_n_retrievals_nodata;
60655+atomic_unchecked_t fscache_n_retrievals_nobufs;
60656+atomic_unchecked_t fscache_n_retrievals_intr;
60657+atomic_unchecked_t fscache_n_retrievals_nomem;
60658+atomic_unchecked_t fscache_n_retrievals_object_dead;
60659+atomic_unchecked_t fscache_n_retrieval_ops;
60660+atomic_unchecked_t fscache_n_retrieval_op_waits;
60661
60662-atomic_t fscache_n_stores;
60663-atomic_t fscache_n_stores_ok;
60664-atomic_t fscache_n_stores_again;
60665-atomic_t fscache_n_stores_nobufs;
60666-atomic_t fscache_n_stores_oom;
60667-atomic_t fscache_n_store_ops;
60668-atomic_t fscache_n_store_calls;
60669-atomic_t fscache_n_store_pages;
60670-atomic_t fscache_n_store_radix_deletes;
60671-atomic_t fscache_n_store_pages_over_limit;
60672+atomic_unchecked_t fscache_n_stores;
60673+atomic_unchecked_t fscache_n_stores_ok;
60674+atomic_unchecked_t fscache_n_stores_again;
60675+atomic_unchecked_t fscache_n_stores_nobufs;
60676+atomic_unchecked_t fscache_n_stores_oom;
60677+atomic_unchecked_t fscache_n_store_ops;
60678+atomic_unchecked_t fscache_n_store_calls;
60679+atomic_unchecked_t fscache_n_store_pages;
60680+atomic_unchecked_t fscache_n_store_radix_deletes;
60681+atomic_unchecked_t fscache_n_store_pages_over_limit;
60682
60683-atomic_t fscache_n_store_vmscan_not_storing;
60684-atomic_t fscache_n_store_vmscan_gone;
60685-atomic_t fscache_n_store_vmscan_busy;
60686-atomic_t fscache_n_store_vmscan_cancelled;
60687-atomic_t fscache_n_store_vmscan_wait;
60688+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60689+atomic_unchecked_t fscache_n_store_vmscan_gone;
60690+atomic_unchecked_t fscache_n_store_vmscan_busy;
60691+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60692+atomic_unchecked_t fscache_n_store_vmscan_wait;
60693
60694-atomic_t fscache_n_marks;
60695-atomic_t fscache_n_uncaches;
60696+atomic_unchecked_t fscache_n_marks;
60697+atomic_unchecked_t fscache_n_uncaches;
60698
60699-atomic_t fscache_n_acquires;
60700-atomic_t fscache_n_acquires_null;
60701-atomic_t fscache_n_acquires_no_cache;
60702-atomic_t fscache_n_acquires_ok;
60703-atomic_t fscache_n_acquires_nobufs;
60704-atomic_t fscache_n_acquires_oom;
60705+atomic_unchecked_t fscache_n_acquires;
60706+atomic_unchecked_t fscache_n_acquires_null;
60707+atomic_unchecked_t fscache_n_acquires_no_cache;
60708+atomic_unchecked_t fscache_n_acquires_ok;
60709+atomic_unchecked_t fscache_n_acquires_nobufs;
60710+atomic_unchecked_t fscache_n_acquires_oom;
60711
60712-atomic_t fscache_n_invalidates;
60713-atomic_t fscache_n_invalidates_run;
60714+atomic_unchecked_t fscache_n_invalidates;
60715+atomic_unchecked_t fscache_n_invalidates_run;
60716
60717-atomic_t fscache_n_updates;
60718-atomic_t fscache_n_updates_null;
60719-atomic_t fscache_n_updates_run;
60720+atomic_unchecked_t fscache_n_updates;
60721+atomic_unchecked_t fscache_n_updates_null;
60722+atomic_unchecked_t fscache_n_updates_run;
60723
60724-atomic_t fscache_n_relinquishes;
60725-atomic_t fscache_n_relinquishes_null;
60726-atomic_t fscache_n_relinquishes_waitcrt;
60727-atomic_t fscache_n_relinquishes_retire;
60728+atomic_unchecked_t fscache_n_relinquishes;
60729+atomic_unchecked_t fscache_n_relinquishes_null;
60730+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60731+atomic_unchecked_t fscache_n_relinquishes_retire;
60732
60733-atomic_t fscache_n_cookie_index;
60734-atomic_t fscache_n_cookie_data;
60735-atomic_t fscache_n_cookie_special;
60736+atomic_unchecked_t fscache_n_cookie_index;
60737+atomic_unchecked_t fscache_n_cookie_data;
60738+atomic_unchecked_t fscache_n_cookie_special;
60739
60740-atomic_t fscache_n_object_alloc;
60741-atomic_t fscache_n_object_no_alloc;
60742-atomic_t fscache_n_object_lookups;
60743-atomic_t fscache_n_object_lookups_negative;
60744-atomic_t fscache_n_object_lookups_positive;
60745-atomic_t fscache_n_object_lookups_timed_out;
60746-atomic_t fscache_n_object_created;
60747-atomic_t fscache_n_object_avail;
60748-atomic_t fscache_n_object_dead;
60749+atomic_unchecked_t fscache_n_object_alloc;
60750+atomic_unchecked_t fscache_n_object_no_alloc;
60751+atomic_unchecked_t fscache_n_object_lookups;
60752+atomic_unchecked_t fscache_n_object_lookups_negative;
60753+atomic_unchecked_t fscache_n_object_lookups_positive;
60754+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60755+atomic_unchecked_t fscache_n_object_created;
60756+atomic_unchecked_t fscache_n_object_avail;
60757+atomic_unchecked_t fscache_n_object_dead;
60758
60759-atomic_t fscache_n_checkaux_none;
60760-atomic_t fscache_n_checkaux_okay;
60761-atomic_t fscache_n_checkaux_update;
60762-atomic_t fscache_n_checkaux_obsolete;
60763+atomic_unchecked_t fscache_n_checkaux_none;
60764+atomic_unchecked_t fscache_n_checkaux_okay;
60765+atomic_unchecked_t fscache_n_checkaux_update;
60766+atomic_unchecked_t fscache_n_checkaux_obsolete;
60767
60768 atomic_t fscache_n_cop_alloc_object;
60769 atomic_t fscache_n_cop_lookup_object;
60770@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60771 seq_puts(m, "FS-Cache statistics\n");
60772
60773 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60774- atomic_read(&fscache_n_cookie_index),
60775- atomic_read(&fscache_n_cookie_data),
60776- atomic_read(&fscache_n_cookie_special));
60777+ atomic_read_unchecked(&fscache_n_cookie_index),
60778+ atomic_read_unchecked(&fscache_n_cookie_data),
60779+ atomic_read_unchecked(&fscache_n_cookie_special));
60780
60781 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60782- atomic_read(&fscache_n_object_alloc),
60783- atomic_read(&fscache_n_object_no_alloc),
60784- atomic_read(&fscache_n_object_avail),
60785- atomic_read(&fscache_n_object_dead));
60786+ atomic_read_unchecked(&fscache_n_object_alloc),
60787+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60788+ atomic_read_unchecked(&fscache_n_object_avail),
60789+ atomic_read_unchecked(&fscache_n_object_dead));
60790 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60791- atomic_read(&fscache_n_checkaux_none),
60792- atomic_read(&fscache_n_checkaux_okay),
60793- atomic_read(&fscache_n_checkaux_update),
60794- atomic_read(&fscache_n_checkaux_obsolete));
60795+ atomic_read_unchecked(&fscache_n_checkaux_none),
60796+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60797+ atomic_read_unchecked(&fscache_n_checkaux_update),
60798+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60799
60800 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60801- atomic_read(&fscache_n_marks),
60802- atomic_read(&fscache_n_uncaches));
60803+ atomic_read_unchecked(&fscache_n_marks),
60804+ atomic_read_unchecked(&fscache_n_uncaches));
60805
60806 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60807 " oom=%u\n",
60808- atomic_read(&fscache_n_acquires),
60809- atomic_read(&fscache_n_acquires_null),
60810- atomic_read(&fscache_n_acquires_no_cache),
60811- atomic_read(&fscache_n_acquires_ok),
60812- atomic_read(&fscache_n_acquires_nobufs),
60813- atomic_read(&fscache_n_acquires_oom));
60814+ atomic_read_unchecked(&fscache_n_acquires),
60815+ atomic_read_unchecked(&fscache_n_acquires_null),
60816+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60817+ atomic_read_unchecked(&fscache_n_acquires_ok),
60818+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60819+ atomic_read_unchecked(&fscache_n_acquires_oom));
60820
60821 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60822- atomic_read(&fscache_n_object_lookups),
60823- atomic_read(&fscache_n_object_lookups_negative),
60824- atomic_read(&fscache_n_object_lookups_positive),
60825- atomic_read(&fscache_n_object_created),
60826- atomic_read(&fscache_n_object_lookups_timed_out));
60827+ atomic_read_unchecked(&fscache_n_object_lookups),
60828+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60829+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60830+ atomic_read_unchecked(&fscache_n_object_created),
60831+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60832
60833 seq_printf(m, "Invals : n=%u run=%u\n",
60834- atomic_read(&fscache_n_invalidates),
60835- atomic_read(&fscache_n_invalidates_run));
60836+ atomic_read_unchecked(&fscache_n_invalidates),
60837+ atomic_read_unchecked(&fscache_n_invalidates_run));
60838
60839 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60840- atomic_read(&fscache_n_updates),
60841- atomic_read(&fscache_n_updates_null),
60842- atomic_read(&fscache_n_updates_run));
60843+ atomic_read_unchecked(&fscache_n_updates),
60844+ atomic_read_unchecked(&fscache_n_updates_null),
60845+ atomic_read_unchecked(&fscache_n_updates_run));
60846
60847 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60848- atomic_read(&fscache_n_relinquishes),
60849- atomic_read(&fscache_n_relinquishes_null),
60850- atomic_read(&fscache_n_relinquishes_waitcrt),
60851- atomic_read(&fscache_n_relinquishes_retire));
60852+ atomic_read_unchecked(&fscache_n_relinquishes),
60853+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60854+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60855+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60856
60857 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60858- atomic_read(&fscache_n_attr_changed),
60859- atomic_read(&fscache_n_attr_changed_ok),
60860- atomic_read(&fscache_n_attr_changed_nobufs),
60861- atomic_read(&fscache_n_attr_changed_nomem),
60862- atomic_read(&fscache_n_attr_changed_calls));
60863+ atomic_read_unchecked(&fscache_n_attr_changed),
60864+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60865+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60866+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60867+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60868
60869 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60870- atomic_read(&fscache_n_allocs),
60871- atomic_read(&fscache_n_allocs_ok),
60872- atomic_read(&fscache_n_allocs_wait),
60873- atomic_read(&fscache_n_allocs_nobufs),
60874- atomic_read(&fscache_n_allocs_intr));
60875+ atomic_read_unchecked(&fscache_n_allocs),
60876+ atomic_read_unchecked(&fscache_n_allocs_ok),
60877+ atomic_read_unchecked(&fscache_n_allocs_wait),
60878+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60879+ atomic_read_unchecked(&fscache_n_allocs_intr));
60880 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60881- atomic_read(&fscache_n_alloc_ops),
60882- atomic_read(&fscache_n_alloc_op_waits),
60883- atomic_read(&fscache_n_allocs_object_dead));
60884+ atomic_read_unchecked(&fscache_n_alloc_ops),
60885+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60886+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60887
60888 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60889 " int=%u oom=%u\n",
60890- atomic_read(&fscache_n_retrievals),
60891- atomic_read(&fscache_n_retrievals_ok),
60892- atomic_read(&fscache_n_retrievals_wait),
60893- atomic_read(&fscache_n_retrievals_nodata),
60894- atomic_read(&fscache_n_retrievals_nobufs),
60895- atomic_read(&fscache_n_retrievals_intr),
60896- atomic_read(&fscache_n_retrievals_nomem));
60897+ atomic_read_unchecked(&fscache_n_retrievals),
60898+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60899+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60900+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60901+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60902+ atomic_read_unchecked(&fscache_n_retrievals_intr),
60903+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
60904 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60905- atomic_read(&fscache_n_retrieval_ops),
60906- atomic_read(&fscache_n_retrieval_op_waits),
60907- atomic_read(&fscache_n_retrievals_object_dead));
60908+ atomic_read_unchecked(&fscache_n_retrieval_ops),
60909+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60910+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60911
60912 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60913- atomic_read(&fscache_n_stores),
60914- atomic_read(&fscache_n_stores_ok),
60915- atomic_read(&fscache_n_stores_again),
60916- atomic_read(&fscache_n_stores_nobufs),
60917- atomic_read(&fscache_n_stores_oom));
60918+ atomic_read_unchecked(&fscache_n_stores),
60919+ atomic_read_unchecked(&fscache_n_stores_ok),
60920+ atomic_read_unchecked(&fscache_n_stores_again),
60921+ atomic_read_unchecked(&fscache_n_stores_nobufs),
60922+ atomic_read_unchecked(&fscache_n_stores_oom));
60923 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60924- atomic_read(&fscache_n_store_ops),
60925- atomic_read(&fscache_n_store_calls),
60926- atomic_read(&fscache_n_store_pages),
60927- atomic_read(&fscache_n_store_radix_deletes),
60928- atomic_read(&fscache_n_store_pages_over_limit));
60929+ atomic_read_unchecked(&fscache_n_store_ops),
60930+ atomic_read_unchecked(&fscache_n_store_calls),
60931+ atomic_read_unchecked(&fscache_n_store_pages),
60932+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
60933+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60934
60935 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60936- atomic_read(&fscache_n_store_vmscan_not_storing),
60937- atomic_read(&fscache_n_store_vmscan_gone),
60938- atomic_read(&fscache_n_store_vmscan_busy),
60939- atomic_read(&fscache_n_store_vmscan_cancelled),
60940- atomic_read(&fscache_n_store_vmscan_wait));
60941+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60942+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60943+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60944+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60945+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60946
60947 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60948- atomic_read(&fscache_n_op_pend),
60949- atomic_read(&fscache_n_op_run),
60950- atomic_read(&fscache_n_op_enqueue),
60951- atomic_read(&fscache_n_op_cancelled),
60952- atomic_read(&fscache_n_op_rejected));
60953+ atomic_read_unchecked(&fscache_n_op_pend),
60954+ atomic_read_unchecked(&fscache_n_op_run),
60955+ atomic_read_unchecked(&fscache_n_op_enqueue),
60956+ atomic_read_unchecked(&fscache_n_op_cancelled),
60957+ atomic_read_unchecked(&fscache_n_op_rejected));
60958 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60959- atomic_read(&fscache_n_op_deferred_release),
60960- atomic_read(&fscache_n_op_release),
60961- atomic_read(&fscache_n_op_gc));
60962+ atomic_read_unchecked(&fscache_n_op_deferred_release),
60963+ atomic_read_unchecked(&fscache_n_op_release),
60964+ atomic_read_unchecked(&fscache_n_op_gc));
60965
60966 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60967 atomic_read(&fscache_n_cop_alloc_object),
60968diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60969index b96a49b..9bfdc47 100644
60970--- a/fs/fuse/cuse.c
60971+++ b/fs/fuse/cuse.c
60972@@ -606,10 +606,12 @@ static int __init cuse_init(void)
60973 INIT_LIST_HEAD(&cuse_conntbl[i]);
60974
60975 /* inherit and extend fuse_dev_operations */
60976- cuse_channel_fops = fuse_dev_operations;
60977- cuse_channel_fops.owner = THIS_MODULE;
60978- cuse_channel_fops.open = cuse_channel_open;
60979- cuse_channel_fops.release = cuse_channel_release;
60980+ pax_open_kernel();
60981+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60982+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60983+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
60984+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
60985+ pax_close_kernel();
60986
60987 cuse_class = class_create(THIS_MODULE, "cuse");
60988 if (IS_ERR(cuse_class))
60989diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60990index 0a648bb..8d463f1 100644
60991--- a/fs/fuse/dev.c
60992+++ b/fs/fuse/dev.c
60993@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60994 ret = 0;
60995 pipe_lock(pipe);
60996
60997- if (!pipe->readers) {
60998+ if (!atomic_read(&pipe->readers)) {
60999 send_sig(SIGPIPE, current, 0);
61000 if (!ret)
61001 ret = -EPIPE;
61002@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61003 page_nr++;
61004 ret += buf->len;
61005
61006- if (pipe->files)
61007+ if (atomic_read(&pipe->files))
61008 do_wakeup = 1;
61009 }
61010
61011diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61012index 1d1292c..bba17ea 100644
61013--- a/fs/fuse/dir.c
61014+++ b/fs/fuse/dir.c
61015@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61016 return link;
61017 }
61018
61019-static void free_link(char *link)
61020+static void free_link(const char *link)
61021 {
61022 if (!IS_ERR(link))
61023 free_page((unsigned long) link);
61024diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61025index fe649d3..c679164 100644
61026--- a/fs/hostfs/hostfs_kern.c
61027+++ b/fs/hostfs/hostfs_kern.c
61028@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61029
61030 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61031 {
61032- char *s = nd_get_link(nd);
61033+ const char *s = nd_get_link(nd);
61034 if (!IS_ERR(s))
61035 __putname(s);
61036 }
61037diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61038index d19b30a..ef89c36 100644
61039--- a/fs/hugetlbfs/inode.c
61040+++ b/fs/hugetlbfs/inode.c
61041@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61042 struct mm_struct *mm = current->mm;
61043 struct vm_area_struct *vma;
61044 struct hstate *h = hstate_file(file);
61045+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61046 struct vm_unmapped_area_info info;
61047
61048 if (len & ~huge_page_mask(h))
61049@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61050 return addr;
61051 }
61052
61053+#ifdef CONFIG_PAX_RANDMMAP
61054+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61055+#endif
61056+
61057 if (addr) {
61058 addr = ALIGN(addr, huge_page_size(h));
61059 vma = find_vma(mm, addr);
61060- if (TASK_SIZE - len >= addr &&
61061- (!vma || addr + len <= vma->vm_start))
61062+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61063 return addr;
61064 }
61065
61066 info.flags = 0;
61067 info.length = len;
61068 info.low_limit = TASK_UNMAPPED_BASE;
61069+
61070+#ifdef CONFIG_PAX_RANDMMAP
61071+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61072+ info.low_limit += mm->delta_mmap;
61073+#endif
61074+
61075 info.high_limit = TASK_SIZE;
61076 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61077 info.align_offset = 0;
61078@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61079 };
61080 MODULE_ALIAS_FS("hugetlbfs");
61081
61082-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61083+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61084
61085 static int can_do_hugetlb_shm(void)
61086 {
61087diff --git a/fs/inode.c b/fs/inode.c
61088index 4bcdad3..1883822 100644
61089--- a/fs/inode.c
61090+++ b/fs/inode.c
61091@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61092
61093 #ifdef CONFIG_SMP
61094 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61095- static atomic_t shared_last_ino;
61096- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61097+ static atomic_unchecked_t shared_last_ino;
61098+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61099
61100 res = next - LAST_INO_BATCH;
61101 }
61102diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61103index 4a6cf28..d3a29d3 100644
61104--- a/fs/jffs2/erase.c
61105+++ b/fs/jffs2/erase.c
61106@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61107 struct jffs2_unknown_node marker = {
61108 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61109 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61110- .totlen = cpu_to_je32(c->cleanmarker_size)
61111+ .totlen = cpu_to_je32(c->cleanmarker_size),
61112+ .hdr_crc = cpu_to_je32(0)
61113 };
61114
61115 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61116diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61117index a6597d6..41b30ec 100644
61118--- a/fs/jffs2/wbuf.c
61119+++ b/fs/jffs2/wbuf.c
61120@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61121 {
61122 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61123 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61124- .totlen = constant_cpu_to_je32(8)
61125+ .totlen = constant_cpu_to_je32(8),
61126+ .hdr_crc = constant_cpu_to_je32(0)
61127 };
61128
61129 /*
61130diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61131index e2b7483..855bca3 100644
61132--- a/fs/jfs/super.c
61133+++ b/fs/jfs/super.c
61134@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61135
61136 jfs_inode_cachep =
61137 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61138- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61139+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61140 init_once);
61141 if (jfs_inode_cachep == NULL)
61142 return -ENOMEM;
61143diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61144index 39c0143..d54fad4 100644
61145--- a/fs/kernfs/dir.c
61146+++ b/fs/kernfs/dir.c
61147@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61148 *
61149 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61150 */
61151-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61152+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61153 {
61154 unsigned long hash = init_name_hash();
61155 unsigned int len = strlen(name);
61156diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61157index dbf397b..d624b48 100644
61158--- a/fs/kernfs/file.c
61159+++ b/fs/kernfs/file.c
61160@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61161
61162 struct kernfs_open_node {
61163 atomic_t refcnt;
61164- atomic_t event;
61165+ atomic_unchecked_t event;
61166 wait_queue_head_t poll;
61167 struct list_head files; /* goes through kernfs_open_file.list */
61168 };
61169@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61170 {
61171 struct kernfs_open_file *of = sf->private;
61172
61173- of->event = atomic_read(&of->kn->attr.open->event);
61174+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61175
61176 return of->kn->attr.ops->seq_show(sf, v);
61177 }
61178@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61179 return ret;
61180 }
61181
61182-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61183- void *buf, int len, int write)
61184+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61185+ void *buf, size_t len, int write)
61186 {
61187 struct file *file = vma->vm_file;
61188 struct kernfs_open_file *of = kernfs_of(file);
61189- int ret;
61190+ ssize_t ret;
61191
61192 if (!of->vm_ops)
61193 return -EINVAL;
61194@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61195 return -ENOMEM;
61196
61197 atomic_set(&new_on->refcnt, 0);
61198- atomic_set(&new_on->event, 1);
61199+ atomic_set_unchecked(&new_on->event, 1);
61200 init_waitqueue_head(&new_on->poll);
61201 INIT_LIST_HEAD(&new_on->files);
61202 goto retry;
61203@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61204
61205 kernfs_put_active(kn);
61206
61207- if (of->event != atomic_read(&on->event))
61208+ if (of->event != atomic_read_unchecked(&on->event))
61209 goto trigger;
61210
61211 return DEFAULT_POLLMASK;
61212@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61213 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61214 on = kn->attr.open;
61215 if (on) {
61216- atomic_inc(&on->event);
61217+ atomic_inc_unchecked(&on->event);
61218 wake_up_interruptible(&on->poll);
61219 }
61220 }
61221diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61222index 4d45705..b35e0bd 100644
61223--- a/fs/kernfs/symlink.c
61224+++ b/fs/kernfs/symlink.c
61225@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61226 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61227 void *cookie)
61228 {
61229- char *page = nd_get_link(nd);
61230+ const char *page = nd_get_link(nd);
61231 if (!IS_ERR(page))
61232 free_page((unsigned long)page);
61233 }
61234diff --git a/fs/libfs.c b/fs/libfs.c
61235index a184424..944ddce 100644
61236--- a/fs/libfs.c
61237+++ b/fs/libfs.c
61238@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61239
61240 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61241 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61242+ char d_name[sizeof(next->d_iname)];
61243+ const unsigned char *name;
61244+
61245 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61246 if (!simple_positive(next)) {
61247 spin_unlock(&next->d_lock);
61248@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61249
61250 spin_unlock(&next->d_lock);
61251 spin_unlock(&dentry->d_lock);
61252- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61253+ name = next->d_name.name;
61254+ if (name == next->d_iname) {
61255+ memcpy(d_name, name, next->d_name.len);
61256+ name = d_name;
61257+ }
61258+ if (!dir_emit(ctx, name, next->d_name.len,
61259 next->d_inode->i_ino, dt_type(next->d_inode)))
61260 return 0;
61261 spin_lock(&dentry->d_lock);
61262@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61263 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61264 void *cookie)
61265 {
61266- char *s = nd_get_link(nd);
61267+ const char *s = nd_get_link(nd);
61268 if (!IS_ERR(s))
61269 kfree(s);
61270 }
61271diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61272index acd3947..1f896e2 100644
61273--- a/fs/lockd/clntproc.c
61274+++ b/fs/lockd/clntproc.c
61275@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61276 /*
61277 * Cookie counter for NLM requests
61278 */
61279-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61280+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61281
61282 void nlmclnt_next_cookie(struct nlm_cookie *c)
61283 {
61284- u32 cookie = atomic_inc_return(&nlm_cookie);
61285+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61286
61287 memcpy(c->data, &cookie, 4);
61288 c->len=4;
61289diff --git a/fs/locks.c b/fs/locks.c
61290index 92a0f0a..45a48f0 100644
61291--- a/fs/locks.c
61292+++ b/fs/locks.c
61293@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61294 return;
61295
61296 if (filp->f_op->flock) {
61297- struct file_lock fl = {
61298+ struct file_lock flock = {
61299 .fl_pid = current->tgid,
61300 .fl_file = filp,
61301 .fl_flags = FL_FLOCK,
61302 .fl_type = F_UNLCK,
61303 .fl_end = OFFSET_MAX,
61304 };
61305- filp->f_op->flock(filp, F_SETLKW, &fl);
61306- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61307- fl.fl_ops->fl_release_private(&fl);
61308+ filp->f_op->flock(filp, F_SETLKW, &flock);
61309+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61310+ flock.fl_ops->fl_release_private(&flock);
61311 }
61312
61313 spin_lock(&inode->i_lock);
61314diff --git a/fs/mount.h b/fs/mount.h
61315index b29e42f..5ea7fdf 100644
61316--- a/fs/mount.h
61317+++ b/fs/mount.h
61318@@ -11,7 +11,7 @@ struct mnt_namespace {
61319 u64 seq; /* Sequence number to prevent loops */
61320 wait_queue_head_t poll;
61321 int event;
61322-};
61323+} __randomize_layout;
61324
61325 struct mnt_pcp {
61326 int mnt_count;
61327@@ -57,7 +57,7 @@ struct mount {
61328 int mnt_expiry_mark; /* true if marked for expiry */
61329 int mnt_pinned;
61330 struct path mnt_ex_mountpoint;
61331-};
61332+} __randomize_layout;
61333
61334 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61335
61336diff --git a/fs/namei.c b/fs/namei.c
61337index 4b491b4..a0166f9 100644
61338--- a/fs/namei.c
61339+++ b/fs/namei.c
61340@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61341 if (ret != -EACCES)
61342 return ret;
61343
61344+#ifdef CONFIG_GRKERNSEC
61345+ /* we'll block if we have to log due to a denied capability use */
61346+ if (mask & MAY_NOT_BLOCK)
61347+ return -ECHILD;
61348+#endif
61349+
61350 if (S_ISDIR(inode->i_mode)) {
61351 /* DACs are overridable for directories */
61352- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61353- return 0;
61354 if (!(mask & MAY_WRITE))
61355- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61356+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61357+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61358 return 0;
61359+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61360+ return 0;
61361 return -EACCES;
61362 }
61363 /*
61364+ * Searching includes executable on directories, else just read.
61365+ */
61366+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61367+ if (mask == MAY_READ)
61368+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61369+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61370+ return 0;
61371+
61372+ /*
61373 * Read/write DACs are always overridable.
61374 * Executable DACs are overridable when there is
61375 * at least one exec bit set.
61376@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61377 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61378 return 0;
61379
61380- /*
61381- * Searching includes executable on directories, else just read.
61382- */
61383- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61384- if (mask == MAY_READ)
61385- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61386- return 0;
61387-
61388 return -EACCES;
61389 }
61390
61391@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61392 {
61393 struct dentry *dentry = link->dentry;
61394 int error;
61395- char *s;
61396+ const char *s;
61397
61398 BUG_ON(nd->flags & LOOKUP_RCU);
61399
61400@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61401 if (error)
61402 goto out_put_nd_path;
61403
61404+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61405+ dentry->d_inode, dentry, nd->path.mnt)) {
61406+ error = -EACCES;
61407+ goto out_put_nd_path;
61408+ }
61409+
61410 nd->last_type = LAST_BIND;
61411 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61412 error = PTR_ERR(*p);
61413@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61414 if (res)
61415 break;
61416 res = walk_component(nd, path, LOOKUP_FOLLOW);
61417+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61418+ res = -EACCES;
61419 put_link(nd, &link, cookie);
61420 } while (res > 0);
61421
61422@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61423 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61424 {
61425 unsigned long a, b, adata, bdata, mask, hash, len;
61426- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61427+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61428
61429 hash = a = 0;
61430 len = -sizeof(unsigned long);
61431@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61432 if (err)
61433 break;
61434 err = lookup_last(nd, &path);
61435+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61436+ err = -EACCES;
61437 put_link(nd, &link, cookie);
61438 }
61439 }
61440@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61441 if (!err)
61442 err = complete_walk(nd);
61443
61444+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61445+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61446+ path_put(&nd->path);
61447+ err = -ENOENT;
61448+ }
61449+ }
61450+
61451 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61452 if (!d_is_directory(nd->path.dentry)) {
61453 path_put(&nd->path);
61454@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61455 retval = path_lookupat(dfd, name->name,
61456 flags | LOOKUP_REVAL, nd);
61457
61458- if (likely(!retval))
61459+ if (likely(!retval)) {
61460 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61461+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61462+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61463+ path_put(&nd->path);
61464+ return -ENOENT;
61465+ }
61466+ }
61467+ }
61468 return retval;
61469 }
61470
61471@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61472 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61473 return -EPERM;
61474
61475+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61476+ return -EPERM;
61477+ if (gr_handle_rawio(inode))
61478+ return -EPERM;
61479+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61480+ return -EACCES;
61481+
61482 return 0;
61483 }
61484
61485@@ -2787,7 +2826,7 @@ looked_up:
61486 * cleared otherwise prior to returning.
61487 */
61488 static int lookup_open(struct nameidata *nd, struct path *path,
61489- struct file *file,
61490+ struct path *link, struct file *file,
61491 const struct open_flags *op,
61492 bool got_write, int *opened)
61493 {
61494@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61495 /* Negative dentry, just create the file */
61496 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61497 umode_t mode = op->mode;
61498+
61499+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61500+ error = -EACCES;
61501+ goto out_dput;
61502+ }
61503+
61504+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61505+ error = -EACCES;
61506+ goto out_dput;
61507+ }
61508+
61509 if (!IS_POSIXACL(dir->d_inode))
61510 mode &= ~current_umask();
61511 /*
61512@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61513 nd->flags & LOOKUP_EXCL);
61514 if (error)
61515 goto out_dput;
61516+ else
61517+ gr_handle_create(dentry, nd->path.mnt);
61518 }
61519 out_no_open:
61520 path->dentry = dentry;
61521@@ -2857,7 +2909,7 @@ out_dput:
61522 /*
61523 * Handle the last step of open()
61524 */
61525-static int do_last(struct nameidata *nd, struct path *path,
61526+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61527 struct file *file, const struct open_flags *op,
61528 int *opened, struct filename *name)
61529 {
61530@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61531 if (error)
61532 return error;
61533
61534+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61535+ error = -ENOENT;
61536+ goto out;
61537+ }
61538+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61539+ error = -EACCES;
61540+ goto out;
61541+ }
61542+
61543 audit_inode(name, dir, LOOKUP_PARENT);
61544 error = -EISDIR;
61545 /* trailing slashes? */
61546@@ -2926,7 +2987,7 @@ retry_lookup:
61547 */
61548 }
61549 mutex_lock(&dir->d_inode->i_mutex);
61550- error = lookup_open(nd, path, file, op, got_write, opened);
61551+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61552 mutex_unlock(&dir->d_inode->i_mutex);
61553
61554 if (error <= 0) {
61555@@ -2950,11 +3011,28 @@ retry_lookup:
61556 goto finish_open_created;
61557 }
61558
61559+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61560+ error = -ENOENT;
61561+ goto exit_dput;
61562+ }
61563+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61564+ error = -EACCES;
61565+ goto exit_dput;
61566+ }
61567+
61568 /*
61569 * create/update audit record if it already exists.
61570 */
61571- if (d_is_positive(path->dentry))
61572+ if (d_is_positive(path->dentry)) {
61573+ /* only check if O_CREAT is specified, all other checks need to go
61574+ into may_open */
61575+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61576+ error = -EACCES;
61577+ goto exit_dput;
61578+ }
61579+
61580 audit_inode(name, path->dentry, 0);
61581+ }
61582
61583 /*
61584 * If atomic_open() acquired write access it is dropped now due to
61585@@ -2995,6 +3073,11 @@ finish_lookup:
61586 }
61587 }
61588 BUG_ON(inode != path->dentry->d_inode);
61589+ /* if we're resolving a symlink to another symlink */
61590+ if (link && gr_handle_symlink_owner(link, inode)) {
61591+ error = -EACCES;
61592+ goto out;
61593+ }
61594 return 1;
61595 }
61596
61597@@ -3004,7 +3087,6 @@ finish_lookup:
61598 save_parent.dentry = nd->path.dentry;
61599 save_parent.mnt = mntget(path->mnt);
61600 nd->path.dentry = path->dentry;
61601-
61602 }
61603 nd->inode = inode;
61604 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61605@@ -3014,7 +3096,18 @@ finish_open:
61606 path_put(&save_parent);
61607 return error;
61608 }
61609+
61610+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61611+ error = -ENOENT;
61612+ goto out;
61613+ }
61614+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61615+ error = -EACCES;
61616+ goto out;
61617+ }
61618+
61619 audit_inode(name, nd->path.dentry, 0);
61620+
61621 error = -EISDIR;
61622 if ((open_flag & O_CREAT) &&
61623 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61624@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61625 if (unlikely(error))
61626 goto out;
61627
61628- error = do_last(nd, &path, file, op, &opened, pathname);
61629+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61630 while (unlikely(error > 0)) { /* trailing symlink */
61631 struct path link = path;
61632 void *cookie;
61633@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61634 error = follow_link(&link, nd, &cookie);
61635 if (unlikely(error))
61636 break;
61637- error = do_last(nd, &path, file, op, &opened, pathname);
61638+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61639 put_link(nd, &link, cookie);
61640 }
61641 out:
61642@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61643 goto unlock;
61644
61645 error = -EEXIST;
61646- if (d_is_positive(dentry))
61647+ if (d_is_positive(dentry)) {
61648+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61649+ error = -ENOENT;
61650 goto fail;
61651-
61652+ }
61653 /*
61654 * Special case - lookup gave negative, but... we had foo/bar/
61655 * From the vfs_mknod() POV we just have a negative dentry -
61656@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61657 }
61658 EXPORT_SYMBOL(user_path_create);
61659
61660+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61661+{
61662+ struct filename *tmp = getname(pathname);
61663+ struct dentry *res;
61664+ if (IS_ERR(tmp))
61665+ return ERR_CAST(tmp);
61666+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61667+ if (IS_ERR(res))
61668+ putname(tmp);
61669+ else
61670+ *to = tmp;
61671+ return res;
61672+}
61673+
61674 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61675 {
61676 int error = may_create(dir, dentry);
61677@@ -3412,6 +3521,17 @@ retry:
61678
61679 if (!IS_POSIXACL(path.dentry->d_inode))
61680 mode &= ~current_umask();
61681+
61682+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61683+ error = -EPERM;
61684+ goto out;
61685+ }
61686+
61687+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61688+ error = -EACCES;
61689+ goto out;
61690+ }
61691+
61692 error = security_path_mknod(&path, dentry, mode, dev);
61693 if (error)
61694 goto out;
61695@@ -3428,6 +3548,8 @@ retry:
61696 break;
61697 }
61698 out:
61699+ if (!error)
61700+ gr_handle_create(dentry, path.mnt);
61701 done_path_create(&path, dentry);
61702 if (retry_estale(error, lookup_flags)) {
61703 lookup_flags |= LOOKUP_REVAL;
61704@@ -3480,9 +3602,16 @@ retry:
61705
61706 if (!IS_POSIXACL(path.dentry->d_inode))
61707 mode &= ~current_umask();
61708+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61709+ error = -EACCES;
61710+ goto out;
61711+ }
61712 error = security_path_mkdir(&path, dentry, mode);
61713 if (!error)
61714 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61715+ if (!error)
61716+ gr_handle_create(dentry, path.mnt);
61717+out:
61718 done_path_create(&path, dentry);
61719 if (retry_estale(error, lookup_flags)) {
61720 lookup_flags |= LOOKUP_REVAL;
61721@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61722 struct filename *name;
61723 struct dentry *dentry;
61724 struct nameidata nd;
61725+ ino_t saved_ino = 0;
61726+ dev_t saved_dev = 0;
61727 unsigned int lookup_flags = 0;
61728 retry:
61729 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61730@@ -3595,10 +3726,21 @@ retry:
61731 error = -ENOENT;
61732 goto exit3;
61733 }
61734+
61735+ saved_ino = dentry->d_inode->i_ino;
61736+ saved_dev = gr_get_dev_from_dentry(dentry);
61737+
61738+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61739+ error = -EACCES;
61740+ goto exit3;
61741+ }
61742+
61743 error = security_path_rmdir(&nd.path, dentry);
61744 if (error)
61745 goto exit3;
61746 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61747+ if (!error && (saved_dev || saved_ino))
61748+ gr_handle_delete(saved_ino, saved_dev);
61749 exit3:
61750 dput(dentry);
61751 exit2:
61752@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61753 struct nameidata nd;
61754 struct inode *inode = NULL;
61755 struct inode *delegated_inode = NULL;
61756+ ino_t saved_ino = 0;
61757+ dev_t saved_dev = 0;
61758 unsigned int lookup_flags = 0;
61759 retry:
61760 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61761@@ -3714,10 +3858,22 @@ retry_deleg:
61762 if (d_is_negative(dentry))
61763 goto slashes;
61764 ihold(inode);
61765+
61766+ if (inode->i_nlink <= 1) {
61767+ saved_ino = inode->i_ino;
61768+ saved_dev = gr_get_dev_from_dentry(dentry);
61769+ }
61770+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61771+ error = -EACCES;
61772+ goto exit2;
61773+ }
61774+
61775 error = security_path_unlink(&nd.path, dentry);
61776 if (error)
61777 goto exit2;
61778 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61779+ if (!error && (saved_ino || saved_dev))
61780+ gr_handle_delete(saved_ino, saved_dev);
61781 exit2:
61782 dput(dentry);
61783 }
61784@@ -3805,9 +3961,17 @@ retry:
61785 if (IS_ERR(dentry))
61786 goto out_putname;
61787
61788+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61789+ error = -EACCES;
61790+ goto out;
61791+ }
61792+
61793 error = security_path_symlink(&path, dentry, from->name);
61794 if (!error)
61795 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61796+ if (!error)
61797+ gr_handle_create(dentry, path.mnt);
61798+out:
61799 done_path_create(&path, dentry);
61800 if (retry_estale(error, lookup_flags)) {
61801 lookup_flags |= LOOKUP_REVAL;
61802@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61803 struct dentry *new_dentry;
61804 struct path old_path, new_path;
61805 struct inode *delegated_inode = NULL;
61806+ struct filename *to = NULL;
61807 int how = 0;
61808 int error;
61809
61810@@ -3933,7 +4098,7 @@ retry:
61811 if (error)
61812 return error;
61813
61814- new_dentry = user_path_create(newdfd, newname, &new_path,
61815+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61816 (how & LOOKUP_REVAL));
61817 error = PTR_ERR(new_dentry);
61818 if (IS_ERR(new_dentry))
61819@@ -3945,11 +4110,28 @@ retry:
61820 error = may_linkat(&old_path);
61821 if (unlikely(error))
61822 goto out_dput;
61823+
61824+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61825+ old_path.dentry->d_inode,
61826+ old_path.dentry->d_inode->i_mode, to)) {
61827+ error = -EACCES;
61828+ goto out_dput;
61829+ }
61830+
61831+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61832+ old_path.dentry, old_path.mnt, to)) {
61833+ error = -EACCES;
61834+ goto out_dput;
61835+ }
61836+
61837 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61838 if (error)
61839 goto out_dput;
61840 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61841+ if (!error)
61842+ gr_handle_create(new_dentry, new_path.mnt);
61843 out_dput:
61844+ putname(to);
61845 done_path_create(&new_path, new_dentry);
61846 if (delegated_inode) {
61847 error = break_deleg_wait(&delegated_inode);
61848@@ -4236,6 +4418,12 @@ retry_deleg:
61849 if (new_dentry == trap)
61850 goto exit5;
61851
61852+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61853+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61854+ to);
61855+ if (error)
61856+ goto exit5;
61857+
61858 error = security_path_rename(&oldnd.path, old_dentry,
61859 &newnd.path, new_dentry);
61860 if (error)
61861@@ -4243,6 +4431,9 @@ retry_deleg:
61862 error = vfs_rename(old_dir->d_inode, old_dentry,
61863 new_dir->d_inode, new_dentry,
61864 &delegated_inode);
61865+ if (!error)
61866+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61867+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61868 exit5:
61869 dput(new_dentry);
61870 exit4:
61871@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61872
61873 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61874 {
61875+ char tmpbuf[64];
61876+ const char *newlink;
61877 int len;
61878
61879 len = PTR_ERR(link);
61880@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61881 len = strlen(link);
61882 if (len > (unsigned) buflen)
61883 len = buflen;
61884- if (copy_to_user(buffer, link, len))
61885+
61886+ if (len < sizeof(tmpbuf)) {
61887+ memcpy(tmpbuf, link, len);
61888+ newlink = tmpbuf;
61889+ } else
61890+ newlink = link;
61891+
61892+ if (copy_to_user(buffer, newlink, len))
61893 len = -EFAULT;
61894 out:
61895 return len;
61896diff --git a/fs/namespace.c b/fs/namespace.c
61897index 65233a5..82ac953 100644
61898--- a/fs/namespace.c
61899+++ b/fs/namespace.c
61900@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61901 if (!(sb->s_flags & MS_RDONLY))
61902 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61903 up_write(&sb->s_umount);
61904+
61905+ gr_log_remount(mnt->mnt_devname, retval);
61906+
61907 return retval;
61908 }
61909
61910@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61911 }
61912 unlock_mount_hash();
61913 namespace_unlock();
61914+
61915+ gr_log_unmount(mnt->mnt_devname, retval);
61916+
61917 return retval;
61918 }
61919
61920@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61921 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61922 */
61923
61924-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61925+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61926 {
61927 struct path path;
61928 struct mount *mnt;
61929@@ -1422,7 +1428,7 @@ out:
61930 /*
61931 * The 2.0 compatible umount. No flags.
61932 */
61933-SYSCALL_DEFINE1(oldumount, char __user *, name)
61934+SYSCALL_DEFINE1(oldumount, const char __user *, name)
61935 {
61936 return sys_umount(name, 0);
61937 }
61938@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61939 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61940 MS_STRICTATIME);
61941
61942+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61943+ retval = -EPERM;
61944+ goto dput_out;
61945+ }
61946+
61947+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61948+ retval = -EPERM;
61949+ goto dput_out;
61950+ }
61951+
61952 if (flags & MS_REMOUNT)
61953 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61954 data_page);
61955@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61956 dev_name, data_page);
61957 dput_out:
61958 path_put(&path);
61959+
61960+ gr_log_mount(dev_name, dir_name, retval);
61961+
61962 return retval;
61963 }
61964
61965@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61966 * number incrementing at 10Ghz will take 12,427 years to wrap which
61967 * is effectively never, so we can ignore the possibility.
61968 */
61969-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61970+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61971
61972 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61973 {
61974@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61975 kfree(new_ns);
61976 return ERR_PTR(ret);
61977 }
61978- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61979+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61980 atomic_set(&new_ns->count, 1);
61981 new_ns->root = NULL;
61982 INIT_LIST_HEAD(&new_ns->list);
61983@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61984 return new_ns;
61985 }
61986
61987-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61988+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61989 struct user_namespace *user_ns, struct fs_struct *new_fs)
61990 {
61991 struct mnt_namespace *new_ns;
61992@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61993 }
61994 EXPORT_SYMBOL(mount_subtree);
61995
61996-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61997- char __user *, type, unsigned long, flags, void __user *, data)
61998+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61999+ const char __user *, type, unsigned long, flags, void __user *, data)
62000 {
62001 int ret;
62002 char *kernel_type;
62003@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62004 if (error)
62005 goto out2;
62006
62007+ if (gr_handle_chroot_pivot()) {
62008+ error = -EPERM;
62009+ goto out2;
62010+ }
62011+
62012 get_fs_root(current->fs, &root);
62013 old_mp = lock_mount(&old);
62014 error = PTR_ERR(old_mp);
62015@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62016 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62017 return -EPERM;
62018
62019- if (fs->users != 1)
62020+ if (atomic_read(&fs->users) != 1)
62021 return -EINVAL;
62022
62023 get_mnt_ns(mnt_ns);
62024diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62025index f4ccfe6..a5cf064 100644
62026--- a/fs/nfs/callback_xdr.c
62027+++ b/fs/nfs/callback_xdr.c
62028@@ -51,7 +51,7 @@ struct callback_op {
62029 callback_decode_arg_t decode_args;
62030 callback_encode_res_t encode_res;
62031 long res_maxsize;
62032-};
62033+} __do_const;
62034
62035 static struct callback_op callback_ops[];
62036
62037diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62038index 360114a..ac6e265 100644
62039--- a/fs/nfs/inode.c
62040+++ b/fs/nfs/inode.c
62041@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62042 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62043 }
62044
62045-static atomic_long_t nfs_attr_generation_counter;
62046+static atomic_long_unchecked_t nfs_attr_generation_counter;
62047
62048 static unsigned long nfs_read_attr_generation_counter(void)
62049 {
62050- return atomic_long_read(&nfs_attr_generation_counter);
62051+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62052 }
62053
62054 unsigned long nfs_inc_attr_generation_counter(void)
62055 {
62056- return atomic_long_inc_return(&nfs_attr_generation_counter);
62057+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62058 }
62059
62060 void nfs_fattr_init(struct nfs_fattr *fattr)
62061diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62062index 9a914e8..e89c0ea 100644
62063--- a/fs/nfsd/nfs4proc.c
62064+++ b/fs/nfsd/nfs4proc.c
62065@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62066 nfsd4op_rsize op_rsize_bop;
62067 stateid_getter op_get_currentstateid;
62068 stateid_setter op_set_currentstateid;
62069-};
62070+} __do_const;
62071
62072 static struct nfsd4_operation nfsd4_ops[];
62073
62074diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62075index 16e8fa7..b0803f6 100644
62076--- a/fs/nfsd/nfs4xdr.c
62077+++ b/fs/nfsd/nfs4xdr.c
62078@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62079
62080 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62081
62082-static nfsd4_dec nfsd4_dec_ops[] = {
62083+static const nfsd4_dec nfsd4_dec_ops[] = {
62084 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62085 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62086 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62087diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62088index f8f060f..c4ba09a 100644
62089--- a/fs/nfsd/nfscache.c
62090+++ b/fs/nfsd/nfscache.c
62091@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62092 {
62093 struct svc_cacherep *rp = rqstp->rq_cacherep;
62094 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62095- int len;
62096+ long len;
62097 size_t bufsize = 0;
62098
62099 if (!rp)
62100 return;
62101
62102- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62103- len >>= 2;
62104+ if (statp) {
62105+ len = (char*)statp - (char*)resv->iov_base;
62106+ len = resv->iov_len - len;
62107+ len >>= 2;
62108+ }
62109
62110 /* Don't cache excessive amounts of data and XDR failures */
62111 if (!statp || len > (256 >> 2)) {
62112diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62113index eea5ad1..5a84ac7 100644
62114--- a/fs/nfsd/vfs.c
62115+++ b/fs/nfsd/vfs.c
62116@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62117 } else {
62118 oldfs = get_fs();
62119 set_fs(KERNEL_DS);
62120- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62121+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62122 set_fs(oldfs);
62123 }
62124
62125@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62126
62127 /* Write the data. */
62128 oldfs = get_fs(); set_fs(KERNEL_DS);
62129- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62130+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62131 set_fs(oldfs);
62132 if (host_err < 0)
62133 goto out_nfserr;
62134@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62135 */
62136
62137 oldfs = get_fs(); set_fs(KERNEL_DS);
62138- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62139+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62140 set_fs(oldfs);
62141
62142 if (host_err < 0)
62143diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62144index 52ccd34..43a53b1 100644
62145--- a/fs/nls/nls_base.c
62146+++ b/fs/nls/nls_base.c
62147@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62148
62149 int __register_nls(struct nls_table *nls, struct module *owner)
62150 {
62151- struct nls_table ** tmp = &tables;
62152+ struct nls_table *tmp = tables;
62153
62154 if (nls->next)
62155 return -EBUSY;
62156
62157- nls->owner = owner;
62158+ pax_open_kernel();
62159+ *(void **)&nls->owner = owner;
62160+ pax_close_kernel();
62161 spin_lock(&nls_lock);
62162- while (*tmp) {
62163- if (nls == *tmp) {
62164+ while (tmp) {
62165+ if (nls == tmp) {
62166 spin_unlock(&nls_lock);
62167 return -EBUSY;
62168 }
62169- tmp = &(*tmp)->next;
62170+ tmp = tmp->next;
62171 }
62172- nls->next = tables;
62173+ pax_open_kernel();
62174+ *(struct nls_table **)&nls->next = tables;
62175+ pax_close_kernel();
62176 tables = nls;
62177 spin_unlock(&nls_lock);
62178 return 0;
62179@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62180
62181 int unregister_nls(struct nls_table * nls)
62182 {
62183- struct nls_table ** tmp = &tables;
62184+ struct nls_table * const * tmp = &tables;
62185
62186 spin_lock(&nls_lock);
62187 while (*tmp) {
62188 if (nls == *tmp) {
62189- *tmp = nls->next;
62190+ pax_open_kernel();
62191+ *(struct nls_table **)tmp = nls->next;
62192+ pax_close_kernel();
62193 spin_unlock(&nls_lock);
62194 return 0;
62195 }
62196diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62197index 162b3f1..6076a7c 100644
62198--- a/fs/nls/nls_euc-jp.c
62199+++ b/fs/nls/nls_euc-jp.c
62200@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62201 p_nls = load_nls("cp932");
62202
62203 if (p_nls) {
62204- table.charset2upper = p_nls->charset2upper;
62205- table.charset2lower = p_nls->charset2lower;
62206+ pax_open_kernel();
62207+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62208+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62209+ pax_close_kernel();
62210 return register_nls(&table);
62211 }
62212
62213diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62214index a80a741..7b96e1b 100644
62215--- a/fs/nls/nls_koi8-ru.c
62216+++ b/fs/nls/nls_koi8-ru.c
62217@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62218 p_nls = load_nls("koi8-u");
62219
62220 if (p_nls) {
62221- table.charset2upper = p_nls->charset2upper;
62222- table.charset2lower = p_nls->charset2lower;
62223+ pax_open_kernel();
62224+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62225+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62226+ pax_close_kernel();
62227 return register_nls(&table);
62228 }
62229
62230diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62231index 287a22c..a2a043a 100644
62232--- a/fs/notify/fanotify/fanotify_user.c
62233+++ b/fs/notify/fanotify/fanotify_user.c
62234@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62235
62236 fd = fanotify_event_metadata.fd;
62237 ret = -EFAULT;
62238- if (copy_to_user(buf, &fanotify_event_metadata,
62239- fanotify_event_metadata.event_len))
62240+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62241+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62242 goto out_close_fd;
62243
62244 ret = prepare_for_access_response(group, event, fd);
62245diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62246index 1e58402..bb2d6f4 100644
62247--- a/fs/notify/notification.c
62248+++ b/fs/notify/notification.c
62249@@ -48,7 +48,7 @@
62250 #include <linux/fsnotify_backend.h>
62251 #include "fsnotify.h"
62252
62253-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62254+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62255
62256 /**
62257 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62258@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62259 */
62260 u32 fsnotify_get_cookie(void)
62261 {
62262- return atomic_inc_return(&fsnotify_sync_cookie);
62263+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62264 }
62265 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62266
62267diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62268index 9e38daf..5727cae 100644
62269--- a/fs/ntfs/dir.c
62270+++ b/fs/ntfs/dir.c
62271@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62272 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62273 ~(s64)(ndir->itype.index.block_size - 1)));
62274 /* Bounds checks. */
62275- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62276+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62277 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62278 "inode 0x%lx or driver bug.", vdir->i_ino);
62279 goto err_out;
62280diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62281index db9bd8a..8338fb6 100644
62282--- a/fs/ntfs/file.c
62283+++ b/fs/ntfs/file.c
62284@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62285 char *addr;
62286 size_t total = 0;
62287 unsigned len;
62288- int left;
62289+ unsigned left;
62290
62291 do {
62292 len = PAGE_CACHE_SIZE - ofs;
62293diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62294index 82650d5..db37dcf 100644
62295--- a/fs/ntfs/super.c
62296+++ b/fs/ntfs/super.c
62297@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62298 if (!silent)
62299 ntfs_error(sb, "Primary boot sector is invalid.");
62300 } else if (!silent)
62301- ntfs_error(sb, read_err_str, "primary");
62302+ ntfs_error(sb, read_err_str, "%s", "primary");
62303 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62304 if (bh_primary)
62305 brelse(bh_primary);
62306@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62307 goto hotfix_primary_boot_sector;
62308 brelse(bh_backup);
62309 } else if (!silent)
62310- ntfs_error(sb, read_err_str, "backup");
62311+ ntfs_error(sb, read_err_str, "%s", "backup");
62312 /* Try to read NT3.51- backup boot sector. */
62313 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62314 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62315@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62316 "sector.");
62317 brelse(bh_backup);
62318 } else if (!silent)
62319- ntfs_error(sb, read_err_str, "backup");
62320+ ntfs_error(sb, read_err_str, "%s", "backup");
62321 /* We failed. Cleanup and return. */
62322 if (bh_primary)
62323 brelse(bh_primary);
62324diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62325index 0440134..d52c93a 100644
62326--- a/fs/ocfs2/localalloc.c
62327+++ b/fs/ocfs2/localalloc.c
62328@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62329 goto bail;
62330 }
62331
62332- atomic_inc(&osb->alloc_stats.moves);
62333+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62334
62335 bail:
62336 if (handle)
62337diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62338index 553f53c..aaf5133 100644
62339--- a/fs/ocfs2/ocfs2.h
62340+++ b/fs/ocfs2/ocfs2.h
62341@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62342
62343 struct ocfs2_alloc_stats
62344 {
62345- atomic_t moves;
62346- atomic_t local_data;
62347- atomic_t bitmap_data;
62348- atomic_t bg_allocs;
62349- atomic_t bg_extends;
62350+ atomic_unchecked_t moves;
62351+ atomic_unchecked_t local_data;
62352+ atomic_unchecked_t bitmap_data;
62353+ atomic_unchecked_t bg_allocs;
62354+ atomic_unchecked_t bg_extends;
62355 };
62356
62357 enum ocfs2_local_alloc_state
62358diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62359index 47ae266..6e8b793 100644
62360--- a/fs/ocfs2/suballoc.c
62361+++ b/fs/ocfs2/suballoc.c
62362@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62363 mlog_errno(status);
62364 goto bail;
62365 }
62366- atomic_inc(&osb->alloc_stats.bg_extends);
62367+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62368
62369 /* You should never ask for this much metadata */
62370 BUG_ON(bits_wanted >
62371@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62372 mlog_errno(status);
62373 goto bail;
62374 }
62375- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62376+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62377
62378 *suballoc_loc = res.sr_bg_blkno;
62379 *suballoc_bit_start = res.sr_bit_offset;
62380@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62381 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62382 res->sr_bits);
62383
62384- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62385+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62386
62387 BUG_ON(res->sr_bits != 1);
62388
62389@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62390 mlog_errno(status);
62391 goto bail;
62392 }
62393- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62394+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62395
62396 BUG_ON(res.sr_bits != 1);
62397
62398@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62399 cluster_start,
62400 num_clusters);
62401 if (!status)
62402- atomic_inc(&osb->alloc_stats.local_data);
62403+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62404 } else {
62405 if (min_clusters > (osb->bitmap_cpg - 1)) {
62406 /* The only paths asking for contiguousness
62407@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62408 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62409 res.sr_bg_blkno,
62410 res.sr_bit_offset);
62411- atomic_inc(&osb->alloc_stats.bitmap_data);
62412+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62413 *num_clusters = res.sr_bits;
62414 }
62415 }
62416diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62417index 49d84f8..4807e0b 100644
62418--- a/fs/ocfs2/super.c
62419+++ b/fs/ocfs2/super.c
62420@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62421 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62422 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62423 "Stats",
62424- atomic_read(&osb->alloc_stats.bitmap_data),
62425- atomic_read(&osb->alloc_stats.local_data),
62426- atomic_read(&osb->alloc_stats.bg_allocs),
62427- atomic_read(&osb->alloc_stats.moves),
62428- atomic_read(&osb->alloc_stats.bg_extends));
62429+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62430+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62431+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62432+ atomic_read_unchecked(&osb->alloc_stats.moves),
62433+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62434
62435 out += snprintf(buf + out, len - out,
62436 "%10s => State: %u Descriptor: %llu Size: %u bits "
62437@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62438 spin_lock_init(&osb->osb_xattr_lock);
62439 ocfs2_init_steal_slots(osb);
62440
62441- atomic_set(&osb->alloc_stats.moves, 0);
62442- atomic_set(&osb->alloc_stats.local_data, 0);
62443- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62444- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62445- atomic_set(&osb->alloc_stats.bg_extends, 0);
62446+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62447+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62448+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62449+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62450+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62451
62452 /* Copy the blockcheck stats from the superblock probe */
62453 osb->osb_ecc_stats = *stats;
62454diff --git a/fs/open.c b/fs/open.c
62455index b9ed8b2..0d5c7a0 100644
62456--- a/fs/open.c
62457+++ b/fs/open.c
62458@@ -32,6 +32,8 @@
62459 #include <linux/dnotify.h>
62460 #include <linux/compat.h>
62461
62462+#define CREATE_TRACE_POINTS
62463+#include <trace/events/fs.h>
62464 #include "internal.h"
62465
62466 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62467@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62468 error = locks_verify_truncate(inode, NULL, length);
62469 if (!error)
62470 error = security_path_truncate(path);
62471+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62472+ error = -EACCES;
62473 if (!error)
62474 error = do_truncate(path->dentry, length, 0, NULL);
62475
62476@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62477 error = locks_verify_truncate(inode, f.file, length);
62478 if (!error)
62479 error = security_path_truncate(&f.file->f_path);
62480+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62481+ error = -EACCES;
62482 if (!error)
62483 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62484 sb_end_write(inode->i_sb);
62485@@ -361,6 +367,9 @@ retry:
62486 if (__mnt_is_readonly(path.mnt))
62487 res = -EROFS;
62488
62489+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62490+ res = -EACCES;
62491+
62492 out_path_release:
62493 path_put(&path);
62494 if (retry_estale(res, lookup_flags)) {
62495@@ -392,6 +401,8 @@ retry:
62496 if (error)
62497 goto dput_and_out;
62498
62499+ gr_log_chdir(path.dentry, path.mnt);
62500+
62501 set_fs_pwd(current->fs, &path);
62502
62503 dput_and_out:
62504@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62505 goto out_putf;
62506
62507 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62508+
62509+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62510+ error = -EPERM;
62511+
62512+ if (!error)
62513+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62514+
62515 if (!error)
62516 set_fs_pwd(current->fs, &f.file->f_path);
62517 out_putf:
62518@@ -450,7 +468,13 @@ retry:
62519 if (error)
62520 goto dput_and_out;
62521
62522+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62523+ goto dput_and_out;
62524+
62525 set_fs_root(current->fs, &path);
62526+
62527+ gr_handle_chroot_chdir(&path);
62528+
62529 error = 0;
62530 dput_and_out:
62531 path_put(&path);
62532@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62533 return error;
62534 retry_deleg:
62535 mutex_lock(&inode->i_mutex);
62536+
62537+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62538+ error = -EACCES;
62539+ goto out_unlock;
62540+ }
62541+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62542+ error = -EACCES;
62543+ goto out_unlock;
62544+ }
62545+
62546 error = security_path_chmod(path, mode);
62547 if (error)
62548 goto out_unlock;
62549@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62550 uid = make_kuid(current_user_ns(), user);
62551 gid = make_kgid(current_user_ns(), group);
62552
62553+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62554+ return -EACCES;
62555+
62556 newattrs.ia_valid = ATTR_CTIME;
62557 if (user != (uid_t) -1) {
62558 if (!uid_valid(uid))
62559@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62560 } else {
62561 fsnotify_open(f);
62562 fd_install(fd, f);
62563+ trace_do_sys_open(tmp->name, flags, mode);
62564 }
62565 }
62566 putname(tmp);
62567diff --git a/fs/pipe.c b/fs/pipe.c
62568index 78fd0d0..f71fc09 100644
62569--- a/fs/pipe.c
62570+++ b/fs/pipe.c
62571@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62572
62573 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62574 {
62575- if (pipe->files)
62576+ if (atomic_read(&pipe->files))
62577 mutex_lock_nested(&pipe->mutex, subclass);
62578 }
62579
62580@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62581
62582 void pipe_unlock(struct pipe_inode_info *pipe)
62583 {
62584- if (pipe->files)
62585+ if (atomic_read(&pipe->files))
62586 mutex_unlock(&pipe->mutex);
62587 }
62588 EXPORT_SYMBOL(pipe_unlock);
62589@@ -449,9 +449,9 @@ redo:
62590 }
62591 if (bufs) /* More to do? */
62592 continue;
62593- if (!pipe->writers)
62594+ if (!atomic_read(&pipe->writers))
62595 break;
62596- if (!pipe->waiting_writers) {
62597+ if (!atomic_read(&pipe->waiting_writers)) {
62598 /* syscall merging: Usually we must not sleep
62599 * if O_NONBLOCK is set, or if we got some data.
62600 * But if a writer sleeps in kernel space, then
62601@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62602 ret = 0;
62603 __pipe_lock(pipe);
62604
62605- if (!pipe->readers) {
62606+ if (!atomic_read(&pipe->readers)) {
62607 send_sig(SIGPIPE, current, 0);
62608 ret = -EPIPE;
62609 goto out;
62610@@ -562,7 +562,7 @@ redo1:
62611 for (;;) {
62612 int bufs;
62613
62614- if (!pipe->readers) {
62615+ if (!atomic_read(&pipe->readers)) {
62616 send_sig(SIGPIPE, current, 0);
62617 if (!ret)
62618 ret = -EPIPE;
62619@@ -653,9 +653,9 @@ redo2:
62620 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62621 do_wakeup = 0;
62622 }
62623- pipe->waiting_writers++;
62624+ atomic_inc(&pipe->waiting_writers);
62625 pipe_wait(pipe);
62626- pipe->waiting_writers--;
62627+ atomic_dec(&pipe->waiting_writers);
62628 }
62629 out:
62630 __pipe_unlock(pipe);
62631@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62632 mask = 0;
62633 if (filp->f_mode & FMODE_READ) {
62634 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62635- if (!pipe->writers && filp->f_version != pipe->w_counter)
62636+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62637 mask |= POLLHUP;
62638 }
62639
62640@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62641 * Most Unices do not set POLLERR for FIFOs but on Linux they
62642 * behave exactly like pipes for poll().
62643 */
62644- if (!pipe->readers)
62645+ if (!atomic_read(&pipe->readers))
62646 mask |= POLLERR;
62647 }
62648
62649@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62650 int kill = 0;
62651
62652 spin_lock(&inode->i_lock);
62653- if (!--pipe->files) {
62654+ if (atomic_dec_and_test(&pipe->files)) {
62655 inode->i_pipe = NULL;
62656 kill = 1;
62657 }
62658@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62659
62660 __pipe_lock(pipe);
62661 if (file->f_mode & FMODE_READ)
62662- pipe->readers--;
62663+ atomic_dec(&pipe->readers);
62664 if (file->f_mode & FMODE_WRITE)
62665- pipe->writers--;
62666+ atomic_dec(&pipe->writers);
62667
62668- if (pipe->readers || pipe->writers) {
62669+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62670 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62671 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62672 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62673@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62674 kfree(pipe);
62675 }
62676
62677-static struct vfsmount *pipe_mnt __read_mostly;
62678+struct vfsmount *pipe_mnt __read_mostly;
62679
62680 /*
62681 * pipefs_dname() is called from d_path().
62682@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62683 goto fail_iput;
62684
62685 inode->i_pipe = pipe;
62686- pipe->files = 2;
62687- pipe->readers = pipe->writers = 1;
62688+ atomic_set(&pipe->files, 2);
62689+ atomic_set(&pipe->readers, 1);
62690+ atomic_set(&pipe->writers, 1);
62691 inode->i_fop = &pipefifo_fops;
62692
62693 /*
62694@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62695 spin_lock(&inode->i_lock);
62696 if (inode->i_pipe) {
62697 pipe = inode->i_pipe;
62698- pipe->files++;
62699+ atomic_inc(&pipe->files);
62700 spin_unlock(&inode->i_lock);
62701 } else {
62702 spin_unlock(&inode->i_lock);
62703 pipe = alloc_pipe_info();
62704 if (!pipe)
62705 return -ENOMEM;
62706- pipe->files = 1;
62707+ atomic_set(&pipe->files, 1);
62708 spin_lock(&inode->i_lock);
62709 if (unlikely(inode->i_pipe)) {
62710- inode->i_pipe->files++;
62711+ atomic_inc(&inode->i_pipe->files);
62712 spin_unlock(&inode->i_lock);
62713 free_pipe_info(pipe);
62714 pipe = inode->i_pipe;
62715@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62716 * opened, even when there is no process writing the FIFO.
62717 */
62718 pipe->r_counter++;
62719- if (pipe->readers++ == 0)
62720+ if (atomic_inc_return(&pipe->readers) == 1)
62721 wake_up_partner(pipe);
62722
62723- if (!is_pipe && !pipe->writers) {
62724+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62725 if ((filp->f_flags & O_NONBLOCK)) {
62726 /* suppress POLLHUP until we have
62727 * seen a writer */
62728@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62729 * errno=ENXIO when there is no process reading the FIFO.
62730 */
62731 ret = -ENXIO;
62732- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62733+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62734 goto err;
62735
62736 pipe->w_counter++;
62737- if (!pipe->writers++)
62738+ if (atomic_inc_return(&pipe->writers) == 1)
62739 wake_up_partner(pipe);
62740
62741- if (!is_pipe && !pipe->readers) {
62742+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62743 if (wait_for_partner(pipe, &pipe->r_counter))
62744 goto err_wr;
62745 }
62746@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62747 * the process can at least talk to itself.
62748 */
62749
62750- pipe->readers++;
62751- pipe->writers++;
62752+ atomic_inc(&pipe->readers);
62753+ atomic_inc(&pipe->writers);
62754 pipe->r_counter++;
62755 pipe->w_counter++;
62756- if (pipe->readers == 1 || pipe->writers == 1)
62757+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62758 wake_up_partner(pipe);
62759 break;
62760
62761@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62762 return 0;
62763
62764 err_rd:
62765- if (!--pipe->readers)
62766+ if (atomic_dec_and_test(&pipe->readers))
62767 wake_up_interruptible(&pipe->wait);
62768 ret = -ERESTARTSYS;
62769 goto err;
62770
62771 err_wr:
62772- if (!--pipe->writers)
62773+ if (atomic_dec_and_test(&pipe->writers))
62774 wake_up_interruptible(&pipe->wait);
62775 ret = -ERESTARTSYS;
62776 goto err;
62777diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62778index 9e363e4..d936d15 100644
62779--- a/fs/posix_acl.c
62780+++ b/fs/posix_acl.c
62781@@ -20,6 +20,7 @@
62782 #include <linux/xattr.h>
62783 #include <linux/export.h>
62784 #include <linux/user_namespace.h>
62785+#include <linux/grsecurity.h>
62786
62787 struct posix_acl **acl_by_type(struct inode *inode, int type)
62788 {
62789@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62790 }
62791 }
62792 if (mode_p)
62793- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62794+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62795 return not_equiv;
62796 }
62797 EXPORT_SYMBOL(posix_acl_equiv_mode);
62798@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62799 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62800 }
62801
62802- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62803+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62804 return not_equiv;
62805 }
62806
62807@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62808 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62809 int err = -ENOMEM;
62810 if (clone) {
62811+ *mode_p &= ~gr_acl_umask();
62812+
62813 err = posix_acl_create_masq(clone, mode_p);
62814 if (err < 0) {
62815 posix_acl_release(clone);
62816@@ -653,11 +656,12 @@ struct posix_acl *
62817 posix_acl_from_xattr(struct user_namespace *user_ns,
62818 const void *value, size_t size)
62819 {
62820- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62821- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62822+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62823+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62824 int count;
62825 struct posix_acl *acl;
62826 struct posix_acl_entry *acl_e;
62827+ umode_t umask = gr_acl_umask();
62828
62829 if (!value)
62830 return NULL;
62831@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62832
62833 switch(acl_e->e_tag) {
62834 case ACL_USER_OBJ:
62835+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62836+ break;
62837 case ACL_GROUP_OBJ:
62838 case ACL_MASK:
62839+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62840+ break;
62841 case ACL_OTHER:
62842+ acl_e->e_perm &= ~(umask & S_IRWXO);
62843 break;
62844
62845 case ACL_USER:
62846+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62847 acl_e->e_uid =
62848 make_kuid(user_ns,
62849 le32_to_cpu(entry->e_id));
62850@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62851 goto fail;
62852 break;
62853 case ACL_GROUP:
62854+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62855 acl_e->e_gid =
62856 make_kgid(user_ns,
62857 le32_to_cpu(entry->e_id));
62858diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62859index 2183fcf..3c32a98 100644
62860--- a/fs/proc/Kconfig
62861+++ b/fs/proc/Kconfig
62862@@ -30,7 +30,7 @@ config PROC_FS
62863
62864 config PROC_KCORE
62865 bool "/proc/kcore support" if !ARM
62866- depends on PROC_FS && MMU
62867+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62868 help
62869 Provides a virtual ELF core file of the live kernel. This can
62870 be read with gdb and other ELF tools. No modifications can be
62871@@ -38,8 +38,8 @@ config PROC_KCORE
62872
62873 config PROC_VMCORE
62874 bool "/proc/vmcore support"
62875- depends on PROC_FS && CRASH_DUMP
62876- default y
62877+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62878+ default n
62879 help
62880 Exports the dump image of crashed kernel in ELF format.
62881
62882@@ -63,8 +63,8 @@ config PROC_SYSCTL
62883 limited in memory.
62884
62885 config PROC_PAGE_MONITOR
62886- default y
62887- depends on PROC_FS && MMU
62888+ default n
62889+ depends on PROC_FS && MMU && !GRKERNSEC
62890 bool "Enable /proc page monitoring" if EXPERT
62891 help
62892 Various /proc files exist to monitor process memory utilization:
62893diff --git a/fs/proc/array.c b/fs/proc/array.c
62894index 656e401..b5b86b9 100644
62895--- a/fs/proc/array.c
62896+++ b/fs/proc/array.c
62897@@ -60,6 +60,7 @@
62898 #include <linux/tty.h>
62899 #include <linux/string.h>
62900 #include <linux/mman.h>
62901+#include <linux/grsecurity.h>
62902 #include <linux/proc_fs.h>
62903 #include <linux/ioport.h>
62904 #include <linux/uaccess.h>
62905@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62906 seq_putc(m, '\n');
62907 }
62908
62909+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62910+static inline void task_pax(struct seq_file *m, struct task_struct *p)
62911+{
62912+ if (p->mm)
62913+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62914+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62915+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62916+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62917+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62918+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62919+ else
62920+ seq_printf(m, "PaX:\t-----\n");
62921+}
62922+#endif
62923+
62924 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62925 struct pid *pid, struct task_struct *task)
62926 {
62927@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62928 task_cpus_allowed(m, task);
62929 cpuset_task_status_allowed(m, task);
62930 task_context_switch_counts(m, task);
62931+
62932+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62933+ task_pax(m, task);
62934+#endif
62935+
62936+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62937+ task_grsec_rbac(m, task);
62938+#endif
62939+
62940 return 0;
62941 }
62942
62943+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62944+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62945+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62946+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62947+#endif
62948+
62949 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62950 struct pid *pid, struct task_struct *task, int whole)
62951 {
62952@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62953 char tcomm[sizeof(task->comm)];
62954 unsigned long flags;
62955
62956+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62957+ if (current->exec_id != m->exec_id) {
62958+ gr_log_badprocpid("stat");
62959+ return 0;
62960+ }
62961+#endif
62962+
62963 state = *get_task_state(task);
62964 vsize = eip = esp = 0;
62965 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62966@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62967 gtime = task_gtime(task);
62968 }
62969
62970+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62971+ if (PAX_RAND_FLAGS(mm)) {
62972+ eip = 0;
62973+ esp = 0;
62974+ wchan = 0;
62975+ }
62976+#endif
62977+#ifdef CONFIG_GRKERNSEC_HIDESYM
62978+ wchan = 0;
62979+ eip =0;
62980+ esp =0;
62981+#endif
62982+
62983 /* scale priority and nice values from timeslices to -20..20 */
62984 /* to make it look like a "normal" Unix priority/nice value */
62985 priority = task_prio(task);
62986@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62987 seq_put_decimal_ull(m, ' ', vsize);
62988 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62989 seq_put_decimal_ull(m, ' ', rsslim);
62990+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62991+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62992+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62993+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62994+#else
62995 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62996 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62997 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62998+#endif
62999 seq_put_decimal_ull(m, ' ', esp);
63000 seq_put_decimal_ull(m, ' ', eip);
63001 /* The signal information here is obsolete.
63002@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63003 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63004 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63005
63006- if (mm && permitted) {
63007+ if (mm && permitted
63008+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63009+ && !PAX_RAND_FLAGS(mm)
63010+#endif
63011+ ) {
63012 seq_put_decimal_ull(m, ' ', mm->start_data);
63013 seq_put_decimal_ull(m, ' ', mm->end_data);
63014 seq_put_decimal_ull(m, ' ', mm->start_brk);
63015@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63016 struct pid *pid, struct task_struct *task)
63017 {
63018 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63019- struct mm_struct *mm = get_task_mm(task);
63020+ struct mm_struct *mm;
63021
63022+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63023+ if (current->exec_id != m->exec_id) {
63024+ gr_log_badprocpid("statm");
63025+ return 0;
63026+ }
63027+#endif
63028+ mm = get_task_mm(task);
63029 if (mm) {
63030 size = task_statm(mm, &shared, &text, &data, &resident);
63031 mmput(mm);
63032@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63033 return 0;
63034 }
63035
63036+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63037+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63038+{
63039+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63040+}
63041+#endif
63042+
63043 #ifdef CONFIG_CHECKPOINT_RESTORE
63044 static struct pid *
63045 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63046diff --git a/fs/proc/base.c b/fs/proc/base.c
63047index b976062..584d0bc 100644
63048--- a/fs/proc/base.c
63049+++ b/fs/proc/base.c
63050@@ -113,6 +113,14 @@ struct pid_entry {
63051 union proc_op op;
63052 };
63053
63054+struct getdents_callback {
63055+ struct linux_dirent __user * current_dir;
63056+ struct linux_dirent __user * previous;
63057+ struct file * file;
63058+ int count;
63059+ int error;
63060+};
63061+
63062 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63063 .name = (NAME), \
63064 .len = sizeof(NAME) - 1, \
63065@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63066 if (!mm->arg_end)
63067 goto out_mm; /* Shh! No looking before we're done */
63068
63069+ if (gr_acl_handle_procpidmem(task))
63070+ goto out_mm;
63071+
63072 len = mm->arg_end - mm->arg_start;
63073
63074 if (len > PAGE_SIZE)
63075@@ -237,12 +248,28 @@ out:
63076 return res;
63077 }
63078
63079+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63080+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63081+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63082+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63083+#endif
63084+
63085 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63086 {
63087 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63088 int res = PTR_ERR(mm);
63089 if (mm && !IS_ERR(mm)) {
63090 unsigned int nwords = 0;
63091+
63092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63093+ /* allow if we're currently ptracing this task */
63094+ if (PAX_RAND_FLAGS(mm) &&
63095+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63096+ mmput(mm);
63097+ return 0;
63098+ }
63099+#endif
63100+
63101 do {
63102 nwords += 2;
63103 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63104@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63105 }
63106
63107
63108-#ifdef CONFIG_KALLSYMS
63109+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63110 /*
63111 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63112 * Returns the resolved symbol. If that fails, simply return the address.
63113@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63114 mutex_unlock(&task->signal->cred_guard_mutex);
63115 }
63116
63117-#ifdef CONFIG_STACKTRACE
63118+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63119
63120 #define MAX_STACK_TRACE_DEPTH 64
63121
63122@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63123 return count;
63124 }
63125
63126-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63127+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63128 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63129 {
63130 long nr;
63131@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63132 /************************************************************************/
63133
63134 /* permission checks */
63135-static int proc_fd_access_allowed(struct inode *inode)
63136+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63137 {
63138 struct task_struct *task;
63139 int allowed = 0;
63140@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63141 */
63142 task = get_proc_task(inode);
63143 if (task) {
63144- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63145+ if (log)
63146+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63147+ else
63148+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63149 put_task_struct(task);
63150 }
63151 return allowed;
63152@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63153 struct task_struct *task,
63154 int hide_pid_min)
63155 {
63156+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63157+ return false;
63158+
63159+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63160+ rcu_read_lock();
63161+ {
63162+ const struct cred *tmpcred = current_cred();
63163+ const struct cred *cred = __task_cred(task);
63164+
63165+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63166+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63167+ || in_group_p(grsec_proc_gid)
63168+#endif
63169+ ) {
63170+ rcu_read_unlock();
63171+ return true;
63172+ }
63173+ }
63174+ rcu_read_unlock();
63175+
63176+ if (!pid->hide_pid)
63177+ return false;
63178+#endif
63179+
63180 if (pid->hide_pid < hide_pid_min)
63181 return true;
63182 if (in_group_p(pid->pid_gid))
63183 return true;
63184+
63185 return ptrace_may_access(task, PTRACE_MODE_READ);
63186 }
63187
63188@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63189 put_task_struct(task);
63190
63191 if (!has_perms) {
63192+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63193+ {
63194+#else
63195 if (pid->hide_pid == 2) {
63196+#endif
63197 /*
63198 * Let's make getdents(), stat(), and open()
63199 * consistent with each other. If a process
63200@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63201 if (!task)
63202 return -ESRCH;
63203
63204+ if (gr_acl_handle_procpidmem(task)) {
63205+ put_task_struct(task);
63206+ return -EPERM;
63207+ }
63208+
63209 mm = mm_access(task, mode);
63210 put_task_struct(task);
63211
63212@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63213
63214 file->private_data = mm;
63215
63216+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63217+ file->f_version = current->exec_id;
63218+#endif
63219+
63220 return 0;
63221 }
63222
63223@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63224 ssize_t copied;
63225 char *page;
63226
63227+#ifdef CONFIG_GRKERNSEC
63228+ if (write)
63229+ return -EPERM;
63230+#endif
63231+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63232+ if (file->f_version != current->exec_id) {
63233+ gr_log_badprocpid("mem");
63234+ return 0;
63235+ }
63236+#endif
63237+
63238 if (!mm)
63239 return 0;
63240
63241@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63242 goto free;
63243
63244 while (count > 0) {
63245- int this_len = min_t(int, count, PAGE_SIZE);
63246+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63247
63248 if (write && copy_from_user(page, buf, this_len)) {
63249 copied = -EFAULT;
63250@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63251 if (!mm)
63252 return 0;
63253
63254+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63255+ if (file->f_version != current->exec_id) {
63256+ gr_log_badprocpid("environ");
63257+ return 0;
63258+ }
63259+#endif
63260+
63261 page = (char *)__get_free_page(GFP_TEMPORARY);
63262 if (!page)
63263 return -ENOMEM;
63264@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63265 goto free;
63266 while (count > 0) {
63267 size_t this_len, max_len;
63268- int retval;
63269+ ssize_t retval;
63270
63271 if (src >= (mm->env_end - mm->env_start))
63272 break;
63273@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63274 int error = -EACCES;
63275
63276 /* Are we allowed to snoop on the tasks file descriptors? */
63277- if (!proc_fd_access_allowed(inode))
63278+ if (!proc_fd_access_allowed(inode, 0))
63279 goto out;
63280
63281 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63282@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63283 struct path path;
63284
63285 /* Are we allowed to snoop on the tasks file descriptors? */
63286- if (!proc_fd_access_allowed(inode))
63287- goto out;
63288+ /* logging this is needed for learning on chromium to work properly,
63289+ but we don't want to flood the logs from 'ps' which does a readlink
63290+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63291+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63292+ */
63293+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63294+ if (!proc_fd_access_allowed(inode,0))
63295+ goto out;
63296+ } else {
63297+ if (!proc_fd_access_allowed(inode,1))
63298+ goto out;
63299+ }
63300
63301 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63302 if (error)
63303@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63304 rcu_read_lock();
63305 cred = __task_cred(task);
63306 inode->i_uid = cred->euid;
63307+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63308+ inode->i_gid = grsec_proc_gid;
63309+#else
63310 inode->i_gid = cred->egid;
63311+#endif
63312 rcu_read_unlock();
63313 }
63314 security_task_to_inode(task, inode);
63315@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63316 return -ENOENT;
63317 }
63318 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63319+#ifdef CONFIG_GRKERNSEC_PROC_USER
63320+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63321+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63322+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63323+#endif
63324 task_dumpable(task)) {
63325 cred = __task_cred(task);
63326 stat->uid = cred->euid;
63327+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63328+ stat->gid = grsec_proc_gid;
63329+#else
63330 stat->gid = cred->egid;
63331+#endif
63332 }
63333 }
63334 rcu_read_unlock();
63335@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63336
63337 if (task) {
63338 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63339+#ifdef CONFIG_GRKERNSEC_PROC_USER
63340+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63341+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63342+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63343+#endif
63344 task_dumpable(task)) {
63345 rcu_read_lock();
63346 cred = __task_cred(task);
63347 inode->i_uid = cred->euid;
63348+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63349+ inode->i_gid = grsec_proc_gid;
63350+#else
63351 inode->i_gid = cred->egid;
63352+#endif
63353 rcu_read_unlock();
63354 } else {
63355 inode->i_uid = GLOBAL_ROOT_UID;
63356@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63357 if (!task)
63358 goto out_no_task;
63359
63360+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63361+ goto out;
63362+
63363 /*
63364 * Yes, it does not scale. And it should not. Don't add
63365 * new entries into /proc/<tgid>/ without very good reasons.
63366@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63367 if (!task)
63368 return -ENOENT;
63369
63370+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63371+ goto out;
63372+
63373 if (!dir_emit_dots(file, ctx))
63374 goto out;
63375
63376@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63377 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63378 #endif
63379 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63380-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63381+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63382 INF("syscall", S_IRUGO, proc_pid_syscall),
63383 #endif
63384 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63385@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63386 #ifdef CONFIG_SECURITY
63387 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63388 #endif
63389-#ifdef CONFIG_KALLSYMS
63390+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63391 INF("wchan", S_IRUGO, proc_pid_wchan),
63392 #endif
63393-#ifdef CONFIG_STACKTRACE
63394+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63395 ONE("stack", S_IRUGO, proc_pid_stack),
63396 #endif
63397 #ifdef CONFIG_SCHEDSTATS
63398@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63399 #ifdef CONFIG_HARDWALL
63400 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63401 #endif
63402+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63403+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63404+#endif
63405 #ifdef CONFIG_USER_NS
63406 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63407 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63408@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63409 if (!inode)
63410 goto out;
63411
63412+#ifdef CONFIG_GRKERNSEC_PROC_USER
63413+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63414+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63415+ inode->i_gid = grsec_proc_gid;
63416+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63417+#else
63418 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63419+#endif
63420 inode->i_op = &proc_tgid_base_inode_operations;
63421 inode->i_fop = &proc_tgid_base_operations;
63422 inode->i_flags|=S_IMMUTABLE;
63423@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63424 if (!task)
63425 goto out;
63426
63427+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63428+ goto out_put_task;
63429+
63430 result = proc_pid_instantiate(dir, dentry, task, NULL);
63431+out_put_task:
63432 put_task_struct(task);
63433 out:
63434 return ERR_PTR(result);
63435@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63436 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63437 #endif
63438 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63439-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63440+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63441 INF("syscall", S_IRUGO, proc_pid_syscall),
63442 #endif
63443 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63444@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63445 #ifdef CONFIG_SECURITY
63446 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63447 #endif
63448-#ifdef CONFIG_KALLSYMS
63449+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63450 INF("wchan", S_IRUGO, proc_pid_wchan),
63451 #endif
63452-#ifdef CONFIG_STACKTRACE
63453+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63454 ONE("stack", S_IRUGO, proc_pid_stack),
63455 #endif
63456 #ifdef CONFIG_SCHEDSTATS
63457diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63458index cbd82df..c0407d2 100644
63459--- a/fs/proc/cmdline.c
63460+++ b/fs/proc/cmdline.c
63461@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63462
63463 static int __init proc_cmdline_init(void)
63464 {
63465+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63466+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63467+#else
63468 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63469+#endif
63470 return 0;
63471 }
63472 fs_initcall(proc_cmdline_init);
63473diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63474index 50493ed..248166b 100644
63475--- a/fs/proc/devices.c
63476+++ b/fs/proc/devices.c
63477@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63478
63479 static int __init proc_devices_init(void)
63480 {
63481+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63482+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63483+#else
63484 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63485+#endif
63486 return 0;
63487 }
63488 fs_initcall(proc_devices_init);
63489diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63490index 985ea88..d118a0a 100644
63491--- a/fs/proc/fd.c
63492+++ b/fs/proc/fd.c
63493@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63494 if (!task)
63495 return -ENOENT;
63496
63497- files = get_files_struct(task);
63498+ if (!gr_acl_handle_procpidmem(task))
63499+ files = get_files_struct(task);
63500 put_task_struct(task);
63501
63502 if (files) {
63503@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63504 */
63505 int proc_fd_permission(struct inode *inode, int mask)
63506 {
63507+ struct task_struct *task;
63508 int rv = generic_permission(inode, mask);
63509- if (rv == 0)
63510- return 0;
63511+
63512 if (task_tgid(current) == proc_pid(inode))
63513 rv = 0;
63514+
63515+ task = get_proc_task(inode);
63516+ if (task == NULL)
63517+ return rv;
63518+
63519+ if (gr_acl_handle_procpidmem(task))
63520+ rv = -EACCES;
63521+
63522+ put_task_struct(task);
63523+
63524 return rv;
63525 }
63526
63527diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63528index b7f268e..3bea6b7 100644
63529--- a/fs/proc/generic.c
63530+++ b/fs/proc/generic.c
63531@@ -23,6 +23,7 @@
63532 #include <linux/bitops.h>
63533 #include <linux/spinlock.h>
63534 #include <linux/completion.h>
63535+#include <linux/grsecurity.h>
63536 #include <asm/uaccess.h>
63537
63538 #include "internal.h"
63539@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63540 return proc_lookup_de(PDE(dir), dir, dentry);
63541 }
63542
63543+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63544+ unsigned int flags)
63545+{
63546+ if (gr_proc_is_restricted())
63547+ return ERR_PTR(-EACCES);
63548+
63549+ return proc_lookup_de(PDE(dir), dir, dentry);
63550+}
63551+
63552 /*
63553 * This returns non-zero if at EOF, so that the /proc
63554 * root directory can use this and check if it should
63555@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63556 return proc_readdir_de(PDE(inode), file, ctx);
63557 }
63558
63559+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63560+{
63561+ struct inode *inode = file_inode(file);
63562+
63563+ if (gr_proc_is_restricted())
63564+ return -EACCES;
63565+
63566+ return proc_readdir_de(PDE(inode), file, ctx);
63567+}
63568+
63569 /*
63570 * These are the generic /proc directory operations. They
63571 * use the in-memory "struct proc_dir_entry" tree to parse
63572@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63573 .iterate = proc_readdir,
63574 };
63575
63576+static const struct file_operations proc_dir_restricted_operations = {
63577+ .llseek = generic_file_llseek,
63578+ .read = generic_read_dir,
63579+ .iterate = proc_readdir_restrict,
63580+};
63581+
63582 /*
63583 * proc directories can do almost nothing..
63584 */
63585@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63586 .setattr = proc_notify_change,
63587 };
63588
63589+static const struct inode_operations proc_dir_restricted_inode_operations = {
63590+ .lookup = proc_lookup_restrict,
63591+ .getattr = proc_getattr,
63592+ .setattr = proc_notify_change,
63593+};
63594+
63595 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63596 {
63597 struct proc_dir_entry *tmp;
63598@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63599 return ret;
63600
63601 if (S_ISDIR(dp->mode)) {
63602- dp->proc_fops = &proc_dir_operations;
63603- dp->proc_iops = &proc_dir_inode_operations;
63604+ if (dp->restricted) {
63605+ dp->proc_fops = &proc_dir_restricted_operations;
63606+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63607+ } else {
63608+ dp->proc_fops = &proc_dir_operations;
63609+ dp->proc_iops = &proc_dir_inode_operations;
63610+ }
63611 dir->nlink++;
63612 } else if (S_ISLNK(dp->mode)) {
63613 dp->proc_iops = &proc_link_inode_operations;
63614@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63615 }
63616 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63617
63618+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63619+ struct proc_dir_entry *parent, void *data)
63620+{
63621+ struct proc_dir_entry *ent;
63622+
63623+ if (mode == 0)
63624+ mode = S_IRUGO | S_IXUGO;
63625+
63626+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63627+ if (ent) {
63628+ ent->data = data;
63629+ ent->restricted = 1;
63630+ if (proc_register(parent, ent) < 0) {
63631+ kfree(ent);
63632+ ent = NULL;
63633+ }
63634+ }
63635+ return ent;
63636+}
63637+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63638+
63639 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63640 struct proc_dir_entry *parent)
63641 {
63642@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63643 }
63644 EXPORT_SYMBOL(proc_mkdir);
63645
63646+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63647+ struct proc_dir_entry *parent)
63648+{
63649+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63650+}
63651+EXPORT_SYMBOL(proc_mkdir_restrict);
63652+
63653 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63654 struct proc_dir_entry *parent,
63655 const struct file_operations *proc_fops,
63656diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63657index 124fc43..8afbb02 100644
63658--- a/fs/proc/inode.c
63659+++ b/fs/proc/inode.c
63660@@ -23,11 +23,17 @@
63661 #include <linux/slab.h>
63662 #include <linux/mount.h>
63663 #include <linux/magic.h>
63664+#include <linux/grsecurity.h>
63665
63666 #include <asm/uaccess.h>
63667
63668 #include "internal.h"
63669
63670+#ifdef CONFIG_PROC_SYSCTL
63671+extern const struct inode_operations proc_sys_inode_operations;
63672+extern const struct inode_operations proc_sys_dir_operations;
63673+#endif
63674+
63675 static void proc_evict_inode(struct inode *inode)
63676 {
63677 struct proc_dir_entry *de;
63678@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63679 ns = PROC_I(inode)->ns.ns;
63680 if (ns_ops && ns)
63681 ns_ops->put(ns);
63682+
63683+#ifdef CONFIG_PROC_SYSCTL
63684+ if (inode->i_op == &proc_sys_inode_operations ||
63685+ inode->i_op == &proc_sys_dir_operations)
63686+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63687+#endif
63688+
63689 }
63690
63691 static struct kmem_cache * proc_inode_cachep;
63692@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63693 if (de->mode) {
63694 inode->i_mode = de->mode;
63695 inode->i_uid = de->uid;
63696+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63697+ inode->i_gid = grsec_proc_gid;
63698+#else
63699 inode->i_gid = de->gid;
63700+#endif
63701 }
63702 if (de->size)
63703 inode->i_size = de->size;
63704diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63705index 651d09a..6a4b495 100644
63706--- a/fs/proc/internal.h
63707+++ b/fs/proc/internal.h
63708@@ -46,9 +46,10 @@ struct proc_dir_entry {
63709 struct completion *pde_unload_completion;
63710 struct list_head pde_openers; /* who did ->open, but not ->release */
63711 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63712+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63713 u8 namelen;
63714 char name[];
63715-};
63716+} __randomize_layout;
63717
63718 union proc_op {
63719 int (*proc_get_link)(struct dentry *, struct path *);
63720@@ -67,7 +68,7 @@ struct proc_inode {
63721 struct ctl_table *sysctl_entry;
63722 struct proc_ns ns;
63723 struct inode vfs_inode;
63724-};
63725+} __randomize_layout;
63726
63727 /*
63728 * General functions
63729@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63730 struct pid *, struct task_struct *);
63731 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63732 struct pid *, struct task_struct *);
63733+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63734+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63735+#endif
63736
63737 /*
63738 * base.c
63739@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63740 extern spinlock_t proc_subdir_lock;
63741
63742 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63743+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63744 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63745 struct dentry *);
63746 extern int proc_readdir(struct file *, struct dir_context *);
63747+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63748 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63749
63750 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63751diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63752index a352d57..cb94a5c 100644
63753--- a/fs/proc/interrupts.c
63754+++ b/fs/proc/interrupts.c
63755@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63756
63757 static int __init proc_interrupts_init(void)
63758 {
63759+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63760+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63761+#else
63762 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63763+#endif
63764 return 0;
63765 }
63766 fs_initcall(proc_interrupts_init);
63767diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63768index 39e6ef3..2f9cb5e 100644
63769--- a/fs/proc/kcore.c
63770+++ b/fs/proc/kcore.c
63771@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63772 * the addresses in the elf_phdr on our list.
63773 */
63774 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63775- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63776+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63777+ if (tsz > buflen)
63778 tsz = buflen;
63779-
63780+
63781 while (buflen) {
63782 struct kcore_list *m;
63783
63784@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63785 kfree(elf_buf);
63786 } else {
63787 if (kern_addr_valid(start)) {
63788- unsigned long n;
63789+ char *elf_buf;
63790+ mm_segment_t oldfs;
63791
63792- n = copy_to_user(buffer, (char *)start, tsz);
63793- /*
63794- * We cannot distinguish between fault on source
63795- * and fault on destination. When this happens
63796- * we clear too and hope it will trigger the
63797- * EFAULT again.
63798- */
63799- if (n) {
63800- if (clear_user(buffer + tsz - n,
63801- n))
63802+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63803+ if (!elf_buf)
63804+ return -ENOMEM;
63805+ oldfs = get_fs();
63806+ set_fs(KERNEL_DS);
63807+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63808+ set_fs(oldfs);
63809+ if (copy_to_user(buffer, elf_buf, tsz)) {
63810+ kfree(elf_buf);
63811 return -EFAULT;
63812+ }
63813 }
63814+ set_fs(oldfs);
63815+ kfree(elf_buf);
63816 } else {
63817 if (clear_user(buffer, tsz))
63818 return -EFAULT;
63819@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63820
63821 static int open_kcore(struct inode *inode, struct file *filp)
63822 {
63823+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63824+ return -EPERM;
63825+#endif
63826 if (!capable(CAP_SYS_RAWIO))
63827 return -EPERM;
63828 if (kcore_need_update)
63829diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63830index 136e548..1f88922 100644
63831--- a/fs/proc/meminfo.c
63832+++ b/fs/proc/meminfo.c
63833@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63834 vmi.used >> 10,
63835 vmi.largest_chunk >> 10
63836 #ifdef CONFIG_MEMORY_FAILURE
63837- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63838+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63839 #endif
63840 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63841 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63842diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63843index d4a3574..b421ce9 100644
63844--- a/fs/proc/nommu.c
63845+++ b/fs/proc/nommu.c
63846@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63847
63848 if (file) {
63849 seq_pad(m, ' ');
63850- seq_path(m, &file->f_path, "");
63851+ seq_path(m, &file->f_path, "\n\\");
63852 }
63853
63854 seq_putc(m, '\n');
63855diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63856index 4677bb7..94067cd 100644
63857--- a/fs/proc/proc_net.c
63858+++ b/fs/proc/proc_net.c
63859@@ -23,6 +23,7 @@
63860 #include <linux/nsproxy.h>
63861 #include <net/net_namespace.h>
63862 #include <linux/seq_file.h>
63863+#include <linux/grsecurity.h>
63864
63865 #include "internal.h"
63866
63867@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
63868 return maybe_get_net(PDE_NET(PDE(inode)));
63869 }
63870
63871+extern const struct seq_operations dev_seq_ops;
63872+
63873 int seq_open_net(struct inode *ino, struct file *f,
63874 const struct seq_operations *ops, int size)
63875 {
63876@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
63877
63878 BUG_ON(size < sizeof(*p));
63879
63880+ /* only permit access to /proc/net/dev */
63881+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
63882+ return -EACCES;
63883+
63884 net = get_proc_net(ino);
63885 if (net == NULL)
63886 return -ENXIO;
63887@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
63888 int err;
63889 struct net *net;
63890
63891+ if (gr_proc_is_restricted())
63892+ return -EACCES;
63893+
63894 err = -ENXIO;
63895 net = get_proc_net(inode);
63896 if (net == NULL)
63897diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63898index 7129046..6914844 100644
63899--- a/fs/proc/proc_sysctl.c
63900+++ b/fs/proc/proc_sysctl.c
63901@@ -11,13 +11,21 @@
63902 #include <linux/namei.h>
63903 #include <linux/mm.h>
63904 #include <linux/module.h>
63905+#include <linux/nsproxy.h>
63906+#ifdef CONFIG_GRKERNSEC
63907+#include <net/net_namespace.h>
63908+#endif
63909 #include "internal.h"
63910
63911+extern int gr_handle_chroot_sysctl(const int op);
63912+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63913+ const int op);
63914+
63915 static const struct dentry_operations proc_sys_dentry_operations;
63916 static const struct file_operations proc_sys_file_operations;
63917-static const struct inode_operations proc_sys_inode_operations;
63918+const struct inode_operations proc_sys_inode_operations;
63919 static const struct file_operations proc_sys_dir_file_operations;
63920-static const struct inode_operations proc_sys_dir_operations;
63921+const struct inode_operations proc_sys_dir_operations;
63922
63923 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63924 {
63925@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63926
63927 err = NULL;
63928 d_set_d_op(dentry, &proc_sys_dentry_operations);
63929+
63930+ gr_handle_proc_create(dentry, inode);
63931+
63932 d_add(dentry, inode);
63933
63934 out:
63935@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63936 struct inode *inode = file_inode(filp);
63937 struct ctl_table_header *head = grab_header(inode);
63938 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63939+ int op = write ? MAY_WRITE : MAY_READ;
63940 ssize_t error;
63941 size_t res;
63942
63943@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63944 * and won't be until we finish.
63945 */
63946 error = -EPERM;
63947- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63948+ if (sysctl_perm(head, table, op))
63949 goto out;
63950
63951 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63952@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63953 if (!table->proc_handler)
63954 goto out;
63955
63956+#ifdef CONFIG_GRKERNSEC
63957+ error = -EPERM;
63958+ if (gr_handle_chroot_sysctl(op))
63959+ goto out;
63960+ dget(filp->f_path.dentry);
63961+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63962+ dput(filp->f_path.dentry);
63963+ goto out;
63964+ }
63965+ dput(filp->f_path.dentry);
63966+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63967+ goto out;
63968+ if (write) {
63969+ if (current->nsproxy->net_ns != table->extra2) {
63970+ if (!capable(CAP_SYS_ADMIN))
63971+ goto out;
63972+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63973+ goto out;
63974+ }
63975+#endif
63976+
63977 /* careful: calling conventions are nasty here */
63978 res = count;
63979 error = table->proc_handler(table, write, buf, &res, ppos);
63980@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63981 return false;
63982 } else {
63983 d_set_d_op(child, &proc_sys_dentry_operations);
63984+
63985+ gr_handle_proc_create(child, inode);
63986+
63987 d_add(child, inode);
63988 }
63989 } else {
63990@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63991 if ((*pos)++ < ctx->pos)
63992 return true;
63993
63994+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63995+ return 0;
63996+
63997 if (unlikely(S_ISLNK(table->mode)))
63998 res = proc_sys_link_fill_cache(file, ctx, head, table);
63999 else
64000@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64001 if (IS_ERR(head))
64002 return PTR_ERR(head);
64003
64004+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64005+ return -ENOENT;
64006+
64007 generic_fillattr(inode, stat);
64008 if (table)
64009 stat->mode = (stat->mode & S_IFMT) | table->mode;
64010@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64011 .llseek = generic_file_llseek,
64012 };
64013
64014-static const struct inode_operations proc_sys_inode_operations = {
64015+const struct inode_operations proc_sys_inode_operations = {
64016 .permission = proc_sys_permission,
64017 .setattr = proc_sys_setattr,
64018 .getattr = proc_sys_getattr,
64019 };
64020
64021-static const struct inode_operations proc_sys_dir_operations = {
64022+const struct inode_operations proc_sys_dir_operations = {
64023 .lookup = proc_sys_lookup,
64024 .permission = proc_sys_permission,
64025 .setattr = proc_sys_setattr,
64026@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64027 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64028 const char *name, int namelen)
64029 {
64030- struct ctl_table *table;
64031+ ctl_table_no_const *table;
64032 struct ctl_dir *new;
64033 struct ctl_node *node;
64034 char *new_name;
64035@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64036 return NULL;
64037
64038 node = (struct ctl_node *)(new + 1);
64039- table = (struct ctl_table *)(node + 1);
64040+ table = (ctl_table_no_const *)(node + 1);
64041 new_name = (char *)(table + 2);
64042 memcpy(new_name, name, namelen);
64043 new_name[namelen] = '\0';
64044@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64045 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64046 struct ctl_table_root *link_root)
64047 {
64048- struct ctl_table *link_table, *entry, *link;
64049+ ctl_table_no_const *link_table, *link;
64050+ struct ctl_table *entry;
64051 struct ctl_table_header *links;
64052 struct ctl_node *node;
64053 char *link_name;
64054@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64055 return NULL;
64056
64057 node = (struct ctl_node *)(links + 1);
64058- link_table = (struct ctl_table *)(node + nr_entries);
64059+ link_table = (ctl_table_no_const *)(node + nr_entries);
64060 link_name = (char *)&link_table[nr_entries + 1];
64061
64062 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64063@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64064 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64065 struct ctl_table *table)
64066 {
64067- struct ctl_table *ctl_table_arg = NULL;
64068- struct ctl_table *entry, *files;
64069+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64070+ struct ctl_table *entry;
64071 int nr_files = 0;
64072 int nr_dirs = 0;
64073 int err = -ENOMEM;
64074@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64075 nr_files++;
64076 }
64077
64078- files = table;
64079 /* If there are mixed files and directories we need a new table */
64080 if (nr_dirs && nr_files) {
64081- struct ctl_table *new;
64082+ ctl_table_no_const *new;
64083 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64084 GFP_KERNEL);
64085 if (!files)
64086@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64087 /* Register everything except a directory full of subdirectories */
64088 if (nr_files || !nr_dirs) {
64089 struct ctl_table_header *header;
64090- header = __register_sysctl_table(set, path, files);
64091+ header = __register_sysctl_table(set, path, files ? files : table);
64092 if (!header) {
64093 kfree(ctl_table_arg);
64094 goto out;
64095diff --git a/fs/proc/root.c b/fs/proc/root.c
64096index 87dbcbe..55e1b4d 100644
64097--- a/fs/proc/root.c
64098+++ b/fs/proc/root.c
64099@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64100 #ifdef CONFIG_PROC_DEVICETREE
64101 proc_device_tree_init();
64102 #endif
64103+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64104+#ifdef CONFIG_GRKERNSEC_PROC_USER
64105+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64106+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64107+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64108+#endif
64109+#else
64110 proc_mkdir("bus", NULL);
64111+#endif
64112 proc_sys_init();
64113 }
64114
64115diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64116index 6f599c6..8f4644f 100644
64117--- a/fs/proc/stat.c
64118+++ b/fs/proc/stat.c
64119@@ -11,6 +11,7 @@
64120 #include <linux/irqnr.h>
64121 #include <asm/cputime.h>
64122 #include <linux/tick.h>
64123+#include <linux/grsecurity.h>
64124
64125 #ifndef arch_irq_stat_cpu
64126 #define arch_irq_stat_cpu(cpu) 0
64127@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64128 u64 sum_softirq = 0;
64129 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64130 struct timespec boottime;
64131+ int unrestricted = 1;
64132+
64133+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64134+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64135+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64136+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64137+ && !in_group_p(grsec_proc_gid)
64138+#endif
64139+ )
64140+ unrestricted = 0;
64141+#endif
64142+#endif
64143
64144 user = nice = system = idle = iowait =
64145 irq = softirq = steal = 0;
64146@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
64147 getboottime(&boottime);
64148 jif = boottime.tv_sec;
64149
64150+ if (unrestricted) {
64151 for_each_possible_cpu(i) {
64152 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
64153 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64154@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
64155 }
64156 }
64157 sum += arch_irq_stat();
64158+ }
64159
64160 seq_puts(p, "cpu ");
64161 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64162@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
64163 seq_putc(p, '\n');
64164
64165 for_each_online_cpu(i) {
64166+ if (unrestricted) {
64167 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
64168 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
64169 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64170@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
64171 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64172 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64173 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64174+ }
64175 seq_printf(p, "cpu%d", i);
64176 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64177 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64178@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64179
64180 /* sum again ? it could be updated? */
64181 for_each_irq_nr(j)
64182- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64183+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64184
64185 seq_printf(p,
64186 "\nctxt %llu\n"
64187@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64188 "processes %lu\n"
64189 "procs_running %lu\n"
64190 "procs_blocked %lu\n",
64191- nr_context_switches(),
64192+ unrestricted ? nr_context_switches() : 0ULL,
64193 (unsigned long)jif,
64194- total_forks,
64195- nr_running(),
64196- nr_iowait());
64197+ unrestricted ? total_forks : 0UL,
64198+ unrestricted ? nr_running() : 0UL,
64199+ unrestricted ? nr_iowait() : 0UL);
64200
64201 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64202
64203diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64204index fb52b54..5fc7c14 100644
64205--- a/fs/proc/task_mmu.c
64206+++ b/fs/proc/task_mmu.c
64207@@ -12,12 +12,19 @@
64208 #include <linux/swap.h>
64209 #include <linux/swapops.h>
64210 #include <linux/mmu_notifier.h>
64211+#include <linux/grsecurity.h>
64212
64213 #include <asm/elf.h>
64214 #include <asm/uaccess.h>
64215 #include <asm/tlbflush.h>
64216 #include "internal.h"
64217
64218+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64219+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64220+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64221+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64222+#endif
64223+
64224 void task_mem(struct seq_file *m, struct mm_struct *mm)
64225 {
64226 unsigned long data, text, lib, swap;
64227@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64228 "VmExe:\t%8lu kB\n"
64229 "VmLib:\t%8lu kB\n"
64230 "VmPTE:\t%8lu kB\n"
64231- "VmSwap:\t%8lu kB\n",
64232- hiwater_vm << (PAGE_SHIFT-10),
64233+ "VmSwap:\t%8lu kB\n"
64234+
64235+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64236+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64237+#endif
64238+
64239+ ,hiwater_vm << (PAGE_SHIFT-10),
64240 total_vm << (PAGE_SHIFT-10),
64241 mm->locked_vm << (PAGE_SHIFT-10),
64242 mm->pinned_vm << (PAGE_SHIFT-10),
64243@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64244 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64245 (PTRS_PER_PTE * sizeof(pte_t) *
64246 atomic_long_read(&mm->nr_ptes)) >> 10,
64247- swap << (PAGE_SHIFT-10));
64248+ swap << (PAGE_SHIFT-10)
64249+
64250+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64251+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64252+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64253+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64254+#else
64255+ , mm->context.user_cs_base
64256+ , mm->context.user_cs_limit
64257+#endif
64258+#endif
64259+
64260+ );
64261 }
64262
64263 unsigned long task_vsize(struct mm_struct *mm)
64264@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64265 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64266 }
64267
64268- /* We don't show the stack guard page in /proc/maps */
64269+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64270+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64271+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64272+#else
64273 start = vma->vm_start;
64274- if (stack_guard_page_start(vma, start))
64275- start += PAGE_SIZE;
64276 end = vma->vm_end;
64277- if (stack_guard_page_end(vma, end))
64278- end -= PAGE_SIZE;
64279+#endif
64280
64281 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64282 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64283@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64284 flags & VM_WRITE ? 'w' : '-',
64285 flags & VM_EXEC ? 'x' : '-',
64286 flags & VM_MAYSHARE ? 's' : 'p',
64287+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64288+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64289+#else
64290 pgoff,
64291+#endif
64292 MAJOR(dev), MINOR(dev), ino);
64293
64294 /*
64295@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64296 */
64297 if (file) {
64298 seq_pad(m, ' ');
64299- seq_path(m, &file->f_path, "\n");
64300+ seq_path(m, &file->f_path, "\n\\");
64301 goto done;
64302 }
64303
64304@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64305 * Thread stack in /proc/PID/task/TID/maps or
64306 * the main process stack.
64307 */
64308- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64309- vma->vm_end >= mm->start_stack)) {
64310+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64311+ (vma->vm_start <= mm->start_stack &&
64312+ vma->vm_end >= mm->start_stack)) {
64313 name = "[stack]";
64314 } else {
64315 /* Thread stack in /proc/PID/maps */
64316@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64317 struct proc_maps_private *priv = m->private;
64318 struct task_struct *task = priv->task;
64319
64320+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64321+ if (current->exec_id != m->exec_id) {
64322+ gr_log_badprocpid("maps");
64323+ return 0;
64324+ }
64325+#endif
64326+
64327 show_map_vma(m, vma, is_pid);
64328
64329 if (m->count < m->size) /* vma is copied successfully */
64330@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64331 .private = &mss,
64332 };
64333
64334+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64335+ if (current->exec_id != m->exec_id) {
64336+ gr_log_badprocpid("smaps");
64337+ return 0;
64338+ }
64339+#endif
64340 memset(&mss, 0, sizeof mss);
64341- mss.vma = vma;
64342- /* mmap_sem is held in m_start */
64343- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64344- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64345-
64346+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64347+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64348+#endif
64349+ mss.vma = vma;
64350+ /* mmap_sem is held in m_start */
64351+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64352+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64353+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64354+ }
64355+#endif
64356 show_map_vma(m, vma, is_pid);
64357
64358 seq_printf(m,
64359@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64360 "KernelPageSize: %8lu kB\n"
64361 "MMUPageSize: %8lu kB\n"
64362 "Locked: %8lu kB\n",
64363+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64364+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64365+#else
64366 (vma->vm_end - vma->vm_start) >> 10,
64367+#endif
64368 mss.resident >> 10,
64369 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64370 mss.shared_clean >> 10,
64371@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64372 char buffer[64];
64373 int nid;
64374
64375+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64376+ if (current->exec_id != m->exec_id) {
64377+ gr_log_badprocpid("numa_maps");
64378+ return 0;
64379+ }
64380+#endif
64381+
64382 if (!mm)
64383 return 0;
64384
64385@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64386 mpol_to_str(buffer, sizeof(buffer), pol);
64387 mpol_cond_put(pol);
64388
64389+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64390+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64391+#else
64392 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64393+#endif
64394
64395 if (file) {
64396 seq_printf(m, " file=");
64397- seq_path(m, &file->f_path, "\n\t= ");
64398+ seq_path(m, &file->f_path, "\n\t\\= ");
64399 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64400 seq_printf(m, " heap");
64401 } else {
64402diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64403index 678455d..ebd3245 100644
64404--- a/fs/proc/task_nommu.c
64405+++ b/fs/proc/task_nommu.c
64406@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64407 else
64408 bytes += kobjsize(mm);
64409
64410- if (current->fs && current->fs->users > 1)
64411+ if (current->fs && atomic_read(&current->fs->users) > 1)
64412 sbytes += kobjsize(current->fs);
64413 else
64414 bytes += kobjsize(current->fs);
64415@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64416
64417 if (file) {
64418 seq_pad(m, ' ');
64419- seq_path(m, &file->f_path, "");
64420+ seq_path(m, &file->f_path, "\n\\");
64421 } else if (mm) {
64422 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64423
64424diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64425index 88d4585..c10bfeb 100644
64426--- a/fs/proc/vmcore.c
64427+++ b/fs/proc/vmcore.c
64428@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64429 nr_bytes = count;
64430
64431 /* If pfn is not ram, return zeros for sparse dump files */
64432- if (pfn_is_ram(pfn) == 0)
64433- memset(buf, 0, nr_bytes);
64434- else {
64435+ if (pfn_is_ram(pfn) == 0) {
64436+ if (userbuf) {
64437+ if (clear_user((char __force_user *)buf, nr_bytes))
64438+ return -EFAULT;
64439+ } else
64440+ memset(buf, 0, nr_bytes);
64441+ } else {
64442 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64443 offset, userbuf);
64444 if (tmp < 0)
64445@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64446 static int copy_to(void *target, void *src, size_t size, int userbuf)
64447 {
64448 if (userbuf) {
64449- if (copy_to_user((char __user *) target, src, size))
64450+ if (copy_to_user((char __force_user *) target, src, size))
64451 return -EFAULT;
64452 } else {
64453 memcpy(target, src, size);
64454@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64455 if (*fpos < m->offset + m->size) {
64456 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64457 start = m->paddr + *fpos - m->offset;
64458- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64459+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64460 if (tmp < 0)
64461 return tmp;
64462 buflen -= tsz;
64463@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64464 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64465 size_t buflen, loff_t *fpos)
64466 {
64467- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64468+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64469 }
64470
64471 /*
64472diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64473index b00fcc9..e0c6381 100644
64474--- a/fs/qnx6/qnx6.h
64475+++ b/fs/qnx6/qnx6.h
64476@@ -74,7 +74,7 @@ enum {
64477 BYTESEX_BE,
64478 };
64479
64480-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64481+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64482 {
64483 if (sbi->s_bytesex == BYTESEX_LE)
64484 return le64_to_cpu((__force __le64)n);
64485@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64486 return (__force __fs64)cpu_to_be64(n);
64487 }
64488
64489-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64490+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64491 {
64492 if (sbi->s_bytesex == BYTESEX_LE)
64493 return le32_to_cpu((__force __le32)n);
64494diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64495index 72d2917..c917c12 100644
64496--- a/fs/quota/netlink.c
64497+++ b/fs/quota/netlink.c
64498@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64499 void quota_send_warning(struct kqid qid, dev_t dev,
64500 const char warntype)
64501 {
64502- static atomic_t seq;
64503+ static atomic_unchecked_t seq;
64504 struct sk_buff *skb;
64505 void *msg_head;
64506 int ret;
64507@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64508 "VFS: Not enough memory to send quota warning.\n");
64509 return;
64510 }
64511- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64512+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64513 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64514 if (!msg_head) {
64515 printk(KERN_ERR
64516diff --git a/fs/read_write.c b/fs/read_write.c
64517index 28cc9c8..208e4fb 100644
64518--- a/fs/read_write.c
64519+++ b/fs/read_write.c
64520@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64521
64522 old_fs = get_fs();
64523 set_fs(get_ds());
64524- p = (__force const char __user *)buf;
64525+ p = (const char __force_user *)buf;
64526 if (count > MAX_RW_COUNT)
64527 count = MAX_RW_COUNT;
64528 if (file->f_op->write)
64529diff --git a/fs/readdir.c b/fs/readdir.c
64530index 5b53d99..a6c3049 100644
64531--- a/fs/readdir.c
64532+++ b/fs/readdir.c
64533@@ -17,6 +17,7 @@
64534 #include <linux/security.h>
64535 #include <linux/syscalls.h>
64536 #include <linux/unistd.h>
64537+#include <linux/namei.h>
64538
64539 #include <asm/uaccess.h>
64540
64541@@ -69,6 +70,7 @@ struct old_linux_dirent {
64542 struct readdir_callback {
64543 struct dir_context ctx;
64544 struct old_linux_dirent __user * dirent;
64545+ struct file * file;
64546 int result;
64547 };
64548
64549@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64550 buf->result = -EOVERFLOW;
64551 return -EOVERFLOW;
64552 }
64553+
64554+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64555+ return 0;
64556+
64557 buf->result++;
64558 dirent = buf->dirent;
64559 if (!access_ok(VERIFY_WRITE, dirent,
64560@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64561 if (!f.file)
64562 return -EBADF;
64563
64564+ buf.file = f.file;
64565 error = iterate_dir(f.file, &buf.ctx);
64566 if (buf.result)
64567 error = buf.result;
64568@@ -142,6 +149,7 @@ struct getdents_callback {
64569 struct dir_context ctx;
64570 struct linux_dirent __user * current_dir;
64571 struct linux_dirent __user * previous;
64572+ struct file * file;
64573 int count;
64574 int error;
64575 };
64576@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64577 buf->error = -EOVERFLOW;
64578 return -EOVERFLOW;
64579 }
64580+
64581+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64582+ return 0;
64583+
64584 dirent = buf->previous;
64585 if (dirent) {
64586 if (__put_user(offset, &dirent->d_off))
64587@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64588 if (!f.file)
64589 return -EBADF;
64590
64591+ buf.file = f.file;
64592 error = iterate_dir(f.file, &buf.ctx);
64593 if (error >= 0)
64594 error = buf.error;
64595@@ -226,6 +239,7 @@ struct getdents_callback64 {
64596 struct dir_context ctx;
64597 struct linux_dirent64 __user * current_dir;
64598 struct linux_dirent64 __user * previous;
64599+ struct file *file;
64600 int count;
64601 int error;
64602 };
64603@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64604 buf->error = -EINVAL; /* only used if we fail.. */
64605 if (reclen > buf->count)
64606 return -EINVAL;
64607+
64608+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64609+ return 0;
64610+
64611 dirent = buf->previous;
64612 if (dirent) {
64613 if (__put_user(offset, &dirent->d_off))
64614@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64615 if (!f.file)
64616 return -EBADF;
64617
64618+ buf.file = f.file;
64619 error = iterate_dir(f.file, &buf.ctx);
64620 if (error >= 0)
64621 error = buf.error;
64622diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64623index 9a3c68c..767933e 100644
64624--- a/fs/reiserfs/do_balan.c
64625+++ b/fs/reiserfs/do_balan.c
64626@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64627 return;
64628 }
64629
64630- atomic_inc(&(fs_generation(tb->tb_sb)));
64631+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64632 do_balance_starts(tb);
64633
64634 /* balance leaf returns 0 except if combining L R and S into
64635diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64636index ee382ef..f4eb6eb5 100644
64637--- a/fs/reiserfs/item_ops.c
64638+++ b/fs/reiserfs/item_ops.c
64639@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64640 }
64641
64642 static struct item_operations errcatch_ops = {
64643- errcatch_bytes_number,
64644- errcatch_decrement_key,
64645- errcatch_is_left_mergeable,
64646- errcatch_print_item,
64647- errcatch_check_item,
64648+ .bytes_number = errcatch_bytes_number,
64649+ .decrement_key = errcatch_decrement_key,
64650+ .is_left_mergeable = errcatch_is_left_mergeable,
64651+ .print_item = errcatch_print_item,
64652+ .check_item = errcatch_check_item,
64653
64654- errcatch_create_vi,
64655- errcatch_check_left,
64656- errcatch_check_right,
64657- errcatch_part_size,
64658- errcatch_unit_num,
64659- errcatch_print_vi
64660+ .create_vi = errcatch_create_vi,
64661+ .check_left = errcatch_check_left,
64662+ .check_right = errcatch_check_right,
64663+ .part_size = errcatch_part_size,
64664+ .unit_num = errcatch_unit_num,
64665+ .print_vi = errcatch_print_vi
64666 };
64667
64668 //////////////////////////////////////////////////////////////////////////////
64669diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64670index 02b0b7d..c85018b 100644
64671--- a/fs/reiserfs/procfs.c
64672+++ b/fs/reiserfs/procfs.c
64673@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64674 "SMALL_TAILS " : "NO_TAILS ",
64675 replay_only(sb) ? "REPLAY_ONLY " : "",
64676 convert_reiserfs(sb) ? "CONV " : "",
64677- atomic_read(&r->s_generation_counter),
64678+ atomic_read_unchecked(&r->s_generation_counter),
64679 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64680 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64681 SF(s_good_search_by_key_reada), SF(s_bmaps),
64682diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64683index 8d06adf..7e1c9f8 100644
64684--- a/fs/reiserfs/reiserfs.h
64685+++ b/fs/reiserfs/reiserfs.h
64686@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64687 /* Comment? -Hans */
64688 wait_queue_head_t s_wait;
64689 /* To be obsoleted soon by per buffer seals.. -Hans */
64690- atomic_t s_generation_counter; // increased by one every time the
64691+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64692 // tree gets re-balanced
64693 unsigned long s_properties; /* File system properties. Currently holds
64694 on-disk FS format */
64695@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64696 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64697
64698 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64699-#define get_generation(s) atomic_read (&fs_generation(s))
64700+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64701 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64702 #define __fs_changed(gen,s) (gen != get_generation (s))
64703 #define fs_changed(gen,s) \
64704diff --git a/fs/select.c b/fs/select.c
64705index 467bb1c..cf9d65a 100644
64706--- a/fs/select.c
64707+++ b/fs/select.c
64708@@ -20,6 +20,7 @@
64709 #include <linux/export.h>
64710 #include <linux/slab.h>
64711 #include <linux/poll.h>
64712+#include <linux/security.h>
64713 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64714 #include <linux/file.h>
64715 #include <linux/fdtable.h>
64716@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64717 struct poll_list *walk = head;
64718 unsigned long todo = nfds;
64719
64720+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64721 if (nfds > rlimit(RLIMIT_NOFILE))
64722 return -EINVAL;
64723
64724diff --git a/fs/seq_file.c b/fs/seq_file.c
64725index 1d641bb..c2f4743 100644
64726--- a/fs/seq_file.c
64727+++ b/fs/seq_file.c
64728@@ -10,6 +10,8 @@
64729 #include <linux/seq_file.h>
64730 #include <linux/slab.h>
64731 #include <linux/cred.h>
64732+#include <linux/sched.h>
64733+#include <linux/grsecurity.h>
64734
64735 #include <asm/uaccess.h>
64736 #include <asm/page.h>
64737@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64738 #ifdef CONFIG_USER_NS
64739 p->user_ns = file->f_cred->user_ns;
64740 #endif
64741+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64742+ p->exec_id = current->exec_id;
64743+#endif
64744
64745 /*
64746 * Wrappers around seq_open(e.g. swaps_open) need to be
64747@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64748 }
64749 EXPORT_SYMBOL(seq_open);
64750
64751+
64752+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64753+{
64754+ if (gr_proc_is_restricted())
64755+ return -EACCES;
64756+
64757+ return seq_open(file, op);
64758+}
64759+EXPORT_SYMBOL(seq_open_restrict);
64760+
64761 static int traverse(struct seq_file *m, loff_t offset)
64762 {
64763 loff_t pos = 0, index;
64764@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64765 return 0;
64766 }
64767 if (!m->buf) {
64768- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64769+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64770 if (!m->buf)
64771 return -ENOMEM;
64772 }
64773@@ -137,7 +152,7 @@ Eoverflow:
64774 m->op->stop(m, p);
64775 kfree(m->buf);
64776 m->count = 0;
64777- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64778+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64779 return !m->buf ? -ENOMEM : -EAGAIN;
64780 }
64781
64782@@ -153,7 +168,7 @@ Eoverflow:
64783 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64784 {
64785 struct seq_file *m = file->private_data;
64786- size_t copied = 0;
64787+ ssize_t copied = 0;
64788 loff_t pos;
64789 size_t n;
64790 void *p;
64791@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64792
64793 /* grab buffer if we didn't have one */
64794 if (!m->buf) {
64795- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64796+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64797 if (!m->buf)
64798 goto Enomem;
64799 }
64800@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64801 m->op->stop(m, p);
64802 kfree(m->buf);
64803 m->count = 0;
64804- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64805+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64806 if (!m->buf)
64807 goto Enomem;
64808 m->version = 0;
64809@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
64810 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64811 void *data)
64812 {
64813- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64814+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64815 int res = -ENOMEM;
64816
64817 if (op) {
64818@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
64819 }
64820 EXPORT_SYMBOL(single_open_size);
64821
64822+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
64823+ void *data)
64824+{
64825+ if (gr_proc_is_restricted())
64826+ return -EACCES;
64827+
64828+ return single_open(file, show, data);
64829+}
64830+EXPORT_SYMBOL(single_open_restrict);
64831+
64832+
64833 int single_release(struct inode *inode, struct file *file)
64834 {
64835 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
64836diff --git a/fs/splice.c b/fs/splice.c
64837index 12028fa..a6f2619 100644
64838--- a/fs/splice.c
64839+++ b/fs/splice.c
64840@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64841 pipe_lock(pipe);
64842
64843 for (;;) {
64844- if (!pipe->readers) {
64845+ if (!atomic_read(&pipe->readers)) {
64846 send_sig(SIGPIPE, current, 0);
64847 if (!ret)
64848 ret = -EPIPE;
64849@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64850 page_nr++;
64851 ret += buf->len;
64852
64853- if (pipe->files)
64854+ if (atomic_read(&pipe->files))
64855 do_wakeup = 1;
64856
64857 if (!--spd->nr_pages)
64858@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64859 do_wakeup = 0;
64860 }
64861
64862- pipe->waiting_writers++;
64863+ atomic_inc(&pipe->waiting_writers);
64864 pipe_wait(pipe);
64865- pipe->waiting_writers--;
64866+ atomic_dec(&pipe->waiting_writers);
64867 }
64868
64869 pipe_unlock(pipe);
64870@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64871 old_fs = get_fs();
64872 set_fs(get_ds());
64873 /* The cast to a user pointer is valid due to the set_fs() */
64874- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64875+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64876 set_fs(old_fs);
64877
64878 return res;
64879@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64880 old_fs = get_fs();
64881 set_fs(get_ds());
64882 /* The cast to a user pointer is valid due to the set_fs() */
64883- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64884+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64885 set_fs(old_fs);
64886
64887 return res;
64888@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64889 goto err;
64890
64891 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64892- vec[i].iov_base = (void __user *) page_address(page);
64893+ vec[i].iov_base = (void __force_user *) page_address(page);
64894 vec[i].iov_len = this_len;
64895 spd.pages[i] = page;
64896 spd.nr_pages++;
64897@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64898 ops->release(pipe, buf);
64899 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64900 pipe->nrbufs--;
64901- if (pipe->files)
64902+ if (atomic_read(&pipe->files))
64903 sd->need_wakeup = true;
64904 }
64905
64906@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64907 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64908 {
64909 while (!pipe->nrbufs) {
64910- if (!pipe->writers)
64911+ if (!atomic_read(&pipe->writers))
64912 return 0;
64913
64914- if (!pipe->waiting_writers && sd->num_spliced)
64915+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64916 return 0;
64917
64918 if (sd->flags & SPLICE_F_NONBLOCK)
64919@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64920 * out of the pipe right after the splice_to_pipe(). So set
64921 * PIPE_READERS appropriately.
64922 */
64923- pipe->readers = 1;
64924+ atomic_set(&pipe->readers, 1);
64925
64926 current->splice_pipe = pipe;
64927 }
64928@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64929
64930 partial[buffers].offset = off;
64931 partial[buffers].len = plen;
64932+ partial[buffers].private = 0;
64933
64934 off = 0;
64935 len -= plen;
64936@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64937 ret = -ERESTARTSYS;
64938 break;
64939 }
64940- if (!pipe->writers)
64941+ if (!atomic_read(&pipe->writers))
64942 break;
64943- if (!pipe->waiting_writers) {
64944+ if (!atomic_read(&pipe->waiting_writers)) {
64945 if (flags & SPLICE_F_NONBLOCK) {
64946 ret = -EAGAIN;
64947 break;
64948@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64949 pipe_lock(pipe);
64950
64951 while (pipe->nrbufs >= pipe->buffers) {
64952- if (!pipe->readers) {
64953+ if (!atomic_read(&pipe->readers)) {
64954 send_sig(SIGPIPE, current, 0);
64955 ret = -EPIPE;
64956 break;
64957@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64958 ret = -ERESTARTSYS;
64959 break;
64960 }
64961- pipe->waiting_writers++;
64962+ atomic_inc(&pipe->waiting_writers);
64963 pipe_wait(pipe);
64964- pipe->waiting_writers--;
64965+ atomic_dec(&pipe->waiting_writers);
64966 }
64967
64968 pipe_unlock(pipe);
64969@@ -1880,14 +1881,14 @@ retry:
64970 pipe_double_lock(ipipe, opipe);
64971
64972 do {
64973- if (!opipe->readers) {
64974+ if (!atomic_read(&opipe->readers)) {
64975 send_sig(SIGPIPE, current, 0);
64976 if (!ret)
64977 ret = -EPIPE;
64978 break;
64979 }
64980
64981- if (!ipipe->nrbufs && !ipipe->writers)
64982+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64983 break;
64984
64985 /*
64986@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64987 pipe_double_lock(ipipe, opipe);
64988
64989 do {
64990- if (!opipe->readers) {
64991+ if (!atomic_read(&opipe->readers)) {
64992 send_sig(SIGPIPE, current, 0);
64993 if (!ret)
64994 ret = -EPIPE;
64995@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64996 * return EAGAIN if we have the potential of some data in the
64997 * future, otherwise just return 0
64998 */
64999- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65000+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65001 ret = -EAGAIN;
65002
65003 pipe_unlock(ipipe);
65004diff --git a/fs/stat.c b/fs/stat.c
65005index ae0c3ce..9ee641c 100644
65006--- a/fs/stat.c
65007+++ b/fs/stat.c
65008@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65009 stat->gid = inode->i_gid;
65010 stat->rdev = inode->i_rdev;
65011 stat->size = i_size_read(inode);
65012- stat->atime = inode->i_atime;
65013- stat->mtime = inode->i_mtime;
65014+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65015+ stat->atime = inode->i_ctime;
65016+ stat->mtime = inode->i_ctime;
65017+ } else {
65018+ stat->atime = inode->i_atime;
65019+ stat->mtime = inode->i_mtime;
65020+ }
65021 stat->ctime = inode->i_ctime;
65022 stat->blksize = (1 << inode->i_blkbits);
65023 stat->blocks = inode->i_blocks;
65024@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65025 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65026 {
65027 struct inode *inode = path->dentry->d_inode;
65028+ int retval;
65029
65030- if (inode->i_op->getattr)
65031- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65032+ if (inode->i_op->getattr) {
65033+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65034+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65035+ stat->atime = stat->ctime;
65036+ stat->mtime = stat->ctime;
65037+ }
65038+ return retval;
65039+ }
65040
65041 generic_fillattr(inode, stat);
65042 return 0;
65043diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65044index ee0d761..b346c58 100644
65045--- a/fs/sysfs/dir.c
65046+++ b/fs/sysfs/dir.c
65047@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65048 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65049 {
65050 struct kernfs_node *parent, *kn;
65051+ const char *name;
65052+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65053+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65054+ const char *parent_name;
65055+#endif
65056
65057 BUG_ON(!kobj);
65058
65059+ name = kobject_name(kobj);
65060+
65061 if (kobj->parent)
65062 parent = kobj->parent->sd;
65063 else
65064@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65065 if (!parent)
65066 return -ENOENT;
65067
65068- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65069- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65070+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65071+ parent_name = parent->name;
65072+ mode = S_IRWXU;
65073+
65074+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65075+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65076+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65077+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65078+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65079+#endif
65080+
65081+ kn = kernfs_create_dir_ns(parent, name,
65082+ mode, kobj, ns);
65083 if (IS_ERR(kn)) {
65084 if (PTR_ERR(kn) == -EEXIST)
65085- sysfs_warn_dup(parent, kobject_name(kobj));
65086+ sysfs_warn_dup(parent, name);
65087 return PTR_ERR(kn);
65088 }
65089
65090diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65091index 69d4889..a810bd4 100644
65092--- a/fs/sysv/sysv.h
65093+++ b/fs/sysv/sysv.h
65094@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65095 #endif
65096 }
65097
65098-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65099+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65100 {
65101 if (sbi->s_bytesex == BYTESEX_PDP)
65102 return PDP_swab((__force __u32)n);
65103diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65104index e18b988..f1d4ad0f 100644
65105--- a/fs/ubifs/io.c
65106+++ b/fs/ubifs/io.c
65107@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65108 return err;
65109 }
65110
65111-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65112+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65113 {
65114 int err;
65115
65116diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65117index c175b4d..8f36a16 100644
65118--- a/fs/udf/misc.c
65119+++ b/fs/udf/misc.c
65120@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65121
65122 u8 udf_tag_checksum(const struct tag *t)
65123 {
65124- u8 *data = (u8 *)t;
65125+ const u8 *data = (const u8 *)t;
65126 u8 checksum = 0;
65127 int i;
65128 for (i = 0; i < sizeof(struct tag); ++i)
65129diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65130index 8d974c4..b82f6ec 100644
65131--- a/fs/ufs/swab.h
65132+++ b/fs/ufs/swab.h
65133@@ -22,7 +22,7 @@ enum {
65134 BYTESEX_BE
65135 };
65136
65137-static inline u64
65138+static inline u64 __intentional_overflow(-1)
65139 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65140 {
65141 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65142@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65143 return (__force __fs64)cpu_to_be64(n);
65144 }
65145
65146-static inline u32
65147+static inline u32 __intentional_overflow(-1)
65148 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65149 {
65150 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65151diff --git a/fs/utimes.c b/fs/utimes.c
65152index aa138d6..5f3a811 100644
65153--- a/fs/utimes.c
65154+++ b/fs/utimes.c
65155@@ -1,6 +1,7 @@
65156 #include <linux/compiler.h>
65157 #include <linux/file.h>
65158 #include <linux/fs.h>
65159+#include <linux/security.h>
65160 #include <linux/linkage.h>
65161 #include <linux/mount.h>
65162 #include <linux/namei.h>
65163@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65164 }
65165 }
65166 retry_deleg:
65167+
65168+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65169+ error = -EACCES;
65170+ goto mnt_drop_write_and_out;
65171+ }
65172+
65173 mutex_lock(&inode->i_mutex);
65174 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65175 mutex_unlock(&inode->i_mutex);
65176diff --git a/fs/xattr.c b/fs/xattr.c
65177index 3377dff..f394815 100644
65178--- a/fs/xattr.c
65179+++ b/fs/xattr.c
65180@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65181 return rc;
65182 }
65183
65184+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65185+ssize_t
65186+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65187+{
65188+ struct inode *inode = dentry->d_inode;
65189+ ssize_t error;
65190+
65191+ error = inode_permission(inode, MAY_EXEC);
65192+ if (error)
65193+ return error;
65194+
65195+ if (inode->i_op->getxattr)
65196+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65197+ else
65198+ error = -EOPNOTSUPP;
65199+
65200+ return error;
65201+}
65202+EXPORT_SYMBOL(pax_getxattr);
65203+#endif
65204+
65205 ssize_t
65206 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65207 {
65208@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65209 * Extended attribute SET operations
65210 */
65211 static long
65212-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65213+setxattr(struct path *path, const char __user *name, const void __user *value,
65214 size_t size, int flags)
65215 {
65216 int error;
65217@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65218 posix_acl_fix_xattr_from_user(kvalue, size);
65219 }
65220
65221- error = vfs_setxattr(d, kname, kvalue, size, flags);
65222+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65223+ error = -EACCES;
65224+ goto out;
65225+ }
65226+
65227+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65228 out:
65229 if (vvalue)
65230 vfree(vvalue);
65231@@ -377,7 +403,7 @@ retry:
65232 return error;
65233 error = mnt_want_write(path.mnt);
65234 if (!error) {
65235- error = setxattr(path.dentry, name, value, size, flags);
65236+ error = setxattr(&path, name, value, size, flags);
65237 mnt_drop_write(path.mnt);
65238 }
65239 path_put(&path);
65240@@ -401,7 +427,7 @@ retry:
65241 return error;
65242 error = mnt_want_write(path.mnt);
65243 if (!error) {
65244- error = setxattr(path.dentry, name, value, size, flags);
65245+ error = setxattr(&path, name, value, size, flags);
65246 mnt_drop_write(path.mnt);
65247 }
65248 path_put(&path);
65249@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65250 const void __user *,value, size_t, size, int, flags)
65251 {
65252 struct fd f = fdget(fd);
65253- struct dentry *dentry;
65254 int error = -EBADF;
65255
65256 if (!f.file)
65257 return error;
65258- dentry = f.file->f_path.dentry;
65259- audit_inode(NULL, dentry, 0);
65260+ audit_inode(NULL, f.file->f_path.dentry, 0);
65261 error = mnt_want_write_file(f.file);
65262 if (!error) {
65263- error = setxattr(dentry, name, value, size, flags);
65264+ error = setxattr(&f.file->f_path, name, value, size, flags);
65265 mnt_drop_write_file(f.file);
65266 }
65267 fdput(f);
65268@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65269 * Extended attribute REMOVE operations
65270 */
65271 static long
65272-removexattr(struct dentry *d, const char __user *name)
65273+removexattr(struct path *path, const char __user *name)
65274 {
65275 int error;
65276 char kname[XATTR_NAME_MAX + 1];
65277@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65278 if (error < 0)
65279 return error;
65280
65281- return vfs_removexattr(d, kname);
65282+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65283+ return -EACCES;
65284+
65285+ return vfs_removexattr(path->dentry, kname);
65286 }
65287
65288 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65289@@ -652,7 +679,7 @@ retry:
65290 return error;
65291 error = mnt_want_write(path.mnt);
65292 if (!error) {
65293- error = removexattr(path.dentry, name);
65294+ error = removexattr(&path, name);
65295 mnt_drop_write(path.mnt);
65296 }
65297 path_put(&path);
65298@@ -675,7 +702,7 @@ retry:
65299 return error;
65300 error = mnt_want_write(path.mnt);
65301 if (!error) {
65302- error = removexattr(path.dentry, name);
65303+ error = removexattr(&path, name);
65304 mnt_drop_write(path.mnt);
65305 }
65306 path_put(&path);
65307@@ -689,16 +716,16 @@ retry:
65308 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65309 {
65310 struct fd f = fdget(fd);
65311- struct dentry *dentry;
65312+ struct path *path;
65313 int error = -EBADF;
65314
65315 if (!f.file)
65316 return error;
65317- dentry = f.file->f_path.dentry;
65318- audit_inode(NULL, dentry, 0);
65319+ path = &f.file->f_path;
65320+ audit_inode(NULL, path->dentry, 0);
65321 error = mnt_want_write_file(f.file);
65322 if (!error) {
65323- error = removexattr(dentry, name);
65324+ error = removexattr(path, name);
65325 mnt_drop_write_file(f.file);
65326 }
65327 fdput(f);
65328diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65329index 152543c..d80c361 100644
65330--- a/fs/xfs/xfs_bmap.c
65331+++ b/fs/xfs/xfs_bmap.c
65332@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65333
65334 #else
65335 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65336-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65337+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65338 #endif /* DEBUG */
65339
65340 /*
65341diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65342index aead369..0dfecfd 100644
65343--- a/fs/xfs/xfs_dir2_readdir.c
65344+++ b/fs/xfs/xfs_dir2_readdir.c
65345@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65346 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65347 filetype = dp->d_ops->sf_get_ftype(sfep);
65348 ctx->pos = off & 0x7fffffff;
65349- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65350+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65351+ char name[sfep->namelen];
65352+ memcpy(name, sfep->name, sfep->namelen);
65353+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65354+ return 0;
65355+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65356 xfs_dir3_get_dtype(mp, filetype)))
65357 return 0;
65358 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65359diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65360index bcfe612..aa399c0 100644
65361--- a/fs/xfs/xfs_ioctl.c
65362+++ b/fs/xfs/xfs_ioctl.c
65363@@ -122,7 +122,7 @@ xfs_find_handle(
65364 }
65365
65366 error = -EFAULT;
65367- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65368+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65369 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65370 goto out_put;
65371
65372diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65373new file mode 100644
65374index 0000000..3abaf02
65375--- /dev/null
65376+++ b/grsecurity/Kconfig
65377@@ -0,0 +1,1161 @@
65378+#
65379+# grecurity configuration
65380+#
65381+menu "Memory Protections"
65382+depends on GRKERNSEC
65383+
65384+config GRKERNSEC_KMEM
65385+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65386+ default y if GRKERNSEC_CONFIG_AUTO
65387+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65388+ help
65389+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65390+ be written to or read from to modify or leak the contents of the running
65391+ kernel. /dev/port will also not be allowed to be opened, writing to
65392+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65393+ If you have module support disabled, enabling this will close up several
65394+ ways that are currently used to insert malicious code into the running
65395+ kernel.
65396+
65397+ Even with this feature enabled, we still highly recommend that
65398+ you use the RBAC system, as it is still possible for an attacker to
65399+ modify the running kernel through other more obscure methods.
65400+
65401+ It is highly recommended that you say Y here if you meet all the
65402+ conditions above.
65403+
65404+config GRKERNSEC_VM86
65405+ bool "Restrict VM86 mode"
65406+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65407+ depends on X86_32
65408+
65409+ help
65410+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65411+ make use of a special execution mode on 32bit x86 processors called
65412+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65413+ video cards and will still work with this option enabled. The purpose
65414+ of the option is to prevent exploitation of emulation errors in
65415+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65416+ Nearly all users should be able to enable this option.
65417+
65418+config GRKERNSEC_IO
65419+ bool "Disable privileged I/O"
65420+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65421+ depends on X86
65422+ select RTC_CLASS
65423+ select RTC_INTF_DEV
65424+ select RTC_DRV_CMOS
65425+
65426+ help
65427+ If you say Y here, all ioperm and iopl calls will return an error.
65428+ Ioperm and iopl can be used to modify the running kernel.
65429+ Unfortunately, some programs need this access to operate properly,
65430+ the most notable of which are XFree86 and hwclock. hwclock can be
65431+ remedied by having RTC support in the kernel, so real-time
65432+ clock support is enabled if this option is enabled, to ensure
65433+ that hwclock operates correctly. If hwclock still does not work,
65434+ either update udev or symlink /dev/rtc to /dev/rtc0.
65435+
65436+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65437+ you may not be able to boot into a graphical environment with this
65438+ option enabled. In this case, you should use the RBAC system instead.
65439+
65440+config GRKERNSEC_JIT_HARDEN
65441+ bool "Harden BPF JIT against spray attacks"
65442+ default y if GRKERNSEC_CONFIG_AUTO
65443+ depends on BPF_JIT && X86
65444+ help
65445+ If you say Y here, the native code generated by the kernel's Berkeley
65446+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65447+ attacks that attempt to fit attacker-beneficial instructions in
65448+ 32bit immediate fields of JIT-generated native instructions. The
65449+ attacker will generally aim to cause an unintended instruction sequence
65450+ of JIT-generated native code to execute by jumping into the middle of
65451+ a generated instruction. This feature effectively randomizes the 32bit
65452+ immediate constants present in the generated code to thwart such attacks.
65453+
65454+ If you're using KERNEXEC, it's recommended that you enable this option
65455+ to supplement the hardening of the kernel.
65456+
65457+config GRKERNSEC_PERF_HARDEN
65458+ bool "Disable unprivileged PERF_EVENTS usage by default"
65459+ default y if GRKERNSEC_CONFIG_AUTO
65460+ depends on PERF_EVENTS
65461+ help
65462+ If you say Y here, the range of acceptable values for the
65463+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65464+ default to a new value: 3. When the sysctl is set to this value, no
65465+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65466+
65467+ Though PERF_EVENTS can be used legitimately for performance monitoring
65468+ and low-level application profiling, it is forced on regardless of
65469+ configuration, has been at fault for several vulnerabilities, and
65470+ creates new opportunities for side channels and other information leaks.
65471+
65472+ This feature puts PERF_EVENTS into a secure default state and permits
65473+ the administrator to change out of it temporarily if unprivileged
65474+ application profiling is needed.
65475+
65476+config GRKERNSEC_RAND_THREADSTACK
65477+ bool "Insert random gaps between thread stacks"
65478+ default y if GRKERNSEC_CONFIG_AUTO
65479+ depends on PAX_RANDMMAP && !PPC
65480+ help
65481+ If you say Y here, a random-sized gap will be enforced between allocated
65482+ thread stacks. Glibc's NPTL and other threading libraries that
65483+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65484+ The implementation currently provides 8 bits of entropy for the gap.
65485+
65486+ Many distributions do not compile threaded remote services with the
65487+ -fstack-check argument to GCC, causing the variable-sized stack-based
65488+ allocator, alloca(), to not probe the stack on allocation. This
65489+ permits an unbounded alloca() to skip over any guard page and potentially
65490+ modify another thread's stack reliably. An enforced random gap
65491+ reduces the reliability of such an attack and increases the chance
65492+ that such a read/write to another thread's stack instead lands in
65493+ an unmapped area, causing a crash and triggering grsecurity's
65494+ anti-bruteforcing logic.
65495+
65496+config GRKERNSEC_PROC_MEMMAP
65497+ bool "Harden ASLR against information leaks and entropy reduction"
65498+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65499+ depends on PAX_NOEXEC || PAX_ASLR
65500+ help
65501+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65502+ give no information about the addresses of its mappings if
65503+ PaX features that rely on random addresses are enabled on the task.
65504+ In addition to sanitizing this information and disabling other
65505+ dangerous sources of information, this option causes reads of sensitive
65506+ /proc/<pid> entries where the file descriptor was opened in a different
65507+ task than the one performing the read. Such attempts are logged.
65508+ This option also limits argv/env strings for suid/sgid binaries
65509+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65510+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65511+ binaries to prevent alternative mmap layouts from being abused.
65512+
65513+ If you use PaX it is essential that you say Y here as it closes up
65514+ several holes that make full ASLR useless locally.
65515+
65516+config GRKERNSEC_BRUTE
65517+ bool "Deter exploit bruteforcing"
65518+ default y if GRKERNSEC_CONFIG_AUTO
65519+ help
65520+ If you say Y here, attempts to bruteforce exploits against forking
65521+ daemons such as apache or sshd, as well as against suid/sgid binaries
65522+ will be deterred. When a child of a forking daemon is killed by PaX
65523+ or crashes due to an illegal instruction or other suspicious signal,
65524+ the parent process will be delayed 30 seconds upon every subsequent
65525+ fork until the administrator is able to assess the situation and
65526+ restart the daemon.
65527+ In the suid/sgid case, the attempt is logged, the user has all their
65528+ existing instances of the suid/sgid binary terminated and will
65529+ be unable to execute any suid/sgid binaries for 15 minutes.
65530+
65531+ It is recommended that you also enable signal logging in the auditing
65532+ section so that logs are generated when a process triggers a suspicious
65533+ signal.
65534+ If the sysctl option is enabled, a sysctl option with name
65535+ "deter_bruteforce" is created.
65536+
65537+config GRKERNSEC_MODHARDEN
65538+ bool "Harden module auto-loading"
65539+ default y if GRKERNSEC_CONFIG_AUTO
65540+ depends on MODULES
65541+ help
65542+ If you say Y here, module auto-loading in response to use of some
65543+ feature implemented by an unloaded module will be restricted to
65544+ root users. Enabling this option helps defend against attacks
65545+ by unprivileged users who abuse the auto-loading behavior to
65546+ cause a vulnerable module to load that is then exploited.
65547+
65548+ If this option prevents a legitimate use of auto-loading for a
65549+ non-root user, the administrator can execute modprobe manually
65550+ with the exact name of the module mentioned in the alert log.
65551+ Alternatively, the administrator can add the module to the list
65552+ of modules loaded at boot by modifying init scripts.
65553+
65554+ Modification of init scripts will most likely be needed on
65555+ Ubuntu servers with encrypted home directory support enabled,
65556+ as the first non-root user logging in will cause the ecb(aes),
65557+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65558+
65559+config GRKERNSEC_HIDESYM
65560+ bool "Hide kernel symbols"
65561+ default y if GRKERNSEC_CONFIG_AUTO
65562+ select PAX_USERCOPY_SLABS
65563+ help
65564+ If you say Y here, getting information on loaded modules, and
65565+ displaying all kernel symbols through a syscall will be restricted
65566+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65567+ /proc/kallsyms will be restricted to the root user. The RBAC
65568+ system can hide that entry even from root.
65569+
65570+ This option also prevents leaking of kernel addresses through
65571+ several /proc entries.
65572+
65573+ Note that this option is only effective provided the following
65574+ conditions are met:
65575+ 1) The kernel using grsecurity is not precompiled by some distribution
65576+ 2) You have also enabled GRKERNSEC_DMESG
65577+ 3) You are using the RBAC system and hiding other files such as your
65578+ kernel image and System.map. Alternatively, enabling this option
65579+ causes the permissions on /boot, /lib/modules, and the kernel
65580+ source directory to change at compile time to prevent
65581+ reading by non-root users.
65582+ If the above conditions are met, this option will aid in providing a
65583+ useful protection against local kernel exploitation of overflows
65584+ and arbitrary read/write vulnerabilities.
65585+
65586+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65587+ in addition to this feature.
65588+
65589+config GRKERNSEC_RANDSTRUCT
65590+ bool "Randomize layout of sensitive kernel structures"
65591+ default y if GRKERNSEC_CONFIG_AUTO
65592+ select GRKERNSEC_HIDESYM
65593+ select MODVERSIONS if MODULES
65594+ help
65595+ If you say Y here, the layouts of a number of sensitive kernel
65596+ structures (task, fs, cred, etc) and all structures composed entirely
65597+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65598+ This can introduce the requirement of an additional infoleak
65599+ vulnerability for exploits targeting these structure types.
65600+
65601+ Enabling this feature will introduce some performance impact, slightly
65602+ increase memory usage, and prevent the use of forensic tools like
65603+ Volatility against the system (unless the kernel source tree isn't
65604+ cleaned after kernel installation).
65605+
65606+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65607+ It remains after a make clean to allow for external modules to be compiled
65608+ with the existing seed and will be removed by a make mrproper or
65609+ make distclean.
65610+
65611+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65612+ to install the supporting headers explicitly in addition to the normal
65613+ gcc package.
65614+
65615+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65616+ bool "Use cacheline-aware structure randomization"
65617+ depends on GRKERNSEC_RANDSTRUCT
65618+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65619+ help
65620+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65621+ at restricting randomization to cacheline-sized groups of elements. It
65622+ will further not randomize bitfields in structures. This reduces the
65623+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65624+
65625+config GRKERNSEC_KERN_LOCKOUT
65626+ bool "Active kernel exploit response"
65627+ default y if GRKERNSEC_CONFIG_AUTO
65628+ depends on X86 || ARM || PPC || SPARC
65629+ help
65630+ If you say Y here, when a PaX alert is triggered due to suspicious
65631+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65632+ or an OOPS occurs due to bad memory accesses, instead of just
65633+ terminating the offending process (and potentially allowing
65634+ a subsequent exploit from the same user), we will take one of two
65635+ actions:
65636+ If the user was root, we will panic the system
65637+ If the user was non-root, we will log the attempt, terminate
65638+ all processes owned by the user, then prevent them from creating
65639+ any new processes until the system is restarted
65640+ This deters repeated kernel exploitation/bruteforcing attempts
65641+ and is useful for later forensics.
65642+
65643+config GRKERNSEC_OLD_ARM_USERLAND
65644+ bool "Old ARM userland compatibility"
65645+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65646+ help
65647+ If you say Y here, stubs of executable code to perform such operations
65648+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65649+ table. This is unfortunately needed for old ARM userland meant to run
65650+ across a wide range of processors. Without this option enabled,
65651+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65652+ which is enough for Linaro userlands or other userlands designed for v6
65653+ and newer ARM CPUs. It's recommended that you try without this option enabled
65654+ first, and only enable it if your userland does not boot (it will likely fail
65655+ at init time).
65656+
65657+endmenu
65658+menu "Role Based Access Control Options"
65659+depends on GRKERNSEC
65660+
65661+config GRKERNSEC_RBAC_DEBUG
65662+ bool
65663+
65664+config GRKERNSEC_NO_RBAC
65665+ bool "Disable RBAC system"
65666+ help
65667+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65668+ preventing the RBAC system from being enabled. You should only say Y
65669+ here if you have no intention of using the RBAC system, so as to prevent
65670+ an attacker with root access from misusing the RBAC system to hide files
65671+ and processes when loadable module support and /dev/[k]mem have been
65672+ locked down.
65673+
65674+config GRKERNSEC_ACL_HIDEKERN
65675+ bool "Hide kernel processes"
65676+ help
65677+ If you say Y here, all kernel threads will be hidden to all
65678+ processes but those whose subject has the "view hidden processes"
65679+ flag.
65680+
65681+config GRKERNSEC_ACL_MAXTRIES
65682+ int "Maximum tries before password lockout"
65683+ default 3
65684+ help
65685+ This option enforces the maximum number of times a user can attempt
65686+ to authorize themselves with the grsecurity RBAC system before being
65687+ denied the ability to attempt authorization again for a specified time.
65688+ The lower the number, the harder it will be to brute-force a password.
65689+
65690+config GRKERNSEC_ACL_TIMEOUT
65691+ int "Time to wait after max password tries, in seconds"
65692+ default 30
65693+ help
65694+ This option specifies the time the user must wait after attempting to
65695+ authorize to the RBAC system with the maximum number of invalid
65696+ passwords. The higher the number, the harder it will be to brute-force
65697+ a password.
65698+
65699+endmenu
65700+menu "Filesystem Protections"
65701+depends on GRKERNSEC
65702+
65703+config GRKERNSEC_PROC
65704+ bool "Proc restrictions"
65705+ default y if GRKERNSEC_CONFIG_AUTO
65706+ help
65707+ If you say Y here, the permissions of the /proc filesystem
65708+ will be altered to enhance system security and privacy. You MUST
65709+ choose either a user only restriction or a user and group restriction.
65710+ Depending upon the option you choose, you can either restrict users to
65711+ see only the processes they themselves run, or choose a group that can
65712+ view all processes and files normally restricted to root if you choose
65713+ the "restrict to user only" option. NOTE: If you're running identd or
65714+ ntpd as a non-root user, you will have to run it as the group you
65715+ specify here.
65716+
65717+config GRKERNSEC_PROC_USER
65718+ bool "Restrict /proc to user only"
65719+ depends on GRKERNSEC_PROC
65720+ help
65721+ If you say Y here, non-root users will only be able to view their own
65722+ processes, and restricts them from viewing network-related information,
65723+ and viewing kernel symbol and module information.
65724+
65725+config GRKERNSEC_PROC_USERGROUP
65726+ bool "Allow special group"
65727+ default y if GRKERNSEC_CONFIG_AUTO
65728+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65729+ help
65730+ If you say Y here, you will be able to select a group that will be
65731+ able to view all processes and network-related information. If you've
65732+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65733+ remain hidden. This option is useful if you want to run identd as
65734+ a non-root user. The group you select may also be chosen at boot time
65735+ via "grsec_proc_gid=" on the kernel commandline.
65736+
65737+config GRKERNSEC_PROC_GID
65738+ int "GID for special group"
65739+ depends on GRKERNSEC_PROC_USERGROUP
65740+ default 1001
65741+
65742+config GRKERNSEC_PROC_ADD
65743+ bool "Additional restrictions"
65744+ default y if GRKERNSEC_CONFIG_AUTO
65745+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65746+ help
65747+ If you say Y here, additional restrictions will be placed on
65748+ /proc that keep normal users from viewing device information and
65749+ slabinfo information that could be useful for exploits.
65750+
65751+config GRKERNSEC_LINK
65752+ bool "Linking restrictions"
65753+ default y if GRKERNSEC_CONFIG_AUTO
65754+ help
65755+ If you say Y here, /tmp race exploits will be prevented, since users
65756+ will no longer be able to follow symlinks owned by other users in
65757+ world-writable +t directories (e.g. /tmp), unless the owner of the
65758+ symlink is the owner of the directory. users will also not be
65759+ able to hardlink to files they do not own. If the sysctl option is
65760+ enabled, a sysctl option with name "linking_restrictions" is created.
65761+
65762+config GRKERNSEC_SYMLINKOWN
65763+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65764+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65765+ help
65766+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65767+ that prevents it from being used as a security feature. As Apache
65768+ verifies the symlink by performing a stat() against the target of
65769+ the symlink before it is followed, an attacker can setup a symlink
65770+ to point to a same-owned file, then replace the symlink with one
65771+ that targets another user's file just after Apache "validates" the
65772+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65773+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65774+ will be in place for the group you specify. If the sysctl option
65775+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65776+ created.
65777+
65778+config GRKERNSEC_SYMLINKOWN_GID
65779+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65780+ depends on GRKERNSEC_SYMLINKOWN
65781+ default 1006
65782+ help
65783+ Setting this GID determines what group kernel-enforced
65784+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65785+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65786+
65787+config GRKERNSEC_FIFO
65788+ bool "FIFO restrictions"
65789+ default y if GRKERNSEC_CONFIG_AUTO
65790+ help
65791+ If you say Y here, users will not be able to write to FIFOs they don't
65792+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65793+ the FIFO is the same owner of the directory it's held in. If the sysctl
65794+ option is enabled, a sysctl option with name "fifo_restrictions" is
65795+ created.
65796+
65797+config GRKERNSEC_SYSFS_RESTRICT
65798+ bool "Sysfs/debugfs restriction"
65799+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65800+ depends on SYSFS
65801+ help
65802+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65803+ any filesystem normally mounted under it (e.g. debugfs) will be
65804+ mostly accessible only by root. These filesystems generally provide access
65805+ to hardware and debug information that isn't appropriate for unprivileged
65806+ users of the system. Sysfs and debugfs have also become a large source
65807+ of new vulnerabilities, ranging from infoleaks to local compromise.
65808+ There has been very little oversight with an eye toward security involved
65809+ in adding new exporters of information to these filesystems, so their
65810+ use is discouraged.
65811+ For reasons of compatibility, a few directories have been whitelisted
65812+ for access by non-root users:
65813+ /sys/fs/selinux
65814+ /sys/fs/fuse
65815+ /sys/devices/system/cpu
65816+
65817+config GRKERNSEC_ROFS
65818+ bool "Runtime read-only mount protection"
65819+ depends on SYSCTL
65820+ help
65821+ If you say Y here, a sysctl option with name "romount_protect" will
65822+ be created. By setting this option to 1 at runtime, filesystems
65823+ will be protected in the following ways:
65824+ * No new writable mounts will be allowed
65825+ * Existing read-only mounts won't be able to be remounted read/write
65826+ * Write operations will be denied on all block devices
65827+ This option acts independently of grsec_lock: once it is set to 1,
65828+ it cannot be turned off. Therefore, please be mindful of the resulting
65829+ behavior if this option is enabled in an init script on a read-only
65830+ filesystem.
65831+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65832+ and GRKERNSEC_IO should be enabled and module loading disabled via
65833+ config or at runtime.
65834+ This feature is mainly intended for secure embedded systems.
65835+
65836+
65837+config GRKERNSEC_DEVICE_SIDECHANNEL
65838+ bool "Eliminate stat/notify-based device sidechannels"
65839+ default y if GRKERNSEC_CONFIG_AUTO
65840+ help
65841+ If you say Y here, timing analyses on block or character
65842+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65843+ will be thwarted for unprivileged users. If a process without
65844+ CAP_MKNOD stats such a device, the last access and last modify times
65845+ will match the device's create time. No access or modify events
65846+ will be triggered through inotify/dnotify/fanotify for such devices.
65847+ This feature will prevent attacks that may at a minimum
65848+ allow an attacker to determine the administrator's password length.
65849+
65850+config GRKERNSEC_CHROOT
65851+ bool "Chroot jail restrictions"
65852+ default y if GRKERNSEC_CONFIG_AUTO
65853+ help
65854+ If you say Y here, you will be able to choose several options that will
65855+ make breaking out of a chrooted jail much more difficult. If you
65856+ encounter no software incompatibilities with the following options, it
65857+ is recommended that you enable each one.
65858+
65859+ Note that the chroot restrictions are not intended to apply to "chroots"
65860+ to directories that are simple bind mounts of the global root filesystem.
65861+ For several other reasons, a user shouldn't expect any significant
65862+ security by performing such a chroot.
65863+
65864+config GRKERNSEC_CHROOT_MOUNT
65865+ bool "Deny mounts"
65866+ default y if GRKERNSEC_CONFIG_AUTO
65867+ depends on GRKERNSEC_CHROOT
65868+ help
65869+ If you say Y here, processes inside a chroot will not be able to
65870+ mount or remount filesystems. If the sysctl option is enabled, a
65871+ sysctl option with name "chroot_deny_mount" is created.
65872+
65873+config GRKERNSEC_CHROOT_DOUBLE
65874+ bool "Deny double-chroots"
65875+ default y if GRKERNSEC_CONFIG_AUTO
65876+ depends on GRKERNSEC_CHROOT
65877+ help
65878+ If you say Y here, processes inside a chroot will not be able to chroot
65879+ again outside the chroot. This is a widely used method of breaking
65880+ out of a chroot jail and should not be allowed. If the sysctl
65881+ option is enabled, a sysctl option with name
65882+ "chroot_deny_chroot" is created.
65883+
65884+config GRKERNSEC_CHROOT_PIVOT
65885+ bool "Deny pivot_root in chroot"
65886+ default y if GRKERNSEC_CONFIG_AUTO
65887+ depends on GRKERNSEC_CHROOT
65888+ help
65889+ If you say Y here, processes inside a chroot will not be able to use
65890+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65891+ works similar to chroot in that it changes the root filesystem. This
65892+ function could be misused in a chrooted process to attempt to break out
65893+ of the chroot, and therefore should not be allowed. If the sysctl
65894+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
65895+ created.
65896+
65897+config GRKERNSEC_CHROOT_CHDIR
65898+ bool "Enforce chdir(\"/\") on all chroots"
65899+ default y if GRKERNSEC_CONFIG_AUTO
65900+ depends on GRKERNSEC_CHROOT
65901+ help
65902+ If you say Y here, the current working directory of all newly-chrooted
65903+ applications will be set to the the root directory of the chroot.
65904+ The man page on chroot(2) states:
65905+ Note that this call does not change the current working
65906+ directory, so that `.' can be outside the tree rooted at
65907+ `/'. In particular, the super-user can escape from a
65908+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65909+
65910+ It is recommended that you say Y here, since it's not known to break
65911+ any software. If the sysctl option is enabled, a sysctl option with
65912+ name "chroot_enforce_chdir" is created.
65913+
65914+config GRKERNSEC_CHROOT_CHMOD
65915+ bool "Deny (f)chmod +s"
65916+ default y if GRKERNSEC_CONFIG_AUTO
65917+ depends on GRKERNSEC_CHROOT
65918+ help
65919+ If you say Y here, processes inside a chroot will not be able to chmod
65920+ or fchmod files to make them have suid or sgid bits. This protects
65921+ against another published method of breaking a chroot. If the sysctl
65922+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
65923+ created.
65924+
65925+config GRKERNSEC_CHROOT_FCHDIR
65926+ bool "Deny fchdir out of chroot"
65927+ default y if GRKERNSEC_CONFIG_AUTO
65928+ depends on GRKERNSEC_CHROOT
65929+ help
65930+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
65931+ to a file descriptor of the chrooting process that points to a directory
65932+ outside the filesystem will be stopped. If the sysctl option
65933+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65934+
65935+config GRKERNSEC_CHROOT_MKNOD
65936+ bool "Deny mknod"
65937+ default y if GRKERNSEC_CONFIG_AUTO
65938+ depends on GRKERNSEC_CHROOT
65939+ help
65940+ If you say Y here, processes inside a chroot will not be allowed to
65941+ mknod. The problem with using mknod inside a chroot is that it
65942+ would allow an attacker to create a device entry that is the same
65943+ as one on the physical root of your system, which could range from
65944+ anything from the console device to a device for your harddrive (which
65945+ they could then use to wipe the drive or steal data). It is recommended
65946+ that you say Y here, unless you run into software incompatibilities.
65947+ If the sysctl option is enabled, a sysctl option with name
65948+ "chroot_deny_mknod" is created.
65949+
65950+config GRKERNSEC_CHROOT_SHMAT
65951+ bool "Deny shmat() out of chroot"
65952+ default y if GRKERNSEC_CONFIG_AUTO
65953+ depends on GRKERNSEC_CHROOT
65954+ help
65955+ If you say Y here, processes inside a chroot will not be able to attach
65956+ to shared memory segments that were created outside of the chroot jail.
65957+ It is recommended that you say Y here. If the sysctl option is enabled,
65958+ a sysctl option with name "chroot_deny_shmat" is created.
65959+
65960+config GRKERNSEC_CHROOT_UNIX
65961+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
65962+ default y if GRKERNSEC_CONFIG_AUTO
65963+ depends on GRKERNSEC_CHROOT
65964+ help
65965+ If you say Y here, processes inside a chroot will not be able to
65966+ connect to abstract (meaning not belonging to a filesystem) Unix
65967+ domain sockets that were bound outside of a chroot. It is recommended
65968+ that you say Y here. If the sysctl option is enabled, a sysctl option
65969+ with name "chroot_deny_unix" is created.
65970+
65971+config GRKERNSEC_CHROOT_FINDTASK
65972+ bool "Protect outside processes"
65973+ default y if GRKERNSEC_CONFIG_AUTO
65974+ depends on GRKERNSEC_CHROOT
65975+ help
65976+ If you say Y here, processes inside a chroot will not be able to
65977+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65978+ getsid, or view any process outside of the chroot. If the sysctl
65979+ option is enabled, a sysctl option with name "chroot_findtask" is
65980+ created.
65981+
65982+config GRKERNSEC_CHROOT_NICE
65983+ bool "Restrict priority changes"
65984+ default y if GRKERNSEC_CONFIG_AUTO
65985+ depends on GRKERNSEC_CHROOT
65986+ help
65987+ If you say Y here, processes inside a chroot will not be able to raise
65988+ the priority of processes in the chroot, or alter the priority of
65989+ processes outside the chroot. This provides more security than simply
65990+ removing CAP_SYS_NICE from the process' capability set. If the
65991+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65992+ is created.
65993+
65994+config GRKERNSEC_CHROOT_SYSCTL
65995+ bool "Deny sysctl writes"
65996+ default y if GRKERNSEC_CONFIG_AUTO
65997+ depends on GRKERNSEC_CHROOT
65998+ help
65999+ If you say Y here, an attacker in a chroot will not be able to
66000+ write to sysctl entries, either by sysctl(2) or through a /proc
66001+ interface. It is strongly recommended that you say Y here. If the
66002+ sysctl option is enabled, a sysctl option with name
66003+ "chroot_deny_sysctl" is created.
66004+
66005+config GRKERNSEC_CHROOT_CAPS
66006+ bool "Capability restrictions"
66007+ default y if GRKERNSEC_CONFIG_AUTO
66008+ depends on GRKERNSEC_CHROOT
66009+ help
66010+ If you say Y here, the capabilities on all processes within a
66011+ chroot jail will be lowered to stop module insertion, raw i/o,
66012+ system and net admin tasks, rebooting the system, modifying immutable
66013+ files, modifying IPC owned by another, and changing the system time.
66014+ This is left an option because it can break some apps. Disable this
66015+ if your chrooted apps are having problems performing those kinds of
66016+ tasks. If the sysctl option is enabled, a sysctl option with
66017+ name "chroot_caps" is created.
66018+
66019+config GRKERNSEC_CHROOT_INITRD
66020+ bool "Exempt initrd tasks from restrictions"
66021+ default y if GRKERNSEC_CONFIG_AUTO
66022+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66023+ help
66024+ If you say Y here, tasks started prior to init will be exempted from
66025+ grsecurity's chroot restrictions. This option is mainly meant to
66026+ resolve Plymouth's performing privileged operations unnecessarily
66027+ in a chroot.
66028+
66029+endmenu
66030+menu "Kernel Auditing"
66031+depends on GRKERNSEC
66032+
66033+config GRKERNSEC_AUDIT_GROUP
66034+ bool "Single group for auditing"
66035+ help
66036+ If you say Y here, the exec and chdir logging features will only operate
66037+ on a group you specify. This option is recommended if you only want to
66038+ watch certain users instead of having a large amount of logs from the
66039+ entire system. If the sysctl option is enabled, a sysctl option with
66040+ name "audit_group" is created.
66041+
66042+config GRKERNSEC_AUDIT_GID
66043+ int "GID for auditing"
66044+ depends on GRKERNSEC_AUDIT_GROUP
66045+ default 1007
66046+
66047+config GRKERNSEC_EXECLOG
66048+ bool "Exec logging"
66049+ help
66050+ If you say Y here, all execve() calls will be logged (since the
66051+ other exec*() calls are frontends to execve(), all execution
66052+ will be logged). Useful for shell-servers that like to keep track
66053+ of their users. If the sysctl option is enabled, a sysctl option with
66054+ name "exec_logging" is created.
66055+ WARNING: This option when enabled will produce a LOT of logs, especially
66056+ on an active system.
66057+
66058+config GRKERNSEC_RESLOG
66059+ bool "Resource logging"
66060+ default y if GRKERNSEC_CONFIG_AUTO
66061+ help
66062+ If you say Y here, all attempts to overstep resource limits will
66063+ be logged with the resource name, the requested size, and the current
66064+ limit. It is highly recommended that you say Y here. If the sysctl
66065+ option is enabled, a sysctl option with name "resource_logging" is
66066+ created. If the RBAC system is enabled, the sysctl value is ignored.
66067+
66068+config GRKERNSEC_CHROOT_EXECLOG
66069+ bool "Log execs within chroot"
66070+ help
66071+ If you say Y here, all executions inside a chroot jail will be logged
66072+ to syslog. This can cause a large amount of logs if certain
66073+ applications (eg. djb's daemontools) are installed on the system, and
66074+ is therefore left as an option. If the sysctl option is enabled, a
66075+ sysctl option with name "chroot_execlog" is created.
66076+
66077+config GRKERNSEC_AUDIT_PTRACE
66078+ bool "Ptrace logging"
66079+ help
66080+ If you say Y here, all attempts to attach to a process via ptrace
66081+ will be logged. If the sysctl option is enabled, a sysctl option
66082+ with name "audit_ptrace" is created.
66083+
66084+config GRKERNSEC_AUDIT_CHDIR
66085+ bool "Chdir logging"
66086+ help
66087+ If you say Y here, all chdir() calls will be logged. If the sysctl
66088+ option is enabled, a sysctl option with name "audit_chdir" is created.
66089+
66090+config GRKERNSEC_AUDIT_MOUNT
66091+ bool "(Un)Mount logging"
66092+ help
66093+ If you say Y here, all mounts and unmounts will be logged. If the
66094+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66095+ created.
66096+
66097+config GRKERNSEC_SIGNAL
66098+ bool "Signal logging"
66099+ default y if GRKERNSEC_CONFIG_AUTO
66100+ help
66101+ If you say Y here, certain important signals will be logged, such as
66102+ SIGSEGV, which will as a result inform you of when a error in a program
66103+ occurred, which in some cases could mean a possible exploit attempt.
66104+ If the sysctl option is enabled, a sysctl option with name
66105+ "signal_logging" is created.
66106+
66107+config GRKERNSEC_FORKFAIL
66108+ bool "Fork failure logging"
66109+ help
66110+ If you say Y here, all failed fork() attempts will be logged.
66111+ This could suggest a fork bomb, or someone attempting to overstep
66112+ their process limit. If the sysctl option is enabled, a sysctl option
66113+ with name "forkfail_logging" is created.
66114+
66115+config GRKERNSEC_TIME
66116+ bool "Time change logging"
66117+ default y if GRKERNSEC_CONFIG_AUTO
66118+ help
66119+ If you say Y here, any changes of the system clock will be logged.
66120+ If the sysctl option is enabled, a sysctl option with name
66121+ "timechange_logging" is created.
66122+
66123+config GRKERNSEC_PROC_IPADDR
66124+ bool "/proc/<pid>/ipaddr support"
66125+ default y if GRKERNSEC_CONFIG_AUTO
66126+ help
66127+ If you say Y here, a new entry will be added to each /proc/<pid>
66128+ directory that contains the IP address of the person using the task.
66129+ The IP is carried across local TCP and AF_UNIX stream sockets.
66130+ This information can be useful for IDS/IPSes to perform remote response
66131+ to a local attack. The entry is readable by only the owner of the
66132+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66133+ the RBAC system), and thus does not create privacy concerns.
66134+
66135+config GRKERNSEC_RWXMAP_LOG
66136+ bool 'Denied RWX mmap/mprotect logging'
66137+ default y if GRKERNSEC_CONFIG_AUTO
66138+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66139+ help
66140+ If you say Y here, calls to mmap() and mprotect() with explicit
66141+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66142+ denied by the PAX_MPROTECT feature. This feature will also
66143+ log other problematic scenarios that can occur when PAX_MPROTECT
66144+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66145+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66146+ is created.
66147+
66148+endmenu
66149+
66150+menu "Executable Protections"
66151+depends on GRKERNSEC
66152+
66153+config GRKERNSEC_DMESG
66154+ bool "Dmesg(8) restriction"
66155+ default y if GRKERNSEC_CONFIG_AUTO
66156+ help
66157+ If you say Y here, non-root users will not be able to use dmesg(8)
66158+ to view the contents of the kernel's circular log buffer.
66159+ The kernel's log buffer often contains kernel addresses and other
66160+ identifying information useful to an attacker in fingerprinting a
66161+ system for a targeted exploit.
66162+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66163+ created.
66164+
66165+config GRKERNSEC_HARDEN_PTRACE
66166+ bool "Deter ptrace-based process snooping"
66167+ default y if GRKERNSEC_CONFIG_AUTO
66168+ help
66169+ If you say Y here, TTY sniffers and other malicious monitoring
66170+ programs implemented through ptrace will be defeated. If you
66171+ have been using the RBAC system, this option has already been
66172+ enabled for several years for all users, with the ability to make
66173+ fine-grained exceptions.
66174+
66175+ This option only affects the ability of non-root users to ptrace
66176+ processes that are not a descendent of the ptracing process.
66177+ This means that strace ./binary and gdb ./binary will still work,
66178+ but attaching to arbitrary processes will not. If the sysctl
66179+ option is enabled, a sysctl option with name "harden_ptrace" is
66180+ created.
66181+
66182+config GRKERNSEC_PTRACE_READEXEC
66183+ bool "Require read access to ptrace sensitive binaries"
66184+ default y if GRKERNSEC_CONFIG_AUTO
66185+ help
66186+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66187+ binaries. This option is useful in environments that
66188+ remove the read bits (e.g. file mode 4711) from suid binaries to
66189+ prevent infoleaking of their contents. This option adds
66190+ consistency to the use of that file mode, as the binary could normally
66191+ be read out when run without privileges while ptracing.
66192+
66193+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66194+ is created.
66195+
66196+config GRKERNSEC_SETXID
66197+ bool "Enforce consistent multithreaded privileges"
66198+ default y if GRKERNSEC_CONFIG_AUTO
66199+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66200+ help
66201+ If you say Y here, a change from a root uid to a non-root uid
66202+ in a multithreaded application will cause the resulting uids,
66203+ gids, supplementary groups, and capabilities in that thread
66204+ to be propagated to the other threads of the process. In most
66205+ cases this is unnecessary, as glibc will emulate this behavior
66206+ on behalf of the application. Other libcs do not act in the
66207+ same way, allowing the other threads of the process to continue
66208+ running with root privileges. If the sysctl option is enabled,
66209+ a sysctl option with name "consistent_setxid" is created.
66210+
66211+config GRKERNSEC_HARDEN_IPC
66212+ bool "Disallow access to overly-permissive IPC objects"
66213+ default y if GRKERNSEC_CONFIG_AUTO
66214+ depends on SYSVIPC
66215+ help
66216+ If you say Y here, access to overly-permissive IPC objects (shared
66217+ memory, message queues, and semaphores) will be denied for processes
66218+ given the following criteria beyond normal permission checks:
66219+ 1) If the IPC object is world-accessible and the euid doesn't match
66220+ that of the creator or current uid for the IPC object
66221+ 2) If the IPC object is group-accessible and the egid doesn't
66222+ match that of the creator or current gid for the IPC object
66223+ It's a common error to grant too much permission to these objects,
66224+ with impact ranging from denial of service and information leaking to
66225+ privilege escalation. This feature was developed in response to
66226+ research by Tim Brown:
66227+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66228+ who found hundreds of such insecure usages. Processes with
66229+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66230+ If the sysctl option is enabled, a sysctl option with name
66231+ "harden_ipc" is created.
66232+
66233+config GRKERNSEC_TPE
66234+ bool "Trusted Path Execution (TPE)"
66235+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66236+ help
66237+ If you say Y here, you will be able to choose a gid to add to the
66238+ supplementary groups of users you want to mark as "untrusted."
66239+ These users will not be able to execute any files that are not in
66240+ root-owned directories writable only by root. If the sysctl option
66241+ is enabled, a sysctl option with name "tpe" is created.
66242+
66243+config GRKERNSEC_TPE_ALL
66244+ bool "Partially restrict all non-root users"
66245+ depends on GRKERNSEC_TPE
66246+ help
66247+ If you say Y here, all non-root users will be covered under
66248+ a weaker TPE restriction. This is separate from, and in addition to,
66249+ the main TPE options that you have selected elsewhere. Thus, if a
66250+ "trusted" GID is chosen, this restriction applies to even that GID.
66251+ Under this restriction, all non-root users will only be allowed to
66252+ execute files in directories they own that are not group or
66253+ world-writable, or in directories owned by root and writable only by
66254+ root. If the sysctl option is enabled, a sysctl option with name
66255+ "tpe_restrict_all" is created.
66256+
66257+config GRKERNSEC_TPE_INVERT
66258+ bool "Invert GID option"
66259+ depends on GRKERNSEC_TPE
66260+ help
66261+ If you say Y here, the group you specify in the TPE configuration will
66262+ decide what group TPE restrictions will be *disabled* for. This
66263+ option is useful if you want TPE restrictions to be applied to most
66264+ users on the system. If the sysctl option is enabled, a sysctl option
66265+ with name "tpe_invert" is created. Unlike other sysctl options, this
66266+ entry will default to on for backward-compatibility.
66267+
66268+config GRKERNSEC_TPE_GID
66269+ int
66270+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66271+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66272+
66273+config GRKERNSEC_TPE_UNTRUSTED_GID
66274+ int "GID for TPE-untrusted users"
66275+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66276+ default 1005
66277+ help
66278+ Setting this GID determines what group TPE restrictions will be
66279+ *enabled* for. If the sysctl option is enabled, a sysctl option
66280+ with name "tpe_gid" is created.
66281+
66282+config GRKERNSEC_TPE_TRUSTED_GID
66283+ int "GID for TPE-trusted users"
66284+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66285+ default 1005
66286+ help
66287+ Setting this GID determines what group TPE restrictions will be
66288+ *disabled* for. If the sysctl option is enabled, a sysctl option
66289+ with name "tpe_gid" is created.
66290+
66291+endmenu
66292+menu "Network Protections"
66293+depends on GRKERNSEC
66294+
66295+config GRKERNSEC_RANDNET
66296+ bool "Larger entropy pools"
66297+ default y if GRKERNSEC_CONFIG_AUTO
66298+ help
66299+ If you say Y here, the entropy pools used for many features of Linux
66300+ and grsecurity will be doubled in size. Since several grsecurity
66301+ features use additional randomness, it is recommended that you say Y
66302+ here. Saying Y here has a similar effect as modifying
66303+ /proc/sys/kernel/random/poolsize.
66304+
66305+config GRKERNSEC_BLACKHOLE
66306+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66307+ default y if GRKERNSEC_CONFIG_AUTO
66308+ depends on NET
66309+ help
66310+ If you say Y here, neither TCP resets nor ICMP
66311+ destination-unreachable packets will be sent in response to packets
66312+ sent to ports for which no associated listening process exists.
66313+ This feature supports both IPV4 and IPV6 and exempts the
66314+ loopback interface from blackholing. Enabling this feature
66315+ makes a host more resilient to DoS attacks and reduces network
66316+ visibility against scanners.
66317+
66318+ The blackhole feature as-implemented is equivalent to the FreeBSD
66319+ blackhole feature, as it prevents RST responses to all packets, not
66320+ just SYNs. Under most application behavior this causes no
66321+ problems, but applications (like haproxy) may not close certain
66322+ connections in a way that cleanly terminates them on the remote
66323+ end, leaving the remote host in LAST_ACK state. Because of this
66324+ side-effect and to prevent intentional LAST_ACK DoSes, this
66325+ feature also adds automatic mitigation against such attacks.
66326+ The mitigation drastically reduces the amount of time a socket
66327+ can spend in LAST_ACK state. If you're using haproxy and not
66328+ all servers it connects to have this option enabled, consider
66329+ disabling this feature on the haproxy host.
66330+
66331+ If the sysctl option is enabled, two sysctl options with names
66332+ "ip_blackhole" and "lastack_retries" will be created.
66333+ While "ip_blackhole" takes the standard zero/non-zero on/off
66334+ toggle, "lastack_retries" uses the same kinds of values as
66335+ "tcp_retries1" and "tcp_retries2". The default value of 4
66336+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66337+ state.
66338+
66339+config GRKERNSEC_NO_SIMULT_CONNECT
66340+ bool "Disable TCP Simultaneous Connect"
66341+ default y if GRKERNSEC_CONFIG_AUTO
66342+ depends on NET
66343+ help
66344+ If you say Y here, a feature by Willy Tarreau will be enabled that
66345+ removes a weakness in Linux's strict implementation of TCP that
66346+ allows two clients to connect to each other without either entering
66347+ a listening state. The weakness allows an attacker to easily prevent
66348+ a client from connecting to a known server provided the source port
66349+ for the connection is guessed correctly.
66350+
66351+ As the weakness could be used to prevent an antivirus or IPS from
66352+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66353+ it should be eliminated by enabling this option. Though Linux is
66354+ one of few operating systems supporting simultaneous connect, it
66355+ has no legitimate use in practice and is rarely supported by firewalls.
66356+
66357+config GRKERNSEC_SOCKET
66358+ bool "Socket restrictions"
66359+ depends on NET
66360+ help
66361+ If you say Y here, you will be able to choose from several options.
66362+ If you assign a GID on your system and add it to the supplementary
66363+ groups of users you want to restrict socket access to, this patch
66364+ will perform up to three things, based on the option(s) you choose.
66365+
66366+config GRKERNSEC_SOCKET_ALL
66367+ bool "Deny any sockets to group"
66368+ depends on GRKERNSEC_SOCKET
66369+ help
66370+ If you say Y here, you will be able to choose a GID of whose users will
66371+ be unable to connect to other hosts from your machine or run server
66372+ applications from your machine. If the sysctl option is enabled, a
66373+ sysctl option with name "socket_all" is created.
66374+
66375+config GRKERNSEC_SOCKET_ALL_GID
66376+ int "GID to deny all sockets for"
66377+ depends on GRKERNSEC_SOCKET_ALL
66378+ default 1004
66379+ help
66380+ Here you can choose the GID to disable socket access for. Remember to
66381+ add the users you want socket access disabled for to the GID
66382+ specified here. If the sysctl option is enabled, a sysctl option
66383+ with name "socket_all_gid" is created.
66384+
66385+config GRKERNSEC_SOCKET_CLIENT
66386+ bool "Deny client sockets to group"
66387+ depends on GRKERNSEC_SOCKET
66388+ help
66389+ If you say Y here, you will be able to choose a GID of whose users will
66390+ be unable to connect to other hosts from your machine, but will be
66391+ able to run servers. If this option is enabled, all users in the group
66392+ you specify will have to use passive mode when initiating ftp transfers
66393+ from the shell on your machine. If the sysctl option is enabled, a
66394+ sysctl option with name "socket_client" is created.
66395+
66396+config GRKERNSEC_SOCKET_CLIENT_GID
66397+ int "GID to deny client sockets for"
66398+ depends on GRKERNSEC_SOCKET_CLIENT
66399+ default 1003
66400+ help
66401+ Here you can choose the GID to disable client socket access for.
66402+ Remember to add the users you want client socket access disabled for to
66403+ the GID specified here. If the sysctl option is enabled, a sysctl
66404+ option with name "socket_client_gid" is created.
66405+
66406+config GRKERNSEC_SOCKET_SERVER
66407+ bool "Deny server sockets to group"
66408+ depends on GRKERNSEC_SOCKET
66409+ help
66410+ If you say Y here, you will be able to choose a GID of whose users will
66411+ be unable to run server applications from your machine. If the sysctl
66412+ option is enabled, a sysctl option with name "socket_server" is created.
66413+
66414+config GRKERNSEC_SOCKET_SERVER_GID
66415+ int "GID to deny server sockets for"
66416+ depends on GRKERNSEC_SOCKET_SERVER
66417+ default 1002
66418+ help
66419+ Here you can choose the GID to disable server socket access for.
66420+ Remember to add the users you want server socket access disabled for to
66421+ the GID specified here. If the sysctl option is enabled, a sysctl
66422+ option with name "socket_server_gid" is created.
66423+
66424+endmenu
66425+
66426+menu "Physical Protections"
66427+depends on GRKERNSEC
66428+
66429+config GRKERNSEC_DENYUSB
66430+ bool "Deny new USB connections after toggle"
66431+ default y if GRKERNSEC_CONFIG_AUTO
66432+ depends on SYSCTL && USB_SUPPORT
66433+ help
66434+ If you say Y here, a new sysctl option with name "deny_new_usb"
66435+ will be created. Setting its value to 1 will prevent any new
66436+ USB devices from being recognized by the OS. Any attempted USB
66437+ device insertion will be logged. This option is intended to be
66438+ used against custom USB devices designed to exploit vulnerabilities
66439+ in various USB device drivers.
66440+
66441+ For greatest effectiveness, this sysctl should be set after any
66442+ relevant init scripts. This option is safe to enable in distros
66443+ as each user can choose whether or not to toggle the sysctl.
66444+
66445+config GRKERNSEC_DENYUSB_FORCE
66446+ bool "Reject all USB devices not connected at boot"
66447+ select USB
66448+ depends on GRKERNSEC_DENYUSB
66449+ help
66450+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66451+ that doesn't involve a sysctl entry. This option should only be
66452+ enabled if you're sure you want to deny all new USB connections
66453+ at runtime and don't want to modify init scripts. This should not
66454+ be enabled by distros. It forces the core USB code to be built
66455+ into the kernel image so that all devices connected at boot time
66456+ can be recognized and new USB device connections can be prevented
66457+ prior to init running.
66458+
66459+endmenu
66460+
66461+menu "Sysctl Support"
66462+depends on GRKERNSEC && SYSCTL
66463+
66464+config GRKERNSEC_SYSCTL
66465+ bool "Sysctl support"
66466+ default y if GRKERNSEC_CONFIG_AUTO
66467+ help
66468+ If you say Y here, you will be able to change the options that
66469+ grsecurity runs with at bootup, without having to recompile your
66470+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66471+ to enable (1) or disable (0) various features. All the sysctl entries
66472+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66473+ All features enabled in the kernel configuration are disabled at boot
66474+ if you do not say Y to the "Turn on features by default" option.
66475+ All options should be set at startup, and the grsec_lock entry should
66476+ be set to a non-zero value after all the options are set.
66477+ *THIS IS EXTREMELY IMPORTANT*
66478+
66479+config GRKERNSEC_SYSCTL_DISTRO
66480+ bool "Extra sysctl support for distro makers (READ HELP)"
66481+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66482+ help
66483+ If you say Y here, additional sysctl options will be created
66484+ for features that affect processes running as root. Therefore,
66485+ it is critical when using this option that the grsec_lock entry be
66486+ enabled after boot. Only distros with prebuilt kernel packages
66487+ with this option enabled that can ensure grsec_lock is enabled
66488+ after boot should use this option.
66489+ *Failure to set grsec_lock after boot makes all grsec features
66490+ this option covers useless*
66491+
66492+ Currently this option creates the following sysctl entries:
66493+ "Disable Privileged I/O": "disable_priv_io"
66494+
66495+config GRKERNSEC_SYSCTL_ON
66496+ bool "Turn on features by default"
66497+ default y if GRKERNSEC_CONFIG_AUTO
66498+ depends on GRKERNSEC_SYSCTL
66499+ help
66500+ If you say Y here, instead of having all features enabled in the
66501+ kernel configuration disabled at boot time, the features will be
66502+ enabled at boot time. It is recommended you say Y here unless
66503+ there is some reason you would want all sysctl-tunable features to
66504+ be disabled by default. As mentioned elsewhere, it is important
66505+ to enable the grsec_lock entry once you have finished modifying
66506+ the sysctl entries.
66507+
66508+endmenu
66509+menu "Logging Options"
66510+depends on GRKERNSEC
66511+
66512+config GRKERNSEC_FLOODTIME
66513+ int "Seconds in between log messages (minimum)"
66514+ default 10
66515+ help
66516+ This option allows you to enforce the number of seconds between
66517+ grsecurity log messages. The default should be suitable for most
66518+ people, however, if you choose to change it, choose a value small enough
66519+ to allow informative logs to be produced, but large enough to
66520+ prevent flooding.
66521+
66522+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66523+ any rate limiting on grsecurity log messages.
66524+
66525+config GRKERNSEC_FLOODBURST
66526+ int "Number of messages in a burst (maximum)"
66527+ default 6
66528+ help
66529+ This option allows you to choose the maximum number of messages allowed
66530+ within the flood time interval you chose in a separate option. The
66531+ default should be suitable for most people, however if you find that
66532+ many of your logs are being interpreted as flooding, you may want to
66533+ raise this value.
66534+
66535+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66536+ any rate limiting on grsecurity log messages.
66537+
66538+endmenu
66539diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66540new file mode 100644
66541index 0000000..30ababb
66542--- /dev/null
66543+++ b/grsecurity/Makefile
66544@@ -0,0 +1,54 @@
66545+# grsecurity – access control and security hardening for Linux
66546+# All code in this directory and various hooks located throughout the Linux kernel are
66547+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66548+# http://www.grsecurity.net spender@grsecurity.net
66549+#
66550+# This program is free software; you can redistribute it and/or
66551+# modify it under the terms of the GNU General Public License version 2
66552+# as published by the Free Software Foundation.
66553+#
66554+# This program is distributed in the hope that it will be useful,
66555+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66556+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66557+# GNU General Public License for more details.
66558+#
66559+# You should have received a copy of the GNU General Public License
66560+# along with this program; if not, write to the Free Software
66561+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66562+
66563+KBUILD_CFLAGS += -Werror
66564+
66565+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66566+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66567+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66568+ grsec_usb.o grsec_ipc.o grsec_proc.o
66569+
66570+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66571+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66572+ gracl_learn.o grsec_log.o gracl_policy.o
66573+ifdef CONFIG_COMPAT
66574+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66575+endif
66576+
66577+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66578+
66579+ifdef CONFIG_NET
66580+obj-y += grsec_sock.o
66581+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66582+endif
66583+
66584+ifndef CONFIG_GRKERNSEC
66585+obj-y += grsec_disabled.o
66586+endif
66587+
66588+ifdef CONFIG_GRKERNSEC_HIDESYM
66589+extra-y := grsec_hidesym.o
66590+$(obj)/grsec_hidesym.o:
66591+ @-chmod -f 500 /boot
66592+ @-chmod -f 500 /lib/modules
66593+ @-chmod -f 500 /lib64/modules
66594+ @-chmod -f 500 /lib32/modules
66595+ @-chmod -f 700 .
66596+ @-chmod -f 700 $(objtree)
66597+ @echo ' grsec: protected kernel image paths'
66598+endif
66599diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66600new file mode 100644
66601index 0000000..e56396f
66602--- /dev/null
66603+++ b/grsecurity/gracl.c
66604@@ -0,0 +1,2679 @@
66605+#include <linux/kernel.h>
66606+#include <linux/module.h>
66607+#include <linux/sched.h>
66608+#include <linux/mm.h>
66609+#include <linux/file.h>
66610+#include <linux/fs.h>
66611+#include <linux/namei.h>
66612+#include <linux/mount.h>
66613+#include <linux/tty.h>
66614+#include <linux/proc_fs.h>
66615+#include <linux/lglock.h>
66616+#include <linux/slab.h>
66617+#include <linux/vmalloc.h>
66618+#include <linux/types.h>
66619+#include <linux/sysctl.h>
66620+#include <linux/netdevice.h>
66621+#include <linux/ptrace.h>
66622+#include <linux/gracl.h>
66623+#include <linux/gralloc.h>
66624+#include <linux/security.h>
66625+#include <linux/grinternal.h>
66626+#include <linux/pid_namespace.h>
66627+#include <linux/stop_machine.h>
66628+#include <linux/fdtable.h>
66629+#include <linux/percpu.h>
66630+#include <linux/lglock.h>
66631+#include <linux/hugetlb.h>
66632+#include <linux/posix-timers.h>
66633+#include <linux/prefetch.h>
66634+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66635+#include <linux/magic.h>
66636+#include <linux/pagemap.h>
66637+#include "../fs/btrfs/async-thread.h"
66638+#include "../fs/btrfs/ctree.h"
66639+#include "../fs/btrfs/btrfs_inode.h"
66640+#endif
66641+#include "../fs/mount.h"
66642+
66643+#include <asm/uaccess.h>
66644+#include <asm/errno.h>
66645+#include <asm/mman.h>
66646+
66647+#define FOR_EACH_ROLE_START(role) \
66648+ role = running_polstate.role_list; \
66649+ while (role) {
66650+
66651+#define FOR_EACH_ROLE_END(role) \
66652+ role = role->prev; \
66653+ }
66654+
66655+extern struct path gr_real_root;
66656+
66657+static struct gr_policy_state running_polstate;
66658+struct gr_policy_state *polstate = &running_polstate;
66659+extern struct gr_alloc_state *current_alloc_state;
66660+
66661+extern char *gr_shared_page[4];
66662+DEFINE_RWLOCK(gr_inode_lock);
66663+
66664+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66665+
66666+#ifdef CONFIG_NET
66667+extern struct vfsmount *sock_mnt;
66668+#endif
66669+
66670+extern struct vfsmount *pipe_mnt;
66671+extern struct vfsmount *shm_mnt;
66672+
66673+#ifdef CONFIG_HUGETLBFS
66674+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66675+#endif
66676+
66677+extern u16 acl_sp_role_value;
66678+extern struct acl_object_label *fakefs_obj_rw;
66679+extern struct acl_object_label *fakefs_obj_rwx;
66680+
66681+int gr_acl_is_enabled(void)
66682+{
66683+ return (gr_status & GR_READY);
66684+}
66685+
66686+void gr_enable_rbac_system(void)
66687+{
66688+ pax_open_kernel();
66689+ gr_status |= GR_READY;
66690+ pax_close_kernel();
66691+}
66692+
66693+int gr_rbac_disable(void *unused)
66694+{
66695+ pax_open_kernel();
66696+ gr_status &= ~GR_READY;
66697+ pax_close_kernel();
66698+
66699+ return 0;
66700+}
66701+
66702+static inline dev_t __get_dev(const struct dentry *dentry)
66703+{
66704+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66705+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66706+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66707+ else
66708+#endif
66709+ return dentry->d_sb->s_dev;
66710+}
66711+
66712+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66713+{
66714+ return __get_dev(dentry);
66715+}
66716+
66717+static char gr_task_roletype_to_char(struct task_struct *task)
66718+{
66719+ switch (task->role->roletype &
66720+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66721+ GR_ROLE_SPECIAL)) {
66722+ case GR_ROLE_DEFAULT:
66723+ return 'D';
66724+ case GR_ROLE_USER:
66725+ return 'U';
66726+ case GR_ROLE_GROUP:
66727+ return 'G';
66728+ case GR_ROLE_SPECIAL:
66729+ return 'S';
66730+ }
66731+
66732+ return 'X';
66733+}
66734+
66735+char gr_roletype_to_char(void)
66736+{
66737+ return gr_task_roletype_to_char(current);
66738+}
66739+
66740+__inline__ int
66741+gr_acl_tpe_check(void)
66742+{
66743+ if (unlikely(!(gr_status & GR_READY)))
66744+ return 0;
66745+ if (current->role->roletype & GR_ROLE_TPE)
66746+ return 1;
66747+ else
66748+ return 0;
66749+}
66750+
66751+int
66752+gr_handle_rawio(const struct inode *inode)
66753+{
66754+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66755+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66756+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66757+ !capable(CAP_SYS_RAWIO))
66758+ return 1;
66759+#endif
66760+ return 0;
66761+}
66762+
66763+int
66764+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66765+{
66766+ if (likely(lena != lenb))
66767+ return 0;
66768+
66769+ return !memcmp(a, b, lena);
66770+}
66771+
66772+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66773+{
66774+ *buflen -= namelen;
66775+ if (*buflen < 0)
66776+ return -ENAMETOOLONG;
66777+ *buffer -= namelen;
66778+ memcpy(*buffer, str, namelen);
66779+ return 0;
66780+}
66781+
66782+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66783+{
66784+ return prepend(buffer, buflen, name->name, name->len);
66785+}
66786+
66787+static int prepend_path(const struct path *path, struct path *root,
66788+ char **buffer, int *buflen)
66789+{
66790+ struct dentry *dentry = path->dentry;
66791+ struct vfsmount *vfsmnt = path->mnt;
66792+ struct mount *mnt = real_mount(vfsmnt);
66793+ bool slash = false;
66794+ int error = 0;
66795+
66796+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66797+ struct dentry * parent;
66798+
66799+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66800+ /* Global root? */
66801+ if (!mnt_has_parent(mnt)) {
66802+ goto out;
66803+ }
66804+ dentry = mnt->mnt_mountpoint;
66805+ mnt = mnt->mnt_parent;
66806+ vfsmnt = &mnt->mnt;
66807+ continue;
66808+ }
66809+ parent = dentry->d_parent;
66810+ prefetch(parent);
66811+ spin_lock(&dentry->d_lock);
66812+ error = prepend_name(buffer, buflen, &dentry->d_name);
66813+ spin_unlock(&dentry->d_lock);
66814+ if (!error)
66815+ error = prepend(buffer, buflen, "/", 1);
66816+ if (error)
66817+ break;
66818+
66819+ slash = true;
66820+ dentry = parent;
66821+ }
66822+
66823+out:
66824+ if (!error && !slash)
66825+ error = prepend(buffer, buflen, "/", 1);
66826+
66827+ return error;
66828+}
66829+
66830+/* this must be called with mount_lock and rename_lock held */
66831+
66832+static char *__our_d_path(const struct path *path, struct path *root,
66833+ char *buf, int buflen)
66834+{
66835+ char *res = buf + buflen;
66836+ int error;
66837+
66838+ prepend(&res, &buflen, "\0", 1);
66839+ error = prepend_path(path, root, &res, &buflen);
66840+ if (error)
66841+ return ERR_PTR(error);
66842+
66843+ return res;
66844+}
66845+
66846+static char *
66847+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66848+{
66849+ char *retval;
66850+
66851+ retval = __our_d_path(path, root, buf, buflen);
66852+ if (unlikely(IS_ERR(retval)))
66853+ retval = strcpy(buf, "<path too long>");
66854+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66855+ retval[1] = '\0';
66856+
66857+ return retval;
66858+}
66859+
66860+static char *
66861+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66862+ char *buf, int buflen)
66863+{
66864+ struct path path;
66865+ char *res;
66866+
66867+ path.dentry = (struct dentry *)dentry;
66868+ path.mnt = (struct vfsmount *)vfsmnt;
66869+
66870+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66871+ by the RBAC system */
66872+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66873+
66874+ return res;
66875+}
66876+
66877+static char *
66878+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66879+ char *buf, int buflen)
66880+{
66881+ char *res;
66882+ struct path path;
66883+ struct path root;
66884+ struct task_struct *reaper = init_pid_ns.child_reaper;
66885+
66886+ path.dentry = (struct dentry *)dentry;
66887+ path.mnt = (struct vfsmount *)vfsmnt;
66888+
66889+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66890+ get_fs_root(reaper->fs, &root);
66891+
66892+ read_seqlock_excl(&mount_lock);
66893+ write_seqlock(&rename_lock);
66894+ res = gen_full_path(&path, &root, buf, buflen);
66895+ write_sequnlock(&rename_lock);
66896+ read_sequnlock_excl(&mount_lock);
66897+
66898+ path_put(&root);
66899+ return res;
66900+}
66901+
66902+char *
66903+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66904+{
66905+ char *ret;
66906+ read_seqlock_excl(&mount_lock);
66907+ write_seqlock(&rename_lock);
66908+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66909+ PAGE_SIZE);
66910+ write_sequnlock(&rename_lock);
66911+ read_sequnlock_excl(&mount_lock);
66912+ return ret;
66913+}
66914+
66915+static char *
66916+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66917+{
66918+ char *ret;
66919+ char *buf;
66920+ int buflen;
66921+
66922+ read_seqlock_excl(&mount_lock);
66923+ write_seqlock(&rename_lock);
66924+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66925+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66926+ buflen = (int)(ret - buf);
66927+ if (buflen >= 5)
66928+ prepend(&ret, &buflen, "/proc", 5);
66929+ else
66930+ ret = strcpy(buf, "<path too long>");
66931+ write_sequnlock(&rename_lock);
66932+ read_sequnlock_excl(&mount_lock);
66933+ return ret;
66934+}
66935+
66936+char *
66937+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66938+{
66939+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66940+ PAGE_SIZE);
66941+}
66942+
66943+char *
66944+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66945+{
66946+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66947+ PAGE_SIZE);
66948+}
66949+
66950+char *
66951+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66952+{
66953+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66954+ PAGE_SIZE);
66955+}
66956+
66957+char *
66958+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66959+{
66960+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66961+ PAGE_SIZE);
66962+}
66963+
66964+char *
66965+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66966+{
66967+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66968+ PAGE_SIZE);
66969+}
66970+
66971+__inline__ __u32
66972+to_gr_audit(const __u32 reqmode)
66973+{
66974+ /* masks off auditable permission flags, then shifts them to create
66975+ auditing flags, and adds the special case of append auditing if
66976+ we're requesting write */
66977+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66978+}
66979+
66980+struct acl_role_label *
66981+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66982+ const gid_t gid)
66983+{
66984+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66985+ struct acl_role_label *match;
66986+ struct role_allowed_ip *ipp;
66987+ unsigned int x;
66988+ u32 curr_ip = task->signal->saved_ip;
66989+
66990+ match = state->acl_role_set.r_hash[index];
66991+
66992+ while (match) {
66993+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66994+ for (x = 0; x < match->domain_child_num; x++) {
66995+ if (match->domain_children[x] == uid)
66996+ goto found;
66997+ }
66998+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66999+ break;
67000+ match = match->next;
67001+ }
67002+found:
67003+ if (match == NULL) {
67004+ try_group:
67005+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67006+ match = state->acl_role_set.r_hash[index];
67007+
67008+ while (match) {
67009+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67010+ for (x = 0; x < match->domain_child_num; x++) {
67011+ if (match->domain_children[x] == gid)
67012+ goto found2;
67013+ }
67014+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67015+ break;
67016+ match = match->next;
67017+ }
67018+found2:
67019+ if (match == NULL)
67020+ match = state->default_role;
67021+ if (match->allowed_ips == NULL)
67022+ return match;
67023+ else {
67024+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67025+ if (likely
67026+ ((ntohl(curr_ip) & ipp->netmask) ==
67027+ (ntohl(ipp->addr) & ipp->netmask)))
67028+ return match;
67029+ }
67030+ match = state->default_role;
67031+ }
67032+ } else if (match->allowed_ips == NULL) {
67033+ return match;
67034+ } else {
67035+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67036+ if (likely
67037+ ((ntohl(curr_ip) & ipp->netmask) ==
67038+ (ntohl(ipp->addr) & ipp->netmask)))
67039+ return match;
67040+ }
67041+ goto try_group;
67042+ }
67043+
67044+ return match;
67045+}
67046+
67047+static struct acl_role_label *
67048+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67049+ const gid_t gid)
67050+{
67051+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67052+}
67053+
67054+struct acl_subject_label *
67055+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67056+ const struct acl_role_label *role)
67057+{
67058+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67059+ struct acl_subject_label *match;
67060+
67061+ match = role->subj_hash[index];
67062+
67063+ while (match && (match->inode != ino || match->device != dev ||
67064+ (match->mode & GR_DELETED))) {
67065+ match = match->next;
67066+ }
67067+
67068+ if (match && !(match->mode & GR_DELETED))
67069+ return match;
67070+ else
67071+ return NULL;
67072+}
67073+
67074+struct acl_subject_label *
67075+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67076+ const struct acl_role_label *role)
67077+{
67078+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67079+ struct acl_subject_label *match;
67080+
67081+ match = role->subj_hash[index];
67082+
67083+ while (match && (match->inode != ino || match->device != dev ||
67084+ !(match->mode & GR_DELETED))) {
67085+ match = match->next;
67086+ }
67087+
67088+ if (match && (match->mode & GR_DELETED))
67089+ return match;
67090+ else
67091+ return NULL;
67092+}
67093+
67094+static struct acl_object_label *
67095+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67096+ const struct acl_subject_label *subj)
67097+{
67098+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67099+ struct acl_object_label *match;
67100+
67101+ match = subj->obj_hash[index];
67102+
67103+ while (match && (match->inode != ino || match->device != dev ||
67104+ (match->mode & GR_DELETED))) {
67105+ match = match->next;
67106+ }
67107+
67108+ if (match && !(match->mode & GR_DELETED))
67109+ return match;
67110+ else
67111+ return NULL;
67112+}
67113+
67114+static struct acl_object_label *
67115+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67116+ const struct acl_subject_label *subj)
67117+{
67118+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67119+ struct acl_object_label *match;
67120+
67121+ match = subj->obj_hash[index];
67122+
67123+ while (match && (match->inode != ino || match->device != dev ||
67124+ !(match->mode & GR_DELETED))) {
67125+ match = match->next;
67126+ }
67127+
67128+ if (match && (match->mode & GR_DELETED))
67129+ return match;
67130+
67131+ match = subj->obj_hash[index];
67132+
67133+ while (match && (match->inode != ino || match->device != dev ||
67134+ (match->mode & GR_DELETED))) {
67135+ match = match->next;
67136+ }
67137+
67138+ if (match && !(match->mode & GR_DELETED))
67139+ return match;
67140+ else
67141+ return NULL;
67142+}
67143+
67144+struct name_entry *
67145+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67146+{
67147+ unsigned int len = strlen(name);
67148+ unsigned int key = full_name_hash(name, len);
67149+ unsigned int index = key % state->name_set.n_size;
67150+ struct name_entry *match;
67151+
67152+ match = state->name_set.n_hash[index];
67153+
67154+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67155+ match = match->next;
67156+
67157+ return match;
67158+}
67159+
67160+static struct name_entry *
67161+lookup_name_entry(const char *name)
67162+{
67163+ return __lookup_name_entry(&running_polstate, name);
67164+}
67165+
67166+static struct name_entry *
67167+lookup_name_entry_create(const char *name)
67168+{
67169+ unsigned int len = strlen(name);
67170+ unsigned int key = full_name_hash(name, len);
67171+ unsigned int index = key % running_polstate.name_set.n_size;
67172+ struct name_entry *match;
67173+
67174+ match = running_polstate.name_set.n_hash[index];
67175+
67176+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67177+ !match->deleted))
67178+ match = match->next;
67179+
67180+ if (match && match->deleted)
67181+ return match;
67182+
67183+ match = running_polstate.name_set.n_hash[index];
67184+
67185+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67186+ match->deleted))
67187+ match = match->next;
67188+
67189+ if (match && !match->deleted)
67190+ return match;
67191+ else
67192+ return NULL;
67193+}
67194+
67195+static struct inodev_entry *
67196+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67197+{
67198+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67199+ struct inodev_entry *match;
67200+
67201+ match = running_polstate.inodev_set.i_hash[index];
67202+
67203+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67204+ match = match->next;
67205+
67206+ return match;
67207+}
67208+
67209+void
67210+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67211+{
67212+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67213+ state->inodev_set.i_size);
67214+ struct inodev_entry **curr;
67215+
67216+ entry->prev = NULL;
67217+
67218+ curr = &state->inodev_set.i_hash[index];
67219+ if (*curr != NULL)
67220+ (*curr)->prev = entry;
67221+
67222+ entry->next = *curr;
67223+ *curr = entry;
67224+
67225+ return;
67226+}
67227+
67228+static void
67229+insert_inodev_entry(struct inodev_entry *entry)
67230+{
67231+ __insert_inodev_entry(&running_polstate, entry);
67232+}
67233+
67234+void
67235+insert_acl_obj_label(struct acl_object_label *obj,
67236+ struct acl_subject_label *subj)
67237+{
67238+ unsigned int index =
67239+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67240+ struct acl_object_label **curr;
67241+
67242+ obj->prev = NULL;
67243+
67244+ curr = &subj->obj_hash[index];
67245+ if (*curr != NULL)
67246+ (*curr)->prev = obj;
67247+
67248+ obj->next = *curr;
67249+ *curr = obj;
67250+
67251+ return;
67252+}
67253+
67254+void
67255+insert_acl_subj_label(struct acl_subject_label *obj,
67256+ struct acl_role_label *role)
67257+{
67258+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67259+ struct acl_subject_label **curr;
67260+
67261+ obj->prev = NULL;
67262+
67263+ curr = &role->subj_hash[index];
67264+ if (*curr != NULL)
67265+ (*curr)->prev = obj;
67266+
67267+ obj->next = *curr;
67268+ *curr = obj;
67269+
67270+ return;
67271+}
67272+
67273+/* derived from glibc fnmatch() 0: match, 1: no match*/
67274+
67275+static int
67276+glob_match(const char *p, const char *n)
67277+{
67278+ char c;
67279+
67280+ while ((c = *p++) != '\0') {
67281+ switch (c) {
67282+ case '?':
67283+ if (*n == '\0')
67284+ return 1;
67285+ else if (*n == '/')
67286+ return 1;
67287+ break;
67288+ case '\\':
67289+ if (*n != c)
67290+ return 1;
67291+ break;
67292+ case '*':
67293+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67294+ if (*n == '/')
67295+ return 1;
67296+ else if (c == '?') {
67297+ if (*n == '\0')
67298+ return 1;
67299+ else
67300+ ++n;
67301+ }
67302+ }
67303+ if (c == '\0') {
67304+ return 0;
67305+ } else {
67306+ const char *endp;
67307+
67308+ if ((endp = strchr(n, '/')) == NULL)
67309+ endp = n + strlen(n);
67310+
67311+ if (c == '[') {
67312+ for (--p; n < endp; ++n)
67313+ if (!glob_match(p, n))
67314+ return 0;
67315+ } else if (c == '/') {
67316+ while (*n != '\0' && *n != '/')
67317+ ++n;
67318+ if (*n == '/' && !glob_match(p, n + 1))
67319+ return 0;
67320+ } else {
67321+ for (--p; n < endp; ++n)
67322+ if (*n == c && !glob_match(p, n))
67323+ return 0;
67324+ }
67325+
67326+ return 1;
67327+ }
67328+ case '[':
67329+ {
67330+ int not;
67331+ char cold;
67332+
67333+ if (*n == '\0' || *n == '/')
67334+ return 1;
67335+
67336+ not = (*p == '!' || *p == '^');
67337+ if (not)
67338+ ++p;
67339+
67340+ c = *p++;
67341+ for (;;) {
67342+ unsigned char fn = (unsigned char)*n;
67343+
67344+ if (c == '\0')
67345+ return 1;
67346+ else {
67347+ if (c == fn)
67348+ goto matched;
67349+ cold = c;
67350+ c = *p++;
67351+
67352+ if (c == '-' && *p != ']') {
67353+ unsigned char cend = *p++;
67354+
67355+ if (cend == '\0')
67356+ return 1;
67357+
67358+ if (cold <= fn && fn <= cend)
67359+ goto matched;
67360+
67361+ c = *p++;
67362+ }
67363+ }
67364+
67365+ if (c == ']')
67366+ break;
67367+ }
67368+ if (!not)
67369+ return 1;
67370+ break;
67371+ matched:
67372+ while (c != ']') {
67373+ if (c == '\0')
67374+ return 1;
67375+
67376+ c = *p++;
67377+ }
67378+ if (not)
67379+ return 1;
67380+ }
67381+ break;
67382+ default:
67383+ if (c != *n)
67384+ return 1;
67385+ }
67386+
67387+ ++n;
67388+ }
67389+
67390+ if (*n == '\0')
67391+ return 0;
67392+
67393+ if (*n == '/')
67394+ return 0;
67395+
67396+ return 1;
67397+}
67398+
67399+static struct acl_object_label *
67400+chk_glob_label(struct acl_object_label *globbed,
67401+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67402+{
67403+ struct acl_object_label *tmp;
67404+
67405+ if (*path == NULL)
67406+ *path = gr_to_filename_nolock(dentry, mnt);
67407+
67408+ tmp = globbed;
67409+
67410+ while (tmp) {
67411+ if (!glob_match(tmp->filename, *path))
67412+ return tmp;
67413+ tmp = tmp->next;
67414+ }
67415+
67416+ return NULL;
67417+}
67418+
67419+static struct acl_object_label *
67420+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67421+ const ino_t curr_ino, const dev_t curr_dev,
67422+ const struct acl_subject_label *subj, char **path, const int checkglob)
67423+{
67424+ struct acl_subject_label *tmpsubj;
67425+ struct acl_object_label *retval;
67426+ struct acl_object_label *retval2;
67427+
67428+ tmpsubj = (struct acl_subject_label *) subj;
67429+ read_lock(&gr_inode_lock);
67430+ do {
67431+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67432+ if (retval) {
67433+ if (checkglob && retval->globbed) {
67434+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67435+ if (retval2)
67436+ retval = retval2;
67437+ }
67438+ break;
67439+ }
67440+ } while ((tmpsubj = tmpsubj->parent_subject));
67441+ read_unlock(&gr_inode_lock);
67442+
67443+ return retval;
67444+}
67445+
67446+static __inline__ struct acl_object_label *
67447+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67448+ struct dentry *curr_dentry,
67449+ const struct acl_subject_label *subj, char **path, const int checkglob)
67450+{
67451+ int newglob = checkglob;
67452+ ino_t inode;
67453+ dev_t device;
67454+
67455+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67456+ as we don't want a / * rule to match instead of the / object
67457+ don't do this for create lookups that call this function though, since they're looking up
67458+ on the parent and thus need globbing checks on all paths
67459+ */
67460+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67461+ newglob = GR_NO_GLOB;
67462+
67463+ spin_lock(&curr_dentry->d_lock);
67464+ inode = curr_dentry->d_inode->i_ino;
67465+ device = __get_dev(curr_dentry);
67466+ spin_unlock(&curr_dentry->d_lock);
67467+
67468+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67469+}
67470+
67471+#ifdef CONFIG_HUGETLBFS
67472+static inline bool
67473+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67474+{
67475+ int i;
67476+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67477+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67478+ return true;
67479+ }
67480+
67481+ return false;
67482+}
67483+#endif
67484+
67485+static struct acl_object_label *
67486+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67487+ const struct acl_subject_label *subj, char *path, const int checkglob)
67488+{
67489+ struct dentry *dentry = (struct dentry *) l_dentry;
67490+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67491+ struct mount *real_mnt = real_mount(mnt);
67492+ struct acl_object_label *retval;
67493+ struct dentry *parent;
67494+
67495+ read_seqlock_excl(&mount_lock);
67496+ write_seqlock(&rename_lock);
67497+
67498+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67499+#ifdef CONFIG_NET
67500+ mnt == sock_mnt ||
67501+#endif
67502+#ifdef CONFIG_HUGETLBFS
67503+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67504+#endif
67505+ /* ignore Eric Biederman */
67506+ IS_PRIVATE(l_dentry->d_inode))) {
67507+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67508+ goto out;
67509+ }
67510+
67511+ for (;;) {
67512+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67513+ break;
67514+
67515+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67516+ if (!mnt_has_parent(real_mnt))
67517+ break;
67518+
67519+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67520+ if (retval != NULL)
67521+ goto out;
67522+
67523+ dentry = real_mnt->mnt_mountpoint;
67524+ real_mnt = real_mnt->mnt_parent;
67525+ mnt = &real_mnt->mnt;
67526+ continue;
67527+ }
67528+
67529+ parent = dentry->d_parent;
67530+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67531+ if (retval != NULL)
67532+ goto out;
67533+
67534+ dentry = parent;
67535+ }
67536+
67537+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67538+
67539+ /* gr_real_root is pinned so we don't have to hold a reference */
67540+ if (retval == NULL)
67541+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67542+out:
67543+ write_sequnlock(&rename_lock);
67544+ read_sequnlock_excl(&mount_lock);
67545+
67546+ BUG_ON(retval == NULL);
67547+
67548+ return retval;
67549+}
67550+
67551+static __inline__ struct acl_object_label *
67552+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67553+ const struct acl_subject_label *subj)
67554+{
67555+ char *path = NULL;
67556+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67557+}
67558+
67559+static __inline__ struct acl_object_label *
67560+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67561+ const struct acl_subject_label *subj)
67562+{
67563+ char *path = NULL;
67564+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67565+}
67566+
67567+static __inline__ struct acl_object_label *
67568+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67569+ const struct acl_subject_label *subj, char *path)
67570+{
67571+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67572+}
67573+
67574+struct acl_subject_label *
67575+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67576+ const struct acl_role_label *role)
67577+{
67578+ struct dentry *dentry = (struct dentry *) l_dentry;
67579+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67580+ struct mount *real_mnt = real_mount(mnt);
67581+ struct acl_subject_label *retval;
67582+ struct dentry *parent;
67583+
67584+ read_seqlock_excl(&mount_lock);
67585+ write_seqlock(&rename_lock);
67586+
67587+ for (;;) {
67588+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67589+ break;
67590+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67591+ if (!mnt_has_parent(real_mnt))
67592+ break;
67593+
67594+ spin_lock(&dentry->d_lock);
67595+ read_lock(&gr_inode_lock);
67596+ retval =
67597+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67598+ __get_dev(dentry), role);
67599+ read_unlock(&gr_inode_lock);
67600+ spin_unlock(&dentry->d_lock);
67601+ if (retval != NULL)
67602+ goto out;
67603+
67604+ dentry = real_mnt->mnt_mountpoint;
67605+ real_mnt = real_mnt->mnt_parent;
67606+ mnt = &real_mnt->mnt;
67607+ continue;
67608+ }
67609+
67610+ spin_lock(&dentry->d_lock);
67611+ read_lock(&gr_inode_lock);
67612+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67613+ __get_dev(dentry), role);
67614+ read_unlock(&gr_inode_lock);
67615+ parent = dentry->d_parent;
67616+ spin_unlock(&dentry->d_lock);
67617+
67618+ if (retval != NULL)
67619+ goto out;
67620+
67621+ dentry = parent;
67622+ }
67623+
67624+ spin_lock(&dentry->d_lock);
67625+ read_lock(&gr_inode_lock);
67626+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67627+ __get_dev(dentry), role);
67628+ read_unlock(&gr_inode_lock);
67629+ spin_unlock(&dentry->d_lock);
67630+
67631+ if (unlikely(retval == NULL)) {
67632+ /* gr_real_root is pinned, we don't need to hold a reference */
67633+ read_lock(&gr_inode_lock);
67634+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67635+ __get_dev(gr_real_root.dentry), role);
67636+ read_unlock(&gr_inode_lock);
67637+ }
67638+out:
67639+ write_sequnlock(&rename_lock);
67640+ read_sequnlock_excl(&mount_lock);
67641+
67642+ BUG_ON(retval == NULL);
67643+
67644+ return retval;
67645+}
67646+
67647+void
67648+assign_special_role(const char *rolename)
67649+{
67650+ struct acl_object_label *obj;
67651+ struct acl_role_label *r;
67652+ struct acl_role_label *assigned = NULL;
67653+ struct task_struct *tsk;
67654+ struct file *filp;
67655+
67656+ FOR_EACH_ROLE_START(r)
67657+ if (!strcmp(rolename, r->rolename) &&
67658+ (r->roletype & GR_ROLE_SPECIAL)) {
67659+ assigned = r;
67660+ break;
67661+ }
67662+ FOR_EACH_ROLE_END(r)
67663+
67664+ if (!assigned)
67665+ return;
67666+
67667+ read_lock(&tasklist_lock);
67668+ read_lock(&grsec_exec_file_lock);
67669+
67670+ tsk = current->real_parent;
67671+ if (tsk == NULL)
67672+ goto out_unlock;
67673+
67674+ filp = tsk->exec_file;
67675+ if (filp == NULL)
67676+ goto out_unlock;
67677+
67678+ tsk->is_writable = 0;
67679+ tsk->inherited = 0;
67680+
67681+ tsk->acl_sp_role = 1;
67682+ tsk->acl_role_id = ++acl_sp_role_value;
67683+ tsk->role = assigned;
67684+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67685+
67686+ /* ignore additional mmap checks for processes that are writable
67687+ by the default ACL */
67688+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67689+ if (unlikely(obj->mode & GR_WRITE))
67690+ tsk->is_writable = 1;
67691+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67692+ if (unlikely(obj->mode & GR_WRITE))
67693+ tsk->is_writable = 1;
67694+
67695+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67696+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67697+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67698+#endif
67699+
67700+out_unlock:
67701+ read_unlock(&grsec_exec_file_lock);
67702+ read_unlock(&tasklist_lock);
67703+ return;
67704+}
67705+
67706+
67707+static void
67708+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67709+{
67710+ struct task_struct *task = current;
67711+ const struct cred *cred = current_cred();
67712+
67713+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67714+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67715+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67716+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67717+
67718+ return;
67719+}
67720+
67721+static void
67722+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67723+{
67724+ struct task_struct *task = current;
67725+ const struct cred *cred = current_cred();
67726+
67727+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67728+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67729+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67730+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67731+
67732+ return;
67733+}
67734+
67735+static void
67736+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67737+{
67738+ struct task_struct *task = current;
67739+ const struct cred *cred = current_cred();
67740+
67741+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67742+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67743+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67744+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67745+
67746+ return;
67747+}
67748+
67749+static void
67750+gr_set_proc_res(struct task_struct *task)
67751+{
67752+ struct acl_subject_label *proc;
67753+ unsigned short i;
67754+
67755+ proc = task->acl;
67756+
67757+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67758+ return;
67759+
67760+ for (i = 0; i < RLIM_NLIMITS; i++) {
67761+ if (!(proc->resmask & (1U << i)))
67762+ continue;
67763+
67764+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67765+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67766+
67767+ if (i == RLIMIT_CPU)
67768+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67769+ }
67770+
67771+ return;
67772+}
67773+
67774+/* both of the below must be called with
67775+ rcu_read_lock();
67776+ read_lock(&tasklist_lock);
67777+ read_lock(&grsec_exec_file_lock);
67778+*/
67779+
67780+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67781+{
67782+ char *tmpname;
67783+ struct acl_subject_label *tmpsubj;
67784+ struct file *filp;
67785+ struct name_entry *nmatch;
67786+
67787+ filp = task->exec_file;
67788+ if (filp == NULL)
67789+ return NULL;
67790+
67791+ /* the following is to apply the correct subject
67792+ on binaries running when the RBAC system
67793+ is enabled, when the binaries have been
67794+ replaced or deleted since their execution
67795+ -----
67796+ when the RBAC system starts, the inode/dev
67797+ from exec_file will be one the RBAC system
67798+ is unaware of. It only knows the inode/dev
67799+ of the present file on disk, or the absence
67800+ of it.
67801+ */
67802+
67803+ if (filename)
67804+ nmatch = __lookup_name_entry(state, filename);
67805+ else {
67806+ preempt_disable();
67807+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67808+
67809+ nmatch = __lookup_name_entry(state, tmpname);
67810+ preempt_enable();
67811+ }
67812+ tmpsubj = NULL;
67813+ if (nmatch) {
67814+ if (nmatch->deleted)
67815+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67816+ else
67817+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67818+ }
67819+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67820+ then we fall back to a normal lookup based on the binary's ino/dev
67821+ */
67822+ if (tmpsubj == NULL)
67823+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67824+
67825+ return tmpsubj;
67826+}
67827+
67828+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67829+{
67830+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67831+}
67832+
67833+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67834+{
67835+ struct acl_object_label *obj;
67836+ struct file *filp;
67837+
67838+ filp = task->exec_file;
67839+
67840+ task->acl = subj;
67841+ task->is_writable = 0;
67842+ /* ignore additional mmap checks for processes that are writable
67843+ by the default ACL */
67844+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67845+ if (unlikely(obj->mode & GR_WRITE))
67846+ task->is_writable = 1;
67847+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67848+ if (unlikely(obj->mode & GR_WRITE))
67849+ task->is_writable = 1;
67850+
67851+ gr_set_proc_res(task);
67852+
67853+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67854+ 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);
67855+#endif
67856+}
67857+
67858+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67859+{
67860+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67861+}
67862+
67863+__u32
67864+gr_search_file(const struct dentry * dentry, const __u32 mode,
67865+ const struct vfsmount * mnt)
67866+{
67867+ __u32 retval = mode;
67868+ struct acl_subject_label *curracl;
67869+ struct acl_object_label *currobj;
67870+
67871+ if (unlikely(!(gr_status & GR_READY)))
67872+ return (mode & ~GR_AUDITS);
67873+
67874+ curracl = current->acl;
67875+
67876+ currobj = chk_obj_label(dentry, mnt, curracl);
67877+ retval = currobj->mode & mode;
67878+
67879+ /* if we're opening a specified transfer file for writing
67880+ (e.g. /dev/initctl), then transfer our role to init
67881+ */
67882+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67883+ current->role->roletype & GR_ROLE_PERSIST)) {
67884+ struct task_struct *task = init_pid_ns.child_reaper;
67885+
67886+ if (task->role != current->role) {
67887+ struct acl_subject_label *subj;
67888+
67889+ task->acl_sp_role = 0;
67890+ task->acl_role_id = current->acl_role_id;
67891+ task->role = current->role;
67892+ rcu_read_lock();
67893+ read_lock(&grsec_exec_file_lock);
67894+ subj = gr_get_subject_for_task(task, NULL);
67895+ gr_apply_subject_to_task(task, subj);
67896+ read_unlock(&grsec_exec_file_lock);
67897+ rcu_read_unlock();
67898+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67899+ }
67900+ }
67901+
67902+ if (unlikely
67903+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67904+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67905+ __u32 new_mode = mode;
67906+
67907+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67908+
67909+ retval = new_mode;
67910+
67911+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67912+ new_mode |= GR_INHERIT;
67913+
67914+ if (!(mode & GR_NOLEARN))
67915+ gr_log_learn(dentry, mnt, new_mode);
67916+ }
67917+
67918+ return retval;
67919+}
67920+
67921+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67922+ const struct dentry *parent,
67923+ const struct vfsmount *mnt)
67924+{
67925+ struct name_entry *match;
67926+ struct acl_object_label *matchpo;
67927+ struct acl_subject_label *curracl;
67928+ char *path;
67929+
67930+ if (unlikely(!(gr_status & GR_READY)))
67931+ return NULL;
67932+
67933+ preempt_disable();
67934+ path = gr_to_filename_rbac(new_dentry, mnt);
67935+ match = lookup_name_entry_create(path);
67936+
67937+ curracl = current->acl;
67938+
67939+ if (match) {
67940+ read_lock(&gr_inode_lock);
67941+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67942+ read_unlock(&gr_inode_lock);
67943+
67944+ if (matchpo) {
67945+ preempt_enable();
67946+ return matchpo;
67947+ }
67948+ }
67949+
67950+ // lookup parent
67951+
67952+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67953+
67954+ preempt_enable();
67955+ return matchpo;
67956+}
67957+
67958+__u32
67959+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67960+ const struct vfsmount * mnt, const __u32 mode)
67961+{
67962+ struct acl_object_label *matchpo;
67963+ __u32 retval;
67964+
67965+ if (unlikely(!(gr_status & GR_READY)))
67966+ return (mode & ~GR_AUDITS);
67967+
67968+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
67969+
67970+ retval = matchpo->mode & mode;
67971+
67972+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67973+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67974+ __u32 new_mode = mode;
67975+
67976+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67977+
67978+ gr_log_learn(new_dentry, mnt, new_mode);
67979+ return new_mode;
67980+ }
67981+
67982+ return retval;
67983+}
67984+
67985+__u32
67986+gr_check_link(const struct dentry * new_dentry,
67987+ const struct dentry * parent_dentry,
67988+ const struct vfsmount * parent_mnt,
67989+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67990+{
67991+ struct acl_object_label *obj;
67992+ __u32 oldmode, newmode;
67993+ __u32 needmode;
67994+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67995+ GR_DELETE | GR_INHERIT;
67996+
67997+ if (unlikely(!(gr_status & GR_READY)))
67998+ return (GR_CREATE | GR_LINK);
67999+
68000+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68001+ oldmode = obj->mode;
68002+
68003+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68004+ newmode = obj->mode;
68005+
68006+ needmode = newmode & checkmodes;
68007+
68008+ // old name for hardlink must have at least the permissions of the new name
68009+ if ((oldmode & needmode) != needmode)
68010+ goto bad;
68011+
68012+ // if old name had restrictions/auditing, make sure the new name does as well
68013+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68014+
68015+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68016+ if (is_privileged_binary(old_dentry))
68017+ needmode |= GR_SETID;
68018+
68019+ if ((newmode & needmode) != needmode)
68020+ goto bad;
68021+
68022+ // enforce minimum permissions
68023+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68024+ return newmode;
68025+bad:
68026+ needmode = oldmode;
68027+ if (is_privileged_binary(old_dentry))
68028+ needmode |= GR_SETID;
68029+
68030+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68031+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68032+ return (GR_CREATE | GR_LINK);
68033+ } else if (newmode & GR_SUPPRESS)
68034+ return GR_SUPPRESS;
68035+ else
68036+ return 0;
68037+}
68038+
68039+int
68040+gr_check_hidden_task(const struct task_struct *task)
68041+{
68042+ if (unlikely(!(gr_status & GR_READY)))
68043+ return 0;
68044+
68045+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68046+ return 1;
68047+
68048+ return 0;
68049+}
68050+
68051+int
68052+gr_check_protected_task(const struct task_struct *task)
68053+{
68054+ if (unlikely(!(gr_status & GR_READY) || !task))
68055+ return 0;
68056+
68057+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68058+ task->acl != current->acl)
68059+ return 1;
68060+
68061+ return 0;
68062+}
68063+
68064+int
68065+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68066+{
68067+ struct task_struct *p;
68068+ int ret = 0;
68069+
68070+ if (unlikely(!(gr_status & GR_READY) || !pid))
68071+ return ret;
68072+
68073+ read_lock(&tasklist_lock);
68074+ do_each_pid_task(pid, type, p) {
68075+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68076+ p->acl != current->acl) {
68077+ ret = 1;
68078+ goto out;
68079+ }
68080+ } while_each_pid_task(pid, type, p);
68081+out:
68082+ read_unlock(&tasklist_lock);
68083+
68084+ return ret;
68085+}
68086+
68087+void
68088+gr_copy_label(struct task_struct *tsk)
68089+{
68090+ struct task_struct *p = current;
68091+
68092+ tsk->inherited = p->inherited;
68093+ tsk->acl_sp_role = 0;
68094+ tsk->acl_role_id = p->acl_role_id;
68095+ tsk->acl = p->acl;
68096+ tsk->role = p->role;
68097+ tsk->signal->used_accept = 0;
68098+ tsk->signal->curr_ip = p->signal->curr_ip;
68099+ tsk->signal->saved_ip = p->signal->saved_ip;
68100+ if (p->exec_file)
68101+ get_file(p->exec_file);
68102+ tsk->exec_file = p->exec_file;
68103+ tsk->is_writable = p->is_writable;
68104+ if (unlikely(p->signal->used_accept)) {
68105+ p->signal->curr_ip = 0;
68106+ p->signal->saved_ip = 0;
68107+ }
68108+
68109+ return;
68110+}
68111+
68112+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68113+
68114+int
68115+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68116+{
68117+ unsigned int i;
68118+ __u16 num;
68119+ uid_t *uidlist;
68120+ uid_t curuid;
68121+ int realok = 0;
68122+ int effectiveok = 0;
68123+ int fsok = 0;
68124+ uid_t globalreal, globaleffective, globalfs;
68125+
68126+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68127+ struct user_struct *user;
68128+
68129+ if (!uid_valid(real))
68130+ goto skipit;
68131+
68132+ /* find user based on global namespace */
68133+
68134+ globalreal = GR_GLOBAL_UID(real);
68135+
68136+ user = find_user(make_kuid(&init_user_ns, globalreal));
68137+ if (user == NULL)
68138+ goto skipit;
68139+
68140+ if (gr_process_kernel_setuid_ban(user)) {
68141+ /* for find_user */
68142+ free_uid(user);
68143+ return 1;
68144+ }
68145+
68146+ /* for find_user */
68147+ free_uid(user);
68148+
68149+skipit:
68150+#endif
68151+
68152+ if (unlikely(!(gr_status & GR_READY)))
68153+ return 0;
68154+
68155+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68156+ gr_log_learn_uid_change(real, effective, fs);
68157+
68158+ num = current->acl->user_trans_num;
68159+ uidlist = current->acl->user_transitions;
68160+
68161+ if (uidlist == NULL)
68162+ return 0;
68163+
68164+ if (!uid_valid(real)) {
68165+ realok = 1;
68166+ globalreal = (uid_t)-1;
68167+ } else {
68168+ globalreal = GR_GLOBAL_UID(real);
68169+ }
68170+ if (!uid_valid(effective)) {
68171+ effectiveok = 1;
68172+ globaleffective = (uid_t)-1;
68173+ } else {
68174+ globaleffective = GR_GLOBAL_UID(effective);
68175+ }
68176+ if (!uid_valid(fs)) {
68177+ fsok = 1;
68178+ globalfs = (uid_t)-1;
68179+ } else {
68180+ globalfs = GR_GLOBAL_UID(fs);
68181+ }
68182+
68183+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68184+ for (i = 0; i < num; i++) {
68185+ curuid = uidlist[i];
68186+ if (globalreal == curuid)
68187+ realok = 1;
68188+ if (globaleffective == curuid)
68189+ effectiveok = 1;
68190+ if (globalfs == curuid)
68191+ fsok = 1;
68192+ }
68193+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68194+ for (i = 0; i < num; i++) {
68195+ curuid = uidlist[i];
68196+ if (globalreal == curuid)
68197+ break;
68198+ if (globaleffective == curuid)
68199+ break;
68200+ if (globalfs == curuid)
68201+ break;
68202+ }
68203+ /* not in deny list */
68204+ if (i == num) {
68205+ realok = 1;
68206+ effectiveok = 1;
68207+ fsok = 1;
68208+ }
68209+ }
68210+
68211+ if (realok && effectiveok && fsok)
68212+ return 0;
68213+ else {
68214+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68215+ return 1;
68216+ }
68217+}
68218+
68219+int
68220+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68221+{
68222+ unsigned int i;
68223+ __u16 num;
68224+ gid_t *gidlist;
68225+ gid_t curgid;
68226+ int realok = 0;
68227+ int effectiveok = 0;
68228+ int fsok = 0;
68229+ gid_t globalreal, globaleffective, globalfs;
68230+
68231+ if (unlikely(!(gr_status & GR_READY)))
68232+ return 0;
68233+
68234+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68235+ gr_log_learn_gid_change(real, effective, fs);
68236+
68237+ num = current->acl->group_trans_num;
68238+ gidlist = current->acl->group_transitions;
68239+
68240+ if (gidlist == NULL)
68241+ return 0;
68242+
68243+ if (!gid_valid(real)) {
68244+ realok = 1;
68245+ globalreal = (gid_t)-1;
68246+ } else {
68247+ globalreal = GR_GLOBAL_GID(real);
68248+ }
68249+ if (!gid_valid(effective)) {
68250+ effectiveok = 1;
68251+ globaleffective = (gid_t)-1;
68252+ } else {
68253+ globaleffective = GR_GLOBAL_GID(effective);
68254+ }
68255+ if (!gid_valid(fs)) {
68256+ fsok = 1;
68257+ globalfs = (gid_t)-1;
68258+ } else {
68259+ globalfs = GR_GLOBAL_GID(fs);
68260+ }
68261+
68262+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68263+ for (i = 0; i < num; i++) {
68264+ curgid = gidlist[i];
68265+ if (globalreal == curgid)
68266+ realok = 1;
68267+ if (globaleffective == curgid)
68268+ effectiveok = 1;
68269+ if (globalfs == curgid)
68270+ fsok = 1;
68271+ }
68272+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68273+ for (i = 0; i < num; i++) {
68274+ curgid = gidlist[i];
68275+ if (globalreal == curgid)
68276+ break;
68277+ if (globaleffective == curgid)
68278+ break;
68279+ if (globalfs == curgid)
68280+ break;
68281+ }
68282+ /* not in deny list */
68283+ if (i == num) {
68284+ realok = 1;
68285+ effectiveok = 1;
68286+ fsok = 1;
68287+ }
68288+ }
68289+
68290+ if (realok && effectiveok && fsok)
68291+ return 0;
68292+ else {
68293+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68294+ return 1;
68295+ }
68296+}
68297+
68298+extern int gr_acl_is_capable(const int cap);
68299+
68300+void
68301+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68302+{
68303+ struct acl_role_label *role = task->role;
68304+ struct acl_subject_label *subj = NULL;
68305+ struct acl_object_label *obj;
68306+ struct file *filp;
68307+ uid_t uid;
68308+ gid_t gid;
68309+
68310+ if (unlikely(!(gr_status & GR_READY)))
68311+ return;
68312+
68313+ uid = GR_GLOBAL_UID(kuid);
68314+ gid = GR_GLOBAL_GID(kgid);
68315+
68316+ filp = task->exec_file;
68317+
68318+ /* kernel process, we'll give them the kernel role */
68319+ if (unlikely(!filp)) {
68320+ task->role = running_polstate.kernel_role;
68321+ task->acl = running_polstate.kernel_role->root_label;
68322+ return;
68323+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68324+ /* save the current ip at time of role lookup so that the proper
68325+ IP will be learned for role_allowed_ip */
68326+ task->signal->saved_ip = task->signal->curr_ip;
68327+ role = lookup_acl_role_label(task, uid, gid);
68328+ }
68329+
68330+ /* don't change the role if we're not a privileged process */
68331+ if (role && task->role != role &&
68332+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68333+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68334+ return;
68335+
68336+ /* perform subject lookup in possibly new role
68337+ we can use this result below in the case where role == task->role
68338+ */
68339+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68340+
68341+ /* if we changed uid/gid, but result in the same role
68342+ and are using inheritance, don't lose the inherited subject
68343+ if current subject is other than what normal lookup
68344+ would result in, we arrived via inheritance, don't
68345+ lose subject
68346+ */
68347+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68348+ (subj == task->acl)))
68349+ task->acl = subj;
68350+
68351+ /* leave task->inherited unaffected */
68352+
68353+ task->role = role;
68354+
68355+ task->is_writable = 0;
68356+
68357+ /* ignore additional mmap checks for processes that are writable
68358+ by the default ACL */
68359+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68360+ if (unlikely(obj->mode & GR_WRITE))
68361+ task->is_writable = 1;
68362+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68363+ if (unlikely(obj->mode & GR_WRITE))
68364+ task->is_writable = 1;
68365+
68366+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68367+ 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);
68368+#endif
68369+
68370+ gr_set_proc_res(task);
68371+
68372+ return;
68373+}
68374+
68375+int
68376+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68377+ const int unsafe_flags)
68378+{
68379+ struct task_struct *task = current;
68380+ struct acl_subject_label *newacl;
68381+ struct acl_object_label *obj;
68382+ __u32 retmode;
68383+
68384+ if (unlikely(!(gr_status & GR_READY)))
68385+ return 0;
68386+
68387+ newacl = chk_subj_label(dentry, mnt, task->role);
68388+
68389+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68390+ did an exec
68391+ */
68392+ rcu_read_lock();
68393+ read_lock(&tasklist_lock);
68394+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68395+ (task->parent->acl->mode & GR_POVERRIDE))) {
68396+ read_unlock(&tasklist_lock);
68397+ rcu_read_unlock();
68398+ goto skip_check;
68399+ }
68400+ read_unlock(&tasklist_lock);
68401+ rcu_read_unlock();
68402+
68403+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68404+ !(task->role->roletype & GR_ROLE_GOD) &&
68405+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68406+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68407+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68408+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68409+ else
68410+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68411+ return -EACCES;
68412+ }
68413+
68414+skip_check:
68415+
68416+ obj = chk_obj_label(dentry, mnt, task->acl);
68417+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68418+
68419+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68420+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68421+ if (obj->nested)
68422+ task->acl = obj->nested;
68423+ else
68424+ task->acl = newacl;
68425+ task->inherited = 0;
68426+ } else {
68427+ task->inherited = 1;
68428+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68429+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68430+ }
68431+
68432+ task->is_writable = 0;
68433+
68434+ /* ignore additional mmap checks for processes that are writable
68435+ by the default ACL */
68436+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68437+ if (unlikely(obj->mode & GR_WRITE))
68438+ task->is_writable = 1;
68439+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68440+ if (unlikely(obj->mode & GR_WRITE))
68441+ task->is_writable = 1;
68442+
68443+ gr_set_proc_res(task);
68444+
68445+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68446+ 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);
68447+#endif
68448+ return 0;
68449+}
68450+
68451+/* always called with valid inodev ptr */
68452+static void
68453+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68454+{
68455+ struct acl_object_label *matchpo;
68456+ struct acl_subject_label *matchps;
68457+ struct acl_subject_label *subj;
68458+ struct acl_role_label *role;
68459+ unsigned int x;
68460+
68461+ FOR_EACH_ROLE_START(role)
68462+ FOR_EACH_SUBJECT_START(role, subj, x)
68463+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68464+ matchpo->mode |= GR_DELETED;
68465+ FOR_EACH_SUBJECT_END(subj,x)
68466+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68467+ /* nested subjects aren't in the role's subj_hash table */
68468+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68469+ matchpo->mode |= GR_DELETED;
68470+ FOR_EACH_NESTED_SUBJECT_END(subj)
68471+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68472+ matchps->mode |= GR_DELETED;
68473+ FOR_EACH_ROLE_END(role)
68474+
68475+ inodev->nentry->deleted = 1;
68476+
68477+ return;
68478+}
68479+
68480+void
68481+gr_handle_delete(const ino_t ino, const dev_t dev)
68482+{
68483+ struct inodev_entry *inodev;
68484+
68485+ if (unlikely(!(gr_status & GR_READY)))
68486+ return;
68487+
68488+ write_lock(&gr_inode_lock);
68489+ inodev = lookup_inodev_entry(ino, dev);
68490+ if (inodev != NULL)
68491+ do_handle_delete(inodev, ino, dev);
68492+ write_unlock(&gr_inode_lock);
68493+
68494+ return;
68495+}
68496+
68497+static void
68498+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68499+ const ino_t newinode, const dev_t newdevice,
68500+ struct acl_subject_label *subj)
68501+{
68502+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68503+ struct acl_object_label *match;
68504+
68505+ match = subj->obj_hash[index];
68506+
68507+ while (match && (match->inode != oldinode ||
68508+ match->device != olddevice ||
68509+ !(match->mode & GR_DELETED)))
68510+ match = match->next;
68511+
68512+ if (match && (match->inode == oldinode)
68513+ && (match->device == olddevice)
68514+ && (match->mode & GR_DELETED)) {
68515+ if (match->prev == NULL) {
68516+ subj->obj_hash[index] = match->next;
68517+ if (match->next != NULL)
68518+ match->next->prev = NULL;
68519+ } else {
68520+ match->prev->next = match->next;
68521+ if (match->next != NULL)
68522+ match->next->prev = match->prev;
68523+ }
68524+ match->prev = NULL;
68525+ match->next = NULL;
68526+ match->inode = newinode;
68527+ match->device = newdevice;
68528+ match->mode &= ~GR_DELETED;
68529+
68530+ insert_acl_obj_label(match, subj);
68531+ }
68532+
68533+ return;
68534+}
68535+
68536+static void
68537+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68538+ const ino_t newinode, const dev_t newdevice,
68539+ struct acl_role_label *role)
68540+{
68541+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68542+ struct acl_subject_label *match;
68543+
68544+ match = role->subj_hash[index];
68545+
68546+ while (match && (match->inode != oldinode ||
68547+ match->device != olddevice ||
68548+ !(match->mode & GR_DELETED)))
68549+ match = match->next;
68550+
68551+ if (match && (match->inode == oldinode)
68552+ && (match->device == olddevice)
68553+ && (match->mode & GR_DELETED)) {
68554+ if (match->prev == NULL) {
68555+ role->subj_hash[index] = match->next;
68556+ if (match->next != NULL)
68557+ match->next->prev = NULL;
68558+ } else {
68559+ match->prev->next = match->next;
68560+ if (match->next != NULL)
68561+ match->next->prev = match->prev;
68562+ }
68563+ match->prev = NULL;
68564+ match->next = NULL;
68565+ match->inode = newinode;
68566+ match->device = newdevice;
68567+ match->mode &= ~GR_DELETED;
68568+
68569+ insert_acl_subj_label(match, role);
68570+ }
68571+
68572+ return;
68573+}
68574+
68575+static void
68576+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68577+ const ino_t newinode, const dev_t newdevice)
68578+{
68579+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68580+ struct inodev_entry *match;
68581+
68582+ match = running_polstate.inodev_set.i_hash[index];
68583+
68584+ while (match && (match->nentry->inode != oldinode ||
68585+ match->nentry->device != olddevice || !match->nentry->deleted))
68586+ match = match->next;
68587+
68588+ if (match && (match->nentry->inode == oldinode)
68589+ && (match->nentry->device == olddevice) &&
68590+ match->nentry->deleted) {
68591+ if (match->prev == NULL) {
68592+ running_polstate.inodev_set.i_hash[index] = match->next;
68593+ if (match->next != NULL)
68594+ match->next->prev = NULL;
68595+ } else {
68596+ match->prev->next = match->next;
68597+ if (match->next != NULL)
68598+ match->next->prev = match->prev;
68599+ }
68600+ match->prev = NULL;
68601+ match->next = NULL;
68602+ match->nentry->inode = newinode;
68603+ match->nentry->device = newdevice;
68604+ match->nentry->deleted = 0;
68605+
68606+ insert_inodev_entry(match);
68607+ }
68608+
68609+ return;
68610+}
68611+
68612+static void
68613+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68614+{
68615+ struct acl_subject_label *subj;
68616+ struct acl_role_label *role;
68617+ unsigned int x;
68618+
68619+ FOR_EACH_ROLE_START(role)
68620+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68621+
68622+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68623+ if ((subj->inode == ino) && (subj->device == dev)) {
68624+ subj->inode = ino;
68625+ subj->device = dev;
68626+ }
68627+ /* nested subjects aren't in the role's subj_hash table */
68628+ update_acl_obj_label(matchn->inode, matchn->device,
68629+ ino, dev, subj);
68630+ FOR_EACH_NESTED_SUBJECT_END(subj)
68631+ FOR_EACH_SUBJECT_START(role, subj, x)
68632+ update_acl_obj_label(matchn->inode, matchn->device,
68633+ ino, dev, subj);
68634+ FOR_EACH_SUBJECT_END(subj,x)
68635+ FOR_EACH_ROLE_END(role)
68636+
68637+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68638+
68639+ return;
68640+}
68641+
68642+static void
68643+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68644+ const struct vfsmount *mnt)
68645+{
68646+ ino_t ino = dentry->d_inode->i_ino;
68647+ dev_t dev = __get_dev(dentry);
68648+
68649+ __do_handle_create(matchn, ino, dev);
68650+
68651+ return;
68652+}
68653+
68654+void
68655+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68656+{
68657+ struct name_entry *matchn;
68658+
68659+ if (unlikely(!(gr_status & GR_READY)))
68660+ return;
68661+
68662+ preempt_disable();
68663+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68664+
68665+ if (unlikely((unsigned long)matchn)) {
68666+ write_lock(&gr_inode_lock);
68667+ do_handle_create(matchn, dentry, mnt);
68668+ write_unlock(&gr_inode_lock);
68669+ }
68670+ preempt_enable();
68671+
68672+ return;
68673+}
68674+
68675+void
68676+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68677+{
68678+ struct name_entry *matchn;
68679+
68680+ if (unlikely(!(gr_status & GR_READY)))
68681+ return;
68682+
68683+ preempt_disable();
68684+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68685+
68686+ if (unlikely((unsigned long)matchn)) {
68687+ write_lock(&gr_inode_lock);
68688+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68689+ write_unlock(&gr_inode_lock);
68690+ }
68691+ preempt_enable();
68692+
68693+ return;
68694+}
68695+
68696+void
68697+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68698+ struct dentry *old_dentry,
68699+ struct dentry *new_dentry,
68700+ struct vfsmount *mnt, const __u8 replace)
68701+{
68702+ struct name_entry *matchn;
68703+ struct inodev_entry *inodev;
68704+ struct inode *inode = new_dentry->d_inode;
68705+ ino_t old_ino = old_dentry->d_inode->i_ino;
68706+ dev_t old_dev = __get_dev(old_dentry);
68707+
68708+ /* vfs_rename swaps the name and parent link for old_dentry and
68709+ new_dentry
68710+ at this point, old_dentry has the new name, parent link, and inode
68711+ for the renamed file
68712+ if a file is being replaced by a rename, new_dentry has the inode
68713+ and name for the replaced file
68714+ */
68715+
68716+ if (unlikely(!(gr_status & GR_READY)))
68717+ return;
68718+
68719+ preempt_disable();
68720+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68721+
68722+ /* we wouldn't have to check d_inode if it weren't for
68723+ NFS silly-renaming
68724+ */
68725+
68726+ write_lock(&gr_inode_lock);
68727+ if (unlikely(replace && inode)) {
68728+ ino_t new_ino = inode->i_ino;
68729+ dev_t new_dev = __get_dev(new_dentry);
68730+
68731+ inodev = lookup_inodev_entry(new_ino, new_dev);
68732+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68733+ do_handle_delete(inodev, new_ino, new_dev);
68734+ }
68735+
68736+ inodev = lookup_inodev_entry(old_ino, old_dev);
68737+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68738+ do_handle_delete(inodev, old_ino, old_dev);
68739+
68740+ if (unlikely((unsigned long)matchn))
68741+ do_handle_create(matchn, old_dentry, mnt);
68742+
68743+ write_unlock(&gr_inode_lock);
68744+ preempt_enable();
68745+
68746+ return;
68747+}
68748+
68749+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68750+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68751+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68752+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68753+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68754+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68755+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68756+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68757+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68758+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68759+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68760+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68761+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68762+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68763+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68764+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68765+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68766+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68767+};
68768+
68769+void
68770+gr_learn_resource(const struct task_struct *task,
68771+ const int res, const unsigned long wanted, const int gt)
68772+{
68773+ struct acl_subject_label *acl;
68774+ const struct cred *cred;
68775+
68776+ if (unlikely((gr_status & GR_READY) &&
68777+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68778+ goto skip_reslog;
68779+
68780+ gr_log_resource(task, res, wanted, gt);
68781+skip_reslog:
68782+
68783+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68784+ return;
68785+
68786+ acl = task->acl;
68787+
68788+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68789+ !(acl->resmask & (1U << (unsigned short) res))))
68790+ return;
68791+
68792+ if (wanted >= acl->res[res].rlim_cur) {
68793+ unsigned long res_add;
68794+
68795+ res_add = wanted + res_learn_bumps[res];
68796+
68797+ acl->res[res].rlim_cur = res_add;
68798+
68799+ if (wanted > acl->res[res].rlim_max)
68800+ acl->res[res].rlim_max = res_add;
68801+
68802+ /* only log the subject filename, since resource logging is supported for
68803+ single-subject learning only */
68804+ rcu_read_lock();
68805+ cred = __task_cred(task);
68806+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68807+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68808+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68809+ "", (unsigned long) res, &task->signal->saved_ip);
68810+ rcu_read_unlock();
68811+ }
68812+
68813+ return;
68814+}
68815+EXPORT_SYMBOL_GPL(gr_learn_resource);
68816+#endif
68817+
68818+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68819+void
68820+pax_set_initial_flags(struct linux_binprm *bprm)
68821+{
68822+ struct task_struct *task = current;
68823+ struct acl_subject_label *proc;
68824+ unsigned long flags;
68825+
68826+ if (unlikely(!(gr_status & GR_READY)))
68827+ return;
68828+
68829+ flags = pax_get_flags(task);
68830+
68831+ proc = task->acl;
68832+
68833+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68834+ flags &= ~MF_PAX_PAGEEXEC;
68835+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68836+ flags &= ~MF_PAX_SEGMEXEC;
68837+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68838+ flags &= ~MF_PAX_RANDMMAP;
68839+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68840+ flags &= ~MF_PAX_EMUTRAMP;
68841+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68842+ flags &= ~MF_PAX_MPROTECT;
68843+
68844+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68845+ flags |= MF_PAX_PAGEEXEC;
68846+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68847+ flags |= MF_PAX_SEGMEXEC;
68848+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68849+ flags |= MF_PAX_RANDMMAP;
68850+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68851+ flags |= MF_PAX_EMUTRAMP;
68852+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68853+ flags |= MF_PAX_MPROTECT;
68854+
68855+ pax_set_flags(task, flags);
68856+
68857+ return;
68858+}
68859+#endif
68860+
68861+int
68862+gr_handle_proc_ptrace(struct task_struct *task)
68863+{
68864+ struct file *filp;
68865+ struct task_struct *tmp = task;
68866+ struct task_struct *curtemp = current;
68867+ __u32 retmode;
68868+
68869+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68870+ if (unlikely(!(gr_status & GR_READY)))
68871+ return 0;
68872+#endif
68873+
68874+ read_lock(&tasklist_lock);
68875+ read_lock(&grsec_exec_file_lock);
68876+ filp = task->exec_file;
68877+
68878+ while (task_pid_nr(tmp) > 0) {
68879+ if (tmp == curtemp)
68880+ break;
68881+ tmp = tmp->real_parent;
68882+ }
68883+
68884+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68885+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68886+ read_unlock(&grsec_exec_file_lock);
68887+ read_unlock(&tasklist_lock);
68888+ return 1;
68889+ }
68890+
68891+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68892+ if (!(gr_status & GR_READY)) {
68893+ read_unlock(&grsec_exec_file_lock);
68894+ read_unlock(&tasklist_lock);
68895+ return 0;
68896+ }
68897+#endif
68898+
68899+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68900+ read_unlock(&grsec_exec_file_lock);
68901+ read_unlock(&tasklist_lock);
68902+
68903+ if (retmode & GR_NOPTRACE)
68904+ return 1;
68905+
68906+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68907+ && (current->acl != task->acl || (current->acl != current->role->root_label
68908+ && task_pid_nr(current) != task_pid_nr(task))))
68909+ return 1;
68910+
68911+ return 0;
68912+}
68913+
68914+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68915+{
68916+ if (unlikely(!(gr_status & GR_READY)))
68917+ return;
68918+
68919+ if (!(current->role->roletype & GR_ROLE_GOD))
68920+ return;
68921+
68922+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68923+ p->role->rolename, gr_task_roletype_to_char(p),
68924+ p->acl->filename);
68925+}
68926+
68927+int
68928+gr_handle_ptrace(struct task_struct *task, const long request)
68929+{
68930+ struct task_struct *tmp = task;
68931+ struct task_struct *curtemp = current;
68932+ __u32 retmode;
68933+
68934+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68935+ if (unlikely(!(gr_status & GR_READY)))
68936+ return 0;
68937+#endif
68938+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68939+ read_lock(&tasklist_lock);
68940+ while (task_pid_nr(tmp) > 0) {
68941+ if (tmp == curtemp)
68942+ break;
68943+ tmp = tmp->real_parent;
68944+ }
68945+
68946+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68947+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68948+ read_unlock(&tasklist_lock);
68949+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68950+ return 1;
68951+ }
68952+ read_unlock(&tasklist_lock);
68953+ }
68954+
68955+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68956+ if (!(gr_status & GR_READY))
68957+ return 0;
68958+#endif
68959+
68960+ read_lock(&grsec_exec_file_lock);
68961+ if (unlikely(!task->exec_file)) {
68962+ read_unlock(&grsec_exec_file_lock);
68963+ return 0;
68964+ }
68965+
68966+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68967+ read_unlock(&grsec_exec_file_lock);
68968+
68969+ if (retmode & GR_NOPTRACE) {
68970+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68971+ return 1;
68972+ }
68973+
68974+ if (retmode & GR_PTRACERD) {
68975+ switch (request) {
68976+ case PTRACE_SEIZE:
68977+ case PTRACE_POKETEXT:
68978+ case PTRACE_POKEDATA:
68979+ case PTRACE_POKEUSR:
68980+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68981+ case PTRACE_SETREGS:
68982+ case PTRACE_SETFPREGS:
68983+#endif
68984+#ifdef CONFIG_X86
68985+ case PTRACE_SETFPXREGS:
68986+#endif
68987+#ifdef CONFIG_ALTIVEC
68988+ case PTRACE_SETVRREGS:
68989+#endif
68990+ return 1;
68991+ default:
68992+ return 0;
68993+ }
68994+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
68995+ !(current->role->roletype & GR_ROLE_GOD) &&
68996+ (current->acl != task->acl)) {
68997+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68998+ return 1;
68999+ }
69000+
69001+ return 0;
69002+}
69003+
69004+static int is_writable_mmap(const struct file *filp)
69005+{
69006+ struct task_struct *task = current;
69007+ struct acl_object_label *obj, *obj2;
69008+
69009+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69010+ !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))) {
69011+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69012+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69013+ task->role->root_label);
69014+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69015+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69016+ return 1;
69017+ }
69018+ }
69019+ return 0;
69020+}
69021+
69022+int
69023+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69024+{
69025+ __u32 mode;
69026+
69027+ if (unlikely(!file || !(prot & PROT_EXEC)))
69028+ return 1;
69029+
69030+ if (is_writable_mmap(file))
69031+ return 0;
69032+
69033+ mode =
69034+ gr_search_file(file->f_path.dentry,
69035+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69036+ file->f_path.mnt);
69037+
69038+ if (!gr_tpe_allow(file))
69039+ return 0;
69040+
69041+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69042+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69043+ return 0;
69044+ } else if (unlikely(!(mode & GR_EXEC))) {
69045+ return 0;
69046+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69047+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69048+ return 1;
69049+ }
69050+
69051+ return 1;
69052+}
69053+
69054+int
69055+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69056+{
69057+ __u32 mode;
69058+
69059+ if (unlikely(!file || !(prot & PROT_EXEC)))
69060+ return 1;
69061+
69062+ if (is_writable_mmap(file))
69063+ return 0;
69064+
69065+ mode =
69066+ gr_search_file(file->f_path.dentry,
69067+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69068+ file->f_path.mnt);
69069+
69070+ if (!gr_tpe_allow(file))
69071+ return 0;
69072+
69073+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69074+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69075+ return 0;
69076+ } else if (unlikely(!(mode & GR_EXEC))) {
69077+ return 0;
69078+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69079+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69080+ return 1;
69081+ }
69082+
69083+ return 1;
69084+}
69085+
69086+void
69087+gr_acl_handle_psacct(struct task_struct *task, const long code)
69088+{
69089+ unsigned long runtime, cputime;
69090+ cputime_t utime, stime;
69091+ unsigned int wday, cday;
69092+ __u8 whr, chr;
69093+ __u8 wmin, cmin;
69094+ __u8 wsec, csec;
69095+ struct timespec timeval;
69096+
69097+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69098+ !(task->acl->mode & GR_PROCACCT)))
69099+ return;
69100+
69101+ do_posix_clock_monotonic_gettime(&timeval);
69102+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69103+ wday = runtime / (60 * 60 * 24);
69104+ runtime -= wday * (60 * 60 * 24);
69105+ whr = runtime / (60 * 60);
69106+ runtime -= whr * (60 * 60);
69107+ wmin = runtime / 60;
69108+ runtime -= wmin * 60;
69109+ wsec = runtime;
69110+
69111+ task_cputime(task, &utime, &stime);
69112+ cputime = cputime_to_secs(utime + stime);
69113+ cday = cputime / (60 * 60 * 24);
69114+ cputime -= cday * (60 * 60 * 24);
69115+ chr = cputime / (60 * 60);
69116+ cputime -= chr * (60 * 60);
69117+ cmin = cputime / 60;
69118+ cputime -= cmin * 60;
69119+ csec = cputime;
69120+
69121+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69122+
69123+ return;
69124+}
69125+
69126+#ifdef CONFIG_TASKSTATS
69127+int gr_is_taskstats_denied(int pid)
69128+{
69129+ struct task_struct *task;
69130+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69131+ const struct cred *cred;
69132+#endif
69133+ int ret = 0;
69134+
69135+ /* restrict taskstats viewing to un-chrooted root users
69136+ who have the 'view' subject flag if the RBAC system is enabled
69137+ */
69138+
69139+ rcu_read_lock();
69140+ read_lock(&tasklist_lock);
69141+ task = find_task_by_vpid(pid);
69142+ if (task) {
69143+#ifdef CONFIG_GRKERNSEC_CHROOT
69144+ if (proc_is_chrooted(task))
69145+ ret = -EACCES;
69146+#endif
69147+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69148+ cred = __task_cred(task);
69149+#ifdef CONFIG_GRKERNSEC_PROC_USER
69150+ if (gr_is_global_nonroot(cred->uid))
69151+ ret = -EACCES;
69152+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69153+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69154+ ret = -EACCES;
69155+#endif
69156+#endif
69157+ if (gr_status & GR_READY) {
69158+ if (!(task->acl->mode & GR_VIEW))
69159+ ret = -EACCES;
69160+ }
69161+ } else
69162+ ret = -ENOENT;
69163+
69164+ read_unlock(&tasklist_lock);
69165+ rcu_read_unlock();
69166+
69167+ return ret;
69168+}
69169+#endif
69170+
69171+/* AUXV entries are filled via a descendant of search_binary_handler
69172+ after we've already applied the subject for the target
69173+*/
69174+int gr_acl_enable_at_secure(void)
69175+{
69176+ if (unlikely(!(gr_status & GR_READY)))
69177+ return 0;
69178+
69179+ if (current->acl->mode & GR_ATSECURE)
69180+ return 1;
69181+
69182+ return 0;
69183+}
69184+
69185+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69186+{
69187+ struct task_struct *task = current;
69188+ struct dentry *dentry = file->f_path.dentry;
69189+ struct vfsmount *mnt = file->f_path.mnt;
69190+ struct acl_object_label *obj, *tmp;
69191+ struct acl_subject_label *subj;
69192+ unsigned int bufsize;
69193+ int is_not_root;
69194+ char *path;
69195+ dev_t dev = __get_dev(dentry);
69196+
69197+ if (unlikely(!(gr_status & GR_READY)))
69198+ return 1;
69199+
69200+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69201+ return 1;
69202+
69203+ /* ignore Eric Biederman */
69204+ if (IS_PRIVATE(dentry->d_inode))
69205+ return 1;
69206+
69207+ subj = task->acl;
69208+ read_lock(&gr_inode_lock);
69209+ do {
69210+ obj = lookup_acl_obj_label(ino, dev, subj);
69211+ if (obj != NULL) {
69212+ read_unlock(&gr_inode_lock);
69213+ return (obj->mode & GR_FIND) ? 1 : 0;
69214+ }
69215+ } while ((subj = subj->parent_subject));
69216+ read_unlock(&gr_inode_lock);
69217+
69218+ /* this is purely an optimization since we're looking for an object
69219+ for the directory we're doing a readdir on
69220+ if it's possible for any globbed object to match the entry we're
69221+ filling into the directory, then the object we find here will be
69222+ an anchor point with attached globbed objects
69223+ */
69224+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69225+ if (obj->globbed == NULL)
69226+ return (obj->mode & GR_FIND) ? 1 : 0;
69227+
69228+ is_not_root = ((obj->filename[0] == '/') &&
69229+ (obj->filename[1] == '\0')) ? 0 : 1;
69230+ bufsize = PAGE_SIZE - namelen - is_not_root;
69231+
69232+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69233+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69234+ return 1;
69235+
69236+ preempt_disable();
69237+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69238+ bufsize);
69239+
69240+ bufsize = strlen(path);
69241+
69242+ /* if base is "/", don't append an additional slash */
69243+ if (is_not_root)
69244+ *(path + bufsize) = '/';
69245+ memcpy(path + bufsize + is_not_root, name, namelen);
69246+ *(path + bufsize + namelen + is_not_root) = '\0';
69247+
69248+ tmp = obj->globbed;
69249+ while (tmp) {
69250+ if (!glob_match(tmp->filename, path)) {
69251+ preempt_enable();
69252+ return (tmp->mode & GR_FIND) ? 1 : 0;
69253+ }
69254+ tmp = tmp->next;
69255+ }
69256+ preempt_enable();
69257+ return (obj->mode & GR_FIND) ? 1 : 0;
69258+}
69259+
69260+void gr_put_exec_file(struct task_struct *task)
69261+{
69262+ struct file *filp;
69263+
69264+ write_lock(&grsec_exec_file_lock);
69265+ filp = task->exec_file;
69266+ task->exec_file = NULL;
69267+ write_unlock(&grsec_exec_file_lock);
69268+
69269+ if (filp)
69270+ fput(filp);
69271+
69272+ return;
69273+}
69274+
69275+
69276+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69277+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69278+#endif
69279+#ifdef CONFIG_SECURITY
69280+EXPORT_SYMBOL_GPL(gr_check_user_change);
69281+EXPORT_SYMBOL_GPL(gr_check_group_change);
69282+#endif
69283+
69284diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69285new file mode 100644
69286index 0000000..18ffbbd
69287--- /dev/null
69288+++ b/grsecurity/gracl_alloc.c
69289@@ -0,0 +1,105 @@
69290+#include <linux/kernel.h>
69291+#include <linux/mm.h>
69292+#include <linux/slab.h>
69293+#include <linux/vmalloc.h>
69294+#include <linux/gracl.h>
69295+#include <linux/grsecurity.h>
69296+
69297+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69298+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69299+
69300+static __inline__ int
69301+alloc_pop(void)
69302+{
69303+ if (current_alloc_state->alloc_stack_next == 1)
69304+ return 0;
69305+
69306+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69307+
69308+ current_alloc_state->alloc_stack_next--;
69309+
69310+ return 1;
69311+}
69312+
69313+static __inline__ int
69314+alloc_push(void *buf)
69315+{
69316+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69317+ return 1;
69318+
69319+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69320+
69321+ current_alloc_state->alloc_stack_next++;
69322+
69323+ return 0;
69324+}
69325+
69326+void *
69327+acl_alloc(unsigned long len)
69328+{
69329+ void *ret = NULL;
69330+
69331+ if (!len || len > PAGE_SIZE)
69332+ goto out;
69333+
69334+ ret = kmalloc(len, GFP_KERNEL);
69335+
69336+ if (ret) {
69337+ if (alloc_push(ret)) {
69338+ kfree(ret);
69339+ ret = NULL;
69340+ }
69341+ }
69342+
69343+out:
69344+ return ret;
69345+}
69346+
69347+void *
69348+acl_alloc_num(unsigned long num, unsigned long len)
69349+{
69350+ if (!len || (num > (PAGE_SIZE / len)))
69351+ return NULL;
69352+
69353+ return acl_alloc(num * len);
69354+}
69355+
69356+void
69357+acl_free_all(void)
69358+{
69359+ if (!current_alloc_state->alloc_stack)
69360+ return;
69361+
69362+ while (alloc_pop()) ;
69363+
69364+ if (current_alloc_state->alloc_stack) {
69365+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69366+ kfree(current_alloc_state->alloc_stack);
69367+ else
69368+ vfree(current_alloc_state->alloc_stack);
69369+ }
69370+
69371+ current_alloc_state->alloc_stack = NULL;
69372+ current_alloc_state->alloc_stack_size = 1;
69373+ current_alloc_state->alloc_stack_next = 1;
69374+
69375+ return;
69376+}
69377+
69378+int
69379+acl_alloc_stack_init(unsigned long size)
69380+{
69381+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69382+ current_alloc_state->alloc_stack =
69383+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69384+ else
69385+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69386+
69387+ current_alloc_state->alloc_stack_size = size;
69388+ current_alloc_state->alloc_stack_next = 1;
69389+
69390+ if (!current_alloc_state->alloc_stack)
69391+ return 0;
69392+ else
69393+ return 1;
69394+}
69395diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69396new file mode 100644
69397index 0000000..bdd51ea
69398--- /dev/null
69399+++ b/grsecurity/gracl_cap.c
69400@@ -0,0 +1,110 @@
69401+#include <linux/kernel.h>
69402+#include <linux/module.h>
69403+#include <linux/sched.h>
69404+#include <linux/gracl.h>
69405+#include <linux/grsecurity.h>
69406+#include <linux/grinternal.h>
69407+
69408+extern const char *captab_log[];
69409+extern int captab_log_entries;
69410+
69411+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69412+{
69413+ struct acl_subject_label *curracl;
69414+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69415+ kernel_cap_t cap_audit = __cap_empty_set;
69416+
69417+ if (!gr_acl_is_enabled())
69418+ return 1;
69419+
69420+ curracl = task->acl;
69421+
69422+ cap_drop = curracl->cap_lower;
69423+ cap_mask = curracl->cap_mask;
69424+ cap_audit = curracl->cap_invert_audit;
69425+
69426+ while ((curracl = curracl->parent_subject)) {
69427+ /* if the cap isn't specified in the current computed mask but is specified in the
69428+ current level subject, and is lowered in the current level subject, then add
69429+ it to the set of dropped capabilities
69430+ otherwise, add the current level subject's mask to the current computed mask
69431+ */
69432+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69433+ cap_raise(cap_mask, cap);
69434+ if (cap_raised(curracl->cap_lower, cap))
69435+ cap_raise(cap_drop, cap);
69436+ if (cap_raised(curracl->cap_invert_audit, cap))
69437+ cap_raise(cap_audit, cap);
69438+ }
69439+ }
69440+
69441+ if (!cap_raised(cap_drop, cap)) {
69442+ if (cap_raised(cap_audit, cap))
69443+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69444+ return 1;
69445+ }
69446+
69447+ curracl = task->acl;
69448+
69449+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69450+ && cap_raised(cred->cap_effective, cap)) {
69451+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69452+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69453+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69454+ gr_to_filename(task->exec_file->f_path.dentry,
69455+ task->exec_file->f_path.mnt) : curracl->filename,
69456+ curracl->filename, 0UL,
69457+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69458+ return 1;
69459+ }
69460+
69461+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69462+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69463+
69464+ return 0;
69465+}
69466+
69467+int
69468+gr_acl_is_capable(const int cap)
69469+{
69470+ return gr_task_acl_is_capable(current, current_cred(), cap);
69471+}
69472+
69473+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69474+{
69475+ struct acl_subject_label *curracl;
69476+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69477+
69478+ if (!gr_acl_is_enabled())
69479+ return 1;
69480+
69481+ curracl = task->acl;
69482+
69483+ cap_drop = curracl->cap_lower;
69484+ cap_mask = curracl->cap_mask;
69485+
69486+ while ((curracl = curracl->parent_subject)) {
69487+ /* if the cap isn't specified in the current computed mask but is specified in the
69488+ current level subject, and is lowered in the current level subject, then add
69489+ it to the set of dropped capabilities
69490+ otherwise, add the current level subject's mask to the current computed mask
69491+ */
69492+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69493+ cap_raise(cap_mask, cap);
69494+ if (cap_raised(curracl->cap_lower, cap))
69495+ cap_raise(cap_drop, cap);
69496+ }
69497+ }
69498+
69499+ if (!cap_raised(cap_drop, cap))
69500+ return 1;
69501+
69502+ return 0;
69503+}
69504+
69505+int
69506+gr_acl_is_capable_nolog(const int cap)
69507+{
69508+ return gr_task_acl_is_capable_nolog(current, cap);
69509+}
69510+
69511diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69512new file mode 100644
69513index 0000000..ca25605
69514--- /dev/null
69515+++ b/grsecurity/gracl_compat.c
69516@@ -0,0 +1,270 @@
69517+#include <linux/kernel.h>
69518+#include <linux/gracl.h>
69519+#include <linux/compat.h>
69520+#include <linux/gracl_compat.h>
69521+
69522+#include <asm/uaccess.h>
69523+
69524+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69525+{
69526+ struct gr_arg_wrapper_compat uwrapcompat;
69527+
69528+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69529+ return -EFAULT;
69530+
69531+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69532+ (uwrapcompat.version != 0x2901)) ||
69533+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69534+ return -EINVAL;
69535+
69536+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69537+ uwrap->version = uwrapcompat.version;
69538+ uwrap->size = sizeof(struct gr_arg);
69539+
69540+ return 0;
69541+}
69542+
69543+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69544+{
69545+ struct gr_arg_compat argcompat;
69546+
69547+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69548+ return -EFAULT;
69549+
69550+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69551+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69552+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69553+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69554+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69555+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69556+
69557+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69558+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69559+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69560+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69561+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69562+ arg->segv_device = argcompat.segv_device;
69563+ arg->segv_inode = argcompat.segv_inode;
69564+ arg->segv_uid = argcompat.segv_uid;
69565+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69566+ arg->mode = argcompat.mode;
69567+
69568+ return 0;
69569+}
69570+
69571+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69572+{
69573+ struct acl_object_label_compat objcompat;
69574+
69575+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69576+ return -EFAULT;
69577+
69578+ obj->filename = compat_ptr(objcompat.filename);
69579+ obj->inode = objcompat.inode;
69580+ obj->device = objcompat.device;
69581+ obj->mode = objcompat.mode;
69582+
69583+ obj->nested = compat_ptr(objcompat.nested);
69584+ obj->globbed = compat_ptr(objcompat.globbed);
69585+
69586+ obj->prev = compat_ptr(objcompat.prev);
69587+ obj->next = compat_ptr(objcompat.next);
69588+
69589+ return 0;
69590+}
69591+
69592+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69593+{
69594+ unsigned int i;
69595+ struct acl_subject_label_compat subjcompat;
69596+
69597+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69598+ return -EFAULT;
69599+
69600+ subj->filename = compat_ptr(subjcompat.filename);
69601+ subj->inode = subjcompat.inode;
69602+ subj->device = subjcompat.device;
69603+ subj->mode = subjcompat.mode;
69604+ subj->cap_mask = subjcompat.cap_mask;
69605+ subj->cap_lower = subjcompat.cap_lower;
69606+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69607+
69608+ for (i = 0; i < GR_NLIMITS; i++) {
69609+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69610+ subj->res[i].rlim_cur = RLIM_INFINITY;
69611+ else
69612+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69613+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69614+ subj->res[i].rlim_max = RLIM_INFINITY;
69615+ else
69616+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69617+ }
69618+ subj->resmask = subjcompat.resmask;
69619+
69620+ subj->user_trans_type = subjcompat.user_trans_type;
69621+ subj->group_trans_type = subjcompat.group_trans_type;
69622+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69623+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69624+ subj->user_trans_num = subjcompat.user_trans_num;
69625+ subj->group_trans_num = subjcompat.group_trans_num;
69626+
69627+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69628+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69629+ subj->ip_type = subjcompat.ip_type;
69630+ subj->ips = compat_ptr(subjcompat.ips);
69631+ subj->ip_num = subjcompat.ip_num;
69632+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69633+
69634+ subj->crashes = subjcompat.crashes;
69635+ subj->expires = subjcompat.expires;
69636+
69637+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69638+ subj->hash = compat_ptr(subjcompat.hash);
69639+ subj->prev = compat_ptr(subjcompat.prev);
69640+ subj->next = compat_ptr(subjcompat.next);
69641+
69642+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69643+ subj->obj_hash_size = subjcompat.obj_hash_size;
69644+ subj->pax_flags = subjcompat.pax_flags;
69645+
69646+ return 0;
69647+}
69648+
69649+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69650+{
69651+ struct acl_role_label_compat rolecompat;
69652+
69653+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69654+ return -EFAULT;
69655+
69656+ role->rolename = compat_ptr(rolecompat.rolename);
69657+ role->uidgid = rolecompat.uidgid;
69658+ role->roletype = rolecompat.roletype;
69659+
69660+ role->auth_attempts = rolecompat.auth_attempts;
69661+ role->expires = rolecompat.expires;
69662+
69663+ role->root_label = compat_ptr(rolecompat.root_label);
69664+ role->hash = compat_ptr(rolecompat.hash);
69665+
69666+ role->prev = compat_ptr(rolecompat.prev);
69667+ role->next = compat_ptr(rolecompat.next);
69668+
69669+ role->transitions = compat_ptr(rolecompat.transitions);
69670+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69671+ role->domain_children = compat_ptr(rolecompat.domain_children);
69672+ role->domain_child_num = rolecompat.domain_child_num;
69673+
69674+ role->umask = rolecompat.umask;
69675+
69676+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69677+ role->subj_hash_size = rolecompat.subj_hash_size;
69678+
69679+ return 0;
69680+}
69681+
69682+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69683+{
69684+ struct role_allowed_ip_compat roleip_compat;
69685+
69686+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69687+ return -EFAULT;
69688+
69689+ roleip->addr = roleip_compat.addr;
69690+ roleip->netmask = roleip_compat.netmask;
69691+
69692+ roleip->prev = compat_ptr(roleip_compat.prev);
69693+ roleip->next = compat_ptr(roleip_compat.next);
69694+
69695+ return 0;
69696+}
69697+
69698+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69699+{
69700+ struct role_transition_compat trans_compat;
69701+
69702+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69703+ return -EFAULT;
69704+
69705+ trans->rolename = compat_ptr(trans_compat.rolename);
69706+
69707+ trans->prev = compat_ptr(trans_compat.prev);
69708+ trans->next = compat_ptr(trans_compat.next);
69709+
69710+ return 0;
69711+
69712+}
69713+
69714+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69715+{
69716+ struct gr_hash_struct_compat hash_compat;
69717+
69718+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69719+ return -EFAULT;
69720+
69721+ hash->table = compat_ptr(hash_compat.table);
69722+ hash->nametable = compat_ptr(hash_compat.nametable);
69723+ hash->first = compat_ptr(hash_compat.first);
69724+
69725+ hash->table_size = hash_compat.table_size;
69726+ hash->used_size = hash_compat.used_size;
69727+
69728+ hash->type = hash_compat.type;
69729+
69730+ return 0;
69731+}
69732+
69733+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69734+{
69735+ compat_uptr_t ptrcompat;
69736+
69737+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69738+ return -EFAULT;
69739+
69740+ *(void **)ptr = compat_ptr(ptrcompat);
69741+
69742+ return 0;
69743+}
69744+
69745+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69746+{
69747+ struct acl_ip_label_compat ip_compat;
69748+
69749+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69750+ return -EFAULT;
69751+
69752+ ip->iface = compat_ptr(ip_compat.iface);
69753+ ip->addr = ip_compat.addr;
69754+ ip->netmask = ip_compat.netmask;
69755+ ip->low = ip_compat.low;
69756+ ip->high = ip_compat.high;
69757+ ip->mode = ip_compat.mode;
69758+ ip->type = ip_compat.type;
69759+
69760+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69761+
69762+ ip->prev = compat_ptr(ip_compat.prev);
69763+ ip->next = compat_ptr(ip_compat.next);
69764+
69765+ return 0;
69766+}
69767+
69768+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69769+{
69770+ struct sprole_pw_compat pw_compat;
69771+
69772+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69773+ return -EFAULT;
69774+
69775+ pw->rolename = compat_ptr(pw_compat.rolename);
69776+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69777+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69778+
69779+ return 0;
69780+}
69781+
69782+size_t get_gr_arg_wrapper_size_compat(void)
69783+{
69784+ return sizeof(struct gr_arg_wrapper_compat);
69785+}
69786+
69787diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69788new file mode 100644
69789index 0000000..a89b1f4
69790--- /dev/null
69791+++ b/grsecurity/gracl_fs.c
69792@@ -0,0 +1,437 @@
69793+#include <linux/kernel.h>
69794+#include <linux/sched.h>
69795+#include <linux/types.h>
69796+#include <linux/fs.h>
69797+#include <linux/file.h>
69798+#include <linux/stat.h>
69799+#include <linux/grsecurity.h>
69800+#include <linux/grinternal.h>
69801+#include <linux/gracl.h>
69802+
69803+umode_t
69804+gr_acl_umask(void)
69805+{
69806+ if (unlikely(!gr_acl_is_enabled()))
69807+ return 0;
69808+
69809+ return current->role->umask;
69810+}
69811+
69812+__u32
69813+gr_acl_handle_hidden_file(const struct dentry * dentry,
69814+ const struct vfsmount * mnt)
69815+{
69816+ __u32 mode;
69817+
69818+ if (unlikely(d_is_negative(dentry)))
69819+ return GR_FIND;
69820+
69821+ mode =
69822+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69823+
69824+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69825+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69826+ return mode;
69827+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69828+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69829+ return 0;
69830+ } else if (unlikely(!(mode & GR_FIND)))
69831+ return 0;
69832+
69833+ return GR_FIND;
69834+}
69835+
69836+__u32
69837+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69838+ int acc_mode)
69839+{
69840+ __u32 reqmode = GR_FIND;
69841+ __u32 mode;
69842+
69843+ if (unlikely(d_is_negative(dentry)))
69844+ return reqmode;
69845+
69846+ if (acc_mode & MAY_APPEND)
69847+ reqmode |= GR_APPEND;
69848+ else if (acc_mode & MAY_WRITE)
69849+ reqmode |= GR_WRITE;
69850+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69851+ reqmode |= GR_READ;
69852+
69853+ mode =
69854+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69855+ mnt);
69856+
69857+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69858+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69859+ reqmode & GR_READ ? " reading" : "",
69860+ reqmode & GR_WRITE ? " writing" : reqmode &
69861+ GR_APPEND ? " appending" : "");
69862+ return reqmode;
69863+ } else
69864+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69865+ {
69866+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69867+ reqmode & GR_READ ? " reading" : "",
69868+ reqmode & GR_WRITE ? " writing" : reqmode &
69869+ GR_APPEND ? " appending" : "");
69870+ return 0;
69871+ } else if (unlikely((mode & reqmode) != reqmode))
69872+ return 0;
69873+
69874+ return reqmode;
69875+}
69876+
69877+__u32
69878+gr_acl_handle_creat(const struct dentry * dentry,
69879+ const struct dentry * p_dentry,
69880+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69881+ const int imode)
69882+{
69883+ __u32 reqmode = GR_WRITE | GR_CREATE;
69884+ __u32 mode;
69885+
69886+ if (acc_mode & MAY_APPEND)
69887+ reqmode |= GR_APPEND;
69888+ // if a directory was required or the directory already exists, then
69889+ // don't count this open as a read
69890+ if ((acc_mode & MAY_READ) &&
69891+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69892+ reqmode |= GR_READ;
69893+ if ((open_flags & O_CREAT) &&
69894+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69895+ reqmode |= GR_SETID;
69896+
69897+ mode =
69898+ gr_check_create(dentry, p_dentry, p_mnt,
69899+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69900+
69901+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69902+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69903+ reqmode & GR_READ ? " reading" : "",
69904+ reqmode & GR_WRITE ? " writing" : reqmode &
69905+ GR_APPEND ? " appending" : "");
69906+ return reqmode;
69907+ } else
69908+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69909+ {
69910+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69911+ reqmode & GR_READ ? " reading" : "",
69912+ reqmode & GR_WRITE ? " writing" : reqmode &
69913+ GR_APPEND ? " appending" : "");
69914+ return 0;
69915+ } else if (unlikely((mode & reqmode) != reqmode))
69916+ return 0;
69917+
69918+ return reqmode;
69919+}
69920+
69921+__u32
69922+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69923+ const int fmode)
69924+{
69925+ __u32 mode, reqmode = GR_FIND;
69926+
69927+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69928+ reqmode |= GR_EXEC;
69929+ if (fmode & S_IWOTH)
69930+ reqmode |= GR_WRITE;
69931+ if (fmode & S_IROTH)
69932+ reqmode |= GR_READ;
69933+
69934+ mode =
69935+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69936+ mnt);
69937+
69938+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69939+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69940+ reqmode & GR_READ ? " reading" : "",
69941+ reqmode & GR_WRITE ? " writing" : "",
69942+ reqmode & GR_EXEC ? " executing" : "");
69943+ return reqmode;
69944+ } else
69945+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69946+ {
69947+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69948+ reqmode & GR_READ ? " reading" : "",
69949+ reqmode & GR_WRITE ? " writing" : "",
69950+ reqmode & GR_EXEC ? " executing" : "");
69951+ return 0;
69952+ } else if (unlikely((mode & reqmode) != reqmode))
69953+ return 0;
69954+
69955+ return reqmode;
69956+}
69957+
69958+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69959+{
69960+ __u32 mode;
69961+
69962+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69963+
69964+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69965+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69966+ return mode;
69967+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69968+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69969+ return 0;
69970+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69971+ return 0;
69972+
69973+ return (reqmode);
69974+}
69975+
69976+__u32
69977+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69978+{
69979+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69980+}
69981+
69982+__u32
69983+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69984+{
69985+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69986+}
69987+
69988+__u32
69989+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69990+{
69991+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69992+}
69993+
69994+__u32
69995+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69996+{
69997+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69998+}
69999+
70000+__u32
70001+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70002+ umode_t *modeptr)
70003+{
70004+ umode_t mode;
70005+
70006+ *modeptr &= ~gr_acl_umask();
70007+ mode = *modeptr;
70008+
70009+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70010+ return 1;
70011+
70012+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70013+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70014+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70015+ GR_CHMOD_ACL_MSG);
70016+ } else {
70017+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70018+ }
70019+}
70020+
70021+__u32
70022+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70023+{
70024+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70025+}
70026+
70027+__u32
70028+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70029+{
70030+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70031+}
70032+
70033+__u32
70034+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70035+{
70036+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70037+}
70038+
70039+__u32
70040+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70041+{
70042+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70043+}
70044+
70045+__u32
70046+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70047+{
70048+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70049+ GR_UNIXCONNECT_ACL_MSG);
70050+}
70051+
70052+/* hardlinks require at minimum create and link permission,
70053+ any additional privilege required is based on the
70054+ privilege of the file being linked to
70055+*/
70056+__u32
70057+gr_acl_handle_link(const struct dentry * new_dentry,
70058+ const struct dentry * parent_dentry,
70059+ const struct vfsmount * parent_mnt,
70060+ const struct dentry * old_dentry,
70061+ const struct vfsmount * old_mnt, const struct filename *to)
70062+{
70063+ __u32 mode;
70064+ __u32 needmode = GR_CREATE | GR_LINK;
70065+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70066+
70067+ mode =
70068+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70069+ old_mnt);
70070+
70071+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70072+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70073+ return mode;
70074+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70075+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70076+ return 0;
70077+ } else if (unlikely((mode & needmode) != needmode))
70078+ return 0;
70079+
70080+ return 1;
70081+}
70082+
70083+__u32
70084+gr_acl_handle_symlink(const struct dentry * new_dentry,
70085+ const struct dentry * parent_dentry,
70086+ const struct vfsmount * parent_mnt, const struct filename *from)
70087+{
70088+ __u32 needmode = GR_WRITE | GR_CREATE;
70089+ __u32 mode;
70090+
70091+ mode =
70092+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70093+ GR_CREATE | GR_AUDIT_CREATE |
70094+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70095+
70096+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70097+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70098+ return mode;
70099+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70100+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70101+ return 0;
70102+ } else if (unlikely((mode & needmode) != needmode))
70103+ return 0;
70104+
70105+ return (GR_WRITE | GR_CREATE);
70106+}
70107+
70108+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)
70109+{
70110+ __u32 mode;
70111+
70112+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70113+
70114+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70115+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70116+ return mode;
70117+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70118+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70119+ return 0;
70120+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70121+ return 0;
70122+
70123+ return (reqmode);
70124+}
70125+
70126+__u32
70127+gr_acl_handle_mknod(const struct dentry * new_dentry,
70128+ const struct dentry * parent_dentry,
70129+ const struct vfsmount * parent_mnt,
70130+ const int mode)
70131+{
70132+ __u32 reqmode = GR_WRITE | GR_CREATE;
70133+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70134+ reqmode |= GR_SETID;
70135+
70136+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70137+ reqmode, GR_MKNOD_ACL_MSG);
70138+}
70139+
70140+__u32
70141+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70142+ const struct dentry *parent_dentry,
70143+ const struct vfsmount *parent_mnt)
70144+{
70145+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70146+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70147+}
70148+
70149+#define RENAME_CHECK_SUCCESS(old, new) \
70150+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70151+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70152+
70153+int
70154+gr_acl_handle_rename(struct dentry *new_dentry,
70155+ struct dentry *parent_dentry,
70156+ const struct vfsmount *parent_mnt,
70157+ struct dentry *old_dentry,
70158+ struct inode *old_parent_inode,
70159+ struct vfsmount *old_mnt, const struct filename *newname)
70160+{
70161+ __u32 comp1, comp2;
70162+ int error = 0;
70163+
70164+ if (unlikely(!gr_acl_is_enabled()))
70165+ return 0;
70166+
70167+ if (d_is_negative(new_dentry)) {
70168+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70169+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70170+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70171+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70172+ GR_DELETE | GR_AUDIT_DELETE |
70173+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70174+ GR_SUPPRESS, old_mnt);
70175+ } else {
70176+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70177+ GR_CREATE | GR_DELETE |
70178+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70179+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70180+ GR_SUPPRESS, parent_mnt);
70181+ comp2 =
70182+ gr_search_file(old_dentry,
70183+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70184+ GR_DELETE | GR_AUDIT_DELETE |
70185+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70186+ }
70187+
70188+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70189+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70190+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70191+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70192+ && !(comp2 & GR_SUPPRESS)) {
70193+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70194+ error = -EACCES;
70195+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70196+ error = -EACCES;
70197+
70198+ return error;
70199+}
70200+
70201+void
70202+gr_acl_handle_exit(void)
70203+{
70204+ u16 id;
70205+ char *rolename;
70206+
70207+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70208+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70209+ id = current->acl_role_id;
70210+ rolename = current->role->rolename;
70211+ gr_set_acls(1);
70212+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70213+ }
70214+
70215+ gr_put_exec_file(current);
70216+ return;
70217+}
70218+
70219+int
70220+gr_acl_handle_procpidmem(const struct task_struct *task)
70221+{
70222+ if (unlikely(!gr_acl_is_enabled()))
70223+ return 0;
70224+
70225+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70226+ return -EACCES;
70227+
70228+ return 0;
70229+}
70230diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70231new file mode 100644
70232index 0000000..f056b81
70233--- /dev/null
70234+++ b/grsecurity/gracl_ip.c
70235@@ -0,0 +1,386 @@
70236+#include <linux/kernel.h>
70237+#include <asm/uaccess.h>
70238+#include <asm/errno.h>
70239+#include <net/sock.h>
70240+#include <linux/file.h>
70241+#include <linux/fs.h>
70242+#include <linux/net.h>
70243+#include <linux/in.h>
70244+#include <linux/skbuff.h>
70245+#include <linux/ip.h>
70246+#include <linux/udp.h>
70247+#include <linux/types.h>
70248+#include <linux/sched.h>
70249+#include <linux/netdevice.h>
70250+#include <linux/inetdevice.h>
70251+#include <linux/gracl.h>
70252+#include <linux/grsecurity.h>
70253+#include <linux/grinternal.h>
70254+
70255+#define GR_BIND 0x01
70256+#define GR_CONNECT 0x02
70257+#define GR_INVERT 0x04
70258+#define GR_BINDOVERRIDE 0x08
70259+#define GR_CONNECTOVERRIDE 0x10
70260+#define GR_SOCK_FAMILY 0x20
70261+
70262+static const char * gr_protocols[IPPROTO_MAX] = {
70263+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70264+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70265+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70266+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70267+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70268+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70269+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70270+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70271+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70272+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70273+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70274+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70275+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70276+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70277+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70278+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70279+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70280+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70281+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70282+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70283+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70284+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70285+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70286+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70287+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70288+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70289+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70290+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70291+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70292+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70293+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70294+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70295+ };
70296+
70297+static const char * gr_socktypes[SOCK_MAX] = {
70298+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70299+ "unknown:7", "unknown:8", "unknown:9", "packet"
70300+ };
70301+
70302+static const char * gr_sockfamilies[AF_MAX+1] = {
70303+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70304+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70305+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70306+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70307+ };
70308+
70309+const char *
70310+gr_proto_to_name(unsigned char proto)
70311+{
70312+ return gr_protocols[proto];
70313+}
70314+
70315+const char *
70316+gr_socktype_to_name(unsigned char type)
70317+{
70318+ return gr_socktypes[type];
70319+}
70320+
70321+const char *
70322+gr_sockfamily_to_name(unsigned char family)
70323+{
70324+ return gr_sockfamilies[family];
70325+}
70326+
70327+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70328+
70329+int
70330+gr_search_socket(const int domain, const int type, const int protocol)
70331+{
70332+ struct acl_subject_label *curr;
70333+ const struct cred *cred = current_cred();
70334+
70335+ if (unlikely(!gr_acl_is_enabled()))
70336+ goto exit;
70337+
70338+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70339+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70340+ goto exit; // let the kernel handle it
70341+
70342+ curr = current->acl;
70343+
70344+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70345+ /* the family is allowed, if this is PF_INET allow it only if
70346+ the extra sock type/protocol checks pass */
70347+ if (domain == PF_INET)
70348+ goto inet_check;
70349+ goto exit;
70350+ } else {
70351+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70352+ __u32 fakeip = 0;
70353+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70354+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70355+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70356+ gr_to_filename(current->exec_file->f_path.dentry,
70357+ current->exec_file->f_path.mnt) :
70358+ curr->filename, curr->filename,
70359+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70360+ &current->signal->saved_ip);
70361+ goto exit;
70362+ }
70363+ goto exit_fail;
70364+ }
70365+
70366+inet_check:
70367+ /* the rest of this checking is for IPv4 only */
70368+ if (!curr->ips)
70369+ goto exit;
70370+
70371+ if ((curr->ip_type & (1U << type)) &&
70372+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70373+ goto exit;
70374+
70375+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70376+ /* we don't place acls on raw sockets , and sometimes
70377+ dgram/ip sockets are opened for ioctl and not
70378+ bind/connect, so we'll fake a bind learn log */
70379+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70380+ __u32 fakeip = 0;
70381+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70382+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70383+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70384+ gr_to_filename(current->exec_file->f_path.dentry,
70385+ current->exec_file->f_path.mnt) :
70386+ curr->filename, curr->filename,
70387+ &fakeip, 0, type,
70388+ protocol, GR_CONNECT, &current->signal->saved_ip);
70389+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70390+ __u32 fakeip = 0;
70391+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70392+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70393+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70394+ gr_to_filename(current->exec_file->f_path.dentry,
70395+ current->exec_file->f_path.mnt) :
70396+ curr->filename, curr->filename,
70397+ &fakeip, 0, type,
70398+ protocol, GR_BIND, &current->signal->saved_ip);
70399+ }
70400+ /* we'll log when they use connect or bind */
70401+ goto exit;
70402+ }
70403+
70404+exit_fail:
70405+ if (domain == PF_INET)
70406+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70407+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70408+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70409+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70410+ gr_socktype_to_name(type), protocol);
70411+
70412+ return 0;
70413+exit:
70414+ return 1;
70415+}
70416+
70417+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)
70418+{
70419+ if ((ip->mode & mode) &&
70420+ (ip_port >= ip->low) &&
70421+ (ip_port <= ip->high) &&
70422+ ((ntohl(ip_addr) & our_netmask) ==
70423+ (ntohl(our_addr) & our_netmask))
70424+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70425+ && (ip->type & (1U << type))) {
70426+ if (ip->mode & GR_INVERT)
70427+ return 2; // specifically denied
70428+ else
70429+ return 1; // allowed
70430+ }
70431+
70432+ return 0; // not specifically allowed, may continue parsing
70433+}
70434+
70435+static int
70436+gr_search_connectbind(const int full_mode, struct sock *sk,
70437+ struct sockaddr_in *addr, const int type)
70438+{
70439+ char iface[IFNAMSIZ] = {0};
70440+ struct acl_subject_label *curr;
70441+ struct acl_ip_label *ip;
70442+ struct inet_sock *isk;
70443+ struct net_device *dev;
70444+ struct in_device *idev;
70445+ unsigned long i;
70446+ int ret;
70447+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70448+ __u32 ip_addr = 0;
70449+ __u32 our_addr;
70450+ __u32 our_netmask;
70451+ char *p;
70452+ __u16 ip_port = 0;
70453+ const struct cred *cred = current_cred();
70454+
70455+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70456+ return 0;
70457+
70458+ curr = current->acl;
70459+ isk = inet_sk(sk);
70460+
70461+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70462+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70463+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70464+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70465+ struct sockaddr_in saddr;
70466+ int err;
70467+
70468+ saddr.sin_family = AF_INET;
70469+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70470+ saddr.sin_port = isk->inet_sport;
70471+
70472+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70473+ if (err)
70474+ return err;
70475+
70476+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70477+ if (err)
70478+ return err;
70479+ }
70480+
70481+ if (!curr->ips)
70482+ return 0;
70483+
70484+ ip_addr = addr->sin_addr.s_addr;
70485+ ip_port = ntohs(addr->sin_port);
70486+
70487+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70488+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70489+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70490+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70491+ gr_to_filename(current->exec_file->f_path.dentry,
70492+ current->exec_file->f_path.mnt) :
70493+ curr->filename, curr->filename,
70494+ &ip_addr, ip_port, type,
70495+ sk->sk_protocol, mode, &current->signal->saved_ip);
70496+ return 0;
70497+ }
70498+
70499+ for (i = 0; i < curr->ip_num; i++) {
70500+ ip = *(curr->ips + i);
70501+ if (ip->iface != NULL) {
70502+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70503+ p = strchr(iface, ':');
70504+ if (p != NULL)
70505+ *p = '\0';
70506+ dev = dev_get_by_name(sock_net(sk), iface);
70507+ if (dev == NULL)
70508+ continue;
70509+ idev = in_dev_get(dev);
70510+ if (idev == NULL) {
70511+ dev_put(dev);
70512+ continue;
70513+ }
70514+ rcu_read_lock();
70515+ for_ifa(idev) {
70516+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70517+ our_addr = ifa->ifa_address;
70518+ our_netmask = 0xffffffff;
70519+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70520+ if (ret == 1) {
70521+ rcu_read_unlock();
70522+ in_dev_put(idev);
70523+ dev_put(dev);
70524+ return 0;
70525+ } else if (ret == 2) {
70526+ rcu_read_unlock();
70527+ in_dev_put(idev);
70528+ dev_put(dev);
70529+ goto denied;
70530+ }
70531+ }
70532+ } endfor_ifa(idev);
70533+ rcu_read_unlock();
70534+ in_dev_put(idev);
70535+ dev_put(dev);
70536+ } else {
70537+ our_addr = ip->addr;
70538+ our_netmask = ip->netmask;
70539+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70540+ if (ret == 1)
70541+ return 0;
70542+ else if (ret == 2)
70543+ goto denied;
70544+ }
70545+ }
70546+
70547+denied:
70548+ if (mode == GR_BIND)
70549+ 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));
70550+ else if (mode == GR_CONNECT)
70551+ 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));
70552+
70553+ return -EACCES;
70554+}
70555+
70556+int
70557+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70558+{
70559+ /* always allow disconnection of dgram sockets with connect */
70560+ if (addr->sin_family == AF_UNSPEC)
70561+ return 0;
70562+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70563+}
70564+
70565+int
70566+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70567+{
70568+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70569+}
70570+
70571+int gr_search_listen(struct socket *sock)
70572+{
70573+ struct sock *sk = sock->sk;
70574+ struct sockaddr_in addr;
70575+
70576+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70577+ addr.sin_port = inet_sk(sk)->inet_sport;
70578+
70579+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70580+}
70581+
70582+int gr_search_accept(struct socket *sock)
70583+{
70584+ struct sock *sk = sock->sk;
70585+ struct sockaddr_in addr;
70586+
70587+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70588+ addr.sin_port = inet_sk(sk)->inet_sport;
70589+
70590+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70591+}
70592+
70593+int
70594+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70595+{
70596+ if (addr)
70597+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70598+ else {
70599+ struct sockaddr_in sin;
70600+ const struct inet_sock *inet = inet_sk(sk);
70601+
70602+ sin.sin_addr.s_addr = inet->inet_daddr;
70603+ sin.sin_port = inet->inet_dport;
70604+
70605+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70606+ }
70607+}
70608+
70609+int
70610+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70611+{
70612+ struct sockaddr_in sin;
70613+
70614+ if (unlikely(skb->len < sizeof (struct udphdr)))
70615+ return 0; // skip this packet
70616+
70617+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70618+ sin.sin_port = udp_hdr(skb)->source;
70619+
70620+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70621+}
70622diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70623new file mode 100644
70624index 0000000..25f54ef
70625--- /dev/null
70626+++ b/grsecurity/gracl_learn.c
70627@@ -0,0 +1,207 @@
70628+#include <linux/kernel.h>
70629+#include <linux/mm.h>
70630+#include <linux/sched.h>
70631+#include <linux/poll.h>
70632+#include <linux/string.h>
70633+#include <linux/file.h>
70634+#include <linux/types.h>
70635+#include <linux/vmalloc.h>
70636+#include <linux/grinternal.h>
70637+
70638+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70639+ size_t count, loff_t *ppos);
70640+extern int gr_acl_is_enabled(void);
70641+
70642+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70643+static int gr_learn_attached;
70644+
70645+/* use a 512k buffer */
70646+#define LEARN_BUFFER_SIZE (512 * 1024)
70647+
70648+static DEFINE_SPINLOCK(gr_learn_lock);
70649+static DEFINE_MUTEX(gr_learn_user_mutex);
70650+
70651+/* we need to maintain two buffers, so that the kernel context of grlearn
70652+ uses a semaphore around the userspace copying, and the other kernel contexts
70653+ use a spinlock when copying into the buffer, since they cannot sleep
70654+*/
70655+static char *learn_buffer;
70656+static char *learn_buffer_user;
70657+static int learn_buffer_len;
70658+static int learn_buffer_user_len;
70659+
70660+static ssize_t
70661+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70662+{
70663+ DECLARE_WAITQUEUE(wait, current);
70664+ ssize_t retval = 0;
70665+
70666+ add_wait_queue(&learn_wait, &wait);
70667+ set_current_state(TASK_INTERRUPTIBLE);
70668+ do {
70669+ mutex_lock(&gr_learn_user_mutex);
70670+ spin_lock(&gr_learn_lock);
70671+ if (learn_buffer_len)
70672+ break;
70673+ spin_unlock(&gr_learn_lock);
70674+ mutex_unlock(&gr_learn_user_mutex);
70675+ if (file->f_flags & O_NONBLOCK) {
70676+ retval = -EAGAIN;
70677+ goto out;
70678+ }
70679+ if (signal_pending(current)) {
70680+ retval = -ERESTARTSYS;
70681+ goto out;
70682+ }
70683+
70684+ schedule();
70685+ } while (1);
70686+
70687+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70688+ learn_buffer_user_len = learn_buffer_len;
70689+ retval = learn_buffer_len;
70690+ learn_buffer_len = 0;
70691+
70692+ spin_unlock(&gr_learn_lock);
70693+
70694+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70695+ retval = -EFAULT;
70696+
70697+ mutex_unlock(&gr_learn_user_mutex);
70698+out:
70699+ set_current_state(TASK_RUNNING);
70700+ remove_wait_queue(&learn_wait, &wait);
70701+ return retval;
70702+}
70703+
70704+static unsigned int
70705+poll_learn(struct file * file, poll_table * wait)
70706+{
70707+ poll_wait(file, &learn_wait, wait);
70708+
70709+ if (learn_buffer_len)
70710+ return (POLLIN | POLLRDNORM);
70711+
70712+ return 0;
70713+}
70714+
70715+void
70716+gr_clear_learn_entries(void)
70717+{
70718+ char *tmp;
70719+
70720+ mutex_lock(&gr_learn_user_mutex);
70721+ spin_lock(&gr_learn_lock);
70722+ tmp = learn_buffer;
70723+ learn_buffer = NULL;
70724+ spin_unlock(&gr_learn_lock);
70725+ if (tmp)
70726+ vfree(tmp);
70727+ if (learn_buffer_user != NULL) {
70728+ vfree(learn_buffer_user);
70729+ learn_buffer_user = NULL;
70730+ }
70731+ learn_buffer_len = 0;
70732+ mutex_unlock(&gr_learn_user_mutex);
70733+
70734+ return;
70735+}
70736+
70737+void
70738+gr_add_learn_entry(const char *fmt, ...)
70739+{
70740+ va_list args;
70741+ unsigned int len;
70742+
70743+ if (!gr_learn_attached)
70744+ return;
70745+
70746+ spin_lock(&gr_learn_lock);
70747+
70748+ /* leave a gap at the end so we know when it's "full" but don't have to
70749+ compute the exact length of the string we're trying to append
70750+ */
70751+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70752+ spin_unlock(&gr_learn_lock);
70753+ wake_up_interruptible(&learn_wait);
70754+ return;
70755+ }
70756+ if (learn_buffer == NULL) {
70757+ spin_unlock(&gr_learn_lock);
70758+ return;
70759+ }
70760+
70761+ va_start(args, fmt);
70762+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70763+ va_end(args);
70764+
70765+ learn_buffer_len += len + 1;
70766+
70767+ spin_unlock(&gr_learn_lock);
70768+ wake_up_interruptible(&learn_wait);
70769+
70770+ return;
70771+}
70772+
70773+static int
70774+open_learn(struct inode *inode, struct file *file)
70775+{
70776+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70777+ return -EBUSY;
70778+ if (file->f_mode & FMODE_READ) {
70779+ int retval = 0;
70780+ mutex_lock(&gr_learn_user_mutex);
70781+ if (learn_buffer == NULL)
70782+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70783+ if (learn_buffer_user == NULL)
70784+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70785+ if (learn_buffer == NULL) {
70786+ retval = -ENOMEM;
70787+ goto out_error;
70788+ }
70789+ if (learn_buffer_user == NULL) {
70790+ retval = -ENOMEM;
70791+ goto out_error;
70792+ }
70793+ learn_buffer_len = 0;
70794+ learn_buffer_user_len = 0;
70795+ gr_learn_attached = 1;
70796+out_error:
70797+ mutex_unlock(&gr_learn_user_mutex);
70798+ return retval;
70799+ }
70800+ return 0;
70801+}
70802+
70803+static int
70804+close_learn(struct inode *inode, struct file *file)
70805+{
70806+ if (file->f_mode & FMODE_READ) {
70807+ char *tmp = NULL;
70808+ mutex_lock(&gr_learn_user_mutex);
70809+ spin_lock(&gr_learn_lock);
70810+ tmp = learn_buffer;
70811+ learn_buffer = NULL;
70812+ spin_unlock(&gr_learn_lock);
70813+ if (tmp)
70814+ vfree(tmp);
70815+ if (learn_buffer_user != NULL) {
70816+ vfree(learn_buffer_user);
70817+ learn_buffer_user = NULL;
70818+ }
70819+ learn_buffer_len = 0;
70820+ learn_buffer_user_len = 0;
70821+ gr_learn_attached = 0;
70822+ mutex_unlock(&gr_learn_user_mutex);
70823+ }
70824+
70825+ return 0;
70826+}
70827+
70828+const struct file_operations grsec_fops = {
70829+ .read = read_learn,
70830+ .write = write_grsec_handler,
70831+ .open = open_learn,
70832+ .release = close_learn,
70833+ .poll = poll_learn,
70834+};
70835diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70836new file mode 100644
70837index 0000000..361a099
70838--- /dev/null
70839+++ b/grsecurity/gracl_policy.c
70840@@ -0,0 +1,1782 @@
70841+#include <linux/kernel.h>
70842+#include <linux/module.h>
70843+#include <linux/sched.h>
70844+#include <linux/mm.h>
70845+#include <linux/file.h>
70846+#include <linux/fs.h>
70847+#include <linux/namei.h>
70848+#include <linux/mount.h>
70849+#include <linux/tty.h>
70850+#include <linux/proc_fs.h>
70851+#include <linux/lglock.h>
70852+#include <linux/slab.h>
70853+#include <linux/vmalloc.h>
70854+#include <linux/types.h>
70855+#include <linux/sysctl.h>
70856+#include <linux/netdevice.h>
70857+#include <linux/ptrace.h>
70858+#include <linux/gracl.h>
70859+#include <linux/gralloc.h>
70860+#include <linux/security.h>
70861+#include <linux/grinternal.h>
70862+#include <linux/pid_namespace.h>
70863+#include <linux/stop_machine.h>
70864+#include <linux/fdtable.h>
70865+#include <linux/percpu.h>
70866+#include <linux/lglock.h>
70867+#include <linux/hugetlb.h>
70868+#include <linux/posix-timers.h>
70869+#include "../fs/mount.h"
70870+
70871+#include <asm/uaccess.h>
70872+#include <asm/errno.h>
70873+#include <asm/mman.h>
70874+
70875+extern struct gr_policy_state *polstate;
70876+
70877+#define FOR_EACH_ROLE_START(role) \
70878+ role = polstate->role_list; \
70879+ while (role) {
70880+
70881+#define FOR_EACH_ROLE_END(role) \
70882+ role = role->prev; \
70883+ }
70884+
70885+struct path gr_real_root;
70886+
70887+extern struct gr_alloc_state *current_alloc_state;
70888+
70889+u16 acl_sp_role_value;
70890+
70891+static DEFINE_MUTEX(gr_dev_mutex);
70892+
70893+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70894+extern void gr_clear_learn_entries(void);
70895+
70896+static struct gr_arg gr_usermode;
70897+static unsigned char gr_system_salt[GR_SALT_LEN];
70898+static unsigned char gr_system_sum[GR_SHA_LEN];
70899+
70900+static unsigned int gr_auth_attempts = 0;
70901+static unsigned long gr_auth_expires = 0UL;
70902+
70903+struct acl_object_label *fakefs_obj_rw;
70904+struct acl_object_label *fakefs_obj_rwx;
70905+
70906+extern int gr_init_uidset(void);
70907+extern void gr_free_uidset(void);
70908+extern void gr_remove_uid(uid_t uid);
70909+extern int gr_find_uid(uid_t uid);
70910+
70911+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70912+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70913+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70914+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70915+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);
70916+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70917+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70918+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70919+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70920+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70921+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70922+extern void assign_special_role(const char *rolename);
70923+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70924+extern int gr_rbac_disable(void *unused);
70925+extern void gr_enable_rbac_system(void);
70926+
70927+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70928+{
70929+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70930+ return -EFAULT;
70931+
70932+ return 0;
70933+}
70934+
70935+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70936+{
70937+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70938+ return -EFAULT;
70939+
70940+ return 0;
70941+}
70942+
70943+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70944+{
70945+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70946+ return -EFAULT;
70947+
70948+ return 0;
70949+}
70950+
70951+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70952+{
70953+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70954+ return -EFAULT;
70955+
70956+ return 0;
70957+}
70958+
70959+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70960+{
70961+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70962+ return -EFAULT;
70963+
70964+ return 0;
70965+}
70966+
70967+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70968+{
70969+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70970+ return -EFAULT;
70971+
70972+ return 0;
70973+}
70974+
70975+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70976+{
70977+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70978+ return -EFAULT;
70979+
70980+ return 0;
70981+}
70982+
70983+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70984+{
70985+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70986+ return -EFAULT;
70987+
70988+ return 0;
70989+}
70990+
70991+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70992+{
70993+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70994+ return -EFAULT;
70995+
70996+ return 0;
70997+}
70998+
70999+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71000+{
71001+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71002+ return -EFAULT;
71003+
71004+ if (((uwrap->version != GRSECURITY_VERSION) &&
71005+ (uwrap->version != 0x2901)) ||
71006+ (uwrap->size != sizeof(struct gr_arg)))
71007+ return -EINVAL;
71008+
71009+ return 0;
71010+}
71011+
71012+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71013+{
71014+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71015+ return -EFAULT;
71016+
71017+ return 0;
71018+}
71019+
71020+static size_t get_gr_arg_wrapper_size_normal(void)
71021+{
71022+ return sizeof(struct gr_arg_wrapper);
71023+}
71024+
71025+#ifdef CONFIG_COMPAT
71026+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71027+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71028+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71029+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71030+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71031+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71032+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71033+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71034+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71035+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71036+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71037+extern size_t get_gr_arg_wrapper_size_compat(void);
71038+
71039+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71040+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71041+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71042+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71043+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71044+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71045+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71046+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71047+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71048+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71049+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71050+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71051+
71052+#else
71053+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71054+#define copy_gr_arg copy_gr_arg_normal
71055+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71056+#define copy_acl_object_label copy_acl_object_label_normal
71057+#define copy_acl_subject_label copy_acl_subject_label_normal
71058+#define copy_acl_role_label copy_acl_role_label_normal
71059+#define copy_acl_ip_label copy_acl_ip_label_normal
71060+#define copy_pointer_from_array copy_pointer_from_array_normal
71061+#define copy_sprole_pw copy_sprole_pw_normal
71062+#define copy_role_transition copy_role_transition_normal
71063+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71064+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71065+#endif
71066+
71067+static struct acl_subject_label *
71068+lookup_subject_map(const struct acl_subject_label *userp)
71069+{
71070+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71071+ struct subject_map *match;
71072+
71073+ match = polstate->subj_map_set.s_hash[index];
71074+
71075+ while (match && match->user != userp)
71076+ match = match->next;
71077+
71078+ if (match != NULL)
71079+ return match->kernel;
71080+ else
71081+ return NULL;
71082+}
71083+
71084+static void
71085+insert_subj_map_entry(struct subject_map *subjmap)
71086+{
71087+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71088+ struct subject_map **curr;
71089+
71090+ subjmap->prev = NULL;
71091+
71092+ curr = &polstate->subj_map_set.s_hash[index];
71093+ if (*curr != NULL)
71094+ (*curr)->prev = subjmap;
71095+
71096+ subjmap->next = *curr;
71097+ *curr = subjmap;
71098+
71099+ return;
71100+}
71101+
71102+static void
71103+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71104+{
71105+ unsigned int index =
71106+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71107+ struct acl_role_label **curr;
71108+ struct acl_role_label *tmp, *tmp2;
71109+
71110+ curr = &polstate->acl_role_set.r_hash[index];
71111+
71112+ /* simple case, slot is empty, just set it to our role */
71113+ if (*curr == NULL) {
71114+ *curr = role;
71115+ } else {
71116+ /* example:
71117+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71118+ 2 -> 3
71119+ */
71120+ /* first check to see if we can already be reached via this slot */
71121+ tmp = *curr;
71122+ while (tmp && tmp != role)
71123+ tmp = tmp->next;
71124+ if (tmp == role) {
71125+ /* we don't need to add ourselves to this slot's chain */
71126+ return;
71127+ }
71128+ /* we need to add ourselves to this chain, two cases */
71129+ if (role->next == NULL) {
71130+ /* simple case, append the current chain to our role */
71131+ role->next = *curr;
71132+ *curr = role;
71133+ } else {
71134+ /* 1 -> 2 -> 3 -> 4
71135+ 2 -> 3 -> 4
71136+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71137+ */
71138+ /* trickier case: walk our role's chain until we find
71139+ the role for the start of the current slot's chain */
71140+ tmp = role;
71141+ tmp2 = *curr;
71142+ while (tmp->next && tmp->next != tmp2)
71143+ tmp = tmp->next;
71144+ if (tmp->next == tmp2) {
71145+ /* from example above, we found 3, so just
71146+ replace this slot's chain with ours */
71147+ *curr = role;
71148+ } else {
71149+ /* we didn't find a subset of our role's chain
71150+ in the current slot's chain, so append their
71151+ chain to ours, and set us as the first role in
71152+ the slot's chain
71153+
71154+ we could fold this case with the case above,
71155+ but making it explicit for clarity
71156+ */
71157+ tmp->next = tmp2;
71158+ *curr = role;
71159+ }
71160+ }
71161+ }
71162+
71163+ return;
71164+}
71165+
71166+static void
71167+insert_acl_role_label(struct acl_role_label *role)
71168+{
71169+ int i;
71170+
71171+ if (polstate->role_list == NULL) {
71172+ polstate->role_list = role;
71173+ role->prev = NULL;
71174+ } else {
71175+ role->prev = polstate->role_list;
71176+ polstate->role_list = role;
71177+ }
71178+
71179+ /* used for hash chains */
71180+ role->next = NULL;
71181+
71182+ if (role->roletype & GR_ROLE_DOMAIN) {
71183+ for (i = 0; i < role->domain_child_num; i++)
71184+ __insert_acl_role_label(role, role->domain_children[i]);
71185+ } else
71186+ __insert_acl_role_label(role, role->uidgid);
71187+}
71188+
71189+static int
71190+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71191+{
71192+ struct name_entry **curr, *nentry;
71193+ struct inodev_entry *ientry;
71194+ unsigned int len = strlen(name);
71195+ unsigned int key = full_name_hash(name, len);
71196+ unsigned int index = key % polstate->name_set.n_size;
71197+
71198+ curr = &polstate->name_set.n_hash[index];
71199+
71200+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71201+ curr = &((*curr)->next);
71202+
71203+ if (*curr != NULL)
71204+ return 1;
71205+
71206+ nentry = acl_alloc(sizeof (struct name_entry));
71207+ if (nentry == NULL)
71208+ return 0;
71209+ ientry = acl_alloc(sizeof (struct inodev_entry));
71210+ if (ientry == NULL)
71211+ return 0;
71212+ ientry->nentry = nentry;
71213+
71214+ nentry->key = key;
71215+ nentry->name = name;
71216+ nentry->inode = inode;
71217+ nentry->device = device;
71218+ nentry->len = len;
71219+ nentry->deleted = deleted;
71220+
71221+ nentry->prev = NULL;
71222+ curr = &polstate->name_set.n_hash[index];
71223+ if (*curr != NULL)
71224+ (*curr)->prev = nentry;
71225+ nentry->next = *curr;
71226+ *curr = nentry;
71227+
71228+ /* insert us into the table searchable by inode/dev */
71229+ __insert_inodev_entry(polstate, ientry);
71230+
71231+ return 1;
71232+}
71233+
71234+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71235+
71236+static void *
71237+create_table(__u32 * len, int elementsize)
71238+{
71239+ unsigned int table_sizes[] = {
71240+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71241+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71242+ 4194301, 8388593, 16777213, 33554393, 67108859
71243+ };
71244+ void *newtable = NULL;
71245+ unsigned int pwr = 0;
71246+
71247+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71248+ table_sizes[pwr] <= *len)
71249+ pwr++;
71250+
71251+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71252+ return newtable;
71253+
71254+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71255+ newtable =
71256+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71257+ else
71258+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71259+
71260+ *len = table_sizes[pwr];
71261+
71262+ return newtable;
71263+}
71264+
71265+static int
71266+init_variables(const struct gr_arg *arg, bool reload)
71267+{
71268+ struct task_struct *reaper = init_pid_ns.child_reaper;
71269+ unsigned int stacksize;
71270+
71271+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71272+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71273+ polstate->name_set.n_size = arg->role_db.num_objects;
71274+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71275+
71276+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71277+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71278+ return 1;
71279+
71280+ if (!reload) {
71281+ if (!gr_init_uidset())
71282+ return 1;
71283+ }
71284+
71285+ /* set up the stack that holds allocation info */
71286+
71287+ stacksize = arg->role_db.num_pointers + 5;
71288+
71289+ if (!acl_alloc_stack_init(stacksize))
71290+ return 1;
71291+
71292+ if (!reload) {
71293+ /* grab reference for the real root dentry and vfsmount */
71294+ get_fs_root(reaper->fs, &gr_real_root);
71295+
71296+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71297+ 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);
71298+#endif
71299+
71300+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71301+ if (fakefs_obj_rw == NULL)
71302+ return 1;
71303+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71304+
71305+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71306+ if (fakefs_obj_rwx == NULL)
71307+ return 1;
71308+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71309+ }
71310+
71311+ polstate->subj_map_set.s_hash =
71312+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71313+ polstate->acl_role_set.r_hash =
71314+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71315+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71316+ polstate->inodev_set.i_hash =
71317+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71318+
71319+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71320+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71321+ return 1;
71322+
71323+ memset(polstate->subj_map_set.s_hash, 0,
71324+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71325+ memset(polstate->acl_role_set.r_hash, 0,
71326+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71327+ memset(polstate->name_set.n_hash, 0,
71328+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71329+ memset(polstate->inodev_set.i_hash, 0,
71330+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71331+
71332+ return 0;
71333+}
71334+
71335+/* free information not needed after startup
71336+ currently contains user->kernel pointer mappings for subjects
71337+*/
71338+
71339+static void
71340+free_init_variables(void)
71341+{
71342+ __u32 i;
71343+
71344+ if (polstate->subj_map_set.s_hash) {
71345+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71346+ if (polstate->subj_map_set.s_hash[i]) {
71347+ kfree(polstate->subj_map_set.s_hash[i]);
71348+ polstate->subj_map_set.s_hash[i] = NULL;
71349+ }
71350+ }
71351+
71352+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71353+ PAGE_SIZE)
71354+ kfree(polstate->subj_map_set.s_hash);
71355+ else
71356+ vfree(polstate->subj_map_set.s_hash);
71357+ }
71358+
71359+ return;
71360+}
71361+
71362+static void
71363+free_variables(bool reload)
71364+{
71365+ struct acl_subject_label *s;
71366+ struct acl_role_label *r;
71367+ struct task_struct *task, *task2;
71368+ unsigned int x;
71369+
71370+ if (!reload) {
71371+ gr_clear_learn_entries();
71372+
71373+ read_lock(&tasklist_lock);
71374+ do_each_thread(task2, task) {
71375+ task->acl_sp_role = 0;
71376+ task->acl_role_id = 0;
71377+ task->inherited = 0;
71378+ task->acl = NULL;
71379+ task->role = NULL;
71380+ } while_each_thread(task2, task);
71381+ read_unlock(&tasklist_lock);
71382+
71383+ kfree(fakefs_obj_rw);
71384+ fakefs_obj_rw = NULL;
71385+ kfree(fakefs_obj_rwx);
71386+ fakefs_obj_rwx = NULL;
71387+
71388+ /* release the reference to the real root dentry and vfsmount */
71389+ path_put(&gr_real_root);
71390+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71391+ }
71392+
71393+ /* free all object hash tables */
71394+
71395+ FOR_EACH_ROLE_START(r)
71396+ if (r->subj_hash == NULL)
71397+ goto next_role;
71398+ FOR_EACH_SUBJECT_START(r, s, x)
71399+ if (s->obj_hash == NULL)
71400+ break;
71401+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71402+ kfree(s->obj_hash);
71403+ else
71404+ vfree(s->obj_hash);
71405+ FOR_EACH_SUBJECT_END(s, x)
71406+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71407+ if (s->obj_hash == NULL)
71408+ break;
71409+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71410+ kfree(s->obj_hash);
71411+ else
71412+ vfree(s->obj_hash);
71413+ FOR_EACH_NESTED_SUBJECT_END(s)
71414+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71415+ kfree(r->subj_hash);
71416+ else
71417+ vfree(r->subj_hash);
71418+ r->subj_hash = NULL;
71419+next_role:
71420+ FOR_EACH_ROLE_END(r)
71421+
71422+ acl_free_all();
71423+
71424+ if (polstate->acl_role_set.r_hash) {
71425+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71426+ PAGE_SIZE)
71427+ kfree(polstate->acl_role_set.r_hash);
71428+ else
71429+ vfree(polstate->acl_role_set.r_hash);
71430+ }
71431+ if (polstate->name_set.n_hash) {
71432+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71433+ PAGE_SIZE)
71434+ kfree(polstate->name_set.n_hash);
71435+ else
71436+ vfree(polstate->name_set.n_hash);
71437+ }
71438+
71439+ if (polstate->inodev_set.i_hash) {
71440+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71441+ PAGE_SIZE)
71442+ kfree(polstate->inodev_set.i_hash);
71443+ else
71444+ vfree(polstate->inodev_set.i_hash);
71445+ }
71446+
71447+ if (!reload)
71448+ gr_free_uidset();
71449+
71450+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71451+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71452+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71453+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71454+
71455+ polstate->default_role = NULL;
71456+ polstate->kernel_role = NULL;
71457+ polstate->role_list = NULL;
71458+
71459+ return;
71460+}
71461+
71462+static struct acl_subject_label *
71463+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71464+
71465+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71466+{
71467+ unsigned int len = strnlen_user(*name, maxlen);
71468+ char *tmp;
71469+
71470+ if (!len || len >= maxlen)
71471+ return -EINVAL;
71472+
71473+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71474+ return -ENOMEM;
71475+
71476+ if (copy_from_user(tmp, *name, len))
71477+ return -EFAULT;
71478+
71479+ tmp[len-1] = '\0';
71480+ *name = tmp;
71481+
71482+ return 0;
71483+}
71484+
71485+static int
71486+copy_user_glob(struct acl_object_label *obj)
71487+{
71488+ struct acl_object_label *g_tmp, **guser;
71489+ int error;
71490+
71491+ if (obj->globbed == NULL)
71492+ return 0;
71493+
71494+ guser = &obj->globbed;
71495+ while (*guser) {
71496+ g_tmp = (struct acl_object_label *)
71497+ acl_alloc(sizeof (struct acl_object_label));
71498+ if (g_tmp == NULL)
71499+ return -ENOMEM;
71500+
71501+ if (copy_acl_object_label(g_tmp, *guser))
71502+ return -EFAULT;
71503+
71504+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71505+ if (error)
71506+ return error;
71507+
71508+ *guser = g_tmp;
71509+ guser = &(g_tmp->next);
71510+ }
71511+
71512+ return 0;
71513+}
71514+
71515+static int
71516+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71517+ struct acl_role_label *role)
71518+{
71519+ struct acl_object_label *o_tmp;
71520+ int ret;
71521+
71522+ while (userp) {
71523+ if ((o_tmp = (struct acl_object_label *)
71524+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71525+ return -ENOMEM;
71526+
71527+ if (copy_acl_object_label(o_tmp, userp))
71528+ return -EFAULT;
71529+
71530+ userp = o_tmp->prev;
71531+
71532+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71533+ if (ret)
71534+ return ret;
71535+
71536+ insert_acl_obj_label(o_tmp, subj);
71537+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71538+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71539+ return -ENOMEM;
71540+
71541+ ret = copy_user_glob(o_tmp);
71542+ if (ret)
71543+ return ret;
71544+
71545+ if (o_tmp->nested) {
71546+ int already_copied;
71547+
71548+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71549+ if (IS_ERR(o_tmp->nested))
71550+ return PTR_ERR(o_tmp->nested);
71551+
71552+ /* insert into nested subject list if we haven't copied this one yet
71553+ to prevent duplicate entries */
71554+ if (!already_copied) {
71555+ o_tmp->nested->next = role->hash->first;
71556+ role->hash->first = o_tmp->nested;
71557+ }
71558+ }
71559+ }
71560+
71561+ return 0;
71562+}
71563+
71564+static __u32
71565+count_user_subjs(struct acl_subject_label *userp)
71566+{
71567+ struct acl_subject_label s_tmp;
71568+ __u32 num = 0;
71569+
71570+ while (userp) {
71571+ if (copy_acl_subject_label(&s_tmp, userp))
71572+ break;
71573+
71574+ userp = s_tmp.prev;
71575+ }
71576+
71577+ return num;
71578+}
71579+
71580+static int
71581+copy_user_allowedips(struct acl_role_label *rolep)
71582+{
71583+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71584+
71585+ ruserip = rolep->allowed_ips;
71586+
71587+ while (ruserip) {
71588+ rlast = rtmp;
71589+
71590+ if ((rtmp = (struct role_allowed_ip *)
71591+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71592+ return -ENOMEM;
71593+
71594+ if (copy_role_allowed_ip(rtmp, ruserip))
71595+ return -EFAULT;
71596+
71597+ ruserip = rtmp->prev;
71598+
71599+ if (!rlast) {
71600+ rtmp->prev = NULL;
71601+ rolep->allowed_ips = rtmp;
71602+ } else {
71603+ rlast->next = rtmp;
71604+ rtmp->prev = rlast;
71605+ }
71606+
71607+ if (!ruserip)
71608+ rtmp->next = NULL;
71609+ }
71610+
71611+ return 0;
71612+}
71613+
71614+static int
71615+copy_user_transitions(struct acl_role_label *rolep)
71616+{
71617+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71618+ int error;
71619+
71620+ rusertp = rolep->transitions;
71621+
71622+ while (rusertp) {
71623+ rlast = rtmp;
71624+
71625+ if ((rtmp = (struct role_transition *)
71626+ acl_alloc(sizeof (struct role_transition))) == NULL)
71627+ return -ENOMEM;
71628+
71629+ if (copy_role_transition(rtmp, rusertp))
71630+ return -EFAULT;
71631+
71632+ rusertp = rtmp->prev;
71633+
71634+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71635+ if (error)
71636+ return error;
71637+
71638+ if (!rlast) {
71639+ rtmp->prev = NULL;
71640+ rolep->transitions = rtmp;
71641+ } else {
71642+ rlast->next = rtmp;
71643+ rtmp->prev = rlast;
71644+ }
71645+
71646+ if (!rusertp)
71647+ rtmp->next = NULL;
71648+ }
71649+
71650+ return 0;
71651+}
71652+
71653+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71654+{
71655+ struct acl_object_label o_tmp;
71656+ __u32 num = 0;
71657+
71658+ while (userp) {
71659+ if (copy_acl_object_label(&o_tmp, userp))
71660+ break;
71661+
71662+ userp = o_tmp.prev;
71663+ num++;
71664+ }
71665+
71666+ return num;
71667+}
71668+
71669+static struct acl_subject_label *
71670+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71671+{
71672+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71673+ __u32 num_objs;
71674+ struct acl_ip_label **i_tmp, *i_utmp2;
71675+ struct gr_hash_struct ghash;
71676+ struct subject_map *subjmap;
71677+ unsigned int i_num;
71678+ int err;
71679+
71680+ if (already_copied != NULL)
71681+ *already_copied = 0;
71682+
71683+ s_tmp = lookup_subject_map(userp);
71684+
71685+ /* we've already copied this subject into the kernel, just return
71686+ the reference to it, and don't copy it over again
71687+ */
71688+ if (s_tmp) {
71689+ if (already_copied != NULL)
71690+ *already_copied = 1;
71691+ return(s_tmp);
71692+ }
71693+
71694+ if ((s_tmp = (struct acl_subject_label *)
71695+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71696+ return ERR_PTR(-ENOMEM);
71697+
71698+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71699+ if (subjmap == NULL)
71700+ return ERR_PTR(-ENOMEM);
71701+
71702+ subjmap->user = userp;
71703+ subjmap->kernel = s_tmp;
71704+ insert_subj_map_entry(subjmap);
71705+
71706+ if (copy_acl_subject_label(s_tmp, userp))
71707+ return ERR_PTR(-EFAULT);
71708+
71709+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71710+ if (err)
71711+ return ERR_PTR(err);
71712+
71713+ if (!strcmp(s_tmp->filename, "/"))
71714+ role->root_label = s_tmp;
71715+
71716+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71717+ return ERR_PTR(-EFAULT);
71718+
71719+ /* copy user and group transition tables */
71720+
71721+ if (s_tmp->user_trans_num) {
71722+ uid_t *uidlist;
71723+
71724+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71725+ if (uidlist == NULL)
71726+ return ERR_PTR(-ENOMEM);
71727+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71728+ return ERR_PTR(-EFAULT);
71729+
71730+ s_tmp->user_transitions = uidlist;
71731+ }
71732+
71733+ if (s_tmp->group_trans_num) {
71734+ gid_t *gidlist;
71735+
71736+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71737+ if (gidlist == NULL)
71738+ return ERR_PTR(-ENOMEM);
71739+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71740+ return ERR_PTR(-EFAULT);
71741+
71742+ s_tmp->group_transitions = gidlist;
71743+ }
71744+
71745+ /* set up object hash table */
71746+ num_objs = count_user_objs(ghash.first);
71747+
71748+ s_tmp->obj_hash_size = num_objs;
71749+ s_tmp->obj_hash =
71750+ (struct acl_object_label **)
71751+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71752+
71753+ if (!s_tmp->obj_hash)
71754+ return ERR_PTR(-ENOMEM);
71755+
71756+ memset(s_tmp->obj_hash, 0,
71757+ s_tmp->obj_hash_size *
71758+ sizeof (struct acl_object_label *));
71759+
71760+ /* add in objects */
71761+ err = copy_user_objs(ghash.first, s_tmp, role);
71762+
71763+ if (err)
71764+ return ERR_PTR(err);
71765+
71766+ /* set pointer for parent subject */
71767+ if (s_tmp->parent_subject) {
71768+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71769+
71770+ if (IS_ERR(s_tmp2))
71771+ return s_tmp2;
71772+
71773+ s_tmp->parent_subject = s_tmp2;
71774+ }
71775+
71776+ /* add in ip acls */
71777+
71778+ if (!s_tmp->ip_num) {
71779+ s_tmp->ips = NULL;
71780+ goto insert;
71781+ }
71782+
71783+ i_tmp =
71784+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71785+ sizeof (struct acl_ip_label *));
71786+
71787+ if (!i_tmp)
71788+ return ERR_PTR(-ENOMEM);
71789+
71790+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71791+ *(i_tmp + i_num) =
71792+ (struct acl_ip_label *)
71793+ acl_alloc(sizeof (struct acl_ip_label));
71794+ if (!*(i_tmp + i_num))
71795+ return ERR_PTR(-ENOMEM);
71796+
71797+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71798+ return ERR_PTR(-EFAULT);
71799+
71800+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71801+ return ERR_PTR(-EFAULT);
71802+
71803+ if ((*(i_tmp + i_num))->iface == NULL)
71804+ continue;
71805+
71806+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71807+ if (err)
71808+ return ERR_PTR(err);
71809+ }
71810+
71811+ s_tmp->ips = i_tmp;
71812+
71813+insert:
71814+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71815+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71816+ return ERR_PTR(-ENOMEM);
71817+
71818+ return s_tmp;
71819+}
71820+
71821+static int
71822+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71823+{
71824+ struct acl_subject_label s_pre;
71825+ struct acl_subject_label * ret;
71826+ int err;
71827+
71828+ while (userp) {
71829+ if (copy_acl_subject_label(&s_pre, userp))
71830+ return -EFAULT;
71831+
71832+ ret = do_copy_user_subj(userp, role, NULL);
71833+
71834+ err = PTR_ERR(ret);
71835+ if (IS_ERR(ret))
71836+ return err;
71837+
71838+ insert_acl_subj_label(ret, role);
71839+
71840+ userp = s_pre.prev;
71841+ }
71842+
71843+ return 0;
71844+}
71845+
71846+static int
71847+copy_user_acl(struct gr_arg *arg)
71848+{
71849+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71850+ struct acl_subject_label *subj_list;
71851+ struct sprole_pw *sptmp;
71852+ struct gr_hash_struct *ghash;
71853+ uid_t *domainlist;
71854+ unsigned int r_num;
71855+ int err = 0;
71856+ __u16 i;
71857+ __u32 num_subjs;
71858+
71859+ /* we need a default and kernel role */
71860+ if (arg->role_db.num_roles < 2)
71861+ return -EINVAL;
71862+
71863+ /* copy special role authentication info from userspace */
71864+
71865+ polstate->num_sprole_pws = arg->num_sprole_pws;
71866+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71867+
71868+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71869+ return -ENOMEM;
71870+
71871+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71872+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71873+ if (!sptmp)
71874+ return -ENOMEM;
71875+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71876+ return -EFAULT;
71877+
71878+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71879+ if (err)
71880+ return err;
71881+
71882+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71883+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71884+#endif
71885+
71886+ polstate->acl_special_roles[i] = sptmp;
71887+ }
71888+
71889+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71890+
71891+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71892+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
71893+
71894+ if (!r_tmp)
71895+ return -ENOMEM;
71896+
71897+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71898+ return -EFAULT;
71899+
71900+ if (copy_acl_role_label(r_tmp, r_utmp2))
71901+ return -EFAULT;
71902+
71903+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71904+ if (err)
71905+ return err;
71906+
71907+ if (!strcmp(r_tmp->rolename, "default")
71908+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71909+ polstate->default_role = r_tmp;
71910+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71911+ polstate->kernel_role = r_tmp;
71912+ }
71913+
71914+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71915+ return -ENOMEM;
71916+
71917+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
71918+ return -EFAULT;
71919+
71920+ r_tmp->hash = ghash;
71921+
71922+ num_subjs = count_user_subjs(r_tmp->hash->first);
71923+
71924+ r_tmp->subj_hash_size = num_subjs;
71925+ r_tmp->subj_hash =
71926+ (struct acl_subject_label **)
71927+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71928+
71929+ if (!r_tmp->subj_hash)
71930+ return -ENOMEM;
71931+
71932+ err = copy_user_allowedips(r_tmp);
71933+ if (err)
71934+ return err;
71935+
71936+ /* copy domain info */
71937+ if (r_tmp->domain_children != NULL) {
71938+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71939+ if (domainlist == NULL)
71940+ return -ENOMEM;
71941+
71942+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71943+ return -EFAULT;
71944+
71945+ r_tmp->domain_children = domainlist;
71946+ }
71947+
71948+ err = copy_user_transitions(r_tmp);
71949+ if (err)
71950+ return err;
71951+
71952+ memset(r_tmp->subj_hash, 0,
71953+ r_tmp->subj_hash_size *
71954+ sizeof (struct acl_subject_label *));
71955+
71956+ /* acquire the list of subjects, then NULL out
71957+ the list prior to parsing the subjects for this role,
71958+ as during this parsing the list is replaced with a list
71959+ of *nested* subjects for the role
71960+ */
71961+ subj_list = r_tmp->hash->first;
71962+
71963+ /* set nested subject list to null */
71964+ r_tmp->hash->first = NULL;
71965+
71966+ err = copy_user_subjs(subj_list, r_tmp);
71967+
71968+ if (err)
71969+ return err;
71970+
71971+ insert_acl_role_label(r_tmp);
71972+ }
71973+
71974+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71975+ return -EINVAL;
71976+
71977+ return err;
71978+}
71979+
71980+static int gracl_reload_apply_policies(void *reload)
71981+{
71982+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71983+ struct task_struct *task, *task2;
71984+ struct acl_role_label *role, *rtmp;
71985+ struct acl_subject_label *subj;
71986+ const struct cred *cred;
71987+ int role_applied;
71988+ int ret = 0;
71989+
71990+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71991+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71992+
71993+ /* first make sure we'll be able to apply the new policy cleanly */
71994+ do_each_thread(task2, task) {
71995+ if (task->exec_file == NULL)
71996+ continue;
71997+ role_applied = 0;
71998+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71999+ /* preserve special roles */
72000+ FOR_EACH_ROLE_START(role)
72001+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72002+ rtmp = task->role;
72003+ task->role = role;
72004+ role_applied = 1;
72005+ break;
72006+ }
72007+ FOR_EACH_ROLE_END(role)
72008+ }
72009+ if (!role_applied) {
72010+ cred = __task_cred(task);
72011+ rtmp = task->role;
72012+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72013+ }
72014+ /* this handles non-nested inherited subjects, nested subjects will still
72015+ be dropped currently */
72016+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72017+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72018+ /* change the role back so that we've made no modifications to the policy */
72019+ task->role = rtmp;
72020+
72021+ if (subj == NULL || task->tmpacl == NULL) {
72022+ ret = -EINVAL;
72023+ goto out;
72024+ }
72025+ } while_each_thread(task2, task);
72026+
72027+ /* now actually apply the policy */
72028+
72029+ do_each_thread(task2, task) {
72030+ if (task->exec_file) {
72031+ role_applied = 0;
72032+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72033+ /* preserve special roles */
72034+ FOR_EACH_ROLE_START(role)
72035+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72036+ task->role = role;
72037+ role_applied = 1;
72038+ break;
72039+ }
72040+ FOR_EACH_ROLE_END(role)
72041+ }
72042+ if (!role_applied) {
72043+ cred = __task_cred(task);
72044+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72045+ }
72046+ /* this handles non-nested inherited subjects, nested subjects will still
72047+ be dropped currently */
72048+ if (!reload_state->oldmode && task->inherited)
72049+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72050+ else {
72051+ /* looked up and tagged to the task previously */
72052+ subj = task->tmpacl;
72053+ }
72054+ /* subj will be non-null */
72055+ __gr_apply_subject_to_task(polstate, task, subj);
72056+ if (reload_state->oldmode) {
72057+ task->acl_role_id = 0;
72058+ task->acl_sp_role = 0;
72059+ task->inherited = 0;
72060+ }
72061+ } else {
72062+ // it's a kernel process
72063+ task->role = polstate->kernel_role;
72064+ task->acl = polstate->kernel_role->root_label;
72065+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72066+ task->acl->mode &= ~GR_PROCFIND;
72067+#endif
72068+ }
72069+ } while_each_thread(task2, task);
72070+
72071+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72072+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72073+
72074+out:
72075+
72076+ return ret;
72077+}
72078+
72079+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72080+{
72081+ struct gr_reload_state new_reload_state = { };
72082+ int err;
72083+
72084+ new_reload_state.oldpolicy_ptr = polstate;
72085+ new_reload_state.oldalloc_ptr = current_alloc_state;
72086+ new_reload_state.oldmode = oldmode;
72087+
72088+ current_alloc_state = &new_reload_state.newalloc;
72089+ polstate = &new_reload_state.newpolicy;
72090+
72091+ /* everything relevant is now saved off, copy in the new policy */
72092+ if (init_variables(args, true)) {
72093+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72094+ err = -ENOMEM;
72095+ goto error;
72096+ }
72097+
72098+ err = copy_user_acl(args);
72099+ free_init_variables();
72100+ if (err)
72101+ goto error;
72102+ /* the new policy is copied in, with the old policy available via saved_state
72103+ first go through applying roles, making sure to preserve special roles
72104+ then apply new subjects, making sure to preserve inherited and nested subjects,
72105+ though currently only inherited subjects will be preserved
72106+ */
72107+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72108+ if (err)
72109+ goto error;
72110+
72111+ /* we've now applied the new policy, so restore the old policy state to free it */
72112+ polstate = &new_reload_state.oldpolicy;
72113+ current_alloc_state = &new_reload_state.oldalloc;
72114+ free_variables(true);
72115+
72116+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72117+ to running_polstate/current_alloc_state inside stop_machine
72118+ */
72119+ err = 0;
72120+ goto out;
72121+error:
72122+ /* on error of loading the new policy, we'll just keep the previous
72123+ policy set around
72124+ */
72125+ free_variables(true);
72126+
72127+ /* doesn't affect runtime, but maintains consistent state */
72128+out:
72129+ polstate = new_reload_state.oldpolicy_ptr;
72130+ current_alloc_state = new_reload_state.oldalloc_ptr;
72131+
72132+ return err;
72133+}
72134+
72135+static int
72136+gracl_init(struct gr_arg *args)
72137+{
72138+ int error = 0;
72139+
72140+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72141+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72142+
72143+ if (init_variables(args, false)) {
72144+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72145+ error = -ENOMEM;
72146+ goto out;
72147+ }
72148+
72149+ error = copy_user_acl(args);
72150+ free_init_variables();
72151+ if (error)
72152+ goto out;
72153+
72154+ error = gr_set_acls(0);
72155+ if (error)
72156+ goto out;
72157+
72158+ gr_enable_rbac_system();
72159+
72160+ return 0;
72161+
72162+out:
72163+ free_variables(false);
72164+ return error;
72165+}
72166+
72167+static int
72168+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72169+ unsigned char **sum)
72170+{
72171+ struct acl_role_label *r;
72172+ struct role_allowed_ip *ipp;
72173+ struct role_transition *trans;
72174+ unsigned int i;
72175+ int found = 0;
72176+ u32 curr_ip = current->signal->curr_ip;
72177+
72178+ current->signal->saved_ip = curr_ip;
72179+
72180+ /* check transition table */
72181+
72182+ for (trans = current->role->transitions; trans; trans = trans->next) {
72183+ if (!strcmp(rolename, trans->rolename)) {
72184+ found = 1;
72185+ break;
72186+ }
72187+ }
72188+
72189+ if (!found)
72190+ return 0;
72191+
72192+ /* handle special roles that do not require authentication
72193+ and check ip */
72194+
72195+ FOR_EACH_ROLE_START(r)
72196+ if (!strcmp(rolename, r->rolename) &&
72197+ (r->roletype & GR_ROLE_SPECIAL)) {
72198+ found = 0;
72199+ if (r->allowed_ips != NULL) {
72200+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72201+ if ((ntohl(curr_ip) & ipp->netmask) ==
72202+ (ntohl(ipp->addr) & ipp->netmask))
72203+ found = 1;
72204+ }
72205+ } else
72206+ found = 2;
72207+ if (!found)
72208+ return 0;
72209+
72210+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72211+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72212+ *salt = NULL;
72213+ *sum = NULL;
72214+ return 1;
72215+ }
72216+ }
72217+ FOR_EACH_ROLE_END(r)
72218+
72219+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72220+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72221+ *salt = polstate->acl_special_roles[i]->salt;
72222+ *sum = polstate->acl_special_roles[i]->sum;
72223+ return 1;
72224+ }
72225+ }
72226+
72227+ return 0;
72228+}
72229+
72230+int gr_check_secure_terminal(struct task_struct *task)
72231+{
72232+ struct task_struct *p, *p2, *p3;
72233+ struct files_struct *files;
72234+ struct fdtable *fdt;
72235+ struct file *our_file = NULL, *file;
72236+ int i;
72237+
72238+ if (task->signal->tty == NULL)
72239+ return 1;
72240+
72241+ files = get_files_struct(task);
72242+ if (files != NULL) {
72243+ rcu_read_lock();
72244+ fdt = files_fdtable(files);
72245+ for (i=0; i < fdt->max_fds; i++) {
72246+ file = fcheck_files(files, i);
72247+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72248+ get_file(file);
72249+ our_file = file;
72250+ }
72251+ }
72252+ rcu_read_unlock();
72253+ put_files_struct(files);
72254+ }
72255+
72256+ if (our_file == NULL)
72257+ return 1;
72258+
72259+ read_lock(&tasklist_lock);
72260+ do_each_thread(p2, p) {
72261+ files = get_files_struct(p);
72262+ if (files == NULL ||
72263+ (p->signal && p->signal->tty == task->signal->tty)) {
72264+ if (files != NULL)
72265+ put_files_struct(files);
72266+ continue;
72267+ }
72268+ rcu_read_lock();
72269+ fdt = files_fdtable(files);
72270+ for (i=0; i < fdt->max_fds; i++) {
72271+ file = fcheck_files(files, i);
72272+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72273+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72274+ p3 = task;
72275+ while (task_pid_nr(p3) > 0) {
72276+ if (p3 == p)
72277+ break;
72278+ p3 = p3->real_parent;
72279+ }
72280+ if (p3 == p)
72281+ break;
72282+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72283+ gr_handle_alertkill(p);
72284+ rcu_read_unlock();
72285+ put_files_struct(files);
72286+ read_unlock(&tasklist_lock);
72287+ fput(our_file);
72288+ return 0;
72289+ }
72290+ }
72291+ rcu_read_unlock();
72292+ put_files_struct(files);
72293+ } while_each_thread(p2, p);
72294+ read_unlock(&tasklist_lock);
72295+
72296+ fput(our_file);
72297+ return 1;
72298+}
72299+
72300+ssize_t
72301+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72302+{
72303+ struct gr_arg_wrapper uwrap;
72304+ unsigned char *sprole_salt = NULL;
72305+ unsigned char *sprole_sum = NULL;
72306+ int error = 0;
72307+ int error2 = 0;
72308+ size_t req_count = 0;
72309+ unsigned char oldmode = 0;
72310+
72311+ mutex_lock(&gr_dev_mutex);
72312+
72313+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72314+ error = -EPERM;
72315+ goto out;
72316+ }
72317+
72318+#ifdef CONFIG_COMPAT
72319+ pax_open_kernel();
72320+ if (is_compat_task()) {
72321+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72322+ copy_gr_arg = &copy_gr_arg_compat;
72323+ copy_acl_object_label = &copy_acl_object_label_compat;
72324+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72325+ copy_acl_role_label = &copy_acl_role_label_compat;
72326+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72327+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72328+ copy_role_transition = &copy_role_transition_compat;
72329+ copy_sprole_pw = &copy_sprole_pw_compat;
72330+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72331+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72332+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72333+ } else {
72334+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72335+ copy_gr_arg = &copy_gr_arg_normal;
72336+ copy_acl_object_label = &copy_acl_object_label_normal;
72337+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72338+ copy_acl_role_label = &copy_acl_role_label_normal;
72339+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72340+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72341+ copy_role_transition = &copy_role_transition_normal;
72342+ copy_sprole_pw = &copy_sprole_pw_normal;
72343+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72344+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72345+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72346+ }
72347+ pax_close_kernel();
72348+#endif
72349+
72350+ req_count = get_gr_arg_wrapper_size();
72351+
72352+ if (count != req_count) {
72353+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72354+ error = -EINVAL;
72355+ goto out;
72356+ }
72357+
72358+
72359+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72360+ gr_auth_expires = 0;
72361+ gr_auth_attempts = 0;
72362+ }
72363+
72364+ error = copy_gr_arg_wrapper(buf, &uwrap);
72365+ if (error)
72366+ goto out;
72367+
72368+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72369+ if (error)
72370+ goto out;
72371+
72372+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72373+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72374+ time_after(gr_auth_expires, get_seconds())) {
72375+ error = -EBUSY;
72376+ goto out;
72377+ }
72378+
72379+ /* if non-root trying to do anything other than use a special role,
72380+ do not attempt authentication, do not count towards authentication
72381+ locking
72382+ */
72383+
72384+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72385+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72386+ gr_is_global_nonroot(current_uid())) {
72387+ error = -EPERM;
72388+ goto out;
72389+ }
72390+
72391+ /* ensure pw and special role name are null terminated */
72392+
72393+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72394+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72395+
72396+ /* Okay.
72397+ * We have our enough of the argument structure..(we have yet
72398+ * to copy_from_user the tables themselves) . Copy the tables
72399+ * only if we need them, i.e. for loading operations. */
72400+
72401+ switch (gr_usermode.mode) {
72402+ case GR_STATUS:
72403+ if (gr_acl_is_enabled()) {
72404+ error = 1;
72405+ if (!gr_check_secure_terminal(current))
72406+ error = 3;
72407+ } else
72408+ error = 2;
72409+ goto out;
72410+ case GR_SHUTDOWN:
72411+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72412+ stop_machine(gr_rbac_disable, NULL, NULL);
72413+ free_variables(false);
72414+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72415+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72416+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72417+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72418+ } else if (gr_acl_is_enabled()) {
72419+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72420+ error = -EPERM;
72421+ } else {
72422+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72423+ error = -EAGAIN;
72424+ }
72425+ break;
72426+ case GR_ENABLE:
72427+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72428+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72429+ else {
72430+ if (gr_acl_is_enabled())
72431+ error = -EAGAIN;
72432+ else
72433+ error = error2;
72434+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72435+ }
72436+ break;
72437+ case GR_OLDRELOAD:
72438+ oldmode = 1;
72439+ case GR_RELOAD:
72440+ if (!gr_acl_is_enabled()) {
72441+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72442+ error = -EAGAIN;
72443+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72444+ error2 = gracl_reload(&gr_usermode, oldmode);
72445+ if (!error2)
72446+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72447+ else {
72448+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72449+ error = error2;
72450+ }
72451+ } else {
72452+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72453+ error = -EPERM;
72454+ }
72455+ break;
72456+ case GR_SEGVMOD:
72457+ if (unlikely(!gr_acl_is_enabled())) {
72458+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72459+ error = -EAGAIN;
72460+ break;
72461+ }
72462+
72463+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72464+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72465+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72466+ struct acl_subject_label *segvacl;
72467+ segvacl =
72468+ lookup_acl_subj_label(gr_usermode.segv_inode,
72469+ gr_usermode.segv_device,
72470+ current->role);
72471+ if (segvacl) {
72472+ segvacl->crashes = 0;
72473+ segvacl->expires = 0;
72474+ }
72475+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72476+ gr_remove_uid(gr_usermode.segv_uid);
72477+ }
72478+ } else {
72479+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72480+ error = -EPERM;
72481+ }
72482+ break;
72483+ case GR_SPROLE:
72484+ case GR_SPROLEPAM:
72485+ if (unlikely(!gr_acl_is_enabled())) {
72486+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72487+ error = -EAGAIN;
72488+ break;
72489+ }
72490+
72491+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72492+ current->role->expires = 0;
72493+ current->role->auth_attempts = 0;
72494+ }
72495+
72496+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72497+ time_after(current->role->expires, get_seconds())) {
72498+ error = -EBUSY;
72499+ goto out;
72500+ }
72501+
72502+ if (lookup_special_role_auth
72503+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72504+ && ((!sprole_salt && !sprole_sum)
72505+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72506+ char *p = "";
72507+ assign_special_role(gr_usermode.sp_role);
72508+ read_lock(&tasklist_lock);
72509+ if (current->real_parent)
72510+ p = current->real_parent->role->rolename;
72511+ read_unlock(&tasklist_lock);
72512+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72513+ p, acl_sp_role_value);
72514+ } else {
72515+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72516+ error = -EPERM;
72517+ if(!(current->role->auth_attempts++))
72518+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72519+
72520+ goto out;
72521+ }
72522+ break;
72523+ case GR_UNSPROLE:
72524+ if (unlikely(!gr_acl_is_enabled())) {
72525+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72526+ error = -EAGAIN;
72527+ break;
72528+ }
72529+
72530+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72531+ char *p = "";
72532+ int i = 0;
72533+
72534+ read_lock(&tasklist_lock);
72535+ if (current->real_parent) {
72536+ p = current->real_parent->role->rolename;
72537+ i = current->real_parent->acl_role_id;
72538+ }
72539+ read_unlock(&tasklist_lock);
72540+
72541+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72542+ gr_set_acls(1);
72543+ } else {
72544+ error = -EPERM;
72545+ goto out;
72546+ }
72547+ break;
72548+ default:
72549+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72550+ error = -EINVAL;
72551+ break;
72552+ }
72553+
72554+ if (error != -EPERM)
72555+ goto out;
72556+
72557+ if(!(gr_auth_attempts++))
72558+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72559+
72560+ out:
72561+ mutex_unlock(&gr_dev_mutex);
72562+
72563+ if (!error)
72564+ error = req_count;
72565+
72566+ return error;
72567+}
72568+
72569+int
72570+gr_set_acls(const int type)
72571+{
72572+ struct task_struct *task, *task2;
72573+ struct acl_role_label *role = current->role;
72574+ struct acl_subject_label *subj;
72575+ __u16 acl_role_id = current->acl_role_id;
72576+ const struct cred *cred;
72577+ int ret;
72578+
72579+ rcu_read_lock();
72580+ read_lock(&tasklist_lock);
72581+ read_lock(&grsec_exec_file_lock);
72582+ do_each_thread(task2, task) {
72583+ /* check to see if we're called from the exit handler,
72584+ if so, only replace ACLs that have inherited the admin
72585+ ACL */
72586+
72587+ if (type && (task->role != role ||
72588+ task->acl_role_id != acl_role_id))
72589+ continue;
72590+
72591+ task->acl_role_id = 0;
72592+ task->acl_sp_role = 0;
72593+ task->inherited = 0;
72594+
72595+ if (task->exec_file) {
72596+ cred = __task_cred(task);
72597+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72598+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72599+ if (subj == NULL) {
72600+ ret = -EINVAL;
72601+ read_unlock(&grsec_exec_file_lock);
72602+ read_unlock(&tasklist_lock);
72603+ rcu_read_unlock();
72604+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72605+ return ret;
72606+ }
72607+ __gr_apply_subject_to_task(polstate, task, subj);
72608+ } else {
72609+ // it's a kernel process
72610+ task->role = polstate->kernel_role;
72611+ task->acl = polstate->kernel_role->root_label;
72612+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72613+ task->acl->mode &= ~GR_PROCFIND;
72614+#endif
72615+ }
72616+ } while_each_thread(task2, task);
72617+ read_unlock(&grsec_exec_file_lock);
72618+ read_unlock(&tasklist_lock);
72619+ rcu_read_unlock();
72620+
72621+ return 0;
72622+}
72623diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72624new file mode 100644
72625index 0000000..39645c9
72626--- /dev/null
72627+++ b/grsecurity/gracl_res.c
72628@@ -0,0 +1,68 @@
72629+#include <linux/kernel.h>
72630+#include <linux/sched.h>
72631+#include <linux/gracl.h>
72632+#include <linux/grinternal.h>
72633+
72634+static const char *restab_log[] = {
72635+ [RLIMIT_CPU] = "RLIMIT_CPU",
72636+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72637+ [RLIMIT_DATA] = "RLIMIT_DATA",
72638+ [RLIMIT_STACK] = "RLIMIT_STACK",
72639+ [RLIMIT_CORE] = "RLIMIT_CORE",
72640+ [RLIMIT_RSS] = "RLIMIT_RSS",
72641+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72642+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72643+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72644+ [RLIMIT_AS] = "RLIMIT_AS",
72645+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72646+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72647+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72648+ [RLIMIT_NICE] = "RLIMIT_NICE",
72649+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72650+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72651+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72652+};
72653+
72654+void
72655+gr_log_resource(const struct task_struct *task,
72656+ const int res, const unsigned long wanted, const int gt)
72657+{
72658+ const struct cred *cred;
72659+ unsigned long rlim;
72660+
72661+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72662+ return;
72663+
72664+ // not yet supported resource
72665+ if (unlikely(!restab_log[res]))
72666+ return;
72667+
72668+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72669+ rlim = task_rlimit_max(task, res);
72670+ else
72671+ rlim = task_rlimit(task, res);
72672+
72673+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72674+ return;
72675+
72676+ rcu_read_lock();
72677+ cred = __task_cred(task);
72678+
72679+ if (res == RLIMIT_NPROC &&
72680+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72681+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72682+ goto out_rcu_unlock;
72683+ else if (res == RLIMIT_MEMLOCK &&
72684+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72685+ goto out_rcu_unlock;
72686+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72687+ goto out_rcu_unlock;
72688+ rcu_read_unlock();
72689+
72690+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72691+
72692+ return;
72693+out_rcu_unlock:
72694+ rcu_read_unlock();
72695+ return;
72696+}
72697diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72698new file mode 100644
72699index 0000000..2040e61
72700--- /dev/null
72701+++ b/grsecurity/gracl_segv.c
72702@@ -0,0 +1,313 @@
72703+#include <linux/kernel.h>
72704+#include <linux/mm.h>
72705+#include <asm/uaccess.h>
72706+#include <asm/errno.h>
72707+#include <asm/mman.h>
72708+#include <net/sock.h>
72709+#include <linux/file.h>
72710+#include <linux/fs.h>
72711+#include <linux/net.h>
72712+#include <linux/in.h>
72713+#include <linux/slab.h>
72714+#include <linux/types.h>
72715+#include <linux/sched.h>
72716+#include <linux/timer.h>
72717+#include <linux/gracl.h>
72718+#include <linux/grsecurity.h>
72719+#include <linux/grinternal.h>
72720+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72721+#include <linux/magic.h>
72722+#include <linux/pagemap.h>
72723+#include "../fs/btrfs/async-thread.h"
72724+#include "../fs/btrfs/ctree.h"
72725+#include "../fs/btrfs/btrfs_inode.h"
72726+#endif
72727+
72728+static struct crash_uid *uid_set;
72729+static unsigned short uid_used;
72730+static DEFINE_SPINLOCK(gr_uid_lock);
72731+extern rwlock_t gr_inode_lock;
72732+extern struct acl_subject_label *
72733+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72734+ struct acl_role_label *role);
72735+
72736+static inline dev_t __get_dev(const struct dentry *dentry)
72737+{
72738+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72739+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72740+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72741+ else
72742+#endif
72743+ return dentry->d_sb->s_dev;
72744+}
72745+
72746+int
72747+gr_init_uidset(void)
72748+{
72749+ uid_set =
72750+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72751+ uid_used = 0;
72752+
72753+ return uid_set ? 1 : 0;
72754+}
72755+
72756+void
72757+gr_free_uidset(void)
72758+{
72759+ if (uid_set) {
72760+ struct crash_uid *tmpset;
72761+ spin_lock(&gr_uid_lock);
72762+ tmpset = uid_set;
72763+ uid_set = NULL;
72764+ uid_used = 0;
72765+ spin_unlock(&gr_uid_lock);
72766+ if (tmpset)
72767+ kfree(tmpset);
72768+ }
72769+
72770+ return;
72771+}
72772+
72773+int
72774+gr_find_uid(const uid_t uid)
72775+{
72776+ struct crash_uid *tmp = uid_set;
72777+ uid_t buid;
72778+ int low = 0, high = uid_used - 1, mid;
72779+
72780+ while (high >= low) {
72781+ mid = (low + high) >> 1;
72782+ buid = tmp[mid].uid;
72783+ if (buid == uid)
72784+ return mid;
72785+ if (buid > uid)
72786+ high = mid - 1;
72787+ if (buid < uid)
72788+ low = mid + 1;
72789+ }
72790+
72791+ return -1;
72792+}
72793+
72794+static __inline__ void
72795+gr_insertsort(void)
72796+{
72797+ unsigned short i, j;
72798+ struct crash_uid index;
72799+
72800+ for (i = 1; i < uid_used; i++) {
72801+ index = uid_set[i];
72802+ j = i;
72803+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72804+ uid_set[j] = uid_set[j - 1];
72805+ j--;
72806+ }
72807+ uid_set[j] = index;
72808+ }
72809+
72810+ return;
72811+}
72812+
72813+static __inline__ void
72814+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72815+{
72816+ int loc;
72817+ uid_t uid = GR_GLOBAL_UID(kuid);
72818+
72819+ if (uid_used == GR_UIDTABLE_MAX)
72820+ return;
72821+
72822+ loc = gr_find_uid(uid);
72823+
72824+ if (loc >= 0) {
72825+ uid_set[loc].expires = expires;
72826+ return;
72827+ }
72828+
72829+ uid_set[uid_used].uid = uid;
72830+ uid_set[uid_used].expires = expires;
72831+ uid_used++;
72832+
72833+ gr_insertsort();
72834+
72835+ return;
72836+}
72837+
72838+void
72839+gr_remove_uid(const unsigned short loc)
72840+{
72841+ unsigned short i;
72842+
72843+ for (i = loc + 1; i < uid_used; i++)
72844+ uid_set[i - 1] = uid_set[i];
72845+
72846+ uid_used--;
72847+
72848+ return;
72849+}
72850+
72851+int
72852+gr_check_crash_uid(const kuid_t kuid)
72853+{
72854+ int loc;
72855+ int ret = 0;
72856+ uid_t uid;
72857+
72858+ if (unlikely(!gr_acl_is_enabled()))
72859+ return 0;
72860+
72861+ uid = GR_GLOBAL_UID(kuid);
72862+
72863+ spin_lock(&gr_uid_lock);
72864+ loc = gr_find_uid(uid);
72865+
72866+ if (loc < 0)
72867+ goto out_unlock;
72868+
72869+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
72870+ gr_remove_uid(loc);
72871+ else
72872+ ret = 1;
72873+
72874+out_unlock:
72875+ spin_unlock(&gr_uid_lock);
72876+ return ret;
72877+}
72878+
72879+static __inline__ int
72880+proc_is_setxid(const struct cred *cred)
72881+{
72882+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72883+ !uid_eq(cred->uid, cred->fsuid))
72884+ return 1;
72885+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72886+ !gid_eq(cred->gid, cred->fsgid))
72887+ return 1;
72888+
72889+ return 0;
72890+}
72891+
72892+extern int gr_fake_force_sig(int sig, struct task_struct *t);
72893+
72894+void
72895+gr_handle_crash(struct task_struct *task, const int sig)
72896+{
72897+ struct acl_subject_label *curr;
72898+ struct task_struct *tsk, *tsk2;
72899+ const struct cred *cred;
72900+ const struct cred *cred2;
72901+
72902+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72903+ return;
72904+
72905+ if (unlikely(!gr_acl_is_enabled()))
72906+ return;
72907+
72908+ curr = task->acl;
72909+
72910+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
72911+ return;
72912+
72913+ if (time_before_eq(curr->expires, get_seconds())) {
72914+ curr->expires = 0;
72915+ curr->crashes = 0;
72916+ }
72917+
72918+ curr->crashes++;
72919+
72920+ if (!curr->expires)
72921+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72922+
72923+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72924+ time_after(curr->expires, get_seconds())) {
72925+ rcu_read_lock();
72926+ cred = __task_cred(task);
72927+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72928+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72929+ spin_lock(&gr_uid_lock);
72930+ gr_insert_uid(cred->uid, curr->expires);
72931+ spin_unlock(&gr_uid_lock);
72932+ curr->expires = 0;
72933+ curr->crashes = 0;
72934+ read_lock(&tasklist_lock);
72935+ do_each_thread(tsk2, tsk) {
72936+ cred2 = __task_cred(tsk);
72937+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
72938+ gr_fake_force_sig(SIGKILL, tsk);
72939+ } while_each_thread(tsk2, tsk);
72940+ read_unlock(&tasklist_lock);
72941+ } else {
72942+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72943+ read_lock(&tasklist_lock);
72944+ read_lock(&grsec_exec_file_lock);
72945+ do_each_thread(tsk2, tsk) {
72946+ if (likely(tsk != task)) {
72947+ // if this thread has the same subject as the one that triggered
72948+ // RES_CRASH and it's the same binary, kill it
72949+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72950+ gr_fake_force_sig(SIGKILL, tsk);
72951+ }
72952+ } while_each_thread(tsk2, tsk);
72953+ read_unlock(&grsec_exec_file_lock);
72954+ read_unlock(&tasklist_lock);
72955+ }
72956+ rcu_read_unlock();
72957+ }
72958+
72959+ return;
72960+}
72961+
72962+int
72963+gr_check_crash_exec(const struct file *filp)
72964+{
72965+ struct acl_subject_label *curr;
72966+
72967+ if (unlikely(!gr_acl_is_enabled()))
72968+ return 0;
72969+
72970+ read_lock(&gr_inode_lock);
72971+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72972+ __get_dev(filp->f_path.dentry),
72973+ current->role);
72974+ read_unlock(&gr_inode_lock);
72975+
72976+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72977+ (!curr->crashes && !curr->expires))
72978+ return 0;
72979+
72980+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72981+ time_after(curr->expires, get_seconds()))
72982+ return 1;
72983+ else if (time_before_eq(curr->expires, get_seconds())) {
72984+ curr->crashes = 0;
72985+ curr->expires = 0;
72986+ }
72987+
72988+ return 0;
72989+}
72990+
72991+void
72992+gr_handle_alertkill(struct task_struct *task)
72993+{
72994+ struct acl_subject_label *curracl;
72995+ __u32 curr_ip;
72996+ struct task_struct *p, *p2;
72997+
72998+ if (unlikely(!gr_acl_is_enabled()))
72999+ return;
73000+
73001+ curracl = task->acl;
73002+ curr_ip = task->signal->curr_ip;
73003+
73004+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73005+ read_lock(&tasklist_lock);
73006+ do_each_thread(p2, p) {
73007+ if (p->signal->curr_ip == curr_ip)
73008+ gr_fake_force_sig(SIGKILL, p);
73009+ } while_each_thread(p2, p);
73010+ read_unlock(&tasklist_lock);
73011+ } else if (curracl->mode & GR_KILLPROC)
73012+ gr_fake_force_sig(SIGKILL, task);
73013+
73014+ return;
73015+}
73016diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73017new file mode 100644
73018index 0000000..98011b0
73019--- /dev/null
73020+++ b/grsecurity/gracl_shm.c
73021@@ -0,0 +1,40 @@
73022+#include <linux/kernel.h>
73023+#include <linux/mm.h>
73024+#include <linux/sched.h>
73025+#include <linux/file.h>
73026+#include <linux/ipc.h>
73027+#include <linux/gracl.h>
73028+#include <linux/grsecurity.h>
73029+#include <linux/grinternal.h>
73030+
73031+int
73032+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73033+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73034+{
73035+ struct task_struct *task;
73036+
73037+ if (!gr_acl_is_enabled())
73038+ return 1;
73039+
73040+ rcu_read_lock();
73041+ read_lock(&tasklist_lock);
73042+
73043+ task = find_task_by_vpid(shm_cprid);
73044+
73045+ if (unlikely(!task))
73046+ task = find_task_by_vpid(shm_lapid);
73047+
73048+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73049+ (task_pid_nr(task) == shm_lapid)) &&
73050+ (task->acl->mode & GR_PROTSHM) &&
73051+ (task->acl != current->acl))) {
73052+ read_unlock(&tasklist_lock);
73053+ rcu_read_unlock();
73054+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73055+ return 0;
73056+ }
73057+ read_unlock(&tasklist_lock);
73058+ rcu_read_unlock();
73059+
73060+ return 1;
73061+}
73062diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73063new file mode 100644
73064index 0000000..bc0be01
73065--- /dev/null
73066+++ b/grsecurity/grsec_chdir.c
73067@@ -0,0 +1,19 @@
73068+#include <linux/kernel.h>
73069+#include <linux/sched.h>
73070+#include <linux/fs.h>
73071+#include <linux/file.h>
73072+#include <linux/grsecurity.h>
73073+#include <linux/grinternal.h>
73074+
73075+void
73076+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73077+{
73078+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73079+ if ((grsec_enable_chdir && grsec_enable_group &&
73080+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73081+ !grsec_enable_group)) {
73082+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73083+ }
73084+#endif
73085+ return;
73086+}
73087diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73088new file mode 100644
73089index 0000000..651d6c2
73090--- /dev/null
73091+++ b/grsecurity/grsec_chroot.c
73092@@ -0,0 +1,370 @@
73093+#include <linux/kernel.h>
73094+#include <linux/module.h>
73095+#include <linux/sched.h>
73096+#include <linux/file.h>
73097+#include <linux/fs.h>
73098+#include <linux/mount.h>
73099+#include <linux/types.h>
73100+#include "../fs/mount.h"
73101+#include <linux/grsecurity.h>
73102+#include <linux/grinternal.h>
73103+
73104+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73105+int gr_init_ran;
73106+#endif
73107+
73108+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73109+{
73110+#ifdef CONFIG_GRKERNSEC
73111+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73112+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73113+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73114+ && gr_init_ran
73115+#endif
73116+ )
73117+ task->gr_is_chrooted = 1;
73118+ else {
73119+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73120+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73121+ gr_init_ran = 1;
73122+#endif
73123+ task->gr_is_chrooted = 0;
73124+ }
73125+
73126+ task->gr_chroot_dentry = path->dentry;
73127+#endif
73128+ return;
73129+}
73130+
73131+void gr_clear_chroot_entries(struct task_struct *task)
73132+{
73133+#ifdef CONFIG_GRKERNSEC
73134+ task->gr_is_chrooted = 0;
73135+ task->gr_chroot_dentry = NULL;
73136+#endif
73137+ return;
73138+}
73139+
73140+int
73141+gr_handle_chroot_unix(const pid_t pid)
73142+{
73143+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73144+ struct task_struct *p;
73145+
73146+ if (unlikely(!grsec_enable_chroot_unix))
73147+ return 1;
73148+
73149+ if (likely(!proc_is_chrooted(current)))
73150+ return 1;
73151+
73152+ rcu_read_lock();
73153+ read_lock(&tasklist_lock);
73154+ p = find_task_by_vpid_unrestricted(pid);
73155+ if (unlikely(p && !have_same_root(current, p))) {
73156+ read_unlock(&tasklist_lock);
73157+ rcu_read_unlock();
73158+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73159+ return 0;
73160+ }
73161+ read_unlock(&tasklist_lock);
73162+ rcu_read_unlock();
73163+#endif
73164+ return 1;
73165+}
73166+
73167+int
73168+gr_handle_chroot_nice(void)
73169+{
73170+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73171+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73172+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73173+ return -EPERM;
73174+ }
73175+#endif
73176+ return 0;
73177+}
73178+
73179+int
73180+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73181+{
73182+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73183+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73184+ && proc_is_chrooted(current)) {
73185+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73186+ return -EACCES;
73187+ }
73188+#endif
73189+ return 0;
73190+}
73191+
73192+int
73193+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73194+{
73195+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73196+ struct task_struct *p;
73197+ int ret = 0;
73198+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73199+ return ret;
73200+
73201+ read_lock(&tasklist_lock);
73202+ do_each_pid_task(pid, type, p) {
73203+ if (!have_same_root(current, p)) {
73204+ ret = 1;
73205+ goto out;
73206+ }
73207+ } while_each_pid_task(pid, type, p);
73208+out:
73209+ read_unlock(&tasklist_lock);
73210+ return ret;
73211+#endif
73212+ return 0;
73213+}
73214+
73215+int
73216+gr_pid_is_chrooted(struct task_struct *p)
73217+{
73218+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73219+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73220+ return 0;
73221+
73222+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73223+ !have_same_root(current, p)) {
73224+ return 1;
73225+ }
73226+#endif
73227+ return 0;
73228+}
73229+
73230+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73231+
73232+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73233+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73234+{
73235+ struct path path, currentroot;
73236+ int ret = 0;
73237+
73238+ path.dentry = (struct dentry *)u_dentry;
73239+ path.mnt = (struct vfsmount *)u_mnt;
73240+ get_fs_root(current->fs, &currentroot);
73241+ if (path_is_under(&path, &currentroot))
73242+ ret = 1;
73243+ path_put(&currentroot);
73244+
73245+ return ret;
73246+}
73247+#endif
73248+
73249+int
73250+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73251+{
73252+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73253+ if (!grsec_enable_chroot_fchdir)
73254+ return 1;
73255+
73256+ if (!proc_is_chrooted(current))
73257+ return 1;
73258+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73259+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73260+ return 0;
73261+ }
73262+#endif
73263+ return 1;
73264+}
73265+
73266+int
73267+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73268+ const time_t shm_createtime)
73269+{
73270+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73271+ struct task_struct *p;
73272+ time_t starttime;
73273+
73274+ if (unlikely(!grsec_enable_chroot_shmat))
73275+ return 1;
73276+
73277+ if (likely(!proc_is_chrooted(current)))
73278+ return 1;
73279+
73280+ rcu_read_lock();
73281+ read_lock(&tasklist_lock);
73282+
73283+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73284+ starttime = p->start_time.tv_sec;
73285+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73286+ if (have_same_root(current, p)) {
73287+ goto allow;
73288+ } else {
73289+ read_unlock(&tasklist_lock);
73290+ rcu_read_unlock();
73291+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73292+ return 0;
73293+ }
73294+ }
73295+ /* creator exited, pid reuse, fall through to next check */
73296+ }
73297+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73298+ if (unlikely(!have_same_root(current, p))) {
73299+ read_unlock(&tasklist_lock);
73300+ rcu_read_unlock();
73301+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73302+ return 0;
73303+ }
73304+ }
73305+
73306+allow:
73307+ read_unlock(&tasklist_lock);
73308+ rcu_read_unlock();
73309+#endif
73310+ return 1;
73311+}
73312+
73313+void
73314+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73315+{
73316+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73317+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73318+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73319+#endif
73320+ return;
73321+}
73322+
73323+int
73324+gr_handle_chroot_mknod(const struct dentry *dentry,
73325+ const struct vfsmount *mnt, const int mode)
73326+{
73327+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73328+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73329+ proc_is_chrooted(current)) {
73330+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73331+ return -EPERM;
73332+ }
73333+#endif
73334+ return 0;
73335+}
73336+
73337+int
73338+gr_handle_chroot_mount(const struct dentry *dentry,
73339+ const struct vfsmount *mnt, const char *dev_name)
73340+{
73341+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73342+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73343+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73344+ return -EPERM;
73345+ }
73346+#endif
73347+ return 0;
73348+}
73349+
73350+int
73351+gr_handle_chroot_pivot(void)
73352+{
73353+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73354+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73355+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73356+ return -EPERM;
73357+ }
73358+#endif
73359+ return 0;
73360+}
73361+
73362+int
73363+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73364+{
73365+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73366+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73367+ !gr_is_outside_chroot(dentry, mnt)) {
73368+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73369+ return -EPERM;
73370+ }
73371+#endif
73372+ return 0;
73373+}
73374+
73375+extern const char *captab_log[];
73376+extern int captab_log_entries;
73377+
73378+int
73379+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73380+{
73381+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73382+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73383+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73384+ if (cap_raised(chroot_caps, cap)) {
73385+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73386+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73387+ }
73388+ return 0;
73389+ }
73390+ }
73391+#endif
73392+ return 1;
73393+}
73394+
73395+int
73396+gr_chroot_is_capable(const int cap)
73397+{
73398+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73399+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73400+#endif
73401+ return 1;
73402+}
73403+
73404+int
73405+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73406+{
73407+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73408+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73409+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73410+ if (cap_raised(chroot_caps, cap)) {
73411+ return 0;
73412+ }
73413+ }
73414+#endif
73415+ return 1;
73416+}
73417+
73418+int
73419+gr_chroot_is_capable_nolog(const int cap)
73420+{
73421+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73422+ return gr_task_chroot_is_capable_nolog(current, cap);
73423+#endif
73424+ return 1;
73425+}
73426+
73427+int
73428+gr_handle_chroot_sysctl(const int op)
73429+{
73430+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73431+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73432+ proc_is_chrooted(current))
73433+ return -EACCES;
73434+#endif
73435+ return 0;
73436+}
73437+
73438+void
73439+gr_handle_chroot_chdir(const struct path *path)
73440+{
73441+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73442+ if (grsec_enable_chroot_chdir)
73443+ set_fs_pwd(current->fs, path);
73444+#endif
73445+ return;
73446+}
73447+
73448+int
73449+gr_handle_chroot_chmod(const struct dentry *dentry,
73450+ const struct vfsmount *mnt, const int mode)
73451+{
73452+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73453+ /* allow chmod +s on directories, but not files */
73454+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73455+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73456+ proc_is_chrooted(current)) {
73457+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73458+ return -EPERM;
73459+ }
73460+#endif
73461+ return 0;
73462+}
73463diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73464new file mode 100644
73465index 0000000..4d6fce8
73466--- /dev/null
73467+++ b/grsecurity/grsec_disabled.c
73468@@ -0,0 +1,433 @@
73469+#include <linux/kernel.h>
73470+#include <linux/module.h>
73471+#include <linux/sched.h>
73472+#include <linux/file.h>
73473+#include <linux/fs.h>
73474+#include <linux/kdev_t.h>
73475+#include <linux/net.h>
73476+#include <linux/in.h>
73477+#include <linux/ip.h>
73478+#include <linux/skbuff.h>
73479+#include <linux/sysctl.h>
73480+
73481+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73482+void
73483+pax_set_initial_flags(struct linux_binprm *bprm)
73484+{
73485+ return;
73486+}
73487+#endif
73488+
73489+#ifdef CONFIG_SYSCTL
73490+__u32
73491+gr_handle_sysctl(const struct ctl_table * table, const int op)
73492+{
73493+ return 0;
73494+}
73495+#endif
73496+
73497+#ifdef CONFIG_TASKSTATS
73498+int gr_is_taskstats_denied(int pid)
73499+{
73500+ return 0;
73501+}
73502+#endif
73503+
73504+int
73505+gr_acl_is_enabled(void)
73506+{
73507+ return 0;
73508+}
73509+
73510+void
73511+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73512+{
73513+ return;
73514+}
73515+
73516+int
73517+gr_handle_rawio(const struct inode *inode)
73518+{
73519+ return 0;
73520+}
73521+
73522+void
73523+gr_acl_handle_psacct(struct task_struct *task, const long code)
73524+{
73525+ return;
73526+}
73527+
73528+int
73529+gr_handle_ptrace(struct task_struct *task, const long request)
73530+{
73531+ return 0;
73532+}
73533+
73534+int
73535+gr_handle_proc_ptrace(struct task_struct *task)
73536+{
73537+ return 0;
73538+}
73539+
73540+int
73541+gr_set_acls(const int type)
73542+{
73543+ return 0;
73544+}
73545+
73546+int
73547+gr_check_hidden_task(const struct task_struct *tsk)
73548+{
73549+ return 0;
73550+}
73551+
73552+int
73553+gr_check_protected_task(const struct task_struct *task)
73554+{
73555+ return 0;
73556+}
73557+
73558+int
73559+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73560+{
73561+ return 0;
73562+}
73563+
73564+void
73565+gr_copy_label(struct task_struct *tsk)
73566+{
73567+ return;
73568+}
73569+
73570+void
73571+gr_set_pax_flags(struct task_struct *task)
73572+{
73573+ return;
73574+}
73575+
73576+int
73577+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73578+ const int unsafe_share)
73579+{
73580+ return 0;
73581+}
73582+
73583+void
73584+gr_handle_delete(const ino_t ino, const dev_t dev)
73585+{
73586+ return;
73587+}
73588+
73589+void
73590+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73591+{
73592+ return;
73593+}
73594+
73595+void
73596+gr_handle_crash(struct task_struct *task, const int sig)
73597+{
73598+ return;
73599+}
73600+
73601+int
73602+gr_check_crash_exec(const struct file *filp)
73603+{
73604+ return 0;
73605+}
73606+
73607+int
73608+gr_check_crash_uid(const kuid_t uid)
73609+{
73610+ return 0;
73611+}
73612+
73613+void
73614+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73615+ struct dentry *old_dentry,
73616+ struct dentry *new_dentry,
73617+ struct vfsmount *mnt, const __u8 replace)
73618+{
73619+ return;
73620+}
73621+
73622+int
73623+gr_search_socket(const int family, const int type, const int protocol)
73624+{
73625+ return 1;
73626+}
73627+
73628+int
73629+gr_search_connectbind(const int mode, const struct socket *sock,
73630+ const struct sockaddr_in *addr)
73631+{
73632+ return 0;
73633+}
73634+
73635+void
73636+gr_handle_alertkill(struct task_struct *task)
73637+{
73638+ return;
73639+}
73640+
73641+__u32
73642+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73643+{
73644+ return 1;
73645+}
73646+
73647+__u32
73648+gr_acl_handle_hidden_file(const struct dentry * dentry,
73649+ const struct vfsmount * mnt)
73650+{
73651+ return 1;
73652+}
73653+
73654+__u32
73655+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73656+ int acc_mode)
73657+{
73658+ return 1;
73659+}
73660+
73661+__u32
73662+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73663+{
73664+ return 1;
73665+}
73666+
73667+__u32
73668+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73669+{
73670+ return 1;
73671+}
73672+
73673+int
73674+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73675+ unsigned int *vm_flags)
73676+{
73677+ return 1;
73678+}
73679+
73680+__u32
73681+gr_acl_handle_truncate(const struct dentry * dentry,
73682+ const struct vfsmount * mnt)
73683+{
73684+ return 1;
73685+}
73686+
73687+__u32
73688+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73689+{
73690+ return 1;
73691+}
73692+
73693+__u32
73694+gr_acl_handle_access(const struct dentry * dentry,
73695+ const struct vfsmount * mnt, const int fmode)
73696+{
73697+ return 1;
73698+}
73699+
73700+__u32
73701+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73702+ umode_t *mode)
73703+{
73704+ return 1;
73705+}
73706+
73707+__u32
73708+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73709+{
73710+ return 1;
73711+}
73712+
73713+__u32
73714+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73715+{
73716+ return 1;
73717+}
73718+
73719+__u32
73720+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73721+{
73722+ return 1;
73723+}
73724+
73725+void
73726+grsecurity_init(void)
73727+{
73728+ return;
73729+}
73730+
73731+umode_t gr_acl_umask(void)
73732+{
73733+ return 0;
73734+}
73735+
73736+__u32
73737+gr_acl_handle_mknod(const struct dentry * new_dentry,
73738+ const struct dentry * parent_dentry,
73739+ const struct vfsmount * parent_mnt,
73740+ const int mode)
73741+{
73742+ return 1;
73743+}
73744+
73745+__u32
73746+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73747+ const struct dentry * parent_dentry,
73748+ const struct vfsmount * parent_mnt)
73749+{
73750+ return 1;
73751+}
73752+
73753+__u32
73754+gr_acl_handle_symlink(const struct dentry * new_dentry,
73755+ const struct dentry * parent_dentry,
73756+ const struct vfsmount * parent_mnt, const struct filename *from)
73757+{
73758+ return 1;
73759+}
73760+
73761+__u32
73762+gr_acl_handle_link(const struct dentry * new_dentry,
73763+ const struct dentry * parent_dentry,
73764+ const struct vfsmount * parent_mnt,
73765+ const struct dentry * old_dentry,
73766+ const struct vfsmount * old_mnt, const struct filename *to)
73767+{
73768+ return 1;
73769+}
73770+
73771+int
73772+gr_acl_handle_rename(const struct dentry *new_dentry,
73773+ const struct dentry *parent_dentry,
73774+ const struct vfsmount *parent_mnt,
73775+ const struct dentry *old_dentry,
73776+ const struct inode *old_parent_inode,
73777+ const struct vfsmount *old_mnt, const struct filename *newname)
73778+{
73779+ return 0;
73780+}
73781+
73782+int
73783+gr_acl_handle_filldir(const struct file *file, const char *name,
73784+ const int namelen, const ino_t ino)
73785+{
73786+ return 1;
73787+}
73788+
73789+int
73790+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73791+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73792+{
73793+ return 1;
73794+}
73795+
73796+int
73797+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73798+{
73799+ return 0;
73800+}
73801+
73802+int
73803+gr_search_accept(const struct socket *sock)
73804+{
73805+ return 0;
73806+}
73807+
73808+int
73809+gr_search_listen(const struct socket *sock)
73810+{
73811+ return 0;
73812+}
73813+
73814+int
73815+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73816+{
73817+ return 0;
73818+}
73819+
73820+__u32
73821+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73822+{
73823+ return 1;
73824+}
73825+
73826+__u32
73827+gr_acl_handle_creat(const struct dentry * dentry,
73828+ const struct dentry * p_dentry,
73829+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73830+ const int imode)
73831+{
73832+ return 1;
73833+}
73834+
73835+void
73836+gr_acl_handle_exit(void)
73837+{
73838+ return;
73839+}
73840+
73841+int
73842+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73843+{
73844+ return 1;
73845+}
73846+
73847+void
73848+gr_set_role_label(const kuid_t uid, const kgid_t gid)
73849+{
73850+ return;
73851+}
73852+
73853+int
73854+gr_acl_handle_procpidmem(const struct task_struct *task)
73855+{
73856+ return 0;
73857+}
73858+
73859+int
73860+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73861+{
73862+ return 0;
73863+}
73864+
73865+int
73866+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73867+{
73868+ return 0;
73869+}
73870+
73871+int
73872+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73873+{
73874+ return 0;
73875+}
73876+
73877+int
73878+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73879+{
73880+ return 0;
73881+}
73882+
73883+int gr_acl_enable_at_secure(void)
73884+{
73885+ return 0;
73886+}
73887+
73888+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73889+{
73890+ return dentry->d_sb->s_dev;
73891+}
73892+
73893+void gr_put_exec_file(struct task_struct *task)
73894+{
73895+ return;
73896+}
73897+
73898+#ifdef CONFIG_SECURITY
73899+EXPORT_SYMBOL_GPL(gr_check_user_change);
73900+EXPORT_SYMBOL_GPL(gr_check_group_change);
73901+#endif
73902diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73903new file mode 100644
73904index 0000000..f35f454
73905--- /dev/null
73906+++ b/grsecurity/grsec_exec.c
73907@@ -0,0 +1,187 @@
73908+#include <linux/kernel.h>
73909+#include <linux/sched.h>
73910+#include <linux/file.h>
73911+#include <linux/binfmts.h>
73912+#include <linux/fs.h>
73913+#include <linux/types.h>
73914+#include <linux/grdefs.h>
73915+#include <linux/grsecurity.h>
73916+#include <linux/grinternal.h>
73917+#include <linux/capability.h>
73918+#include <linux/module.h>
73919+#include <linux/compat.h>
73920+
73921+#include <asm/uaccess.h>
73922+
73923+#ifdef CONFIG_GRKERNSEC_EXECLOG
73924+static char gr_exec_arg_buf[132];
73925+static DEFINE_MUTEX(gr_exec_arg_mutex);
73926+#endif
73927+
73928+struct user_arg_ptr {
73929+#ifdef CONFIG_COMPAT
73930+ bool is_compat;
73931+#endif
73932+ union {
73933+ const char __user *const __user *native;
73934+#ifdef CONFIG_COMPAT
73935+ const compat_uptr_t __user *compat;
73936+#endif
73937+ } ptr;
73938+};
73939+
73940+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73941+
73942+void
73943+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73944+{
73945+#ifdef CONFIG_GRKERNSEC_EXECLOG
73946+ char *grarg = gr_exec_arg_buf;
73947+ unsigned int i, x, execlen = 0;
73948+ char c;
73949+
73950+ if (!((grsec_enable_execlog && grsec_enable_group &&
73951+ in_group_p(grsec_audit_gid))
73952+ || (grsec_enable_execlog && !grsec_enable_group)))
73953+ return;
73954+
73955+ mutex_lock(&gr_exec_arg_mutex);
73956+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
73957+
73958+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
73959+ const char __user *p;
73960+ unsigned int len;
73961+
73962+ p = get_user_arg_ptr(argv, i);
73963+ if (IS_ERR(p))
73964+ goto log;
73965+
73966+ len = strnlen_user(p, 128 - execlen);
73967+ if (len > 128 - execlen)
73968+ len = 128 - execlen;
73969+ else if (len > 0)
73970+ len--;
73971+ if (copy_from_user(grarg + execlen, p, len))
73972+ goto log;
73973+
73974+ /* rewrite unprintable characters */
73975+ for (x = 0; x < len; x++) {
73976+ c = *(grarg + execlen + x);
73977+ if (c < 32 || c > 126)
73978+ *(grarg + execlen + x) = ' ';
73979+ }
73980+
73981+ execlen += len;
73982+ *(grarg + execlen) = ' ';
73983+ *(grarg + execlen + 1) = '\0';
73984+ execlen++;
73985+ }
73986+
73987+ log:
73988+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73989+ bprm->file->f_path.mnt, grarg);
73990+ mutex_unlock(&gr_exec_arg_mutex);
73991+#endif
73992+ return;
73993+}
73994+
73995+#ifdef CONFIG_GRKERNSEC
73996+extern int gr_acl_is_capable(const int cap);
73997+extern int gr_acl_is_capable_nolog(const int cap);
73998+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73999+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74000+extern int gr_chroot_is_capable(const int cap);
74001+extern int gr_chroot_is_capable_nolog(const int cap);
74002+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74003+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74004+#endif
74005+
74006+const char *captab_log[] = {
74007+ "CAP_CHOWN",
74008+ "CAP_DAC_OVERRIDE",
74009+ "CAP_DAC_READ_SEARCH",
74010+ "CAP_FOWNER",
74011+ "CAP_FSETID",
74012+ "CAP_KILL",
74013+ "CAP_SETGID",
74014+ "CAP_SETUID",
74015+ "CAP_SETPCAP",
74016+ "CAP_LINUX_IMMUTABLE",
74017+ "CAP_NET_BIND_SERVICE",
74018+ "CAP_NET_BROADCAST",
74019+ "CAP_NET_ADMIN",
74020+ "CAP_NET_RAW",
74021+ "CAP_IPC_LOCK",
74022+ "CAP_IPC_OWNER",
74023+ "CAP_SYS_MODULE",
74024+ "CAP_SYS_RAWIO",
74025+ "CAP_SYS_CHROOT",
74026+ "CAP_SYS_PTRACE",
74027+ "CAP_SYS_PACCT",
74028+ "CAP_SYS_ADMIN",
74029+ "CAP_SYS_BOOT",
74030+ "CAP_SYS_NICE",
74031+ "CAP_SYS_RESOURCE",
74032+ "CAP_SYS_TIME",
74033+ "CAP_SYS_TTY_CONFIG",
74034+ "CAP_MKNOD",
74035+ "CAP_LEASE",
74036+ "CAP_AUDIT_WRITE",
74037+ "CAP_AUDIT_CONTROL",
74038+ "CAP_SETFCAP",
74039+ "CAP_MAC_OVERRIDE",
74040+ "CAP_MAC_ADMIN",
74041+ "CAP_SYSLOG",
74042+ "CAP_WAKE_ALARM"
74043+};
74044+
74045+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74046+
74047+int gr_is_capable(const int cap)
74048+{
74049+#ifdef CONFIG_GRKERNSEC
74050+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74051+ return 1;
74052+ return 0;
74053+#else
74054+ return 1;
74055+#endif
74056+}
74057+
74058+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74059+{
74060+#ifdef CONFIG_GRKERNSEC
74061+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74062+ return 1;
74063+ return 0;
74064+#else
74065+ return 1;
74066+#endif
74067+}
74068+
74069+int gr_is_capable_nolog(const int cap)
74070+{
74071+#ifdef CONFIG_GRKERNSEC
74072+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74073+ return 1;
74074+ return 0;
74075+#else
74076+ return 1;
74077+#endif
74078+}
74079+
74080+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74081+{
74082+#ifdef CONFIG_GRKERNSEC
74083+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74084+ return 1;
74085+ return 0;
74086+#else
74087+ return 1;
74088+#endif
74089+}
74090+
74091+EXPORT_SYMBOL_GPL(gr_is_capable);
74092+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74093+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74094+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74095diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74096new file mode 100644
74097index 0000000..06cc6ea
74098--- /dev/null
74099+++ b/grsecurity/grsec_fifo.c
74100@@ -0,0 +1,24 @@
74101+#include <linux/kernel.h>
74102+#include <linux/sched.h>
74103+#include <linux/fs.h>
74104+#include <linux/file.h>
74105+#include <linux/grinternal.h>
74106+
74107+int
74108+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74109+ const struct dentry *dir, const int flag, const int acc_mode)
74110+{
74111+#ifdef CONFIG_GRKERNSEC_FIFO
74112+ const struct cred *cred = current_cred();
74113+
74114+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74115+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74116+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74117+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74118+ if (!inode_permission(dentry->d_inode, acc_mode))
74119+ 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));
74120+ return -EACCES;
74121+ }
74122+#endif
74123+ return 0;
74124+}
74125diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74126new file mode 100644
74127index 0000000..8ca18bf
74128--- /dev/null
74129+++ b/grsecurity/grsec_fork.c
74130@@ -0,0 +1,23 @@
74131+#include <linux/kernel.h>
74132+#include <linux/sched.h>
74133+#include <linux/grsecurity.h>
74134+#include <linux/grinternal.h>
74135+#include <linux/errno.h>
74136+
74137+void
74138+gr_log_forkfail(const int retval)
74139+{
74140+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74141+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74142+ switch (retval) {
74143+ case -EAGAIN:
74144+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74145+ break;
74146+ case -ENOMEM:
74147+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74148+ break;
74149+ }
74150+ }
74151+#endif
74152+ return;
74153+}
74154diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74155new file mode 100644
74156index 0000000..ae6c028
74157--- /dev/null
74158+++ b/grsecurity/grsec_init.c
74159@@ -0,0 +1,272 @@
74160+#include <linux/kernel.h>
74161+#include <linux/sched.h>
74162+#include <linux/mm.h>
74163+#include <linux/gracl.h>
74164+#include <linux/slab.h>
74165+#include <linux/vmalloc.h>
74166+#include <linux/percpu.h>
74167+#include <linux/module.h>
74168+
74169+int grsec_enable_ptrace_readexec;
74170+int grsec_enable_setxid;
74171+int grsec_enable_symlinkown;
74172+kgid_t grsec_symlinkown_gid;
74173+int grsec_enable_brute;
74174+int grsec_enable_link;
74175+int grsec_enable_dmesg;
74176+int grsec_enable_harden_ptrace;
74177+int grsec_enable_harden_ipc;
74178+int grsec_enable_fifo;
74179+int grsec_enable_execlog;
74180+int grsec_enable_signal;
74181+int grsec_enable_forkfail;
74182+int grsec_enable_audit_ptrace;
74183+int grsec_enable_time;
74184+int grsec_enable_group;
74185+kgid_t grsec_audit_gid;
74186+int grsec_enable_chdir;
74187+int grsec_enable_mount;
74188+int grsec_enable_rofs;
74189+int grsec_deny_new_usb;
74190+int grsec_enable_chroot_findtask;
74191+int grsec_enable_chroot_mount;
74192+int grsec_enable_chroot_shmat;
74193+int grsec_enable_chroot_fchdir;
74194+int grsec_enable_chroot_double;
74195+int grsec_enable_chroot_pivot;
74196+int grsec_enable_chroot_chdir;
74197+int grsec_enable_chroot_chmod;
74198+int grsec_enable_chroot_mknod;
74199+int grsec_enable_chroot_nice;
74200+int grsec_enable_chroot_execlog;
74201+int grsec_enable_chroot_caps;
74202+int grsec_enable_chroot_sysctl;
74203+int grsec_enable_chroot_unix;
74204+int grsec_enable_tpe;
74205+kgid_t grsec_tpe_gid;
74206+int grsec_enable_blackhole;
74207+#ifdef CONFIG_IPV6_MODULE
74208+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74209+#endif
74210+int grsec_lastack_retries;
74211+int grsec_enable_tpe_all;
74212+int grsec_enable_tpe_invert;
74213+int grsec_enable_socket_all;
74214+kgid_t grsec_socket_all_gid;
74215+int grsec_enable_socket_client;
74216+kgid_t grsec_socket_client_gid;
74217+int grsec_enable_socket_server;
74218+kgid_t grsec_socket_server_gid;
74219+int grsec_resource_logging;
74220+int grsec_disable_privio;
74221+int grsec_enable_log_rwxmaps;
74222+int grsec_lock;
74223+
74224+DEFINE_SPINLOCK(grsec_alert_lock);
74225+unsigned long grsec_alert_wtime = 0;
74226+unsigned long grsec_alert_fyet = 0;
74227+
74228+DEFINE_SPINLOCK(grsec_audit_lock);
74229+
74230+DEFINE_RWLOCK(grsec_exec_file_lock);
74231+
74232+char *gr_shared_page[4];
74233+
74234+char *gr_alert_log_fmt;
74235+char *gr_audit_log_fmt;
74236+char *gr_alert_log_buf;
74237+char *gr_audit_log_buf;
74238+
74239+void __init
74240+grsecurity_init(void)
74241+{
74242+ int j;
74243+ /* create the per-cpu shared pages */
74244+
74245+#ifdef CONFIG_X86
74246+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74247+#endif
74248+
74249+ for (j = 0; j < 4; j++) {
74250+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74251+ if (gr_shared_page[j] == NULL) {
74252+ panic("Unable to allocate grsecurity shared page");
74253+ return;
74254+ }
74255+ }
74256+
74257+ /* allocate log buffers */
74258+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74259+ if (!gr_alert_log_fmt) {
74260+ panic("Unable to allocate grsecurity alert log format buffer");
74261+ return;
74262+ }
74263+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74264+ if (!gr_audit_log_fmt) {
74265+ panic("Unable to allocate grsecurity audit log format buffer");
74266+ return;
74267+ }
74268+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74269+ if (!gr_alert_log_buf) {
74270+ panic("Unable to allocate grsecurity alert log buffer");
74271+ return;
74272+ }
74273+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74274+ if (!gr_audit_log_buf) {
74275+ panic("Unable to allocate grsecurity audit log buffer");
74276+ return;
74277+ }
74278+
74279+#ifdef CONFIG_GRKERNSEC_IO
74280+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74281+ grsec_disable_privio = 1;
74282+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74283+ grsec_disable_privio = 1;
74284+#else
74285+ grsec_disable_privio = 0;
74286+#endif
74287+#endif
74288+
74289+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74290+ /* for backward compatibility, tpe_invert always defaults to on if
74291+ enabled in the kernel
74292+ */
74293+ grsec_enable_tpe_invert = 1;
74294+#endif
74295+
74296+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74297+#ifndef CONFIG_GRKERNSEC_SYSCTL
74298+ grsec_lock = 1;
74299+#endif
74300+
74301+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74302+ grsec_enable_log_rwxmaps = 1;
74303+#endif
74304+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74305+ grsec_enable_group = 1;
74306+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74307+#endif
74308+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74309+ grsec_enable_ptrace_readexec = 1;
74310+#endif
74311+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74312+ grsec_enable_chdir = 1;
74313+#endif
74314+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74315+ grsec_enable_harden_ptrace = 1;
74316+#endif
74317+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74318+ grsec_enable_harden_ipc = 1;
74319+#endif
74320+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74321+ grsec_enable_mount = 1;
74322+#endif
74323+#ifdef CONFIG_GRKERNSEC_LINK
74324+ grsec_enable_link = 1;
74325+#endif
74326+#ifdef CONFIG_GRKERNSEC_BRUTE
74327+ grsec_enable_brute = 1;
74328+#endif
74329+#ifdef CONFIG_GRKERNSEC_DMESG
74330+ grsec_enable_dmesg = 1;
74331+#endif
74332+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74333+ grsec_enable_blackhole = 1;
74334+ grsec_lastack_retries = 4;
74335+#endif
74336+#ifdef CONFIG_GRKERNSEC_FIFO
74337+ grsec_enable_fifo = 1;
74338+#endif
74339+#ifdef CONFIG_GRKERNSEC_EXECLOG
74340+ grsec_enable_execlog = 1;
74341+#endif
74342+#ifdef CONFIG_GRKERNSEC_SETXID
74343+ grsec_enable_setxid = 1;
74344+#endif
74345+#ifdef CONFIG_GRKERNSEC_SIGNAL
74346+ grsec_enable_signal = 1;
74347+#endif
74348+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74349+ grsec_enable_forkfail = 1;
74350+#endif
74351+#ifdef CONFIG_GRKERNSEC_TIME
74352+ grsec_enable_time = 1;
74353+#endif
74354+#ifdef CONFIG_GRKERNSEC_RESLOG
74355+ grsec_resource_logging = 1;
74356+#endif
74357+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74358+ grsec_enable_chroot_findtask = 1;
74359+#endif
74360+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74361+ grsec_enable_chroot_unix = 1;
74362+#endif
74363+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74364+ grsec_enable_chroot_mount = 1;
74365+#endif
74366+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74367+ grsec_enable_chroot_fchdir = 1;
74368+#endif
74369+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74370+ grsec_enable_chroot_shmat = 1;
74371+#endif
74372+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74373+ grsec_enable_audit_ptrace = 1;
74374+#endif
74375+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74376+ grsec_enable_chroot_double = 1;
74377+#endif
74378+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74379+ grsec_enable_chroot_pivot = 1;
74380+#endif
74381+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74382+ grsec_enable_chroot_chdir = 1;
74383+#endif
74384+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74385+ grsec_enable_chroot_chmod = 1;
74386+#endif
74387+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74388+ grsec_enable_chroot_mknod = 1;
74389+#endif
74390+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74391+ grsec_enable_chroot_nice = 1;
74392+#endif
74393+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74394+ grsec_enable_chroot_execlog = 1;
74395+#endif
74396+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74397+ grsec_enable_chroot_caps = 1;
74398+#endif
74399+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74400+ grsec_enable_chroot_sysctl = 1;
74401+#endif
74402+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74403+ grsec_enable_symlinkown = 1;
74404+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74405+#endif
74406+#ifdef CONFIG_GRKERNSEC_TPE
74407+ grsec_enable_tpe = 1;
74408+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74409+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74410+ grsec_enable_tpe_all = 1;
74411+#endif
74412+#endif
74413+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74414+ grsec_enable_socket_all = 1;
74415+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74416+#endif
74417+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74418+ grsec_enable_socket_client = 1;
74419+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74420+#endif
74421+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74422+ grsec_enable_socket_server = 1;
74423+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74424+#endif
74425+#endif
74426+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74427+ grsec_deny_new_usb = 1;
74428+#endif
74429+
74430+ return;
74431+}
74432diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74433new file mode 100644
74434index 0000000..1773300
74435--- /dev/null
74436+++ b/grsecurity/grsec_ipc.c
74437@@ -0,0 +1,48 @@
74438+#include <linux/kernel.h>
74439+#include <linux/mm.h>
74440+#include <linux/sched.h>
74441+#include <linux/file.h>
74442+#include <linux/ipc.h>
74443+#include <linux/ipc_namespace.h>
74444+#include <linux/grsecurity.h>
74445+#include <linux/grinternal.h>
74446+
74447+int
74448+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74449+{
74450+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74451+ int write;
74452+ int orig_granted_mode;
74453+ kuid_t euid;
74454+ kgid_t egid;
74455+
74456+ if (!grsec_enable_harden_ipc)
74457+ return 1;
74458+
74459+ euid = current_euid();
74460+ egid = current_egid();
74461+
74462+ write = requested_mode & 00002;
74463+ orig_granted_mode = ipcp->mode;
74464+
74465+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74466+ orig_granted_mode >>= 6;
74467+ else {
74468+ /* if likely wrong permissions, lock to user */
74469+ if (orig_granted_mode & 0007)
74470+ orig_granted_mode = 0;
74471+ /* otherwise do a egid-only check */
74472+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74473+ orig_granted_mode >>= 3;
74474+ /* otherwise, no access */
74475+ else
74476+ orig_granted_mode = 0;
74477+ }
74478+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74479+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74480+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74481+ return 0;
74482+ }
74483+#endif
74484+ return 1;
74485+}
74486diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74487new file mode 100644
74488index 0000000..5e05e20
74489--- /dev/null
74490+++ b/grsecurity/grsec_link.c
74491@@ -0,0 +1,58 @@
74492+#include <linux/kernel.h>
74493+#include <linux/sched.h>
74494+#include <linux/fs.h>
74495+#include <linux/file.h>
74496+#include <linux/grinternal.h>
74497+
74498+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74499+{
74500+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74501+ const struct inode *link_inode = link->dentry->d_inode;
74502+
74503+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74504+ /* ignore root-owned links, e.g. /proc/self */
74505+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74506+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74507+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74508+ return 1;
74509+ }
74510+#endif
74511+ return 0;
74512+}
74513+
74514+int
74515+gr_handle_follow_link(const struct inode *parent,
74516+ const struct inode *inode,
74517+ const struct dentry *dentry, const struct vfsmount *mnt)
74518+{
74519+#ifdef CONFIG_GRKERNSEC_LINK
74520+ const struct cred *cred = current_cred();
74521+
74522+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74523+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74524+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74525+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74526+ return -EACCES;
74527+ }
74528+#endif
74529+ return 0;
74530+}
74531+
74532+int
74533+gr_handle_hardlink(const struct dentry *dentry,
74534+ const struct vfsmount *mnt,
74535+ struct inode *inode, const int mode, const struct filename *to)
74536+{
74537+#ifdef CONFIG_GRKERNSEC_LINK
74538+ const struct cred *cred = current_cred();
74539+
74540+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74541+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74542+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74543+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74544+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74545+ return -EPERM;
74546+ }
74547+#endif
74548+ return 0;
74549+}
74550diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74551new file mode 100644
74552index 0000000..dbe0a6b
74553--- /dev/null
74554+++ b/grsecurity/grsec_log.c
74555@@ -0,0 +1,341 @@
74556+#include <linux/kernel.h>
74557+#include <linux/sched.h>
74558+#include <linux/file.h>
74559+#include <linux/tty.h>
74560+#include <linux/fs.h>
74561+#include <linux/mm.h>
74562+#include <linux/grinternal.h>
74563+
74564+#ifdef CONFIG_TREE_PREEMPT_RCU
74565+#define DISABLE_PREEMPT() preempt_disable()
74566+#define ENABLE_PREEMPT() preempt_enable()
74567+#else
74568+#define DISABLE_PREEMPT()
74569+#define ENABLE_PREEMPT()
74570+#endif
74571+
74572+#define BEGIN_LOCKS(x) \
74573+ DISABLE_PREEMPT(); \
74574+ rcu_read_lock(); \
74575+ read_lock(&tasklist_lock); \
74576+ read_lock(&grsec_exec_file_lock); \
74577+ if (x != GR_DO_AUDIT) \
74578+ spin_lock(&grsec_alert_lock); \
74579+ else \
74580+ spin_lock(&grsec_audit_lock)
74581+
74582+#define END_LOCKS(x) \
74583+ if (x != GR_DO_AUDIT) \
74584+ spin_unlock(&grsec_alert_lock); \
74585+ else \
74586+ spin_unlock(&grsec_audit_lock); \
74587+ read_unlock(&grsec_exec_file_lock); \
74588+ read_unlock(&tasklist_lock); \
74589+ rcu_read_unlock(); \
74590+ ENABLE_PREEMPT(); \
74591+ if (x == GR_DONT_AUDIT) \
74592+ gr_handle_alertkill(current)
74593+
74594+enum {
74595+ FLOODING,
74596+ NO_FLOODING
74597+};
74598+
74599+extern char *gr_alert_log_fmt;
74600+extern char *gr_audit_log_fmt;
74601+extern char *gr_alert_log_buf;
74602+extern char *gr_audit_log_buf;
74603+
74604+static int gr_log_start(int audit)
74605+{
74606+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74607+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74608+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74609+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74610+ unsigned long curr_secs = get_seconds();
74611+
74612+ if (audit == GR_DO_AUDIT)
74613+ goto set_fmt;
74614+
74615+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74616+ grsec_alert_wtime = curr_secs;
74617+ grsec_alert_fyet = 0;
74618+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74619+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74620+ grsec_alert_fyet++;
74621+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74622+ grsec_alert_wtime = curr_secs;
74623+ grsec_alert_fyet++;
74624+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74625+ return FLOODING;
74626+ }
74627+ else return FLOODING;
74628+
74629+set_fmt:
74630+#endif
74631+ memset(buf, 0, PAGE_SIZE);
74632+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74633+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74634+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74635+ } else if (current->signal->curr_ip) {
74636+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74637+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74638+ } else if (gr_acl_is_enabled()) {
74639+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74640+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74641+ } else {
74642+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74643+ strcpy(buf, fmt);
74644+ }
74645+
74646+ return NO_FLOODING;
74647+}
74648+
74649+static void gr_log_middle(int audit, const char *msg, va_list ap)
74650+ __attribute__ ((format (printf, 2, 0)));
74651+
74652+static void gr_log_middle(int audit, const char *msg, va_list ap)
74653+{
74654+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74655+ unsigned int len = strlen(buf);
74656+
74657+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74658+
74659+ return;
74660+}
74661+
74662+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74663+ __attribute__ ((format (printf, 2, 3)));
74664+
74665+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74666+{
74667+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74668+ unsigned int len = strlen(buf);
74669+ va_list ap;
74670+
74671+ va_start(ap, msg);
74672+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74673+ va_end(ap);
74674+
74675+ return;
74676+}
74677+
74678+static void gr_log_end(int audit, int append_default)
74679+{
74680+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74681+ if (append_default) {
74682+ struct task_struct *task = current;
74683+ struct task_struct *parent = task->real_parent;
74684+ const struct cred *cred = __task_cred(task);
74685+ const struct cred *pcred = __task_cred(parent);
74686+ unsigned int len = strlen(buf);
74687+
74688+ 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));
74689+ }
74690+
74691+ printk("%s\n", buf);
74692+
74693+ return;
74694+}
74695+
74696+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74697+{
74698+ int logtype;
74699+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74700+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74701+ void *voidptr = NULL;
74702+ int num1 = 0, num2 = 0;
74703+ unsigned long ulong1 = 0, ulong2 = 0;
74704+ struct dentry *dentry = NULL;
74705+ struct vfsmount *mnt = NULL;
74706+ struct file *file = NULL;
74707+ struct task_struct *task = NULL;
74708+ struct vm_area_struct *vma = NULL;
74709+ const struct cred *cred, *pcred;
74710+ va_list ap;
74711+
74712+ BEGIN_LOCKS(audit);
74713+ logtype = gr_log_start(audit);
74714+ if (logtype == FLOODING) {
74715+ END_LOCKS(audit);
74716+ return;
74717+ }
74718+ va_start(ap, argtypes);
74719+ switch (argtypes) {
74720+ case GR_TTYSNIFF:
74721+ task = va_arg(ap, struct task_struct *);
74722+ 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));
74723+ break;
74724+ case GR_SYSCTL_HIDDEN:
74725+ str1 = va_arg(ap, char *);
74726+ gr_log_middle_varargs(audit, msg, result, str1);
74727+ break;
74728+ case GR_RBAC:
74729+ dentry = va_arg(ap, struct dentry *);
74730+ mnt = va_arg(ap, struct vfsmount *);
74731+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74732+ break;
74733+ case GR_RBAC_STR:
74734+ dentry = va_arg(ap, struct dentry *);
74735+ mnt = va_arg(ap, struct vfsmount *);
74736+ str1 = va_arg(ap, char *);
74737+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74738+ break;
74739+ case GR_STR_RBAC:
74740+ str1 = va_arg(ap, char *);
74741+ dentry = va_arg(ap, struct dentry *);
74742+ mnt = va_arg(ap, struct vfsmount *);
74743+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74744+ break;
74745+ case GR_RBAC_MODE2:
74746+ dentry = va_arg(ap, struct dentry *);
74747+ mnt = va_arg(ap, struct vfsmount *);
74748+ str1 = va_arg(ap, char *);
74749+ str2 = va_arg(ap, char *);
74750+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74751+ break;
74752+ case GR_RBAC_MODE3:
74753+ dentry = va_arg(ap, struct dentry *);
74754+ mnt = va_arg(ap, struct vfsmount *);
74755+ str1 = va_arg(ap, char *);
74756+ str2 = va_arg(ap, char *);
74757+ str3 = va_arg(ap, char *);
74758+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74759+ break;
74760+ case GR_FILENAME:
74761+ dentry = va_arg(ap, struct dentry *);
74762+ mnt = va_arg(ap, struct vfsmount *);
74763+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74764+ break;
74765+ case GR_STR_FILENAME:
74766+ str1 = va_arg(ap, char *);
74767+ dentry = va_arg(ap, struct dentry *);
74768+ mnt = va_arg(ap, struct vfsmount *);
74769+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74770+ break;
74771+ case GR_FILENAME_STR:
74772+ dentry = va_arg(ap, struct dentry *);
74773+ mnt = va_arg(ap, struct vfsmount *);
74774+ str1 = va_arg(ap, char *);
74775+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74776+ break;
74777+ case GR_FILENAME_TWO_INT:
74778+ dentry = va_arg(ap, struct dentry *);
74779+ mnt = va_arg(ap, struct vfsmount *);
74780+ num1 = va_arg(ap, int);
74781+ num2 = va_arg(ap, int);
74782+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74783+ break;
74784+ case GR_FILENAME_TWO_INT_STR:
74785+ dentry = va_arg(ap, struct dentry *);
74786+ mnt = va_arg(ap, struct vfsmount *);
74787+ num1 = va_arg(ap, int);
74788+ num2 = va_arg(ap, int);
74789+ str1 = va_arg(ap, char *);
74790+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74791+ break;
74792+ case GR_TEXTREL:
74793+ file = va_arg(ap, struct file *);
74794+ ulong1 = va_arg(ap, unsigned long);
74795+ ulong2 = va_arg(ap, unsigned long);
74796+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74797+ break;
74798+ case GR_PTRACE:
74799+ task = va_arg(ap, struct task_struct *);
74800+ 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));
74801+ break;
74802+ case GR_RESOURCE:
74803+ task = va_arg(ap, struct task_struct *);
74804+ cred = __task_cred(task);
74805+ pcred = __task_cred(task->real_parent);
74806+ ulong1 = va_arg(ap, unsigned long);
74807+ str1 = va_arg(ap, char *);
74808+ ulong2 = va_arg(ap, unsigned long);
74809+ 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));
74810+ break;
74811+ case GR_CAP:
74812+ task = va_arg(ap, struct task_struct *);
74813+ cred = __task_cred(task);
74814+ pcred = __task_cred(task->real_parent);
74815+ str1 = va_arg(ap, char *);
74816+ 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));
74817+ break;
74818+ case GR_SIG:
74819+ str1 = va_arg(ap, char *);
74820+ voidptr = va_arg(ap, void *);
74821+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74822+ break;
74823+ case GR_SIG2:
74824+ task = va_arg(ap, struct task_struct *);
74825+ cred = __task_cred(task);
74826+ pcred = __task_cred(task->real_parent);
74827+ num1 = va_arg(ap, int);
74828+ 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));
74829+ break;
74830+ case GR_CRASH1:
74831+ task = va_arg(ap, struct task_struct *);
74832+ cred = __task_cred(task);
74833+ pcred = __task_cred(task->real_parent);
74834+ ulong1 = va_arg(ap, unsigned long);
74835+ 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);
74836+ break;
74837+ case GR_CRASH2:
74838+ task = va_arg(ap, struct task_struct *);
74839+ cred = __task_cred(task);
74840+ pcred = __task_cred(task->real_parent);
74841+ ulong1 = va_arg(ap, unsigned long);
74842+ 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);
74843+ break;
74844+ case GR_RWXMAP:
74845+ file = va_arg(ap, struct file *);
74846+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74847+ break;
74848+ case GR_RWXMAPVMA:
74849+ vma = va_arg(ap, struct vm_area_struct *);
74850+ if (vma->vm_file)
74851+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74852+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74853+ str1 = "<stack>";
74854+ else if (vma->vm_start <= current->mm->brk &&
74855+ vma->vm_end >= current->mm->start_brk)
74856+ str1 = "<heap>";
74857+ else
74858+ str1 = "<anonymous mapping>";
74859+ gr_log_middle_varargs(audit, msg, str1);
74860+ break;
74861+ case GR_PSACCT:
74862+ {
74863+ unsigned int wday, cday;
74864+ __u8 whr, chr;
74865+ __u8 wmin, cmin;
74866+ __u8 wsec, csec;
74867+ char cur_tty[64] = { 0 };
74868+ char parent_tty[64] = { 0 };
74869+
74870+ task = va_arg(ap, struct task_struct *);
74871+ wday = va_arg(ap, unsigned int);
74872+ cday = va_arg(ap, unsigned int);
74873+ whr = va_arg(ap, int);
74874+ chr = va_arg(ap, int);
74875+ wmin = va_arg(ap, int);
74876+ cmin = va_arg(ap, int);
74877+ wsec = va_arg(ap, int);
74878+ csec = va_arg(ap, int);
74879+ ulong1 = va_arg(ap, unsigned long);
74880+ cred = __task_cred(task);
74881+ pcred = __task_cred(task->real_parent);
74882+
74883+ 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));
74884+ }
74885+ break;
74886+ default:
74887+ gr_log_middle(audit, msg, ap);
74888+ }
74889+ va_end(ap);
74890+ // these don't need DEFAULTSECARGS printed on the end
74891+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74892+ gr_log_end(audit, 0);
74893+ else
74894+ gr_log_end(audit, 1);
74895+ END_LOCKS(audit);
74896+}
74897diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74898new file mode 100644
74899index 0000000..0e39d8c
74900--- /dev/null
74901+++ b/grsecurity/grsec_mem.c
74902@@ -0,0 +1,48 @@
74903+#include <linux/kernel.h>
74904+#include <linux/sched.h>
74905+#include <linux/mm.h>
74906+#include <linux/mman.h>
74907+#include <linux/module.h>
74908+#include <linux/grinternal.h>
74909+
74910+void gr_handle_msr_write(void)
74911+{
74912+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74913+ return;
74914+}
74915+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74916+
74917+void
74918+gr_handle_ioperm(void)
74919+{
74920+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74921+ return;
74922+}
74923+
74924+void
74925+gr_handle_iopl(void)
74926+{
74927+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74928+ return;
74929+}
74930+
74931+void
74932+gr_handle_mem_readwrite(u64 from, u64 to)
74933+{
74934+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74935+ return;
74936+}
74937+
74938+void
74939+gr_handle_vm86(void)
74940+{
74941+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74942+ return;
74943+}
74944+
74945+void
74946+gr_log_badprocpid(const char *entry)
74947+{
74948+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74949+ return;
74950+}
74951diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74952new file mode 100644
74953index 0000000..cd9e124
74954--- /dev/null
74955+++ b/grsecurity/grsec_mount.c
74956@@ -0,0 +1,65 @@
74957+#include <linux/kernel.h>
74958+#include <linux/sched.h>
74959+#include <linux/mount.h>
74960+#include <linux/major.h>
74961+#include <linux/grsecurity.h>
74962+#include <linux/grinternal.h>
74963+
74964+void
74965+gr_log_remount(const char *devname, const int retval)
74966+{
74967+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74968+ if (grsec_enable_mount && (retval >= 0))
74969+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74970+#endif
74971+ return;
74972+}
74973+
74974+void
74975+gr_log_unmount(const char *devname, const int retval)
74976+{
74977+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74978+ if (grsec_enable_mount && (retval >= 0))
74979+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74980+#endif
74981+ return;
74982+}
74983+
74984+void
74985+gr_log_mount(const char *from, const char *to, const int retval)
74986+{
74987+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74988+ if (grsec_enable_mount && (retval >= 0))
74989+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74990+#endif
74991+ return;
74992+}
74993+
74994+int
74995+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74996+{
74997+#ifdef CONFIG_GRKERNSEC_ROFS
74998+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74999+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75000+ return -EPERM;
75001+ } else
75002+ return 0;
75003+#endif
75004+ return 0;
75005+}
75006+
75007+int
75008+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75009+{
75010+#ifdef CONFIG_GRKERNSEC_ROFS
75011+ struct inode *inode = dentry->d_inode;
75012+
75013+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75014+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75015+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75016+ return -EPERM;
75017+ } else
75018+ return 0;
75019+#endif
75020+ return 0;
75021+}
75022diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75023new file mode 100644
75024index 0000000..6ee9d50
75025--- /dev/null
75026+++ b/grsecurity/grsec_pax.c
75027@@ -0,0 +1,45 @@
75028+#include <linux/kernel.h>
75029+#include <linux/sched.h>
75030+#include <linux/mm.h>
75031+#include <linux/file.h>
75032+#include <linux/grinternal.h>
75033+#include <linux/grsecurity.h>
75034+
75035+void
75036+gr_log_textrel(struct vm_area_struct * vma)
75037+{
75038+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75039+ if (grsec_enable_log_rwxmaps)
75040+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75041+#endif
75042+ return;
75043+}
75044+
75045+void gr_log_ptgnustack(struct file *file)
75046+{
75047+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75048+ if (grsec_enable_log_rwxmaps)
75049+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75050+#endif
75051+ return;
75052+}
75053+
75054+void
75055+gr_log_rwxmmap(struct file *file)
75056+{
75057+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75058+ if (grsec_enable_log_rwxmaps)
75059+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75060+#endif
75061+ return;
75062+}
75063+
75064+void
75065+gr_log_rwxmprotect(struct vm_area_struct *vma)
75066+{
75067+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75068+ if (grsec_enable_log_rwxmaps)
75069+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75070+#endif
75071+ return;
75072+}
75073diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75074new file mode 100644
75075index 0000000..2005a3a
75076--- /dev/null
75077+++ b/grsecurity/grsec_proc.c
75078@@ -0,0 +1,20 @@
75079+#include <linux/kernel.h>
75080+#include <linux/sched.h>
75081+#include <linux/grsecurity.h>
75082+#include <linux/grinternal.h>
75083+
75084+int gr_proc_is_restricted(void)
75085+{
75086+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75087+ const struct cred *cred = current_cred();
75088+#endif
75089+
75090+#ifdef CONFIG_GRKERNSEC_PROC_USER
75091+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75092+ return -EACCES;
75093+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75094+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75095+ return -EACCES;
75096+#endif
75097+ return 0;
75098+}
75099diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75100new file mode 100644
75101index 0000000..f7f29aa
75102--- /dev/null
75103+++ b/grsecurity/grsec_ptrace.c
75104@@ -0,0 +1,30 @@
75105+#include <linux/kernel.h>
75106+#include <linux/sched.h>
75107+#include <linux/grinternal.h>
75108+#include <linux/security.h>
75109+
75110+void
75111+gr_audit_ptrace(struct task_struct *task)
75112+{
75113+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75114+ if (grsec_enable_audit_ptrace)
75115+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75116+#endif
75117+ return;
75118+}
75119+
75120+int
75121+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75122+{
75123+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75124+ const struct dentry *dentry = file->f_path.dentry;
75125+ const struct vfsmount *mnt = file->f_path.mnt;
75126+
75127+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75128+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75129+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75130+ return -EACCES;
75131+ }
75132+#endif
75133+ return 0;
75134+}
75135diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75136new file mode 100644
75137index 0000000..3860c7e
75138--- /dev/null
75139+++ b/grsecurity/grsec_sig.c
75140@@ -0,0 +1,236 @@
75141+#include <linux/kernel.h>
75142+#include <linux/sched.h>
75143+#include <linux/fs.h>
75144+#include <linux/delay.h>
75145+#include <linux/grsecurity.h>
75146+#include <linux/grinternal.h>
75147+#include <linux/hardirq.h>
75148+
75149+char *signames[] = {
75150+ [SIGSEGV] = "Segmentation fault",
75151+ [SIGILL] = "Illegal instruction",
75152+ [SIGABRT] = "Abort",
75153+ [SIGBUS] = "Invalid alignment/Bus error"
75154+};
75155+
75156+void
75157+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75158+{
75159+#ifdef CONFIG_GRKERNSEC_SIGNAL
75160+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75161+ (sig == SIGABRT) || (sig == SIGBUS))) {
75162+ if (task_pid_nr(t) == task_pid_nr(current)) {
75163+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75164+ } else {
75165+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75166+ }
75167+ }
75168+#endif
75169+ return;
75170+}
75171+
75172+int
75173+gr_handle_signal(const struct task_struct *p, const int sig)
75174+{
75175+#ifdef CONFIG_GRKERNSEC
75176+ /* ignore the 0 signal for protected task checks */
75177+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75178+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75179+ return -EPERM;
75180+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75181+ return -EPERM;
75182+ }
75183+#endif
75184+ return 0;
75185+}
75186+
75187+#ifdef CONFIG_GRKERNSEC
75188+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75189+
75190+int gr_fake_force_sig(int sig, struct task_struct *t)
75191+{
75192+ unsigned long int flags;
75193+ int ret, blocked, ignored;
75194+ struct k_sigaction *action;
75195+
75196+ spin_lock_irqsave(&t->sighand->siglock, flags);
75197+ action = &t->sighand->action[sig-1];
75198+ ignored = action->sa.sa_handler == SIG_IGN;
75199+ blocked = sigismember(&t->blocked, sig);
75200+ if (blocked || ignored) {
75201+ action->sa.sa_handler = SIG_DFL;
75202+ if (blocked) {
75203+ sigdelset(&t->blocked, sig);
75204+ recalc_sigpending_and_wake(t);
75205+ }
75206+ }
75207+ if (action->sa.sa_handler == SIG_DFL)
75208+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75209+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75210+
75211+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75212+
75213+ return ret;
75214+}
75215+#endif
75216+
75217+#define GR_USER_BAN_TIME (15 * 60)
75218+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75219+
75220+void gr_handle_brute_attach(int dumpable)
75221+{
75222+#ifdef CONFIG_GRKERNSEC_BRUTE
75223+ struct task_struct *p = current;
75224+ kuid_t uid = GLOBAL_ROOT_UID;
75225+ int daemon = 0;
75226+
75227+ if (!grsec_enable_brute)
75228+ return;
75229+
75230+ rcu_read_lock();
75231+ read_lock(&tasklist_lock);
75232+ read_lock(&grsec_exec_file_lock);
75233+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75234+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75235+ p->real_parent->brute = 1;
75236+ daemon = 1;
75237+ } else {
75238+ const struct cred *cred = __task_cred(p), *cred2;
75239+ struct task_struct *tsk, *tsk2;
75240+
75241+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75242+ struct user_struct *user;
75243+
75244+ uid = cred->uid;
75245+
75246+ /* this is put upon execution past expiration */
75247+ user = find_user(uid);
75248+ if (user == NULL)
75249+ goto unlock;
75250+ user->suid_banned = 1;
75251+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75252+ if (user->suid_ban_expires == ~0UL)
75253+ user->suid_ban_expires--;
75254+
75255+ /* only kill other threads of the same binary, from the same user */
75256+ do_each_thread(tsk2, tsk) {
75257+ cred2 = __task_cred(tsk);
75258+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75259+ gr_fake_force_sig(SIGKILL, tsk);
75260+ } while_each_thread(tsk2, tsk);
75261+ }
75262+ }
75263+unlock:
75264+ read_unlock(&grsec_exec_file_lock);
75265+ read_unlock(&tasklist_lock);
75266+ rcu_read_unlock();
75267+
75268+ if (gr_is_global_nonroot(uid))
75269+ 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);
75270+ else if (daemon)
75271+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75272+
75273+#endif
75274+ return;
75275+}
75276+
75277+void gr_handle_brute_check(void)
75278+{
75279+#ifdef CONFIG_GRKERNSEC_BRUTE
75280+ struct task_struct *p = current;
75281+
75282+ if (unlikely(p->brute)) {
75283+ if (!grsec_enable_brute)
75284+ p->brute = 0;
75285+ else if (time_before(get_seconds(), p->brute_expires))
75286+ msleep(30 * 1000);
75287+ }
75288+#endif
75289+ return;
75290+}
75291+
75292+void gr_handle_kernel_exploit(void)
75293+{
75294+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75295+ const struct cred *cred;
75296+ struct task_struct *tsk, *tsk2;
75297+ struct user_struct *user;
75298+ kuid_t uid;
75299+
75300+ if (in_irq() || in_serving_softirq() || in_nmi())
75301+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75302+
75303+ uid = current_uid();
75304+
75305+ if (gr_is_global_root(uid))
75306+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75307+ else {
75308+ /* kill all the processes of this user, hold a reference
75309+ to their creds struct, and prevent them from creating
75310+ another process until system reset
75311+ */
75312+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75313+ GR_GLOBAL_UID(uid));
75314+ /* we intentionally leak this ref */
75315+ user = get_uid(current->cred->user);
75316+ if (user)
75317+ user->kernel_banned = 1;
75318+
75319+ /* kill all processes of this user */
75320+ read_lock(&tasklist_lock);
75321+ do_each_thread(tsk2, tsk) {
75322+ cred = __task_cred(tsk);
75323+ if (uid_eq(cred->uid, uid))
75324+ gr_fake_force_sig(SIGKILL, tsk);
75325+ } while_each_thread(tsk2, tsk);
75326+ read_unlock(&tasklist_lock);
75327+ }
75328+#endif
75329+}
75330+
75331+#ifdef CONFIG_GRKERNSEC_BRUTE
75332+static bool suid_ban_expired(struct user_struct *user)
75333+{
75334+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75335+ user->suid_banned = 0;
75336+ user->suid_ban_expires = 0;
75337+ free_uid(user);
75338+ return true;
75339+ }
75340+
75341+ return false;
75342+}
75343+#endif
75344+
75345+int gr_process_kernel_exec_ban(void)
75346+{
75347+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75348+ if (unlikely(current->cred->user->kernel_banned))
75349+ return -EPERM;
75350+#endif
75351+ return 0;
75352+}
75353+
75354+int gr_process_kernel_setuid_ban(struct user_struct *user)
75355+{
75356+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75357+ if (unlikely(user->kernel_banned))
75358+ gr_fake_force_sig(SIGKILL, current);
75359+#endif
75360+ return 0;
75361+}
75362+
75363+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75364+{
75365+#ifdef CONFIG_GRKERNSEC_BRUTE
75366+ struct user_struct *user = current->cred->user;
75367+ if (unlikely(user->suid_banned)) {
75368+ if (suid_ban_expired(user))
75369+ return 0;
75370+ /* disallow execution of suid binaries only */
75371+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75372+ return -EPERM;
75373+ }
75374+#endif
75375+ return 0;
75376+}
75377diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75378new file mode 100644
75379index 0000000..c0aef3a
75380--- /dev/null
75381+++ b/grsecurity/grsec_sock.c
75382@@ -0,0 +1,244 @@
75383+#include <linux/kernel.h>
75384+#include <linux/module.h>
75385+#include <linux/sched.h>
75386+#include <linux/file.h>
75387+#include <linux/net.h>
75388+#include <linux/in.h>
75389+#include <linux/ip.h>
75390+#include <net/sock.h>
75391+#include <net/inet_sock.h>
75392+#include <linux/grsecurity.h>
75393+#include <linux/grinternal.h>
75394+#include <linux/gracl.h>
75395+
75396+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75397+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75398+
75399+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75400+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75401+
75402+#ifdef CONFIG_UNIX_MODULE
75403+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75404+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75405+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75406+EXPORT_SYMBOL_GPL(gr_handle_create);
75407+#endif
75408+
75409+#ifdef CONFIG_GRKERNSEC
75410+#define gr_conn_table_size 32749
75411+struct conn_table_entry {
75412+ struct conn_table_entry *next;
75413+ struct signal_struct *sig;
75414+};
75415+
75416+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75417+DEFINE_SPINLOCK(gr_conn_table_lock);
75418+
75419+extern const char * gr_socktype_to_name(unsigned char type);
75420+extern const char * gr_proto_to_name(unsigned char proto);
75421+extern const char * gr_sockfamily_to_name(unsigned char family);
75422+
75423+static __inline__ int
75424+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75425+{
75426+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75427+}
75428+
75429+static __inline__ int
75430+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75431+ __u16 sport, __u16 dport)
75432+{
75433+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75434+ sig->gr_sport == sport && sig->gr_dport == dport))
75435+ return 1;
75436+ else
75437+ return 0;
75438+}
75439+
75440+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75441+{
75442+ struct conn_table_entry **match;
75443+ unsigned int index;
75444+
75445+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75446+ sig->gr_sport, sig->gr_dport,
75447+ gr_conn_table_size);
75448+
75449+ newent->sig = sig;
75450+
75451+ match = &gr_conn_table[index];
75452+ newent->next = *match;
75453+ *match = newent;
75454+
75455+ return;
75456+}
75457+
75458+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75459+{
75460+ struct conn_table_entry *match, *last = NULL;
75461+ unsigned int index;
75462+
75463+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75464+ sig->gr_sport, sig->gr_dport,
75465+ gr_conn_table_size);
75466+
75467+ match = gr_conn_table[index];
75468+ while (match && !conn_match(match->sig,
75469+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75470+ sig->gr_dport)) {
75471+ last = match;
75472+ match = match->next;
75473+ }
75474+
75475+ if (match) {
75476+ if (last)
75477+ last->next = match->next;
75478+ else
75479+ gr_conn_table[index] = NULL;
75480+ kfree(match);
75481+ }
75482+
75483+ return;
75484+}
75485+
75486+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75487+ __u16 sport, __u16 dport)
75488+{
75489+ struct conn_table_entry *match;
75490+ unsigned int index;
75491+
75492+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75493+
75494+ match = gr_conn_table[index];
75495+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75496+ match = match->next;
75497+
75498+ if (match)
75499+ return match->sig;
75500+ else
75501+ return NULL;
75502+}
75503+
75504+#endif
75505+
75506+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75507+{
75508+#ifdef CONFIG_GRKERNSEC
75509+ struct signal_struct *sig = task->signal;
75510+ struct conn_table_entry *newent;
75511+
75512+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75513+ if (newent == NULL)
75514+ return;
75515+ /* no bh lock needed since we are called with bh disabled */
75516+ spin_lock(&gr_conn_table_lock);
75517+ gr_del_task_from_ip_table_nolock(sig);
75518+ sig->gr_saddr = inet->inet_rcv_saddr;
75519+ sig->gr_daddr = inet->inet_daddr;
75520+ sig->gr_sport = inet->inet_sport;
75521+ sig->gr_dport = inet->inet_dport;
75522+ gr_add_to_task_ip_table_nolock(sig, newent);
75523+ spin_unlock(&gr_conn_table_lock);
75524+#endif
75525+ return;
75526+}
75527+
75528+void gr_del_task_from_ip_table(struct task_struct *task)
75529+{
75530+#ifdef CONFIG_GRKERNSEC
75531+ spin_lock_bh(&gr_conn_table_lock);
75532+ gr_del_task_from_ip_table_nolock(task->signal);
75533+ spin_unlock_bh(&gr_conn_table_lock);
75534+#endif
75535+ return;
75536+}
75537+
75538+void
75539+gr_attach_curr_ip(const struct sock *sk)
75540+{
75541+#ifdef CONFIG_GRKERNSEC
75542+ struct signal_struct *p, *set;
75543+ const struct inet_sock *inet = inet_sk(sk);
75544+
75545+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75546+ return;
75547+
75548+ set = current->signal;
75549+
75550+ spin_lock_bh(&gr_conn_table_lock);
75551+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75552+ inet->inet_dport, inet->inet_sport);
75553+ if (unlikely(p != NULL)) {
75554+ set->curr_ip = p->curr_ip;
75555+ set->used_accept = 1;
75556+ gr_del_task_from_ip_table_nolock(p);
75557+ spin_unlock_bh(&gr_conn_table_lock);
75558+ return;
75559+ }
75560+ spin_unlock_bh(&gr_conn_table_lock);
75561+
75562+ set->curr_ip = inet->inet_daddr;
75563+ set->used_accept = 1;
75564+#endif
75565+ return;
75566+}
75567+
75568+int
75569+gr_handle_sock_all(const int family, const int type, const int protocol)
75570+{
75571+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75572+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75573+ (family != AF_UNIX)) {
75574+ if (family == AF_INET)
75575+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75576+ else
75577+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75578+ return -EACCES;
75579+ }
75580+#endif
75581+ return 0;
75582+}
75583+
75584+int
75585+gr_handle_sock_server(const struct sockaddr *sck)
75586+{
75587+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75588+ if (grsec_enable_socket_server &&
75589+ in_group_p(grsec_socket_server_gid) &&
75590+ sck && (sck->sa_family != AF_UNIX) &&
75591+ (sck->sa_family != AF_LOCAL)) {
75592+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75593+ return -EACCES;
75594+ }
75595+#endif
75596+ return 0;
75597+}
75598+
75599+int
75600+gr_handle_sock_server_other(const struct sock *sck)
75601+{
75602+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75603+ if (grsec_enable_socket_server &&
75604+ in_group_p(grsec_socket_server_gid) &&
75605+ sck && (sck->sk_family != AF_UNIX) &&
75606+ (sck->sk_family != AF_LOCAL)) {
75607+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75608+ return -EACCES;
75609+ }
75610+#endif
75611+ return 0;
75612+}
75613+
75614+int
75615+gr_handle_sock_client(const struct sockaddr *sck)
75616+{
75617+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75618+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75619+ sck && (sck->sa_family != AF_UNIX) &&
75620+ (sck->sa_family != AF_LOCAL)) {
75621+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75622+ return -EACCES;
75623+ }
75624+#endif
75625+ return 0;
75626+}
75627diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75628new file mode 100644
75629index 0000000..8159888
75630--- /dev/null
75631+++ b/grsecurity/grsec_sysctl.c
75632@@ -0,0 +1,479 @@
75633+#include <linux/kernel.h>
75634+#include <linux/sched.h>
75635+#include <linux/sysctl.h>
75636+#include <linux/grsecurity.h>
75637+#include <linux/grinternal.h>
75638+
75639+int
75640+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75641+{
75642+#ifdef CONFIG_GRKERNSEC_SYSCTL
75643+ if (dirname == NULL || name == NULL)
75644+ return 0;
75645+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75646+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75647+ return -EACCES;
75648+ }
75649+#endif
75650+ return 0;
75651+}
75652+
75653+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75654+static int __maybe_unused __read_only one = 1;
75655+#endif
75656+
75657+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75658+ defined(CONFIG_GRKERNSEC_DENYUSB)
75659+struct ctl_table grsecurity_table[] = {
75660+#ifdef CONFIG_GRKERNSEC_SYSCTL
75661+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75662+#ifdef CONFIG_GRKERNSEC_IO
75663+ {
75664+ .procname = "disable_priv_io",
75665+ .data = &grsec_disable_privio,
75666+ .maxlen = sizeof(int),
75667+ .mode = 0600,
75668+ .proc_handler = &proc_dointvec,
75669+ },
75670+#endif
75671+#endif
75672+#ifdef CONFIG_GRKERNSEC_LINK
75673+ {
75674+ .procname = "linking_restrictions",
75675+ .data = &grsec_enable_link,
75676+ .maxlen = sizeof(int),
75677+ .mode = 0600,
75678+ .proc_handler = &proc_dointvec,
75679+ },
75680+#endif
75681+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75682+ {
75683+ .procname = "enforce_symlinksifowner",
75684+ .data = &grsec_enable_symlinkown,
75685+ .maxlen = sizeof(int),
75686+ .mode = 0600,
75687+ .proc_handler = &proc_dointvec,
75688+ },
75689+ {
75690+ .procname = "symlinkown_gid",
75691+ .data = &grsec_symlinkown_gid,
75692+ .maxlen = sizeof(int),
75693+ .mode = 0600,
75694+ .proc_handler = &proc_dointvec,
75695+ },
75696+#endif
75697+#ifdef CONFIG_GRKERNSEC_BRUTE
75698+ {
75699+ .procname = "deter_bruteforce",
75700+ .data = &grsec_enable_brute,
75701+ .maxlen = sizeof(int),
75702+ .mode = 0600,
75703+ .proc_handler = &proc_dointvec,
75704+ },
75705+#endif
75706+#ifdef CONFIG_GRKERNSEC_FIFO
75707+ {
75708+ .procname = "fifo_restrictions",
75709+ .data = &grsec_enable_fifo,
75710+ .maxlen = sizeof(int),
75711+ .mode = 0600,
75712+ .proc_handler = &proc_dointvec,
75713+ },
75714+#endif
75715+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75716+ {
75717+ .procname = "ptrace_readexec",
75718+ .data = &grsec_enable_ptrace_readexec,
75719+ .maxlen = sizeof(int),
75720+ .mode = 0600,
75721+ .proc_handler = &proc_dointvec,
75722+ },
75723+#endif
75724+#ifdef CONFIG_GRKERNSEC_SETXID
75725+ {
75726+ .procname = "consistent_setxid",
75727+ .data = &grsec_enable_setxid,
75728+ .maxlen = sizeof(int),
75729+ .mode = 0600,
75730+ .proc_handler = &proc_dointvec,
75731+ },
75732+#endif
75733+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75734+ {
75735+ .procname = "ip_blackhole",
75736+ .data = &grsec_enable_blackhole,
75737+ .maxlen = sizeof(int),
75738+ .mode = 0600,
75739+ .proc_handler = &proc_dointvec,
75740+ },
75741+ {
75742+ .procname = "lastack_retries",
75743+ .data = &grsec_lastack_retries,
75744+ .maxlen = sizeof(int),
75745+ .mode = 0600,
75746+ .proc_handler = &proc_dointvec,
75747+ },
75748+#endif
75749+#ifdef CONFIG_GRKERNSEC_EXECLOG
75750+ {
75751+ .procname = "exec_logging",
75752+ .data = &grsec_enable_execlog,
75753+ .maxlen = sizeof(int),
75754+ .mode = 0600,
75755+ .proc_handler = &proc_dointvec,
75756+ },
75757+#endif
75758+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75759+ {
75760+ .procname = "rwxmap_logging",
75761+ .data = &grsec_enable_log_rwxmaps,
75762+ .maxlen = sizeof(int),
75763+ .mode = 0600,
75764+ .proc_handler = &proc_dointvec,
75765+ },
75766+#endif
75767+#ifdef CONFIG_GRKERNSEC_SIGNAL
75768+ {
75769+ .procname = "signal_logging",
75770+ .data = &grsec_enable_signal,
75771+ .maxlen = sizeof(int),
75772+ .mode = 0600,
75773+ .proc_handler = &proc_dointvec,
75774+ },
75775+#endif
75776+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75777+ {
75778+ .procname = "forkfail_logging",
75779+ .data = &grsec_enable_forkfail,
75780+ .maxlen = sizeof(int),
75781+ .mode = 0600,
75782+ .proc_handler = &proc_dointvec,
75783+ },
75784+#endif
75785+#ifdef CONFIG_GRKERNSEC_TIME
75786+ {
75787+ .procname = "timechange_logging",
75788+ .data = &grsec_enable_time,
75789+ .maxlen = sizeof(int),
75790+ .mode = 0600,
75791+ .proc_handler = &proc_dointvec,
75792+ },
75793+#endif
75794+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75795+ {
75796+ .procname = "chroot_deny_shmat",
75797+ .data = &grsec_enable_chroot_shmat,
75798+ .maxlen = sizeof(int),
75799+ .mode = 0600,
75800+ .proc_handler = &proc_dointvec,
75801+ },
75802+#endif
75803+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75804+ {
75805+ .procname = "chroot_deny_unix",
75806+ .data = &grsec_enable_chroot_unix,
75807+ .maxlen = sizeof(int),
75808+ .mode = 0600,
75809+ .proc_handler = &proc_dointvec,
75810+ },
75811+#endif
75812+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75813+ {
75814+ .procname = "chroot_deny_mount",
75815+ .data = &grsec_enable_chroot_mount,
75816+ .maxlen = sizeof(int),
75817+ .mode = 0600,
75818+ .proc_handler = &proc_dointvec,
75819+ },
75820+#endif
75821+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75822+ {
75823+ .procname = "chroot_deny_fchdir",
75824+ .data = &grsec_enable_chroot_fchdir,
75825+ .maxlen = sizeof(int),
75826+ .mode = 0600,
75827+ .proc_handler = &proc_dointvec,
75828+ },
75829+#endif
75830+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75831+ {
75832+ .procname = "chroot_deny_chroot",
75833+ .data = &grsec_enable_chroot_double,
75834+ .maxlen = sizeof(int),
75835+ .mode = 0600,
75836+ .proc_handler = &proc_dointvec,
75837+ },
75838+#endif
75839+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75840+ {
75841+ .procname = "chroot_deny_pivot",
75842+ .data = &grsec_enable_chroot_pivot,
75843+ .maxlen = sizeof(int),
75844+ .mode = 0600,
75845+ .proc_handler = &proc_dointvec,
75846+ },
75847+#endif
75848+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75849+ {
75850+ .procname = "chroot_enforce_chdir",
75851+ .data = &grsec_enable_chroot_chdir,
75852+ .maxlen = sizeof(int),
75853+ .mode = 0600,
75854+ .proc_handler = &proc_dointvec,
75855+ },
75856+#endif
75857+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75858+ {
75859+ .procname = "chroot_deny_chmod",
75860+ .data = &grsec_enable_chroot_chmod,
75861+ .maxlen = sizeof(int),
75862+ .mode = 0600,
75863+ .proc_handler = &proc_dointvec,
75864+ },
75865+#endif
75866+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75867+ {
75868+ .procname = "chroot_deny_mknod",
75869+ .data = &grsec_enable_chroot_mknod,
75870+ .maxlen = sizeof(int),
75871+ .mode = 0600,
75872+ .proc_handler = &proc_dointvec,
75873+ },
75874+#endif
75875+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75876+ {
75877+ .procname = "chroot_restrict_nice",
75878+ .data = &grsec_enable_chroot_nice,
75879+ .maxlen = sizeof(int),
75880+ .mode = 0600,
75881+ .proc_handler = &proc_dointvec,
75882+ },
75883+#endif
75884+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75885+ {
75886+ .procname = "chroot_execlog",
75887+ .data = &grsec_enable_chroot_execlog,
75888+ .maxlen = sizeof(int),
75889+ .mode = 0600,
75890+ .proc_handler = &proc_dointvec,
75891+ },
75892+#endif
75893+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75894+ {
75895+ .procname = "chroot_caps",
75896+ .data = &grsec_enable_chroot_caps,
75897+ .maxlen = sizeof(int),
75898+ .mode = 0600,
75899+ .proc_handler = &proc_dointvec,
75900+ },
75901+#endif
75902+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75903+ {
75904+ .procname = "chroot_deny_sysctl",
75905+ .data = &grsec_enable_chroot_sysctl,
75906+ .maxlen = sizeof(int),
75907+ .mode = 0600,
75908+ .proc_handler = &proc_dointvec,
75909+ },
75910+#endif
75911+#ifdef CONFIG_GRKERNSEC_TPE
75912+ {
75913+ .procname = "tpe",
75914+ .data = &grsec_enable_tpe,
75915+ .maxlen = sizeof(int),
75916+ .mode = 0600,
75917+ .proc_handler = &proc_dointvec,
75918+ },
75919+ {
75920+ .procname = "tpe_gid",
75921+ .data = &grsec_tpe_gid,
75922+ .maxlen = sizeof(int),
75923+ .mode = 0600,
75924+ .proc_handler = &proc_dointvec,
75925+ },
75926+#endif
75927+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75928+ {
75929+ .procname = "tpe_invert",
75930+ .data = &grsec_enable_tpe_invert,
75931+ .maxlen = sizeof(int),
75932+ .mode = 0600,
75933+ .proc_handler = &proc_dointvec,
75934+ },
75935+#endif
75936+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75937+ {
75938+ .procname = "tpe_restrict_all",
75939+ .data = &grsec_enable_tpe_all,
75940+ .maxlen = sizeof(int),
75941+ .mode = 0600,
75942+ .proc_handler = &proc_dointvec,
75943+ },
75944+#endif
75945+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75946+ {
75947+ .procname = "socket_all",
75948+ .data = &grsec_enable_socket_all,
75949+ .maxlen = sizeof(int),
75950+ .mode = 0600,
75951+ .proc_handler = &proc_dointvec,
75952+ },
75953+ {
75954+ .procname = "socket_all_gid",
75955+ .data = &grsec_socket_all_gid,
75956+ .maxlen = sizeof(int),
75957+ .mode = 0600,
75958+ .proc_handler = &proc_dointvec,
75959+ },
75960+#endif
75961+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75962+ {
75963+ .procname = "socket_client",
75964+ .data = &grsec_enable_socket_client,
75965+ .maxlen = sizeof(int),
75966+ .mode = 0600,
75967+ .proc_handler = &proc_dointvec,
75968+ },
75969+ {
75970+ .procname = "socket_client_gid",
75971+ .data = &grsec_socket_client_gid,
75972+ .maxlen = sizeof(int),
75973+ .mode = 0600,
75974+ .proc_handler = &proc_dointvec,
75975+ },
75976+#endif
75977+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75978+ {
75979+ .procname = "socket_server",
75980+ .data = &grsec_enable_socket_server,
75981+ .maxlen = sizeof(int),
75982+ .mode = 0600,
75983+ .proc_handler = &proc_dointvec,
75984+ },
75985+ {
75986+ .procname = "socket_server_gid",
75987+ .data = &grsec_socket_server_gid,
75988+ .maxlen = sizeof(int),
75989+ .mode = 0600,
75990+ .proc_handler = &proc_dointvec,
75991+ },
75992+#endif
75993+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75994+ {
75995+ .procname = "audit_group",
75996+ .data = &grsec_enable_group,
75997+ .maxlen = sizeof(int),
75998+ .mode = 0600,
75999+ .proc_handler = &proc_dointvec,
76000+ },
76001+ {
76002+ .procname = "audit_gid",
76003+ .data = &grsec_audit_gid,
76004+ .maxlen = sizeof(int),
76005+ .mode = 0600,
76006+ .proc_handler = &proc_dointvec,
76007+ },
76008+#endif
76009+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76010+ {
76011+ .procname = "audit_chdir",
76012+ .data = &grsec_enable_chdir,
76013+ .maxlen = sizeof(int),
76014+ .mode = 0600,
76015+ .proc_handler = &proc_dointvec,
76016+ },
76017+#endif
76018+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76019+ {
76020+ .procname = "audit_mount",
76021+ .data = &grsec_enable_mount,
76022+ .maxlen = sizeof(int),
76023+ .mode = 0600,
76024+ .proc_handler = &proc_dointvec,
76025+ },
76026+#endif
76027+#ifdef CONFIG_GRKERNSEC_DMESG
76028+ {
76029+ .procname = "dmesg",
76030+ .data = &grsec_enable_dmesg,
76031+ .maxlen = sizeof(int),
76032+ .mode = 0600,
76033+ .proc_handler = &proc_dointvec,
76034+ },
76035+#endif
76036+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76037+ {
76038+ .procname = "chroot_findtask",
76039+ .data = &grsec_enable_chroot_findtask,
76040+ .maxlen = sizeof(int),
76041+ .mode = 0600,
76042+ .proc_handler = &proc_dointvec,
76043+ },
76044+#endif
76045+#ifdef CONFIG_GRKERNSEC_RESLOG
76046+ {
76047+ .procname = "resource_logging",
76048+ .data = &grsec_resource_logging,
76049+ .maxlen = sizeof(int),
76050+ .mode = 0600,
76051+ .proc_handler = &proc_dointvec,
76052+ },
76053+#endif
76054+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76055+ {
76056+ .procname = "audit_ptrace",
76057+ .data = &grsec_enable_audit_ptrace,
76058+ .maxlen = sizeof(int),
76059+ .mode = 0600,
76060+ .proc_handler = &proc_dointvec,
76061+ },
76062+#endif
76063+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76064+ {
76065+ .procname = "harden_ptrace",
76066+ .data = &grsec_enable_harden_ptrace,
76067+ .maxlen = sizeof(int),
76068+ .mode = 0600,
76069+ .proc_handler = &proc_dointvec,
76070+ },
76071+#endif
76072+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76073+ {
76074+ .procname = "harden_ipc",
76075+ .data = &grsec_enable_harden_ipc,
76076+ .maxlen = sizeof(int),
76077+ .mode = 0600,
76078+ .proc_handler = &proc_dointvec,
76079+ },
76080+#endif
76081+ {
76082+ .procname = "grsec_lock",
76083+ .data = &grsec_lock,
76084+ .maxlen = sizeof(int),
76085+ .mode = 0600,
76086+ .proc_handler = &proc_dointvec,
76087+ },
76088+#endif
76089+#ifdef CONFIG_GRKERNSEC_ROFS
76090+ {
76091+ .procname = "romount_protect",
76092+ .data = &grsec_enable_rofs,
76093+ .maxlen = sizeof(int),
76094+ .mode = 0600,
76095+ .proc_handler = &proc_dointvec_minmax,
76096+ .extra1 = &one,
76097+ .extra2 = &one,
76098+ },
76099+#endif
76100+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76101+ {
76102+ .procname = "deny_new_usb",
76103+ .data = &grsec_deny_new_usb,
76104+ .maxlen = sizeof(int),
76105+ .mode = 0600,
76106+ .proc_handler = &proc_dointvec,
76107+ },
76108+#endif
76109+ { }
76110+};
76111+#endif
76112diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76113new file mode 100644
76114index 0000000..61b514e
76115--- /dev/null
76116+++ b/grsecurity/grsec_time.c
76117@@ -0,0 +1,16 @@
76118+#include <linux/kernel.h>
76119+#include <linux/sched.h>
76120+#include <linux/grinternal.h>
76121+#include <linux/module.h>
76122+
76123+void
76124+gr_log_timechange(void)
76125+{
76126+#ifdef CONFIG_GRKERNSEC_TIME
76127+ if (grsec_enable_time)
76128+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76129+#endif
76130+ return;
76131+}
76132+
76133+EXPORT_SYMBOL_GPL(gr_log_timechange);
76134diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76135new file mode 100644
76136index 0000000..ee57dcf
76137--- /dev/null
76138+++ b/grsecurity/grsec_tpe.c
76139@@ -0,0 +1,73 @@
76140+#include <linux/kernel.h>
76141+#include <linux/sched.h>
76142+#include <linux/file.h>
76143+#include <linux/fs.h>
76144+#include <linux/grinternal.h>
76145+
76146+extern int gr_acl_tpe_check(void);
76147+
76148+int
76149+gr_tpe_allow(const struct file *file)
76150+{
76151+#ifdef CONFIG_GRKERNSEC
76152+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76153+ const struct cred *cred = current_cred();
76154+ char *msg = NULL;
76155+ char *msg2 = NULL;
76156+
76157+ // never restrict root
76158+ if (gr_is_global_root(cred->uid))
76159+ return 1;
76160+
76161+ if (grsec_enable_tpe) {
76162+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76163+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76164+ msg = "not being in trusted group";
76165+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76166+ msg = "being in untrusted group";
76167+#else
76168+ if (in_group_p(grsec_tpe_gid))
76169+ msg = "being in untrusted group";
76170+#endif
76171+ }
76172+ if (!msg && gr_acl_tpe_check())
76173+ msg = "being in untrusted role";
76174+
76175+ // not in any affected group/role
76176+ if (!msg)
76177+ goto next_check;
76178+
76179+ if (gr_is_global_nonroot(inode->i_uid))
76180+ msg2 = "file in non-root-owned directory";
76181+ else if (inode->i_mode & S_IWOTH)
76182+ msg2 = "file in world-writable directory";
76183+ else if (inode->i_mode & S_IWGRP)
76184+ msg2 = "file in group-writable directory";
76185+
76186+ if (msg && msg2) {
76187+ char fullmsg[70] = {0};
76188+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76189+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76190+ return 0;
76191+ }
76192+ msg = NULL;
76193+next_check:
76194+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76195+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76196+ return 1;
76197+
76198+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76199+ msg = "directory not owned by user";
76200+ else if (inode->i_mode & S_IWOTH)
76201+ msg = "file in world-writable directory";
76202+ else if (inode->i_mode & S_IWGRP)
76203+ msg = "file in group-writable directory";
76204+
76205+ if (msg) {
76206+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76207+ return 0;
76208+ }
76209+#endif
76210+#endif
76211+ return 1;
76212+}
76213diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76214new file mode 100644
76215index 0000000..ae02d8e
76216--- /dev/null
76217+++ b/grsecurity/grsec_usb.c
76218@@ -0,0 +1,15 @@
76219+#include <linux/kernel.h>
76220+#include <linux/grinternal.h>
76221+#include <linux/module.h>
76222+
76223+int gr_handle_new_usb(void)
76224+{
76225+#ifdef CONFIG_GRKERNSEC_DENYUSB
76226+ if (grsec_deny_new_usb) {
76227+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76228+ return 1;
76229+ }
76230+#endif
76231+ return 0;
76232+}
76233+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76234diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76235new file mode 100644
76236index 0000000..9f7b1ac
76237--- /dev/null
76238+++ b/grsecurity/grsum.c
76239@@ -0,0 +1,61 @@
76240+#include <linux/err.h>
76241+#include <linux/kernel.h>
76242+#include <linux/sched.h>
76243+#include <linux/mm.h>
76244+#include <linux/scatterlist.h>
76245+#include <linux/crypto.h>
76246+#include <linux/gracl.h>
76247+
76248+
76249+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76250+#error "crypto and sha256 must be built into the kernel"
76251+#endif
76252+
76253+int
76254+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76255+{
76256+ char *p;
76257+ struct crypto_hash *tfm;
76258+ struct hash_desc desc;
76259+ struct scatterlist sg;
76260+ unsigned char temp_sum[GR_SHA_LEN];
76261+ volatile int retval = 0;
76262+ volatile int dummy = 0;
76263+ unsigned int i;
76264+
76265+ sg_init_table(&sg, 1);
76266+
76267+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76268+ if (IS_ERR(tfm)) {
76269+ /* should never happen, since sha256 should be built in */
76270+ return 1;
76271+ }
76272+
76273+ desc.tfm = tfm;
76274+ desc.flags = 0;
76275+
76276+ crypto_hash_init(&desc);
76277+
76278+ p = salt;
76279+ sg_set_buf(&sg, p, GR_SALT_LEN);
76280+ crypto_hash_update(&desc, &sg, sg.length);
76281+
76282+ p = entry->pw;
76283+ sg_set_buf(&sg, p, strlen(p));
76284+
76285+ crypto_hash_update(&desc, &sg, sg.length);
76286+
76287+ crypto_hash_final(&desc, temp_sum);
76288+
76289+ memset(entry->pw, 0, GR_PW_LEN);
76290+
76291+ for (i = 0; i < GR_SHA_LEN; i++)
76292+ if (sum[i] != temp_sum[i])
76293+ retval = 1;
76294+ else
76295+ dummy = 1; // waste a cycle
76296+
76297+ crypto_free_hash(tfm);
76298+
76299+ return retval;
76300+}
76301diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76302index 77ff547..181834f 100644
76303--- a/include/asm-generic/4level-fixup.h
76304+++ b/include/asm-generic/4level-fixup.h
76305@@ -13,8 +13,10 @@
76306 #define pmd_alloc(mm, pud, address) \
76307 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76308 NULL: pmd_offset(pud, address))
76309+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76310
76311 #define pud_alloc(mm, pgd, address) (pgd)
76312+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76313 #define pud_offset(pgd, start) (pgd)
76314 #define pud_none(pud) 0
76315 #define pud_bad(pud) 0
76316diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76317index b7babf0..97f4c4f 100644
76318--- a/include/asm-generic/atomic-long.h
76319+++ b/include/asm-generic/atomic-long.h
76320@@ -22,6 +22,12 @@
76321
76322 typedef atomic64_t atomic_long_t;
76323
76324+#ifdef CONFIG_PAX_REFCOUNT
76325+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76326+#else
76327+typedef atomic64_t atomic_long_unchecked_t;
76328+#endif
76329+
76330 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76331
76332 static inline long atomic_long_read(atomic_long_t *l)
76333@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76334 return (long)atomic64_read(v);
76335 }
76336
76337+#ifdef CONFIG_PAX_REFCOUNT
76338+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76339+{
76340+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76341+
76342+ return (long)atomic64_read_unchecked(v);
76343+}
76344+#endif
76345+
76346 static inline void atomic_long_set(atomic_long_t *l, long i)
76347 {
76348 atomic64_t *v = (atomic64_t *)l;
76349@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76350 atomic64_set(v, i);
76351 }
76352
76353+#ifdef CONFIG_PAX_REFCOUNT
76354+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76355+{
76356+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76357+
76358+ atomic64_set_unchecked(v, i);
76359+}
76360+#endif
76361+
76362 static inline void atomic_long_inc(atomic_long_t *l)
76363 {
76364 atomic64_t *v = (atomic64_t *)l;
76365@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76366 atomic64_inc(v);
76367 }
76368
76369+#ifdef CONFIG_PAX_REFCOUNT
76370+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76371+{
76372+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76373+
76374+ atomic64_inc_unchecked(v);
76375+}
76376+#endif
76377+
76378 static inline void atomic_long_dec(atomic_long_t *l)
76379 {
76380 atomic64_t *v = (atomic64_t *)l;
76381@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76382 atomic64_dec(v);
76383 }
76384
76385+#ifdef CONFIG_PAX_REFCOUNT
76386+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76387+{
76388+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76389+
76390+ atomic64_dec_unchecked(v);
76391+}
76392+#endif
76393+
76394 static inline void atomic_long_add(long i, atomic_long_t *l)
76395 {
76396 atomic64_t *v = (atomic64_t *)l;
76397@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76398 atomic64_add(i, v);
76399 }
76400
76401+#ifdef CONFIG_PAX_REFCOUNT
76402+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76403+{
76404+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76405+
76406+ atomic64_add_unchecked(i, v);
76407+}
76408+#endif
76409+
76410 static inline void atomic_long_sub(long i, atomic_long_t *l)
76411 {
76412 atomic64_t *v = (atomic64_t *)l;
76413@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76414 atomic64_sub(i, v);
76415 }
76416
76417+#ifdef CONFIG_PAX_REFCOUNT
76418+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76419+{
76420+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76421+
76422+ atomic64_sub_unchecked(i, v);
76423+}
76424+#endif
76425+
76426 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76427 {
76428 atomic64_t *v = (atomic64_t *)l;
76429@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76430 return atomic64_add_negative(i, v);
76431 }
76432
76433-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76434+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76435 {
76436 atomic64_t *v = (atomic64_t *)l;
76437
76438 return (long)atomic64_add_return(i, v);
76439 }
76440
76441+#ifdef CONFIG_PAX_REFCOUNT
76442+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76443+{
76444+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76445+
76446+ return (long)atomic64_add_return_unchecked(i, v);
76447+}
76448+#endif
76449+
76450 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76451 {
76452 atomic64_t *v = (atomic64_t *)l;
76453@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76454 return (long)atomic64_inc_return(v);
76455 }
76456
76457+#ifdef CONFIG_PAX_REFCOUNT
76458+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76459+{
76460+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76461+
76462+ return (long)atomic64_inc_return_unchecked(v);
76463+}
76464+#endif
76465+
76466 static inline long atomic_long_dec_return(atomic_long_t *l)
76467 {
76468 atomic64_t *v = (atomic64_t *)l;
76469@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76470
76471 typedef atomic_t atomic_long_t;
76472
76473+#ifdef CONFIG_PAX_REFCOUNT
76474+typedef atomic_unchecked_t atomic_long_unchecked_t;
76475+#else
76476+typedef atomic_t atomic_long_unchecked_t;
76477+#endif
76478+
76479 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76480 static inline long atomic_long_read(atomic_long_t *l)
76481 {
76482@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76483 return (long)atomic_read(v);
76484 }
76485
76486+#ifdef CONFIG_PAX_REFCOUNT
76487+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76488+{
76489+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76490+
76491+ return (long)atomic_read_unchecked(v);
76492+}
76493+#endif
76494+
76495 static inline void atomic_long_set(atomic_long_t *l, long i)
76496 {
76497 atomic_t *v = (atomic_t *)l;
76498@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76499 atomic_set(v, i);
76500 }
76501
76502+#ifdef CONFIG_PAX_REFCOUNT
76503+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76504+{
76505+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76506+
76507+ atomic_set_unchecked(v, i);
76508+}
76509+#endif
76510+
76511 static inline void atomic_long_inc(atomic_long_t *l)
76512 {
76513 atomic_t *v = (atomic_t *)l;
76514@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76515 atomic_inc(v);
76516 }
76517
76518+#ifdef CONFIG_PAX_REFCOUNT
76519+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76520+{
76521+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76522+
76523+ atomic_inc_unchecked(v);
76524+}
76525+#endif
76526+
76527 static inline void atomic_long_dec(atomic_long_t *l)
76528 {
76529 atomic_t *v = (atomic_t *)l;
76530@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76531 atomic_dec(v);
76532 }
76533
76534+#ifdef CONFIG_PAX_REFCOUNT
76535+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76536+{
76537+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76538+
76539+ atomic_dec_unchecked(v);
76540+}
76541+#endif
76542+
76543 static inline void atomic_long_add(long i, atomic_long_t *l)
76544 {
76545 atomic_t *v = (atomic_t *)l;
76546@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76547 atomic_add(i, v);
76548 }
76549
76550+#ifdef CONFIG_PAX_REFCOUNT
76551+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76552+{
76553+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76554+
76555+ atomic_add_unchecked(i, v);
76556+}
76557+#endif
76558+
76559 static inline void atomic_long_sub(long i, atomic_long_t *l)
76560 {
76561 atomic_t *v = (atomic_t *)l;
76562@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76563 atomic_sub(i, v);
76564 }
76565
76566+#ifdef CONFIG_PAX_REFCOUNT
76567+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76568+{
76569+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76570+
76571+ atomic_sub_unchecked(i, v);
76572+}
76573+#endif
76574+
76575 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76576 {
76577 atomic_t *v = (atomic_t *)l;
76578@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76579 return (long)atomic_add_return(i, v);
76580 }
76581
76582+#ifdef CONFIG_PAX_REFCOUNT
76583+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76584+{
76585+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76586+
76587+ return (long)atomic_add_return_unchecked(i, v);
76588+}
76589+
76590+#endif
76591+
76592 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76593 {
76594 atomic_t *v = (atomic_t *)l;
76595@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76596 return (long)atomic_inc_return(v);
76597 }
76598
76599+#ifdef CONFIG_PAX_REFCOUNT
76600+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76601+{
76602+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76603+
76604+ return (long)atomic_inc_return_unchecked(v);
76605+}
76606+#endif
76607+
76608 static inline long atomic_long_dec_return(atomic_long_t *l)
76609 {
76610 atomic_t *v = (atomic_t *)l;
76611@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76612
76613 #endif /* BITS_PER_LONG == 64 */
76614
76615+#ifdef CONFIG_PAX_REFCOUNT
76616+static inline void pax_refcount_needs_these_functions(void)
76617+{
76618+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76619+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76620+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76621+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76622+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76623+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76624+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76625+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76626+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76627+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76628+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76629+#ifdef CONFIG_X86
76630+ atomic_clear_mask_unchecked(0, NULL);
76631+ atomic_set_mask_unchecked(0, NULL);
76632+#endif
76633+
76634+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76635+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76636+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76637+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76638+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76639+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76640+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76641+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76642+}
76643+#else
76644+#define atomic_read_unchecked(v) atomic_read(v)
76645+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76646+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76647+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76648+#define atomic_inc_unchecked(v) atomic_inc(v)
76649+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76650+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76651+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76652+#define atomic_dec_unchecked(v) atomic_dec(v)
76653+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76654+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76655+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76656+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76657+
76658+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76659+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76660+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76661+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76662+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76663+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76664+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76665+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76666+#endif
76667+
76668 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76669diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76670index 33bd2de..f31bff97 100644
76671--- a/include/asm-generic/atomic.h
76672+++ b/include/asm-generic/atomic.h
76673@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76674 * Atomically clears the bits set in @mask from @v
76675 */
76676 #ifndef atomic_clear_mask
76677-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76678+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76679 {
76680 unsigned long flags;
76681
76682diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76683index b18ce4f..2ee2843 100644
76684--- a/include/asm-generic/atomic64.h
76685+++ b/include/asm-generic/atomic64.h
76686@@ -16,6 +16,8 @@ typedef struct {
76687 long long counter;
76688 } atomic64_t;
76689
76690+typedef atomic64_t atomic64_unchecked_t;
76691+
76692 #define ATOMIC64_INIT(i) { (i) }
76693
76694 extern long long atomic64_read(const atomic64_t *v);
76695@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76696 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76697 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76698
76699+#define atomic64_read_unchecked(v) atomic64_read(v)
76700+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76701+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76702+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76703+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76704+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76705+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76706+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76707+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76708+
76709 #endif /* _ASM_GENERIC_ATOMIC64_H */
76710diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76711index a60a7cc..0fe12f2 100644
76712--- a/include/asm-generic/bitops/__fls.h
76713+++ b/include/asm-generic/bitops/__fls.h
76714@@ -9,7 +9,7 @@
76715 *
76716 * Undefined if no set bit exists, so code should check against 0 first.
76717 */
76718-static __always_inline unsigned long __fls(unsigned long word)
76719+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76720 {
76721 int num = BITS_PER_LONG - 1;
76722
76723diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76724index 0576d1f..dad6c71 100644
76725--- a/include/asm-generic/bitops/fls.h
76726+++ b/include/asm-generic/bitops/fls.h
76727@@ -9,7 +9,7 @@
76728 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76729 */
76730
76731-static __always_inline int fls(int x)
76732+static __always_inline int __intentional_overflow(-1) fls(int x)
76733 {
76734 int r = 32;
76735
76736diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76737index b097cf8..3d40e14 100644
76738--- a/include/asm-generic/bitops/fls64.h
76739+++ b/include/asm-generic/bitops/fls64.h
76740@@ -15,7 +15,7 @@
76741 * at position 64.
76742 */
76743 #if BITS_PER_LONG == 32
76744-static __always_inline int fls64(__u64 x)
76745+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76746 {
76747 __u32 h = x >> 32;
76748 if (h)
76749@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76750 return fls(x);
76751 }
76752 #elif BITS_PER_LONG == 64
76753-static __always_inline int fls64(__u64 x)
76754+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76755 {
76756 if (x == 0)
76757 return 0;
76758diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76759index 1bfcfe5..e04c5c9 100644
76760--- a/include/asm-generic/cache.h
76761+++ b/include/asm-generic/cache.h
76762@@ -6,7 +6,7 @@
76763 * cache lines need to provide their own cache.h.
76764 */
76765
76766-#define L1_CACHE_SHIFT 5
76767-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76768+#define L1_CACHE_SHIFT 5UL
76769+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76770
76771 #endif /* __ASM_GENERIC_CACHE_H */
76772diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76773index 0d68a1e..b74a761 100644
76774--- a/include/asm-generic/emergency-restart.h
76775+++ b/include/asm-generic/emergency-restart.h
76776@@ -1,7 +1,7 @@
76777 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76778 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76779
76780-static inline void machine_emergency_restart(void)
76781+static inline __noreturn void machine_emergency_restart(void)
76782 {
76783 machine_restart(NULL);
76784 }
76785diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76786index 90f99c7..00ce236 100644
76787--- a/include/asm-generic/kmap_types.h
76788+++ b/include/asm-generic/kmap_types.h
76789@@ -2,9 +2,9 @@
76790 #define _ASM_GENERIC_KMAP_TYPES_H
76791
76792 #ifdef __WITH_KM_FENCE
76793-# define KM_TYPE_NR 41
76794+# define KM_TYPE_NR 42
76795 #else
76796-# define KM_TYPE_NR 20
76797+# define KM_TYPE_NR 21
76798 #endif
76799
76800 #endif
76801diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76802index 9ceb03b..62b0b8f 100644
76803--- a/include/asm-generic/local.h
76804+++ b/include/asm-generic/local.h
76805@@ -23,24 +23,37 @@ typedef struct
76806 atomic_long_t a;
76807 } local_t;
76808
76809+typedef struct {
76810+ atomic_long_unchecked_t a;
76811+} local_unchecked_t;
76812+
76813 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76814
76815 #define local_read(l) atomic_long_read(&(l)->a)
76816+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76817 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76818+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76819 #define local_inc(l) atomic_long_inc(&(l)->a)
76820+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76821 #define local_dec(l) atomic_long_dec(&(l)->a)
76822+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76823 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76824+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76825 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76826+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76827
76828 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76829 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76830 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76831 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76832 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76833+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76834 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76835 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76836+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76837
76838 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76839+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76840 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76841 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76842 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76843diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76844index 725612b..9cc513a 100644
76845--- a/include/asm-generic/pgtable-nopmd.h
76846+++ b/include/asm-generic/pgtable-nopmd.h
76847@@ -1,14 +1,19 @@
76848 #ifndef _PGTABLE_NOPMD_H
76849 #define _PGTABLE_NOPMD_H
76850
76851-#ifndef __ASSEMBLY__
76852-
76853 #include <asm-generic/pgtable-nopud.h>
76854
76855-struct mm_struct;
76856-
76857 #define __PAGETABLE_PMD_FOLDED
76858
76859+#define PMD_SHIFT PUD_SHIFT
76860+#define PTRS_PER_PMD 1
76861+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76862+#define PMD_MASK (~(PMD_SIZE-1))
76863+
76864+#ifndef __ASSEMBLY__
76865+
76866+struct mm_struct;
76867+
76868 /*
76869 * Having the pmd type consist of a pud gets the size right, and allows
76870 * us to conceptually access the pud entry that this pmd is folded into
76871@@ -16,11 +21,6 @@ struct mm_struct;
76872 */
76873 typedef struct { pud_t pud; } pmd_t;
76874
76875-#define PMD_SHIFT PUD_SHIFT
76876-#define PTRS_PER_PMD 1
76877-#define PMD_SIZE (1UL << PMD_SHIFT)
76878-#define PMD_MASK (~(PMD_SIZE-1))
76879-
76880 /*
76881 * The "pud_xxx()" functions here are trivial for a folded two-level
76882 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76883diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76884index 810431d..0ec4804f 100644
76885--- a/include/asm-generic/pgtable-nopud.h
76886+++ b/include/asm-generic/pgtable-nopud.h
76887@@ -1,10 +1,15 @@
76888 #ifndef _PGTABLE_NOPUD_H
76889 #define _PGTABLE_NOPUD_H
76890
76891-#ifndef __ASSEMBLY__
76892-
76893 #define __PAGETABLE_PUD_FOLDED
76894
76895+#define PUD_SHIFT PGDIR_SHIFT
76896+#define PTRS_PER_PUD 1
76897+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76898+#define PUD_MASK (~(PUD_SIZE-1))
76899+
76900+#ifndef __ASSEMBLY__
76901+
76902 /*
76903 * Having the pud type consist of a pgd gets the size right, and allows
76904 * us to conceptually access the pgd entry that this pud is folded into
76905@@ -12,11 +17,6 @@
76906 */
76907 typedef struct { pgd_t pgd; } pud_t;
76908
76909-#define PUD_SHIFT PGDIR_SHIFT
76910-#define PTRS_PER_PUD 1
76911-#define PUD_SIZE (1UL << PUD_SHIFT)
76912-#define PUD_MASK (~(PUD_SIZE-1))
76913-
76914 /*
76915 * The "pgd_xxx()" functions here are trivial for a folded two-level
76916 * setup: the pud is never bad, and a pud always exists (as it's folded
76917@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76918 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76919
76920 #define pgd_populate(mm, pgd, pud) do { } while (0)
76921+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76922 /*
76923 * (puds are folded into pgds so this doesn't get actually called,
76924 * but the define is needed for a generic inline function.)
76925diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76926index 34c7bdc..38d4f3b 100644
76927--- a/include/asm-generic/pgtable.h
76928+++ b/include/asm-generic/pgtable.h
76929@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
76930 }
76931 #endif /* CONFIG_NUMA_BALANCING */
76932
76933+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76934+#ifdef CONFIG_PAX_KERNEXEC
76935+#error KERNEXEC requires pax_open_kernel
76936+#else
76937+static inline unsigned long pax_open_kernel(void) { return 0; }
76938+#endif
76939+#endif
76940+
76941+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76942+#ifdef CONFIG_PAX_KERNEXEC
76943+#error KERNEXEC requires pax_close_kernel
76944+#else
76945+static inline unsigned long pax_close_kernel(void) { return 0; }
76946+#endif
76947+#endif
76948+
76949 #endif /* CONFIG_MMU */
76950
76951 #endif /* !__ASSEMBLY__ */
76952diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76953index 72d8803..cb9749c 100644
76954--- a/include/asm-generic/uaccess.h
76955+++ b/include/asm-generic/uaccess.h
76956@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76957 return __clear_user(to, n);
76958 }
76959
76960+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76961+#ifdef CONFIG_PAX_MEMORY_UDEREF
76962+#error UDEREF requires pax_open_userland
76963+#else
76964+static inline unsigned long pax_open_userland(void) { return 0; }
76965+#endif
76966+#endif
76967+
76968+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76969+#ifdef CONFIG_PAX_MEMORY_UDEREF
76970+#error UDEREF requires pax_close_userland
76971+#else
76972+static inline unsigned long pax_close_userland(void) { return 0; }
76973+#endif
76974+#endif
76975+
76976 #endif /* __ASM_GENERIC_UACCESS_H */
76977diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76978index bc2121f..2f41f9a 100644
76979--- a/include/asm-generic/vmlinux.lds.h
76980+++ b/include/asm-generic/vmlinux.lds.h
76981@@ -232,6 +232,7 @@
76982 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76983 VMLINUX_SYMBOL(__start_rodata) = .; \
76984 *(.rodata) *(.rodata.*) \
76985+ *(.data..read_only) \
76986 *(__vermagic) /* Kernel version magic */ \
76987 . = ALIGN(8); \
76988 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76989@@ -716,17 +717,18 @@
76990 * section in the linker script will go there too. @phdr should have
76991 * a leading colon.
76992 *
76993- * Note that this macros defines __per_cpu_load as an absolute symbol.
76994+ * Note that this macros defines per_cpu_load as an absolute symbol.
76995 * If there is no need to put the percpu section at a predetermined
76996 * address, use PERCPU_SECTION.
76997 */
76998 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76999- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77000- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77001+ per_cpu_load = .; \
77002+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77003 - LOAD_OFFSET) { \
77004+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77005 PERCPU_INPUT(cacheline) \
77006 } phdr \
77007- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77008+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77009
77010 /**
77011 * PERCPU_SECTION - define output section for percpu area, simple version
77012diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77013index e73c19e..5b89e00 100644
77014--- a/include/crypto/algapi.h
77015+++ b/include/crypto/algapi.h
77016@@ -34,7 +34,7 @@ struct crypto_type {
77017 unsigned int maskclear;
77018 unsigned int maskset;
77019 unsigned int tfmsize;
77020-};
77021+} __do_const;
77022
77023 struct crypto_instance {
77024 struct crypto_alg alg;
77025diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77026index 04a7f31..668d424 100644
77027--- a/include/drm/drmP.h
77028+++ b/include/drm/drmP.h
77029@@ -67,6 +67,7 @@
77030 #include <linux/workqueue.h>
77031 #include <linux/poll.h>
77032 #include <asm/pgalloc.h>
77033+#include <asm/local.h>
77034 #include <drm/drm.h>
77035 #include <drm/drm_sarea.h>
77036 #include <drm/drm_vma_manager.h>
77037@@ -297,10 +298,12 @@ do { \
77038 * \param cmd command.
77039 * \param arg argument.
77040 */
77041-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77042+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77043+ struct drm_file *file_priv);
77044+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77045 struct drm_file *file_priv);
77046
77047-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77048+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77049 unsigned long arg);
77050
77051 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77052@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77053 struct drm_ioctl_desc {
77054 unsigned int cmd;
77055 int flags;
77056- drm_ioctl_t *func;
77057+ drm_ioctl_t func;
77058 unsigned int cmd_drv;
77059 const char *name;
77060-};
77061+} __do_const;
77062
77063 /**
77064 * Creates a driver or general drm_ioctl_desc array entry for the given
77065@@ -1022,7 +1025,8 @@ struct drm_info_list {
77066 int (*show)(struct seq_file*, void*); /** show callback */
77067 u32 driver_features; /**< Required driver features for this entry */
77068 void *data;
77069-};
77070+} __do_const;
77071+typedef struct drm_info_list __no_const drm_info_list_no_const;
77072
77073 /**
77074 * debugfs node structure. This structure represents a debugfs file.
77075@@ -1106,7 +1110,7 @@ struct drm_device {
77076
77077 /** \name Usage Counters */
77078 /*@{ */
77079- int open_count; /**< Outstanding files open */
77080+ local_t open_count; /**< Outstanding files open */
77081 int buf_use; /**< Buffers in use -- cannot alloc */
77082 atomic_t buf_alloc; /**< Buffer allocation in progress */
77083 /*@} */
77084diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77085index b1388b5..e1d1163 100644
77086--- a/include/drm/drm_crtc_helper.h
77087+++ b/include/drm/drm_crtc_helper.h
77088@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77089 struct drm_connector *connector);
77090 /* disable encoder when not in use - more explicit than dpms off */
77091 void (*disable)(struct drm_encoder *encoder);
77092-};
77093+} __no_const;
77094
77095 /**
77096 * drm_connector_helper_funcs - helper operations for connectors
77097diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77098index 940ece4..8cb727f 100644
77099--- a/include/drm/i915_pciids.h
77100+++ b/include/drm/i915_pciids.h
77101@@ -37,7 +37,7 @@
77102 */
77103 #define INTEL_VGA_DEVICE(id, info) { \
77104 0x8086, id, \
77105- ~0, ~0, \
77106+ PCI_ANY_ID, PCI_ANY_ID, \
77107 0x030000, 0xff0000, \
77108 (unsigned long) info }
77109
77110diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77111index 72dcbe8..8db58d7 100644
77112--- a/include/drm/ttm/ttm_memory.h
77113+++ b/include/drm/ttm/ttm_memory.h
77114@@ -48,7 +48,7 @@
77115
77116 struct ttm_mem_shrink {
77117 int (*do_shrink) (struct ttm_mem_shrink *);
77118-};
77119+} __no_const;
77120
77121 /**
77122 * struct ttm_mem_global - Global memory accounting structure.
77123diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77124index 49a8284..9643967 100644
77125--- a/include/drm/ttm/ttm_page_alloc.h
77126+++ b/include/drm/ttm/ttm_page_alloc.h
77127@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77128 */
77129 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77130
77131+struct device;
77132 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77133 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77134
77135diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77136index 4b840e8..155d235 100644
77137--- a/include/keys/asymmetric-subtype.h
77138+++ b/include/keys/asymmetric-subtype.h
77139@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77140 /* Verify the signature on a key of this subtype (optional) */
77141 int (*verify_signature)(const struct key *key,
77142 const struct public_key_signature *sig);
77143-};
77144+} __do_const;
77145
77146 /**
77147 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77148diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77149index c1da539..1dcec55 100644
77150--- a/include/linux/atmdev.h
77151+++ b/include/linux/atmdev.h
77152@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77153 #endif
77154
77155 struct k_atm_aal_stats {
77156-#define __HANDLE_ITEM(i) atomic_t i
77157+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77158 __AAL_STAT_ITEMS
77159 #undef __HANDLE_ITEM
77160 };
77161@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77162 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77163 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77164 struct module *owner;
77165-};
77166+} __do_const ;
77167
77168 struct atmphy_ops {
77169 int (*start)(struct atm_dev *dev);
77170diff --git a/include/linux/audit.h b/include/linux/audit.h
77171index ec1464d..833274b 100644
77172--- a/include/linux/audit.h
77173+++ b/include/linux/audit.h
77174@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77175 extern unsigned int audit_serial(void);
77176 extern int auditsc_get_stamp(struct audit_context *ctx,
77177 struct timespec *t, unsigned int *serial);
77178-extern int audit_set_loginuid(kuid_t loginuid);
77179+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77180
77181 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77182 {
77183diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77184index b4a745d..e3c0942 100644
77185--- a/include/linux/binfmts.h
77186+++ b/include/linux/binfmts.h
77187@@ -45,7 +45,7 @@ struct linux_binprm {
77188 unsigned interp_data;
77189 unsigned long loader, exec;
77190 char tcomm[TASK_COMM_LEN];
77191-};
77192+} __randomize_layout;
77193
77194 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77195 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77196@@ -74,8 +74,10 @@ struct linux_binfmt {
77197 int (*load_binary)(struct linux_binprm *);
77198 int (*load_shlib)(struct file *);
77199 int (*core_dump)(struct coredump_params *cprm);
77200+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77201+ void (*handle_mmap)(struct file *);
77202 unsigned long min_coredump; /* minimal dump size */
77203-};
77204+} __do_const __randomize_layout;
77205
77206 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77207
77208diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77209index be5fd38..d71192a 100644
77210--- a/include/linux/bitops.h
77211+++ b/include/linux/bitops.h
77212@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77213 * @word: value to rotate
77214 * @shift: bits to roll
77215 */
77216-static inline __u32 rol32(__u32 word, unsigned int shift)
77217+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77218 {
77219 return (word << shift) | (word >> (32 - shift));
77220 }
77221@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77222 * @word: value to rotate
77223 * @shift: bits to roll
77224 */
77225-static inline __u32 ror32(__u32 word, unsigned int shift)
77226+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77227 {
77228 return (word >> shift) | (word << (32 - shift));
77229 }
77230@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77231 return (__s32)(value << shift) >> shift;
77232 }
77233
77234-static inline unsigned fls_long(unsigned long l)
77235+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77236 {
77237 if (sizeof(l) == 4)
77238 return fls(l);
77239diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77240index 4afa4f8..1ed7824 100644
77241--- a/include/linux/blkdev.h
77242+++ b/include/linux/blkdev.h
77243@@ -1572,7 +1572,7 @@ struct block_device_operations {
77244 /* this callback is with swap_lock and sometimes page table lock held */
77245 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77246 struct module *owner;
77247-};
77248+} __do_const;
77249
77250 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77251 unsigned long);
77252diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77253index afc1343..9735539 100644
77254--- a/include/linux/blktrace_api.h
77255+++ b/include/linux/blktrace_api.h
77256@@ -25,7 +25,7 @@ struct blk_trace {
77257 struct dentry *dropped_file;
77258 struct dentry *msg_file;
77259 struct list_head running_list;
77260- atomic_t dropped;
77261+ atomic_unchecked_t dropped;
77262 };
77263
77264 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77265diff --git a/include/linux/cache.h b/include/linux/cache.h
77266index 17e7e82..1d7da26 100644
77267--- a/include/linux/cache.h
77268+++ b/include/linux/cache.h
77269@@ -16,6 +16,14 @@
77270 #define __read_mostly
77271 #endif
77272
77273+#ifndef __read_only
77274+#ifdef CONFIG_PAX_KERNEXEC
77275+#error KERNEXEC requires __read_only
77276+#else
77277+#define __read_only __read_mostly
77278+#endif
77279+#endif
77280+
77281 #ifndef ____cacheline_aligned
77282 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77283 #endif
77284diff --git a/include/linux/capability.h b/include/linux/capability.h
77285index a6ee1f9..e1ca49d 100644
77286--- a/include/linux/capability.h
77287+++ b/include/linux/capability.h
77288@@ -212,8 +212,13 @@ extern bool capable(int cap);
77289 extern bool ns_capable(struct user_namespace *ns, int cap);
77290 extern bool inode_capable(const struct inode *inode, int cap);
77291 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77292+extern bool capable_nolog(int cap);
77293+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77294+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77295
77296 /* audit system wants to get cap info from files as well */
77297 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77298
77299+extern int is_privileged_binary(const struct dentry *dentry);
77300+
77301 #endif /* !_LINUX_CAPABILITY_H */
77302diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77303index 8609d57..86e4d79 100644
77304--- a/include/linux/cdrom.h
77305+++ b/include/linux/cdrom.h
77306@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77307
77308 /* driver specifications */
77309 const int capability; /* capability flags */
77310- int n_minors; /* number of active minor devices */
77311 /* handle uniform packets for scsi type devices (scsi,atapi) */
77312 int (*generic_packet) (struct cdrom_device_info *,
77313 struct packet_command *);
77314diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77315index 4ce9056..86caac6 100644
77316--- a/include/linux/cleancache.h
77317+++ b/include/linux/cleancache.h
77318@@ -31,7 +31,7 @@ struct cleancache_ops {
77319 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77320 void (*invalidate_inode)(int, struct cleancache_filekey);
77321 void (*invalidate_fs)(int);
77322-};
77323+} __no_const;
77324
77325 extern struct cleancache_ops *
77326 cleancache_register_ops(struct cleancache_ops *ops);
77327diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77328index 939533d..cf0a57c 100644
77329--- a/include/linux/clk-provider.h
77330+++ b/include/linux/clk-provider.h
77331@@ -166,6 +166,7 @@ struct clk_ops {
77332 unsigned long parent_accuracy);
77333 void (*init)(struct clk_hw *hw);
77334 };
77335+typedef struct clk_ops __no_const clk_ops_no_const;
77336
77337 /**
77338 * struct clk_init_data - holds init data that's common to all clocks and is
77339diff --git a/include/linux/compat.h b/include/linux/compat.h
77340index 3f448c6..df3ce1d 100644
77341--- a/include/linux/compat.h
77342+++ b/include/linux/compat.h
77343@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77344 compat_size_t __user *len_ptr);
77345
77346 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77347-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77348+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77349 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77350 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77351 compat_ssize_t msgsz, int msgflg);
77352@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77353 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77354 compat_ulong_t addr, compat_ulong_t data);
77355 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77356- compat_long_t addr, compat_long_t data);
77357+ compat_ulong_t addr, compat_ulong_t data);
77358
77359 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77360 /*
77361diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77362index 2507fd2..55203f8 100644
77363--- a/include/linux/compiler-gcc4.h
77364+++ b/include/linux/compiler-gcc4.h
77365@@ -39,9 +39,34 @@
77366 # define __compiletime_warning(message) __attribute__((warning(message)))
77367 # define __compiletime_error(message) __attribute__((error(message)))
77368 #endif /* __CHECKER__ */
77369+
77370+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77371+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77372+#define __bos0(ptr) __bos((ptr), 0)
77373+#define __bos1(ptr) __bos((ptr), 1)
77374 #endif /* GCC_VERSION >= 40300 */
77375
77376 #if GCC_VERSION >= 40500
77377+
77378+#ifdef RANDSTRUCT_PLUGIN
77379+#define __randomize_layout __attribute__((randomize_layout))
77380+#define __no_randomize_layout __attribute__((no_randomize_layout))
77381+#endif
77382+
77383+#ifdef CONSTIFY_PLUGIN
77384+#define __no_const __attribute__((no_const))
77385+#define __do_const __attribute__((do_const))
77386+#endif
77387+
77388+#ifdef SIZE_OVERFLOW_PLUGIN
77389+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77390+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77391+#endif
77392+
77393+#ifdef LATENT_ENTROPY_PLUGIN
77394+#define __latent_entropy __attribute__((latent_entropy))
77395+#endif
77396+
77397 /*
77398 * Mark a position in code as unreachable. This can be used to
77399 * suppress control flow warnings after asm blocks that transfer
77400diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77401index 2472740..4857634 100644
77402--- a/include/linux/compiler.h
77403+++ b/include/linux/compiler.h
77404@@ -5,11 +5,14 @@
77405
77406 #ifdef __CHECKER__
77407 # define __user __attribute__((noderef, address_space(1)))
77408+# define __force_user __force __user
77409 # define __kernel __attribute__((address_space(0)))
77410+# define __force_kernel __force __kernel
77411 # define __safe __attribute__((safe))
77412 # define __force __attribute__((force))
77413 # define __nocast __attribute__((nocast))
77414 # define __iomem __attribute__((noderef, address_space(2)))
77415+# define __force_iomem __force __iomem
77416 # define __must_hold(x) __attribute__((context(x,1,1)))
77417 # define __acquires(x) __attribute__((context(x,0,1)))
77418 # define __releases(x) __attribute__((context(x,1,0)))
77419@@ -17,20 +20,37 @@
77420 # define __release(x) __context__(x,-1)
77421 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77422 # define __percpu __attribute__((noderef, address_space(3)))
77423+# define __force_percpu __force __percpu
77424 #ifdef CONFIG_SPARSE_RCU_POINTER
77425 # define __rcu __attribute__((noderef, address_space(4)))
77426+# define __force_rcu __force __rcu
77427 #else
77428 # define __rcu
77429+# define __force_rcu
77430 #endif
77431 extern void __chk_user_ptr(const volatile void __user *);
77432 extern void __chk_io_ptr(const volatile void __iomem *);
77433 #else
77434-# define __user
77435-# define __kernel
77436+# ifdef CHECKER_PLUGIN
77437+//# define __user
77438+//# define __force_user
77439+//# define __kernel
77440+//# define __force_kernel
77441+# else
77442+# ifdef STRUCTLEAK_PLUGIN
77443+# define __user __attribute__((user))
77444+# else
77445+# define __user
77446+# endif
77447+# define __force_user
77448+# define __kernel
77449+# define __force_kernel
77450+# endif
77451 # define __safe
77452 # define __force
77453 # define __nocast
77454 # define __iomem
77455+# define __force_iomem
77456 # define __chk_user_ptr(x) (void)0
77457 # define __chk_io_ptr(x) (void)0
77458 # define __builtin_warning(x, y...) (1)
77459@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77460 # define __release(x) (void)0
77461 # define __cond_lock(x,c) (c)
77462 # define __percpu
77463+# define __force_percpu
77464 # define __rcu
77465+# define __force_rcu
77466 #endif
77467
77468 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77469@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77470 # define __attribute_const__ /* unimplemented */
77471 #endif
77472
77473+#ifndef __randomize_layout
77474+# define __randomize_layout
77475+#endif
77476+
77477+#ifndef __no_randomize_layout
77478+# define __no_randomize_layout
77479+#endif
77480+
77481+#ifndef __no_const
77482+# define __no_const
77483+#endif
77484+
77485+#ifndef __do_const
77486+# define __do_const
77487+#endif
77488+
77489+#ifndef __size_overflow
77490+# define __size_overflow(...)
77491+#endif
77492+
77493+#ifndef __intentional_overflow
77494+# define __intentional_overflow(...)
77495+#endif
77496+
77497+#ifndef __latent_entropy
77498+# define __latent_entropy
77499+#endif
77500+
77501 /*
77502 * Tell gcc if a function is cold. The compiler will assume any path
77503 * directly leading to the call is unlikely.
77504@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77505 #define __cold
77506 #endif
77507
77508+#ifndef __alloc_size
77509+#define __alloc_size(...)
77510+#endif
77511+
77512+#ifndef __bos
77513+#define __bos(ptr, arg)
77514+#endif
77515+
77516+#ifndef __bos0
77517+#define __bos0(ptr)
77518+#endif
77519+
77520+#ifndef __bos1
77521+#define __bos1(ptr)
77522+#endif
77523+
77524 /* Simple shorthand for a section definition */
77525 #ifndef __section
77526 # define __section(S) __attribute__ ((__section__(#S)))
77527@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77528 * use is to mediate communication between process-level code and irq/NMI
77529 * handlers, all running on the same CPU.
77530 */
77531-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77532+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77533+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77534
77535 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77536 #ifdef CONFIG_KPROBES
77537diff --git a/include/linux/completion.h b/include/linux/completion.h
77538index 5d5aaae..0ea9b84 100644
77539--- a/include/linux/completion.h
77540+++ b/include/linux/completion.h
77541@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77542
77543 extern void wait_for_completion(struct completion *);
77544 extern void wait_for_completion_io(struct completion *);
77545-extern int wait_for_completion_interruptible(struct completion *x);
77546-extern int wait_for_completion_killable(struct completion *x);
77547+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77548+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77549 extern unsigned long wait_for_completion_timeout(struct completion *x,
77550- unsigned long timeout);
77551+ unsigned long timeout) __intentional_overflow(-1);
77552 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77553- unsigned long timeout);
77554+ unsigned long timeout) __intentional_overflow(-1);
77555 extern long wait_for_completion_interruptible_timeout(
77556- struct completion *x, unsigned long timeout);
77557+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77558 extern long wait_for_completion_killable_timeout(
77559- struct completion *x, unsigned long timeout);
77560+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77561 extern bool try_wait_for_completion(struct completion *x);
77562 extern bool completion_done(struct completion *x);
77563
77564diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77565index 34025df..d94bbbc 100644
77566--- a/include/linux/configfs.h
77567+++ b/include/linux/configfs.h
77568@@ -125,7 +125,7 @@ struct configfs_attribute {
77569 const char *ca_name;
77570 struct module *ca_owner;
77571 umode_t ca_mode;
77572-};
77573+} __do_const;
77574
77575 /*
77576 * Users often need to create attribute structures for their configurable
77577diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77578index 4d89e0e..5281847 100644
77579--- a/include/linux/cpufreq.h
77580+++ b/include/linux/cpufreq.h
77581@@ -191,6 +191,7 @@ struct global_attr {
77582 ssize_t (*store)(struct kobject *a, struct attribute *b,
77583 const char *c, size_t count);
77584 };
77585+typedef struct global_attr __no_const global_attr_no_const;
77586
77587 #define define_one_global_ro(_name) \
77588 static struct global_attr _name = \
77589@@ -232,7 +233,7 @@ struct cpufreq_driver {
77590 bool boost_supported;
77591 bool boost_enabled;
77592 int (*set_boost) (int state);
77593-};
77594+} __do_const;
77595
77596 /* flags */
77597 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77598diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77599index 50fcbb0..9d2dbd9 100644
77600--- a/include/linux/cpuidle.h
77601+++ b/include/linux/cpuidle.h
77602@@ -50,7 +50,8 @@ struct cpuidle_state {
77603 int index);
77604
77605 int (*enter_dead) (struct cpuidle_device *dev, int index);
77606-};
77607+} __do_const;
77608+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77609
77610 /* Idle State Flags */
77611 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77612@@ -192,7 +193,7 @@ struct cpuidle_governor {
77613 void (*reflect) (struct cpuidle_device *dev, int index);
77614
77615 struct module *owner;
77616-};
77617+} __do_const;
77618
77619 #ifdef CONFIG_CPU_IDLE
77620 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77621diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77622index d08e4d2..95fad61 100644
77623--- a/include/linux/cpumask.h
77624+++ b/include/linux/cpumask.h
77625@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77626 }
77627
77628 /* Valid inputs for n are -1 and 0. */
77629-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77630+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77631 {
77632 return n+1;
77633 }
77634
77635-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77636+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77637 {
77638 return n+1;
77639 }
77640
77641-static inline unsigned int cpumask_next_and(int n,
77642+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77643 const struct cpumask *srcp,
77644 const struct cpumask *andp)
77645 {
77646@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77647 *
77648 * Returns >= nr_cpu_ids if no further cpus set.
77649 */
77650-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77651+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77652 {
77653 /* -1 is a legal arg here. */
77654 if (n != -1)
77655@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77656 *
77657 * Returns >= nr_cpu_ids if no further cpus unset.
77658 */
77659-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77660+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77661 {
77662 /* -1 is a legal arg here. */
77663 if (n != -1)
77664@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77665 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77666 }
77667
77668-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77669+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77670 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77671
77672 /**
77673diff --git a/include/linux/cred.h b/include/linux/cred.h
77674index 04421e8..117e17a 100644
77675--- a/include/linux/cred.h
77676+++ b/include/linux/cred.h
77677@@ -35,7 +35,7 @@ struct group_info {
77678 int nblocks;
77679 kgid_t small_block[NGROUPS_SMALL];
77680 kgid_t *blocks[0];
77681-};
77682+} __randomize_layout;
77683
77684 /**
77685 * get_group_info - Get a reference to a group info structure
77686@@ -136,7 +136,7 @@ struct cred {
77687 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77688 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77689 struct rcu_head rcu; /* RCU deletion hook */
77690-};
77691+} __randomize_layout;
77692
77693 extern void __put_cred(struct cred *);
77694 extern void exit_creds(struct task_struct *);
77695@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77696 static inline void validate_process_creds(void)
77697 {
77698 }
77699+static inline void validate_task_creds(struct task_struct *task)
77700+{
77701+}
77702 #endif
77703
77704 /**
77705diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77706index b92eadf..b4ecdc1 100644
77707--- a/include/linux/crypto.h
77708+++ b/include/linux/crypto.h
77709@@ -373,7 +373,7 @@ struct cipher_tfm {
77710 const u8 *key, unsigned int keylen);
77711 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77712 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77713-};
77714+} __no_const;
77715
77716 struct hash_tfm {
77717 int (*init)(struct hash_desc *desc);
77718@@ -394,13 +394,13 @@ struct compress_tfm {
77719 int (*cot_decompress)(struct crypto_tfm *tfm,
77720 const u8 *src, unsigned int slen,
77721 u8 *dst, unsigned int *dlen);
77722-};
77723+} __no_const;
77724
77725 struct rng_tfm {
77726 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77727 unsigned int dlen);
77728 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77729-};
77730+} __no_const;
77731
77732 #define crt_ablkcipher crt_u.ablkcipher
77733 #define crt_aead crt_u.aead
77734diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77735index 653589e..4ef254a 100644
77736--- a/include/linux/ctype.h
77737+++ b/include/linux/ctype.h
77738@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77739 * Fast implementation of tolower() for internal usage. Do not use in your
77740 * code.
77741 */
77742-static inline char _tolower(const char c)
77743+static inline unsigned char _tolower(const unsigned char c)
77744 {
77745 return c | 0x20;
77746 }
77747diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77748index bf72e9a..4ca7927 100644
77749--- a/include/linux/dcache.h
77750+++ b/include/linux/dcache.h
77751@@ -133,7 +133,7 @@ struct dentry {
77752 } d_u;
77753 struct list_head d_subdirs; /* our children */
77754 struct hlist_node d_alias; /* inode alias list */
77755-};
77756+} __randomize_layout;
77757
77758 /*
77759 * dentry->d_lock spinlock nesting subclasses:
77760diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77761index 7925bf0..d5143d2 100644
77762--- a/include/linux/decompress/mm.h
77763+++ b/include/linux/decompress/mm.h
77764@@ -77,7 +77,7 @@ static void free(void *where)
77765 * warnings when not needed (indeed large_malloc / large_free are not
77766 * needed by inflate */
77767
77768-#define malloc(a) kmalloc(a, GFP_KERNEL)
77769+#define malloc(a) kmalloc((a), GFP_KERNEL)
77770 #define free(a) kfree(a)
77771
77772 #define large_malloc(a) vmalloc(a)
77773diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77774index d48dc00..211ee54 100644
77775--- a/include/linux/devfreq.h
77776+++ b/include/linux/devfreq.h
77777@@ -114,7 +114,7 @@ struct devfreq_governor {
77778 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77779 int (*event_handler)(struct devfreq *devfreq,
77780 unsigned int event, void *data);
77781-};
77782+} __do_const;
77783
77784 /**
77785 * struct devfreq - Device devfreq structure
77786diff --git a/include/linux/device.h b/include/linux/device.h
77787index 952b010..d5b7691 100644
77788--- a/include/linux/device.h
77789+++ b/include/linux/device.h
77790@@ -310,7 +310,7 @@ struct subsys_interface {
77791 struct list_head node;
77792 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77793 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77794-};
77795+} __do_const;
77796
77797 int subsys_interface_register(struct subsys_interface *sif);
77798 void subsys_interface_unregister(struct subsys_interface *sif);
77799@@ -506,7 +506,7 @@ struct device_type {
77800 void (*release)(struct device *dev);
77801
77802 const struct dev_pm_ops *pm;
77803-};
77804+} __do_const;
77805
77806 /* interface for exporting device attributes */
77807 struct device_attribute {
77808@@ -516,11 +516,12 @@ struct device_attribute {
77809 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77810 const char *buf, size_t count);
77811 };
77812+typedef struct device_attribute __no_const device_attribute_no_const;
77813
77814 struct dev_ext_attribute {
77815 struct device_attribute attr;
77816 void *var;
77817-};
77818+} __do_const;
77819
77820 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77821 char *buf);
77822diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77823index fd4aee2..1f28db9 100644
77824--- a/include/linux/dma-mapping.h
77825+++ b/include/linux/dma-mapping.h
77826@@ -54,7 +54,7 @@ struct dma_map_ops {
77827 u64 (*get_required_mask)(struct device *dev);
77828 #endif
77829 int is_phys;
77830-};
77831+} __do_const;
77832
77833 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77834
77835diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77836index c5c92d5..6a5c2b2 100644
77837--- a/include/linux/dmaengine.h
77838+++ b/include/linux/dmaengine.h
77839@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
77840 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77841 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77842
77843-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77844+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77845 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77846-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77847+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77848 struct dma_pinned_list *pinned_list, struct page *page,
77849 unsigned int offset, size_t len);
77850
77851diff --git a/include/linux/efi.h b/include/linux/efi.h
77852index 0a819e7..8ed47f1 100644
77853--- a/include/linux/efi.h
77854+++ b/include/linux/efi.h
77855@@ -768,6 +768,7 @@ struct efivar_operations {
77856 efi_set_variable_t *set_variable;
77857 efi_query_variable_store_t *query_variable_store;
77858 };
77859+typedef struct efivar_operations __no_const efivar_operations_no_const;
77860
77861 struct efivars {
77862 /*
77863diff --git a/include/linux/elf.h b/include/linux/elf.h
77864index 67a5fa7..b817372 100644
77865--- a/include/linux/elf.h
77866+++ b/include/linux/elf.h
77867@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77868 #define elf_note elf32_note
77869 #define elf_addr_t Elf32_Off
77870 #define Elf_Half Elf32_Half
77871+#define elf_dyn Elf32_Dyn
77872
77873 #else
77874
77875@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77876 #define elf_note elf64_note
77877 #define elf_addr_t Elf64_Off
77878 #define Elf_Half Elf64_Half
77879+#define elf_dyn Elf64_Dyn
77880
77881 #endif
77882
77883diff --git a/include/linux/err.h b/include/linux/err.h
77884index 15f92e0..e825a8e 100644
77885--- a/include/linux/err.h
77886+++ b/include/linux/err.h
77887@@ -19,12 +19,12 @@
77888
77889 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77890
77891-static inline void * __must_check ERR_PTR(long error)
77892+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77893 {
77894 return (void *) error;
77895 }
77896
77897-static inline long __must_check PTR_ERR(__force const void *ptr)
77898+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77899 {
77900 return (long) ptr;
77901 }
77902diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77903index 21c59af..6057a03 100644
77904--- a/include/linux/extcon.h
77905+++ b/include/linux/extcon.h
77906@@ -135,7 +135,7 @@ struct extcon_dev {
77907 /* /sys/class/extcon/.../mutually_exclusive/... */
77908 struct attribute_group attr_g_muex;
77909 struct attribute **attrs_muex;
77910- struct device_attribute *d_attrs_muex;
77911+ device_attribute_no_const *d_attrs_muex;
77912 };
77913
77914 /**
77915diff --git a/include/linux/fb.h b/include/linux/fb.h
77916index fe6ac95..898d41d 100644
77917--- a/include/linux/fb.h
77918+++ b/include/linux/fb.h
77919@@ -304,7 +304,7 @@ struct fb_ops {
77920 /* called at KDB enter and leave time to prepare the console */
77921 int (*fb_debug_enter)(struct fb_info *info);
77922 int (*fb_debug_leave)(struct fb_info *info);
77923-};
77924+} __do_const;
77925
77926 #ifdef CONFIG_FB_TILEBLITTING
77927 #define FB_TILE_CURSOR_NONE 0
77928diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77929index 70e8e21..1939916 100644
77930--- a/include/linux/fdtable.h
77931+++ b/include/linux/fdtable.h
77932@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77933 void put_files_struct(struct files_struct *fs);
77934 void reset_files_struct(struct files_struct *);
77935 int unshare_files(struct files_struct **);
77936-struct files_struct *dup_fd(struct files_struct *, int *);
77937+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77938 void do_close_on_exec(struct files_struct *);
77939 int iterate_fd(struct files_struct *, unsigned,
77940 int (*)(const void *, struct file *, unsigned),
77941diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77942index 8293262..2b3b8bd 100644
77943--- a/include/linux/frontswap.h
77944+++ b/include/linux/frontswap.h
77945@@ -11,7 +11,7 @@ struct frontswap_ops {
77946 int (*load)(unsigned, pgoff_t, struct page *);
77947 void (*invalidate_page)(unsigned, pgoff_t);
77948 void (*invalidate_area)(unsigned);
77949-};
77950+} __no_const;
77951
77952 extern bool frontswap_enabled;
77953 extern struct frontswap_ops *
77954diff --git a/include/linux/fs.h b/include/linux/fs.h
77955index 23b2a35..8764ab7 100644
77956--- a/include/linux/fs.h
77957+++ b/include/linux/fs.h
77958@@ -426,7 +426,7 @@ struct address_space {
77959 spinlock_t private_lock; /* for use by the address_space */
77960 struct list_head private_list; /* ditto */
77961 void *private_data; /* ditto */
77962-} __attribute__((aligned(sizeof(long))));
77963+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77964 /*
77965 * On most architectures that alignment is already the case; but
77966 * must be enforced here for CRIS, to let the least significant bit
77967@@ -469,7 +469,7 @@ struct block_device {
77968 int bd_fsfreeze_count;
77969 /* Mutex for freeze */
77970 struct mutex bd_fsfreeze_mutex;
77971-};
77972+} __randomize_layout;
77973
77974 /*
77975 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77976@@ -613,7 +613,7 @@ struct inode {
77977 atomic_t i_readcount; /* struct files open RO */
77978 #endif
77979 void *i_private; /* fs or device private pointer */
77980-};
77981+} __randomize_layout;
77982
77983 static inline int inode_unhashed(struct inode *inode)
77984 {
77985@@ -812,7 +812,7 @@ struct file {
77986 #ifdef CONFIG_DEBUG_WRITECOUNT
77987 unsigned long f_mnt_write_state;
77988 #endif
77989-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
77990+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
77991
77992 struct file_handle {
77993 __u32 handle_bytes;
77994@@ -982,7 +982,7 @@ struct file_lock {
77995 int state; /* state of grant or error if -ve */
77996 } afs;
77997 } fl_u;
77998-};
77999+} __randomize_layout;
78000
78001 /* The following constant reflects the upper bound of the file/locking space */
78002 #ifndef OFFSET_MAX
78003@@ -1329,7 +1329,7 @@ struct super_block {
78004 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78005 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78006 struct rcu_head rcu;
78007-};
78008+} __randomize_layout;
78009
78010 extern struct timespec current_fs_time(struct super_block *sb);
78011
78012@@ -1551,7 +1551,8 @@ struct file_operations {
78013 long (*fallocate)(struct file *file, int mode, loff_t offset,
78014 loff_t len);
78015 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78016-};
78017+} __do_const __randomize_layout;
78018+typedef struct file_operations __no_const file_operations_no_const;
78019
78020 struct inode_operations {
78021 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78022@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78023 return !IS_DEADDIR(inode);
78024 }
78025
78026+static inline bool is_sidechannel_device(const struct inode *inode)
78027+{
78028+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78029+ umode_t mode = inode->i_mode;
78030+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78031+#else
78032+ return false;
78033+#endif
78034+}
78035+
78036 #endif /* _LINUX_FS_H */
78037diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78038index 0efc3e6..fd23610 100644
78039--- a/include/linux/fs_struct.h
78040+++ b/include/linux/fs_struct.h
78041@@ -6,13 +6,13 @@
78042 #include <linux/seqlock.h>
78043
78044 struct fs_struct {
78045- int users;
78046+ atomic_t users;
78047 spinlock_t lock;
78048 seqcount_t seq;
78049 int umask;
78050 int in_exec;
78051 struct path root, pwd;
78052-};
78053+} __randomize_layout;
78054
78055 extern struct kmem_cache *fs_cachep;
78056
78057diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78058index 7714849..a4a5c7a 100644
78059--- a/include/linux/fscache-cache.h
78060+++ b/include/linux/fscache-cache.h
78061@@ -113,7 +113,7 @@ struct fscache_operation {
78062 fscache_operation_release_t release;
78063 };
78064
78065-extern atomic_t fscache_op_debug_id;
78066+extern atomic_unchecked_t fscache_op_debug_id;
78067 extern void fscache_op_work_func(struct work_struct *work);
78068
78069 extern void fscache_enqueue_operation(struct fscache_operation *);
78070@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78071 INIT_WORK(&op->work, fscache_op_work_func);
78072 atomic_set(&op->usage, 1);
78073 op->state = FSCACHE_OP_ST_INITIALISED;
78074- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78075+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78076 op->processor = processor;
78077 op->release = release;
78078 INIT_LIST_HEAD(&op->pend_link);
78079diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78080index 115bb81..e7b812b 100644
78081--- a/include/linux/fscache.h
78082+++ b/include/linux/fscache.h
78083@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78084 * - this is mandatory for any object that may have data
78085 */
78086 void (*now_uncached)(void *cookie_netfs_data);
78087-};
78088+} __do_const;
78089
78090 /*
78091 * fscache cached network filesystem type
78092diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78093index 1c804b0..1432c2b 100644
78094--- a/include/linux/fsnotify.h
78095+++ b/include/linux/fsnotify.h
78096@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78097 struct inode *inode = file_inode(file);
78098 __u32 mask = FS_ACCESS;
78099
78100+ if (is_sidechannel_device(inode))
78101+ return;
78102+
78103 if (S_ISDIR(inode->i_mode))
78104 mask |= FS_ISDIR;
78105
78106@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78107 struct inode *inode = file_inode(file);
78108 __u32 mask = FS_MODIFY;
78109
78110+ if (is_sidechannel_device(inode))
78111+ return;
78112+
78113 if (S_ISDIR(inode->i_mode))
78114 mask |= FS_ISDIR;
78115
78116@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78117 */
78118 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78119 {
78120- return kstrdup(name, GFP_KERNEL);
78121+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78122 }
78123
78124 /*
78125diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78126index 9f3c275..8bdff5d 100644
78127--- a/include/linux/genhd.h
78128+++ b/include/linux/genhd.h
78129@@ -194,7 +194,7 @@ struct gendisk {
78130 struct kobject *slave_dir;
78131
78132 struct timer_rand_state *random;
78133- atomic_t sync_io; /* RAID */
78134+ atomic_unchecked_t sync_io; /* RAID */
78135 struct disk_events *ev;
78136 #ifdef CONFIG_BLK_DEV_INTEGRITY
78137 struct blk_integrity *integrity;
78138@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78139 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78140
78141 /* drivers/char/random.c */
78142-extern void add_disk_randomness(struct gendisk *disk);
78143+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78144 extern void rand_initialize_disk(struct gendisk *disk);
78145
78146 static inline sector_t get_start_sect(struct block_device *bdev)
78147diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78148index c0894dd..2fbf10c 100644
78149--- a/include/linux/genl_magic_func.h
78150+++ b/include/linux/genl_magic_func.h
78151@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78152 },
78153
78154 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78155-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78156+static struct genl_ops ZZZ_genl_ops[] = {
78157 #include GENL_MAGIC_INCLUDE_FILE
78158 };
78159
78160diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78161index 39b81dc..819dc51 100644
78162--- a/include/linux/gfp.h
78163+++ b/include/linux/gfp.h
78164@@ -36,6 +36,13 @@ struct vm_area_struct;
78165 #define ___GFP_NO_KSWAPD 0x400000u
78166 #define ___GFP_OTHER_NODE 0x800000u
78167 #define ___GFP_WRITE 0x1000000u
78168+
78169+#ifdef CONFIG_PAX_USERCOPY_SLABS
78170+#define ___GFP_USERCOPY 0x2000000u
78171+#else
78172+#define ___GFP_USERCOPY 0
78173+#endif
78174+
78175 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78176
78177 /*
78178@@ -93,6 +100,7 @@ struct vm_area_struct;
78179 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78180 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78181 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78182+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78183
78184 /*
78185 * This may seem redundant, but it's a way of annotating false positives vs.
78186@@ -100,7 +108,7 @@ struct vm_area_struct;
78187 */
78188 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78189
78190-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78191+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78192 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78193
78194 /* This equals 0, but use constants in case they ever change */
78195@@ -158,6 +166,8 @@ struct vm_area_struct;
78196 /* 4GB DMA on some platforms */
78197 #define GFP_DMA32 __GFP_DMA32
78198
78199+#define GFP_USERCOPY __GFP_USERCOPY
78200+
78201 /* Convert GFP flags to their corresponding migrate type */
78202 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78203 {
78204diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78205new file mode 100644
78206index 0000000..edb2cb6
78207--- /dev/null
78208+++ b/include/linux/gracl.h
78209@@ -0,0 +1,340 @@
78210+#ifndef GR_ACL_H
78211+#define GR_ACL_H
78212+
78213+#include <linux/grdefs.h>
78214+#include <linux/resource.h>
78215+#include <linux/capability.h>
78216+#include <linux/dcache.h>
78217+#include <asm/resource.h>
78218+
78219+/* Major status information */
78220+
78221+#define GR_VERSION "grsecurity 3.0"
78222+#define GRSECURITY_VERSION 0x3000
78223+
78224+enum {
78225+ GR_SHUTDOWN = 0,
78226+ GR_ENABLE = 1,
78227+ GR_SPROLE = 2,
78228+ GR_OLDRELOAD = 3,
78229+ GR_SEGVMOD = 4,
78230+ GR_STATUS = 5,
78231+ GR_UNSPROLE = 6,
78232+ GR_PASSSET = 7,
78233+ GR_SPROLEPAM = 8,
78234+ GR_RELOAD = 9,
78235+};
78236+
78237+/* Password setup definitions
78238+ * kernel/grhash.c */
78239+enum {
78240+ GR_PW_LEN = 128,
78241+ GR_SALT_LEN = 16,
78242+ GR_SHA_LEN = 32,
78243+};
78244+
78245+enum {
78246+ GR_SPROLE_LEN = 64,
78247+};
78248+
78249+enum {
78250+ GR_NO_GLOB = 0,
78251+ GR_REG_GLOB,
78252+ GR_CREATE_GLOB
78253+};
78254+
78255+#define GR_NLIMITS 32
78256+
78257+/* Begin Data Structures */
78258+
78259+struct sprole_pw {
78260+ unsigned char *rolename;
78261+ unsigned char salt[GR_SALT_LEN];
78262+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78263+};
78264+
78265+struct name_entry {
78266+ __u32 key;
78267+ ino_t inode;
78268+ dev_t device;
78269+ char *name;
78270+ __u16 len;
78271+ __u8 deleted;
78272+ struct name_entry *prev;
78273+ struct name_entry *next;
78274+};
78275+
78276+struct inodev_entry {
78277+ struct name_entry *nentry;
78278+ struct inodev_entry *prev;
78279+ struct inodev_entry *next;
78280+};
78281+
78282+struct acl_role_db {
78283+ struct acl_role_label **r_hash;
78284+ __u32 r_size;
78285+};
78286+
78287+struct inodev_db {
78288+ struct inodev_entry **i_hash;
78289+ __u32 i_size;
78290+};
78291+
78292+struct name_db {
78293+ struct name_entry **n_hash;
78294+ __u32 n_size;
78295+};
78296+
78297+struct crash_uid {
78298+ uid_t uid;
78299+ unsigned long expires;
78300+};
78301+
78302+struct gr_hash_struct {
78303+ void **table;
78304+ void **nametable;
78305+ void *first;
78306+ __u32 table_size;
78307+ __u32 used_size;
78308+ int type;
78309+};
78310+
78311+/* Userspace Grsecurity ACL data structures */
78312+
78313+struct acl_subject_label {
78314+ char *filename;
78315+ ino_t inode;
78316+ dev_t device;
78317+ __u32 mode;
78318+ kernel_cap_t cap_mask;
78319+ kernel_cap_t cap_lower;
78320+ kernel_cap_t cap_invert_audit;
78321+
78322+ struct rlimit res[GR_NLIMITS];
78323+ __u32 resmask;
78324+
78325+ __u8 user_trans_type;
78326+ __u8 group_trans_type;
78327+ uid_t *user_transitions;
78328+ gid_t *group_transitions;
78329+ __u16 user_trans_num;
78330+ __u16 group_trans_num;
78331+
78332+ __u32 sock_families[2];
78333+ __u32 ip_proto[8];
78334+ __u32 ip_type;
78335+ struct acl_ip_label **ips;
78336+ __u32 ip_num;
78337+ __u32 inaddr_any_override;
78338+
78339+ __u32 crashes;
78340+ unsigned long expires;
78341+
78342+ struct acl_subject_label *parent_subject;
78343+ struct gr_hash_struct *hash;
78344+ struct acl_subject_label *prev;
78345+ struct acl_subject_label *next;
78346+
78347+ struct acl_object_label **obj_hash;
78348+ __u32 obj_hash_size;
78349+ __u16 pax_flags;
78350+};
78351+
78352+struct role_allowed_ip {
78353+ __u32 addr;
78354+ __u32 netmask;
78355+
78356+ struct role_allowed_ip *prev;
78357+ struct role_allowed_ip *next;
78358+};
78359+
78360+struct role_transition {
78361+ char *rolename;
78362+
78363+ struct role_transition *prev;
78364+ struct role_transition *next;
78365+};
78366+
78367+struct acl_role_label {
78368+ char *rolename;
78369+ uid_t uidgid;
78370+ __u16 roletype;
78371+
78372+ __u16 auth_attempts;
78373+ unsigned long expires;
78374+
78375+ struct acl_subject_label *root_label;
78376+ struct gr_hash_struct *hash;
78377+
78378+ struct acl_role_label *prev;
78379+ struct acl_role_label *next;
78380+
78381+ struct role_transition *transitions;
78382+ struct role_allowed_ip *allowed_ips;
78383+ uid_t *domain_children;
78384+ __u16 domain_child_num;
78385+
78386+ umode_t umask;
78387+
78388+ struct acl_subject_label **subj_hash;
78389+ __u32 subj_hash_size;
78390+};
78391+
78392+struct user_acl_role_db {
78393+ struct acl_role_label **r_table;
78394+ __u32 num_pointers; /* Number of allocations to track */
78395+ __u32 num_roles; /* Number of roles */
78396+ __u32 num_domain_children; /* Number of domain children */
78397+ __u32 num_subjects; /* Number of subjects */
78398+ __u32 num_objects; /* Number of objects */
78399+};
78400+
78401+struct acl_object_label {
78402+ char *filename;
78403+ ino_t inode;
78404+ dev_t device;
78405+ __u32 mode;
78406+
78407+ struct acl_subject_label *nested;
78408+ struct acl_object_label *globbed;
78409+
78410+ /* next two structures not used */
78411+
78412+ struct acl_object_label *prev;
78413+ struct acl_object_label *next;
78414+};
78415+
78416+struct acl_ip_label {
78417+ char *iface;
78418+ __u32 addr;
78419+ __u32 netmask;
78420+ __u16 low, high;
78421+ __u8 mode;
78422+ __u32 type;
78423+ __u32 proto[8];
78424+
78425+ /* next two structures not used */
78426+
78427+ struct acl_ip_label *prev;
78428+ struct acl_ip_label *next;
78429+};
78430+
78431+struct gr_arg {
78432+ struct user_acl_role_db role_db;
78433+ unsigned char pw[GR_PW_LEN];
78434+ unsigned char salt[GR_SALT_LEN];
78435+ unsigned char sum[GR_SHA_LEN];
78436+ unsigned char sp_role[GR_SPROLE_LEN];
78437+ struct sprole_pw *sprole_pws;
78438+ dev_t segv_device;
78439+ ino_t segv_inode;
78440+ uid_t segv_uid;
78441+ __u16 num_sprole_pws;
78442+ __u16 mode;
78443+};
78444+
78445+struct gr_arg_wrapper {
78446+ struct gr_arg *arg;
78447+ __u32 version;
78448+ __u32 size;
78449+};
78450+
78451+struct subject_map {
78452+ struct acl_subject_label *user;
78453+ struct acl_subject_label *kernel;
78454+ struct subject_map *prev;
78455+ struct subject_map *next;
78456+};
78457+
78458+struct acl_subj_map_db {
78459+ struct subject_map **s_hash;
78460+ __u32 s_size;
78461+};
78462+
78463+struct gr_policy_state {
78464+ struct sprole_pw **acl_special_roles;
78465+ __u16 num_sprole_pws;
78466+ struct acl_role_label *kernel_role;
78467+ struct acl_role_label *role_list;
78468+ struct acl_role_label *default_role;
78469+ struct acl_role_db acl_role_set;
78470+ struct acl_subj_map_db subj_map_set;
78471+ struct name_db name_set;
78472+ struct inodev_db inodev_set;
78473+};
78474+
78475+struct gr_alloc_state {
78476+ unsigned long alloc_stack_next;
78477+ unsigned long alloc_stack_size;
78478+ void **alloc_stack;
78479+};
78480+
78481+struct gr_reload_state {
78482+ struct gr_policy_state oldpolicy;
78483+ struct gr_alloc_state oldalloc;
78484+ struct gr_policy_state newpolicy;
78485+ struct gr_alloc_state newalloc;
78486+ struct gr_policy_state *oldpolicy_ptr;
78487+ struct gr_alloc_state *oldalloc_ptr;
78488+ unsigned char oldmode;
78489+};
78490+
78491+/* End Data Structures Section */
78492+
78493+/* Hash functions generated by empirical testing by Brad Spengler
78494+ Makes good use of the low bits of the inode. Generally 0-1 times
78495+ in loop for successful match. 0-3 for unsuccessful match.
78496+ Shift/add algorithm with modulus of table size and an XOR*/
78497+
78498+static __inline__ unsigned int
78499+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78500+{
78501+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78502+}
78503+
78504+ static __inline__ unsigned int
78505+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78506+{
78507+ return ((const unsigned long)userp % sz);
78508+}
78509+
78510+static __inline__ unsigned int
78511+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78512+{
78513+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78514+}
78515+
78516+static __inline__ unsigned int
78517+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78518+{
78519+ return full_name_hash((const unsigned char *)name, len) % sz;
78520+}
78521+
78522+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78523+ subj = NULL; \
78524+ iter = 0; \
78525+ while (iter < role->subj_hash_size) { \
78526+ if (subj == NULL) \
78527+ subj = role->subj_hash[iter]; \
78528+ if (subj == NULL) { \
78529+ iter++; \
78530+ continue; \
78531+ }
78532+
78533+#define FOR_EACH_SUBJECT_END(subj,iter) \
78534+ subj = subj->next; \
78535+ if (subj == NULL) \
78536+ iter++; \
78537+ }
78538+
78539+
78540+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78541+ subj = role->hash->first; \
78542+ while (subj != NULL) {
78543+
78544+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78545+ subj = subj->next; \
78546+ }
78547+
78548+#endif
78549+
78550diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78551new file mode 100644
78552index 0000000..33ebd1f
78553--- /dev/null
78554+++ b/include/linux/gracl_compat.h
78555@@ -0,0 +1,156 @@
78556+#ifndef GR_ACL_COMPAT_H
78557+#define GR_ACL_COMPAT_H
78558+
78559+#include <linux/resource.h>
78560+#include <asm/resource.h>
78561+
78562+struct sprole_pw_compat {
78563+ compat_uptr_t rolename;
78564+ unsigned char salt[GR_SALT_LEN];
78565+ unsigned char sum[GR_SHA_LEN];
78566+};
78567+
78568+struct gr_hash_struct_compat {
78569+ compat_uptr_t table;
78570+ compat_uptr_t nametable;
78571+ compat_uptr_t first;
78572+ __u32 table_size;
78573+ __u32 used_size;
78574+ int type;
78575+};
78576+
78577+struct acl_subject_label_compat {
78578+ compat_uptr_t filename;
78579+ compat_ino_t inode;
78580+ __u32 device;
78581+ __u32 mode;
78582+ kernel_cap_t cap_mask;
78583+ kernel_cap_t cap_lower;
78584+ kernel_cap_t cap_invert_audit;
78585+
78586+ struct compat_rlimit res[GR_NLIMITS];
78587+ __u32 resmask;
78588+
78589+ __u8 user_trans_type;
78590+ __u8 group_trans_type;
78591+ compat_uptr_t user_transitions;
78592+ compat_uptr_t group_transitions;
78593+ __u16 user_trans_num;
78594+ __u16 group_trans_num;
78595+
78596+ __u32 sock_families[2];
78597+ __u32 ip_proto[8];
78598+ __u32 ip_type;
78599+ compat_uptr_t ips;
78600+ __u32 ip_num;
78601+ __u32 inaddr_any_override;
78602+
78603+ __u32 crashes;
78604+ compat_ulong_t expires;
78605+
78606+ compat_uptr_t parent_subject;
78607+ compat_uptr_t hash;
78608+ compat_uptr_t prev;
78609+ compat_uptr_t next;
78610+
78611+ compat_uptr_t obj_hash;
78612+ __u32 obj_hash_size;
78613+ __u16 pax_flags;
78614+};
78615+
78616+struct role_allowed_ip_compat {
78617+ __u32 addr;
78618+ __u32 netmask;
78619+
78620+ compat_uptr_t prev;
78621+ compat_uptr_t next;
78622+};
78623+
78624+struct role_transition_compat {
78625+ compat_uptr_t rolename;
78626+
78627+ compat_uptr_t prev;
78628+ compat_uptr_t next;
78629+};
78630+
78631+struct acl_role_label_compat {
78632+ compat_uptr_t rolename;
78633+ uid_t uidgid;
78634+ __u16 roletype;
78635+
78636+ __u16 auth_attempts;
78637+ compat_ulong_t expires;
78638+
78639+ compat_uptr_t root_label;
78640+ compat_uptr_t hash;
78641+
78642+ compat_uptr_t prev;
78643+ compat_uptr_t next;
78644+
78645+ compat_uptr_t transitions;
78646+ compat_uptr_t allowed_ips;
78647+ compat_uptr_t domain_children;
78648+ __u16 domain_child_num;
78649+
78650+ umode_t umask;
78651+
78652+ compat_uptr_t subj_hash;
78653+ __u32 subj_hash_size;
78654+};
78655+
78656+struct user_acl_role_db_compat {
78657+ compat_uptr_t r_table;
78658+ __u32 num_pointers;
78659+ __u32 num_roles;
78660+ __u32 num_domain_children;
78661+ __u32 num_subjects;
78662+ __u32 num_objects;
78663+};
78664+
78665+struct acl_object_label_compat {
78666+ compat_uptr_t filename;
78667+ compat_ino_t inode;
78668+ __u32 device;
78669+ __u32 mode;
78670+
78671+ compat_uptr_t nested;
78672+ compat_uptr_t globbed;
78673+
78674+ compat_uptr_t prev;
78675+ compat_uptr_t next;
78676+};
78677+
78678+struct acl_ip_label_compat {
78679+ compat_uptr_t iface;
78680+ __u32 addr;
78681+ __u32 netmask;
78682+ __u16 low, high;
78683+ __u8 mode;
78684+ __u32 type;
78685+ __u32 proto[8];
78686+
78687+ compat_uptr_t prev;
78688+ compat_uptr_t next;
78689+};
78690+
78691+struct gr_arg_compat {
78692+ struct user_acl_role_db_compat role_db;
78693+ unsigned char pw[GR_PW_LEN];
78694+ unsigned char salt[GR_SALT_LEN];
78695+ unsigned char sum[GR_SHA_LEN];
78696+ unsigned char sp_role[GR_SPROLE_LEN];
78697+ compat_uptr_t sprole_pws;
78698+ __u32 segv_device;
78699+ compat_ino_t segv_inode;
78700+ uid_t segv_uid;
78701+ __u16 num_sprole_pws;
78702+ __u16 mode;
78703+};
78704+
78705+struct gr_arg_wrapper_compat {
78706+ compat_uptr_t arg;
78707+ __u32 version;
78708+ __u32 size;
78709+};
78710+
78711+#endif
78712diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78713new file mode 100644
78714index 0000000..323ecf2
78715--- /dev/null
78716+++ b/include/linux/gralloc.h
78717@@ -0,0 +1,9 @@
78718+#ifndef __GRALLOC_H
78719+#define __GRALLOC_H
78720+
78721+void acl_free_all(void);
78722+int acl_alloc_stack_init(unsigned long size);
78723+void *acl_alloc(unsigned long len);
78724+void *acl_alloc_num(unsigned long num, unsigned long len);
78725+
78726+#endif
78727diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78728new file mode 100644
78729index 0000000..be66033
78730--- /dev/null
78731+++ b/include/linux/grdefs.h
78732@@ -0,0 +1,140 @@
78733+#ifndef GRDEFS_H
78734+#define GRDEFS_H
78735+
78736+/* Begin grsecurity status declarations */
78737+
78738+enum {
78739+ GR_READY = 0x01,
78740+ GR_STATUS_INIT = 0x00 // disabled state
78741+};
78742+
78743+/* Begin ACL declarations */
78744+
78745+/* Role flags */
78746+
78747+enum {
78748+ GR_ROLE_USER = 0x0001,
78749+ GR_ROLE_GROUP = 0x0002,
78750+ GR_ROLE_DEFAULT = 0x0004,
78751+ GR_ROLE_SPECIAL = 0x0008,
78752+ GR_ROLE_AUTH = 0x0010,
78753+ GR_ROLE_NOPW = 0x0020,
78754+ GR_ROLE_GOD = 0x0040,
78755+ GR_ROLE_LEARN = 0x0080,
78756+ GR_ROLE_TPE = 0x0100,
78757+ GR_ROLE_DOMAIN = 0x0200,
78758+ GR_ROLE_PAM = 0x0400,
78759+ GR_ROLE_PERSIST = 0x0800
78760+};
78761+
78762+/* ACL Subject and Object mode flags */
78763+enum {
78764+ GR_DELETED = 0x80000000
78765+};
78766+
78767+/* ACL Object-only mode flags */
78768+enum {
78769+ GR_READ = 0x00000001,
78770+ GR_APPEND = 0x00000002,
78771+ GR_WRITE = 0x00000004,
78772+ GR_EXEC = 0x00000008,
78773+ GR_FIND = 0x00000010,
78774+ GR_INHERIT = 0x00000020,
78775+ GR_SETID = 0x00000040,
78776+ GR_CREATE = 0x00000080,
78777+ GR_DELETE = 0x00000100,
78778+ GR_LINK = 0x00000200,
78779+ GR_AUDIT_READ = 0x00000400,
78780+ GR_AUDIT_APPEND = 0x00000800,
78781+ GR_AUDIT_WRITE = 0x00001000,
78782+ GR_AUDIT_EXEC = 0x00002000,
78783+ GR_AUDIT_FIND = 0x00004000,
78784+ GR_AUDIT_INHERIT= 0x00008000,
78785+ GR_AUDIT_SETID = 0x00010000,
78786+ GR_AUDIT_CREATE = 0x00020000,
78787+ GR_AUDIT_DELETE = 0x00040000,
78788+ GR_AUDIT_LINK = 0x00080000,
78789+ GR_PTRACERD = 0x00100000,
78790+ GR_NOPTRACE = 0x00200000,
78791+ GR_SUPPRESS = 0x00400000,
78792+ GR_NOLEARN = 0x00800000,
78793+ GR_INIT_TRANSFER= 0x01000000
78794+};
78795+
78796+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78797+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78798+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78799+
78800+/* ACL subject-only mode flags */
78801+enum {
78802+ GR_KILL = 0x00000001,
78803+ GR_VIEW = 0x00000002,
78804+ GR_PROTECTED = 0x00000004,
78805+ GR_LEARN = 0x00000008,
78806+ GR_OVERRIDE = 0x00000010,
78807+ /* just a placeholder, this mode is only used in userspace */
78808+ GR_DUMMY = 0x00000020,
78809+ GR_PROTSHM = 0x00000040,
78810+ GR_KILLPROC = 0x00000080,
78811+ GR_KILLIPPROC = 0x00000100,
78812+ /* just a placeholder, this mode is only used in userspace */
78813+ GR_NOTROJAN = 0x00000200,
78814+ GR_PROTPROCFD = 0x00000400,
78815+ GR_PROCACCT = 0x00000800,
78816+ GR_RELAXPTRACE = 0x00001000,
78817+ //GR_NESTED = 0x00002000,
78818+ GR_INHERITLEARN = 0x00004000,
78819+ GR_PROCFIND = 0x00008000,
78820+ GR_POVERRIDE = 0x00010000,
78821+ GR_KERNELAUTH = 0x00020000,
78822+ GR_ATSECURE = 0x00040000,
78823+ GR_SHMEXEC = 0x00080000
78824+};
78825+
78826+enum {
78827+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78828+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78829+ GR_PAX_ENABLE_MPROTECT = 0x0004,
78830+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
78831+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78832+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78833+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78834+ GR_PAX_DISABLE_MPROTECT = 0x0400,
78835+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
78836+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78837+};
78838+
78839+enum {
78840+ GR_ID_USER = 0x01,
78841+ GR_ID_GROUP = 0x02,
78842+};
78843+
78844+enum {
78845+ GR_ID_ALLOW = 0x01,
78846+ GR_ID_DENY = 0x02,
78847+};
78848+
78849+#define GR_CRASH_RES 31
78850+#define GR_UIDTABLE_MAX 500
78851+
78852+/* begin resource learning section */
78853+enum {
78854+ GR_RLIM_CPU_BUMP = 60,
78855+ GR_RLIM_FSIZE_BUMP = 50000,
78856+ GR_RLIM_DATA_BUMP = 10000,
78857+ GR_RLIM_STACK_BUMP = 1000,
78858+ GR_RLIM_CORE_BUMP = 10000,
78859+ GR_RLIM_RSS_BUMP = 500000,
78860+ GR_RLIM_NPROC_BUMP = 1,
78861+ GR_RLIM_NOFILE_BUMP = 5,
78862+ GR_RLIM_MEMLOCK_BUMP = 50000,
78863+ GR_RLIM_AS_BUMP = 500000,
78864+ GR_RLIM_LOCKS_BUMP = 2,
78865+ GR_RLIM_SIGPENDING_BUMP = 5,
78866+ GR_RLIM_MSGQUEUE_BUMP = 10000,
78867+ GR_RLIM_NICE_BUMP = 1,
78868+ GR_RLIM_RTPRIO_BUMP = 1,
78869+ GR_RLIM_RTTIME_BUMP = 1000000
78870+};
78871+
78872+#endif
78873diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78874new file mode 100644
78875index 0000000..d25522e
78876--- /dev/null
78877+++ b/include/linux/grinternal.h
78878@@ -0,0 +1,229 @@
78879+#ifndef __GRINTERNAL_H
78880+#define __GRINTERNAL_H
78881+
78882+#ifdef CONFIG_GRKERNSEC
78883+
78884+#include <linux/fs.h>
78885+#include <linux/mnt_namespace.h>
78886+#include <linux/nsproxy.h>
78887+#include <linux/gracl.h>
78888+#include <linux/grdefs.h>
78889+#include <linux/grmsg.h>
78890+
78891+void gr_add_learn_entry(const char *fmt, ...)
78892+ __attribute__ ((format (printf, 1, 2)));
78893+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78894+ const struct vfsmount *mnt);
78895+__u32 gr_check_create(const struct dentry *new_dentry,
78896+ const struct dentry *parent,
78897+ const struct vfsmount *mnt, const __u32 mode);
78898+int gr_check_protected_task(const struct task_struct *task);
78899+__u32 to_gr_audit(const __u32 reqmode);
78900+int gr_set_acls(const int type);
78901+int gr_acl_is_enabled(void);
78902+char gr_roletype_to_char(void);
78903+
78904+void gr_handle_alertkill(struct task_struct *task);
78905+char *gr_to_filename(const struct dentry *dentry,
78906+ const struct vfsmount *mnt);
78907+char *gr_to_filename1(const struct dentry *dentry,
78908+ const struct vfsmount *mnt);
78909+char *gr_to_filename2(const struct dentry *dentry,
78910+ const struct vfsmount *mnt);
78911+char *gr_to_filename3(const struct dentry *dentry,
78912+ const struct vfsmount *mnt);
78913+
78914+extern int grsec_enable_ptrace_readexec;
78915+extern int grsec_enable_harden_ptrace;
78916+extern int grsec_enable_link;
78917+extern int grsec_enable_fifo;
78918+extern int grsec_enable_execve;
78919+extern int grsec_enable_shm;
78920+extern int grsec_enable_execlog;
78921+extern int grsec_enable_signal;
78922+extern int grsec_enable_audit_ptrace;
78923+extern int grsec_enable_forkfail;
78924+extern int grsec_enable_time;
78925+extern int grsec_enable_rofs;
78926+extern int grsec_deny_new_usb;
78927+extern int grsec_enable_chroot_shmat;
78928+extern int grsec_enable_chroot_mount;
78929+extern int grsec_enable_chroot_double;
78930+extern int grsec_enable_chroot_pivot;
78931+extern int grsec_enable_chroot_chdir;
78932+extern int grsec_enable_chroot_chmod;
78933+extern int grsec_enable_chroot_mknod;
78934+extern int grsec_enable_chroot_fchdir;
78935+extern int grsec_enable_chroot_nice;
78936+extern int grsec_enable_chroot_execlog;
78937+extern int grsec_enable_chroot_caps;
78938+extern int grsec_enable_chroot_sysctl;
78939+extern int grsec_enable_chroot_unix;
78940+extern int grsec_enable_symlinkown;
78941+extern kgid_t grsec_symlinkown_gid;
78942+extern int grsec_enable_tpe;
78943+extern kgid_t grsec_tpe_gid;
78944+extern int grsec_enable_tpe_all;
78945+extern int grsec_enable_tpe_invert;
78946+extern int grsec_enable_socket_all;
78947+extern kgid_t grsec_socket_all_gid;
78948+extern int grsec_enable_socket_client;
78949+extern kgid_t grsec_socket_client_gid;
78950+extern int grsec_enable_socket_server;
78951+extern kgid_t grsec_socket_server_gid;
78952+extern kgid_t grsec_audit_gid;
78953+extern int grsec_enable_group;
78954+extern int grsec_enable_log_rwxmaps;
78955+extern int grsec_enable_mount;
78956+extern int grsec_enable_chdir;
78957+extern int grsec_resource_logging;
78958+extern int grsec_enable_blackhole;
78959+extern int grsec_lastack_retries;
78960+extern int grsec_enable_brute;
78961+extern int grsec_enable_harden_ipc;
78962+extern int grsec_lock;
78963+
78964+extern spinlock_t grsec_alert_lock;
78965+extern unsigned long grsec_alert_wtime;
78966+extern unsigned long grsec_alert_fyet;
78967+
78968+extern spinlock_t grsec_audit_lock;
78969+
78970+extern rwlock_t grsec_exec_file_lock;
78971+
78972+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78973+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78974+ (tsk)->exec_file->f_path.mnt) : "/")
78975+
78976+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78977+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78978+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78979+
78980+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78981+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
78982+ (tsk)->exec_file->f_path.mnt) : "/")
78983+
78984+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78985+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78986+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78987+
78988+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78989+
78990+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78991+
78992+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78993+{
78994+ if (file1 && file2) {
78995+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
78996+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
78997+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78998+ return true;
78999+ }
79000+
79001+ return false;
79002+}
79003+
79004+#define GR_CHROOT_CAPS {{ \
79005+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79006+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79007+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79008+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79009+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79010+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79011+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79012+
79013+#define security_learn(normal_msg,args...) \
79014+({ \
79015+ read_lock(&grsec_exec_file_lock); \
79016+ gr_add_learn_entry(normal_msg "\n", ## args); \
79017+ read_unlock(&grsec_exec_file_lock); \
79018+})
79019+
79020+enum {
79021+ GR_DO_AUDIT,
79022+ GR_DONT_AUDIT,
79023+ /* used for non-audit messages that we shouldn't kill the task on */
79024+ GR_DONT_AUDIT_GOOD
79025+};
79026+
79027+enum {
79028+ GR_TTYSNIFF,
79029+ GR_RBAC,
79030+ GR_RBAC_STR,
79031+ GR_STR_RBAC,
79032+ GR_RBAC_MODE2,
79033+ GR_RBAC_MODE3,
79034+ GR_FILENAME,
79035+ GR_SYSCTL_HIDDEN,
79036+ GR_NOARGS,
79037+ GR_ONE_INT,
79038+ GR_ONE_INT_TWO_STR,
79039+ GR_ONE_STR,
79040+ GR_STR_INT,
79041+ GR_TWO_STR_INT,
79042+ GR_TWO_INT,
79043+ GR_TWO_U64,
79044+ GR_THREE_INT,
79045+ GR_FIVE_INT_TWO_STR,
79046+ GR_TWO_STR,
79047+ GR_THREE_STR,
79048+ GR_FOUR_STR,
79049+ GR_STR_FILENAME,
79050+ GR_FILENAME_STR,
79051+ GR_FILENAME_TWO_INT,
79052+ GR_FILENAME_TWO_INT_STR,
79053+ GR_TEXTREL,
79054+ GR_PTRACE,
79055+ GR_RESOURCE,
79056+ GR_CAP,
79057+ GR_SIG,
79058+ GR_SIG2,
79059+ GR_CRASH1,
79060+ GR_CRASH2,
79061+ GR_PSACCT,
79062+ GR_RWXMAP,
79063+ GR_RWXMAPVMA
79064+};
79065+
79066+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79067+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79068+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79069+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79070+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79071+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79072+#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)
79073+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79074+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79075+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79076+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79077+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79078+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79079+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79080+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79081+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79082+#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)
79083+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79084+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79085+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79086+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79087+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79088+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79089+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79090+#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)
79091+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79092+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79093+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79094+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79095+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79096+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79097+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79098+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79099+#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)
79100+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79101+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79102+
79103+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79104+
79105+#endif
79106+
79107+#endif
79108diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79109new file mode 100644
79110index 0000000..ba93581
79111--- /dev/null
79112+++ b/include/linux/grmsg.h
79113@@ -0,0 +1,116 @@
79114+#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"
79115+#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"
79116+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79117+#define GR_STOPMOD_MSG "denied modification of module state by "
79118+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79119+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79120+#define GR_IOPERM_MSG "denied use of ioperm() by "
79121+#define GR_IOPL_MSG "denied use of iopl() by "
79122+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79123+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79124+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79125+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79126+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79127+#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"
79128+#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"
79129+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79130+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79131+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79132+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79133+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79134+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79135+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79136+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79137+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79138+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79139+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79140+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79141+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79142+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79143+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79144+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79145+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79146+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79147+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79148+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79149+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79150+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79151+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79152+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79153+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79154+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79155+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79156+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79157+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79158+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79159+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79160+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79161+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79162+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79163+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79164+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79165+#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"
79166+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79167+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79168+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79169+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79170+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79171+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79172+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79173+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79174+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79175+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79176+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79177+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79178+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79179+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79180+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79181+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79182+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79183+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79184+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79185+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79186+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79187+#define GR_NICE_CHROOT_MSG "denied priority change by "
79188+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79189+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79190+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79191+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79192+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79193+#define GR_TIME_MSG "time set by "
79194+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79195+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79196+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79197+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79198+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79199+#define GR_BIND_MSG "denied bind() by "
79200+#define GR_CONNECT_MSG "denied connect() by "
79201+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79202+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79203+#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"
79204+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79205+#define GR_CAP_ACL_MSG "use of %s denied for "
79206+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79207+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79208+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79209+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79210+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79211+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79212+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79213+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79214+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79215+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79216+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79217+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79218+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79219+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79220+#define GR_VM86_MSG "denied use of vm86 by "
79221+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79222+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79223+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79224+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79225+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79226+#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 "
79227+#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 "
79228+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79229+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79230diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79231new file mode 100644
79232index 0000000..f2d8c6c
79233--- /dev/null
79234+++ b/include/linux/grsecurity.h
79235@@ -0,0 +1,248 @@
79236+#ifndef GR_SECURITY_H
79237+#define GR_SECURITY_H
79238+#include <linux/fs.h>
79239+#include <linux/fs_struct.h>
79240+#include <linux/binfmts.h>
79241+#include <linux/gracl.h>
79242+
79243+/* notify of brain-dead configs */
79244+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79245+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79246+#endif
79247+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79248+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79249+#endif
79250+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79251+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79252+#endif
79253+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79254+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79255+#endif
79256+
79257+int gr_handle_new_usb(void);
79258+
79259+void gr_handle_brute_attach(int dumpable);
79260+void gr_handle_brute_check(void);
79261+void gr_handle_kernel_exploit(void);
79262+
79263+char gr_roletype_to_char(void);
79264+
79265+int gr_proc_is_restricted(void);
79266+
79267+int gr_acl_enable_at_secure(void);
79268+
79269+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79270+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79271+
79272+void gr_del_task_from_ip_table(struct task_struct *p);
79273+
79274+int gr_pid_is_chrooted(struct task_struct *p);
79275+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79276+int gr_handle_chroot_nice(void);
79277+int gr_handle_chroot_sysctl(const int op);
79278+int gr_handle_chroot_setpriority(struct task_struct *p,
79279+ const int niceval);
79280+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79281+int gr_handle_chroot_chroot(const struct dentry *dentry,
79282+ const struct vfsmount *mnt);
79283+void gr_handle_chroot_chdir(const struct path *path);
79284+int gr_handle_chroot_chmod(const struct dentry *dentry,
79285+ const struct vfsmount *mnt, const int mode);
79286+int gr_handle_chroot_mknod(const struct dentry *dentry,
79287+ const struct vfsmount *mnt, const int mode);
79288+int gr_handle_chroot_mount(const struct dentry *dentry,
79289+ const struct vfsmount *mnt,
79290+ const char *dev_name);
79291+int gr_handle_chroot_pivot(void);
79292+int gr_handle_chroot_unix(const pid_t pid);
79293+
79294+int gr_handle_rawio(const struct inode *inode);
79295+
79296+void gr_handle_ioperm(void);
79297+void gr_handle_iopl(void);
79298+void gr_handle_msr_write(void);
79299+
79300+umode_t gr_acl_umask(void);
79301+
79302+int gr_tpe_allow(const struct file *file);
79303+
79304+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79305+void gr_clear_chroot_entries(struct task_struct *task);
79306+
79307+void gr_log_forkfail(const int retval);
79308+void gr_log_timechange(void);
79309+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79310+void gr_log_chdir(const struct dentry *dentry,
79311+ const struct vfsmount *mnt);
79312+void gr_log_chroot_exec(const struct dentry *dentry,
79313+ const struct vfsmount *mnt);
79314+void gr_log_remount(const char *devname, const int retval);
79315+void gr_log_unmount(const char *devname, const int retval);
79316+void gr_log_mount(const char *from, const char *to, const int retval);
79317+void gr_log_textrel(struct vm_area_struct *vma);
79318+void gr_log_ptgnustack(struct file *file);
79319+void gr_log_rwxmmap(struct file *file);
79320+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79321+
79322+int gr_handle_follow_link(const struct inode *parent,
79323+ const struct inode *inode,
79324+ const struct dentry *dentry,
79325+ const struct vfsmount *mnt);
79326+int gr_handle_fifo(const struct dentry *dentry,
79327+ const struct vfsmount *mnt,
79328+ const struct dentry *dir, const int flag,
79329+ const int acc_mode);
79330+int gr_handle_hardlink(const struct dentry *dentry,
79331+ const struct vfsmount *mnt,
79332+ struct inode *inode,
79333+ const int mode, const struct filename *to);
79334+
79335+int gr_is_capable(const int cap);
79336+int gr_is_capable_nolog(const int cap);
79337+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79338+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79339+
79340+void gr_copy_label(struct task_struct *tsk);
79341+void gr_handle_crash(struct task_struct *task, const int sig);
79342+int gr_handle_signal(const struct task_struct *p, const int sig);
79343+int gr_check_crash_uid(const kuid_t uid);
79344+int gr_check_protected_task(const struct task_struct *task);
79345+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79346+int gr_acl_handle_mmap(const struct file *file,
79347+ const unsigned long prot);
79348+int gr_acl_handle_mprotect(const struct file *file,
79349+ const unsigned long prot);
79350+int gr_check_hidden_task(const struct task_struct *tsk);
79351+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79352+ const struct vfsmount *mnt);
79353+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79354+ const struct vfsmount *mnt);
79355+__u32 gr_acl_handle_access(const struct dentry *dentry,
79356+ const struct vfsmount *mnt, const int fmode);
79357+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79358+ const struct vfsmount *mnt, umode_t *mode);
79359+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79360+ const struct vfsmount *mnt);
79361+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79362+ const struct vfsmount *mnt);
79363+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79364+ const struct vfsmount *mnt);
79365+int gr_handle_ptrace(struct task_struct *task, const long request);
79366+int gr_handle_proc_ptrace(struct task_struct *task);
79367+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79368+ const struct vfsmount *mnt);
79369+int gr_check_crash_exec(const struct file *filp);
79370+int gr_acl_is_enabled(void);
79371+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79372+ const kgid_t gid);
79373+int gr_set_proc_label(const struct dentry *dentry,
79374+ const struct vfsmount *mnt,
79375+ const int unsafe_flags);
79376+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79377+ const struct vfsmount *mnt);
79378+__u32 gr_acl_handle_open(const struct dentry *dentry,
79379+ const struct vfsmount *mnt, int acc_mode);
79380+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79381+ const struct dentry *p_dentry,
79382+ const struct vfsmount *p_mnt,
79383+ int open_flags, int acc_mode, const int imode);
79384+void gr_handle_create(const struct dentry *dentry,
79385+ const struct vfsmount *mnt);
79386+void gr_handle_proc_create(const struct dentry *dentry,
79387+ const struct inode *inode);
79388+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79389+ const struct dentry *parent_dentry,
79390+ const struct vfsmount *parent_mnt,
79391+ const int mode);
79392+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79393+ const struct dentry *parent_dentry,
79394+ const struct vfsmount *parent_mnt);
79395+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79396+ const struct vfsmount *mnt);
79397+void gr_handle_delete(const ino_t ino, const dev_t dev);
79398+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79399+ const struct vfsmount *mnt);
79400+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79401+ const struct dentry *parent_dentry,
79402+ const struct vfsmount *parent_mnt,
79403+ const struct filename *from);
79404+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79405+ const struct dentry *parent_dentry,
79406+ const struct vfsmount *parent_mnt,
79407+ const struct dentry *old_dentry,
79408+ const struct vfsmount *old_mnt, const struct filename *to);
79409+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79410+int gr_acl_handle_rename(struct dentry *new_dentry,
79411+ struct dentry *parent_dentry,
79412+ const struct vfsmount *parent_mnt,
79413+ struct dentry *old_dentry,
79414+ struct inode *old_parent_inode,
79415+ struct vfsmount *old_mnt, const struct filename *newname);
79416+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79417+ struct dentry *old_dentry,
79418+ struct dentry *new_dentry,
79419+ struct vfsmount *mnt, const __u8 replace);
79420+__u32 gr_check_link(const struct dentry *new_dentry,
79421+ const struct dentry *parent_dentry,
79422+ const struct vfsmount *parent_mnt,
79423+ const struct dentry *old_dentry,
79424+ const struct vfsmount *old_mnt);
79425+int gr_acl_handle_filldir(const struct file *file, const char *name,
79426+ const unsigned int namelen, const ino_t ino);
79427+
79428+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79429+ const struct vfsmount *mnt);
79430+void gr_acl_handle_exit(void);
79431+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79432+int gr_acl_handle_procpidmem(const struct task_struct *task);
79433+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79434+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79435+void gr_audit_ptrace(struct task_struct *task);
79436+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79437+void gr_put_exec_file(struct task_struct *task);
79438+
79439+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79440+
79441+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79442+extern void gr_learn_resource(const struct task_struct *task, const int res,
79443+ const unsigned long wanted, const int gt);
79444+#else
79445+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79446+ const unsigned long wanted, const int gt)
79447+{
79448+}
79449+#endif
79450+
79451+#ifdef CONFIG_GRKERNSEC_RESLOG
79452+extern void gr_log_resource(const struct task_struct *task, const int res,
79453+ const unsigned long wanted, const int gt);
79454+#else
79455+static inline void gr_log_resource(const struct task_struct *task, const int res,
79456+ const unsigned long wanted, const int gt)
79457+{
79458+}
79459+#endif
79460+
79461+#ifdef CONFIG_GRKERNSEC
79462+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79463+void gr_handle_vm86(void);
79464+void gr_handle_mem_readwrite(u64 from, u64 to);
79465+
79466+void gr_log_badprocpid(const char *entry);
79467+
79468+extern int grsec_enable_dmesg;
79469+extern int grsec_disable_privio;
79470+
79471+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79472+extern kgid_t grsec_proc_gid;
79473+#endif
79474+
79475+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79476+extern int grsec_enable_chroot_findtask;
79477+#endif
79478+#ifdef CONFIG_GRKERNSEC_SETXID
79479+extern int grsec_enable_setxid;
79480+#endif
79481+#endif
79482+
79483+#endif
79484diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79485new file mode 100644
79486index 0000000..e7ffaaf
79487--- /dev/null
79488+++ b/include/linux/grsock.h
79489@@ -0,0 +1,19 @@
79490+#ifndef __GRSOCK_H
79491+#define __GRSOCK_H
79492+
79493+extern void gr_attach_curr_ip(const struct sock *sk);
79494+extern int gr_handle_sock_all(const int family, const int type,
79495+ const int protocol);
79496+extern int gr_handle_sock_server(const struct sockaddr *sck);
79497+extern int gr_handle_sock_server_other(const struct sock *sck);
79498+extern int gr_handle_sock_client(const struct sockaddr *sck);
79499+extern int gr_search_connect(struct socket * sock,
79500+ struct sockaddr_in * addr);
79501+extern int gr_search_bind(struct socket * sock,
79502+ struct sockaddr_in * addr);
79503+extern int gr_search_listen(struct socket * sock);
79504+extern int gr_search_accept(struct socket * sock);
79505+extern int gr_search_socket(const int domain, const int type,
79506+ const int protocol);
79507+
79508+#endif
79509diff --git a/include/linux/hash.h b/include/linux/hash.h
79510index bd1754c..8240892 100644
79511--- a/include/linux/hash.h
79512+++ b/include/linux/hash.h
79513@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79514 struct fast_hash_ops {
79515 u32 (*hash)(const void *data, u32 len, u32 seed);
79516 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79517-};
79518+} __no_const;
79519
79520 /**
79521 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79522diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79523index 7fb31da..08b5114 100644
79524--- a/include/linux/highmem.h
79525+++ b/include/linux/highmem.h
79526@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79527 kunmap_atomic(kaddr);
79528 }
79529
79530+static inline void sanitize_highpage(struct page *page)
79531+{
79532+ void *kaddr;
79533+ unsigned long flags;
79534+
79535+ local_irq_save(flags);
79536+ kaddr = kmap_atomic(page);
79537+ clear_page(kaddr);
79538+ kunmap_atomic(kaddr);
79539+ local_irq_restore(flags);
79540+}
79541+
79542 static inline void zero_user_segments(struct page *page,
79543 unsigned start1, unsigned end1,
79544 unsigned start2, unsigned end2)
79545diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79546index 1c7b89a..7dda400 100644
79547--- a/include/linux/hwmon-sysfs.h
79548+++ b/include/linux/hwmon-sysfs.h
79549@@ -25,7 +25,8 @@
79550 struct sensor_device_attribute{
79551 struct device_attribute dev_attr;
79552 int index;
79553-};
79554+} __do_const;
79555+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79556 #define to_sensor_dev_attr(_dev_attr) \
79557 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79558
79559@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79560 struct device_attribute dev_attr;
79561 u8 index;
79562 u8 nr;
79563-};
79564+} __do_const;
79565+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79566 #define to_sensor_dev_attr_2(_dev_attr) \
79567 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79568
79569diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79570index deddeb8..bcaf62d 100644
79571--- a/include/linux/i2c.h
79572+++ b/include/linux/i2c.h
79573@@ -378,6 +378,7 @@ struct i2c_algorithm {
79574 /* To determine what the adapter supports */
79575 u32 (*functionality) (struct i2c_adapter *);
79576 };
79577+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79578
79579 /**
79580 * struct i2c_bus_recovery_info - I2C bus recovery information
79581diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79582index d23c3c2..eb63c81 100644
79583--- a/include/linux/i2o.h
79584+++ b/include/linux/i2o.h
79585@@ -565,7 +565,7 @@ struct i2o_controller {
79586 struct i2o_device *exec; /* Executive */
79587 #if BITS_PER_LONG == 64
79588 spinlock_t context_list_lock; /* lock for context_list */
79589- atomic_t context_list_counter; /* needed for unique contexts */
79590+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79591 struct list_head context_list; /* list of context id's
79592 and pointers */
79593 #endif
79594diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79595index aff7ad8..3942bbd 100644
79596--- a/include/linux/if_pppox.h
79597+++ b/include/linux/if_pppox.h
79598@@ -76,7 +76,7 @@ struct pppox_proto {
79599 int (*ioctl)(struct socket *sock, unsigned int cmd,
79600 unsigned long arg);
79601 struct module *owner;
79602-};
79603+} __do_const;
79604
79605 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79606 extern void unregister_pppox_proto(int proto_num);
79607diff --git a/include/linux/init.h b/include/linux/init.h
79608index e168880..d9b489d 100644
79609--- a/include/linux/init.h
79610+++ b/include/linux/init.h
79611@@ -37,9 +37,17 @@
79612 * section.
79613 */
79614
79615+#define add_init_latent_entropy __latent_entropy
79616+
79617+#ifdef CONFIG_MEMORY_HOTPLUG
79618+#define add_meminit_latent_entropy
79619+#else
79620+#define add_meminit_latent_entropy __latent_entropy
79621+#endif
79622+
79623 /* These are for everybody (although not all archs will actually
79624 discard it in modules) */
79625-#define __init __section(.init.text) __cold notrace
79626+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79627 #define __initdata __section(.init.data)
79628 #define __initconst __constsection(.init.rodata)
79629 #define __exitdata __section(.exit.data)
79630@@ -100,7 +108,7 @@
79631 #define __cpuexitconst
79632
79633 /* Used for MEMORY_HOTPLUG */
79634-#define __meminit __section(.meminit.text) __cold notrace
79635+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79636 #define __meminitdata __section(.meminit.data)
79637 #define __meminitconst __constsection(.meminit.rodata)
79638 #define __memexit __section(.memexit.text) __exitused __cold notrace
79639diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79640index 6df7f9f..d0bf699 100644
79641--- a/include/linux/init_task.h
79642+++ b/include/linux/init_task.h
79643@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79644
79645 #define INIT_TASK_COMM "swapper"
79646
79647+#ifdef CONFIG_X86
79648+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79649+#else
79650+#define INIT_TASK_THREAD_INFO
79651+#endif
79652+
79653 #ifdef CONFIG_RT_MUTEXES
79654 # define INIT_RT_MUTEXES(tsk) \
79655 .pi_waiters = RB_ROOT, \
79656@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79657 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79658 .comm = INIT_TASK_COMM, \
79659 .thread = INIT_THREAD, \
79660+ INIT_TASK_THREAD_INFO \
79661 .fs = &init_fs, \
79662 .files = &init_files, \
79663 .signal = &init_signals, \
79664diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79665index a2678d3..e411b1b 100644
79666--- a/include/linux/interrupt.h
79667+++ b/include/linux/interrupt.h
79668@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79669
79670 struct softirq_action
79671 {
79672- void (*action)(struct softirq_action *);
79673-};
79674+ void (*action)(void);
79675+} __no_const;
79676
79677 asmlinkage void do_softirq(void);
79678 asmlinkage void __do_softirq(void);
79679@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79680 }
79681 #endif
79682
79683-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79684+extern void open_softirq(int nr, void (*action)(void));
79685 extern void softirq_init(void);
79686 extern void __raise_softirq_irqoff(unsigned int nr);
79687
79688diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79689index b96a5b2..2732d1c 100644
79690--- a/include/linux/iommu.h
79691+++ b/include/linux/iommu.h
79692@@ -131,7 +131,7 @@ struct iommu_ops {
79693 u32 (*domain_get_windows)(struct iommu_domain *domain);
79694
79695 unsigned long pgsize_bitmap;
79696-};
79697+} __do_const;
79698
79699 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79700 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79701diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79702index 89b7c24..382af74 100644
79703--- a/include/linux/ioport.h
79704+++ b/include/linux/ioport.h
79705@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79706 int adjust_resource(struct resource *res, resource_size_t start,
79707 resource_size_t size);
79708 resource_size_t resource_alignment(struct resource *res);
79709-static inline resource_size_t resource_size(const struct resource *res)
79710+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79711 {
79712 return res->end - res->start + 1;
79713 }
79714diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79715index 35e7eca..6afb7ad 100644
79716--- a/include/linux/ipc_namespace.h
79717+++ b/include/linux/ipc_namespace.h
79718@@ -69,7 +69,7 @@ struct ipc_namespace {
79719 struct user_namespace *user_ns;
79720
79721 unsigned int proc_inum;
79722-};
79723+} __randomize_layout;
79724
79725 extern struct ipc_namespace init_ipc_ns;
79726 extern atomic_t nr_ipc_ns;
79727diff --git a/include/linux/irq.h b/include/linux/irq.h
79728index 7dc1003..407327b 100644
79729--- a/include/linux/irq.h
79730+++ b/include/linux/irq.h
79731@@ -338,7 +338,8 @@ struct irq_chip {
79732 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79733
79734 unsigned long flags;
79735-};
79736+} __do_const;
79737+typedef struct irq_chip __no_const irq_chip_no_const;
79738
79739 /*
79740 * irq_chip specific flags
79741diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79742index 0ceb389..eed3fb8 100644
79743--- a/include/linux/irqchip/arm-gic.h
79744+++ b/include/linux/irqchip/arm-gic.h
79745@@ -73,9 +73,11 @@
79746
79747 #ifndef __ASSEMBLY__
79748
79749+#include <linux/irq.h>
79750+
79751 struct device_node;
79752
79753-extern struct irq_chip gic_arch_extn;
79754+extern irq_chip_no_const gic_arch_extn;
79755
79756 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79757 u32 offset, struct device_node *);
79758diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79759index 1f44466..b481806 100644
79760--- a/include/linux/jiffies.h
79761+++ b/include/linux/jiffies.h
79762@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79763 /*
79764 * Convert various time units to each other:
79765 */
79766-extern unsigned int jiffies_to_msecs(const unsigned long j);
79767-extern unsigned int jiffies_to_usecs(const unsigned long j);
79768+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79769+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79770
79771-static inline u64 jiffies_to_nsecs(const unsigned long j)
79772+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79773 {
79774 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79775 }
79776
79777-extern unsigned long msecs_to_jiffies(const unsigned int m);
79778-extern unsigned long usecs_to_jiffies(const unsigned int u);
79779+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79780+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79781 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79782 extern void jiffies_to_timespec(const unsigned long jiffies,
79783- struct timespec *value);
79784-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79785+ struct timespec *value) __intentional_overflow(-1);
79786+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79787 extern void jiffies_to_timeval(const unsigned long jiffies,
79788 struct timeval *value);
79789
79790diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79791index 6883e19..e854fcb 100644
79792--- a/include/linux/kallsyms.h
79793+++ b/include/linux/kallsyms.h
79794@@ -15,7 +15,8 @@
79795
79796 struct module;
79797
79798-#ifdef CONFIG_KALLSYMS
79799+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79800+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79801 /* Lookup the address for a symbol. Returns 0 if not found. */
79802 unsigned long kallsyms_lookup_name(const char *name);
79803
79804@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79805 /* Stupid that this does nothing, but I didn't create this mess. */
79806 #define __print_symbol(fmt, addr)
79807 #endif /*CONFIG_KALLSYMS*/
79808+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79809+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79810+extern unsigned long kallsyms_lookup_name(const char *name);
79811+extern void __print_symbol(const char *fmt, unsigned long address);
79812+extern int sprint_backtrace(char *buffer, unsigned long address);
79813+extern int sprint_symbol(char *buffer, unsigned long address);
79814+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79815+const char *kallsyms_lookup(unsigned long addr,
79816+ unsigned long *symbolsize,
79817+ unsigned long *offset,
79818+ char **modname, char *namebuf);
79819+extern int kallsyms_lookup_size_offset(unsigned long addr,
79820+ unsigned long *symbolsize,
79821+ unsigned long *offset);
79822+#endif
79823
79824 /* This macro allows us to keep printk typechecking */
79825 static __printf(1, 2)
79826diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79827index a74c3a8..28d3f21 100644
79828--- a/include/linux/key-type.h
79829+++ b/include/linux/key-type.h
79830@@ -131,7 +131,7 @@ struct key_type {
79831 /* internal fields */
79832 struct list_head link; /* link in types list */
79833 struct lock_class_key lock_class; /* key->sem lock class */
79834-};
79835+} __do_const;
79836
79837 extern struct key_type key_type_keyring;
79838
79839diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79840index 6b06d37..c134867 100644
79841--- a/include/linux/kgdb.h
79842+++ b/include/linux/kgdb.h
79843@@ -52,7 +52,7 @@ extern int kgdb_connected;
79844 extern int kgdb_io_module_registered;
79845
79846 extern atomic_t kgdb_setting_breakpoint;
79847-extern atomic_t kgdb_cpu_doing_single_step;
79848+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79849
79850 extern struct task_struct *kgdb_usethread;
79851 extern struct task_struct *kgdb_contthread;
79852@@ -254,7 +254,7 @@ struct kgdb_arch {
79853 void (*correct_hw_break)(void);
79854
79855 void (*enable_nmi)(bool on);
79856-};
79857+} __do_const;
79858
79859 /**
79860 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79861@@ -279,7 +279,7 @@ struct kgdb_io {
79862 void (*pre_exception) (void);
79863 void (*post_exception) (void);
79864 int is_console;
79865-};
79866+} __do_const;
79867
79868 extern struct kgdb_arch arch_kgdb_ops;
79869
79870diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79871index 0555cc6..40116ce 100644
79872--- a/include/linux/kmod.h
79873+++ b/include/linux/kmod.h
79874@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79875 * usually useless though. */
79876 extern __printf(2, 3)
79877 int __request_module(bool wait, const char *name, ...);
79878+extern __printf(3, 4)
79879+int ___request_module(bool wait, char *param_name, const char *name, ...);
79880 #define request_module(mod...) __request_module(true, mod)
79881 #define request_module_nowait(mod...) __request_module(false, mod)
79882 #define try_then_request_module(x, mod...) \
79883@@ -57,6 +59,9 @@ struct subprocess_info {
79884 struct work_struct work;
79885 struct completion *complete;
79886 char *path;
79887+#ifdef CONFIG_GRKERNSEC
79888+ char *origpath;
79889+#endif
79890 char **argv;
79891 char **envp;
79892 int wait;
79893diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79894index 926afb6..58dd6e5 100644
79895--- a/include/linux/kobject.h
79896+++ b/include/linux/kobject.h
79897@@ -116,7 +116,7 @@ struct kobj_type {
79898 struct attribute **default_attrs;
79899 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79900 const void *(*namespace)(struct kobject *kobj);
79901-};
79902+} __do_const;
79903
79904 struct kobj_uevent_env {
79905 char *envp[UEVENT_NUM_ENVP];
79906@@ -139,6 +139,7 @@ struct kobj_attribute {
79907 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79908 const char *buf, size_t count);
79909 };
79910+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79911
79912 extern const struct sysfs_ops kobj_sysfs_ops;
79913
79914@@ -166,7 +167,7 @@ struct kset {
79915 spinlock_t list_lock;
79916 struct kobject kobj;
79917 const struct kset_uevent_ops *uevent_ops;
79918-};
79919+} __randomize_layout;
79920
79921 extern void kset_init(struct kset *kset);
79922 extern int __must_check kset_register(struct kset *kset);
79923diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79924index df32d25..fb52e27 100644
79925--- a/include/linux/kobject_ns.h
79926+++ b/include/linux/kobject_ns.h
79927@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79928 const void *(*netlink_ns)(struct sock *sk);
79929 const void *(*initial_ns)(void);
79930 void (*drop_ns)(void *);
79931-};
79932+} __do_const;
79933
79934 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79935 int kobj_ns_type_registered(enum kobj_ns_type type);
79936diff --git a/include/linux/kref.h b/include/linux/kref.h
79937index 484604d..0f6c5b6 100644
79938--- a/include/linux/kref.h
79939+++ b/include/linux/kref.h
79940@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79941 static inline int kref_sub(struct kref *kref, unsigned int count,
79942 void (*release)(struct kref *kref))
79943 {
79944- WARN_ON(release == NULL);
79945+ BUG_ON(release == NULL);
79946
79947 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79948 release(kref);
79949diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79950index b8e9a43..632678d 100644
79951--- a/include/linux/kvm_host.h
79952+++ b/include/linux/kvm_host.h
79953@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
79954 {
79955 }
79956 #endif
79957-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79958+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79959 struct module *module);
79960 void kvm_exit(void);
79961
79962@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79963 struct kvm_guest_debug *dbg);
79964 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79965
79966-int kvm_arch_init(void *opaque);
79967+int kvm_arch_init(const void *opaque);
79968 void kvm_arch_exit(void);
79969
79970 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79971diff --git a/include/linux/libata.h b/include/linux/libata.h
79972index bec6dbe..2873d64 100644
79973--- a/include/linux/libata.h
79974+++ b/include/linux/libata.h
79975@@ -975,7 +975,7 @@ struct ata_port_operations {
79976 * fields must be pointers.
79977 */
79978 const struct ata_port_operations *inherits;
79979-};
79980+} __do_const;
79981
79982 struct ata_port_info {
79983 unsigned long flags;
79984diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79985index a6a42dd..6c5ebce 100644
79986--- a/include/linux/linkage.h
79987+++ b/include/linux/linkage.h
79988@@ -36,6 +36,7 @@
79989 #endif
79990
79991 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79992+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79993 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79994
79995 /*
79996diff --git a/include/linux/list.h b/include/linux/list.h
79997index ef95941..82db65a 100644
79998--- a/include/linux/list.h
79999+++ b/include/linux/list.h
80000@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80001 extern void list_del(struct list_head *entry);
80002 #endif
80003
80004+extern void __pax_list_add(struct list_head *new,
80005+ struct list_head *prev,
80006+ struct list_head *next);
80007+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80008+{
80009+ __pax_list_add(new, head, head->next);
80010+}
80011+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80012+{
80013+ __pax_list_add(new, head->prev, head);
80014+}
80015+extern void pax_list_del(struct list_head *entry);
80016+
80017 /**
80018 * list_replace - replace old entry by new one
80019 * @old : the element to be replaced
80020@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80021 INIT_LIST_HEAD(entry);
80022 }
80023
80024+extern void pax_list_del_init(struct list_head *entry);
80025+
80026 /**
80027 * list_move - delete from one list and add as another's head
80028 * @list: the entry to move
80029diff --git a/include/linux/math64.h b/include/linux/math64.h
80030index c45c089..298841c 100644
80031--- a/include/linux/math64.h
80032+++ b/include/linux/math64.h
80033@@ -15,7 +15,7 @@
80034 * This is commonly provided by 32bit archs to provide an optimized 64bit
80035 * divide.
80036 */
80037-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80038+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80039 {
80040 *remainder = dividend % divisor;
80041 return dividend / divisor;
80042@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80043 /**
80044 * div64_u64 - unsigned 64bit divide with 64bit divisor
80045 */
80046-static inline u64 div64_u64(u64 dividend, u64 divisor)
80047+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80048 {
80049 return dividend / divisor;
80050 }
80051@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80052 #define div64_ul(x, y) div_u64((x), (y))
80053
80054 #ifndef div_u64_rem
80055-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80056+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80057 {
80058 *remainder = do_div(dividend, divisor);
80059 return dividend;
80060@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80061 #endif
80062
80063 #ifndef div64_u64
80064-extern u64 div64_u64(u64 dividend, u64 divisor);
80065+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80066 #endif
80067
80068 #ifndef div64_s64
80069@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80070 * divide.
80071 */
80072 #ifndef div_u64
80073-static inline u64 div_u64(u64 dividend, u32 divisor)
80074+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80075 {
80076 u32 remainder;
80077 return div_u64_rem(dividend, divisor, &remainder);
80078diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80079index 5f1ea75..5125ac5 100644
80080--- a/include/linux/mempolicy.h
80081+++ b/include/linux/mempolicy.h
80082@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80083 }
80084
80085 #define vma_policy(vma) ((vma)->vm_policy)
80086+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80087+{
80088+ vma->vm_policy = pol;
80089+}
80090
80091 static inline void mpol_get(struct mempolicy *pol)
80092 {
80093@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80094 }
80095
80096 #define vma_policy(vma) NULL
80097+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80098+{
80099+}
80100
80101 static inline int
80102 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80103diff --git a/include/linux/mm.h b/include/linux/mm.h
80104index c1b7414..5ea2ad8 100644
80105--- a/include/linux/mm.h
80106+++ b/include/linux/mm.h
80107@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80108 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80109 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80110 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80111+
80112+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80113+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80114+#endif
80115+
80116 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80117
80118 #ifdef CONFIG_MEM_SOFT_DIRTY
80119@@ -229,8 +234,8 @@ struct vm_operations_struct {
80120 /* called by access_process_vm when get_user_pages() fails, typically
80121 * for use by special VMAs that can switch between memory and hardware
80122 */
80123- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80124- void *buf, int len, int write);
80125+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80126+ void *buf, size_t len, int write);
80127 #ifdef CONFIG_NUMA
80128 /*
80129 * set_policy() op must add a reference to any non-NULL @new mempolicy
80130@@ -260,6 +265,7 @@ struct vm_operations_struct {
80131 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80132 unsigned long size, pgoff_t pgoff);
80133 };
80134+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80135
80136 struct mmu_gather;
80137 struct inode;
80138@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80139 unsigned long *pfn);
80140 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80141 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80142-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80143- void *buf, int len, int write);
80144+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80145+ void *buf, size_t len, int write);
80146
80147 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80148 loff_t const holebegin, loff_t const holelen)
80149@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80150 }
80151 #endif
80152
80153-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80154-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80155- void *buf, int len, int write);
80156+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80157+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80158+ void *buf, size_t len, int write);
80159
80160 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80161 unsigned long start, unsigned long nr_pages,
80162@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80163 int set_page_dirty_lock(struct page *page);
80164 int clear_page_dirty_for_io(struct page *page);
80165
80166-/* Is the vma a continuation of the stack vma above it? */
80167-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80168-{
80169- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80170-}
80171-
80172-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80173- unsigned long addr)
80174-{
80175- return (vma->vm_flags & VM_GROWSDOWN) &&
80176- (vma->vm_start == addr) &&
80177- !vma_growsdown(vma->vm_prev, addr);
80178-}
80179-
80180-/* Is the vma a continuation of the stack vma below it? */
80181-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80182-{
80183- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80184-}
80185-
80186-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80187- unsigned long addr)
80188-{
80189- return (vma->vm_flags & VM_GROWSUP) &&
80190- (vma->vm_end == addr) &&
80191- !vma_growsup(vma->vm_next, addr);
80192-}
80193-
80194 extern pid_t
80195 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80196
80197@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80198 }
80199 #endif
80200
80201+#ifdef CONFIG_MMU
80202+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80203+#else
80204+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80205+{
80206+ return __pgprot(0);
80207+}
80208+#endif
80209+
80210 int vma_wants_writenotify(struct vm_area_struct *vma);
80211
80212 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80213@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80214 {
80215 return 0;
80216 }
80217+
80218+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80219+ unsigned long address)
80220+{
80221+ return 0;
80222+}
80223 #else
80224 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80225+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80226 #endif
80227
80228 #ifdef __PAGETABLE_PMD_FOLDED
80229@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80230 {
80231 return 0;
80232 }
80233+
80234+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80235+ unsigned long address)
80236+{
80237+ return 0;
80238+}
80239 #else
80240 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80241+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80242 #endif
80243
80244 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80245@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80246 NULL: pud_offset(pgd, address);
80247 }
80248
80249+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80250+{
80251+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80252+ NULL: pud_offset(pgd, address);
80253+}
80254+
80255 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80256 {
80257 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80258 NULL: pmd_offset(pud, address);
80259 }
80260+
80261+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80262+{
80263+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80264+ NULL: pmd_offset(pud, address);
80265+}
80266 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80267
80268 #if USE_SPLIT_PTE_PTLOCKS
80269@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80270 unsigned long addr, unsigned long len,
80271 unsigned long flags, struct page **pages);
80272
80273-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80274+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80275
80276 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80277 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80278@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80279 unsigned long len, unsigned long prot, unsigned long flags,
80280 unsigned long pgoff, unsigned long *populate);
80281 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80282+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80283
80284 #ifdef CONFIG_MMU
80285 extern int __mm_populate(unsigned long addr, unsigned long len,
80286@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80287 unsigned long high_limit;
80288 unsigned long align_mask;
80289 unsigned long align_offset;
80290+ unsigned long threadstack_offset;
80291 };
80292
80293-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80294-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80295+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80296+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80297
80298 /*
80299 * Search for an unmapped address range.
80300@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80301 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80302 */
80303 static inline unsigned long
80304-vm_unmapped_area(struct vm_unmapped_area_info *info)
80305+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80306 {
80307 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80308 return unmapped_area(info);
80309@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80310 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80311 struct vm_area_struct **pprev);
80312
80313+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80314+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80315+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80316+
80317 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80318 NULL if none. Assume start_addr < end_addr. */
80319 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80320@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80321 return vma;
80322 }
80323
80324-#ifdef CONFIG_MMU
80325-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80326-#else
80327-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80328-{
80329- return __pgprot(0);
80330-}
80331-#endif
80332-
80333 #ifdef CONFIG_NUMA_BALANCING
80334 unsigned long change_prot_numa(struct vm_area_struct *vma,
80335 unsigned long start, unsigned long end);
80336@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80337 static inline void vm_stat_account(struct mm_struct *mm,
80338 unsigned long flags, struct file *file, long pages)
80339 {
80340+
80341+#ifdef CONFIG_PAX_RANDMMAP
80342+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80343+#endif
80344+
80345 mm->total_vm += pages;
80346 }
80347 #endif /* CONFIG_PROC_FS */
80348@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80349 extern int sysctl_memory_failure_early_kill;
80350 extern int sysctl_memory_failure_recovery;
80351 extern void shake_page(struct page *p, int access);
80352-extern atomic_long_t num_poisoned_pages;
80353+extern atomic_long_unchecked_t num_poisoned_pages;
80354 extern int soft_offline_page(struct page *page, int flags);
80355
80356 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80357@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80358 static inline void setup_nr_node_ids(void) {}
80359 #endif
80360
80361+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80362+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80363+#else
80364+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80365+#endif
80366+
80367 #endif /* __KERNEL__ */
80368 #endif /* _LINUX_MM_H */
80369diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80370index 290901a..e99b01c 100644
80371--- a/include/linux/mm_types.h
80372+++ b/include/linux/mm_types.h
80373@@ -307,7 +307,9 @@ struct vm_area_struct {
80374 #ifdef CONFIG_NUMA
80375 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80376 #endif
80377-};
80378+
80379+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80380+} __randomize_layout;
80381
80382 struct core_thread {
80383 struct task_struct *task;
80384@@ -453,7 +455,25 @@ struct mm_struct {
80385 bool tlb_flush_pending;
80386 #endif
80387 struct uprobes_state uprobes_state;
80388-};
80389+
80390+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80391+ unsigned long pax_flags;
80392+#endif
80393+
80394+#ifdef CONFIG_PAX_DLRESOLVE
80395+ unsigned long call_dl_resolve;
80396+#endif
80397+
80398+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80399+ unsigned long call_syscall;
80400+#endif
80401+
80402+#ifdef CONFIG_PAX_ASLR
80403+ unsigned long delta_mmap; /* randomized offset */
80404+ unsigned long delta_stack; /* randomized offset */
80405+#endif
80406+
80407+} __randomize_layout;
80408
80409 static inline void mm_init_cpumask(struct mm_struct *mm)
80410 {
80411diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80412index c5d5278..f0b68c8 100644
80413--- a/include/linux/mmiotrace.h
80414+++ b/include/linux/mmiotrace.h
80415@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80416 /* Called from ioremap.c */
80417 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80418 void __iomem *addr);
80419-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80420+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80421
80422 /* For anyone to insert markers. Remember trailing newline. */
80423 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80424@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80425 {
80426 }
80427
80428-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80429+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80430 {
80431 }
80432
80433diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80434index 9b61b9b..52147d6b 100644
80435--- a/include/linux/mmzone.h
80436+++ b/include/linux/mmzone.h
80437@@ -396,7 +396,7 @@ struct zone {
80438 unsigned long flags; /* zone flags, see below */
80439
80440 /* Zone statistics */
80441- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80442+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80443
80444 /*
80445 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80446diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80447index 45e9214..a7227d6 100644
80448--- a/include/linux/mod_devicetable.h
80449+++ b/include/linux/mod_devicetable.h
80450@@ -13,7 +13,7 @@
80451 typedef unsigned long kernel_ulong_t;
80452 #endif
80453
80454-#define PCI_ANY_ID (~0)
80455+#define PCI_ANY_ID ((__u16)~0)
80456
80457 struct pci_device_id {
80458 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80459@@ -139,7 +139,7 @@ struct usb_device_id {
80460 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80461 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80462
80463-#define HID_ANY_ID (~0)
80464+#define HID_ANY_ID (~0U)
80465 #define HID_BUS_ANY 0xffff
80466 #define HID_GROUP_ANY 0x0000
80467
80468@@ -467,7 +467,7 @@ struct dmi_system_id {
80469 const char *ident;
80470 struct dmi_strmatch matches[4];
80471 void *driver_data;
80472-};
80473+} __do_const;
80474 /*
80475 * struct dmi_device_id appears during expansion of
80476 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80477diff --git a/include/linux/module.h b/include/linux/module.h
80478index eaf60ff..641979a 100644
80479--- a/include/linux/module.h
80480+++ b/include/linux/module.h
80481@@ -17,9 +17,11 @@
80482 #include <linux/moduleparam.h>
80483 #include <linux/tracepoint.h>
80484 #include <linux/export.h>
80485+#include <linux/fs.h>
80486
80487 #include <linux/percpu.h>
80488 #include <asm/module.h>
80489+#include <asm/pgtable.h>
80490
80491 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80492 #define MODULE_SIG_STRING "~Module signature appended~\n"
80493@@ -42,7 +44,7 @@ struct module_kobject {
80494 struct kobject *drivers_dir;
80495 struct module_param_attrs *mp;
80496 struct completion *kobj_completion;
80497-};
80498+} __randomize_layout;
80499
80500 struct module_attribute {
80501 struct attribute attr;
80502@@ -54,12 +56,13 @@ struct module_attribute {
80503 int (*test)(struct module *);
80504 void (*free)(struct module *);
80505 };
80506+typedef struct module_attribute __no_const module_attribute_no_const;
80507
80508 struct module_version_attribute {
80509 struct module_attribute mattr;
80510 const char *module_name;
80511 const char *version;
80512-} __attribute__ ((__aligned__(sizeof(void *))));
80513+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80514
80515 extern ssize_t __modver_version_show(struct module_attribute *,
80516 struct module_kobject *, char *);
80517@@ -238,7 +241,7 @@ struct module {
80518
80519 /* Sysfs stuff. */
80520 struct module_kobject mkobj;
80521- struct module_attribute *modinfo_attrs;
80522+ module_attribute_no_const *modinfo_attrs;
80523 const char *version;
80524 const char *srcversion;
80525 struct kobject *holders_dir;
80526@@ -287,19 +290,16 @@ struct module {
80527 int (*init)(void);
80528
80529 /* If this is non-NULL, vfree after init() returns */
80530- void *module_init;
80531+ void *module_init_rx, *module_init_rw;
80532
80533 /* Here is the actual code + data, vfree'd on unload. */
80534- void *module_core;
80535+ void *module_core_rx, *module_core_rw;
80536
80537 /* Here are the sizes of the init and core sections */
80538- unsigned int init_size, core_size;
80539+ unsigned int init_size_rw, core_size_rw;
80540
80541 /* The size of the executable code in each section. */
80542- unsigned int init_text_size, core_text_size;
80543-
80544- /* Size of RO sections of the module (text+rodata) */
80545- unsigned int init_ro_size, core_ro_size;
80546+ unsigned int init_size_rx, core_size_rx;
80547
80548 /* Arch-specific module values */
80549 struct mod_arch_specific arch;
80550@@ -355,6 +355,10 @@ struct module {
80551 #ifdef CONFIG_EVENT_TRACING
80552 struct ftrace_event_call **trace_events;
80553 unsigned int num_trace_events;
80554+ struct file_operations trace_id;
80555+ struct file_operations trace_enable;
80556+ struct file_operations trace_format;
80557+ struct file_operations trace_filter;
80558 #endif
80559 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80560 unsigned int num_ftrace_callsites;
80561@@ -378,7 +382,7 @@ struct module {
80562 ctor_fn_t *ctors;
80563 unsigned int num_ctors;
80564 #endif
80565-};
80566+} __randomize_layout;
80567 #ifndef MODULE_ARCH_INIT
80568 #define MODULE_ARCH_INIT {}
80569 #endif
80570@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80571 bool is_module_percpu_address(unsigned long addr);
80572 bool is_module_text_address(unsigned long addr);
80573
80574+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80575+{
80576+
80577+#ifdef CONFIG_PAX_KERNEXEC
80578+ if (ktla_ktva(addr) >= (unsigned long)start &&
80579+ ktla_ktva(addr) < (unsigned long)start + size)
80580+ return 1;
80581+#endif
80582+
80583+ return ((void *)addr >= start && (void *)addr < start + size);
80584+}
80585+
80586+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80587+{
80588+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80589+}
80590+
80591+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80592+{
80593+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80594+}
80595+
80596+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80597+{
80598+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80599+}
80600+
80601+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80602+{
80603+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80604+}
80605+
80606 static inline int within_module_core(unsigned long addr, const struct module *mod)
80607 {
80608- return (unsigned long)mod->module_core <= addr &&
80609- addr < (unsigned long)mod->module_core + mod->core_size;
80610+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80611 }
80612
80613 static inline int within_module_init(unsigned long addr, const struct module *mod)
80614 {
80615- return (unsigned long)mod->module_init <= addr &&
80616- addr < (unsigned long)mod->module_init + mod->init_size;
80617+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80618 }
80619
80620 /* Search for module by name: must hold module_mutex. */
80621diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80622index 560ca53..ef621ef 100644
80623--- a/include/linux/moduleloader.h
80624+++ b/include/linux/moduleloader.h
80625@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80626 sections. Returns NULL on failure. */
80627 void *module_alloc(unsigned long size);
80628
80629+#ifdef CONFIG_PAX_KERNEXEC
80630+void *module_alloc_exec(unsigned long size);
80631+#else
80632+#define module_alloc_exec(x) module_alloc(x)
80633+#endif
80634+
80635 /* Free memory returned from module_alloc. */
80636 void module_free(struct module *mod, void *module_region);
80637
80638+#ifdef CONFIG_PAX_KERNEXEC
80639+void module_free_exec(struct module *mod, void *module_region);
80640+#else
80641+#define module_free_exec(x, y) module_free((x), (y))
80642+#endif
80643+
80644 /*
80645 * Apply the given relocation to the (simplified) ELF. Return -error
80646 * or 0.
80647@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80648 unsigned int relsec,
80649 struct module *me)
80650 {
80651+#ifdef CONFIG_MODULES
80652 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80653+#endif
80654 return -ENOEXEC;
80655 }
80656 #endif
80657@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80658 unsigned int relsec,
80659 struct module *me)
80660 {
80661+#ifdef CONFIG_MODULES
80662 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80663+#endif
80664 return -ENOEXEC;
80665 }
80666 #endif
80667diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80668index c3eb102..073c4a6 100644
80669--- a/include/linux/moduleparam.h
80670+++ b/include/linux/moduleparam.h
80671@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80672 * @len is usually just sizeof(string).
80673 */
80674 #define module_param_string(name, string, len, perm) \
80675- static const struct kparam_string __param_string_##name \
80676+ static const struct kparam_string __param_string_##name __used \
80677 = { len, string }; \
80678 __module_param_call(MODULE_PARAM_PREFIX, name, \
80679 &param_ops_string, \
80680@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80681 */
80682 #define module_param_array_named(name, array, type, nump, perm) \
80683 param_check_##type(name, &(array)[0]); \
80684- static const struct kparam_array __param_arr_##name \
80685+ static const struct kparam_array __param_arr_##name __used \
80686 = { .max = ARRAY_SIZE(array), .num = nump, \
80687 .ops = &param_ops_##type, \
80688 .elemsize = sizeof(array[0]), .elem = array }; \
80689diff --git a/include/linux/mount.h b/include/linux/mount.h
80690index 839bac2..a96b37c 100644
80691--- a/include/linux/mount.h
80692+++ b/include/linux/mount.h
80693@@ -59,7 +59,7 @@ struct vfsmount {
80694 struct dentry *mnt_root; /* root of the mounted tree */
80695 struct super_block *mnt_sb; /* pointer to superblock */
80696 int mnt_flags;
80697-};
80698+} __randomize_layout;
80699
80700 struct file; /* forward dec */
80701
80702diff --git a/include/linux/namei.h b/include/linux/namei.h
80703index 492de72..1bddcd4 100644
80704--- a/include/linux/namei.h
80705+++ b/include/linux/namei.h
80706@@ -19,7 +19,7 @@ struct nameidata {
80707 unsigned seq, m_seq;
80708 int last_type;
80709 unsigned depth;
80710- char *saved_names[MAX_NESTED_LINKS + 1];
80711+ const char *saved_names[MAX_NESTED_LINKS + 1];
80712 };
80713
80714 /*
80715@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80716
80717 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80718
80719-static inline void nd_set_link(struct nameidata *nd, char *path)
80720+static inline void nd_set_link(struct nameidata *nd, const char *path)
80721 {
80722 nd->saved_names[nd->depth] = path;
80723 }
80724
80725-static inline char *nd_get_link(struct nameidata *nd)
80726+static inline const char *nd_get_link(const struct nameidata *nd)
80727 {
80728 return nd->saved_names[nd->depth];
80729 }
80730diff --git a/include/linux/net.h b/include/linux/net.h
80731index 94734a6..d8d6931 100644
80732--- a/include/linux/net.h
80733+++ b/include/linux/net.h
80734@@ -192,7 +192,7 @@ struct net_proto_family {
80735 int (*create)(struct net *net, struct socket *sock,
80736 int protocol, int kern);
80737 struct module *owner;
80738-};
80739+} __do_const;
80740
80741 struct iovec;
80742 struct kvec;
80743diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80744index daafd95..74c5d1e 100644
80745--- a/include/linux/netdevice.h
80746+++ b/include/linux/netdevice.h
80747@@ -1146,6 +1146,7 @@ struct net_device_ops {
80748 struct net_device *dev,
80749 void *priv);
80750 };
80751+typedef struct net_device_ops __no_const net_device_ops_no_const;
80752
80753 /*
80754 * The DEVICE structure.
80755@@ -1228,7 +1229,7 @@ struct net_device {
80756 int iflink;
80757
80758 struct net_device_stats stats;
80759- atomic_long_t rx_dropped; /* dropped packets by core network
80760+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80761 * Do not use this in drivers.
80762 */
80763
80764diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80765index 2077489..a15e561 100644
80766--- a/include/linux/netfilter.h
80767+++ b/include/linux/netfilter.h
80768@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80769 #endif
80770 /* Use the module struct to lock set/get code in place */
80771 struct module *owner;
80772-};
80773+} __do_const;
80774
80775 /* Function to register/unregister hook points. */
80776 int nf_register_hook(struct nf_hook_ops *reg);
80777diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80778index 28c7436..2d6156a 100644
80779--- a/include/linux/netfilter/nfnetlink.h
80780+++ b/include/linux/netfilter/nfnetlink.h
80781@@ -19,7 +19,7 @@ struct nfnl_callback {
80782 const struct nlattr * const cda[]);
80783 const struct nla_policy *policy; /* netlink attribute policy */
80784 const u_int16_t attr_count; /* number of nlattr's */
80785-};
80786+} __do_const;
80787
80788 struct nfnetlink_subsystem {
80789 const char *name;
80790diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80791new file mode 100644
80792index 0000000..33f4af8
80793--- /dev/null
80794+++ b/include/linux/netfilter/xt_gradm.h
80795@@ -0,0 +1,9 @@
80796+#ifndef _LINUX_NETFILTER_XT_GRADM_H
80797+#define _LINUX_NETFILTER_XT_GRADM_H 1
80798+
80799+struct xt_gradm_mtinfo {
80800+ __u16 flags;
80801+ __u16 invflags;
80802+};
80803+
80804+#endif
80805diff --git a/include/linux/nls.h b/include/linux/nls.h
80806index 520681b..1d67ed2 100644
80807--- a/include/linux/nls.h
80808+++ b/include/linux/nls.h
80809@@ -31,7 +31,7 @@ struct nls_table {
80810 const unsigned char *charset2upper;
80811 struct module *owner;
80812 struct nls_table *next;
80813-};
80814+} __do_const;
80815
80816 /* this value hold the maximum octet of charset */
80817 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80818diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80819index d14a4c3..a078786 100644
80820--- a/include/linux/notifier.h
80821+++ b/include/linux/notifier.h
80822@@ -54,7 +54,8 @@ struct notifier_block {
80823 notifier_fn_t notifier_call;
80824 struct notifier_block __rcu *next;
80825 int priority;
80826-};
80827+} __do_const;
80828+typedef struct notifier_block __no_const notifier_block_no_const;
80829
80830 struct atomic_notifier_head {
80831 spinlock_t lock;
80832diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80833index b2a0f15..4d7da32 100644
80834--- a/include/linux/oprofile.h
80835+++ b/include/linux/oprofile.h
80836@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80837 int oprofilefs_create_ro_ulong(struct dentry * root,
80838 char const * name, ulong * val);
80839
80840-/** Create a file for read-only access to an atomic_t. */
80841+/** Create a file for read-only access to an atomic_unchecked_t. */
80842 int oprofilefs_create_ro_atomic(struct dentry * root,
80843- char const * name, atomic_t * val);
80844+ char const * name, atomic_unchecked_t * val);
80845
80846 /** create a directory */
80847 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80848diff --git a/include/linux/padata.h b/include/linux/padata.h
80849index 4386946..f50c615 100644
80850--- a/include/linux/padata.h
80851+++ b/include/linux/padata.h
80852@@ -129,7 +129,7 @@ struct parallel_data {
80853 struct padata_serial_queue __percpu *squeue;
80854 atomic_t reorder_objects;
80855 atomic_t refcnt;
80856- atomic_t seq_nr;
80857+ atomic_unchecked_t seq_nr;
80858 struct padata_cpumask cpumask;
80859 spinlock_t lock ____cacheline_aligned;
80860 unsigned int processed;
80861diff --git a/include/linux/path.h b/include/linux/path.h
80862index d137218..be0c176 100644
80863--- a/include/linux/path.h
80864+++ b/include/linux/path.h
80865@@ -1,13 +1,15 @@
80866 #ifndef _LINUX_PATH_H
80867 #define _LINUX_PATH_H
80868
80869+#include <linux/compiler.h>
80870+
80871 struct dentry;
80872 struct vfsmount;
80873
80874 struct path {
80875 struct vfsmount *mnt;
80876 struct dentry *dentry;
80877-};
80878+} __randomize_layout;
80879
80880 extern void path_get(const struct path *);
80881 extern void path_put(const struct path *);
80882diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80883index 5f2e559..7d59314 100644
80884--- a/include/linux/pci_hotplug.h
80885+++ b/include/linux/pci_hotplug.h
80886@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80887 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80888 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80889 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80890-};
80891+} __do_const;
80892+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80893
80894 /**
80895 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80896diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80897index e56b07f..aef789b 100644
80898--- a/include/linux/perf_event.h
80899+++ b/include/linux/perf_event.h
80900@@ -328,8 +328,8 @@ struct perf_event {
80901
80902 enum perf_event_active_state state;
80903 unsigned int attach_state;
80904- local64_t count;
80905- atomic64_t child_count;
80906+ local64_t count; /* PaX: fix it one day */
80907+ atomic64_unchecked_t child_count;
80908
80909 /*
80910 * These are the total time in nanoseconds that the event
80911@@ -380,8 +380,8 @@ struct perf_event {
80912 * These accumulate total time (in nanoseconds) that children
80913 * events have been enabled and running, respectively.
80914 */
80915- atomic64_t child_total_time_enabled;
80916- atomic64_t child_total_time_running;
80917+ atomic64_unchecked_t child_total_time_enabled;
80918+ atomic64_unchecked_t child_total_time_running;
80919
80920 /*
80921 * Protect attach/detach and child_list:
80922@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80923 entry->ip[entry->nr++] = ip;
80924 }
80925
80926-extern int sysctl_perf_event_paranoid;
80927+extern int sysctl_perf_event_legitimately_concerned;
80928 extern int sysctl_perf_event_mlock;
80929 extern int sysctl_perf_event_sample_rate;
80930 extern int sysctl_perf_cpu_time_max_percent;
80931@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80932 loff_t *ppos);
80933
80934
80935+static inline bool perf_paranoid_any(void)
80936+{
80937+ return sysctl_perf_event_legitimately_concerned > 2;
80938+}
80939+
80940 static inline bool perf_paranoid_tracepoint_raw(void)
80941 {
80942- return sysctl_perf_event_paranoid > -1;
80943+ return sysctl_perf_event_legitimately_concerned > -1;
80944 }
80945
80946 static inline bool perf_paranoid_cpu(void)
80947 {
80948- return sysctl_perf_event_paranoid > 0;
80949+ return sysctl_perf_event_legitimately_concerned > 0;
80950 }
80951
80952 static inline bool perf_paranoid_kernel(void)
80953 {
80954- return sysctl_perf_event_paranoid > 1;
80955+ return sysctl_perf_event_legitimately_concerned > 1;
80956 }
80957
80958 extern void perf_event_init(void);
80959@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
80960 struct device_attribute attr;
80961 u64 id;
80962 const char *event_str;
80963-};
80964+} __do_const;
80965
80966 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80967 static struct perf_pmu_events_attr _var = { \
80968diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80969index 7246ef3..1539ea4 100644
80970--- a/include/linux/pid_namespace.h
80971+++ b/include/linux/pid_namespace.h
80972@@ -43,7 +43,7 @@ struct pid_namespace {
80973 int hide_pid;
80974 int reboot; /* group exit code if this pidns was rebooted */
80975 unsigned int proc_inum;
80976-};
80977+} __randomize_layout;
80978
80979 extern struct pid_namespace init_pid_ns;
80980
80981diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80982index ab57526..94598804 100644
80983--- a/include/linux/pipe_fs_i.h
80984+++ b/include/linux/pipe_fs_i.h
80985@@ -47,10 +47,10 @@ struct pipe_inode_info {
80986 struct mutex mutex;
80987 wait_queue_head_t wait;
80988 unsigned int nrbufs, curbuf, buffers;
80989- unsigned int readers;
80990- unsigned int writers;
80991- unsigned int files;
80992- unsigned int waiting_writers;
80993+ atomic_t readers;
80994+ atomic_t writers;
80995+ atomic_t files;
80996+ atomic_t waiting_writers;
80997 unsigned int r_counter;
80998 unsigned int w_counter;
80999 struct page *tmp_page;
81000diff --git a/include/linux/pm.h b/include/linux/pm.h
81001index 8c6583a..febb84c 100644
81002--- a/include/linux/pm.h
81003+++ b/include/linux/pm.h
81004@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81005 struct dev_pm_domain {
81006 struct dev_pm_ops ops;
81007 };
81008+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81009
81010 /*
81011 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81012diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81013index 7c1d252..0e7061d 100644
81014--- a/include/linux/pm_domain.h
81015+++ b/include/linux/pm_domain.h
81016@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81017 int (*thaw_early)(struct device *dev);
81018 int (*thaw)(struct device *dev);
81019 bool (*active_wakeup)(struct device *dev);
81020-};
81021+} __no_const;
81022
81023 struct gpd_cpu_data {
81024 unsigned int saved_exit_latency;
81025- struct cpuidle_state *idle_state;
81026+ cpuidle_state_no_const *idle_state;
81027 };
81028
81029 struct generic_pm_domain {
81030diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81031index 16c9a62..f9f0838 100644
81032--- a/include/linux/pm_runtime.h
81033+++ b/include/linux/pm_runtime.h
81034@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81035
81036 static inline void pm_runtime_mark_last_busy(struct device *dev)
81037 {
81038- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81039+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81040 }
81041
81042 #else /* !CONFIG_PM_RUNTIME */
81043diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81044index 195aafc..49a7bc2 100644
81045--- a/include/linux/pnp.h
81046+++ b/include/linux/pnp.h
81047@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81048 struct pnp_fixup {
81049 char id[7];
81050 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81051-};
81052+} __do_const;
81053
81054 /* config parameters */
81055 #define PNP_CONFIG_NORMAL 0x0001
81056diff --git a/include/linux/poison.h b/include/linux/poison.h
81057index 2110a81..13a11bb 100644
81058--- a/include/linux/poison.h
81059+++ b/include/linux/poison.h
81060@@ -19,8 +19,8 @@
81061 * under normal circumstances, used to verify that nobody uses
81062 * non-initialized list entries.
81063 */
81064-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81065-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81066+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81067+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81068
81069 /********** include/linux/timer.h **********/
81070 /*
81071diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81072index d8b187c3..9a9257a 100644
81073--- a/include/linux/power/smartreflex.h
81074+++ b/include/linux/power/smartreflex.h
81075@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81076 int (*notify)(struct omap_sr *sr, u32 status);
81077 u8 notify_flags;
81078 u8 class_type;
81079-};
81080+} __do_const;
81081
81082 /**
81083 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81084diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81085index 4ea1d37..80f4b33 100644
81086--- a/include/linux/ppp-comp.h
81087+++ b/include/linux/ppp-comp.h
81088@@ -84,7 +84,7 @@ struct compressor {
81089 struct module *owner;
81090 /* Extra skb space needed by the compressor algorithm */
81091 unsigned int comp_extra;
81092-};
81093+} __do_const;
81094
81095 /*
81096 * The return value from decompress routine is the length of the
81097diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81098index de83b4e..c4b997d 100644
81099--- a/include/linux/preempt.h
81100+++ b/include/linux/preempt.h
81101@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81102 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81103 #endif
81104
81105+#define raw_preempt_count_add(val) __preempt_count_add(val)
81106+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81107+
81108 #define __preempt_count_inc() __preempt_count_add(1)
81109 #define __preempt_count_dec() __preempt_count_sub(1)
81110
81111 #define preempt_count_inc() preempt_count_add(1)
81112+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81113 #define preempt_count_dec() preempt_count_sub(1)
81114+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81115
81116 #ifdef CONFIG_PREEMPT_COUNT
81117
81118@@ -41,6 +46,12 @@ do { \
81119 barrier(); \
81120 } while (0)
81121
81122+#define raw_preempt_disable() \
81123+do { \
81124+ raw_preempt_count_inc(); \
81125+ barrier(); \
81126+} while (0)
81127+
81128 #define sched_preempt_enable_no_resched() \
81129 do { \
81130 barrier(); \
81131@@ -49,6 +60,12 @@ do { \
81132
81133 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81134
81135+#define raw_preempt_enable_no_resched() \
81136+do { \
81137+ barrier(); \
81138+ raw_preempt_count_dec(); \
81139+} while (0)
81140+
81141 #ifdef CONFIG_PREEMPT
81142 #define preempt_enable() \
81143 do { \
81144@@ -113,8 +130,10 @@ do { \
81145 * region.
81146 */
81147 #define preempt_disable() barrier()
81148+#define raw_preempt_disable() barrier()
81149 #define sched_preempt_enable_no_resched() barrier()
81150 #define preempt_enable_no_resched() barrier()
81151+#define raw_preempt_enable_no_resched() barrier()
81152 #define preempt_enable() barrier()
81153 #define preempt_check_resched() do { } while (0)
81154
81155@@ -128,11 +147,13 @@ do { \
81156 /*
81157 * Modules have no business playing preemption tricks.
81158 */
81159+#ifndef CONFIG_PAX_KERNEXEC
81160 #undef sched_preempt_enable_no_resched
81161 #undef preempt_enable_no_resched
81162 #undef preempt_enable_no_resched_notrace
81163 #undef preempt_check_resched
81164 #endif
81165+#endif
81166
81167 #define preempt_set_need_resched() \
81168 do { \
81169diff --git a/include/linux/printk.h b/include/linux/printk.h
81170index fa47e27..c08e034 100644
81171--- a/include/linux/printk.h
81172+++ b/include/linux/printk.h
81173@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81174 void early_printk(const char *s, ...) { }
81175 #endif
81176
81177+extern int kptr_restrict;
81178+
81179 #ifdef CONFIG_PRINTK
81180 asmlinkage __printf(5, 0)
81181 int vprintk_emit(int facility, int level,
81182@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81183
81184 extern int printk_delay_msec;
81185 extern int dmesg_restrict;
81186-extern int kptr_restrict;
81187
81188 extern void wake_up_klogd(void);
81189
81190diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81191index 608e60a..bbcb1a0 100644
81192--- a/include/linux/proc_fs.h
81193+++ b/include/linux/proc_fs.h
81194@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81195 extern struct proc_dir_entry *proc_symlink(const char *,
81196 struct proc_dir_entry *, const char *);
81197 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81198+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81199 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81200 struct proc_dir_entry *, void *);
81201+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81202+ struct proc_dir_entry *, void *);
81203 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81204 struct proc_dir_entry *);
81205
81206@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81207 return proc_create_data(name, mode, parent, proc_fops, NULL);
81208 }
81209
81210+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81211+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81212+{
81213+#ifdef CONFIG_GRKERNSEC_PROC_USER
81214+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81215+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81216+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81217+#else
81218+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81219+#endif
81220+}
81221+
81222+
81223 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81224 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81225 extern void *PDE_DATA(const struct inode *);
81226@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81227 static inline struct proc_dir_entry *proc_net_mkdir(
81228 struct net *net, const char *name, struct proc_dir_entry *parent)
81229 {
81230- return proc_mkdir_data(name, 0, parent, net);
81231+ return proc_mkdir_data_restrict(name, 0, parent, net);
81232 }
81233
81234 #endif /* _LINUX_PROC_FS_H */
81235diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81236index 34a1e10..70f6bde 100644
81237--- a/include/linux/proc_ns.h
81238+++ b/include/linux/proc_ns.h
81239@@ -14,7 +14,7 @@ struct proc_ns_operations {
81240 void (*put)(void *ns);
81241 int (*install)(struct nsproxy *nsproxy, void *ns);
81242 unsigned int (*inum)(void *ns);
81243-};
81244+} __do_const __randomize_layout;
81245
81246 struct proc_ns {
81247 void *ns;
81248diff --git a/include/linux/quota.h b/include/linux/quota.h
81249index cc7494a..1e27036 100644
81250--- a/include/linux/quota.h
81251+++ b/include/linux/quota.h
81252@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81253
81254 extern bool qid_eq(struct kqid left, struct kqid right);
81255 extern bool qid_lt(struct kqid left, struct kqid right);
81256-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81257+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81258 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81259 extern bool qid_valid(struct kqid qid);
81260
81261diff --git a/include/linux/random.h b/include/linux/random.h
81262index 1cfce0e..b0b9235 100644
81263--- a/include/linux/random.h
81264+++ b/include/linux/random.h
81265@@ -9,9 +9,19 @@
81266 #include <uapi/linux/random.h>
81267
81268 extern void add_device_randomness(const void *, unsigned int);
81269+
81270+static inline void add_latent_entropy(void)
81271+{
81272+
81273+#ifdef LATENT_ENTROPY_PLUGIN
81274+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81275+#endif
81276+
81277+}
81278+
81279 extern void add_input_randomness(unsigned int type, unsigned int code,
81280- unsigned int value);
81281-extern void add_interrupt_randomness(int irq, int irq_flags);
81282+ unsigned int value) __latent_entropy;
81283+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81284
81285 extern void get_random_bytes(void *buf, int nbytes);
81286 extern void get_random_bytes_arch(void *buf, int nbytes);
81287@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81288 extern const struct file_operations random_fops, urandom_fops;
81289 #endif
81290
81291-unsigned int get_random_int(void);
81292+unsigned int __intentional_overflow(-1) get_random_int(void);
81293 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81294
81295-u32 prandom_u32(void);
81296+u32 prandom_u32(void) __intentional_overflow(-1);
81297 void prandom_bytes(void *buf, int nbytes);
81298 void prandom_seed(u32 seed);
81299 void prandom_reseed_late(void);
81300@@ -37,6 +47,11 @@ struct rnd_state {
81301 u32 prandom_u32_state(struct rnd_state *state);
81302 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81303
81304+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81305+{
81306+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81307+}
81308+
81309 /**
81310 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81311 * @ep_ro: right open interval endpoint
81312diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81313index fea49b5..2ac22bb 100644
81314--- a/include/linux/rbtree_augmented.h
81315+++ b/include/linux/rbtree_augmented.h
81316@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81317 old->rbaugmented = rbcompute(old); \
81318 } \
81319 rbstatic const struct rb_augment_callbacks rbname = { \
81320- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81321+ .propagate = rbname ## _propagate, \
81322+ .copy = rbname ## _copy, \
81323+ .rotate = rbname ## _rotate \
81324 };
81325
81326
81327diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81328index dbaf990..52e07b8 100644
81329--- a/include/linux/rculist.h
81330+++ b/include/linux/rculist.h
81331@@ -29,8 +29,8 @@
81332 */
81333 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81334 {
81335- ACCESS_ONCE(list->next) = list;
81336- ACCESS_ONCE(list->prev) = list;
81337+ ACCESS_ONCE_RW(list->next) = list;
81338+ ACCESS_ONCE_RW(list->prev) = list;
81339 }
81340
81341 /*
81342@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81343 struct list_head *prev, struct list_head *next);
81344 #endif
81345
81346+void __pax_list_add_rcu(struct list_head *new,
81347+ struct list_head *prev, struct list_head *next);
81348+
81349 /**
81350 * list_add_rcu - add a new entry to rcu-protected list
81351 * @new: new entry to be added
81352@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81353 __list_add_rcu(new, head, head->next);
81354 }
81355
81356+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81357+{
81358+ __pax_list_add_rcu(new, head, head->next);
81359+}
81360+
81361 /**
81362 * list_add_tail_rcu - add a new entry to rcu-protected list
81363 * @new: new entry to be added
81364@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81365 __list_add_rcu(new, head->prev, head);
81366 }
81367
81368+static inline void pax_list_add_tail_rcu(struct list_head *new,
81369+ struct list_head *head)
81370+{
81371+ __pax_list_add_rcu(new, head->prev, head);
81372+}
81373+
81374 /**
81375 * list_del_rcu - deletes entry from list without re-initialization
81376 * @entry: the element to delete from the list.
81377@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81378 entry->prev = LIST_POISON2;
81379 }
81380
81381+extern void pax_list_del_rcu(struct list_head *entry);
81382+
81383 /**
81384 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81385 * @n: the element to delete from the hash list.
81386diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81387index 72bf3a0..853347f 100644
81388--- a/include/linux/rcupdate.h
81389+++ b/include/linux/rcupdate.h
81390@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81391 #define rcu_assign_pointer(p, v) \
81392 do { \
81393 smp_wmb(); \
81394- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81395+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81396 } while (0)
81397
81398
81399diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81400index 9e7db9e..7d4fd72 100644
81401--- a/include/linux/reboot.h
81402+++ b/include/linux/reboot.h
81403@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81404 */
81405
81406 extern void migrate_to_reboot_cpu(void);
81407-extern void machine_restart(char *cmd);
81408-extern void machine_halt(void);
81409-extern void machine_power_off(void);
81410+extern void machine_restart(char *cmd) __noreturn;
81411+extern void machine_halt(void) __noreturn;
81412+extern void machine_power_off(void) __noreturn;
81413
81414 extern void machine_shutdown(void);
81415 struct pt_regs;
81416@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81417 */
81418
81419 extern void kernel_restart_prepare(char *cmd);
81420-extern void kernel_restart(char *cmd);
81421-extern void kernel_halt(void);
81422-extern void kernel_power_off(void);
81423+extern void kernel_restart(char *cmd) __noreturn;
81424+extern void kernel_halt(void) __noreturn;
81425+extern void kernel_power_off(void) __noreturn;
81426
81427 extern int C_A_D; /* for sysctl */
81428 void ctrl_alt_del(void);
81429@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81430 * Emergency restart, callable from an interrupt handler.
81431 */
81432
81433-extern void emergency_restart(void);
81434+extern void emergency_restart(void) __noreturn;
81435 #include <asm/emergency-restart.h>
81436
81437 #endif /* _LINUX_REBOOT_H */
81438diff --git a/include/linux/regset.h b/include/linux/regset.h
81439index 8e0c9fe..ac4d221 100644
81440--- a/include/linux/regset.h
81441+++ b/include/linux/regset.h
81442@@ -161,7 +161,8 @@ struct user_regset {
81443 unsigned int align;
81444 unsigned int bias;
81445 unsigned int core_note_type;
81446-};
81447+} __do_const;
81448+typedef struct user_regset __no_const user_regset_no_const;
81449
81450 /**
81451 * struct user_regset_view - available regsets
81452diff --git a/include/linux/relay.h b/include/linux/relay.h
81453index d7c8359..818daf5 100644
81454--- a/include/linux/relay.h
81455+++ b/include/linux/relay.h
81456@@ -157,7 +157,7 @@ struct rchan_callbacks
81457 * The callback should return 0 if successful, negative if not.
81458 */
81459 int (*remove_buf_file)(struct dentry *dentry);
81460-};
81461+} __no_const;
81462
81463 /*
81464 * CONFIG_RELAY kernel API, kernel/relay.c
81465diff --git a/include/linux/rio.h b/include/linux/rio.h
81466index b71d573..2f940bd 100644
81467--- a/include/linux/rio.h
81468+++ b/include/linux/rio.h
81469@@ -355,7 +355,7 @@ struct rio_ops {
81470 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81471 u64 rstart, u32 size, u32 flags);
81472 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81473-};
81474+} __no_const;
81475
81476 #define RIO_RESOURCE_MEM 0x00000100
81477 #define RIO_RESOURCE_DOORBELL 0x00000200
81478diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81479index b66c211..13d2915 100644
81480--- a/include/linux/rmap.h
81481+++ b/include/linux/rmap.h
81482@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81483 void anon_vma_init(void); /* create anon_vma_cachep */
81484 int anon_vma_prepare(struct vm_area_struct *);
81485 void unlink_anon_vmas(struct vm_area_struct *);
81486-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81487-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81488+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81489+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81490
81491 static inline void anon_vma_merge(struct vm_area_struct *vma,
81492 struct vm_area_struct *next)
81493diff --git a/include/linux/sched.h b/include/linux/sched.h
81494index a781dec..be1d2a3 100644
81495--- a/include/linux/sched.h
81496+++ b/include/linux/sched.h
81497@@ -129,6 +129,7 @@ struct fs_struct;
81498 struct perf_event_context;
81499 struct blk_plug;
81500 struct filename;
81501+struct linux_binprm;
81502
81503 /*
81504 * List of flags we want to share for kernel threads,
81505@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81506 extern int in_sched_functions(unsigned long addr);
81507
81508 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81509-extern signed long schedule_timeout(signed long timeout);
81510+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81511 extern signed long schedule_timeout_interruptible(signed long timeout);
81512 extern signed long schedule_timeout_killable(signed long timeout);
81513 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81514@@ -380,6 +381,19 @@ struct nsproxy;
81515 struct user_namespace;
81516
81517 #ifdef CONFIG_MMU
81518+
81519+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81520+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81521+#else
81522+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81523+{
81524+ return 0;
81525+}
81526+#endif
81527+
81528+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81529+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81530+
81531 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81532 extern unsigned long
81533 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81534@@ -677,6 +691,17 @@ struct signal_struct {
81535 #ifdef CONFIG_TASKSTATS
81536 struct taskstats *stats;
81537 #endif
81538+
81539+#ifdef CONFIG_GRKERNSEC
81540+ u32 curr_ip;
81541+ u32 saved_ip;
81542+ u32 gr_saddr;
81543+ u32 gr_daddr;
81544+ u16 gr_sport;
81545+ u16 gr_dport;
81546+ u8 used_accept:1;
81547+#endif
81548+
81549 #ifdef CONFIG_AUDIT
81550 unsigned audit_tty;
81551 unsigned audit_tty_log_passwd;
81552@@ -703,7 +728,7 @@ struct signal_struct {
81553 struct mutex cred_guard_mutex; /* guard against foreign influences on
81554 * credential calculations
81555 * (notably. ptrace) */
81556-};
81557+} __randomize_layout;
81558
81559 /*
81560 * Bits in flags field of signal_struct.
81561@@ -757,6 +782,14 @@ struct user_struct {
81562 struct key *session_keyring; /* UID's default session keyring */
81563 #endif
81564
81565+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81566+ unsigned char kernel_banned;
81567+#endif
81568+#ifdef CONFIG_GRKERNSEC_BRUTE
81569+ unsigned char suid_banned;
81570+ unsigned long suid_ban_expires;
81571+#endif
81572+
81573 /* Hash table maintenance information */
81574 struct hlist_node uidhash_node;
81575 kuid_t uid;
81576@@ -764,7 +797,7 @@ struct user_struct {
81577 #ifdef CONFIG_PERF_EVENTS
81578 atomic_long_t locked_vm;
81579 #endif
81580-};
81581+} __randomize_layout;
81582
81583 extern int uids_sysfs_init(void);
81584
81585@@ -1286,8 +1319,8 @@ struct task_struct {
81586 struct list_head thread_node;
81587
81588 struct completion *vfork_done; /* for vfork() */
81589- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81590- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81591+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81592+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81593
81594 cputime_t utime, stime, utimescaled, stimescaled;
81595 cputime_t gtime;
81596@@ -1312,11 +1345,6 @@ struct task_struct {
81597 struct task_cputime cputime_expires;
81598 struct list_head cpu_timers[3];
81599
81600-/* process credentials */
81601- const struct cred __rcu *real_cred; /* objective and real subjective task
81602- * credentials (COW) */
81603- const struct cred __rcu *cred; /* effective (overridable) subjective task
81604- * credentials (COW) */
81605 char comm[TASK_COMM_LEN]; /* executable name excluding path
81606 - access with [gs]et_task_comm (which lock
81607 it with task_lock())
81608@@ -1333,6 +1361,10 @@ struct task_struct {
81609 #endif
81610 /* CPU-specific state of this task */
81611 struct thread_struct thread;
81612+/* thread_info moved to task_struct */
81613+#ifdef CONFIG_X86
81614+ struct thread_info tinfo;
81615+#endif
81616 /* filesystem information */
81617 struct fs_struct *fs;
81618 /* open file information */
81619@@ -1409,6 +1441,10 @@ struct task_struct {
81620 gfp_t lockdep_reclaim_gfp;
81621 #endif
81622
81623+/* process credentials */
81624+ const struct cred __rcu *real_cred; /* objective and real subjective task
81625+ * credentials (COW) */
81626+
81627 /* journalling filesystem info */
81628 void *journal_info;
81629
81630@@ -1447,6 +1483,10 @@ struct task_struct {
81631 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81632 struct list_head cg_list;
81633 #endif
81634+
81635+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81636+ * credentials (COW) */
81637+
81638 #ifdef CONFIG_FUTEX
81639 struct robust_list_head __user *robust_list;
81640 #ifdef CONFIG_COMPAT
81641@@ -1581,7 +1621,78 @@ struct task_struct {
81642 unsigned int sequential_io;
81643 unsigned int sequential_io_avg;
81644 #endif
81645-};
81646+
81647+#ifdef CONFIG_GRKERNSEC
81648+ /* grsecurity */
81649+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81650+ u64 exec_id;
81651+#endif
81652+#ifdef CONFIG_GRKERNSEC_SETXID
81653+ const struct cred *delayed_cred;
81654+#endif
81655+ struct dentry *gr_chroot_dentry;
81656+ struct acl_subject_label *acl;
81657+ struct acl_subject_label *tmpacl;
81658+ struct acl_role_label *role;
81659+ struct file *exec_file;
81660+ unsigned long brute_expires;
81661+ u16 acl_role_id;
81662+ u8 inherited;
81663+ /* is this the task that authenticated to the special role */
81664+ u8 acl_sp_role;
81665+ u8 is_writable;
81666+ u8 brute;
81667+ u8 gr_is_chrooted;
81668+#endif
81669+
81670+} __randomize_layout;
81671+
81672+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81673+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81674+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81675+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81676+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81677+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81678+
81679+#ifdef CONFIG_PAX_SOFTMODE
81680+extern int pax_softmode;
81681+#endif
81682+
81683+extern int pax_check_flags(unsigned long *);
81684+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81685+
81686+/* if tsk != current then task_lock must be held on it */
81687+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81688+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81689+{
81690+ if (likely(tsk->mm))
81691+ return tsk->mm->pax_flags;
81692+ else
81693+ return 0UL;
81694+}
81695+
81696+/* if tsk != current then task_lock must be held on it */
81697+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81698+{
81699+ if (likely(tsk->mm)) {
81700+ tsk->mm->pax_flags = flags;
81701+ return 0;
81702+ }
81703+ return -EINVAL;
81704+}
81705+#endif
81706+
81707+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81708+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81709+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81710+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81711+#endif
81712+
81713+struct path;
81714+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81715+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81716+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81717+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81718
81719 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81720 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81721@@ -1658,7 +1769,7 @@ struct pid_namespace;
81722 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81723 struct pid_namespace *ns);
81724
81725-static inline pid_t task_pid_nr(struct task_struct *tsk)
81726+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81727 {
81728 return tsk->pid;
81729 }
81730@@ -2112,7 +2223,9 @@ void yield(void);
81731 extern struct exec_domain default_exec_domain;
81732
81733 union thread_union {
81734+#ifndef CONFIG_X86
81735 struct thread_info thread_info;
81736+#endif
81737 unsigned long stack[THREAD_SIZE/sizeof(long)];
81738 };
81739
81740@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81741 */
81742
81743 extern struct task_struct *find_task_by_vpid(pid_t nr);
81744+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81745 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81746 struct pid_namespace *ns);
81747
81748@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81749 extern void exit_itimers(struct signal_struct *);
81750 extern void flush_itimer_signals(void);
81751
81752-extern void do_group_exit(int);
81753+extern __noreturn void do_group_exit(int);
81754
81755 extern int allow_signal(int);
81756 extern int disallow_signal(int);
81757@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81758
81759 #endif
81760
81761-static inline int object_is_on_stack(void *obj)
81762+static inline int object_starts_on_stack(void *obj)
81763 {
81764- void *stack = task_stack_page(current);
81765+ const void *stack = task_stack_page(current);
81766
81767 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81768 }
81769diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81770index 8045a55..c959cd5 100644
81771--- a/include/linux/sched/sysctl.h
81772+++ b/include/linux/sched/sysctl.h
81773@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81774 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81775
81776 extern int sysctl_max_map_count;
81777+extern unsigned long sysctl_heap_stack_gap;
81778
81779 extern unsigned int sysctl_sched_latency;
81780 extern unsigned int sysctl_sched_min_granularity;
81781diff --git a/include/linux/security.h b/include/linux/security.h
81782index 2fc42d1..4d802f2 100644
81783--- a/include/linux/security.h
81784+++ b/include/linux/security.h
81785@@ -27,6 +27,7 @@
81786 #include <linux/slab.h>
81787 #include <linux/err.h>
81788 #include <linux/string.h>
81789+#include <linux/grsecurity.h>
81790
81791 struct linux_binprm;
81792 struct cred;
81793@@ -116,8 +117,6 @@ struct seq_file;
81794
81795 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81796
81797-void reset_security_ops(void);
81798-
81799 #ifdef CONFIG_MMU
81800 extern unsigned long mmap_min_addr;
81801 extern unsigned long dac_mmap_min_addr;
81802@@ -1719,7 +1718,7 @@ struct security_operations {
81803 struct audit_context *actx);
81804 void (*audit_rule_free) (void *lsmrule);
81805 #endif /* CONFIG_AUDIT */
81806-};
81807+} __randomize_layout;
81808
81809 /* prototypes */
81810 extern int security_init(void);
81811diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81812index dc368b8..e895209 100644
81813--- a/include/linux/semaphore.h
81814+++ b/include/linux/semaphore.h
81815@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81816 }
81817
81818 extern void down(struct semaphore *sem);
81819-extern int __must_check down_interruptible(struct semaphore *sem);
81820+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81821 extern int __must_check down_killable(struct semaphore *sem);
81822 extern int __must_check down_trylock(struct semaphore *sem);
81823 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81824diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81825index 52e0097..383f21d 100644
81826--- a/include/linux/seq_file.h
81827+++ b/include/linux/seq_file.h
81828@@ -27,6 +27,9 @@ struct seq_file {
81829 struct mutex lock;
81830 const struct seq_operations *op;
81831 int poll_event;
81832+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81833+ u64 exec_id;
81834+#endif
81835 #ifdef CONFIG_USER_NS
81836 struct user_namespace *user_ns;
81837 #endif
81838@@ -39,6 +42,7 @@ struct seq_operations {
81839 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81840 int (*show) (struct seq_file *m, void *v);
81841 };
81842+typedef struct seq_operations __no_const seq_operations_no_const;
81843
81844 #define SEQ_SKIP 1
81845
81846@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
81847
81848 char *mangle_path(char *s, const char *p, const char *esc);
81849 int seq_open(struct file *, const struct seq_operations *);
81850+int seq_open_restrict(struct file *, const struct seq_operations *);
81851 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
81852 loff_t seq_lseek(struct file *, loff_t, int);
81853 int seq_release(struct inode *, struct file *);
81854@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
81855 }
81856
81857 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
81858+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
81859 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
81860 int single_release(struct inode *, struct file *);
81861 void *__seq_open_private(struct file *, const struct seq_operations *, int);
81862diff --git a/include/linux/shm.h b/include/linux/shm.h
81863index 1e2cd2e..0288750 100644
81864--- a/include/linux/shm.h
81865+++ b/include/linux/shm.h
81866@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81867
81868 /* The task created the shm object. NULL if the task is dead. */
81869 struct task_struct *shm_creator;
81870+#ifdef CONFIG_GRKERNSEC
81871+ time_t shm_createtime;
81872+ pid_t shm_lapid;
81873+#endif
81874 };
81875
81876 /* shm_mode upper byte flags */
81877diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81878index 15ede6a..80161c3 100644
81879--- a/include/linux/skbuff.h
81880+++ b/include/linux/skbuff.h
81881@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81882 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81883 int node);
81884 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81885-static inline struct sk_buff *alloc_skb(unsigned int size,
81886+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81887 gfp_t priority)
81888 {
81889 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81890@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81891 return skb->inner_transport_header - skb->inner_network_header;
81892 }
81893
81894-static inline int skb_network_offset(const struct sk_buff *skb)
81895+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81896 {
81897 return skb_network_header(skb) - skb->data;
81898 }
81899@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81900 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81901 */
81902 #ifndef NET_SKB_PAD
81903-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81904+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81905 #endif
81906
81907 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81908@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81909 int *err);
81910 unsigned int datagram_poll(struct file *file, struct socket *sock,
81911 struct poll_table_struct *wait);
81912-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81913+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81914 struct iovec *to, int size);
81915 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81916 struct iovec *iov);
81917@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
81918 nf_bridge_put(skb->nf_bridge);
81919 skb->nf_bridge = NULL;
81920 #endif
81921+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81922+ skb->nf_trace = 0;
81923+#endif
81924 }
81925
81926 static inline void nf_reset_trace(struct sk_buff *skb)
81927diff --git a/include/linux/slab.h b/include/linux/slab.h
81928index b5b2df6..69f5734 100644
81929--- a/include/linux/slab.h
81930+++ b/include/linux/slab.h
81931@@ -14,15 +14,29 @@
81932 #include <linux/gfp.h>
81933 #include <linux/types.h>
81934 #include <linux/workqueue.h>
81935-
81936+#include <linux/err.h>
81937
81938 /*
81939 * Flags to pass to kmem_cache_create().
81940 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81941 */
81942 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81943+
81944+#ifdef CONFIG_PAX_USERCOPY_SLABS
81945+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81946+#else
81947+#define SLAB_USERCOPY 0x00000000UL
81948+#endif
81949+
81950 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81951 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81952+
81953+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81954+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81955+#else
81956+#define SLAB_NO_SANITIZE 0x00000000UL
81957+#endif
81958+
81959 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81960 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81961 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81962@@ -98,10 +112,13 @@
81963 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81964 * Both make kfree a no-op.
81965 */
81966-#define ZERO_SIZE_PTR ((void *)16)
81967+#define ZERO_SIZE_PTR \
81968+({ \
81969+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81970+ (void *)(-MAX_ERRNO-1L); \
81971+})
81972
81973-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81974- (unsigned long)ZERO_SIZE_PTR)
81975+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81976
81977 #include <linux/kmemleak.h>
81978
81979@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81980 void kfree(const void *);
81981 void kzfree(const void *);
81982 size_t ksize(const void *);
81983+const char *check_heap_object(const void *ptr, unsigned long n);
81984+bool is_usercopy_object(const void *ptr);
81985
81986 /*
81987 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81988@@ -174,7 +193,7 @@ struct kmem_cache {
81989 unsigned int align; /* Alignment as calculated */
81990 unsigned long flags; /* Active flags on the slab */
81991 const char *name; /* Slab name for sysfs */
81992- int refcount; /* Use counter */
81993+ atomic_t refcount; /* Use counter */
81994 void (*ctor)(void *); /* Called on object slot creation */
81995 struct list_head list; /* List of all slab caches on the system */
81996 };
81997@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81998 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81999 #endif
82000
82001+#ifdef CONFIG_PAX_USERCOPY_SLABS
82002+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82003+#endif
82004+
82005 /*
82006 * Figure out which kmalloc slab an allocation of a certain size
82007 * belongs to.
82008@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82009 * 2 = 120 .. 192 bytes
82010 * n = 2^(n-1) .. 2^n -1
82011 */
82012-static __always_inline int kmalloc_index(size_t size)
82013+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82014 {
82015 if (!size)
82016 return 0;
82017@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82018 }
82019 #endif /* !CONFIG_SLOB */
82020
82021-void *__kmalloc(size_t size, gfp_t flags);
82022+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82023 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82024
82025 #ifdef CONFIG_NUMA
82026-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82027+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82028 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82029 #else
82030 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82031diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82032index 8235dfb..47ce586 100644
82033--- a/include/linux/slab_def.h
82034+++ b/include/linux/slab_def.h
82035@@ -38,7 +38,7 @@ struct kmem_cache {
82036 /* 4) cache creation/removal */
82037 const char *name;
82038 struct list_head list;
82039- int refcount;
82040+ atomic_t refcount;
82041 int object_size;
82042 int align;
82043
82044@@ -54,10 +54,14 @@ struct kmem_cache {
82045 unsigned long node_allocs;
82046 unsigned long node_frees;
82047 unsigned long node_overflow;
82048- atomic_t allochit;
82049- atomic_t allocmiss;
82050- atomic_t freehit;
82051- atomic_t freemiss;
82052+ atomic_unchecked_t allochit;
82053+ atomic_unchecked_t allocmiss;
82054+ atomic_unchecked_t freehit;
82055+ atomic_unchecked_t freemiss;
82056+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82057+ atomic_unchecked_t sanitized;
82058+ atomic_unchecked_t not_sanitized;
82059+#endif
82060
82061 /*
82062 * If debugging is enabled, then the allocator can add additional
82063diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82064index f56bfa9..8378a26 100644
82065--- a/include/linux/slub_def.h
82066+++ b/include/linux/slub_def.h
82067@@ -74,7 +74,7 @@ struct kmem_cache {
82068 struct kmem_cache_order_objects max;
82069 struct kmem_cache_order_objects min;
82070 gfp_t allocflags; /* gfp flags to use on each alloc */
82071- int refcount; /* Refcount for slab cache destroy */
82072+ atomic_t refcount; /* Refcount for slab cache destroy */
82073 void (*ctor)(void *);
82074 int inuse; /* Offset to metadata */
82075 int align; /* Alignment */
82076diff --git a/include/linux/smp.h b/include/linux/smp.h
82077index 6ae004e..2743532 100644
82078--- a/include/linux/smp.h
82079+++ b/include/linux/smp.h
82080@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82081 #endif
82082
82083 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82084+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82085 #define put_cpu() preempt_enable()
82086+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82087
82088 /*
82089 * Callback to arch code if there's nosmp or maxcpus=0 on the
82090diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82091index 54f91d3..be2c379 100644
82092--- a/include/linux/sock_diag.h
82093+++ b/include/linux/sock_diag.h
82094@@ -11,7 +11,7 @@ struct sock;
82095 struct sock_diag_handler {
82096 __u8 family;
82097 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82098-};
82099+} __do_const;
82100
82101 int sock_diag_register(const struct sock_diag_handler *h);
82102 void sock_diag_unregister(const struct sock_diag_handler *h);
82103diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82104index 680f9a3..f13aeb0 100644
82105--- a/include/linux/sonet.h
82106+++ b/include/linux/sonet.h
82107@@ -7,7 +7,7 @@
82108 #include <uapi/linux/sonet.h>
82109
82110 struct k_sonet_stats {
82111-#define __HANDLE_ITEM(i) atomic_t i
82112+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82113 __SONET_ITEMS
82114 #undef __HANDLE_ITEM
82115 };
82116diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82117index 07d8e53..dc934c9 100644
82118--- a/include/linux/sunrpc/addr.h
82119+++ b/include/linux/sunrpc/addr.h
82120@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82121 {
82122 switch (sap->sa_family) {
82123 case AF_INET:
82124- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82125+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82126 case AF_INET6:
82127- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82128+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82129 }
82130 return 0;
82131 }
82132@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82133 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82134 const struct sockaddr *src)
82135 {
82136- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82137+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82138 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82139
82140 dsin->sin_family = ssin->sin_family;
82141@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82142 if (sa->sa_family != AF_INET6)
82143 return 0;
82144
82145- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82146+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82147 }
82148
82149 #endif /* _LINUX_SUNRPC_ADDR_H */
82150diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82151index 8af2804..c7414ef 100644
82152--- a/include/linux/sunrpc/clnt.h
82153+++ b/include/linux/sunrpc/clnt.h
82154@@ -97,7 +97,7 @@ struct rpc_procinfo {
82155 unsigned int p_timer; /* Which RTT timer to use */
82156 u32 p_statidx; /* Which procedure to account */
82157 const char * p_name; /* name of procedure */
82158-};
82159+} __do_const;
82160
82161 #ifdef __KERNEL__
82162
82163diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82164index 04e7632..2e2a8a3 100644
82165--- a/include/linux/sunrpc/svc.h
82166+++ b/include/linux/sunrpc/svc.h
82167@@ -412,7 +412,7 @@ struct svc_procedure {
82168 unsigned int pc_count; /* call count */
82169 unsigned int pc_cachetype; /* cache info (NFS) */
82170 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82171-};
82172+} __do_const;
82173
82174 /*
82175 * Function prototypes.
82176diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82177index 0b8e3e6..33e0a01 100644
82178--- a/include/linux/sunrpc/svc_rdma.h
82179+++ b/include/linux/sunrpc/svc_rdma.h
82180@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82181 extern unsigned int svcrdma_max_requests;
82182 extern unsigned int svcrdma_max_req_size;
82183
82184-extern atomic_t rdma_stat_recv;
82185-extern atomic_t rdma_stat_read;
82186-extern atomic_t rdma_stat_write;
82187-extern atomic_t rdma_stat_sq_starve;
82188-extern atomic_t rdma_stat_rq_starve;
82189-extern atomic_t rdma_stat_rq_poll;
82190-extern atomic_t rdma_stat_rq_prod;
82191-extern atomic_t rdma_stat_sq_poll;
82192-extern atomic_t rdma_stat_sq_prod;
82193+extern atomic_unchecked_t rdma_stat_recv;
82194+extern atomic_unchecked_t rdma_stat_read;
82195+extern atomic_unchecked_t rdma_stat_write;
82196+extern atomic_unchecked_t rdma_stat_sq_starve;
82197+extern atomic_unchecked_t rdma_stat_rq_starve;
82198+extern atomic_unchecked_t rdma_stat_rq_poll;
82199+extern atomic_unchecked_t rdma_stat_rq_prod;
82200+extern atomic_unchecked_t rdma_stat_sq_poll;
82201+extern atomic_unchecked_t rdma_stat_sq_prod;
82202
82203 #define RPCRDMA_VERSION 1
82204
82205diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82206index 8d71d65..f79586e 100644
82207--- a/include/linux/sunrpc/svcauth.h
82208+++ b/include/linux/sunrpc/svcauth.h
82209@@ -120,7 +120,7 @@ struct auth_ops {
82210 int (*release)(struct svc_rqst *rq);
82211 void (*domain_release)(struct auth_domain *);
82212 int (*set_client)(struct svc_rqst *rq);
82213-};
82214+} __do_const;
82215
82216 #define SVC_GARBAGE 1
82217 #define SVC_SYSERR 2
82218diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82219index a5ffd32..0935dea 100644
82220--- a/include/linux/swiotlb.h
82221+++ b/include/linux/swiotlb.h
82222@@ -60,7 +60,8 @@ extern void
82223
82224 extern void
82225 swiotlb_free_coherent(struct device *hwdev, size_t size,
82226- void *vaddr, dma_addr_t dma_handle);
82227+ void *vaddr, dma_addr_t dma_handle,
82228+ struct dma_attrs *attrs);
82229
82230 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82231 unsigned long offset, size_t size,
82232diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82233index a747a77..9e14df7 100644
82234--- a/include/linux/syscalls.h
82235+++ b/include/linux/syscalls.h
82236@@ -98,8 +98,14 @@ struct sigaltstack;
82237 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82238
82239 #define __SC_DECL(t, a) t a
82240+#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))
82241 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82242-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82243+#define __SC_LONG(t, a) __typeof( \
82244+ __builtin_choose_expr( \
82245+ sizeof(t) > sizeof(int), \
82246+ (t) 0, \
82247+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82248+ )) a
82249 #define __SC_CAST(t, a) (t) a
82250 #define __SC_ARGS(t, a) a
82251 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82252@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82253 asmlinkage long sys_fsync(unsigned int fd);
82254 asmlinkage long sys_fdatasync(unsigned int fd);
82255 asmlinkage long sys_bdflush(int func, long data);
82256-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82257- char __user *type, unsigned long flags,
82258+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82259+ const char __user *type, unsigned long flags,
82260 void __user *data);
82261-asmlinkage long sys_umount(char __user *name, int flags);
82262-asmlinkage long sys_oldumount(char __user *name);
82263+asmlinkage long sys_umount(const char __user *name, int flags);
82264+asmlinkage long sys_oldumount(const char __user *name);
82265 asmlinkage long sys_truncate(const char __user *path, long length);
82266 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82267 asmlinkage long sys_stat(const char __user *filename,
82268@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82269 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82270 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82271 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82272- struct sockaddr __user *, int);
82273+ struct sockaddr __user *, int) __intentional_overflow(0);
82274 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82275 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82276 unsigned int vlen, unsigned flags);
82277diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82278index 27b3b0b..e093dd9 100644
82279--- a/include/linux/syscore_ops.h
82280+++ b/include/linux/syscore_ops.h
82281@@ -16,7 +16,7 @@ struct syscore_ops {
82282 int (*suspend)(void);
82283 void (*resume)(void);
82284 void (*shutdown)(void);
82285-};
82286+} __do_const;
82287
82288 extern void register_syscore_ops(struct syscore_ops *ops);
82289 extern void unregister_syscore_ops(struct syscore_ops *ops);
82290diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82291index 14a8ff2..fa95f3a 100644
82292--- a/include/linux/sysctl.h
82293+++ b/include/linux/sysctl.h
82294@@ -34,13 +34,13 @@ struct ctl_table_root;
82295 struct ctl_table_header;
82296 struct ctl_dir;
82297
82298-typedef struct ctl_table ctl_table;
82299-
82300 typedef int proc_handler (struct ctl_table *ctl, int write,
82301 void __user *buffer, size_t *lenp, loff_t *ppos);
82302
82303 extern int proc_dostring(struct ctl_table *, int,
82304 void __user *, size_t *, loff_t *);
82305+extern int proc_dostring_modpriv(struct ctl_table *, int,
82306+ void __user *, size_t *, loff_t *);
82307 extern int proc_dointvec(struct ctl_table *, int,
82308 void __user *, size_t *, loff_t *);
82309 extern int proc_dointvec_minmax(struct ctl_table *, int,
82310@@ -115,7 +115,9 @@ struct ctl_table
82311 struct ctl_table_poll *poll;
82312 void *extra1;
82313 void *extra2;
82314-};
82315+} __do_const __randomize_layout;
82316+typedef struct ctl_table __no_const ctl_table_no_const;
82317+typedef struct ctl_table ctl_table;
82318
82319 struct ctl_node {
82320 struct rb_node node;
82321diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82322index 30b2ebe..37412ef 100644
82323--- a/include/linux/sysfs.h
82324+++ b/include/linux/sysfs.h
82325@@ -34,7 +34,8 @@ struct attribute {
82326 struct lock_class_key *key;
82327 struct lock_class_key skey;
82328 #endif
82329-};
82330+} __do_const;
82331+typedef struct attribute __no_const attribute_no_const;
82332
82333 /**
82334 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82335@@ -63,7 +64,8 @@ struct attribute_group {
82336 struct attribute *, int);
82337 struct attribute **attrs;
82338 struct bin_attribute **bin_attrs;
82339-};
82340+} __do_const;
82341+typedef struct attribute_group __no_const attribute_group_no_const;
82342
82343 /**
82344 * Use these macros to make defining attributes easier. See include/linux/device.h
82345@@ -127,7 +129,8 @@ struct bin_attribute {
82346 char *, loff_t, size_t);
82347 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82348 struct vm_area_struct *vma);
82349-};
82350+} __do_const;
82351+typedef struct bin_attribute __no_const bin_attribute_no_const;
82352
82353 /**
82354 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82355diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82356index 387fa7d..3fcde6b 100644
82357--- a/include/linux/sysrq.h
82358+++ b/include/linux/sysrq.h
82359@@ -16,6 +16,7 @@
82360
82361 #include <linux/errno.h>
82362 #include <linux/types.h>
82363+#include <linux/compiler.h>
82364
82365 /* Possible values of bitmask for enabling sysrq functions */
82366 /* 0x0001 is reserved for enable everything */
82367@@ -33,7 +34,7 @@ struct sysrq_key_op {
82368 char *help_msg;
82369 char *action_msg;
82370 int enable_mask;
82371-};
82372+} __do_const;
82373
82374 #ifdef CONFIG_MAGIC_SYSRQ
82375
82376diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82377index fddbe20..0312de8 100644
82378--- a/include/linux/thread_info.h
82379+++ b/include/linux/thread_info.h
82380@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82381 #error "no set_restore_sigmask() provided and default one won't work"
82382 #endif
82383
82384+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82385+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82386+{
82387+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82388+ if (!__builtin_constant_p(n))
82389+#endif
82390+ __check_object_size(ptr, n, to_user);
82391+}
82392+
82393 #endif /* __KERNEL__ */
82394
82395 #endif /* _LINUX_THREAD_INFO_H */
82396diff --git a/include/linux/tty.h b/include/linux/tty.h
82397index b90b5c2..e23a512 100644
82398--- a/include/linux/tty.h
82399+++ b/include/linux/tty.h
82400@@ -202,7 +202,7 @@ struct tty_port {
82401 const struct tty_port_operations *ops; /* Port operations */
82402 spinlock_t lock; /* Lock protecting tty field */
82403 int blocked_open; /* Waiting to open */
82404- int count; /* Usage count */
82405+ atomic_t count; /* Usage count */
82406 wait_queue_head_t open_wait; /* Open waiters */
82407 wait_queue_head_t close_wait; /* Close waiters */
82408 wait_queue_head_t delta_msr_wait; /* Modem status change */
82409@@ -284,7 +284,7 @@ struct tty_struct {
82410 /* If the tty has a pending do_SAK, queue it here - akpm */
82411 struct work_struct SAK_work;
82412 struct tty_port *port;
82413-};
82414+} __randomize_layout;
82415
82416 /* Each of a tty's open files has private_data pointing to tty_file_private */
82417 struct tty_file_private {
82418@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82419 struct tty_struct *tty, struct file *filp);
82420 static inline int tty_port_users(struct tty_port *port)
82421 {
82422- return port->count + port->blocked_open;
82423+ return atomic_read(&port->count) + port->blocked_open;
82424 }
82425
82426 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82427diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82428index 756a609..89db85e 100644
82429--- a/include/linux/tty_driver.h
82430+++ b/include/linux/tty_driver.h
82431@@ -285,7 +285,7 @@ struct tty_operations {
82432 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82433 #endif
82434 const struct file_operations *proc_fops;
82435-};
82436+} __do_const __randomize_layout;
82437
82438 struct tty_driver {
82439 int magic; /* magic number for this structure */
82440@@ -319,7 +319,7 @@ struct tty_driver {
82441
82442 const struct tty_operations *ops;
82443 struct list_head tty_drivers;
82444-};
82445+} __randomize_layout;
82446
82447 extern struct list_head tty_drivers;
82448
82449diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82450index b8347c2..85d8b0f 100644
82451--- a/include/linux/tty_ldisc.h
82452+++ b/include/linux/tty_ldisc.h
82453@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82454
82455 struct module *owner;
82456
82457- int refcount;
82458+ atomic_t refcount;
82459 };
82460
82461 struct tty_ldisc {
82462diff --git a/include/linux/types.h b/include/linux/types.h
82463index 4d118ba..c3ee9bf 100644
82464--- a/include/linux/types.h
82465+++ b/include/linux/types.h
82466@@ -176,10 +176,26 @@ typedef struct {
82467 int counter;
82468 } atomic_t;
82469
82470+#ifdef CONFIG_PAX_REFCOUNT
82471+typedef struct {
82472+ int counter;
82473+} atomic_unchecked_t;
82474+#else
82475+typedef atomic_t atomic_unchecked_t;
82476+#endif
82477+
82478 #ifdef CONFIG_64BIT
82479 typedef struct {
82480 long counter;
82481 } atomic64_t;
82482+
82483+#ifdef CONFIG_PAX_REFCOUNT
82484+typedef struct {
82485+ long counter;
82486+} atomic64_unchecked_t;
82487+#else
82488+typedef atomic64_t atomic64_unchecked_t;
82489+#endif
82490 #endif
82491
82492 struct list_head {
82493diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82494index ecd3319..8a36ded 100644
82495--- a/include/linux/uaccess.h
82496+++ b/include/linux/uaccess.h
82497@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82498 long ret; \
82499 mm_segment_t old_fs = get_fs(); \
82500 \
82501- set_fs(KERNEL_DS); \
82502 pagefault_disable(); \
82503- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82504- pagefault_enable(); \
82505+ set_fs(KERNEL_DS); \
82506+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82507 set_fs(old_fs); \
82508+ pagefault_enable(); \
82509 ret; \
82510 })
82511
82512diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82513index 2d1f9b6..d7a9fce 100644
82514--- a/include/linux/uidgid.h
82515+++ b/include/linux/uidgid.h
82516@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82517
82518 #endif /* CONFIG_USER_NS */
82519
82520+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82521+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82522+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82523+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82524+
82525 #endif /* _LINUX_UIDGID_H */
82526diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82527index 99c1b4d..562e6f3 100644
82528--- a/include/linux/unaligned/access_ok.h
82529+++ b/include/linux/unaligned/access_ok.h
82530@@ -4,34 +4,34 @@
82531 #include <linux/kernel.h>
82532 #include <asm/byteorder.h>
82533
82534-static inline u16 get_unaligned_le16(const void *p)
82535+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82536 {
82537- return le16_to_cpup((__le16 *)p);
82538+ return le16_to_cpup((const __le16 *)p);
82539 }
82540
82541-static inline u32 get_unaligned_le32(const void *p)
82542+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82543 {
82544- return le32_to_cpup((__le32 *)p);
82545+ return le32_to_cpup((const __le32 *)p);
82546 }
82547
82548-static inline u64 get_unaligned_le64(const void *p)
82549+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82550 {
82551- return le64_to_cpup((__le64 *)p);
82552+ return le64_to_cpup((const __le64 *)p);
82553 }
82554
82555-static inline u16 get_unaligned_be16(const void *p)
82556+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82557 {
82558- return be16_to_cpup((__be16 *)p);
82559+ return be16_to_cpup((const __be16 *)p);
82560 }
82561
82562-static inline u32 get_unaligned_be32(const void *p)
82563+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82564 {
82565- return be32_to_cpup((__be32 *)p);
82566+ return be32_to_cpup((const __be32 *)p);
82567 }
82568
82569-static inline u64 get_unaligned_be64(const void *p)
82570+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82571 {
82572- return be64_to_cpup((__be64 *)p);
82573+ return be64_to_cpup((const __be64 *)p);
82574 }
82575
82576 static inline void put_unaligned_le16(u16 val, void *p)
82577diff --git a/include/linux/usb.h b/include/linux/usb.h
82578index 7f6eb85..656e806 100644
82579--- a/include/linux/usb.h
82580+++ b/include/linux/usb.h
82581@@ -563,7 +563,7 @@ struct usb_device {
82582 int maxchild;
82583
82584 u32 quirks;
82585- atomic_t urbnum;
82586+ atomic_unchecked_t urbnum;
82587
82588 unsigned long active_duration;
82589
82590@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82591
82592 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82593 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82594- void *data, __u16 size, int timeout);
82595+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82596 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82597 void *data, int len, int *actual_length, int timeout);
82598 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82599diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82600index e452ba6..78f8e80 100644
82601--- a/include/linux/usb/renesas_usbhs.h
82602+++ b/include/linux/usb/renesas_usbhs.h
82603@@ -39,7 +39,7 @@ enum {
82604 */
82605 struct renesas_usbhs_driver_callback {
82606 int (*notify_hotplug)(struct platform_device *pdev);
82607-};
82608+} __no_const;
82609
82610 /*
82611 * callback functions for platform
82612diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82613index 4836ba3..603f6ee 100644
82614--- a/include/linux/user_namespace.h
82615+++ b/include/linux/user_namespace.h
82616@@ -33,7 +33,7 @@ struct user_namespace {
82617 struct key *persistent_keyring_register;
82618 struct rw_semaphore persistent_keyring_register_sem;
82619 #endif
82620-};
82621+} __randomize_layout;
82622
82623 extern struct user_namespace init_user_ns;
82624
82625diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82626index 239e277..22a5cf5 100644
82627--- a/include/linux/utsname.h
82628+++ b/include/linux/utsname.h
82629@@ -24,7 +24,7 @@ struct uts_namespace {
82630 struct new_utsname name;
82631 struct user_namespace *user_ns;
82632 unsigned int proc_inum;
82633-};
82634+} __randomize_layout;
82635 extern struct uts_namespace init_uts_ns;
82636
82637 #ifdef CONFIG_UTS_NS
82638diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82639index 6f8fbcf..4efc177 100644
82640--- a/include/linux/vermagic.h
82641+++ b/include/linux/vermagic.h
82642@@ -25,9 +25,42 @@
82643 #define MODULE_ARCH_VERMAGIC ""
82644 #endif
82645
82646+#ifdef CONFIG_PAX_REFCOUNT
82647+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82648+#else
82649+#define MODULE_PAX_REFCOUNT ""
82650+#endif
82651+
82652+#ifdef CONSTIFY_PLUGIN
82653+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82654+#else
82655+#define MODULE_CONSTIFY_PLUGIN ""
82656+#endif
82657+
82658+#ifdef STACKLEAK_PLUGIN
82659+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82660+#else
82661+#define MODULE_STACKLEAK_PLUGIN ""
82662+#endif
82663+
82664+#ifdef RANDSTRUCT_PLUGIN
82665+#include <generated/randomize_layout_hash.h>
82666+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82667+#else
82668+#define MODULE_RANDSTRUCT_PLUGIN
82669+#endif
82670+
82671+#ifdef CONFIG_GRKERNSEC
82672+#define MODULE_GRSEC "GRSEC "
82673+#else
82674+#define MODULE_GRSEC ""
82675+#endif
82676+
82677 #define VERMAGIC_STRING \
82678 UTS_RELEASE " " \
82679 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82680 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82681- MODULE_ARCH_VERMAGIC
82682+ MODULE_ARCH_VERMAGIC \
82683+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82684+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82685
82686diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82687index 502073a..a7de024 100644
82688--- a/include/linux/vga_switcheroo.h
82689+++ b/include/linux/vga_switcheroo.h
82690@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82691
82692 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82693
82694-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82695-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82696+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82697+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82698 #else
82699
82700 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82701@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82702
82703 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82704
82705-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82706-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82707+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82708+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82709
82710 #endif
82711 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82712diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82713index 4b8a891..cb8df6e 100644
82714--- a/include/linux/vmalloc.h
82715+++ b/include/linux/vmalloc.h
82716@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82717 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82718 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82719 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82720+
82721+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82722+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82723+#endif
82724+
82725 /* bits [20..32] reserved for arch specific ioremap internals */
82726
82727 /*
82728@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82729
82730 /* for /dev/kmem */
82731 extern long vread(char *buf, char *addr, unsigned long count);
82732-extern long vwrite(char *buf, char *addr, unsigned long count);
82733+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82734
82735 /*
82736 * Internals. Dont't use..
82737diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82738index 67ce70c..d540954 100644
82739--- a/include/linux/vmstat.h
82740+++ b/include/linux/vmstat.h
82741@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82742 /*
82743 * Zone based page accounting with per cpu differentials.
82744 */
82745-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82746+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82747
82748 static inline void zone_page_state_add(long x, struct zone *zone,
82749 enum zone_stat_item item)
82750 {
82751- atomic_long_add(x, &zone->vm_stat[item]);
82752- atomic_long_add(x, &vm_stat[item]);
82753+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82754+ atomic_long_add_unchecked(x, &vm_stat[item]);
82755 }
82756
82757-static inline unsigned long global_page_state(enum zone_stat_item item)
82758+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82759 {
82760- long x = atomic_long_read(&vm_stat[item]);
82761+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82762 #ifdef CONFIG_SMP
82763 if (x < 0)
82764 x = 0;
82765@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82766 return x;
82767 }
82768
82769-static inline unsigned long zone_page_state(struct zone *zone,
82770+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82771 enum zone_stat_item item)
82772 {
82773- long x = atomic_long_read(&zone->vm_stat[item]);
82774+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82775 #ifdef CONFIG_SMP
82776 if (x < 0)
82777 x = 0;
82778@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82779 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82780 enum zone_stat_item item)
82781 {
82782- long x = atomic_long_read(&zone->vm_stat[item]);
82783+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82784
82785 #ifdef CONFIG_SMP
82786 int cpu;
82787@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82788
82789 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82790 {
82791- atomic_long_inc(&zone->vm_stat[item]);
82792- atomic_long_inc(&vm_stat[item]);
82793+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
82794+ atomic_long_inc_unchecked(&vm_stat[item]);
82795 }
82796
82797 static inline void __inc_zone_page_state(struct page *page,
82798@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
82799
82800 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82801 {
82802- atomic_long_dec(&zone->vm_stat[item]);
82803- atomic_long_dec(&vm_stat[item]);
82804+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
82805+ atomic_long_dec_unchecked(&vm_stat[item]);
82806 }
82807
82808 static inline void __dec_zone_page_state(struct page *page,
82809diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82810index 91b0a68..0e9adf6 100644
82811--- a/include/linux/xattr.h
82812+++ b/include/linux/xattr.h
82813@@ -28,7 +28,7 @@ struct xattr_handler {
82814 size_t size, int handler_flags);
82815 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82816 size_t size, int flags, int handler_flags);
82817-};
82818+} __do_const;
82819
82820 struct xattr {
82821 const char *name;
82822@@ -37,6 +37,9 @@ struct xattr {
82823 };
82824
82825 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82826+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82827+ssize_t pax_getxattr(struct dentry *, void *, size_t);
82828+#endif
82829 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82830 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82831 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82832diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82833index 9c5a6b4..09c9438 100644
82834--- a/include/linux/zlib.h
82835+++ b/include/linux/zlib.h
82836@@ -31,6 +31,7 @@
82837 #define _ZLIB_H
82838
82839 #include <linux/zconf.h>
82840+#include <linux/compiler.h>
82841
82842 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82843 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82844@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82845
82846 /* basic functions */
82847
82848-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82849+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82850 /*
82851 Returns the number of bytes that needs to be allocated for a per-
82852 stream workspace with the specified parameters. A pointer to this
82853diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82854index c768c9f..bdcaa5a 100644
82855--- a/include/media/v4l2-dev.h
82856+++ b/include/media/v4l2-dev.h
82857@@ -76,7 +76,7 @@ struct v4l2_file_operations {
82858 int (*mmap) (struct file *, struct vm_area_struct *);
82859 int (*open) (struct file *);
82860 int (*release) (struct file *);
82861-};
82862+} __do_const;
82863
82864 /*
82865 * Newer version of video_device, handled by videodev2.c
82866diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82867index c9b1593..a572459 100644
82868--- a/include/media/v4l2-device.h
82869+++ b/include/media/v4l2-device.h
82870@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82871 this function returns 0. If the name ends with a digit (e.g. cx18),
82872 then the name will be set to cx18-0 since cx180 looks really odd. */
82873 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82874- atomic_t *instance);
82875+ atomic_unchecked_t *instance);
82876
82877 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82878 Since the parent disappears this ensures that v4l2_dev doesn't have an
82879diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82880index 9a36d92..0aafe2a 100644
82881--- a/include/net/9p/transport.h
82882+++ b/include/net/9p/transport.h
82883@@ -60,7 +60,7 @@ struct p9_trans_module {
82884 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82885 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82886 char *, char *, int , int, int, int);
82887-};
82888+} __do_const;
82889
82890 void v9fs_register_trans(struct p9_trans_module *m);
82891 void v9fs_unregister_trans(struct p9_trans_module *m);
82892diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82893index a175ba4..196eb82 100644
82894--- a/include/net/af_unix.h
82895+++ b/include/net/af_unix.h
82896@@ -36,7 +36,7 @@ struct unix_skb_parms {
82897 u32 secid; /* Security ID */
82898 #endif
82899 u32 consumed;
82900-};
82901+} __randomize_layout;
82902
82903 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82904 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82905diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82906index dbc4a89..4a59b5d 100644
82907--- a/include/net/bluetooth/l2cap.h
82908+++ b/include/net/bluetooth/l2cap.h
82909@@ -600,7 +600,7 @@ struct l2cap_ops {
82910 long (*get_sndtimeo) (struct l2cap_chan *chan);
82911 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82912 unsigned long len, int nb);
82913-};
82914+} __do_const;
82915
82916 struct l2cap_conn {
82917 struct hci_conn *hcon;
82918diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82919index f2ae33d..c457cf0 100644
82920--- a/include/net/caif/cfctrl.h
82921+++ b/include/net/caif/cfctrl.h
82922@@ -52,7 +52,7 @@ struct cfctrl_rsp {
82923 void (*radioset_rsp)(void);
82924 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82925 struct cflayer *client_layer);
82926-};
82927+} __no_const;
82928
82929 /* Link Setup Parameters for CAIF-Links. */
82930 struct cfctrl_link_param {
82931@@ -101,8 +101,8 @@ struct cfctrl_request_info {
82932 struct cfctrl {
82933 struct cfsrvl serv;
82934 struct cfctrl_rsp res;
82935- atomic_t req_seq_no;
82936- atomic_t rsp_seq_no;
82937+ atomic_unchecked_t req_seq_no;
82938+ atomic_unchecked_t rsp_seq_no;
82939 struct list_head list;
82940 /* Protects from simultaneous access to first_req list */
82941 spinlock_t info_list_lock;
82942diff --git a/include/net/flow.h b/include/net/flow.h
82943index d23e7fa..e188307 100644
82944--- a/include/net/flow.h
82945+++ b/include/net/flow.h
82946@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82947
82948 void flow_cache_flush(void);
82949 void flow_cache_flush_deferred(void);
82950-extern atomic_t flow_cache_genid;
82951+extern atomic_unchecked_t flow_cache_genid;
82952
82953 #endif
82954diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82955index 93695f0..766d71c 100644
82956--- a/include/net/genetlink.h
82957+++ b/include/net/genetlink.h
82958@@ -120,7 +120,7 @@ struct genl_ops {
82959 u8 cmd;
82960 u8 internal_flags;
82961 u8 flags;
82962-};
82963+} __do_const;
82964
82965 int __genl_register_family(struct genl_family *family);
82966
82967diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82968index 734d9b5..48a9a4b 100644
82969--- a/include/net/gro_cells.h
82970+++ b/include/net/gro_cells.h
82971@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82972 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82973
82974 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82975- atomic_long_inc(&dev->rx_dropped);
82976+ atomic_long_inc_unchecked(&dev->rx_dropped);
82977 kfree_skb(skb);
82978 return;
82979 }
82980diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82981index c55aeed..b3393f4 100644
82982--- a/include/net/inet_connection_sock.h
82983+++ b/include/net/inet_connection_sock.h
82984@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82985 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82986 int (*bind_conflict)(const struct sock *sk,
82987 const struct inet_bind_bucket *tb, bool relax);
82988-};
82989+} __do_const;
82990
82991 /** inet_connection_sock - INET connection oriented sock
82992 *
82993diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82994index 6efe73c..fa94270 100644
82995--- a/include/net/inetpeer.h
82996+++ b/include/net/inetpeer.h
82997@@ -47,8 +47,8 @@ struct inet_peer {
82998 */
82999 union {
83000 struct {
83001- atomic_t rid; /* Frag reception counter */
83002- atomic_t ip_id_count; /* IP ID for the next packet */
83003+ atomic_unchecked_t rid; /* Frag reception counter */
83004+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83005 };
83006 struct rcu_head rcu;
83007 struct inet_peer *gc_next;
83008@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83009 /* can be called with or without local BH being disabled */
83010 static inline int inet_getid(struct inet_peer *p, int more)
83011 {
83012- int old, new;
83013+ int id;
83014 more++;
83015 inet_peer_refcheck(p);
83016- do {
83017- old = atomic_read(&p->ip_id_count);
83018- new = old + more;
83019- if (!new)
83020- new = 1;
83021- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83022- return new;
83023+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83024+ if (!id)
83025+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83026+ return id;
83027 }
83028
83029 #endif /* _NET_INETPEER_H */
83030diff --git a/include/net/ip.h b/include/net/ip.h
83031index 23be0fd..0cb3e2c 100644
83032--- a/include/net/ip.h
83033+++ b/include/net/ip.h
83034@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83035
83036 void inet_get_local_port_range(struct net *net, int *low, int *high);
83037
83038-extern unsigned long *sysctl_local_reserved_ports;
83039+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83040 static inline int inet_is_reserved_local_port(int port)
83041 {
83042 return test_bit(port, sysctl_local_reserved_ports);
83043diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83044index 9922093..a1755d6 100644
83045--- a/include/net/ip_fib.h
83046+++ b/include/net/ip_fib.h
83047@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83048
83049 #define FIB_RES_SADDR(net, res) \
83050 ((FIB_RES_NH(res).nh_saddr_genid == \
83051- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83052+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83053 FIB_RES_NH(res).nh_saddr : \
83054 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83055 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83056diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83057index 5679d92..2e7a690 100644
83058--- a/include/net/ip_vs.h
83059+++ b/include/net/ip_vs.h
83060@@ -558,7 +558,7 @@ struct ip_vs_conn {
83061 struct ip_vs_conn *control; /* Master control connection */
83062 atomic_t n_control; /* Number of controlled ones */
83063 struct ip_vs_dest *dest; /* real server */
83064- atomic_t in_pkts; /* incoming packet counter */
83065+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83066
83067 /* packet transmitter for different forwarding methods. If it
83068 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83069@@ -705,7 +705,7 @@ struct ip_vs_dest {
83070 __be16 port; /* port number of the server */
83071 union nf_inet_addr addr; /* IP address of the server */
83072 volatile unsigned int flags; /* dest status flags */
83073- atomic_t conn_flags; /* flags to copy to conn */
83074+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83075 atomic_t weight; /* server weight */
83076
83077 atomic_t refcnt; /* reference counter */
83078@@ -960,11 +960,11 @@ struct netns_ipvs {
83079 /* ip_vs_lblc */
83080 int sysctl_lblc_expiration;
83081 struct ctl_table_header *lblc_ctl_header;
83082- struct ctl_table *lblc_ctl_table;
83083+ ctl_table_no_const *lblc_ctl_table;
83084 /* ip_vs_lblcr */
83085 int sysctl_lblcr_expiration;
83086 struct ctl_table_header *lblcr_ctl_header;
83087- struct ctl_table *lblcr_ctl_table;
83088+ ctl_table_no_const *lblcr_ctl_table;
83089 /* ip_vs_est */
83090 struct list_head est_list; /* estimator list */
83091 spinlock_t est_lock;
83092diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83093index 8d4f588..2e37ad2 100644
83094--- a/include/net/irda/ircomm_tty.h
83095+++ b/include/net/irda/ircomm_tty.h
83096@@ -33,6 +33,7 @@
83097 #include <linux/termios.h>
83098 #include <linux/timer.h>
83099 #include <linux/tty.h> /* struct tty_struct */
83100+#include <asm/local.h>
83101
83102 #include <net/irda/irias_object.h>
83103 #include <net/irda/ircomm_core.h>
83104diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83105index 714cc9a..ea05f3e 100644
83106--- a/include/net/iucv/af_iucv.h
83107+++ b/include/net/iucv/af_iucv.h
83108@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83109 struct iucv_sock_list {
83110 struct hlist_head head;
83111 rwlock_t lock;
83112- atomic_t autobind_name;
83113+ atomic_unchecked_t autobind_name;
83114 };
83115
83116 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83117diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83118index f3be818..bf46196 100644
83119--- a/include/net/llc_c_ac.h
83120+++ b/include/net/llc_c_ac.h
83121@@ -87,7 +87,7 @@
83122 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83123 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83124
83125-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83126+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83127
83128 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83129 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83130diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83131index 3948cf1..83b28c4 100644
83132--- a/include/net/llc_c_ev.h
83133+++ b/include/net/llc_c_ev.h
83134@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83135 return (struct llc_conn_state_ev *)skb->cb;
83136 }
83137
83138-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83139-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83140+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83141+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83142
83143 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83144 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83145diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83146index 0e79cfb..f46db31 100644
83147--- a/include/net/llc_c_st.h
83148+++ b/include/net/llc_c_st.h
83149@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83150 u8 next_state;
83151 llc_conn_ev_qfyr_t *ev_qualifiers;
83152 llc_conn_action_t *ev_actions;
83153-};
83154+} __do_const;
83155
83156 struct llc_conn_state {
83157 u8 current_state;
83158diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83159index a61b98c..aade1eb 100644
83160--- a/include/net/llc_s_ac.h
83161+++ b/include/net/llc_s_ac.h
83162@@ -23,7 +23,7 @@
83163 #define SAP_ACT_TEST_IND 9
83164
83165 /* All action functions must look like this */
83166-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83167+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83168
83169 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83170 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83171diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83172index 567c681..cd73ac0 100644
83173--- a/include/net/llc_s_st.h
83174+++ b/include/net/llc_s_st.h
83175@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83176 llc_sap_ev_t ev;
83177 u8 next_state;
83178 llc_sap_action_t *ev_actions;
83179-};
83180+} __do_const;
83181
83182 struct llc_sap_state {
83183 u8 curr_state;
83184diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83185index f4ab2fb..71a85ba 100644
83186--- a/include/net/mac80211.h
83187+++ b/include/net/mac80211.h
83188@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83189 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83190 struct dentry *dir);
83191 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83192-};
83193+} __do_const;
83194
83195 static inline int rate_supported(struct ieee80211_sta *sta,
83196 enum ieee80211_band band,
83197diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83198index 7277caf..fd095bc 100644
83199--- a/include/net/neighbour.h
83200+++ b/include/net/neighbour.h
83201@@ -163,7 +163,7 @@ struct neigh_ops {
83202 void (*error_report)(struct neighbour *, struct sk_buff *);
83203 int (*output)(struct neighbour *, struct sk_buff *);
83204 int (*connected_output)(struct neighbour *, struct sk_buff *);
83205-};
83206+} __do_const;
83207
83208 struct pneigh_entry {
83209 struct pneigh_entry *next;
83210@@ -203,7 +203,6 @@ struct neigh_table {
83211 void (*proxy_redo)(struct sk_buff *skb);
83212 char *id;
83213 struct neigh_parms parms;
83214- /* HACK. gc_* should follow parms without a gap! */
83215 int gc_interval;
83216 int gc_thresh1;
83217 int gc_thresh2;
83218@@ -218,7 +217,7 @@ struct neigh_table {
83219 struct neigh_statistics __percpu *stats;
83220 struct neigh_hash_table __rcu *nht;
83221 struct pneigh_entry **phash_buckets;
83222-};
83223+} __randomize_layout;
83224
83225 static inline int neigh_parms_family(struct neigh_parms *p)
83226 {
83227diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83228index 991dcd9..ab58d00 100644
83229--- a/include/net/net_namespace.h
83230+++ b/include/net/net_namespace.h
83231@@ -124,8 +124,8 @@ struct net {
83232 struct netns_ipvs *ipvs;
83233 #endif
83234 struct sock *diag_nlsk;
83235- atomic_t fnhe_genid;
83236-};
83237+ atomic_unchecked_t fnhe_genid;
83238+} __randomize_layout;
83239
83240 /*
83241 * ifindex generation is per-net namespace, and loopback is
83242@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83243 #define __net_init __init
83244 #define __net_exit __exit_refok
83245 #define __net_initdata __initdata
83246+#ifdef CONSTIFY_PLUGIN
83247 #define __net_initconst __initconst
83248+#else
83249+#define __net_initconst __initdata
83250+#endif
83251 #endif
83252
83253 struct pernet_operations {
83254@@ -299,7 +303,7 @@ struct pernet_operations {
83255 void (*exit_batch)(struct list_head *net_exit_list);
83256 int *id;
83257 size_t size;
83258-};
83259+} __do_const;
83260
83261 /*
83262 * Use these carefully. If you implement a network device and it
83263@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83264
83265 static inline int rt_genid_ipv4(struct net *net)
83266 {
83267- return atomic_read(&net->ipv4.rt_genid);
83268+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83269 }
83270
83271 static inline void rt_genid_bump_ipv4(struct net *net)
83272 {
83273- atomic_inc(&net->ipv4.rt_genid);
83274+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83275 }
83276
83277 #if IS_ENABLED(CONFIG_IPV6)
83278 static inline int rt_genid_ipv6(struct net *net)
83279 {
83280- return atomic_read(&net->ipv6.rt_genid);
83281+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83282 }
83283
83284 static inline void rt_genid_bump_ipv6(struct net *net)
83285 {
83286- atomic_inc(&net->ipv6.rt_genid);
83287+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83288 }
83289 #else
83290 static inline int rt_genid_ipv6(struct net *net)
83291@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83292
83293 static inline int fnhe_genid(struct net *net)
83294 {
83295- return atomic_read(&net->fnhe_genid);
83296+ return atomic_read_unchecked(&net->fnhe_genid);
83297 }
83298
83299 static inline void fnhe_genid_bump(struct net *net)
83300 {
83301- atomic_inc(&net->fnhe_genid);
83302+ atomic_inc_unchecked(&net->fnhe_genid);
83303 }
83304
83305 #endif /* __NET_NET_NAMESPACE_H */
83306diff --git a/include/net/netdma.h b/include/net/netdma.h
83307index 8ba8ce2..99b7fff 100644
83308--- a/include/net/netdma.h
83309+++ b/include/net/netdma.h
83310@@ -24,7 +24,7 @@
83311 #include <linux/dmaengine.h>
83312 #include <linux/skbuff.h>
83313
83314-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83315+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83316 struct sk_buff *skb, int offset, struct iovec *to,
83317 size_t len, struct dma_pinned_list *pinned_list);
83318
83319diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83320index 956b175..55d1504 100644
83321--- a/include/net/netfilter/nf_conntrack_extend.h
83322+++ b/include/net/netfilter/nf_conntrack_extend.h
83323@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83324 /* Extensions: optional stuff which isn't permanently in struct. */
83325 struct nf_ct_ext {
83326 struct rcu_head rcu;
83327- u8 offset[NF_CT_EXT_NUM];
83328- u8 len;
83329+ u16 offset[NF_CT_EXT_NUM];
83330+ u16 len;
83331 char data[0];
83332 };
83333
83334diff --git a/include/net/netlink.h b/include/net/netlink.h
83335index 2b47eaa..6d5bcc2 100644
83336--- a/include/net/netlink.h
83337+++ b/include/net/netlink.h
83338@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83339 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83340 {
83341 if (mark)
83342- skb_trim(skb, (unsigned char *) mark - skb->data);
83343+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83344 }
83345
83346 /**
83347diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83348index fbcc7fa..03c7e51 100644
83349--- a/include/net/netns/conntrack.h
83350+++ b/include/net/netns/conntrack.h
83351@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83352 struct nf_proto_net {
83353 #ifdef CONFIG_SYSCTL
83354 struct ctl_table_header *ctl_table_header;
83355- struct ctl_table *ctl_table;
83356+ ctl_table_no_const *ctl_table;
83357 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83358 struct ctl_table_header *ctl_compat_header;
83359- struct ctl_table *ctl_compat_table;
83360+ ctl_table_no_const *ctl_compat_table;
83361 #endif
83362 #endif
83363 unsigned int users;
83364@@ -58,7 +58,7 @@ struct nf_ip_net {
83365 struct nf_icmp_net icmpv6;
83366 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83367 struct ctl_table_header *ctl_table_header;
83368- struct ctl_table *ctl_table;
83369+ ctl_table_no_const *ctl_table;
83370 #endif
83371 };
83372
83373diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83374index 80f500a..f0c23c2 100644
83375--- a/include/net/netns/ipv4.h
83376+++ b/include/net/netns/ipv4.h
83377@@ -74,7 +74,7 @@ struct netns_ipv4 {
83378
83379 kgid_t sysctl_ping_group_range[2];
83380
83381- atomic_t dev_addr_genid;
83382+ atomic_unchecked_t dev_addr_genid;
83383
83384 #ifdef CONFIG_IP_MROUTE
83385 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83386@@ -84,6 +84,6 @@ struct netns_ipv4 {
83387 struct fib_rules_ops *mr_rules_ops;
83388 #endif
83389 #endif
83390- atomic_t rt_genid;
83391+ atomic_unchecked_t rt_genid;
83392 };
83393 #endif
83394diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83395index 21edaf1..4c5faae 100644
83396--- a/include/net/netns/ipv6.h
83397+++ b/include/net/netns/ipv6.h
83398@@ -73,8 +73,8 @@ struct netns_ipv6 {
83399 struct fib_rules_ops *mr6_rules_ops;
83400 #endif
83401 #endif
83402- atomic_t dev_addr_genid;
83403- atomic_t rt_genid;
83404+ atomic_unchecked_t dev_addr_genid;
83405+ atomic_unchecked_t rt_genid;
83406 };
83407
83408 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83409diff --git a/include/net/ping.h b/include/net/ping.h
83410index 026479b..d9b2829 100644
83411--- a/include/net/ping.h
83412+++ b/include/net/ping.h
83413@@ -54,7 +54,7 @@ struct ping_iter_state {
83414
83415 extern struct proto ping_prot;
83416 #if IS_ENABLED(CONFIG_IPV6)
83417-extern struct pingv6_ops pingv6_ops;
83418+extern struct pingv6_ops *pingv6_ops;
83419 #endif
83420
83421 struct pingfakehdr {
83422diff --git a/include/net/protocol.h b/include/net/protocol.h
83423index a7e986b..dc67bce 100644
83424--- a/include/net/protocol.h
83425+++ b/include/net/protocol.h
83426@@ -49,7 +49,7 @@ struct net_protocol {
83427 * socket lookup?
83428 */
83429 icmp_strict_tag_validation:1;
83430-};
83431+} __do_const;
83432
83433 #if IS_ENABLED(CONFIG_IPV6)
83434 struct inet6_protocol {
83435@@ -62,7 +62,7 @@ struct inet6_protocol {
83436 u8 type, u8 code, int offset,
83437 __be32 info);
83438 unsigned int flags; /* INET6_PROTO_xxx */
83439-};
83440+} __do_const;
83441
83442 #define INET6_PROTO_NOPOLICY 0x1
83443 #define INET6_PROTO_FINAL 0x2
83444diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83445index 661e45d..54c39df 100644
83446--- a/include/net/rtnetlink.h
83447+++ b/include/net/rtnetlink.h
83448@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83449 int (*fill_slave_info)(struct sk_buff *skb,
83450 const struct net_device *dev,
83451 const struct net_device *slave_dev);
83452-};
83453+} __do_const;
83454
83455 int __rtnl_link_register(struct rtnl_link_ops *ops);
83456 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83457diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83458index 4a5b9a3..ca27d73 100644
83459--- a/include/net/sctp/checksum.h
83460+++ b/include/net/sctp/checksum.h
83461@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83462 unsigned int offset)
83463 {
83464 struct sctphdr *sh = sctp_hdr(skb);
83465- __le32 ret, old = sh->checksum;
83466- const struct skb_checksum_ops ops = {
83467+ __le32 ret, old = sh->checksum;
83468+ static const struct skb_checksum_ops ops = {
83469 .update = sctp_csum_update,
83470 .combine = sctp_csum_combine,
83471 };
83472diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83473index 7f4eeb3..37e8fe1 100644
83474--- a/include/net/sctp/sm.h
83475+++ b/include/net/sctp/sm.h
83476@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83477 typedef struct {
83478 sctp_state_fn_t *fn;
83479 const char *name;
83480-} sctp_sm_table_entry_t;
83481+} __do_const sctp_sm_table_entry_t;
83482
83483 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83484 * currently in use.
83485@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83486 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83487
83488 /* Extern declarations for major data structures. */
83489-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83490+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83491
83492
83493 /* Get the size of a DATA chunk payload. */
83494diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83495index 6ee76c8..45f2609 100644
83496--- a/include/net/sctp/structs.h
83497+++ b/include/net/sctp/structs.h
83498@@ -507,7 +507,7 @@ struct sctp_pf {
83499 struct sctp_association *asoc);
83500 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83501 struct sctp_af *af;
83502-};
83503+} __do_const;
83504
83505
83506 /* Structure to track chunk fragments that have been acked, but peer
83507diff --git a/include/net/sock.h b/include/net/sock.h
83508index b9586a1..b2948c0 100644
83509--- a/include/net/sock.h
83510+++ b/include/net/sock.h
83511@@ -348,7 +348,7 @@ struct sock {
83512 unsigned int sk_napi_id;
83513 unsigned int sk_ll_usec;
83514 #endif
83515- atomic_t sk_drops;
83516+ atomic_unchecked_t sk_drops;
83517 int sk_rcvbuf;
83518
83519 struct sk_filter __rcu *sk_filter;
83520@@ -1036,7 +1036,7 @@ struct proto {
83521 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83522 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83523 #endif
83524-};
83525+} __randomize_layout;
83526
83527 /*
83528 * Bits in struct cg_proto.flags
83529@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83530 return ret >> PAGE_SHIFT;
83531 }
83532
83533-static inline long
83534+static inline long __intentional_overflow(-1)
83535 sk_memory_allocated(const struct sock *sk)
83536 {
83537 struct proto *prot = sk->sk_prot;
83538@@ -1368,7 +1368,7 @@ struct sock_iocb {
83539 struct scm_cookie *scm;
83540 struct msghdr *msg, async_msg;
83541 struct kiocb *kiocb;
83542-};
83543+} __randomize_layout;
83544
83545 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83546 {
83547@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83548 }
83549
83550 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83551- char __user *from, char *to,
83552+ char __user *from, unsigned char *to,
83553 int copy, int offset)
83554 {
83555 if (skb->ip_summed == CHECKSUM_NONE) {
83556@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83557 }
83558 }
83559
83560-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83561+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83562
83563 /**
83564 * sk_page_frag - return an appropriate page_frag
83565diff --git a/include/net/tcp.h b/include/net/tcp.h
83566index 743acce..44a58b0 100644
83567--- a/include/net/tcp.h
83568+++ b/include/net/tcp.h
83569@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83570 void tcp_xmit_retransmit_queue(struct sock *);
83571 void tcp_simple_retransmit(struct sock *);
83572 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83573-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83574+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83575
83576 void tcp_send_probe0(struct sock *);
83577 void tcp_send_partial(struct sock *);
83578@@ -710,8 +710,8 @@ struct tcp_skb_cb {
83579 struct inet6_skb_parm h6;
83580 #endif
83581 } header; /* For incoming frames */
83582- __u32 seq; /* Starting sequence number */
83583- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83584+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83585+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83586 __u32 when; /* used to compute rtt's */
83587 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83588
83589@@ -725,7 +725,7 @@ struct tcp_skb_cb {
83590
83591 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83592 /* 1 byte hole */
83593- __u32 ack_seq; /* Sequence number ACK'd */
83594+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83595 };
83596
83597 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83598diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83599index fb5654a..4457522 100644
83600--- a/include/net/xfrm.h
83601+++ b/include/net/xfrm.h
83602@@ -286,7 +286,6 @@ struct xfrm_dst;
83603 struct xfrm_policy_afinfo {
83604 unsigned short family;
83605 struct dst_ops *dst_ops;
83606- void (*garbage_collect)(struct net *net);
83607 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83608 const xfrm_address_t *saddr,
83609 const xfrm_address_t *daddr);
83610@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83611 struct net_device *dev,
83612 const struct flowi *fl);
83613 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83614-};
83615+} __do_const;
83616
83617 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83618 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83619@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83620 int (*transport_finish)(struct sk_buff *skb,
83621 int async);
83622 void (*local_error)(struct sk_buff *skb, u32 mtu);
83623-};
83624+} __do_const;
83625
83626 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83627 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83628@@ -428,7 +427,7 @@ struct xfrm_mode {
83629 struct module *owner;
83630 unsigned int encap;
83631 int flags;
83632-};
83633+} __do_const;
83634
83635 /* Flags for xfrm_mode. */
83636 enum {
83637@@ -525,7 +524,7 @@ struct xfrm_policy {
83638 struct timer_list timer;
83639
83640 struct flow_cache_object flo;
83641- atomic_t genid;
83642+ atomic_unchecked_t genid;
83643 u32 priority;
83644 u32 index;
83645 struct xfrm_mark mark;
83646@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83647 }
83648
83649 void xfrm_garbage_collect(struct net *net);
83650+void xfrm_garbage_collect_deferred(struct net *net);
83651
83652 #else
83653
83654@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83655 static inline void xfrm_garbage_collect(struct net *net)
83656 {
83657 }
83658+static inline void xfrm_garbage_collect_deferred(struct net *net)
83659+{
83660+}
83661 #endif
83662
83663 static __inline__
83664diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83665index 1017e0b..227aa4d 100644
83666--- a/include/rdma/iw_cm.h
83667+++ b/include/rdma/iw_cm.h
83668@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83669 int backlog);
83670
83671 int (*destroy_listen)(struct iw_cm_id *cm_id);
83672-};
83673+} __no_const;
83674
83675 /**
83676 * iw_create_cm_id - Create an IW CM identifier.
83677diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83678index 52beadf..598734c 100644
83679--- a/include/scsi/libfc.h
83680+++ b/include/scsi/libfc.h
83681@@ -771,6 +771,7 @@ struct libfc_function_template {
83682 */
83683 void (*disc_stop_final) (struct fc_lport *);
83684 };
83685+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83686
83687 /**
83688 * struct fc_disc - Discovery context
83689@@ -875,7 +876,7 @@ struct fc_lport {
83690 struct fc_vport *vport;
83691
83692 /* Operational Information */
83693- struct libfc_function_template tt;
83694+ libfc_function_template_no_const tt;
83695 u8 link_up;
83696 u8 qfull;
83697 enum fc_lport_state state;
83698diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83699index d65fbec..f80fef2 100644
83700--- a/include/scsi/scsi_device.h
83701+++ b/include/scsi/scsi_device.h
83702@@ -180,9 +180,9 @@ struct scsi_device {
83703 unsigned int max_device_blocked; /* what device_blocked counts down from */
83704 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83705
83706- atomic_t iorequest_cnt;
83707- atomic_t iodone_cnt;
83708- atomic_t ioerr_cnt;
83709+ atomic_unchecked_t iorequest_cnt;
83710+ atomic_unchecked_t iodone_cnt;
83711+ atomic_unchecked_t ioerr_cnt;
83712
83713 struct device sdev_gendev,
83714 sdev_dev;
83715diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83716index b797e8f..8e2c3aa 100644
83717--- a/include/scsi/scsi_transport_fc.h
83718+++ b/include/scsi/scsi_transport_fc.h
83719@@ -751,7 +751,8 @@ struct fc_function_template {
83720 unsigned long show_host_system_hostname:1;
83721
83722 unsigned long disable_target_scan:1;
83723-};
83724+} __do_const;
83725+typedef struct fc_function_template __no_const fc_function_template_no_const;
83726
83727
83728 /**
83729diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83730index ae6c3b8..fd748ac 100644
83731--- a/include/sound/compress_driver.h
83732+++ b/include/sound/compress_driver.h
83733@@ -128,7 +128,7 @@ struct snd_compr_ops {
83734 struct snd_compr_caps *caps);
83735 int (*get_codec_caps) (struct snd_compr_stream *stream,
83736 struct snd_compr_codec_caps *codec);
83737-};
83738+} __no_const;
83739
83740 /**
83741 * struct snd_compr: Compressed device
83742diff --git a/include/sound/soc.h b/include/sound/soc.h
83743index 9a00147..d814573 100644
83744--- a/include/sound/soc.h
83745+++ b/include/sound/soc.h
83746@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83747 /* probe ordering - for components with runtime dependencies */
83748 int probe_order;
83749 int remove_order;
83750-};
83751+} __do_const;
83752
83753 /* SoC platform interface */
83754 struct snd_soc_platform_driver {
83755@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83756 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83757 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83758 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83759-};
83760+} __do_const;
83761
83762 struct snd_soc_platform {
83763 const char *name;
83764diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83765index 1772fad..282e3e2 100644
83766--- a/include/target/target_core_base.h
83767+++ b/include/target/target_core_base.h
83768@@ -754,7 +754,7 @@ struct se_device {
83769 atomic_long_t write_bytes;
83770 /* Active commands on this virtual SE device */
83771 atomic_t simple_cmds;
83772- atomic_t dev_ordered_id;
83773+ atomic_unchecked_t dev_ordered_id;
83774 atomic_t dev_ordered_sync;
83775 atomic_t dev_qf_count;
83776 int export_count;
83777diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83778new file mode 100644
83779index 0000000..fb634b7
83780--- /dev/null
83781+++ b/include/trace/events/fs.h
83782@@ -0,0 +1,53 @@
83783+#undef TRACE_SYSTEM
83784+#define TRACE_SYSTEM fs
83785+
83786+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83787+#define _TRACE_FS_H
83788+
83789+#include <linux/fs.h>
83790+#include <linux/tracepoint.h>
83791+
83792+TRACE_EVENT(do_sys_open,
83793+
83794+ TP_PROTO(const char *filename, int flags, int mode),
83795+
83796+ TP_ARGS(filename, flags, mode),
83797+
83798+ TP_STRUCT__entry(
83799+ __string( filename, filename )
83800+ __field( int, flags )
83801+ __field( int, mode )
83802+ ),
83803+
83804+ TP_fast_assign(
83805+ __assign_str(filename, filename);
83806+ __entry->flags = flags;
83807+ __entry->mode = mode;
83808+ ),
83809+
83810+ TP_printk("\"%s\" %x %o",
83811+ __get_str(filename), __entry->flags, __entry->mode)
83812+);
83813+
83814+TRACE_EVENT(open_exec,
83815+
83816+ TP_PROTO(const char *filename),
83817+
83818+ TP_ARGS(filename),
83819+
83820+ TP_STRUCT__entry(
83821+ __string( filename, filename )
83822+ ),
83823+
83824+ TP_fast_assign(
83825+ __assign_str(filename, filename);
83826+ ),
83827+
83828+ TP_printk("\"%s\"",
83829+ __get_str(filename))
83830+);
83831+
83832+#endif /* _TRACE_FS_H */
83833+
83834+/* This part must be outside protection */
83835+#include <trace/define_trace.h>
83836diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83837index 1c09820..7f5ec79 100644
83838--- a/include/trace/events/irq.h
83839+++ b/include/trace/events/irq.h
83840@@ -36,7 +36,7 @@ struct softirq_action;
83841 */
83842 TRACE_EVENT(irq_handler_entry,
83843
83844- TP_PROTO(int irq, struct irqaction *action),
83845+ TP_PROTO(int irq, const struct irqaction *action),
83846
83847 TP_ARGS(irq, action),
83848
83849@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83850 */
83851 TRACE_EVENT(irq_handler_exit,
83852
83853- TP_PROTO(int irq, struct irqaction *action, int ret),
83854+ TP_PROTO(int irq, const struct irqaction *action, int ret),
83855
83856 TP_ARGS(irq, action, ret),
83857
83858diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83859index 7caf44c..23c6f27 100644
83860--- a/include/uapi/linux/a.out.h
83861+++ b/include/uapi/linux/a.out.h
83862@@ -39,6 +39,14 @@ enum machine_type {
83863 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83864 };
83865
83866+/* Constants for the N_FLAGS field */
83867+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83868+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83869+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83870+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83871+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83872+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83873+
83874 #if !defined (N_MAGIC)
83875 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83876 #endif
83877diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83878index 22b6ad3..aeba37e 100644
83879--- a/include/uapi/linux/bcache.h
83880+++ b/include/uapi/linux/bcache.h
83881@@ -5,6 +5,7 @@
83882 * Bcache on disk data structures
83883 */
83884
83885+#include <linux/compiler.h>
83886 #include <asm/types.h>
83887
83888 #define BITMASK(name, type, field, offset, size) \
83889@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83890 /* Btree keys - all units are in sectors */
83891
83892 struct bkey {
83893- __u64 high;
83894- __u64 low;
83895+ __u64 high __intentional_overflow(-1);
83896+ __u64 low __intentional_overflow(-1);
83897 __u64 ptr[];
83898 };
83899
83900diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83901index d876736..ccce5c0 100644
83902--- a/include/uapi/linux/byteorder/little_endian.h
83903+++ b/include/uapi/linux/byteorder/little_endian.h
83904@@ -42,51 +42,51 @@
83905
83906 static inline __le64 __cpu_to_le64p(const __u64 *p)
83907 {
83908- return (__force __le64)*p;
83909+ return (__force const __le64)*p;
83910 }
83911-static inline __u64 __le64_to_cpup(const __le64 *p)
83912+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83913 {
83914- return (__force __u64)*p;
83915+ return (__force const __u64)*p;
83916 }
83917 static inline __le32 __cpu_to_le32p(const __u32 *p)
83918 {
83919- return (__force __le32)*p;
83920+ return (__force const __le32)*p;
83921 }
83922 static inline __u32 __le32_to_cpup(const __le32 *p)
83923 {
83924- return (__force __u32)*p;
83925+ return (__force const __u32)*p;
83926 }
83927 static inline __le16 __cpu_to_le16p(const __u16 *p)
83928 {
83929- return (__force __le16)*p;
83930+ return (__force const __le16)*p;
83931 }
83932 static inline __u16 __le16_to_cpup(const __le16 *p)
83933 {
83934- return (__force __u16)*p;
83935+ return (__force const __u16)*p;
83936 }
83937 static inline __be64 __cpu_to_be64p(const __u64 *p)
83938 {
83939- return (__force __be64)__swab64p(p);
83940+ return (__force const __be64)__swab64p(p);
83941 }
83942 static inline __u64 __be64_to_cpup(const __be64 *p)
83943 {
83944- return __swab64p((__u64 *)p);
83945+ return __swab64p((const __u64 *)p);
83946 }
83947 static inline __be32 __cpu_to_be32p(const __u32 *p)
83948 {
83949- return (__force __be32)__swab32p(p);
83950+ return (__force const __be32)__swab32p(p);
83951 }
83952-static inline __u32 __be32_to_cpup(const __be32 *p)
83953+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83954 {
83955- return __swab32p((__u32 *)p);
83956+ return __swab32p((const __u32 *)p);
83957 }
83958 static inline __be16 __cpu_to_be16p(const __u16 *p)
83959 {
83960- return (__force __be16)__swab16p(p);
83961+ return (__force const __be16)__swab16p(p);
83962 }
83963 static inline __u16 __be16_to_cpup(const __be16 *p)
83964 {
83965- return __swab16p((__u16 *)p);
83966+ return __swab16p((const __u16 *)p);
83967 }
83968 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83969 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83970diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83971index ef6103b..d4e65dd 100644
83972--- a/include/uapi/linux/elf.h
83973+++ b/include/uapi/linux/elf.h
83974@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83975 #define PT_GNU_EH_FRAME 0x6474e550
83976
83977 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83978+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83979+
83980+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83981+
83982+/* Constants for the e_flags field */
83983+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83984+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83985+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83986+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83987+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83988+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83989
83990 /*
83991 * Extended Numbering
83992@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83993 #define DT_DEBUG 21
83994 #define DT_TEXTREL 22
83995 #define DT_JMPREL 23
83996+#define DT_FLAGS 30
83997+ #define DF_TEXTREL 0x00000004
83998 #define DT_ENCODING 32
83999 #define OLD_DT_LOOS 0x60000000
84000 #define DT_LOOS 0x6000000d
84001@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84002 #define PF_W 0x2
84003 #define PF_X 0x1
84004
84005+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84006+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84007+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84008+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84009+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84010+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84011+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84012+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84013+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84014+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84015+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84016+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84017+
84018 typedef struct elf32_phdr{
84019 Elf32_Word p_type;
84020 Elf32_Off p_offset;
84021@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84022 #define EI_OSABI 7
84023 #define EI_PAD 8
84024
84025+#define EI_PAX 14
84026+
84027 #define ELFMAG0 0x7f /* EI_MAG */
84028 #define ELFMAG1 'E'
84029 #define ELFMAG2 'L'
84030diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84031index aa169c4..6a2771d 100644
84032--- a/include/uapi/linux/personality.h
84033+++ b/include/uapi/linux/personality.h
84034@@ -30,6 +30,7 @@ enum {
84035 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84036 ADDR_NO_RANDOMIZE | \
84037 ADDR_COMPAT_LAYOUT | \
84038+ ADDR_LIMIT_3GB | \
84039 MMAP_PAGE_ZERO)
84040
84041 /*
84042diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84043index 7530e74..e714828 100644
84044--- a/include/uapi/linux/screen_info.h
84045+++ b/include/uapi/linux/screen_info.h
84046@@ -43,7 +43,8 @@ struct screen_info {
84047 __u16 pages; /* 0x32 */
84048 __u16 vesa_attributes; /* 0x34 */
84049 __u32 capabilities; /* 0x36 */
84050- __u8 _reserved[6]; /* 0x3a */
84051+ __u16 vesapm_size; /* 0x3a */
84052+ __u8 _reserved[4]; /* 0x3c */
84053 } __attribute__((packed));
84054
84055 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84056diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84057index 0e011eb..82681b1 100644
84058--- a/include/uapi/linux/swab.h
84059+++ b/include/uapi/linux/swab.h
84060@@ -43,7 +43,7 @@
84061 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84062 */
84063
84064-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84065+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84066 {
84067 #ifdef __HAVE_BUILTIN_BSWAP16__
84068 return __builtin_bswap16(val);
84069@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84070 #endif
84071 }
84072
84073-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84074+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84075 {
84076 #ifdef __HAVE_BUILTIN_BSWAP32__
84077 return __builtin_bswap32(val);
84078@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84079 #endif
84080 }
84081
84082-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84083+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84084 {
84085 #ifdef __HAVE_BUILTIN_BSWAP64__
84086 return __builtin_bswap64(val);
84087diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84088index 6d67213..552fdd9 100644
84089--- a/include/uapi/linux/sysctl.h
84090+++ b/include/uapi/linux/sysctl.h
84091@@ -155,8 +155,6 @@ enum
84092 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84093 };
84094
84095-
84096-
84097 /* CTL_VM names: */
84098 enum
84099 {
84100diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84101index fe94bb9..c9e51c2 100644
84102--- a/include/uapi/linux/videodev2.h
84103+++ b/include/uapi/linux/videodev2.h
84104@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84105 union {
84106 __s32 value;
84107 __s64 value64;
84108- char *string;
84109+ char __user *string;
84110 };
84111 } __attribute__ ((packed));
84112
84113diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84114index c38355c..17a57bc 100644
84115--- a/include/uapi/linux/xattr.h
84116+++ b/include/uapi/linux/xattr.h
84117@@ -73,5 +73,9 @@
84118 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84119 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84120
84121+/* User namespace */
84122+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84123+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84124+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84125
84126 #endif /* _UAPI_LINUX_XATTR_H */
84127diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84128index f9466fa..f4e2b81 100644
84129--- a/include/video/udlfb.h
84130+++ b/include/video/udlfb.h
84131@@ -53,10 +53,10 @@ struct dlfb_data {
84132 u32 pseudo_palette[256];
84133 int blank_mode; /*one of FB_BLANK_ */
84134 /* blit-only rendering path metrics, exposed through sysfs */
84135- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84136- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84137- atomic_t bytes_sent; /* to usb, after compression including overhead */
84138- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84139+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84140+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84141+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84142+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84143 };
84144
84145 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84146diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84147index 30f5362..8ed8ac9 100644
84148--- a/include/video/uvesafb.h
84149+++ b/include/video/uvesafb.h
84150@@ -122,6 +122,7 @@ struct uvesafb_par {
84151 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84152 u8 pmi_setpal; /* PMI for palette changes */
84153 u16 *pmi_base; /* protected mode interface location */
84154+ u8 *pmi_code; /* protected mode code location */
84155 void *pmi_start;
84156 void *pmi_pal;
84157 u8 *vbe_state_orig; /*
84158diff --git a/init/Kconfig b/init/Kconfig
84159index d56cb03..7e6d5dc 100644
84160--- a/init/Kconfig
84161+++ b/init/Kconfig
84162@@ -1079,6 +1079,7 @@ endif # CGROUPS
84163
84164 config CHECKPOINT_RESTORE
84165 bool "Checkpoint/restore support" if EXPERT
84166+ depends on !GRKERNSEC
84167 default n
84168 help
84169 Enables additional kernel features in a sake of checkpoint/restore.
84170@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84171
84172 config COMPAT_BRK
84173 bool "Disable heap randomization"
84174- default y
84175+ default n
84176 help
84177 Randomizing heap placement makes heap exploits harder, but it
84178 also breaks ancient binaries (including anything libc5 based).
84179@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84180 config STOP_MACHINE
84181 bool
84182 default y
84183- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84184+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84185 help
84186 Need stop_machine() primitive.
84187
84188diff --git a/init/Makefile b/init/Makefile
84189index 7bc47ee..6da2dc7 100644
84190--- a/init/Makefile
84191+++ b/init/Makefile
84192@@ -2,6 +2,9 @@
84193 # Makefile for the linux kernel.
84194 #
84195
84196+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84197+asflags-y := $(GCC_PLUGINS_AFLAGS)
84198+
84199 obj-y := main.o version.o mounts.o
84200 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84201 obj-y += noinitramfs.o
84202diff --git a/init/do_mounts.c b/init/do_mounts.c
84203index 8e5addc..c96ea61 100644
84204--- a/init/do_mounts.c
84205+++ b/init/do_mounts.c
84206@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84207 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84208 {
84209 struct super_block *s;
84210- int err = sys_mount(name, "/root", fs, flags, data);
84211+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84212 if (err)
84213 return err;
84214
84215- sys_chdir("/root");
84216+ sys_chdir((const char __force_user *)"/root");
84217 s = current->fs->pwd.dentry->d_sb;
84218 ROOT_DEV = s->s_dev;
84219 printk(KERN_INFO
84220@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84221 va_start(args, fmt);
84222 vsprintf(buf, fmt, args);
84223 va_end(args);
84224- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84225+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84226 if (fd >= 0) {
84227 sys_ioctl(fd, FDEJECT, 0);
84228 sys_close(fd);
84229 }
84230 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84231- fd = sys_open("/dev/console", O_RDWR, 0);
84232+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84233 if (fd >= 0) {
84234 sys_ioctl(fd, TCGETS, (long)&termios);
84235 termios.c_lflag &= ~ICANON;
84236 sys_ioctl(fd, TCSETSF, (long)&termios);
84237- sys_read(fd, &c, 1);
84238+ sys_read(fd, (char __user *)&c, 1);
84239 termios.c_lflag |= ICANON;
84240 sys_ioctl(fd, TCSETSF, (long)&termios);
84241 sys_close(fd);
84242@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84243 mount_root();
84244 out:
84245 devtmpfs_mount("dev");
84246- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84247- sys_chroot(".");
84248+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84249+ sys_chroot((const char __force_user *)".");
84250 }
84251
84252 static bool is_tmpfs;
84253diff --git a/init/do_mounts.h b/init/do_mounts.h
84254index f5b978a..69dbfe8 100644
84255--- a/init/do_mounts.h
84256+++ b/init/do_mounts.h
84257@@ -15,15 +15,15 @@ extern int root_mountflags;
84258
84259 static inline int create_dev(char *name, dev_t dev)
84260 {
84261- sys_unlink(name);
84262- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84263+ sys_unlink((char __force_user *)name);
84264+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84265 }
84266
84267 #if BITS_PER_LONG == 32
84268 static inline u32 bstat(char *name)
84269 {
84270 struct stat64 stat;
84271- if (sys_stat64(name, &stat) != 0)
84272+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84273 return 0;
84274 if (!S_ISBLK(stat.st_mode))
84275 return 0;
84276@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84277 static inline u32 bstat(char *name)
84278 {
84279 struct stat stat;
84280- if (sys_newstat(name, &stat) != 0)
84281+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84282 return 0;
84283 if (!S_ISBLK(stat.st_mode))
84284 return 0;
84285diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84286index 3e0878e..8a9d7a0 100644
84287--- a/init/do_mounts_initrd.c
84288+++ b/init/do_mounts_initrd.c
84289@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84290 {
84291 sys_unshare(CLONE_FS | CLONE_FILES);
84292 /* stdin/stdout/stderr for /linuxrc */
84293- sys_open("/dev/console", O_RDWR, 0);
84294+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84295 sys_dup(0);
84296 sys_dup(0);
84297 /* move initrd over / and chdir/chroot in initrd root */
84298- sys_chdir("/root");
84299- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84300- sys_chroot(".");
84301+ sys_chdir((const char __force_user *)"/root");
84302+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84303+ sys_chroot((const char __force_user *)".");
84304 sys_setsid();
84305 return 0;
84306 }
84307@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84308 create_dev("/dev/root.old", Root_RAM0);
84309 /* mount initrd on rootfs' /root */
84310 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84311- sys_mkdir("/old", 0700);
84312- sys_chdir("/old");
84313+ sys_mkdir((const char __force_user *)"/old", 0700);
84314+ sys_chdir((const char __force_user *)"/old");
84315
84316 /* try loading default modules from initrd */
84317 load_default_modules();
84318@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84319 current->flags &= ~PF_FREEZER_SKIP;
84320
84321 /* move initrd to rootfs' /old */
84322- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84323+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84324 /* switch root and cwd back to / of rootfs */
84325- sys_chroot("..");
84326+ sys_chroot((const char __force_user *)"..");
84327
84328 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84329- sys_chdir("/old");
84330+ sys_chdir((const char __force_user *)"/old");
84331 return;
84332 }
84333
84334- sys_chdir("/");
84335+ sys_chdir((const char __force_user *)"/");
84336 ROOT_DEV = new_decode_dev(real_root_dev);
84337 mount_root();
84338
84339 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84340- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84341+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84342 if (!error)
84343 printk("okay\n");
84344 else {
84345- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84346+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84347 if (error == -ENOENT)
84348 printk("/initrd does not exist. Ignored.\n");
84349 else
84350 printk("failed\n");
84351 printk(KERN_NOTICE "Unmounting old root\n");
84352- sys_umount("/old", MNT_DETACH);
84353+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84354 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84355 if (fd < 0) {
84356 error = fd;
84357@@ -127,11 +127,11 @@ int __init initrd_load(void)
84358 * mounted in the normal path.
84359 */
84360 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84361- sys_unlink("/initrd.image");
84362+ sys_unlink((const char __force_user *)"/initrd.image");
84363 handle_initrd();
84364 return 1;
84365 }
84366 }
84367- sys_unlink("/initrd.image");
84368+ sys_unlink((const char __force_user *)"/initrd.image");
84369 return 0;
84370 }
84371diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84372index 8cb6db5..d729f50 100644
84373--- a/init/do_mounts_md.c
84374+++ b/init/do_mounts_md.c
84375@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84376 partitioned ? "_d" : "", minor,
84377 md_setup_args[ent].device_names);
84378
84379- fd = sys_open(name, 0, 0);
84380+ fd = sys_open((char __force_user *)name, 0, 0);
84381 if (fd < 0) {
84382 printk(KERN_ERR "md: open failed - cannot start "
84383 "array %s\n", name);
84384@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84385 * array without it
84386 */
84387 sys_close(fd);
84388- fd = sys_open(name, 0, 0);
84389+ fd = sys_open((char __force_user *)name, 0, 0);
84390 sys_ioctl(fd, BLKRRPART, 0);
84391 }
84392 sys_close(fd);
84393@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84394
84395 wait_for_device_probe();
84396
84397- fd = sys_open("/dev/md0", 0, 0);
84398+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84399 if (fd >= 0) {
84400 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84401 sys_close(fd);
84402diff --git a/init/init_task.c b/init/init_task.c
84403index ba0a7f36..2bcf1d5 100644
84404--- a/init/init_task.c
84405+++ b/init/init_task.c
84406@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84407 * Initial thread structure. Alignment of this is handled by a special
84408 * linker map entry.
84409 */
84410+#ifdef CONFIG_X86
84411+union thread_union init_thread_union __init_task_data;
84412+#else
84413 union thread_union init_thread_union __init_task_data =
84414 { INIT_THREAD_INFO(init_task) };
84415+#endif
84416diff --git a/init/initramfs.c b/init/initramfs.c
84417index 93b6139..8d628b7 100644
84418--- a/init/initramfs.c
84419+++ b/init/initramfs.c
84420@@ -84,7 +84,7 @@ static void __init free_hash(void)
84421 }
84422 }
84423
84424-static long __init do_utime(char *filename, time_t mtime)
84425+static long __init do_utime(char __force_user *filename, time_t mtime)
84426 {
84427 struct timespec t[2];
84428
84429@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84430 struct dir_entry *de, *tmp;
84431 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84432 list_del(&de->list);
84433- do_utime(de->name, de->mtime);
84434+ do_utime((char __force_user *)de->name, de->mtime);
84435 kfree(de->name);
84436 kfree(de);
84437 }
84438@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84439 if (nlink >= 2) {
84440 char *old = find_link(major, minor, ino, mode, collected);
84441 if (old)
84442- return (sys_link(old, collected) < 0) ? -1 : 1;
84443+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84444 }
84445 return 0;
84446 }
84447@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84448 {
84449 struct stat st;
84450
84451- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84452+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84453 if (S_ISDIR(st.st_mode))
84454- sys_rmdir(path);
84455+ sys_rmdir((char __force_user *)path);
84456 else
84457- sys_unlink(path);
84458+ sys_unlink((char __force_user *)path);
84459 }
84460 }
84461
84462@@ -315,7 +315,7 @@ static int __init do_name(void)
84463 int openflags = O_WRONLY|O_CREAT;
84464 if (ml != 1)
84465 openflags |= O_TRUNC;
84466- wfd = sys_open(collected, openflags, mode);
84467+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84468
84469 if (wfd >= 0) {
84470 sys_fchown(wfd, uid, gid);
84471@@ -327,17 +327,17 @@ static int __init do_name(void)
84472 }
84473 }
84474 } else if (S_ISDIR(mode)) {
84475- sys_mkdir(collected, mode);
84476- sys_chown(collected, uid, gid);
84477- sys_chmod(collected, mode);
84478+ sys_mkdir((char __force_user *)collected, mode);
84479+ sys_chown((char __force_user *)collected, uid, gid);
84480+ sys_chmod((char __force_user *)collected, mode);
84481 dir_add(collected, mtime);
84482 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84483 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84484 if (maybe_link() == 0) {
84485- sys_mknod(collected, mode, rdev);
84486- sys_chown(collected, uid, gid);
84487- sys_chmod(collected, mode);
84488- do_utime(collected, mtime);
84489+ sys_mknod((char __force_user *)collected, mode, rdev);
84490+ sys_chown((char __force_user *)collected, uid, gid);
84491+ sys_chmod((char __force_user *)collected, mode);
84492+ do_utime((char __force_user *)collected, mtime);
84493 }
84494 }
84495 return 0;
84496@@ -346,15 +346,15 @@ static int __init do_name(void)
84497 static int __init do_copy(void)
84498 {
84499 if (count >= body_len) {
84500- sys_write(wfd, victim, body_len);
84501+ sys_write(wfd, (char __force_user *)victim, body_len);
84502 sys_close(wfd);
84503- do_utime(vcollected, mtime);
84504+ do_utime((char __force_user *)vcollected, mtime);
84505 kfree(vcollected);
84506 eat(body_len);
84507 state = SkipIt;
84508 return 0;
84509 } else {
84510- sys_write(wfd, victim, count);
84511+ sys_write(wfd, (char __force_user *)victim, count);
84512 body_len -= count;
84513 eat(count);
84514 return 1;
84515@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84516 {
84517 collected[N_ALIGN(name_len) + body_len] = '\0';
84518 clean_path(collected, 0);
84519- sys_symlink(collected + N_ALIGN(name_len), collected);
84520- sys_lchown(collected, uid, gid);
84521- do_utime(collected, mtime);
84522+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84523+ sys_lchown((char __force_user *)collected, uid, gid);
84524+ do_utime((char __force_user *)collected, mtime);
84525 state = SkipIt;
84526 next_state = Reset;
84527 return 0;
84528diff --git a/init/main.c b/init/main.c
84529index 9c7fd4c..650b4f1 100644
84530--- a/init/main.c
84531+++ b/init/main.c
84532@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84533 static inline void mark_rodata_ro(void) { }
84534 #endif
84535
84536+extern void grsecurity_init(void);
84537+
84538 /*
84539 * Debug helper: via this flag we know that we are in 'early bootup code'
84540 * where only the boot processor is running with IRQ disabled. This means
84541@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84542
84543 __setup("reset_devices", set_reset_devices);
84544
84545+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84546+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84547+static int __init setup_grsec_proc_gid(char *str)
84548+{
84549+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84550+ return 1;
84551+}
84552+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84553+#endif
84554+
84555+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84556+unsigned long pax_user_shadow_base __read_only;
84557+EXPORT_SYMBOL(pax_user_shadow_base);
84558+extern char pax_enter_kernel_user[];
84559+extern char pax_exit_kernel_user[];
84560+#endif
84561+
84562+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84563+static int __init setup_pax_nouderef(char *str)
84564+{
84565+#ifdef CONFIG_X86_32
84566+ unsigned int cpu;
84567+ struct desc_struct *gdt;
84568+
84569+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84570+ gdt = get_cpu_gdt_table(cpu);
84571+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84572+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84573+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84574+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84575+ }
84576+ loadsegment(ds, __KERNEL_DS);
84577+ loadsegment(es, __KERNEL_DS);
84578+ loadsegment(ss, __KERNEL_DS);
84579+#else
84580+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84581+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84582+ clone_pgd_mask = ~(pgdval_t)0UL;
84583+ pax_user_shadow_base = 0UL;
84584+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84585+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84586+#endif
84587+
84588+ return 0;
84589+}
84590+early_param("pax_nouderef", setup_pax_nouderef);
84591+
84592+#ifdef CONFIG_X86_64
84593+static int __init setup_pax_weakuderef(char *str)
84594+{
84595+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84596+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84597+ return 1;
84598+}
84599+__setup("pax_weakuderef", setup_pax_weakuderef);
84600+#endif
84601+#endif
84602+
84603+#ifdef CONFIG_PAX_SOFTMODE
84604+int pax_softmode;
84605+
84606+static int __init setup_pax_softmode(char *str)
84607+{
84608+ get_option(&str, &pax_softmode);
84609+ return 1;
84610+}
84611+__setup("pax_softmode=", setup_pax_softmode);
84612+#endif
84613+
84614 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84615 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84616 static const char *panic_later, *panic_param;
84617@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84618 {
84619 int count = preempt_count();
84620 int ret;
84621- char msgbuf[64];
84622+ const char *msg1 = "", *msg2 = "";
84623
84624 if (initcall_debug)
84625 ret = do_one_initcall_debug(fn);
84626 else
84627 ret = fn();
84628
84629- msgbuf[0] = 0;
84630-
84631 if (preempt_count() != count) {
84632- sprintf(msgbuf, "preemption imbalance ");
84633+ msg1 = " preemption imbalance";
84634 preempt_count_set(count);
84635 }
84636 if (irqs_disabled()) {
84637- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84638+ msg2 = " disabled interrupts";
84639 local_irq_enable();
84640 }
84641- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84642+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84643
84644+ add_latent_entropy();
84645 return ret;
84646 }
84647
84648@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84649 {
84650 argv_init[0] = init_filename;
84651 return do_execve(getname_kernel(init_filename),
84652- (const char __user *const __user *)argv_init,
84653- (const char __user *const __user *)envp_init);
84654+ (const char __user *const __force_user *)argv_init,
84655+ (const char __user *const __force_user *)envp_init);
84656 }
84657
84658 static int try_to_run_init_process(const char *init_filename)
84659@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84660 return ret;
84661 }
84662
84663+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84664+extern int gr_init_ran;
84665+#endif
84666+
84667 static noinline void __init kernel_init_freeable(void);
84668
84669 static int __ref kernel_init(void *unused)
84670@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84671 ramdisk_execute_command, ret);
84672 }
84673
84674+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84675+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84676+ gr_init_ran = 1;
84677+#endif
84678+
84679 /*
84680 * We try each of these until one succeeds.
84681 *
84682@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84683 do_basic_setup();
84684
84685 /* Open the /dev/console on the rootfs, this should never fail */
84686- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84687+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84688 pr_err("Warning: unable to open an initial console.\n");
84689
84690 (void) sys_dup(0);
84691@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84692 if (!ramdisk_execute_command)
84693 ramdisk_execute_command = "/init";
84694
84695- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84696+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84697 ramdisk_execute_command = NULL;
84698 prepare_namespace();
84699 }
84700
84701+ grsecurity_init();
84702+
84703 /*
84704 * Ok, we have completed the initial bootup, and
84705 * we're essentially up and running. Get rid of the
84706diff --git a/ipc/compat.c b/ipc/compat.c
84707index f486b00..442867f 100644
84708--- a/ipc/compat.c
84709+++ b/ipc/compat.c
84710@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84711 COMPAT_SHMLBA);
84712 if (err < 0)
84713 return err;
84714- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84715+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84716 }
84717 case SHMDT:
84718 return sys_shmdt(compat_ptr(ptr));
84719diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84720index 1702864..797fa84 100644
84721--- a/ipc/ipc_sysctl.c
84722+++ b/ipc/ipc_sysctl.c
84723@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84724 static int proc_ipc_dointvec(ctl_table *table, int write,
84725 void __user *buffer, size_t *lenp, loff_t *ppos)
84726 {
84727- struct ctl_table ipc_table;
84728+ ctl_table_no_const ipc_table;
84729
84730 memcpy(&ipc_table, table, sizeof(ipc_table));
84731 ipc_table.data = get_ipc(table);
84732@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84733 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84734 void __user *buffer, size_t *lenp, loff_t *ppos)
84735 {
84736- struct ctl_table ipc_table;
84737+ ctl_table_no_const ipc_table;
84738
84739 memcpy(&ipc_table, table, sizeof(ipc_table));
84740 ipc_table.data = get_ipc(table);
84741@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84742 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84743 void __user *buffer, size_t *lenp, loff_t *ppos)
84744 {
84745- struct ctl_table ipc_table;
84746+ ctl_table_no_const ipc_table;
84747 size_t lenp_bef = *lenp;
84748 int rc;
84749
84750@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84751 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84752 void __user *buffer, size_t *lenp, loff_t *ppos)
84753 {
84754- struct ctl_table ipc_table;
84755+ ctl_table_no_const ipc_table;
84756 memcpy(&ipc_table, table, sizeof(ipc_table));
84757 ipc_table.data = get_ipc(table);
84758
84759@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84760 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84761 void __user *buffer, size_t *lenp, loff_t *ppos)
84762 {
84763- struct ctl_table ipc_table;
84764+ ctl_table_no_const ipc_table;
84765 size_t lenp_bef = *lenp;
84766 int oldval;
84767 int rc;
84768diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84769index 5bb8bfe..a38ec05 100644
84770--- a/ipc/mq_sysctl.c
84771+++ b/ipc/mq_sysctl.c
84772@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84773 static int proc_mq_dointvec(ctl_table *table, int write,
84774 void __user *buffer, size_t *lenp, loff_t *ppos)
84775 {
84776- struct ctl_table mq_table;
84777+ ctl_table_no_const mq_table;
84778 memcpy(&mq_table, table, sizeof(mq_table));
84779 mq_table.data = get_mq(table);
84780
84781@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84782 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84783 void __user *buffer, size_t *lenp, loff_t *ppos)
84784 {
84785- struct ctl_table mq_table;
84786+ ctl_table_no_const mq_table;
84787 memcpy(&mq_table, table, sizeof(mq_table));
84788 mq_table.data = get_mq(table);
84789
84790diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84791index c3b3117..1efa933 100644
84792--- a/ipc/mqueue.c
84793+++ b/ipc/mqueue.c
84794@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84795 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84796 info->attr.mq_msgsize);
84797
84798+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84799 spin_lock(&mq_lock);
84800 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84801 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84802diff --git a/ipc/msg.c b/ipc/msg.c
84803index 6498531..b0ff3c8 100644
84804--- a/ipc/msg.c
84805+++ b/ipc/msg.c
84806@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84807 return security_msg_queue_associate(msq, msgflg);
84808 }
84809
84810+static struct ipc_ops msg_ops = {
84811+ .getnew = newque,
84812+ .associate = msg_security,
84813+ .more_checks = NULL
84814+};
84815+
84816 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84817 {
84818 struct ipc_namespace *ns;
84819- struct ipc_ops msg_ops;
84820 struct ipc_params msg_params;
84821
84822 ns = current->nsproxy->ipc_ns;
84823
84824- msg_ops.getnew = newque;
84825- msg_ops.associate = msg_security;
84826- msg_ops.more_checks = NULL;
84827-
84828 msg_params.key = key;
84829 msg_params.flg = msgflg;
84830
84831diff --git a/ipc/sem.c b/ipc/sem.c
84832index bee5554..e9af81dd 100644
84833--- a/ipc/sem.c
84834+++ b/ipc/sem.c
84835@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84836 return 0;
84837 }
84838
84839+static struct ipc_ops sem_ops = {
84840+ .getnew = newary,
84841+ .associate = sem_security,
84842+ .more_checks = sem_more_checks
84843+};
84844+
84845 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84846 {
84847 struct ipc_namespace *ns;
84848- struct ipc_ops sem_ops;
84849 struct ipc_params sem_params;
84850
84851 ns = current->nsproxy->ipc_ns;
84852@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84853 if (nsems < 0 || nsems > ns->sc_semmsl)
84854 return -EINVAL;
84855
84856- sem_ops.getnew = newary;
84857- sem_ops.associate = sem_security;
84858- sem_ops.more_checks = sem_more_checks;
84859-
84860 sem_params.key = key;
84861 sem_params.flg = semflg;
84862 sem_params.u.nsems = nsems;
84863diff --git a/ipc/shm.c b/ipc/shm.c
84864index 7645961..afc7f02 100644
84865--- a/ipc/shm.c
84866+++ b/ipc/shm.c
84867@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
84868 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84869 #endif
84870
84871+#ifdef CONFIG_GRKERNSEC
84872+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84873+ const time_t shm_createtime, const kuid_t cuid,
84874+ const int shmid);
84875+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84876+ const time_t shm_createtime);
84877+#endif
84878+
84879 void shm_init_ns(struct ipc_namespace *ns)
84880 {
84881 ns->shm_ctlmax = SHMMAX;
84882@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84883 shp->shm_lprid = 0;
84884 shp->shm_atim = shp->shm_dtim = 0;
84885 shp->shm_ctim = get_seconds();
84886+#ifdef CONFIG_GRKERNSEC
84887+ {
84888+ struct timespec timeval;
84889+ do_posix_clock_monotonic_gettime(&timeval);
84890+
84891+ shp->shm_createtime = timeval.tv_sec;
84892+ }
84893+#endif
84894 shp->shm_segsz = size;
84895 shp->shm_nattch = 0;
84896 shp->shm_file = file;
84897@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84898 return 0;
84899 }
84900
84901+static struct ipc_ops shm_ops = {
84902+ .getnew = newseg,
84903+ .associate = shm_security,
84904+ .more_checks = shm_more_checks
84905+};
84906+
84907 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84908 {
84909 struct ipc_namespace *ns;
84910- struct ipc_ops shm_ops;
84911 struct ipc_params shm_params;
84912
84913 ns = current->nsproxy->ipc_ns;
84914
84915- shm_ops.getnew = newseg;
84916- shm_ops.associate = shm_security;
84917- shm_ops.more_checks = shm_more_checks;
84918-
84919 shm_params.key = key;
84920 shm_params.flg = shmflg;
84921 shm_params.u.size = size;
84922@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84923 f_mode = FMODE_READ | FMODE_WRITE;
84924 }
84925 if (shmflg & SHM_EXEC) {
84926+
84927+#ifdef CONFIG_PAX_MPROTECT
84928+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
84929+ goto out;
84930+#endif
84931+
84932 prot |= PROT_EXEC;
84933 acc_mode |= S_IXUGO;
84934 }
84935@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84936 if (err)
84937 goto out_unlock;
84938
84939+#ifdef CONFIG_GRKERNSEC
84940+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84941+ shp->shm_perm.cuid, shmid) ||
84942+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84943+ err = -EACCES;
84944+ goto out_unlock;
84945+ }
84946+#endif
84947+
84948 ipc_lock_object(&shp->shm_perm);
84949
84950 /* check if shm_destroy() is tearing down shp */
84951@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84952 path = shp->shm_file->f_path;
84953 path_get(&path);
84954 shp->shm_nattch++;
84955+#ifdef CONFIG_GRKERNSEC
84956+ shp->shm_lapid = current->pid;
84957+#endif
84958 size = i_size_read(path.dentry->d_inode);
84959 ipc_unlock_object(&shp->shm_perm);
84960 rcu_read_unlock();
84961diff --git a/ipc/util.c b/ipc/util.c
84962index e1b4c6d..8174204 100644
84963--- a/ipc/util.c
84964+++ b/ipc/util.c
84965@@ -71,6 +71,8 @@ struct ipc_proc_iface {
84966 int (*show)(struct seq_file *, void *);
84967 };
84968
84969+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84970+
84971 static void ipc_memory_notifier(struct work_struct *work)
84972 {
84973 ipcns_notify(IPCNS_MEMCHANGED);
84974@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84975 granted_mode >>= 6;
84976 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84977 granted_mode >>= 3;
84978+
84979+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84980+ return -1;
84981+
84982 /* is there some bit set in requested_mode but not in granted_mode? */
84983 if ((requested_mode & ~granted_mode & 0007) &&
84984 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84985diff --git a/kernel/acct.c b/kernel/acct.c
84986index 8d6e145..33e0b1e 100644
84987--- a/kernel/acct.c
84988+++ b/kernel/acct.c
84989@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84990 */
84991 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84992 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84993- file->f_op->write(file, (char *)&ac,
84994+ file->f_op->write(file, (char __force_user *)&ac,
84995 sizeof(acct_t), &file->f_pos);
84996 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84997 set_fs(fs);
84998diff --git a/kernel/audit.c b/kernel/audit.c
84999index 95a20f3..e1cb300 100644
85000--- a/kernel/audit.c
85001+++ b/kernel/audit.c
85002@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85003 3) suppressed due to audit_rate_limit
85004 4) suppressed due to audit_backlog_limit
85005 */
85006-static atomic_t audit_lost = ATOMIC_INIT(0);
85007+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85008
85009 /* The netlink socket. */
85010 static struct sock *audit_sock;
85011@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85012 unsigned long now;
85013 int print;
85014
85015- atomic_inc(&audit_lost);
85016+ atomic_inc_unchecked(&audit_lost);
85017
85018 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85019
85020@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85021 if (print) {
85022 if (printk_ratelimit())
85023 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85024- atomic_read(&audit_lost),
85025+ atomic_read_unchecked(&audit_lost),
85026 audit_rate_limit,
85027 audit_backlog_limit);
85028 audit_panic(message);
85029@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85030 s.pid = audit_pid;
85031 s.rate_limit = audit_rate_limit;
85032 s.backlog_limit = audit_backlog_limit;
85033- s.lost = atomic_read(&audit_lost);
85034+ s.lost = atomic_read_unchecked(&audit_lost);
85035 s.backlog = skb_queue_len(&audit_skb_queue);
85036 s.version = AUDIT_VERSION_LATEST;
85037 s.backlog_wait_time = audit_backlog_wait_time;
85038diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85039index 7aef2f4..db6ced2 100644
85040--- a/kernel/auditsc.c
85041+++ b/kernel/auditsc.c
85042@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85043 }
85044
85045 /* global counter which is incremented every time something logs in */
85046-static atomic_t session_id = ATOMIC_INIT(0);
85047+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85048
85049 static int audit_set_loginuid_perm(kuid_t loginuid)
85050 {
85051@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85052
85053 /* are we setting or clearing? */
85054 if (uid_valid(loginuid))
85055- sessionid = (unsigned int)atomic_inc_return(&session_id);
85056+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85057
85058 task->sessionid = sessionid;
85059 task->loginuid = loginuid;
85060diff --git a/kernel/capability.c b/kernel/capability.c
85061index 34019c5..363f279 100644
85062--- a/kernel/capability.c
85063+++ b/kernel/capability.c
85064@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85065 * before modification is attempted and the application
85066 * fails.
85067 */
85068+ if (tocopy > ARRAY_SIZE(kdata))
85069+ return -EFAULT;
85070+
85071 if (copy_to_user(dataptr, kdata, tocopy
85072 * sizeof(struct __user_cap_data_struct))) {
85073 return -EFAULT;
85074@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85075 int ret;
85076
85077 rcu_read_lock();
85078- ret = security_capable(__task_cred(t), ns, cap);
85079+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85080+ gr_task_is_capable(t, __task_cred(t), cap);
85081 rcu_read_unlock();
85082
85083- return (ret == 0);
85084+ return ret;
85085 }
85086
85087 /**
85088@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85089 int ret;
85090
85091 rcu_read_lock();
85092- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85093+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85094 rcu_read_unlock();
85095
85096- return (ret == 0);
85097+ return ret;
85098 }
85099
85100 /**
85101@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85102 BUG();
85103 }
85104
85105- if (security_capable(current_cred(), ns, cap) == 0) {
85106+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85107 current->flags |= PF_SUPERPRIV;
85108 return true;
85109 }
85110@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85111 }
85112 EXPORT_SYMBOL(ns_capable);
85113
85114+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85115+{
85116+ if (unlikely(!cap_valid(cap))) {
85117+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85118+ BUG();
85119+ }
85120+
85121+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85122+ current->flags |= PF_SUPERPRIV;
85123+ return true;
85124+ }
85125+ return false;
85126+}
85127+EXPORT_SYMBOL(ns_capable_nolog);
85128+
85129 /**
85130 * file_ns_capable - Determine if the file's opener had a capability in effect
85131 * @file: The file we want to check
85132@@ -432,6 +451,12 @@ bool capable(int cap)
85133 }
85134 EXPORT_SYMBOL(capable);
85135
85136+bool capable_nolog(int cap)
85137+{
85138+ return ns_capable_nolog(&init_user_ns, cap);
85139+}
85140+EXPORT_SYMBOL(capable_nolog);
85141+
85142 /**
85143 * inode_capable - Check superior capability over inode
85144 * @inode: The inode in question
85145@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85146 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85147 }
85148 EXPORT_SYMBOL(inode_capable);
85149+
85150+bool inode_capable_nolog(const struct inode *inode, int cap)
85151+{
85152+ struct user_namespace *ns = current_user_ns();
85153+
85154+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85155+}
85156+EXPORT_SYMBOL(inode_capable_nolog);
85157diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85158index 0c753dd..dd7d3d6 100644
85159--- a/kernel/cgroup.c
85160+++ b/kernel/cgroup.c
85161@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85162 struct css_set *cset = link->cset;
85163 struct task_struct *task;
85164 int count = 0;
85165- seq_printf(seq, "css_set %p\n", cset);
85166+ seq_printf(seq, "css_set %pK\n", cset);
85167 list_for_each_entry(task, &cset->tasks, cg_list) {
85168 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85169 seq_puts(seq, " ...\n");
85170diff --git a/kernel/compat.c b/kernel/compat.c
85171index 0a09e48..b46b3d78 100644
85172--- a/kernel/compat.c
85173+++ b/kernel/compat.c
85174@@ -13,6 +13,7 @@
85175
85176 #include <linux/linkage.h>
85177 #include <linux/compat.h>
85178+#include <linux/module.h>
85179 #include <linux/errno.h>
85180 #include <linux/time.h>
85181 #include <linux/signal.h>
85182@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85183 mm_segment_t oldfs;
85184 long ret;
85185
85186- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85187+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85188 oldfs = get_fs();
85189 set_fs(KERNEL_DS);
85190 ret = hrtimer_nanosleep_restart(restart);
85191@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85192 oldfs = get_fs();
85193 set_fs(KERNEL_DS);
85194 ret = hrtimer_nanosleep(&tu,
85195- rmtp ? (struct timespec __user *)&rmt : NULL,
85196+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85197 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85198 set_fs(oldfs);
85199
85200@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85201 mm_segment_t old_fs = get_fs();
85202
85203 set_fs(KERNEL_DS);
85204- ret = sys_sigpending((old_sigset_t __user *) &s);
85205+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85206 set_fs(old_fs);
85207 if (ret == 0)
85208 ret = put_user(s, set);
85209@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85210 mm_segment_t old_fs = get_fs();
85211
85212 set_fs(KERNEL_DS);
85213- ret = sys_old_getrlimit(resource, &r);
85214+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85215 set_fs(old_fs);
85216
85217 if (!ret) {
85218@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85219 set_fs (KERNEL_DS);
85220 ret = sys_wait4(pid,
85221 (stat_addr ?
85222- (unsigned int __user *) &status : NULL),
85223- options, (struct rusage __user *) &r);
85224+ (unsigned int __force_user *) &status : NULL),
85225+ options, (struct rusage __force_user *) &r);
85226 set_fs (old_fs);
85227
85228 if (ret > 0) {
85229@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85230 memset(&info, 0, sizeof(info));
85231
85232 set_fs(KERNEL_DS);
85233- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85234- uru ? (struct rusage __user *)&ru : NULL);
85235+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85236+ uru ? (struct rusage __force_user *)&ru : NULL);
85237 set_fs(old_fs);
85238
85239 if ((ret < 0) || (info.si_signo == 0))
85240@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85241 oldfs = get_fs();
85242 set_fs(KERNEL_DS);
85243 err = sys_timer_settime(timer_id, flags,
85244- (struct itimerspec __user *) &newts,
85245- (struct itimerspec __user *) &oldts);
85246+ (struct itimerspec __force_user *) &newts,
85247+ (struct itimerspec __force_user *) &oldts);
85248 set_fs(oldfs);
85249 if (!err && old && put_compat_itimerspec(old, &oldts))
85250 return -EFAULT;
85251@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85252 oldfs = get_fs();
85253 set_fs(KERNEL_DS);
85254 err = sys_timer_gettime(timer_id,
85255- (struct itimerspec __user *) &ts);
85256+ (struct itimerspec __force_user *) &ts);
85257 set_fs(oldfs);
85258 if (!err && put_compat_itimerspec(setting, &ts))
85259 return -EFAULT;
85260@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85261 oldfs = get_fs();
85262 set_fs(KERNEL_DS);
85263 err = sys_clock_settime(which_clock,
85264- (struct timespec __user *) &ts);
85265+ (struct timespec __force_user *) &ts);
85266 set_fs(oldfs);
85267 return err;
85268 }
85269@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85270 oldfs = get_fs();
85271 set_fs(KERNEL_DS);
85272 err = sys_clock_gettime(which_clock,
85273- (struct timespec __user *) &ts);
85274+ (struct timespec __force_user *) &ts);
85275 set_fs(oldfs);
85276 if (!err && put_compat_timespec(&ts, tp))
85277 return -EFAULT;
85278@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85279
85280 oldfs = get_fs();
85281 set_fs(KERNEL_DS);
85282- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85283+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85284 set_fs(oldfs);
85285
85286 err = compat_put_timex(utp, &txc);
85287@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85288 oldfs = get_fs();
85289 set_fs(KERNEL_DS);
85290 err = sys_clock_getres(which_clock,
85291- (struct timespec __user *) &ts);
85292+ (struct timespec __force_user *) &ts);
85293 set_fs(oldfs);
85294 if (!err && tp && put_compat_timespec(&ts, tp))
85295 return -EFAULT;
85296@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85297 long err;
85298 mm_segment_t oldfs;
85299 struct timespec tu;
85300- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85301+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85302
85303- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85304+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85305 oldfs = get_fs();
85306 set_fs(KERNEL_DS);
85307 err = clock_nanosleep_restart(restart);
85308@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85309 oldfs = get_fs();
85310 set_fs(KERNEL_DS);
85311 err = sys_clock_nanosleep(which_clock, flags,
85312- (struct timespec __user *) &in,
85313- (struct timespec __user *) &out);
85314+ (struct timespec __force_user *) &in,
85315+ (struct timespec __force_user *) &out);
85316 set_fs(oldfs);
85317
85318 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85319@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85320 mm_segment_t old_fs = get_fs();
85321
85322 set_fs(KERNEL_DS);
85323- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85324+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85325 set_fs(old_fs);
85326 if (put_compat_timespec(&t, interval))
85327 return -EFAULT;
85328diff --git a/kernel/configs.c b/kernel/configs.c
85329index c18b1f1..b9a0132 100644
85330--- a/kernel/configs.c
85331+++ b/kernel/configs.c
85332@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85333 struct proc_dir_entry *entry;
85334
85335 /* create the current config file */
85336+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85337+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85338+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85339+ &ikconfig_file_ops);
85340+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85341+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85342+ &ikconfig_file_ops);
85343+#endif
85344+#else
85345 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85346 &ikconfig_file_ops);
85347+#endif
85348+
85349 if (!entry)
85350 return -ENOMEM;
85351
85352diff --git a/kernel/cred.c b/kernel/cred.c
85353index e0573a4..3874e41 100644
85354--- a/kernel/cred.c
85355+++ b/kernel/cred.c
85356@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85357 validate_creds(cred);
85358 alter_cred_subscribers(cred, -1);
85359 put_cred(cred);
85360+
85361+#ifdef CONFIG_GRKERNSEC_SETXID
85362+ cred = (struct cred *) tsk->delayed_cred;
85363+ if (cred != NULL) {
85364+ tsk->delayed_cred = NULL;
85365+ validate_creds(cred);
85366+ alter_cred_subscribers(cred, -1);
85367+ put_cred(cred);
85368+ }
85369+#endif
85370 }
85371
85372 /**
85373@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85374 * Always returns 0 thus allowing this function to be tail-called at the end
85375 * of, say, sys_setgid().
85376 */
85377-int commit_creds(struct cred *new)
85378+static int __commit_creds(struct cred *new)
85379 {
85380 struct task_struct *task = current;
85381 const struct cred *old = task->real_cred;
85382@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85383
85384 get_cred(new); /* we will require a ref for the subj creds too */
85385
85386+ gr_set_role_label(task, new->uid, new->gid);
85387+
85388 /* dumpability changes */
85389 if (!uid_eq(old->euid, new->euid) ||
85390 !gid_eq(old->egid, new->egid) ||
85391@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85392 put_cred(old);
85393 return 0;
85394 }
85395+#ifdef CONFIG_GRKERNSEC_SETXID
85396+extern int set_user(struct cred *new);
85397+
85398+void gr_delayed_cred_worker(void)
85399+{
85400+ const struct cred *new = current->delayed_cred;
85401+ struct cred *ncred;
85402+
85403+ current->delayed_cred = NULL;
85404+
85405+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85406+ // from doing get_cred on it when queueing this
85407+ put_cred(new);
85408+ return;
85409+ } else if (new == NULL)
85410+ return;
85411+
85412+ ncred = prepare_creds();
85413+ if (!ncred)
85414+ goto die;
85415+ // uids
85416+ ncred->uid = new->uid;
85417+ ncred->euid = new->euid;
85418+ ncred->suid = new->suid;
85419+ ncred->fsuid = new->fsuid;
85420+ // gids
85421+ ncred->gid = new->gid;
85422+ ncred->egid = new->egid;
85423+ ncred->sgid = new->sgid;
85424+ ncred->fsgid = new->fsgid;
85425+ // groups
85426+ if (set_groups(ncred, new->group_info) < 0) {
85427+ abort_creds(ncred);
85428+ goto die;
85429+ }
85430+ // caps
85431+ ncred->securebits = new->securebits;
85432+ ncred->cap_inheritable = new->cap_inheritable;
85433+ ncred->cap_permitted = new->cap_permitted;
85434+ ncred->cap_effective = new->cap_effective;
85435+ ncred->cap_bset = new->cap_bset;
85436+
85437+ if (set_user(ncred)) {
85438+ abort_creds(ncred);
85439+ goto die;
85440+ }
85441+
85442+ // from doing get_cred on it when queueing this
85443+ put_cred(new);
85444+
85445+ __commit_creds(ncred);
85446+ return;
85447+die:
85448+ // from doing get_cred on it when queueing this
85449+ put_cred(new);
85450+ do_group_exit(SIGKILL);
85451+}
85452+#endif
85453+
85454+int commit_creds(struct cred *new)
85455+{
85456+#ifdef CONFIG_GRKERNSEC_SETXID
85457+ int ret;
85458+ int schedule_it = 0;
85459+ struct task_struct *t;
85460+
85461+ /* we won't get called with tasklist_lock held for writing
85462+ and interrupts disabled as the cred struct in that case is
85463+ init_cred
85464+ */
85465+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85466+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85467+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85468+ schedule_it = 1;
85469+ }
85470+ ret = __commit_creds(new);
85471+ if (schedule_it) {
85472+ rcu_read_lock();
85473+ read_lock(&tasklist_lock);
85474+ for (t = next_thread(current); t != current;
85475+ t = next_thread(t)) {
85476+ if (t->delayed_cred == NULL) {
85477+ t->delayed_cred = get_cred(new);
85478+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85479+ set_tsk_need_resched(t);
85480+ }
85481+ }
85482+ read_unlock(&tasklist_lock);
85483+ rcu_read_unlock();
85484+ }
85485+ return ret;
85486+#else
85487+ return __commit_creds(new);
85488+#endif
85489+}
85490+
85491 EXPORT_SYMBOL(commit_creds);
85492
85493 /**
85494diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85495index 334b398..9145fb1 100644
85496--- a/kernel/debug/debug_core.c
85497+++ b/kernel/debug/debug_core.c
85498@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85499 */
85500 static atomic_t masters_in_kgdb;
85501 static atomic_t slaves_in_kgdb;
85502-static atomic_t kgdb_break_tasklet_var;
85503+static atomic_unchecked_t kgdb_break_tasklet_var;
85504 atomic_t kgdb_setting_breakpoint;
85505
85506 struct task_struct *kgdb_usethread;
85507@@ -133,7 +133,7 @@ int kgdb_single_step;
85508 static pid_t kgdb_sstep_pid;
85509
85510 /* to keep track of the CPU which is doing the single stepping*/
85511-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85512+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85513
85514 /*
85515 * If you are debugging a problem where roundup (the collection of
85516@@ -541,7 +541,7 @@ return_normal:
85517 * kernel will only try for the value of sstep_tries before
85518 * giving up and continuing on.
85519 */
85520- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85521+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85522 (kgdb_info[cpu].task &&
85523 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85524 atomic_set(&kgdb_active, -1);
85525@@ -639,8 +639,8 @@ cpu_master_loop:
85526 }
85527
85528 kgdb_restore:
85529- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85530- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85531+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85532+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85533 if (kgdb_info[sstep_cpu].task)
85534 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85535 else
85536@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85537 static void kgdb_tasklet_bpt(unsigned long ing)
85538 {
85539 kgdb_breakpoint();
85540- atomic_set(&kgdb_break_tasklet_var, 0);
85541+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85542 }
85543
85544 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85545
85546 void kgdb_schedule_breakpoint(void)
85547 {
85548- if (atomic_read(&kgdb_break_tasklet_var) ||
85549+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85550 atomic_read(&kgdb_active) != -1 ||
85551 atomic_read(&kgdb_setting_breakpoint))
85552 return;
85553- atomic_inc(&kgdb_break_tasklet_var);
85554+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85555 tasklet_schedule(&kgdb_tasklet_breakpoint);
85556 }
85557 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85558diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85559index 0b097c8..11dd5c5 100644
85560--- a/kernel/debug/kdb/kdb_main.c
85561+++ b/kernel/debug/kdb/kdb_main.c
85562@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85563 continue;
85564
85565 kdb_printf("%-20s%8u 0x%p ", mod->name,
85566- mod->core_size, (void *)mod);
85567+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85568 #ifdef CONFIG_MODULE_UNLOAD
85569 kdb_printf("%4ld ", module_refcount(mod));
85570 #endif
85571@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85572 kdb_printf(" (Loading)");
85573 else
85574 kdb_printf(" (Live)");
85575- kdb_printf(" 0x%p", mod->module_core);
85576+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85577
85578 #ifdef CONFIG_MODULE_UNLOAD
85579 {
85580diff --git a/kernel/events/core.c b/kernel/events/core.c
85581index fa0b2d4..67a1c7a 100644
85582--- a/kernel/events/core.c
85583+++ b/kernel/events/core.c
85584@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85585 * 0 - disallow raw tracepoint access for unpriv
85586 * 1 - disallow cpu events for unpriv
85587 * 2 - disallow kernel profiling for unpriv
85588+ * 3 - disallow all unpriv perf event use
85589 */
85590-int sysctl_perf_event_paranoid __read_mostly = 1;
85591+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85592+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85593+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85594+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85595+#else
85596+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85597+#endif
85598
85599 /* Minimum for 512 kiB + 1 user control page */
85600 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85601@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85602
85603 tmp *= sysctl_perf_cpu_time_max_percent;
85604 do_div(tmp, 100);
85605- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85606+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85607 }
85608
85609 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85610@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85611 update_perf_cpu_limits();
85612 }
85613
85614-static atomic64_t perf_event_id;
85615+static atomic64_unchecked_t perf_event_id;
85616
85617 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85618 enum event_type_t event_type);
85619@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85620
85621 static inline u64 perf_event_count(struct perf_event *event)
85622 {
85623- return local64_read(&event->count) + atomic64_read(&event->child_count);
85624+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85625 }
85626
85627 static u64 perf_event_read(struct perf_event *event)
85628@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85629 mutex_lock(&event->child_mutex);
85630 total += perf_event_read(event);
85631 *enabled += event->total_time_enabled +
85632- atomic64_read(&event->child_total_time_enabled);
85633+ atomic64_read_unchecked(&event->child_total_time_enabled);
85634 *running += event->total_time_running +
85635- atomic64_read(&event->child_total_time_running);
85636+ atomic64_read_unchecked(&event->child_total_time_running);
85637
85638 list_for_each_entry(child, &event->child_list, child_list) {
85639 total += perf_event_read(child);
85640@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85641 userpg->offset -= local64_read(&event->hw.prev_count);
85642
85643 userpg->time_enabled = enabled +
85644- atomic64_read(&event->child_total_time_enabled);
85645+ atomic64_read_unchecked(&event->child_total_time_enabled);
85646
85647 userpg->time_running = running +
85648- atomic64_read(&event->child_total_time_running);
85649+ atomic64_read_unchecked(&event->child_total_time_running);
85650
85651 arch_perf_update_userpage(userpg, now);
85652
85653@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85654
85655 /* Data. */
85656 sp = perf_user_stack_pointer(regs);
85657- rem = __output_copy_user(handle, (void *) sp, dump_size);
85658+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85659 dyn_size = dump_size - rem;
85660
85661 perf_output_skip(handle, rem);
85662@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85663 values[n++] = perf_event_count(event);
85664 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85665 values[n++] = enabled +
85666- atomic64_read(&event->child_total_time_enabled);
85667+ atomic64_read_unchecked(&event->child_total_time_enabled);
85668 }
85669 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85670 values[n++] = running +
85671- atomic64_read(&event->child_total_time_running);
85672+ atomic64_read_unchecked(&event->child_total_time_running);
85673 }
85674 if (read_format & PERF_FORMAT_ID)
85675 values[n++] = primary_event_id(event);
85676@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85677 event->parent = parent_event;
85678
85679 event->ns = get_pid_ns(task_active_pid_ns(current));
85680- event->id = atomic64_inc_return(&perf_event_id);
85681+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85682
85683 event->state = PERF_EVENT_STATE_INACTIVE;
85684
85685@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85686 if (flags & ~PERF_FLAG_ALL)
85687 return -EINVAL;
85688
85689+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85690+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85691+ return -EACCES;
85692+#endif
85693+
85694 err = perf_copy_attr(attr_uptr, &attr);
85695 if (err)
85696 return err;
85697@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85698 /*
85699 * Add back the child's count to the parent's count:
85700 */
85701- atomic64_add(child_val, &parent_event->child_count);
85702- atomic64_add(child_event->total_time_enabled,
85703+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85704+ atomic64_add_unchecked(child_event->total_time_enabled,
85705 &parent_event->child_total_time_enabled);
85706- atomic64_add(child_event->total_time_running,
85707+ atomic64_add_unchecked(child_event->total_time_running,
85708 &parent_event->child_total_time_running);
85709
85710 /*
85711diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85712index 569b2187..19940d9 100644
85713--- a/kernel/events/internal.h
85714+++ b/kernel/events/internal.h
85715@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85716 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85717 }
85718
85719-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85720+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85721 static inline unsigned long \
85722 func_name(struct perf_output_handle *handle, \
85723- const void *buf, unsigned long len) \
85724+ const void user *buf, unsigned long len) \
85725 { \
85726 unsigned long size, written; \
85727 \
85728@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85729 return 0;
85730 }
85731
85732-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85733+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85734
85735 static inline unsigned long
85736 memcpy_skip(void *dst, const void *src, unsigned long n)
85737@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85738 return 0;
85739 }
85740
85741-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85742+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85743
85744 #ifndef arch_perf_out_copy_user
85745 #define arch_perf_out_copy_user arch_perf_out_copy_user
85746@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85747 }
85748 #endif
85749
85750-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85751+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85752
85753 /* Callchain handling */
85754 extern struct perf_callchain_entry *
85755diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85756index 307d87c..6466cbe 100644
85757--- a/kernel/events/uprobes.c
85758+++ b/kernel/events/uprobes.c
85759@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85760 {
85761 struct page *page;
85762 uprobe_opcode_t opcode;
85763- int result;
85764+ long result;
85765
85766 pagefault_disable();
85767 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85768diff --git a/kernel/exit.c b/kernel/exit.c
85769index 81b3d67..ef189a4 100644
85770--- a/kernel/exit.c
85771+++ b/kernel/exit.c
85772@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85773 struct task_struct *leader;
85774 int zap_leader;
85775 repeat:
85776+#ifdef CONFIG_NET
85777+ gr_del_task_from_ip_table(p);
85778+#endif
85779+
85780 /* don't need to get the RCU readlock here - the process is dead and
85781 * can't be modifying its own credentials. But shut RCU-lockdep up */
85782 rcu_read_lock();
85783@@ -330,7 +334,7 @@ int allow_signal(int sig)
85784 * know it'll be handled, so that they don't get converted to
85785 * SIGKILL or just silently dropped.
85786 */
85787- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85788+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85789 recalc_sigpending();
85790 spin_unlock_irq(&current->sighand->siglock);
85791 return 0;
85792@@ -706,6 +710,8 @@ void do_exit(long code)
85793 struct task_struct *tsk = current;
85794 int group_dead;
85795
85796+ set_fs(USER_DS);
85797+
85798 profile_task_exit(tsk);
85799
85800 WARN_ON(blk_needs_flush_plug(tsk));
85801@@ -722,7 +728,6 @@ void do_exit(long code)
85802 * mm_release()->clear_child_tid() from writing to a user-controlled
85803 * kernel address.
85804 */
85805- set_fs(USER_DS);
85806
85807 ptrace_event(PTRACE_EVENT_EXIT, code);
85808
85809@@ -781,6 +786,9 @@ void do_exit(long code)
85810 tsk->exit_code = code;
85811 taskstats_exit(tsk, group_dead);
85812
85813+ gr_acl_handle_psacct(tsk, code);
85814+ gr_acl_handle_exit();
85815+
85816 exit_mm(tsk);
85817
85818 if (group_dead)
85819@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85820 * Take down every thread in the group. This is called by fatal signals
85821 * as well as by sys_exit_group (below).
85822 */
85823-void
85824+__noreturn void
85825 do_group_exit(int exit_code)
85826 {
85827 struct signal_struct *sig = current->signal;
85828diff --git a/kernel/fork.c b/kernel/fork.c
85829index a17621c..b77fef8 100644
85830--- a/kernel/fork.c
85831+++ b/kernel/fork.c
85832@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85833 *stackend = STACK_END_MAGIC; /* for overflow detection */
85834
85835 #ifdef CONFIG_CC_STACKPROTECTOR
85836- tsk->stack_canary = get_random_int();
85837+ tsk->stack_canary = pax_get_random_long();
85838 #endif
85839
85840 /*
85841@@ -345,12 +345,80 @@ free_tsk:
85842 }
85843
85844 #ifdef CONFIG_MMU
85845-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85846+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85847+{
85848+ struct vm_area_struct *tmp;
85849+ unsigned long charge;
85850+ struct file *file;
85851+ int retval;
85852+
85853+ charge = 0;
85854+ if (mpnt->vm_flags & VM_ACCOUNT) {
85855+ unsigned long len = vma_pages(mpnt);
85856+
85857+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85858+ goto fail_nomem;
85859+ charge = len;
85860+ }
85861+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85862+ if (!tmp)
85863+ goto fail_nomem;
85864+ *tmp = *mpnt;
85865+ tmp->vm_mm = mm;
85866+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
85867+ retval = vma_dup_policy(mpnt, tmp);
85868+ if (retval)
85869+ goto fail_nomem_policy;
85870+ if (anon_vma_fork(tmp, mpnt))
85871+ goto fail_nomem_anon_vma_fork;
85872+ tmp->vm_flags &= ~VM_LOCKED;
85873+ tmp->vm_next = tmp->vm_prev = NULL;
85874+ tmp->vm_mirror = NULL;
85875+ file = tmp->vm_file;
85876+ if (file) {
85877+ struct inode *inode = file_inode(file);
85878+ struct address_space *mapping = file->f_mapping;
85879+
85880+ get_file(file);
85881+ if (tmp->vm_flags & VM_DENYWRITE)
85882+ atomic_dec(&inode->i_writecount);
85883+ mutex_lock(&mapping->i_mmap_mutex);
85884+ if (tmp->vm_flags & VM_SHARED)
85885+ mapping->i_mmap_writable++;
85886+ flush_dcache_mmap_lock(mapping);
85887+ /* insert tmp into the share list, just after mpnt */
85888+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85889+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85890+ else
85891+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85892+ flush_dcache_mmap_unlock(mapping);
85893+ mutex_unlock(&mapping->i_mmap_mutex);
85894+ }
85895+
85896+ /*
85897+ * Clear hugetlb-related page reserves for children. This only
85898+ * affects MAP_PRIVATE mappings. Faults generated by the child
85899+ * are not guaranteed to succeed, even if read-only
85900+ */
85901+ if (is_vm_hugetlb_page(tmp))
85902+ reset_vma_resv_huge_pages(tmp);
85903+
85904+ return tmp;
85905+
85906+fail_nomem_anon_vma_fork:
85907+ mpol_put(vma_policy(tmp));
85908+fail_nomem_policy:
85909+ kmem_cache_free(vm_area_cachep, tmp);
85910+fail_nomem:
85911+ vm_unacct_memory(charge);
85912+ return NULL;
85913+}
85914+
85915+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85916 {
85917 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85918 struct rb_node **rb_link, *rb_parent;
85919 int retval;
85920- unsigned long charge;
85921
85922 uprobe_start_dup_mmap();
85923 down_write(&oldmm->mmap_sem);
85924@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85925
85926 prev = NULL;
85927 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85928- struct file *file;
85929-
85930 if (mpnt->vm_flags & VM_DONTCOPY) {
85931 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85932 -vma_pages(mpnt));
85933 continue;
85934 }
85935- charge = 0;
85936- if (mpnt->vm_flags & VM_ACCOUNT) {
85937- unsigned long len = vma_pages(mpnt);
85938-
85939- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85940- goto fail_nomem;
85941- charge = len;
85942- }
85943- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85944- if (!tmp)
85945- goto fail_nomem;
85946- *tmp = *mpnt;
85947- INIT_LIST_HEAD(&tmp->anon_vma_chain);
85948- retval = vma_dup_policy(mpnt, tmp);
85949- if (retval)
85950- goto fail_nomem_policy;
85951- tmp->vm_mm = mm;
85952- if (anon_vma_fork(tmp, mpnt))
85953- goto fail_nomem_anon_vma_fork;
85954- tmp->vm_flags &= ~VM_LOCKED;
85955- tmp->vm_next = tmp->vm_prev = NULL;
85956- file = tmp->vm_file;
85957- if (file) {
85958- struct inode *inode = file_inode(file);
85959- struct address_space *mapping = file->f_mapping;
85960-
85961- get_file(file);
85962- if (tmp->vm_flags & VM_DENYWRITE)
85963- atomic_dec(&inode->i_writecount);
85964- mutex_lock(&mapping->i_mmap_mutex);
85965- if (tmp->vm_flags & VM_SHARED)
85966- mapping->i_mmap_writable++;
85967- flush_dcache_mmap_lock(mapping);
85968- /* insert tmp into the share list, just after mpnt */
85969- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85970- vma_nonlinear_insert(tmp,
85971- &mapping->i_mmap_nonlinear);
85972- else
85973- vma_interval_tree_insert_after(tmp, mpnt,
85974- &mapping->i_mmap);
85975- flush_dcache_mmap_unlock(mapping);
85976- mutex_unlock(&mapping->i_mmap_mutex);
85977+ tmp = dup_vma(mm, oldmm, mpnt);
85978+ if (!tmp) {
85979+ retval = -ENOMEM;
85980+ goto out;
85981 }
85982
85983 /*
85984@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85985 if (retval)
85986 goto out;
85987 }
85988+
85989+#ifdef CONFIG_PAX_SEGMEXEC
85990+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85991+ struct vm_area_struct *mpnt_m;
85992+
85993+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85994+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85995+
85996+ if (!mpnt->vm_mirror)
85997+ continue;
85998+
85999+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86000+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86001+ mpnt->vm_mirror = mpnt_m;
86002+ } else {
86003+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86004+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86005+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86006+ mpnt->vm_mirror->vm_mirror = mpnt;
86007+ }
86008+ }
86009+ BUG_ON(mpnt_m);
86010+ }
86011+#endif
86012+
86013 /* a new mm has just been created */
86014 arch_dup_mmap(oldmm, mm);
86015 retval = 0;
86016@@ -468,14 +521,6 @@ out:
86017 up_write(&oldmm->mmap_sem);
86018 uprobe_end_dup_mmap();
86019 return retval;
86020-fail_nomem_anon_vma_fork:
86021- mpol_put(vma_policy(tmp));
86022-fail_nomem_policy:
86023- kmem_cache_free(vm_area_cachep, tmp);
86024-fail_nomem:
86025- retval = -ENOMEM;
86026- vm_unacct_memory(charge);
86027- goto out;
86028 }
86029
86030 static inline int mm_alloc_pgd(struct mm_struct *mm)
86031@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86032 return ERR_PTR(err);
86033
86034 mm = get_task_mm(task);
86035- if (mm && mm != current->mm &&
86036- !ptrace_may_access(task, mode)) {
86037+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86038+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86039 mmput(mm);
86040 mm = ERR_PTR(-EACCES);
86041 }
86042@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86043 spin_unlock(&fs->lock);
86044 return -EAGAIN;
86045 }
86046- fs->users++;
86047+ atomic_inc(&fs->users);
86048 spin_unlock(&fs->lock);
86049 return 0;
86050 }
86051 tsk->fs = copy_fs_struct(fs);
86052 if (!tsk->fs)
86053 return -ENOMEM;
86054+ /* Carry through gr_chroot_dentry and is_chrooted instead
86055+ of recomputing it here. Already copied when the task struct
86056+ is duplicated. This allows pivot_root to not be treated as
86057+ a chroot
86058+ */
86059+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86060+
86061 return 0;
86062 }
86063
86064@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86065 * parts of the process environment (as per the clone
86066 * flags). The actual kick-off is left to the caller.
86067 */
86068-static struct task_struct *copy_process(unsigned long clone_flags,
86069+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86070 unsigned long stack_start,
86071 unsigned long stack_size,
86072 int __user *child_tidptr,
86073@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86074 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86075 #endif
86076 retval = -EAGAIN;
86077+
86078+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86079+
86080 if (atomic_read(&p->real_cred->user->processes) >=
86081 task_rlimit(p, RLIMIT_NPROC)) {
86082 if (p->real_cred->user != INIT_USER &&
86083@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86084 goto bad_fork_free_pid;
86085 }
86086
86087+ /* synchronizes with gr_set_acls()
86088+ we need to call this past the point of no return for fork()
86089+ */
86090+ gr_copy_label(p);
86091+
86092 if (likely(p->pid)) {
86093 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86094
86095@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86096 bad_fork_free:
86097 free_task(p);
86098 fork_out:
86099+ gr_log_forkfail(retval);
86100+
86101 return ERR_PTR(retval);
86102 }
86103
86104@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86105
86106 p = copy_process(clone_flags, stack_start, stack_size,
86107 child_tidptr, NULL, trace);
86108+ add_latent_entropy();
86109 /*
86110 * Do this prior waking up the new thread - the thread pointer
86111 * might get invalid after that point, if the thread exits quickly.
86112@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86113 if (clone_flags & CLONE_PARENT_SETTID)
86114 put_user(nr, parent_tidptr);
86115
86116+ gr_handle_brute_check();
86117+
86118 if (clone_flags & CLONE_VFORK) {
86119 p->vfork_done = &vfork;
86120 init_completion(&vfork);
86121@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86122 mm_cachep = kmem_cache_create("mm_struct",
86123 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86124 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86125- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86126+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86127 mmap_init();
86128 nsproxy_cache_init();
86129 }
86130@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86131 return 0;
86132
86133 /* don't need lock here; in the worst case we'll do useless copy */
86134- if (fs->users == 1)
86135+ if (atomic_read(&fs->users) == 1)
86136 return 0;
86137
86138 *new_fsp = copy_fs_struct(fs);
86139@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86140 fs = current->fs;
86141 spin_lock(&fs->lock);
86142 current->fs = new_fs;
86143- if (--fs->users)
86144+ gr_set_chroot_entries(current, &current->fs->root);
86145+ if (atomic_dec_return(&fs->users))
86146 new_fs = NULL;
86147 else
86148 new_fs = fs;
86149diff --git a/kernel/futex.c b/kernel/futex.c
86150index 6801b37..bb6becca 100644
86151--- a/kernel/futex.c
86152+++ b/kernel/futex.c
86153@@ -54,6 +54,7 @@
86154 #include <linux/mount.h>
86155 #include <linux/pagemap.h>
86156 #include <linux/syscalls.h>
86157+#include <linux/ptrace.h>
86158 #include <linux/signal.h>
86159 #include <linux/export.h>
86160 #include <linux/magic.h>
86161@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86162 struct page *page, *page_head;
86163 int err, ro = 0;
86164
86165+#ifdef CONFIG_PAX_SEGMEXEC
86166+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86167+ return -EFAULT;
86168+#endif
86169+
86170 /*
86171 * The futex address must be "naturally" aligned.
86172 */
86173@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86174
86175 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86176 {
86177- int ret;
86178+ unsigned long ret;
86179
86180 pagefault_disable();
86181 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86182@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86183 {
86184 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86185 u32 curval;
86186+ mm_segment_t oldfs;
86187
86188 /*
86189 * This will fail and we want it. Some arch implementations do
86190@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86191 * implementation, the non-functional ones will return
86192 * -ENOSYS.
86193 */
86194+ oldfs = get_fs();
86195+ set_fs(USER_DS);
86196 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86197 futex_cmpxchg_enabled = 1;
86198+ set_fs(oldfs);
86199 #endif
86200 }
86201
86202diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86203index f9f44fd..29885e4 100644
86204--- a/kernel/futex_compat.c
86205+++ b/kernel/futex_compat.c
86206@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86207 return 0;
86208 }
86209
86210-static void __user *futex_uaddr(struct robust_list __user *entry,
86211+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86212 compat_long_t futex_offset)
86213 {
86214 compat_uptr_t base = ptr_to_compat(entry);
86215diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86216index f45b75b..bfac6d5 100644
86217--- a/kernel/gcov/base.c
86218+++ b/kernel/gcov/base.c
86219@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86220 }
86221
86222 #ifdef CONFIG_MODULES
86223-static inline int within(void *addr, void *start, unsigned long size)
86224-{
86225- return ((addr >= start) && (addr < start + size));
86226-}
86227-
86228 /* Update list and generate events when modules are unloaded. */
86229 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86230 void *data)
86231@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86232
86233 /* Remove entries located in module from linked list. */
86234 while ((info = gcov_info_next(info))) {
86235- if (within(info, mod->module_core, mod->core_size)) {
86236+ if (within_module_core_rw((unsigned long)info, mod)) {
86237 gcov_info_unlink(prev, info);
86238 if (gcov_events_enabled)
86239 gcov_event(GCOV_REMOVE, info);
86240diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86241index 0909436..6037d22 100644
86242--- a/kernel/hrtimer.c
86243+++ b/kernel/hrtimer.c
86244@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86245 local_irq_restore(flags);
86246 }
86247
86248-static void run_hrtimer_softirq(struct softirq_action *h)
86249+static __latent_entropy void run_hrtimer_softirq(void)
86250 {
86251 hrtimer_peek_ahead_timers();
86252 }
86253diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86254index 55fcce6..0e4cf34 100644
86255--- a/kernel/irq_work.c
86256+++ b/kernel/irq_work.c
86257@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86258 return NOTIFY_OK;
86259 }
86260
86261-static struct notifier_block cpu_notify;
86262+static struct notifier_block cpu_notify = {
86263+ .notifier_call = irq_work_cpu_notify,
86264+ .priority = 0,
86265+};
86266
86267 static __init int irq_work_init_cpu_notifier(void)
86268 {
86269- cpu_notify.notifier_call = irq_work_cpu_notify;
86270- cpu_notify.priority = 0;
86271 register_cpu_notifier(&cpu_notify);
86272 return 0;
86273 }
86274diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86275index 9019f15..9a3c42e 100644
86276--- a/kernel/jump_label.c
86277+++ b/kernel/jump_label.c
86278@@ -14,6 +14,7 @@
86279 #include <linux/err.h>
86280 #include <linux/static_key.h>
86281 #include <linux/jump_label_ratelimit.h>
86282+#include <linux/mm.h>
86283
86284 #ifdef HAVE_JUMP_LABEL
86285
86286@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86287
86288 size = (((unsigned long)stop - (unsigned long)start)
86289 / sizeof(struct jump_entry));
86290+ pax_open_kernel();
86291 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86292+ pax_close_kernel();
86293 }
86294
86295 static void jump_label_update(struct static_key *key, int enable);
86296@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86297 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86298 struct jump_entry *iter;
86299
86300+ pax_open_kernel();
86301 for (iter = iter_start; iter < iter_stop; iter++) {
86302 if (within_module_init(iter->code, mod))
86303 iter->code = 0;
86304 }
86305+ pax_close_kernel();
86306 }
86307
86308 static int
86309diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86310index 3127ad5..159d880 100644
86311--- a/kernel/kallsyms.c
86312+++ b/kernel/kallsyms.c
86313@@ -11,6 +11,9 @@
86314 * Changed the compression method from stem compression to "table lookup"
86315 * compression (see scripts/kallsyms.c for a more complete description)
86316 */
86317+#ifdef CONFIG_GRKERNSEC_HIDESYM
86318+#define __INCLUDED_BY_HIDESYM 1
86319+#endif
86320 #include <linux/kallsyms.h>
86321 #include <linux/module.h>
86322 #include <linux/init.h>
86323@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86324
86325 static inline int is_kernel_inittext(unsigned long addr)
86326 {
86327+ if (system_state != SYSTEM_BOOTING)
86328+ return 0;
86329+
86330 if (addr >= (unsigned long)_sinittext
86331 && addr <= (unsigned long)_einittext)
86332 return 1;
86333 return 0;
86334 }
86335
86336+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86337+#ifdef CONFIG_MODULES
86338+static inline int is_module_text(unsigned long addr)
86339+{
86340+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86341+ return 1;
86342+
86343+ addr = ktla_ktva(addr);
86344+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86345+}
86346+#else
86347+static inline int is_module_text(unsigned long addr)
86348+{
86349+ return 0;
86350+}
86351+#endif
86352+#endif
86353+
86354 static inline int is_kernel_text(unsigned long addr)
86355 {
86356 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86357@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86358
86359 static inline int is_kernel(unsigned long addr)
86360 {
86361+
86362+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86363+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86364+ return 1;
86365+
86366+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86367+#else
86368 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86369+#endif
86370+
86371 return 1;
86372 return in_gate_area_no_mm(addr);
86373 }
86374
86375 static int is_ksym_addr(unsigned long addr)
86376 {
86377+
86378+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86379+ if (is_module_text(addr))
86380+ return 0;
86381+#endif
86382+
86383 if (all_var)
86384 return is_kernel(addr);
86385
86386@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86387
86388 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86389 {
86390- iter->name[0] = '\0';
86391 iter->nameoff = get_symbol_offset(new_pos);
86392 iter->pos = new_pos;
86393 }
86394@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86395 {
86396 struct kallsym_iter *iter = m->private;
86397
86398+#ifdef CONFIG_GRKERNSEC_HIDESYM
86399+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86400+ return 0;
86401+#endif
86402+
86403 /* Some debugging symbols have no name. Ignore them. */
86404 if (!iter->name[0])
86405 return 0;
86406@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86407 */
86408 type = iter->exported ? toupper(iter->type) :
86409 tolower(iter->type);
86410+
86411 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86412 type, iter->name, iter->module_name);
86413 } else
86414@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86415 struct kallsym_iter *iter;
86416 int ret;
86417
86418- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86419+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86420 if (!iter)
86421 return -ENOMEM;
86422 reset_iter(iter, 0);
86423diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86424index e30ac0f..3528cac 100644
86425--- a/kernel/kcmp.c
86426+++ b/kernel/kcmp.c
86427@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86428 struct task_struct *task1, *task2;
86429 int ret;
86430
86431+#ifdef CONFIG_GRKERNSEC
86432+ return -ENOSYS;
86433+#endif
86434+
86435 rcu_read_lock();
86436
86437 /*
86438diff --git a/kernel/kexec.c b/kernel/kexec.c
86439index 60bafbe..a120f4f 100644
86440--- a/kernel/kexec.c
86441+++ b/kernel/kexec.c
86442@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86443 unsigned long flags)
86444 {
86445 struct compat_kexec_segment in;
86446- struct kexec_segment out, __user *ksegments;
86447+ struct kexec_segment out;
86448+ struct kexec_segment __user *ksegments;
86449 unsigned long i, result;
86450
86451 /* Don't allow clients that don't understand the native
86452diff --git a/kernel/kmod.c b/kernel/kmod.c
86453index 6b375af..eaff670 100644
86454--- a/kernel/kmod.c
86455+++ b/kernel/kmod.c
86456@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86457 kfree(info->argv);
86458 }
86459
86460-static int call_modprobe(char *module_name, int wait)
86461+static int call_modprobe(char *module_name, char *module_param, int wait)
86462 {
86463 struct subprocess_info *info;
86464 static char *envp[] = {
86465@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86466 NULL
86467 };
86468
86469- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86470+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86471 if (!argv)
86472 goto out;
86473
86474@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86475 argv[1] = "-q";
86476 argv[2] = "--";
86477 argv[3] = module_name; /* check free_modprobe_argv() */
86478- argv[4] = NULL;
86479+ argv[4] = module_param;
86480+ argv[5] = NULL;
86481
86482 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86483 NULL, free_modprobe_argv, NULL);
86484@@ -129,9 +130,8 @@ out:
86485 * If module auto-loading support is disabled then this function
86486 * becomes a no-operation.
86487 */
86488-int __request_module(bool wait, const char *fmt, ...)
86489+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86490 {
86491- va_list args;
86492 char module_name[MODULE_NAME_LEN];
86493 unsigned int max_modprobes;
86494 int ret;
86495@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86496 if (!modprobe_path[0])
86497 return 0;
86498
86499- va_start(args, fmt);
86500- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86501- va_end(args);
86502+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86503 if (ret >= MODULE_NAME_LEN)
86504 return -ENAMETOOLONG;
86505
86506@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86507 if (ret)
86508 return ret;
86509
86510+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86511+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86512+ /* hack to workaround consolekit/udisks stupidity */
86513+ read_lock(&tasklist_lock);
86514+ if (!strcmp(current->comm, "mount") &&
86515+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86516+ read_unlock(&tasklist_lock);
86517+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86518+ return -EPERM;
86519+ }
86520+ read_unlock(&tasklist_lock);
86521+ }
86522+#endif
86523+
86524 /* If modprobe needs a service that is in a module, we get a recursive
86525 * loop. Limit the number of running kmod threads to max_threads/2 or
86526 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86527@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86528
86529 trace_module_request(module_name, wait, _RET_IP_);
86530
86531- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86532+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86533
86534 atomic_dec(&kmod_concurrent);
86535 return ret;
86536 }
86537+
86538+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86539+{
86540+ va_list args;
86541+ int ret;
86542+
86543+ va_start(args, fmt);
86544+ ret = ____request_module(wait, module_param, fmt, args);
86545+ va_end(args);
86546+
86547+ return ret;
86548+}
86549+
86550+int __request_module(bool wait, const char *fmt, ...)
86551+{
86552+ va_list args;
86553+ int ret;
86554+
86555+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86556+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86557+ char module_param[MODULE_NAME_LEN];
86558+
86559+ memset(module_param, 0, sizeof(module_param));
86560+
86561+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86562+
86563+ va_start(args, fmt);
86564+ ret = ____request_module(wait, module_param, fmt, args);
86565+ va_end(args);
86566+
86567+ return ret;
86568+ }
86569+#endif
86570+
86571+ va_start(args, fmt);
86572+ ret = ____request_module(wait, NULL, fmt, args);
86573+ va_end(args);
86574+
86575+ return ret;
86576+}
86577+
86578 EXPORT_SYMBOL(__request_module);
86579 #endif /* CONFIG_MODULES */
86580
86581@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86582 */
86583 set_user_nice(current, 0);
86584
86585+#ifdef CONFIG_GRKERNSEC
86586+ /* this is race-free as far as userland is concerned as we copied
86587+ out the path to be used prior to this point and are now operating
86588+ on that copy
86589+ */
86590+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86591+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86592+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86593+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86594+ retval = -EPERM;
86595+ goto fail;
86596+ }
86597+#endif
86598+
86599 retval = -ENOMEM;
86600 new = prepare_kernel_cred(current);
86601 if (!new)
86602@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86603 commit_creds(new);
86604
86605 retval = do_execve(getname_kernel(sub_info->path),
86606- (const char __user *const __user *)sub_info->argv,
86607- (const char __user *const __user *)sub_info->envp);
86608+ (const char __user *const __force_user *)sub_info->argv,
86609+ (const char __user *const __force_user *)sub_info->envp);
86610 if (!retval)
86611 return 0;
86612
86613@@ -260,6 +327,10 @@ static int call_helper(void *data)
86614
86615 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86616 {
86617+#ifdef CONFIG_GRKERNSEC
86618+ kfree(info->path);
86619+ info->path = info->origpath;
86620+#endif
86621 if (info->cleanup)
86622 (*info->cleanup)(info);
86623 kfree(info);
86624@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86625 *
86626 * Thus the __user pointer cast is valid here.
86627 */
86628- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86629+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86630
86631 /*
86632 * If ret is 0, either ____call_usermodehelper failed and the
86633@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86634 goto out;
86635
86636 INIT_WORK(&sub_info->work, __call_usermodehelper);
86637+#ifdef CONFIG_GRKERNSEC
86638+ sub_info->origpath = path;
86639+ sub_info->path = kstrdup(path, gfp_mask);
86640+#else
86641 sub_info->path = path;
86642+#endif
86643 sub_info->argv = argv;
86644 sub_info->envp = envp;
86645
86646@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86647 static int proc_cap_handler(struct ctl_table *table, int write,
86648 void __user *buffer, size_t *lenp, loff_t *ppos)
86649 {
86650- struct ctl_table t;
86651+ ctl_table_no_const t;
86652 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86653 kernel_cap_t new_cap;
86654 int err, i;
86655diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86656index ceeadfc..11c18b6 100644
86657--- a/kernel/kprobes.c
86658+++ b/kernel/kprobes.c
86659@@ -31,6 +31,9 @@
86660 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86661 * <prasanna@in.ibm.com> added function-return probes.
86662 */
86663+#ifdef CONFIG_GRKERNSEC_HIDESYM
86664+#define __INCLUDED_BY_HIDESYM 1
86665+#endif
86666 #include <linux/kprobes.h>
86667 #include <linux/hash.h>
86668 #include <linux/init.h>
86669@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86670
86671 static void *alloc_insn_page(void)
86672 {
86673- return module_alloc(PAGE_SIZE);
86674+ return module_alloc_exec(PAGE_SIZE);
86675 }
86676
86677 static void free_insn_page(void *page)
86678 {
86679- module_free(NULL, page);
86680+ module_free_exec(NULL, page);
86681 }
86682
86683 struct kprobe_insn_cache kprobe_insn_slots = {
86684@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86685 kprobe_type = "k";
86686
86687 if (sym)
86688- seq_printf(pi, "%p %s %s+0x%x %s ",
86689+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86690 p->addr, kprobe_type, sym, offset,
86691 (modname ? modname : " "));
86692 else
86693- seq_printf(pi, "%p %s %p ",
86694+ seq_printf(pi, "%pK %s %pK ",
86695 p->addr, kprobe_type, p->addr);
86696
86697 if (!pp)
86698diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86699index d945a94..0b7f45f 100644
86700--- a/kernel/ksysfs.c
86701+++ b/kernel/ksysfs.c
86702@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86703 {
86704 if (count+1 > UEVENT_HELPER_PATH_LEN)
86705 return -ENOENT;
86706+ if (!capable(CAP_SYS_ADMIN))
86707+ return -EPERM;
86708 memcpy(uevent_helper, buf, count);
86709 uevent_helper[count] = '\0';
86710 if (count && uevent_helper[count-1] == '\n')
86711@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86712 return count;
86713 }
86714
86715-static struct bin_attribute notes_attr = {
86716+static bin_attribute_no_const notes_attr __read_only = {
86717 .attr = {
86718 .name = "notes",
86719 .mode = S_IRUGO,
86720diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86721index eb8a547..321d8e1 100644
86722--- a/kernel/locking/lockdep.c
86723+++ b/kernel/locking/lockdep.c
86724@@ -597,6 +597,10 @@ static int static_obj(void *obj)
86725 end = (unsigned long) &_end,
86726 addr = (unsigned long) obj;
86727
86728+#ifdef CONFIG_PAX_KERNEXEC
86729+ start = ktla_ktva(start);
86730+#endif
86731+
86732 /*
86733 * static variable?
86734 */
86735@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86736 if (!static_obj(lock->key)) {
86737 debug_locks_off();
86738 printk("INFO: trying to register non-static key.\n");
86739+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86740 printk("the code is fine but needs lockdep annotation.\n");
86741 printk("turning off the locking correctness validator.\n");
86742 dump_stack();
86743@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86744 if (!class)
86745 return 0;
86746 }
86747- atomic_inc((atomic_t *)&class->ops);
86748+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86749 if (very_verbose(class)) {
86750 printk("\nacquire class [%p] %s", class->key, class->name);
86751 if (class->name_version > 1)
86752diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86753index ef43ac4..2720dfa 100644
86754--- a/kernel/locking/lockdep_proc.c
86755+++ b/kernel/locking/lockdep_proc.c
86756@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86757 return 0;
86758 }
86759
86760- seq_printf(m, "%p", class->key);
86761+ seq_printf(m, "%pK", class->key);
86762 #ifdef CONFIG_DEBUG_LOCKDEP
86763 seq_printf(m, " OPS:%8ld", class->ops);
86764 #endif
86765@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86766
86767 list_for_each_entry(entry, &class->locks_after, entry) {
86768 if (entry->distance == 1) {
86769- seq_printf(m, " -> [%p] ", entry->class->key);
86770+ seq_printf(m, " -> [%pK] ", entry->class->key);
86771 print_name(m, entry->class);
86772 seq_puts(m, "\n");
86773 }
86774@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86775 if (!class->key)
86776 continue;
86777
86778- seq_printf(m, "[%p] ", class->key);
86779+ seq_printf(m, "[%pK] ", class->key);
86780 print_name(m, class);
86781 seq_puts(m, "\n");
86782 }
86783@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86784 if (!i)
86785 seq_line(m, '-', 40-namelen, namelen);
86786
86787- snprintf(ip, sizeof(ip), "[<%p>]",
86788+ snprintf(ip, sizeof(ip), "[<%pK>]",
86789 (void *)class->contention_point[i]);
86790 seq_printf(m, "%40s %14lu %29s %pS\n",
86791 name, stats->contention_point[i],
86792@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86793 if (!i)
86794 seq_line(m, '-', 40-namelen, namelen);
86795
86796- snprintf(ip, sizeof(ip), "[<%p>]",
86797+ snprintf(ip, sizeof(ip), "[<%pK>]",
86798 (void *)class->contending_point[i]);
86799 seq_printf(m, "%40s %14lu %29s %pS\n",
86800 name, stats->contending_point[i],
86801diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86802index faf6f5b..dc9070a 100644
86803--- a/kernel/locking/mutex-debug.c
86804+++ b/kernel/locking/mutex-debug.c
86805@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86806 }
86807
86808 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86809- struct thread_info *ti)
86810+ struct task_struct *task)
86811 {
86812 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86813
86814 /* Mark the current thread as blocked on the lock: */
86815- ti->task->blocked_on = waiter;
86816+ task->blocked_on = waiter;
86817 }
86818
86819 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86820- struct thread_info *ti)
86821+ struct task_struct *task)
86822 {
86823 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86824- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86825- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86826- ti->task->blocked_on = NULL;
86827+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
86828+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86829+ task->blocked_on = NULL;
86830
86831 list_del_init(&waiter->list);
86832 waiter->task = NULL;
86833diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86834index 0799fd3..d06ae3b 100644
86835--- a/kernel/locking/mutex-debug.h
86836+++ b/kernel/locking/mutex-debug.h
86837@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86838 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86839 extern void debug_mutex_add_waiter(struct mutex *lock,
86840 struct mutex_waiter *waiter,
86841- struct thread_info *ti);
86842+ struct task_struct *task);
86843 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86844- struct thread_info *ti);
86845+ struct task_struct *task);
86846 extern void debug_mutex_unlock(struct mutex *lock);
86847 extern void debug_mutex_init(struct mutex *lock, const char *name,
86848 struct lock_class_key *key);
86849diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86850index 4dd6e4c..df52693 100644
86851--- a/kernel/locking/mutex.c
86852+++ b/kernel/locking/mutex.c
86853@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86854 node->locked = 1;
86855 return;
86856 }
86857- ACCESS_ONCE(prev->next) = node;
86858+ ACCESS_ONCE_RW(prev->next) = node;
86859 smp_wmb();
86860 /* Wait until the lock holder passes the lock down */
86861 while (!ACCESS_ONCE(node->locked))
86862@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86863 while (!(next = ACCESS_ONCE(node->next)))
86864 arch_mutex_cpu_relax();
86865 }
86866- ACCESS_ONCE(next->locked) = 1;
86867+ ACCESS_ONCE_RW(next->locked) = 1;
86868 smp_wmb();
86869 }
86870
86871@@ -520,7 +520,7 @@ slowpath:
86872 goto skip_wait;
86873
86874 debug_mutex_lock_common(lock, &waiter);
86875- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86876+ debug_mutex_add_waiter(lock, &waiter, task);
86877
86878 /* add waiting tasks to the end of the waitqueue (FIFO): */
86879 list_add_tail(&waiter.list, &lock->wait_list);
86880@@ -564,7 +564,7 @@ slowpath:
86881 schedule_preempt_disabled();
86882 spin_lock_mutex(&lock->wait_lock, flags);
86883 }
86884- mutex_remove_waiter(lock, &waiter, current_thread_info());
86885+ mutex_remove_waiter(lock, &waiter, task);
86886 /* set it to 0 if there are no waiters left: */
86887 if (likely(list_empty(&lock->wait_list)))
86888 atomic_set(&lock->count, 0);
86889@@ -601,7 +601,7 @@ skip_wait:
86890 return 0;
86891
86892 err:
86893- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86894+ mutex_remove_waiter(lock, &waiter, task);
86895 spin_unlock_mutex(&lock->wait_lock, flags);
86896 debug_mutex_free_waiter(&waiter);
86897 mutex_release(&lock->dep_map, 1, ip);
86898diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86899index 1d96dd0..994ff19 100644
86900--- a/kernel/locking/rtmutex-tester.c
86901+++ b/kernel/locking/rtmutex-tester.c
86902@@ -22,7 +22,7 @@
86903 #define MAX_RT_TEST_MUTEXES 8
86904
86905 static spinlock_t rttest_lock;
86906-static atomic_t rttest_event;
86907+static atomic_unchecked_t rttest_event;
86908
86909 struct test_thread_data {
86910 int opcode;
86911@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86912
86913 case RTTEST_LOCKCONT:
86914 td->mutexes[td->opdata] = 1;
86915- td->event = atomic_add_return(1, &rttest_event);
86916+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86917 return 0;
86918
86919 case RTTEST_RESET:
86920@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86921 return 0;
86922
86923 case RTTEST_RESETEVENT:
86924- atomic_set(&rttest_event, 0);
86925+ atomic_set_unchecked(&rttest_event, 0);
86926 return 0;
86927
86928 default:
86929@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86930 return ret;
86931
86932 td->mutexes[id] = 1;
86933- td->event = atomic_add_return(1, &rttest_event);
86934+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86935 rt_mutex_lock(&mutexes[id]);
86936- td->event = atomic_add_return(1, &rttest_event);
86937+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86938 td->mutexes[id] = 4;
86939 return 0;
86940
86941@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86942 return ret;
86943
86944 td->mutexes[id] = 1;
86945- td->event = atomic_add_return(1, &rttest_event);
86946+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86947 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86948- td->event = atomic_add_return(1, &rttest_event);
86949+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86950 td->mutexes[id] = ret ? 0 : 4;
86951 return ret ? -EINTR : 0;
86952
86953@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86954 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86955 return ret;
86956
86957- td->event = atomic_add_return(1, &rttest_event);
86958+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86959 rt_mutex_unlock(&mutexes[id]);
86960- td->event = atomic_add_return(1, &rttest_event);
86961+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86962 td->mutexes[id] = 0;
86963 return 0;
86964
86965@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86966 break;
86967
86968 td->mutexes[dat] = 2;
86969- td->event = atomic_add_return(1, &rttest_event);
86970+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86971 break;
86972
86973 default:
86974@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86975 return;
86976
86977 td->mutexes[dat] = 3;
86978- td->event = atomic_add_return(1, &rttest_event);
86979+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86980 break;
86981
86982 case RTTEST_LOCKNOWAIT:
86983@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86984 return;
86985
86986 td->mutexes[dat] = 1;
86987- td->event = atomic_add_return(1, &rttest_event);
86988+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86989 return;
86990
86991 default:
86992diff --git a/kernel/module.c b/kernel/module.c
86993index d24fcf2..2af3fd9 100644
86994--- a/kernel/module.c
86995+++ b/kernel/module.c
86996@@ -61,6 +61,7 @@
86997 #include <linux/pfn.h>
86998 #include <linux/bsearch.h>
86999 #include <linux/fips.h>
87000+#include <linux/grsecurity.h>
87001 #include <uapi/linux/module.h>
87002 #include "module-internal.h"
87003
87004@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87005
87006 /* Bounds of module allocation, for speeding __module_address.
87007 * Protected by module_mutex. */
87008-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87009+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87010+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87011
87012 int register_module_notifier(struct notifier_block * nb)
87013 {
87014@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87015 return true;
87016
87017 list_for_each_entry_rcu(mod, &modules, list) {
87018- struct symsearch arr[] = {
87019+ struct symsearch modarr[] = {
87020 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87021 NOT_GPL_ONLY, false },
87022 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87023@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87024 if (mod->state == MODULE_STATE_UNFORMED)
87025 continue;
87026
87027- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87028+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87029 return true;
87030 }
87031 return false;
87032@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87033 if (!pcpusec->sh_size)
87034 return 0;
87035
87036- if (align > PAGE_SIZE) {
87037+ if (align-1 >= PAGE_SIZE) {
87038 pr_warn("%s: per-cpu alignment %li > %li\n",
87039 mod->name, align, PAGE_SIZE);
87040 align = PAGE_SIZE;
87041@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87042 static ssize_t show_coresize(struct module_attribute *mattr,
87043 struct module_kobject *mk, char *buffer)
87044 {
87045- return sprintf(buffer, "%u\n", mk->mod->core_size);
87046+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87047 }
87048
87049 static struct module_attribute modinfo_coresize =
87050@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87051 static ssize_t show_initsize(struct module_attribute *mattr,
87052 struct module_kobject *mk, char *buffer)
87053 {
87054- return sprintf(buffer, "%u\n", mk->mod->init_size);
87055+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87056 }
87057
87058 static struct module_attribute modinfo_initsize =
87059@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87060 goto bad_version;
87061 }
87062
87063+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87064+ /*
87065+ * avoid potentially printing jibberish on attempted load
87066+ * of a module randomized with a different seed
87067+ */
87068+ pr_warn("no symbol version for %s\n", symname);
87069+#else
87070 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87071+#endif
87072 return 0;
87073
87074 bad_version:
87075+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87076+ /*
87077+ * avoid potentially printing jibberish on attempted load
87078+ * of a module randomized with a different seed
87079+ */
87080+ printk("attempted module disagrees about version of symbol %s\n",
87081+ symname);
87082+#else
87083 printk("%s: disagrees about version of symbol %s\n",
87084 mod->name, symname);
87085+#endif
87086 return 0;
87087 }
87088
87089@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87090 */
87091 #ifdef CONFIG_SYSFS
87092
87093-#ifdef CONFIG_KALLSYMS
87094+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87095 static inline bool sect_empty(const Elf_Shdr *sect)
87096 {
87097 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87098@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87099 {
87100 unsigned int notes, loaded, i;
87101 struct module_notes_attrs *notes_attrs;
87102- struct bin_attribute *nattr;
87103+ bin_attribute_no_const *nattr;
87104
87105 /* failed to create section attributes, so can't create notes */
87106 if (!mod->sect_attrs)
87107@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87108 static int module_add_modinfo_attrs(struct module *mod)
87109 {
87110 struct module_attribute *attr;
87111- struct module_attribute *temp_attr;
87112+ module_attribute_no_const *temp_attr;
87113 int error = 0;
87114 int i;
87115
87116@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87117
87118 static void unset_module_core_ro_nx(struct module *mod)
87119 {
87120- set_page_attributes(mod->module_core + mod->core_text_size,
87121- mod->module_core + mod->core_size,
87122+ set_page_attributes(mod->module_core_rw,
87123+ mod->module_core_rw + mod->core_size_rw,
87124 set_memory_x);
87125- set_page_attributes(mod->module_core,
87126- mod->module_core + mod->core_ro_size,
87127+ set_page_attributes(mod->module_core_rx,
87128+ mod->module_core_rx + mod->core_size_rx,
87129 set_memory_rw);
87130 }
87131
87132 static void unset_module_init_ro_nx(struct module *mod)
87133 {
87134- set_page_attributes(mod->module_init + mod->init_text_size,
87135- mod->module_init + mod->init_size,
87136+ set_page_attributes(mod->module_init_rw,
87137+ mod->module_init_rw + mod->init_size_rw,
87138 set_memory_x);
87139- set_page_attributes(mod->module_init,
87140- mod->module_init + mod->init_ro_size,
87141+ set_page_attributes(mod->module_init_rx,
87142+ mod->module_init_rx + mod->init_size_rx,
87143 set_memory_rw);
87144 }
87145
87146@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87147 list_for_each_entry_rcu(mod, &modules, list) {
87148 if (mod->state == MODULE_STATE_UNFORMED)
87149 continue;
87150- if ((mod->module_core) && (mod->core_text_size)) {
87151- set_page_attributes(mod->module_core,
87152- mod->module_core + mod->core_text_size,
87153+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87154+ set_page_attributes(mod->module_core_rx,
87155+ mod->module_core_rx + mod->core_size_rx,
87156 set_memory_rw);
87157 }
87158- if ((mod->module_init) && (mod->init_text_size)) {
87159- set_page_attributes(mod->module_init,
87160- mod->module_init + mod->init_text_size,
87161+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87162+ set_page_attributes(mod->module_init_rx,
87163+ mod->module_init_rx + mod->init_size_rx,
87164 set_memory_rw);
87165 }
87166 }
87167@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87168 list_for_each_entry_rcu(mod, &modules, list) {
87169 if (mod->state == MODULE_STATE_UNFORMED)
87170 continue;
87171- if ((mod->module_core) && (mod->core_text_size)) {
87172- set_page_attributes(mod->module_core,
87173- mod->module_core + mod->core_text_size,
87174+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87175+ set_page_attributes(mod->module_core_rx,
87176+ mod->module_core_rx + mod->core_size_rx,
87177 set_memory_ro);
87178 }
87179- if ((mod->module_init) && (mod->init_text_size)) {
87180- set_page_attributes(mod->module_init,
87181- mod->module_init + mod->init_text_size,
87182+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87183+ set_page_attributes(mod->module_init_rx,
87184+ mod->module_init_rx + mod->init_size_rx,
87185 set_memory_ro);
87186 }
87187 }
87188@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87189
87190 /* This may be NULL, but that's OK */
87191 unset_module_init_ro_nx(mod);
87192- module_free(mod, mod->module_init);
87193+ module_free(mod, mod->module_init_rw);
87194+ module_free_exec(mod, mod->module_init_rx);
87195 kfree(mod->args);
87196 percpu_modfree(mod);
87197
87198 /* Free lock-classes: */
87199- lockdep_free_key_range(mod->module_core, mod->core_size);
87200+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87201+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87202
87203 /* Finally, free the core (containing the module structure) */
87204 unset_module_core_ro_nx(mod);
87205- module_free(mod, mod->module_core);
87206+ module_free_exec(mod, mod->module_core_rx);
87207+ module_free(mod, mod->module_core_rw);
87208
87209 #ifdef CONFIG_MPU
87210 update_protections(current->mm);
87211@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87212 int ret = 0;
87213 const struct kernel_symbol *ksym;
87214
87215+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87216+ int is_fs_load = 0;
87217+ int register_filesystem_found = 0;
87218+ char *p;
87219+
87220+ p = strstr(mod->args, "grsec_modharden_fs");
87221+ if (p) {
87222+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87223+ /* copy \0 as well */
87224+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87225+ is_fs_load = 1;
87226+ }
87227+#endif
87228+
87229 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87230 const char *name = info->strtab + sym[i].st_name;
87231
87232+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87233+ /* it's a real shame this will never get ripped and copied
87234+ upstream! ;(
87235+ */
87236+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87237+ register_filesystem_found = 1;
87238+#endif
87239+
87240 switch (sym[i].st_shndx) {
87241 case SHN_COMMON:
87242 /* We compiled with -fno-common. These are not
87243@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87244 ksym = resolve_symbol_wait(mod, info, name);
87245 /* Ok if resolved. */
87246 if (ksym && !IS_ERR(ksym)) {
87247+ pax_open_kernel();
87248 sym[i].st_value = ksym->value;
87249+ pax_close_kernel();
87250 break;
87251 }
87252
87253@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87254 secbase = (unsigned long)mod_percpu(mod);
87255 else
87256 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87257+ pax_open_kernel();
87258 sym[i].st_value += secbase;
87259+ pax_close_kernel();
87260 break;
87261 }
87262 }
87263
87264+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87265+ if (is_fs_load && !register_filesystem_found) {
87266+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87267+ ret = -EPERM;
87268+ }
87269+#endif
87270+
87271 return ret;
87272 }
87273
87274@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87275 || s->sh_entsize != ~0UL
87276 || strstarts(sname, ".init"))
87277 continue;
87278- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87279+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87280+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87281+ else
87282+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87283 pr_debug("\t%s\n", sname);
87284 }
87285- switch (m) {
87286- case 0: /* executable */
87287- mod->core_size = debug_align(mod->core_size);
87288- mod->core_text_size = mod->core_size;
87289- break;
87290- case 1: /* RO: text and ro-data */
87291- mod->core_size = debug_align(mod->core_size);
87292- mod->core_ro_size = mod->core_size;
87293- break;
87294- case 3: /* whole core */
87295- mod->core_size = debug_align(mod->core_size);
87296- break;
87297- }
87298 }
87299
87300 pr_debug("Init section allocation order:\n");
87301@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87302 || s->sh_entsize != ~0UL
87303 || !strstarts(sname, ".init"))
87304 continue;
87305- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87306- | INIT_OFFSET_MASK);
87307+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87308+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87309+ else
87310+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87311+ s->sh_entsize |= INIT_OFFSET_MASK;
87312 pr_debug("\t%s\n", sname);
87313 }
87314- switch (m) {
87315- case 0: /* executable */
87316- mod->init_size = debug_align(mod->init_size);
87317- mod->init_text_size = mod->init_size;
87318- break;
87319- case 1: /* RO: text and ro-data */
87320- mod->init_size = debug_align(mod->init_size);
87321- mod->init_ro_size = mod->init_size;
87322- break;
87323- case 3: /* whole init */
87324- mod->init_size = debug_align(mod->init_size);
87325- break;
87326- }
87327 }
87328 }
87329
87330@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87331
87332 /* Put symbol section at end of init part of module. */
87333 symsect->sh_flags |= SHF_ALLOC;
87334- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87335+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87336 info->index.sym) | INIT_OFFSET_MASK;
87337 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87338
87339@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87340 }
87341
87342 /* Append room for core symbols at end of core part. */
87343- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87344- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87345- mod->core_size += strtab_size;
87346+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87347+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87348+ mod->core_size_rx += strtab_size;
87349
87350 /* Put string table section at end of init part of module. */
87351 strsect->sh_flags |= SHF_ALLOC;
87352- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87353+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87354 info->index.str) | INIT_OFFSET_MASK;
87355 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87356 }
87357@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87358 /* Make sure we get permanent strtab: don't use info->strtab. */
87359 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87360
87361+ pax_open_kernel();
87362+
87363 /* Set types up while we still have access to sections. */
87364 for (i = 0; i < mod->num_symtab; i++)
87365 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87366
87367- mod->core_symtab = dst = mod->module_core + info->symoffs;
87368- mod->core_strtab = s = mod->module_core + info->stroffs;
87369+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87370+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87371 src = mod->symtab;
87372 for (ndst = i = 0; i < mod->num_symtab; i++) {
87373 if (i == 0 ||
87374@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87375 }
87376 }
87377 mod->core_num_syms = ndst;
87378+
87379+ pax_close_kernel();
87380 }
87381 #else
87382 static inline void layout_symtab(struct module *mod, struct load_info *info)
87383@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87384 return vmalloc_exec(size);
87385 }
87386
87387-static void *module_alloc_update_bounds(unsigned long size)
87388+static void *module_alloc_update_bounds_rw(unsigned long size)
87389 {
87390 void *ret = module_alloc(size);
87391
87392 if (ret) {
87393 mutex_lock(&module_mutex);
87394 /* Update module bounds. */
87395- if ((unsigned long)ret < module_addr_min)
87396- module_addr_min = (unsigned long)ret;
87397- if ((unsigned long)ret + size > module_addr_max)
87398- module_addr_max = (unsigned long)ret + size;
87399+ if ((unsigned long)ret < module_addr_min_rw)
87400+ module_addr_min_rw = (unsigned long)ret;
87401+ if ((unsigned long)ret + size > module_addr_max_rw)
87402+ module_addr_max_rw = (unsigned long)ret + size;
87403+ mutex_unlock(&module_mutex);
87404+ }
87405+ return ret;
87406+}
87407+
87408+static void *module_alloc_update_bounds_rx(unsigned long size)
87409+{
87410+ void *ret = module_alloc_exec(size);
87411+
87412+ if (ret) {
87413+ mutex_lock(&module_mutex);
87414+ /* Update module bounds. */
87415+ if ((unsigned long)ret < module_addr_min_rx)
87416+ module_addr_min_rx = (unsigned long)ret;
87417+ if ((unsigned long)ret + size > module_addr_max_rx)
87418+ module_addr_max_rx = (unsigned long)ret + size;
87419 mutex_unlock(&module_mutex);
87420 }
87421 return ret;
87422@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87423 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87424
87425 if (info->index.sym == 0) {
87426+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87427+ /*
87428+ * avoid potentially printing jibberish on attempted load
87429+ * of a module randomized with a different seed
87430+ */
87431+ pr_warn("module has no symbols (stripped?)\n");
87432+#else
87433 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87434+#endif
87435 return ERR_PTR(-ENOEXEC);
87436 }
87437
87438@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87439 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87440 {
87441 const char *modmagic = get_modinfo(info, "vermagic");
87442+ const char *license = get_modinfo(info, "license");
87443 int err;
87444
87445+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87446+ if (!license || !license_is_gpl_compatible(license))
87447+ return -ENOEXEC;
87448+#endif
87449+
87450 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87451 modmagic = NULL;
87452
87453@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87454 }
87455
87456 /* Set up license info based on the info section */
87457- set_license(mod, get_modinfo(info, "license"));
87458+ set_license(mod, license);
87459
87460 return 0;
87461 }
87462@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87463 void *ptr;
87464
87465 /* Do the allocs. */
87466- ptr = module_alloc_update_bounds(mod->core_size);
87467+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87468 /*
87469 * The pointer to this block is stored in the module structure
87470 * which is inside the block. Just mark it as not being a
87471@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87472 if (!ptr)
87473 return -ENOMEM;
87474
87475- memset(ptr, 0, mod->core_size);
87476- mod->module_core = ptr;
87477+ memset(ptr, 0, mod->core_size_rw);
87478+ mod->module_core_rw = ptr;
87479
87480- if (mod->init_size) {
87481- ptr = module_alloc_update_bounds(mod->init_size);
87482+ if (mod->init_size_rw) {
87483+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87484 /*
87485 * The pointer to this block is stored in the module structure
87486 * which is inside the block. This block doesn't need to be
87487@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87488 */
87489 kmemleak_ignore(ptr);
87490 if (!ptr) {
87491- module_free(mod, mod->module_core);
87492+ module_free(mod, mod->module_core_rw);
87493 return -ENOMEM;
87494 }
87495- memset(ptr, 0, mod->init_size);
87496- mod->module_init = ptr;
87497+ memset(ptr, 0, mod->init_size_rw);
87498+ mod->module_init_rw = ptr;
87499 } else
87500- mod->module_init = NULL;
87501+ mod->module_init_rw = NULL;
87502+
87503+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87504+ kmemleak_not_leak(ptr);
87505+ if (!ptr) {
87506+ if (mod->module_init_rw)
87507+ module_free(mod, mod->module_init_rw);
87508+ module_free(mod, mod->module_core_rw);
87509+ return -ENOMEM;
87510+ }
87511+
87512+ pax_open_kernel();
87513+ memset(ptr, 0, mod->core_size_rx);
87514+ pax_close_kernel();
87515+ mod->module_core_rx = ptr;
87516+
87517+ if (mod->init_size_rx) {
87518+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87519+ kmemleak_ignore(ptr);
87520+ if (!ptr && mod->init_size_rx) {
87521+ module_free_exec(mod, mod->module_core_rx);
87522+ if (mod->module_init_rw)
87523+ module_free(mod, mod->module_init_rw);
87524+ module_free(mod, mod->module_core_rw);
87525+ return -ENOMEM;
87526+ }
87527+
87528+ pax_open_kernel();
87529+ memset(ptr, 0, mod->init_size_rx);
87530+ pax_close_kernel();
87531+ mod->module_init_rx = ptr;
87532+ } else
87533+ mod->module_init_rx = NULL;
87534
87535 /* Transfer each section which specifies SHF_ALLOC */
87536 pr_debug("final section addresses:\n");
87537@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87538 if (!(shdr->sh_flags & SHF_ALLOC))
87539 continue;
87540
87541- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87542- dest = mod->module_init
87543- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87544- else
87545- dest = mod->module_core + shdr->sh_entsize;
87546+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87547+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87548+ dest = mod->module_init_rw
87549+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87550+ else
87551+ dest = mod->module_init_rx
87552+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87553+ } else {
87554+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87555+ dest = mod->module_core_rw + shdr->sh_entsize;
87556+ else
87557+ dest = mod->module_core_rx + shdr->sh_entsize;
87558+ }
87559+
87560+ if (shdr->sh_type != SHT_NOBITS) {
87561+
87562+#ifdef CONFIG_PAX_KERNEXEC
87563+#ifdef CONFIG_X86_64
87564+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87565+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87566+#endif
87567+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87568+ pax_open_kernel();
87569+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87570+ pax_close_kernel();
87571+ } else
87572+#endif
87573
87574- if (shdr->sh_type != SHT_NOBITS)
87575 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87576+ }
87577 /* Update sh_addr to point to copy in image. */
87578- shdr->sh_addr = (unsigned long)dest;
87579+
87580+#ifdef CONFIG_PAX_KERNEXEC
87581+ if (shdr->sh_flags & SHF_EXECINSTR)
87582+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87583+ else
87584+#endif
87585+
87586+ shdr->sh_addr = (unsigned long)dest;
87587 pr_debug("\t0x%lx %s\n",
87588 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87589 }
87590@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87591 * Do it before processing of module parameters, so the module
87592 * can provide parameter accessor functions of its own.
87593 */
87594- if (mod->module_init)
87595- flush_icache_range((unsigned long)mod->module_init,
87596- (unsigned long)mod->module_init
87597- + mod->init_size);
87598- flush_icache_range((unsigned long)mod->module_core,
87599- (unsigned long)mod->module_core + mod->core_size);
87600+ if (mod->module_init_rx)
87601+ flush_icache_range((unsigned long)mod->module_init_rx,
87602+ (unsigned long)mod->module_init_rx
87603+ + mod->init_size_rx);
87604+ flush_icache_range((unsigned long)mod->module_core_rx,
87605+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87606
87607 set_fs(old_fs);
87608 }
87609@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87610 static void module_deallocate(struct module *mod, struct load_info *info)
87611 {
87612 percpu_modfree(mod);
87613- module_free(mod, mod->module_init);
87614- module_free(mod, mod->module_core);
87615+ module_free_exec(mod, mod->module_init_rx);
87616+ module_free_exec(mod, mod->module_core_rx);
87617+ module_free(mod, mod->module_init_rw);
87618+ module_free(mod, mod->module_core_rw);
87619 }
87620
87621 int __weak module_finalize(const Elf_Ehdr *hdr,
87622@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87623 static int post_relocation(struct module *mod, const struct load_info *info)
87624 {
87625 /* Sort exception table now relocations are done. */
87626+ pax_open_kernel();
87627 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87628+ pax_close_kernel();
87629
87630 /* Copy relocated percpu area over. */
87631 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87632@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87633 MODULE_STATE_COMING, mod);
87634
87635 /* Set RO and NX regions for core */
87636- set_section_ro_nx(mod->module_core,
87637- mod->core_text_size,
87638- mod->core_ro_size,
87639- mod->core_size);
87640+ set_section_ro_nx(mod->module_core_rx,
87641+ mod->core_size_rx,
87642+ mod->core_size_rx,
87643+ mod->core_size_rx);
87644
87645 /* Set RO and NX regions for init */
87646- set_section_ro_nx(mod->module_init,
87647- mod->init_text_size,
87648- mod->init_ro_size,
87649- mod->init_size);
87650+ set_section_ro_nx(mod->module_init_rx,
87651+ mod->init_size_rx,
87652+ mod->init_size_rx,
87653+ mod->init_size_rx);
87654
87655 do_mod_ctors(mod);
87656 /* Start the module */
87657@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87658 mod->strtab = mod->core_strtab;
87659 #endif
87660 unset_module_init_ro_nx(mod);
87661- module_free(mod, mod->module_init);
87662- mod->module_init = NULL;
87663- mod->init_size = 0;
87664- mod->init_ro_size = 0;
87665- mod->init_text_size = 0;
87666+ module_free(mod, mod->module_init_rw);
87667+ module_free_exec(mod, mod->module_init_rx);
87668+ mod->module_init_rw = NULL;
87669+ mod->module_init_rx = NULL;
87670+ mod->init_size_rw = 0;
87671+ mod->init_size_rx = 0;
87672 mutex_unlock(&module_mutex);
87673 wake_up_all(&module_wq);
87674
87675@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87676 if (err)
87677 goto free_unload;
87678
87679+ /* Now copy in args */
87680+ mod->args = strndup_user(uargs, ~0UL >> 1);
87681+ if (IS_ERR(mod->args)) {
87682+ err = PTR_ERR(mod->args);
87683+ goto free_unload;
87684+ }
87685+
87686 /* Set up MODINFO_ATTR fields */
87687 setup_modinfo(mod, info);
87688
87689+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87690+ {
87691+ char *p, *p2;
87692+
87693+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87694+ 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);
87695+ err = -EPERM;
87696+ goto free_modinfo;
87697+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87698+ p += sizeof("grsec_modharden_normal") - 1;
87699+ p2 = strstr(p, "_");
87700+ if (p2) {
87701+ *p2 = '\0';
87702+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87703+ *p2 = '_';
87704+ }
87705+ err = -EPERM;
87706+ goto free_modinfo;
87707+ }
87708+ }
87709+#endif
87710+
87711 /* Fix up syms, so that st_value is a pointer to location. */
87712 err = simplify_symbols(mod, info);
87713 if (err < 0)
87714@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87715
87716 flush_module_icache(mod);
87717
87718- /* Now copy in args */
87719- mod->args = strndup_user(uargs, ~0UL >> 1);
87720- if (IS_ERR(mod->args)) {
87721- err = PTR_ERR(mod->args);
87722- goto free_arch_cleanup;
87723- }
87724-
87725 dynamic_debug_setup(info->debug, info->num_debug);
87726
87727 /* Finally it's fully formed, ready to start executing. */
87728@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87729 ddebug_cleanup:
87730 dynamic_debug_remove(info->debug);
87731 synchronize_sched();
87732- kfree(mod->args);
87733- free_arch_cleanup:
87734 module_arch_cleanup(mod);
87735 free_modinfo:
87736 free_modinfo(mod);
87737+ kfree(mod->args);
87738 free_unload:
87739 module_unload_free(mod);
87740 unlink_mod:
87741@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87742 unsigned long nextval;
87743
87744 /* At worse, next value is at end of module */
87745- if (within_module_init(addr, mod))
87746- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87747+ if (within_module_init_rx(addr, mod))
87748+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87749+ else if (within_module_init_rw(addr, mod))
87750+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87751+ else if (within_module_core_rx(addr, mod))
87752+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87753+ else if (within_module_core_rw(addr, mod))
87754+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87755 else
87756- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87757+ return NULL;
87758
87759 /* Scan for closest preceding symbol, and next symbol. (ELF
87760 starts real symbols at 1). */
87761@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87762 return 0;
87763
87764 seq_printf(m, "%s %u",
87765- mod->name, mod->init_size + mod->core_size);
87766+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87767 print_unload_info(m, mod);
87768
87769 /* Informative for users. */
87770@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87771 mod->state == MODULE_STATE_COMING ? "Loading":
87772 "Live");
87773 /* Used by oprofile and other similar tools. */
87774- seq_printf(m, " 0x%pK", mod->module_core);
87775+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87776
87777 /* Taints info */
87778 if (mod->taints)
87779@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
87780
87781 static int __init proc_modules_init(void)
87782 {
87783+#ifndef CONFIG_GRKERNSEC_HIDESYM
87784+#ifdef CONFIG_GRKERNSEC_PROC_USER
87785+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87786+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87787+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87788+#else
87789 proc_create("modules", 0, NULL, &proc_modules_operations);
87790+#endif
87791+#else
87792+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87793+#endif
87794 return 0;
87795 }
87796 module_init(proc_modules_init);
87797@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
87798 {
87799 struct module *mod;
87800
87801- if (addr < module_addr_min || addr > module_addr_max)
87802+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87803+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
87804 return NULL;
87805
87806 list_for_each_entry_rcu(mod, &modules, list) {
87807 if (mod->state == MODULE_STATE_UNFORMED)
87808 continue;
87809- if (within_module_core(addr, mod)
87810- || within_module_init(addr, mod))
87811+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
87812 return mod;
87813 }
87814 return NULL;
87815@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
87816 */
87817 struct module *__module_text_address(unsigned long addr)
87818 {
87819- struct module *mod = __module_address(addr);
87820+ struct module *mod;
87821+
87822+#ifdef CONFIG_X86_32
87823+ addr = ktla_ktva(addr);
87824+#endif
87825+
87826+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87827+ return NULL;
87828+
87829+ mod = __module_address(addr);
87830+
87831 if (mod) {
87832 /* Make sure it's within the text section. */
87833- if (!within(addr, mod->module_init, mod->init_text_size)
87834- && !within(addr, mod->module_core, mod->core_text_size))
87835+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87836 mod = NULL;
87837 }
87838 return mod;
87839diff --git a/kernel/notifier.c b/kernel/notifier.c
87840index 2d5cc4c..d9ea600 100644
87841--- a/kernel/notifier.c
87842+++ b/kernel/notifier.c
87843@@ -5,6 +5,7 @@
87844 #include <linux/rcupdate.h>
87845 #include <linux/vmalloc.h>
87846 #include <linux/reboot.h>
87847+#include <linux/mm.h>
87848
87849 /*
87850 * Notifier list for kernel code which wants to be called
87851@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87852 while ((*nl) != NULL) {
87853 if (n->priority > (*nl)->priority)
87854 break;
87855- nl = &((*nl)->next);
87856+ nl = (struct notifier_block **)&((*nl)->next);
87857 }
87858- n->next = *nl;
87859+ pax_open_kernel();
87860+ *(const void **)&n->next = *nl;
87861 rcu_assign_pointer(*nl, n);
87862+ pax_close_kernel();
87863 return 0;
87864 }
87865
87866@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87867 return 0;
87868 if (n->priority > (*nl)->priority)
87869 break;
87870- nl = &((*nl)->next);
87871+ nl = (struct notifier_block **)&((*nl)->next);
87872 }
87873- n->next = *nl;
87874+ pax_open_kernel();
87875+ *(const void **)&n->next = *nl;
87876 rcu_assign_pointer(*nl, n);
87877+ pax_close_kernel();
87878 return 0;
87879 }
87880
87881@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87882 {
87883 while ((*nl) != NULL) {
87884 if ((*nl) == n) {
87885+ pax_open_kernel();
87886 rcu_assign_pointer(*nl, n->next);
87887+ pax_close_kernel();
87888 return 0;
87889 }
87890- nl = &((*nl)->next);
87891+ nl = (struct notifier_block **)&((*nl)->next);
87892 }
87893 return -ENOENT;
87894 }
87895diff --git a/kernel/padata.c b/kernel/padata.c
87896index 161402f..598814c 100644
87897--- a/kernel/padata.c
87898+++ b/kernel/padata.c
87899@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87900 * seq_nr mod. number of cpus in use.
87901 */
87902
87903- seq_nr = atomic_inc_return(&pd->seq_nr);
87904+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87905 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87906
87907 return padata_index_to_cpu(pd, cpu_index);
87908@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87909 padata_init_pqueues(pd);
87910 padata_init_squeues(pd);
87911 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87912- atomic_set(&pd->seq_nr, -1);
87913+ atomic_set_unchecked(&pd->seq_nr, -1);
87914 atomic_set(&pd->reorder_objects, 0);
87915 atomic_set(&pd->refcnt, 0);
87916 pd->pinst = pinst;
87917diff --git a/kernel/panic.c b/kernel/panic.c
87918index 6d63003..486a109 100644
87919--- a/kernel/panic.c
87920+++ b/kernel/panic.c
87921@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87922 /*
87923 * Stop ourself in panic -- architecture code may override this
87924 */
87925-void __weak panic_smp_self_stop(void)
87926+void __weak __noreturn panic_smp_self_stop(void)
87927 {
87928 while (1)
87929 cpu_relax();
87930@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87931 disable_trace_on_warning();
87932
87933 pr_warn("------------[ cut here ]------------\n");
87934- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87935+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87936 raw_smp_processor_id(), current->pid, file, line, caller);
87937
87938 if (args)
87939@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87940 */
87941 void __stack_chk_fail(void)
87942 {
87943- panic("stack-protector: Kernel stack is corrupted in: %p\n",
87944+ dump_stack();
87945+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87946 __builtin_return_address(0));
87947 }
87948 EXPORT_SYMBOL(__stack_chk_fail);
87949diff --git a/kernel/pid.c b/kernel/pid.c
87950index 9b9a266..c20ef80 100644
87951--- a/kernel/pid.c
87952+++ b/kernel/pid.c
87953@@ -33,6 +33,7 @@
87954 #include <linux/rculist.h>
87955 #include <linux/bootmem.h>
87956 #include <linux/hash.h>
87957+#include <linux/security.h>
87958 #include <linux/pid_namespace.h>
87959 #include <linux/init_task.h>
87960 #include <linux/syscalls.h>
87961@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87962
87963 int pid_max = PID_MAX_DEFAULT;
87964
87965-#define RESERVED_PIDS 300
87966+#define RESERVED_PIDS 500
87967
87968 int pid_max_min = RESERVED_PIDS + 1;
87969 int pid_max_max = PID_MAX_LIMIT;
87970@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87971 */
87972 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87973 {
87974+ struct task_struct *task;
87975+
87976 rcu_lockdep_assert(rcu_read_lock_held(),
87977 "find_task_by_pid_ns() needs rcu_read_lock()"
87978 " protection");
87979- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87980+
87981+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87982+
87983+ if (gr_pid_is_chrooted(task))
87984+ return NULL;
87985+
87986+ return task;
87987 }
87988
87989 struct task_struct *find_task_by_vpid(pid_t vnr)
87990@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87991 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87992 }
87993
87994+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87995+{
87996+ rcu_lockdep_assert(rcu_read_lock_held(),
87997+ "find_task_by_pid_ns() needs rcu_read_lock()"
87998+ " protection");
87999+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88000+}
88001+
88002 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88003 {
88004 struct pid *pid;
88005diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88006index db95d8e..a0ca23f 100644
88007--- a/kernel/pid_namespace.c
88008+++ b/kernel/pid_namespace.c
88009@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88010 void __user *buffer, size_t *lenp, loff_t *ppos)
88011 {
88012 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88013- struct ctl_table tmp = *table;
88014+ ctl_table_no_const tmp = *table;
88015
88016 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88017 return -EPERM;
88018diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88019index 3b89464..5e38379 100644
88020--- a/kernel/posix-cpu-timers.c
88021+++ b/kernel/posix-cpu-timers.c
88022@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88023
88024 static __init int init_posix_cpu_timers(void)
88025 {
88026- struct k_clock process = {
88027+ static struct k_clock process = {
88028 .clock_getres = process_cpu_clock_getres,
88029 .clock_get = process_cpu_clock_get,
88030 .timer_create = process_cpu_timer_create,
88031 .nsleep = process_cpu_nsleep,
88032 .nsleep_restart = process_cpu_nsleep_restart,
88033 };
88034- struct k_clock thread = {
88035+ static struct k_clock thread = {
88036 .clock_getres = thread_cpu_clock_getres,
88037 .clock_get = thread_cpu_clock_get,
88038 .timer_create = thread_cpu_timer_create,
88039diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88040index 424c2d4..679242f 100644
88041--- a/kernel/posix-timers.c
88042+++ b/kernel/posix-timers.c
88043@@ -43,6 +43,7 @@
88044 #include <linux/hash.h>
88045 #include <linux/posix-clock.h>
88046 #include <linux/posix-timers.h>
88047+#include <linux/grsecurity.h>
88048 #include <linux/syscalls.h>
88049 #include <linux/wait.h>
88050 #include <linux/workqueue.h>
88051@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88052 * which we beg off on and pass to do_sys_settimeofday().
88053 */
88054
88055-static struct k_clock posix_clocks[MAX_CLOCKS];
88056+static struct k_clock *posix_clocks[MAX_CLOCKS];
88057
88058 /*
88059 * These ones are defined below.
88060@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88061 */
88062 static __init int init_posix_timers(void)
88063 {
88064- struct k_clock clock_realtime = {
88065+ static struct k_clock clock_realtime = {
88066 .clock_getres = hrtimer_get_res,
88067 .clock_get = posix_clock_realtime_get,
88068 .clock_set = posix_clock_realtime_set,
88069@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88070 .timer_get = common_timer_get,
88071 .timer_del = common_timer_del,
88072 };
88073- struct k_clock clock_monotonic = {
88074+ static struct k_clock clock_monotonic = {
88075 .clock_getres = hrtimer_get_res,
88076 .clock_get = posix_ktime_get_ts,
88077 .nsleep = common_nsleep,
88078@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88079 .timer_get = common_timer_get,
88080 .timer_del = common_timer_del,
88081 };
88082- struct k_clock clock_monotonic_raw = {
88083+ static struct k_clock clock_monotonic_raw = {
88084 .clock_getres = hrtimer_get_res,
88085 .clock_get = posix_get_monotonic_raw,
88086 };
88087- struct k_clock clock_realtime_coarse = {
88088+ static struct k_clock clock_realtime_coarse = {
88089 .clock_getres = posix_get_coarse_res,
88090 .clock_get = posix_get_realtime_coarse,
88091 };
88092- struct k_clock clock_monotonic_coarse = {
88093+ static struct k_clock clock_monotonic_coarse = {
88094 .clock_getres = posix_get_coarse_res,
88095 .clock_get = posix_get_monotonic_coarse,
88096 };
88097- struct k_clock clock_tai = {
88098+ static struct k_clock clock_tai = {
88099 .clock_getres = hrtimer_get_res,
88100 .clock_get = posix_get_tai,
88101 .nsleep = common_nsleep,
88102@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88103 .timer_get = common_timer_get,
88104 .timer_del = common_timer_del,
88105 };
88106- struct k_clock clock_boottime = {
88107+ static struct k_clock clock_boottime = {
88108 .clock_getres = hrtimer_get_res,
88109 .clock_get = posix_get_boottime,
88110 .nsleep = common_nsleep,
88111@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88112 return;
88113 }
88114
88115- posix_clocks[clock_id] = *new_clock;
88116+ posix_clocks[clock_id] = new_clock;
88117 }
88118 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88119
88120@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88121 return (id & CLOCKFD_MASK) == CLOCKFD ?
88122 &clock_posix_dynamic : &clock_posix_cpu;
88123
88124- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88125+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88126 return NULL;
88127- return &posix_clocks[id];
88128+ return posix_clocks[id];
88129 }
88130
88131 static int common_timer_create(struct k_itimer *new_timer)
88132@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88133 struct k_clock *kc = clockid_to_kclock(which_clock);
88134 struct k_itimer *new_timer;
88135 int error, new_timer_id;
88136- sigevent_t event;
88137+ sigevent_t event = { };
88138 int it_id_set = IT_ID_NOT_SET;
88139
88140 if (!kc)
88141@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88142 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88143 return -EFAULT;
88144
88145+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88146+ have their clock_set fptr set to a nosettime dummy function
88147+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88148+ call common_clock_set, which calls do_sys_settimeofday, which
88149+ we hook
88150+ */
88151+
88152 return kc->clock_set(which_clock, &new_tp);
88153 }
88154
88155diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88156index 2fac9cc..56fef29 100644
88157--- a/kernel/power/Kconfig
88158+++ b/kernel/power/Kconfig
88159@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88160 config HIBERNATION
88161 bool "Hibernation (aka 'suspend to disk')"
88162 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88163+ depends on !GRKERNSEC_KMEM
88164+ depends on !PAX_MEMORY_SANITIZE
88165 select HIBERNATE_CALLBACKS
88166 select LZO_COMPRESS
88167 select LZO_DECOMPRESS
88168diff --git a/kernel/power/process.c b/kernel/power/process.c
88169index 06ec886..9dba35e 100644
88170--- a/kernel/power/process.c
88171+++ b/kernel/power/process.c
88172@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88173 unsigned int elapsed_msecs;
88174 bool wakeup = false;
88175 int sleep_usecs = USEC_PER_MSEC;
88176+ bool timedout = false;
88177
88178 do_gettimeofday(&start);
88179
88180@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88181
88182 while (true) {
88183 todo = 0;
88184+ if (time_after(jiffies, end_time))
88185+ timedout = true;
88186 read_lock(&tasklist_lock);
88187 do_each_thread(g, p) {
88188 if (p == current || !freeze_task(p))
88189 continue;
88190
88191- if (!freezer_should_skip(p))
88192+ if (!freezer_should_skip(p)) {
88193 todo++;
88194+ if (timedout) {
88195+ printk(KERN_ERR "Task refusing to freeze:\n");
88196+ sched_show_task(p);
88197+ }
88198+ }
88199 } while_each_thread(g, p);
88200 read_unlock(&tasklist_lock);
88201
88202@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88203 todo += wq_busy;
88204 }
88205
88206- if (!todo || time_after(jiffies, end_time))
88207+ if (!todo || timedout)
88208 break;
88209
88210 if (pm_wakeup_pending()) {
88211diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88212index 4dae9cb..039ffbb 100644
88213--- a/kernel/printk/printk.c
88214+++ b/kernel/printk/printk.c
88215@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88216 if (from_file && type != SYSLOG_ACTION_OPEN)
88217 return 0;
88218
88219+#ifdef CONFIG_GRKERNSEC_DMESG
88220+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88221+ return -EPERM;
88222+#endif
88223+
88224 if (syslog_action_restricted(type)) {
88225 if (capable(CAP_SYSLOG))
88226 return 0;
88227diff --git a/kernel/profile.c b/kernel/profile.c
88228index ebdd9c1..612ee05 100644
88229--- a/kernel/profile.c
88230+++ b/kernel/profile.c
88231@@ -37,7 +37,7 @@ struct profile_hit {
88232 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88233 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88234
88235-static atomic_t *prof_buffer;
88236+static atomic_unchecked_t *prof_buffer;
88237 static unsigned long prof_len, prof_shift;
88238
88239 int prof_on __read_mostly;
88240@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88241 hits[i].pc = 0;
88242 continue;
88243 }
88244- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88245+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88246 hits[i].hits = hits[i].pc = 0;
88247 }
88248 }
88249@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88250 * Add the current hit(s) and flush the write-queue out
88251 * to the global buffer:
88252 */
88253- atomic_add(nr_hits, &prof_buffer[pc]);
88254+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88255 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88256- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88257+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88258 hits[i].pc = hits[i].hits = 0;
88259 }
88260 out:
88261@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88262 {
88263 unsigned long pc;
88264 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88265- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88266+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88267 }
88268 #endif /* !CONFIG_SMP */
88269
88270@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88271 return -EFAULT;
88272 buf++; p++; count--; read++;
88273 }
88274- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88275+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88276 if (copy_to_user(buf, (void *)pnt, count))
88277 return -EFAULT;
88278 read += count;
88279@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88280 }
88281 #endif
88282 profile_discard_flip_buffers();
88283- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88284+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88285 return count;
88286 }
88287
88288diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88289index 1f4bcb3..99cf7ab 100644
88290--- a/kernel/ptrace.c
88291+++ b/kernel/ptrace.c
88292@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88293 if (seize)
88294 flags |= PT_SEIZED;
88295 rcu_read_lock();
88296- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88297+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88298 flags |= PT_PTRACE_CAP;
88299 rcu_read_unlock();
88300 task->ptrace = flags;
88301@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88302 break;
88303 return -EIO;
88304 }
88305- if (copy_to_user(dst, buf, retval))
88306+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88307 return -EFAULT;
88308 copied += retval;
88309 src += retval;
88310@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88311 bool seized = child->ptrace & PT_SEIZED;
88312 int ret = -EIO;
88313 siginfo_t siginfo, *si;
88314- void __user *datavp = (void __user *) data;
88315+ void __user *datavp = (__force void __user *) data;
88316 unsigned long __user *datalp = datavp;
88317 unsigned long flags;
88318
88319@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88320 goto out;
88321 }
88322
88323+ if (gr_handle_ptrace(child, request)) {
88324+ ret = -EPERM;
88325+ goto out_put_task_struct;
88326+ }
88327+
88328 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88329 ret = ptrace_attach(child, request, addr, data);
88330 /*
88331 * Some architectures need to do book-keeping after
88332 * a ptrace attach.
88333 */
88334- if (!ret)
88335+ if (!ret) {
88336 arch_ptrace_attach(child);
88337+ gr_audit_ptrace(child);
88338+ }
88339 goto out_put_task_struct;
88340 }
88341
88342@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88343 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88344 if (copied != sizeof(tmp))
88345 return -EIO;
88346- return put_user(tmp, (unsigned long __user *)data);
88347+ return put_user(tmp, (__force unsigned long __user *)data);
88348 }
88349
88350 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88351@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88352 }
88353
88354 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88355- compat_long_t addr, compat_long_t data)
88356+ compat_ulong_t addr, compat_ulong_t data)
88357 {
88358 struct task_struct *child;
88359 long ret;
88360@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88361 goto out;
88362 }
88363
88364+ if (gr_handle_ptrace(child, request)) {
88365+ ret = -EPERM;
88366+ goto out_put_task_struct;
88367+ }
88368+
88369 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88370 ret = ptrace_attach(child, request, addr, data);
88371 /*
88372 * Some architectures need to do book-keeping after
88373 * a ptrace attach.
88374 */
88375- if (!ret)
88376+ if (!ret) {
88377 arch_ptrace_attach(child);
88378+ gr_audit_ptrace(child);
88379+ }
88380 goto out_put_task_struct;
88381 }
88382
88383diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88384index 3318d82..1a5b2d1 100644
88385--- a/kernel/rcu/srcu.c
88386+++ b/kernel/rcu/srcu.c
88387@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88388
88389 idx = ACCESS_ONCE(sp->completed) & 0x1;
88390 preempt_disable();
88391- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88392+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88393 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88394- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88395+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88396 preempt_enable();
88397 return idx;
88398 }
88399diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88400index 1254f31..16258dc 100644
88401--- a/kernel/rcu/tiny.c
88402+++ b/kernel/rcu/tiny.c
88403@@ -46,7 +46,7 @@
88404 /* Forward declarations for tiny_plugin.h. */
88405 struct rcu_ctrlblk;
88406 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88407-static void rcu_process_callbacks(struct softirq_action *unused);
88408+static void rcu_process_callbacks(void);
88409 static void __call_rcu(struct rcu_head *head,
88410 void (*func)(struct rcu_head *rcu),
88411 struct rcu_ctrlblk *rcp);
88412@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88413 false));
88414 }
88415
88416-static void rcu_process_callbacks(struct softirq_action *unused)
88417+static __latent_entropy void rcu_process_callbacks(void)
88418 {
88419 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88420 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88421diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88422index 732f8ae..42c1919 100644
88423--- a/kernel/rcu/torture.c
88424+++ b/kernel/rcu/torture.c
88425@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88426 { 0 };
88427 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88428 { 0 };
88429-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88430-static atomic_t n_rcu_torture_alloc;
88431-static atomic_t n_rcu_torture_alloc_fail;
88432-static atomic_t n_rcu_torture_free;
88433-static atomic_t n_rcu_torture_mberror;
88434-static atomic_t n_rcu_torture_error;
88435+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88436+static atomic_unchecked_t n_rcu_torture_alloc;
88437+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88438+static atomic_unchecked_t n_rcu_torture_free;
88439+static atomic_unchecked_t n_rcu_torture_mberror;
88440+static atomic_unchecked_t n_rcu_torture_error;
88441 static long n_rcu_torture_barrier_error;
88442 static long n_rcu_torture_boost_ktrerror;
88443 static long n_rcu_torture_boost_rterror;
88444@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88445
88446 spin_lock_bh(&rcu_torture_lock);
88447 if (list_empty(&rcu_torture_freelist)) {
88448- atomic_inc(&n_rcu_torture_alloc_fail);
88449+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88450 spin_unlock_bh(&rcu_torture_lock);
88451 return NULL;
88452 }
88453- atomic_inc(&n_rcu_torture_alloc);
88454+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88455 p = rcu_torture_freelist.next;
88456 list_del_init(p);
88457 spin_unlock_bh(&rcu_torture_lock);
88458@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88459 static void
88460 rcu_torture_free(struct rcu_torture *p)
88461 {
88462- atomic_inc(&n_rcu_torture_free);
88463+ atomic_inc_unchecked(&n_rcu_torture_free);
88464 spin_lock_bh(&rcu_torture_lock);
88465 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88466 spin_unlock_bh(&rcu_torture_lock);
88467@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88468 i = rp->rtort_pipe_count;
88469 if (i > RCU_TORTURE_PIPE_LEN)
88470 i = RCU_TORTURE_PIPE_LEN;
88471- atomic_inc(&rcu_torture_wcount[i]);
88472+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88473 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88474 rp->rtort_mbtest = 0;
88475 rcu_torture_free(rp);
88476@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88477 i = old_rp->rtort_pipe_count;
88478 if (i > RCU_TORTURE_PIPE_LEN)
88479 i = RCU_TORTURE_PIPE_LEN;
88480- atomic_inc(&rcu_torture_wcount[i]);
88481+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88482 old_rp->rtort_pipe_count++;
88483 if (gp_normal == gp_exp)
88484 exp = !!(rcu_random(&rand) & 0x80);
88485@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88486 i = rp->rtort_pipe_count;
88487 if (i > RCU_TORTURE_PIPE_LEN)
88488 i = RCU_TORTURE_PIPE_LEN;
88489- atomic_inc(&rcu_torture_wcount[i]);
88490+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88491 if (++rp->rtort_pipe_count >=
88492 RCU_TORTURE_PIPE_LEN) {
88493 rp->rtort_mbtest = 0;
88494@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88495 return;
88496 }
88497 if (p->rtort_mbtest == 0)
88498- atomic_inc(&n_rcu_torture_mberror);
88499+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88500 spin_lock(&rand_lock);
88501 cur_ops->read_delay(&rand);
88502 n_rcu_torture_timers++;
88503@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88504 continue;
88505 }
88506 if (p->rtort_mbtest == 0)
88507- atomic_inc(&n_rcu_torture_mberror);
88508+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88509 cur_ops->read_delay(&rand);
88510 preempt_disable();
88511 pipe_count = p->rtort_pipe_count;
88512@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
88513 }
88514 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88515 page += sprintf(page,
88516- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88517+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88518 rcu_torture_current,
88519 rcu_torture_current_version,
88520 list_empty(&rcu_torture_freelist),
88521- atomic_read(&n_rcu_torture_alloc),
88522- atomic_read(&n_rcu_torture_alloc_fail),
88523- atomic_read(&n_rcu_torture_free));
88524+ atomic_read_unchecked(&n_rcu_torture_alloc),
88525+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88526+ atomic_read_unchecked(&n_rcu_torture_free));
88527 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88528- atomic_read(&n_rcu_torture_mberror),
88529+ atomic_read_unchecked(&n_rcu_torture_mberror),
88530 n_rcu_torture_boost_ktrerror,
88531 n_rcu_torture_boost_rterror);
88532 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88533@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88534 n_barrier_attempts,
88535 n_rcu_torture_barrier_error);
88536 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88537- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88538+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88539 n_rcu_torture_barrier_error != 0 ||
88540 n_rcu_torture_boost_ktrerror != 0 ||
88541 n_rcu_torture_boost_rterror != 0 ||
88542 n_rcu_torture_boost_failure != 0 ||
88543 i > 1) {
88544 page += sprintf(page, "!!! ");
88545- atomic_inc(&n_rcu_torture_error);
88546+ atomic_inc_unchecked(&n_rcu_torture_error);
88547 WARN_ON_ONCE(1);
88548 }
88549 page += sprintf(page, "Reader Pipe: ");
88550@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88551 page += sprintf(page, "Free-Block Circulation: ");
88552 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88553 page += sprintf(page, " %d",
88554- atomic_read(&rcu_torture_wcount[i]));
88555+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88556 }
88557 page += sprintf(page, "\n");
88558 if (cur_ops->stats)
88559@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88560
88561 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88562
88563- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88564+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88565 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88566 else if (n_online_successes != n_online_attempts ||
88567 n_offline_successes != n_offline_attempts)
88568@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88569
88570 rcu_torture_current = NULL;
88571 rcu_torture_current_version = 0;
88572- atomic_set(&n_rcu_torture_alloc, 0);
88573- atomic_set(&n_rcu_torture_alloc_fail, 0);
88574- atomic_set(&n_rcu_torture_free, 0);
88575- atomic_set(&n_rcu_torture_mberror, 0);
88576- atomic_set(&n_rcu_torture_error, 0);
88577+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88578+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88579+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88580+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88581+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88582 n_rcu_torture_barrier_error = 0;
88583 n_rcu_torture_boost_ktrerror = 0;
88584 n_rcu_torture_boost_rterror = 0;
88585 n_rcu_torture_boost_failure = 0;
88586 n_rcu_torture_boosts = 0;
88587 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88588- atomic_set(&rcu_torture_wcount[i], 0);
88589+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88590 for_each_possible_cpu(cpu) {
88591 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88592 per_cpu(rcu_torture_count, cpu)[i] = 0;
88593diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88594index b3d116c..ebf6598 100644
88595--- a/kernel/rcu/tree.c
88596+++ b/kernel/rcu/tree.c
88597@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88598 rcu_prepare_for_idle(smp_processor_id());
88599 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88600 smp_mb__before_atomic_inc(); /* See above. */
88601- atomic_inc(&rdtp->dynticks);
88602+ atomic_inc_unchecked(&rdtp->dynticks);
88603 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88604- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88605+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88606
88607 /*
88608 * It is illegal to enter an extended quiescent state while
88609@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88610 int user)
88611 {
88612 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88613- atomic_inc(&rdtp->dynticks);
88614+ atomic_inc_unchecked(&rdtp->dynticks);
88615 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88616 smp_mb__after_atomic_inc(); /* See above. */
88617- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88618+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88619 rcu_cleanup_after_idle(smp_processor_id());
88620 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88621 if (!user && !is_idle_task(current)) {
88622@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88623 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88624
88625 if (rdtp->dynticks_nmi_nesting == 0 &&
88626- (atomic_read(&rdtp->dynticks) & 0x1))
88627+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88628 return;
88629 rdtp->dynticks_nmi_nesting++;
88630 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88631- atomic_inc(&rdtp->dynticks);
88632+ atomic_inc_unchecked(&rdtp->dynticks);
88633 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88634 smp_mb__after_atomic_inc(); /* See above. */
88635- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88636+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88637 }
88638
88639 /**
88640@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88641 return;
88642 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88643 smp_mb__before_atomic_inc(); /* See above. */
88644- atomic_inc(&rdtp->dynticks);
88645+ atomic_inc_unchecked(&rdtp->dynticks);
88646 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88647- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88648+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88649 }
88650
88651 /**
88652@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88653 */
88654 bool notrace __rcu_is_watching(void)
88655 {
88656- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88657+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88658 }
88659
88660 /**
88661@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88662 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88663 bool *isidle, unsigned long *maxj)
88664 {
88665- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88666+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88667 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88668 return (rdp->dynticks_snap & 0x1) == 0;
88669 }
88670@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88671 unsigned int curr;
88672 unsigned int snap;
88673
88674- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88675+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88676 snap = (unsigned int)rdp->dynticks_snap;
88677
88678 /*
88679@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88680 rdp = this_cpu_ptr(rsp->rda);
88681 rcu_preempt_check_blocked_tasks(rnp);
88682 rnp->qsmask = rnp->qsmaskinit;
88683- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88684+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88685 WARN_ON_ONCE(rnp->completed != rsp->completed);
88686- ACCESS_ONCE(rnp->completed) = rsp->completed;
88687+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88688 if (rnp == rdp->mynode)
88689 __note_gp_changes(rsp, rnp, rdp);
88690 rcu_preempt_boost_start_gp(rnp);
88691@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88692 rcu_for_each_node_breadth_first(rsp, rnp) {
88693 raw_spin_lock_irq(&rnp->lock);
88694 smp_mb__after_unlock_lock();
88695- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88696+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88697 rdp = this_cpu_ptr(rsp->rda);
88698 if (rnp == rdp->mynode)
88699 __note_gp_changes(rsp, rnp, rdp);
88700@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88701 rsp->qlen += rdp->qlen;
88702 rdp->n_cbs_orphaned += rdp->qlen;
88703 rdp->qlen_lazy = 0;
88704- ACCESS_ONCE(rdp->qlen) = 0;
88705+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88706 }
88707
88708 /*
88709@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88710 }
88711 smp_mb(); /* List handling before counting for rcu_barrier(). */
88712 rdp->qlen_lazy -= count_lazy;
88713- ACCESS_ONCE(rdp->qlen) -= count;
88714+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88715 rdp->n_cbs_invoked += count;
88716
88717 /* Reinstate batch limit if we have worked down the excess. */
88718@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88719 /*
88720 * Do RCU core processing for the current CPU.
88721 */
88722-static void rcu_process_callbacks(struct softirq_action *unused)
88723+static void rcu_process_callbacks(void)
88724 {
88725 struct rcu_state *rsp;
88726
88727@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88728 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88729 if (debug_rcu_head_queue(head)) {
88730 /* Probable double call_rcu(), so leak the callback. */
88731- ACCESS_ONCE(head->func) = rcu_leak_callback;
88732+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88733 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88734 return;
88735 }
88736@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88737 local_irq_restore(flags);
88738 return;
88739 }
88740- ACCESS_ONCE(rdp->qlen)++;
88741+ ACCESS_ONCE_RW(rdp->qlen)++;
88742 if (lazy)
88743 rdp->qlen_lazy++;
88744 else
88745@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88746 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88747 * course be required on a 64-bit system.
88748 */
88749- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88750+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88751 (ulong)atomic_long_read(&rsp->expedited_done) +
88752 ULONG_MAX / 8)) {
88753 synchronize_sched();
88754- atomic_long_inc(&rsp->expedited_wrap);
88755+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88756 return;
88757 }
88758
88759@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88760 * Take a ticket. Note that atomic_inc_return() implies a
88761 * full memory barrier.
88762 */
88763- snap = atomic_long_inc_return(&rsp->expedited_start);
88764+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88765 firstsnap = snap;
88766 get_online_cpus();
88767 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88768@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88769 synchronize_sched_expedited_cpu_stop,
88770 NULL) == -EAGAIN) {
88771 put_online_cpus();
88772- atomic_long_inc(&rsp->expedited_tryfail);
88773+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88774
88775 /* Check to see if someone else did our work for us. */
88776 s = atomic_long_read(&rsp->expedited_done);
88777 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88778 /* ensure test happens before caller kfree */
88779 smp_mb__before_atomic_inc(); /* ^^^ */
88780- atomic_long_inc(&rsp->expedited_workdone1);
88781+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88782 return;
88783 }
88784
88785@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
88786 udelay(trycount * num_online_cpus());
88787 } else {
88788 wait_rcu_gp(call_rcu_sched);
88789- atomic_long_inc(&rsp->expedited_normal);
88790+ atomic_long_inc_unchecked(&rsp->expedited_normal);
88791 return;
88792 }
88793
88794@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
88795 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88796 /* ensure test happens before caller kfree */
88797 smp_mb__before_atomic_inc(); /* ^^^ */
88798- atomic_long_inc(&rsp->expedited_workdone2);
88799+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88800 return;
88801 }
88802
88803@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
88804 * period works for us.
88805 */
88806 get_online_cpus();
88807- snap = atomic_long_read(&rsp->expedited_start);
88808+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
88809 smp_mb(); /* ensure read is before try_stop_cpus(). */
88810 }
88811- atomic_long_inc(&rsp->expedited_stoppedcpus);
88812+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88813
88814 /*
88815 * Everyone up to our most recent fetch is covered by our grace
88816@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
88817 * than we did already did their update.
88818 */
88819 do {
88820- atomic_long_inc(&rsp->expedited_done_tries);
88821+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88822 s = atomic_long_read(&rsp->expedited_done);
88823 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88824 /* ensure test happens before caller kfree */
88825 smp_mb__before_atomic_inc(); /* ^^^ */
88826- atomic_long_inc(&rsp->expedited_done_lost);
88827+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88828 break;
88829 }
88830 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88831- atomic_long_inc(&rsp->expedited_done_exit);
88832+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88833
88834 put_online_cpus();
88835 }
88836@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88837 * ACCESS_ONCE() to prevent the compiler from speculating
88838 * the increment to precede the early-exit check.
88839 */
88840- ACCESS_ONCE(rsp->n_barrier_done)++;
88841+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88842 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88843 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88844 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88845@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88846
88847 /* Increment ->n_barrier_done to prevent duplicate work. */
88848 smp_mb(); /* Keep increment after above mechanism. */
88849- ACCESS_ONCE(rsp->n_barrier_done)++;
88850+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88851 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88852 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88853 smp_mb(); /* Keep increment before caller's subsequent code. */
88854@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88855 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88856 init_callback_list(rdp);
88857 rdp->qlen_lazy = 0;
88858- ACCESS_ONCE(rdp->qlen) = 0;
88859+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88860 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88861 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88862- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88863+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88864 rdp->cpu = cpu;
88865 rdp->rsp = rsp;
88866 rcu_boot_init_nocb_percpu_data(rdp);
88867@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88868 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88869 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88870 rcu_sysidle_init_percpu_data(rdp->dynticks);
88871- atomic_set(&rdp->dynticks->dynticks,
88872- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88873+ atomic_set_unchecked(&rdp->dynticks->dynticks,
88874+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88875 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88876
88877 /* Add CPU to rcu_node bitmasks. */
88878diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88879index 8c19873..bf83c57 100644
88880--- a/kernel/rcu/tree.h
88881+++ b/kernel/rcu/tree.h
88882@@ -87,11 +87,11 @@ struct rcu_dynticks {
88883 long long dynticks_nesting; /* Track irq/process nesting level. */
88884 /* Process level is worth LLONG_MAX/2. */
88885 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88886- atomic_t dynticks; /* Even value for idle, else odd. */
88887+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88888 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88889 long long dynticks_idle_nesting;
88890 /* irq/process nesting level from idle. */
88891- atomic_t dynticks_idle; /* Even value for idle, else odd. */
88892+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88893 /* "Idle" excludes userspace execution. */
88894 unsigned long dynticks_idle_jiffies;
88895 /* End of last non-NMI non-idle period. */
88896@@ -431,17 +431,17 @@ struct rcu_state {
88897 /* _rcu_barrier(). */
88898 /* End of fields guarded by barrier_mutex. */
88899
88900- atomic_long_t expedited_start; /* Starting ticket. */
88901- atomic_long_t expedited_done; /* Done ticket. */
88902- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88903- atomic_long_t expedited_tryfail; /* # acquisition failures. */
88904- atomic_long_t expedited_workdone1; /* # done by others #1. */
88905- atomic_long_t expedited_workdone2; /* # done by others #2. */
88906- atomic_long_t expedited_normal; /* # fallbacks to normal. */
88907- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88908- atomic_long_t expedited_done_tries; /* # tries to update _done. */
88909- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88910- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88911+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88912+ atomic_long_t expedited_done; /* Done ticket. */
88913+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88914+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88915+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88916+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88917+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88918+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88919+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88920+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88921+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88922
88923 unsigned long jiffies_force_qs; /* Time at which to invoke */
88924 /* force_quiescent_state(). */
88925diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88926index 6e2ef4b..c15df94 100644
88927--- a/kernel/rcu/tree_plugin.h
88928+++ b/kernel/rcu/tree_plugin.h
88929@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88930 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88931 {
88932 return !rcu_preempted_readers_exp(rnp) &&
88933- ACCESS_ONCE(rnp->expmask) == 0;
88934+ ACCESS_ONCE_RW(rnp->expmask) == 0;
88935 }
88936
88937 /*
88938@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
88939
88940 /* Clean up and exit. */
88941 smp_mb(); /* ensure expedited GP seen before counter increment. */
88942- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88943+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88944 unlock_mb_ret:
88945 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88946 mb_ret:
88947@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88948 free_cpumask_var(cm);
88949 }
88950
88951-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88952+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88953 .store = &rcu_cpu_kthread_task,
88954 .thread_should_run = rcu_cpu_kthread_should_run,
88955 .thread_fn = rcu_cpu_kthread,
88956@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88957 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88958 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88959 cpu, ticks_value, ticks_title,
88960- atomic_read(&rdtp->dynticks) & 0xfff,
88961+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88962 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88963 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88964 fast_no_hz);
88965@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88966
88967 /* Enqueue the callback on the nocb list and update counts. */
88968 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88969- ACCESS_ONCE(*old_rhpp) = rhp;
88970+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
88971 atomic_long_add(rhcount, &rdp->nocb_q_count);
88972 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88973
88974@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
88975 * Extract queued callbacks, update counts, and wait
88976 * for a grace period to elapse.
88977 */
88978- ACCESS_ONCE(rdp->nocb_head) = NULL;
88979+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88980 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88981 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88982 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88983- ACCESS_ONCE(rdp->nocb_p_count) += c;
88984- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88985+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88986+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88987 rcu_nocb_wait_gp(rdp);
88988
88989 /* Each pass through the following loop invokes a callback. */
88990@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
88991 list = next;
88992 }
88993 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88994- ACCESS_ONCE(rdp->nocb_p_count) -= c;
88995- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88996+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88997+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88998 rdp->n_nocbs_invoked += c;
88999 }
89000 return 0;
89001@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89002 {
89003 if (!rcu_nocb_need_deferred_wakeup(rdp))
89004 return;
89005- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89006+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89007 wake_up(&rdp->nocb_wq);
89008 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89009 }
89010@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89011 t = kthread_run(rcu_nocb_kthread, rdp,
89012 "rcuo%c/%d", rsp->abbr, cpu);
89013 BUG_ON(IS_ERR(t));
89014- ACCESS_ONCE(rdp->nocb_kthread) = t;
89015+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89016 }
89017 }
89018
89019@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89020
89021 /* Record start of fully idle period. */
89022 j = jiffies;
89023- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89024+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89025 smp_mb__before_atomic_inc();
89026- atomic_inc(&rdtp->dynticks_idle);
89027+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89028 smp_mb__after_atomic_inc();
89029- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89030+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89031 }
89032
89033 /*
89034@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89035
89036 /* Record end of idle period. */
89037 smp_mb__before_atomic_inc();
89038- atomic_inc(&rdtp->dynticks_idle);
89039+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89040 smp_mb__after_atomic_inc();
89041- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89042+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89043
89044 /*
89045 * If we are the timekeeping CPU, we are permitted to be non-idle
89046@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89047 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89048
89049 /* Pick up current idle and NMI-nesting counter and check. */
89050- cur = atomic_read(&rdtp->dynticks_idle);
89051+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89052 if (cur & 0x1) {
89053 *isidle = false; /* We are not idle! */
89054 return;
89055@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89056 case RCU_SYSIDLE_NOT:
89057
89058 /* First time all are idle, so note a short idle period. */
89059- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89060+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89061 break;
89062
89063 case RCU_SYSIDLE_SHORT:
89064@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89065 static void rcu_sysidle_cancel(void)
89066 {
89067 smp_mb();
89068- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89069+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89070 }
89071
89072 /*
89073@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89074 smp_mb(); /* grace period precedes setting inuse. */
89075
89076 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89077- ACCESS_ONCE(rshp->inuse) = 0;
89078+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89079 }
89080
89081 /*
89082diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89083index 4def475..8ffddde 100644
89084--- a/kernel/rcu/tree_trace.c
89085+++ b/kernel/rcu/tree_trace.c
89086@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89087 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89088 rdp->passed_quiesce, rdp->qs_pending);
89089 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89090- atomic_read(&rdp->dynticks->dynticks),
89091+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89092 rdp->dynticks->dynticks_nesting,
89093 rdp->dynticks->dynticks_nmi_nesting,
89094 rdp->dynticks_fqs);
89095@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89096 struct rcu_state *rsp = (struct rcu_state *)m->private;
89097
89098 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",
89099- atomic_long_read(&rsp->expedited_start),
89100+ atomic_long_read_unchecked(&rsp->expedited_start),
89101 atomic_long_read(&rsp->expedited_done),
89102- atomic_long_read(&rsp->expedited_wrap),
89103- atomic_long_read(&rsp->expedited_tryfail),
89104- atomic_long_read(&rsp->expedited_workdone1),
89105- atomic_long_read(&rsp->expedited_workdone2),
89106- atomic_long_read(&rsp->expedited_normal),
89107- atomic_long_read(&rsp->expedited_stoppedcpus),
89108- atomic_long_read(&rsp->expedited_done_tries),
89109- atomic_long_read(&rsp->expedited_done_lost),
89110- atomic_long_read(&rsp->expedited_done_exit));
89111+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89112+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89113+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89114+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89115+ atomic_long_read_unchecked(&rsp->expedited_normal),
89116+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89117+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89118+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89119+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89120 return 0;
89121 }
89122
89123diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89124index c54609f..2e8829c 100644
89125--- a/kernel/rcu/update.c
89126+++ b/kernel/rcu/update.c
89127@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89128 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89129 */
89130 if (till_stall_check < 3) {
89131- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89132+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89133 till_stall_check = 3;
89134 } else if (till_stall_check > 300) {
89135- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89136+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89137 till_stall_check = 300;
89138 }
89139 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89140diff --git a/kernel/resource.c b/kernel/resource.c
89141index 3f285dc..5755f62 100644
89142--- a/kernel/resource.c
89143+++ b/kernel/resource.c
89144@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89145
89146 static int __init ioresources_init(void)
89147 {
89148+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89149+#ifdef CONFIG_GRKERNSEC_PROC_USER
89150+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89151+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89152+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89153+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89154+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89155+#endif
89156+#else
89157 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89158 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89159+#endif
89160 return 0;
89161 }
89162 __initcall(ioresources_init);
89163diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89164index 4a07353..66b5291 100644
89165--- a/kernel/sched/auto_group.c
89166+++ b/kernel/sched/auto_group.c
89167@@ -11,7 +11,7 @@
89168
89169 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89170 static struct autogroup autogroup_default;
89171-static atomic_t autogroup_seq_nr;
89172+static atomic_unchecked_t autogroup_seq_nr;
89173
89174 void __init autogroup_init(struct task_struct *init_task)
89175 {
89176@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89177
89178 kref_init(&ag->kref);
89179 init_rwsem(&ag->lock);
89180- ag->id = atomic_inc_return(&autogroup_seq_nr);
89181+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89182 ag->tg = tg;
89183 #ifdef CONFIG_RT_GROUP_SCHED
89184 /*
89185diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89186index a63f4dc..349bbb0 100644
89187--- a/kernel/sched/completion.c
89188+++ b/kernel/sched/completion.c
89189@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89190 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89191 * or number of jiffies left till timeout) if completed.
89192 */
89193-long __sched
89194+long __sched __intentional_overflow(-1)
89195 wait_for_completion_interruptible_timeout(struct completion *x,
89196 unsigned long timeout)
89197 {
89198@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89199 *
89200 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89201 */
89202-int __sched wait_for_completion_killable(struct completion *x)
89203+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89204 {
89205 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89206 if (t == -ERESTARTSYS)
89207@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89208 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89209 * or number of jiffies left till timeout) if completed.
89210 */
89211-long __sched
89212+long __sched __intentional_overflow(-1)
89213 wait_for_completion_killable_timeout(struct completion *x,
89214 unsigned long timeout)
89215 {
89216diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89217index f5c6635..ab9f223 100644
89218--- a/kernel/sched/core.c
89219+++ b/kernel/sched/core.c
89220@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89221 int sysctl_numa_balancing(struct ctl_table *table, int write,
89222 void __user *buffer, size_t *lenp, loff_t *ppos)
89223 {
89224- struct ctl_table t;
89225+ ctl_table_no_const t;
89226 int err;
89227 int state = numabalancing_enabled;
89228
89229@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89230 /* convert nice value [19,-20] to rlimit style value [1,40] */
89231 int nice_rlim = 20 - nice;
89232
89233+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89234+
89235 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89236 capable(CAP_SYS_NICE));
89237 }
89238@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89239 if (nice > 19)
89240 nice = 19;
89241
89242- if (increment < 0 && !can_nice(current, nice))
89243+ if (increment < 0 && (!can_nice(current, nice) ||
89244+ gr_handle_chroot_nice()))
89245 return -EPERM;
89246
89247 retval = security_task_setnice(current, nice);
89248@@ -3332,6 +3335,7 @@ recheck:
89249 if (policy != p->policy && !rlim_rtprio)
89250 return -EPERM;
89251
89252+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89253 /* can't increase priority */
89254 if (attr->sched_priority > p->rt_priority &&
89255 attr->sched_priority > rlim_rtprio)
89256@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89257
89258 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89259
89260-static struct ctl_table sd_ctl_dir[] = {
89261+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89262 {
89263 .procname = "sched_domain",
89264 .mode = 0555,
89265@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89266 {}
89267 };
89268
89269-static struct ctl_table *sd_alloc_ctl_entry(int n)
89270+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89271 {
89272- struct ctl_table *entry =
89273+ ctl_table_no_const *entry =
89274 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89275
89276 return entry;
89277 }
89278
89279-static void sd_free_ctl_entry(struct ctl_table **tablep)
89280+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89281 {
89282- struct ctl_table *entry;
89283+ ctl_table_no_const *entry;
89284
89285 /*
89286 * In the intermediate directories, both the child directory and
89287@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89288 * will always be set. In the lowest directory the names are
89289 * static strings and all have proc handlers.
89290 */
89291- for (entry = *tablep; entry->mode; entry++) {
89292- if (entry->child)
89293- sd_free_ctl_entry(&entry->child);
89294+ for (entry = tablep; entry->mode; entry++) {
89295+ if (entry->child) {
89296+ sd_free_ctl_entry(entry->child);
89297+ pax_open_kernel();
89298+ entry->child = NULL;
89299+ pax_close_kernel();
89300+ }
89301 if (entry->proc_handler == NULL)
89302 kfree(entry->procname);
89303 }
89304
89305- kfree(*tablep);
89306- *tablep = NULL;
89307+ kfree(tablep);
89308 }
89309
89310 static int min_load_idx = 0;
89311 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89312
89313 static void
89314-set_table_entry(struct ctl_table *entry,
89315+set_table_entry(ctl_table_no_const *entry,
89316 const char *procname, void *data, int maxlen,
89317 umode_t mode, proc_handler *proc_handler,
89318 bool load_idx)
89319@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89320 static struct ctl_table *
89321 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89322 {
89323- struct ctl_table *table = sd_alloc_ctl_entry(13);
89324+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89325
89326 if (table == NULL)
89327 return NULL;
89328@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89329 return table;
89330 }
89331
89332-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89333+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89334 {
89335- struct ctl_table *entry, *table;
89336+ ctl_table_no_const *entry, *table;
89337 struct sched_domain *sd;
89338 int domain_num = 0, i;
89339 char buf[32];
89340@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89341 static void register_sched_domain_sysctl(void)
89342 {
89343 int i, cpu_num = num_possible_cpus();
89344- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89345+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89346 char buf[32];
89347
89348 WARN_ON(sd_ctl_dir[0].child);
89349+ pax_open_kernel();
89350 sd_ctl_dir[0].child = entry;
89351+ pax_close_kernel();
89352
89353 if (entry == NULL)
89354 return;
89355@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89356 if (sd_sysctl_header)
89357 unregister_sysctl_table(sd_sysctl_header);
89358 sd_sysctl_header = NULL;
89359- if (sd_ctl_dir[0].child)
89360- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89361+ if (sd_ctl_dir[0].child) {
89362+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89363+ pax_open_kernel();
89364+ sd_ctl_dir[0].child = NULL;
89365+ pax_close_kernel();
89366+ }
89367 }
89368 #else
89369 static void register_sched_domain_sysctl(void)
89370diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89371index 9b4c4f3..665489b 100644
89372--- a/kernel/sched/fair.c
89373+++ b/kernel/sched/fair.c
89374@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89375
89376 static void reset_ptenuma_scan(struct task_struct *p)
89377 {
89378- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89379+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89380 p->mm->numa_scan_offset = 0;
89381 }
89382
89383@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89384 * run_rebalance_domains is triggered when needed from the scheduler tick.
89385 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89386 */
89387-static void run_rebalance_domains(struct softirq_action *h)
89388+static __latent_entropy void run_rebalance_domains(void)
89389 {
89390 struct rq *this_rq = this_rq();
89391 enum cpu_idle_type idle = this_rq->idle_balance ?
89392diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89393index f964add..dcd823d 100644
89394--- a/kernel/sched/sched.h
89395+++ b/kernel/sched/sched.h
89396@@ -1157,7 +1157,7 @@ struct sched_class {
89397 #ifdef CONFIG_FAIR_GROUP_SCHED
89398 void (*task_move_group) (struct task_struct *p, int on_rq);
89399 #endif
89400-};
89401+} __do_const;
89402
89403 #define sched_class_highest (&stop_sched_class)
89404 #define for_each_class(class) \
89405diff --git a/kernel/signal.c b/kernel/signal.c
89406index 52f881d..1e9f941 100644
89407--- a/kernel/signal.c
89408+++ b/kernel/signal.c
89409@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89410
89411 int print_fatal_signals __read_mostly;
89412
89413-static void __user *sig_handler(struct task_struct *t, int sig)
89414+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89415 {
89416 return t->sighand->action[sig - 1].sa.sa_handler;
89417 }
89418
89419-static int sig_handler_ignored(void __user *handler, int sig)
89420+static int sig_handler_ignored(__sighandler_t handler, int sig)
89421 {
89422 /* Is it explicitly or implicitly ignored? */
89423 return handler == SIG_IGN ||
89424@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89425
89426 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89427 {
89428- void __user *handler;
89429+ __sighandler_t handler;
89430
89431 handler = sig_handler(t, sig);
89432
89433@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89434 atomic_inc(&user->sigpending);
89435 rcu_read_unlock();
89436
89437+ if (!override_rlimit)
89438+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89439+
89440 if (override_rlimit ||
89441 atomic_read(&user->sigpending) <=
89442 task_rlimit(t, RLIMIT_SIGPENDING)) {
89443@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89444
89445 int unhandled_signal(struct task_struct *tsk, int sig)
89446 {
89447- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89448+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89449 if (is_global_init(tsk))
89450 return 1;
89451 if (handler != SIG_IGN && handler != SIG_DFL)
89452@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89453 }
89454 }
89455
89456+ /* allow glibc communication via tgkill to other threads in our
89457+ thread group */
89458+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89459+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89460+ && gr_handle_signal(t, sig))
89461+ return -EPERM;
89462+
89463 return security_task_kill(t, info, sig, 0);
89464 }
89465
89466@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89467 return send_signal(sig, info, p, 1);
89468 }
89469
89470-static int
89471+int
89472 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89473 {
89474 return send_signal(sig, info, t, 0);
89475@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89476 unsigned long int flags;
89477 int ret, blocked, ignored;
89478 struct k_sigaction *action;
89479+ int is_unhandled = 0;
89480
89481 spin_lock_irqsave(&t->sighand->siglock, flags);
89482 action = &t->sighand->action[sig-1];
89483@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89484 }
89485 if (action->sa.sa_handler == SIG_DFL)
89486 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89487+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89488+ is_unhandled = 1;
89489 ret = specific_send_sig_info(sig, info, t);
89490 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89491
89492+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89493+ normal operation */
89494+ if (is_unhandled) {
89495+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89496+ gr_handle_crash(t, sig);
89497+ }
89498+
89499 return ret;
89500 }
89501
89502@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89503 ret = check_kill_permission(sig, info, p);
89504 rcu_read_unlock();
89505
89506- if (!ret && sig)
89507+ if (!ret && sig) {
89508 ret = do_send_sig_info(sig, info, p, true);
89509+ if (!ret)
89510+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89511+ }
89512
89513 return ret;
89514 }
89515@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89516 int error = -ESRCH;
89517
89518 rcu_read_lock();
89519- p = find_task_by_vpid(pid);
89520+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89521+ /* allow glibc communication via tgkill to other threads in our
89522+ thread group */
89523+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89524+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89525+ p = find_task_by_vpid_unrestricted(pid);
89526+ else
89527+#endif
89528+ p = find_task_by_vpid(pid);
89529 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89530 error = check_kill_permission(sig, info, p);
89531 /*
89532@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89533 }
89534 seg = get_fs();
89535 set_fs(KERNEL_DS);
89536- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89537- (stack_t __force __user *) &uoss,
89538+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89539+ (stack_t __force_user *) &uoss,
89540 compat_user_stack_pointer());
89541 set_fs(seg);
89542 if (ret >= 0 && uoss_ptr) {
89543diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89544index eb89e18..a4e6792 100644
89545--- a/kernel/smpboot.c
89546+++ b/kernel/smpboot.c
89547@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89548 }
89549 smpboot_unpark_thread(plug_thread, cpu);
89550 }
89551- list_add(&plug_thread->list, &hotplug_threads);
89552+ pax_list_add(&plug_thread->list, &hotplug_threads);
89553 out:
89554 mutex_unlock(&smpboot_threads_lock);
89555 return ret;
89556@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89557 {
89558 get_online_cpus();
89559 mutex_lock(&smpboot_threads_lock);
89560- list_del(&plug_thread->list);
89561+ pax_list_del(&plug_thread->list);
89562 smpboot_destroy_threads(plug_thread);
89563 mutex_unlock(&smpboot_threads_lock);
89564 put_online_cpus();
89565diff --git a/kernel/softirq.c b/kernel/softirq.c
89566index 490fcbb..1e502c6 100644
89567--- a/kernel/softirq.c
89568+++ b/kernel/softirq.c
89569@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89570 EXPORT_SYMBOL(irq_stat);
89571 #endif
89572
89573-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89574+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89575
89576 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89577
89578@@ -267,7 +267,7 @@ restart:
89579 kstat_incr_softirqs_this_cpu(vec_nr);
89580
89581 trace_softirq_entry(vec_nr);
89582- h->action(h);
89583+ h->action();
89584 trace_softirq_exit(vec_nr);
89585 if (unlikely(prev_count != preempt_count())) {
89586 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89587@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89588 or_softirq_pending(1UL << nr);
89589 }
89590
89591-void open_softirq(int nr, void (*action)(struct softirq_action *))
89592+void __init open_softirq(int nr, void (*action)(void))
89593 {
89594 softirq_vec[nr].action = action;
89595 }
89596@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89597 }
89598 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89599
89600-static void tasklet_action(struct softirq_action *a)
89601+static void tasklet_action(void)
89602 {
89603 struct tasklet_struct *list;
89604
89605@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89606 }
89607 }
89608
89609-static void tasklet_hi_action(struct softirq_action *a)
89610+static __latent_entropy void tasklet_hi_action(void)
89611 {
89612 struct tasklet_struct *list;
89613
89614@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89615 .notifier_call = cpu_callback
89616 };
89617
89618-static struct smp_hotplug_thread softirq_threads = {
89619+static struct smp_hotplug_thread softirq_threads __read_only = {
89620 .store = &ksoftirqd,
89621 .thread_should_run = ksoftirqd_should_run,
89622 .thread_fn = run_ksoftirqd,
89623diff --git a/kernel/sys.c b/kernel/sys.c
89624index c0a58be..784c618 100644
89625--- a/kernel/sys.c
89626+++ b/kernel/sys.c
89627@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89628 error = -EACCES;
89629 goto out;
89630 }
89631+
89632+ if (gr_handle_chroot_setpriority(p, niceval)) {
89633+ error = -EACCES;
89634+ goto out;
89635+ }
89636+
89637 no_nice = security_task_setnice(p, niceval);
89638 if (no_nice) {
89639 error = no_nice;
89640@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89641 goto error;
89642 }
89643
89644+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89645+ goto error;
89646+
89647 if (rgid != (gid_t) -1 ||
89648 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89649 new->sgid = new->egid;
89650@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89651 old = current_cred();
89652
89653 retval = -EPERM;
89654+
89655+ if (gr_check_group_change(kgid, kgid, kgid))
89656+ goto error;
89657+
89658 if (ns_capable(old->user_ns, CAP_SETGID))
89659 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89660 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89661@@ -403,7 +416,7 @@ error:
89662 /*
89663 * change the user struct in a credentials set to match the new UID
89664 */
89665-static int set_user(struct cred *new)
89666+int set_user(struct cred *new)
89667 {
89668 struct user_struct *new_user;
89669
89670@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89671 goto error;
89672 }
89673
89674+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89675+ goto error;
89676+
89677 if (!uid_eq(new->uid, old->uid)) {
89678 retval = set_user(new);
89679 if (retval < 0)
89680@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89681 old = current_cred();
89682
89683 retval = -EPERM;
89684+
89685+ if (gr_check_crash_uid(kuid))
89686+ goto error;
89687+ if (gr_check_user_change(kuid, kuid, kuid))
89688+ goto error;
89689+
89690 if (ns_capable(old->user_ns, CAP_SETUID)) {
89691 new->suid = new->uid = kuid;
89692 if (!uid_eq(kuid, old->uid)) {
89693@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89694 goto error;
89695 }
89696
89697+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89698+ goto error;
89699+
89700 if (ruid != (uid_t) -1) {
89701 new->uid = kruid;
89702 if (!uid_eq(kruid, old->uid)) {
89703@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89704 goto error;
89705 }
89706
89707+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89708+ goto error;
89709+
89710 if (rgid != (gid_t) -1)
89711 new->gid = krgid;
89712 if (egid != (gid_t) -1)
89713@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89714 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89715 ns_capable(old->user_ns, CAP_SETUID)) {
89716 if (!uid_eq(kuid, old->fsuid)) {
89717+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89718+ goto error;
89719+
89720 new->fsuid = kuid;
89721 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89722 goto change_okay;
89723 }
89724 }
89725
89726+error:
89727 abort_creds(new);
89728 return old_fsuid;
89729
89730@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89731 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89732 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89733 ns_capable(old->user_ns, CAP_SETGID)) {
89734+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89735+ goto error;
89736+
89737 if (!gid_eq(kgid, old->fsgid)) {
89738 new->fsgid = kgid;
89739 goto change_okay;
89740 }
89741 }
89742
89743+error:
89744 abort_creds(new);
89745 return old_fsgid;
89746
89747@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89748 return -EFAULT;
89749
89750 down_read(&uts_sem);
89751- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89752+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89753 __OLD_UTS_LEN);
89754 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89755- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89756+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89757 __OLD_UTS_LEN);
89758 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89759- error |= __copy_to_user(&name->release, &utsname()->release,
89760+ error |= __copy_to_user(name->release, &utsname()->release,
89761 __OLD_UTS_LEN);
89762 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89763- error |= __copy_to_user(&name->version, &utsname()->version,
89764+ error |= __copy_to_user(name->version, &utsname()->version,
89765 __OLD_UTS_LEN);
89766 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89767- error |= __copy_to_user(&name->machine, &utsname()->machine,
89768+ error |= __copy_to_user(name->machine, &utsname()->machine,
89769 __OLD_UTS_LEN);
89770 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89771 up_read(&uts_sem);
89772@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89773 */
89774 new_rlim->rlim_cur = 1;
89775 }
89776+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89777+ is changed to a lower value. Since tasks can be created by the same
89778+ user in between this limit change and an execve by this task, force
89779+ a recheck only for this task by setting PF_NPROC_EXCEEDED
89780+ */
89781+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89782+ tsk->flags |= PF_NPROC_EXCEEDED;
89783 }
89784 if (!retval) {
89785 if (old_rlim)
89786diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89787index aae21e8..58d8c9a 100644
89788--- a/kernel/sysctl.c
89789+++ b/kernel/sysctl.c
89790@@ -94,7 +94,6 @@
89791
89792
89793 #if defined(CONFIG_SYSCTL)
89794-
89795 /* External variables not in a header file. */
89796 extern int max_threads;
89797 extern int suid_dumpable;
89798@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
89799
89800 /* Constants used for minimum and maximum */
89801 #ifdef CONFIG_LOCKUP_DETECTOR
89802-static int sixty = 60;
89803+static int sixty __read_only = 60;
89804 #endif
89805
89806-static int __maybe_unused neg_one = -1;
89807-
89808-static int zero;
89809-static int __maybe_unused one = 1;
89810-static int __maybe_unused two = 2;
89811-static int __maybe_unused three = 3;
89812-static unsigned long one_ul = 1;
89813-static int one_hundred = 100;
89814+static int __maybe_unused neg_one __read_only = -1;
89815+static int zero __read_only = 0;
89816+static int __maybe_unused one __read_only = 1;
89817+static int __maybe_unused two __read_only = 2;
89818+static int __maybe_unused three __read_only = 3;
89819+static unsigned long one_ul __read_only = 1;
89820+static int one_hundred __read_only = 100;
89821 #ifdef CONFIG_PRINTK
89822-static int ten_thousand = 10000;
89823+static int ten_thousand __read_only = 10000;
89824 #endif
89825
89826 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89827@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
89828 void __user *buffer, size_t *lenp, loff_t *ppos);
89829 #endif
89830
89831-#ifdef CONFIG_PRINTK
89832 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89833 void __user *buffer, size_t *lenp, loff_t *ppos);
89834-#endif
89835
89836 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89837 void __user *buffer, size_t *lenp, loff_t *ppos);
89838@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89839
89840 #endif
89841
89842+extern struct ctl_table grsecurity_table[];
89843+
89844 static struct ctl_table kern_table[];
89845 static struct ctl_table vm_table[];
89846 static struct ctl_table fs_table[];
89847@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
89848 int sysctl_legacy_va_layout;
89849 #endif
89850
89851+#ifdef CONFIG_PAX_SOFTMODE
89852+static ctl_table pax_table[] = {
89853+ {
89854+ .procname = "softmode",
89855+ .data = &pax_softmode,
89856+ .maxlen = sizeof(unsigned int),
89857+ .mode = 0600,
89858+ .proc_handler = &proc_dointvec,
89859+ },
89860+
89861+ { }
89862+};
89863+#endif
89864+
89865 /* The default sysctl tables: */
89866
89867 static struct ctl_table sysctl_base_table[] = {
89868@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
89869 #endif
89870
89871 static struct ctl_table kern_table[] = {
89872+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89873+ {
89874+ .procname = "grsecurity",
89875+ .mode = 0500,
89876+ .child = grsecurity_table,
89877+ },
89878+#endif
89879+
89880+#ifdef CONFIG_PAX_SOFTMODE
89881+ {
89882+ .procname = "pax",
89883+ .mode = 0500,
89884+ .child = pax_table,
89885+ },
89886+#endif
89887+
89888 {
89889 .procname = "sched_child_runs_first",
89890 .data = &sysctl_sched_child_runs_first,
89891@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
89892 .data = &modprobe_path,
89893 .maxlen = KMOD_PATH_LEN,
89894 .mode = 0644,
89895- .proc_handler = proc_dostring,
89896+ .proc_handler = proc_dostring_modpriv,
89897 },
89898 {
89899 .procname = "modules_disabled",
89900@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
89901 .extra1 = &zero,
89902 .extra2 = &one,
89903 },
89904+#endif
89905 {
89906 .procname = "kptr_restrict",
89907 .data = &kptr_restrict,
89908 .maxlen = sizeof(int),
89909 .mode = 0644,
89910 .proc_handler = proc_dointvec_minmax_sysadmin,
89911+#ifdef CONFIG_GRKERNSEC_HIDESYM
89912+ .extra1 = &two,
89913+#else
89914 .extra1 = &zero,
89915+#endif
89916 .extra2 = &two,
89917 },
89918-#endif
89919 {
89920 .procname = "ngroups_max",
89921 .data = &ngroups_max,
89922@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
89923 */
89924 {
89925 .procname = "perf_event_paranoid",
89926- .data = &sysctl_perf_event_paranoid,
89927- .maxlen = sizeof(sysctl_perf_event_paranoid),
89928+ .data = &sysctl_perf_event_legitimately_concerned,
89929+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89930 .mode = 0644,
89931- .proc_handler = proc_dointvec,
89932+ /* go ahead, be a hero */
89933+ .proc_handler = proc_dointvec_minmax_sysadmin,
89934+ .extra1 = &neg_one,
89935+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89936+ .extra2 = &three,
89937+#else
89938+ .extra2 = &two,
89939+#endif
89940 },
89941 {
89942 .procname = "perf_event_mlock_kb",
89943@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
89944 .proc_handler = proc_dointvec_minmax,
89945 .extra1 = &zero,
89946 },
89947+ {
89948+ .procname = "heap_stack_gap",
89949+ .data = &sysctl_heap_stack_gap,
89950+ .maxlen = sizeof(sysctl_heap_stack_gap),
89951+ .mode = 0644,
89952+ .proc_handler = proc_doulongvec_minmax,
89953+ },
89954 #else
89955 {
89956 .procname = "nr_trim_pages",
89957@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
89958 buffer, lenp, ppos);
89959 }
89960
89961+int proc_dostring_modpriv(struct ctl_table *table, int write,
89962+ void __user *buffer, size_t *lenp, loff_t *ppos)
89963+{
89964+ if (write && !capable(CAP_SYS_MODULE))
89965+ return -EPERM;
89966+
89967+ return _proc_do_string(table->data, table->maxlen, write,
89968+ buffer, lenp, ppos);
89969+}
89970+
89971 static size_t proc_skip_spaces(char **buf)
89972 {
89973 size_t ret;
89974@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89975 len = strlen(tmp);
89976 if (len > *size)
89977 len = *size;
89978+ if (len > sizeof(tmp))
89979+ len = sizeof(tmp);
89980 if (copy_to_user(*buf, tmp, len))
89981 return -EFAULT;
89982 *size -= len;
89983@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89984 static int proc_taint(struct ctl_table *table, int write,
89985 void __user *buffer, size_t *lenp, loff_t *ppos)
89986 {
89987- struct ctl_table t;
89988+ ctl_table_no_const t;
89989 unsigned long tmptaint = get_taint();
89990 int err;
89991
89992@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
89993 return err;
89994 }
89995
89996-#ifdef CONFIG_PRINTK
89997 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89998 void __user *buffer, size_t *lenp, loff_t *ppos)
89999 {
90000@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90001
90002 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90003 }
90004-#endif
90005
90006 struct do_proc_dointvec_minmax_conv_param {
90007 int *min;
90008@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90009 return -ENOSYS;
90010 }
90011
90012+int proc_dostring_modpriv(struct ctl_table *table, int write,
90013+ void __user *buffer, size_t *lenp, loff_t *ppos)
90014+{
90015+ return -ENOSYS;
90016+}
90017+
90018 int proc_dointvec(struct ctl_table *table, int write,
90019 void __user *buffer, size_t *lenp, loff_t *ppos)
90020 {
90021@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90022 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90023 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90024 EXPORT_SYMBOL(proc_dostring);
90025+EXPORT_SYMBOL(proc_dostring_modpriv);
90026 EXPORT_SYMBOL(proc_doulongvec_minmax);
90027 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90028diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90029index 13d2f7c..c93d0b0 100644
90030--- a/kernel/taskstats.c
90031+++ b/kernel/taskstats.c
90032@@ -28,9 +28,12 @@
90033 #include <linux/fs.h>
90034 #include <linux/file.h>
90035 #include <linux/pid_namespace.h>
90036+#include <linux/grsecurity.h>
90037 #include <net/genetlink.h>
90038 #include <linux/atomic.h>
90039
90040+extern int gr_is_taskstats_denied(int pid);
90041+
90042 /*
90043 * Maximum length of a cpumask that can be specified in
90044 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90045@@ -576,6 +579,9 @@ err:
90046
90047 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90048 {
90049+ if (gr_is_taskstats_denied(current->pid))
90050+ return -EACCES;
90051+
90052 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90053 return cmd_attr_register_cpumask(info);
90054 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90055diff --git a/kernel/time.c b/kernel/time.c
90056index 7c7964c..2a0d412 100644
90057--- a/kernel/time.c
90058+++ b/kernel/time.c
90059@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90060 return error;
90061
90062 if (tz) {
90063+ /* we log in do_settimeofday called below, so don't log twice
90064+ */
90065+ if (!tv)
90066+ gr_log_timechange();
90067+
90068 sys_tz = *tz;
90069 update_vsyscall_tz();
90070 if (firsttime) {
90071diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90072index 88c9c65..7497ebc 100644
90073--- a/kernel/time/alarmtimer.c
90074+++ b/kernel/time/alarmtimer.c
90075@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90076 struct platform_device *pdev;
90077 int error = 0;
90078 int i;
90079- struct k_clock alarm_clock = {
90080+ static struct k_clock alarm_clock = {
90081 .clock_getres = alarm_clock_getres,
90082 .clock_get = alarm_clock_get,
90083 .timer_create = alarm_timer_create,
90084diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90085index 5b40279..81e58db 100644
90086--- a/kernel/time/timekeeping.c
90087+++ b/kernel/time/timekeeping.c
90088@@ -15,6 +15,7 @@
90089 #include <linux/init.h>
90090 #include <linux/mm.h>
90091 #include <linux/sched.h>
90092+#include <linux/grsecurity.h>
90093 #include <linux/syscore_ops.h>
90094 #include <linux/clocksource.h>
90095 #include <linux/jiffies.h>
90096@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90097 if (!timespec_valid_strict(tv))
90098 return -EINVAL;
90099
90100+ gr_log_timechange();
90101+
90102 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90103 write_seqcount_begin(&timekeeper_seq);
90104
90105diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90106index 61ed862..3b52c65 100644
90107--- a/kernel/time/timer_list.c
90108+++ b/kernel/time/timer_list.c
90109@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90110
90111 static void print_name_offset(struct seq_file *m, void *sym)
90112 {
90113+#ifdef CONFIG_GRKERNSEC_HIDESYM
90114+ SEQ_printf(m, "<%p>", NULL);
90115+#else
90116 char symname[KSYM_NAME_LEN];
90117
90118 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90119 SEQ_printf(m, "<%pK>", sym);
90120 else
90121 SEQ_printf(m, "%s", symname);
90122+#endif
90123 }
90124
90125 static void
90126@@ -119,7 +123,11 @@ next_one:
90127 static void
90128 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90129 {
90130+#ifdef CONFIG_GRKERNSEC_HIDESYM
90131+ SEQ_printf(m, " .base: %p\n", NULL);
90132+#else
90133 SEQ_printf(m, " .base: %pK\n", base);
90134+#endif
90135 SEQ_printf(m, " .index: %d\n",
90136 base->index);
90137 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90138@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90139 {
90140 struct proc_dir_entry *pe;
90141
90142+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90143+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90144+#else
90145 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90146+#endif
90147 if (!pe)
90148 return -ENOMEM;
90149 return 0;
90150diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90151index 1fb08f2..ca4bb1e 100644
90152--- a/kernel/time/timer_stats.c
90153+++ b/kernel/time/timer_stats.c
90154@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90155 static unsigned long nr_entries;
90156 static struct entry entries[MAX_ENTRIES];
90157
90158-static atomic_t overflow_count;
90159+static atomic_unchecked_t overflow_count;
90160
90161 /*
90162 * The entries are in a hash-table, for fast lookup:
90163@@ -140,7 +140,7 @@ static void reset_entries(void)
90164 nr_entries = 0;
90165 memset(entries, 0, sizeof(entries));
90166 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90167- atomic_set(&overflow_count, 0);
90168+ atomic_set_unchecked(&overflow_count, 0);
90169 }
90170
90171 static struct entry *alloc_entry(void)
90172@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90173 if (likely(entry))
90174 entry->count++;
90175 else
90176- atomic_inc(&overflow_count);
90177+ atomic_inc_unchecked(&overflow_count);
90178
90179 out_unlock:
90180 raw_spin_unlock_irqrestore(lock, flags);
90181@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90182
90183 static void print_name_offset(struct seq_file *m, unsigned long addr)
90184 {
90185+#ifdef CONFIG_GRKERNSEC_HIDESYM
90186+ seq_printf(m, "<%p>", NULL);
90187+#else
90188 char symname[KSYM_NAME_LEN];
90189
90190 if (lookup_symbol_name(addr, symname) < 0)
90191- seq_printf(m, "<%p>", (void *)addr);
90192+ seq_printf(m, "<%pK>", (void *)addr);
90193 else
90194 seq_printf(m, "%s", symname);
90195+#endif
90196 }
90197
90198 static int tstats_show(struct seq_file *m, void *v)
90199@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90200
90201 seq_puts(m, "Timer Stats Version: v0.3\n");
90202 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90203- if (atomic_read(&overflow_count))
90204- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90205+ if (atomic_read_unchecked(&overflow_count))
90206+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90207 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90208
90209 for (i = 0; i < nr_entries; i++) {
90210@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90211 {
90212 struct proc_dir_entry *pe;
90213
90214+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90215+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90216+#else
90217 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90218+#endif
90219 if (!pe)
90220 return -ENOMEM;
90221 return 0;
90222diff --git a/kernel/timer.c b/kernel/timer.c
90223index accfd24..e00f0c0 100644
90224--- a/kernel/timer.c
90225+++ b/kernel/timer.c
90226@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90227 /*
90228 * This function runs timers and the timer-tq in bottom half context.
90229 */
90230-static void run_timer_softirq(struct softirq_action *h)
90231+static __latent_entropy void run_timer_softirq(void)
90232 {
90233 struct tvec_base *base = __this_cpu_read(tvec_bases);
90234
90235@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90236 *
90237 * In all cases the return value is guaranteed to be non-negative.
90238 */
90239-signed long __sched schedule_timeout(signed long timeout)
90240+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90241 {
90242 struct timer_list timer;
90243 unsigned long expire;
90244diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90245index b418cb0..f879a3d 100644
90246--- a/kernel/trace/blktrace.c
90247+++ b/kernel/trace/blktrace.c
90248@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90249 struct blk_trace *bt = filp->private_data;
90250 char buf[16];
90251
90252- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90253+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90254
90255 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90256 }
90257@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90258 return 1;
90259
90260 bt = buf->chan->private_data;
90261- atomic_inc(&bt->dropped);
90262+ atomic_inc_unchecked(&bt->dropped);
90263 return 0;
90264 }
90265
90266@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90267
90268 bt->dir = dir;
90269 bt->dev = dev;
90270- atomic_set(&bt->dropped, 0);
90271+ atomic_set_unchecked(&bt->dropped, 0);
90272 INIT_LIST_HEAD(&bt->running_list);
90273
90274 ret = -EIO;
90275diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90276index cd7f76d..553c805 100644
90277--- a/kernel/trace/ftrace.c
90278+++ b/kernel/trace/ftrace.c
90279@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90280 if (unlikely(ftrace_disabled))
90281 return 0;
90282
90283+ ret = ftrace_arch_code_modify_prepare();
90284+ FTRACE_WARN_ON(ret);
90285+ if (ret)
90286+ return 0;
90287+
90288 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90289+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90290 if (ret) {
90291 ftrace_bug(ret, ip);
90292- return 0;
90293 }
90294- return 1;
90295+ return ret ? 0 : 1;
90296 }
90297
90298 /*
90299@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90300 if (!count)
90301 return 0;
90302
90303+ pax_open_kernel();
90304 sort(start, count, sizeof(*start),
90305 ftrace_cmp_ips, ftrace_swap_ips);
90306+ pax_close_kernel();
90307
90308 start_pg = ftrace_allocate_pages(count);
90309 if (!start_pg)
90310@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90311 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90312
90313 static int ftrace_graph_active;
90314-static struct notifier_block ftrace_suspend_notifier;
90315-
90316 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90317 {
90318 return 0;
90319@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90320 ftrace_graph_entry = ftrace_graph_entry_test;
90321 }
90322
90323+static struct notifier_block ftrace_suspend_notifier = {
90324+ .notifier_call = ftrace_suspend_notifier_call
90325+};
90326+
90327 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90328 trace_func_graph_ent_t entryfunc)
90329 {
90330@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90331 goto out;
90332 }
90333
90334- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90335 register_pm_notifier(&ftrace_suspend_notifier);
90336
90337 ftrace_graph_active++;
90338diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90339index fc4da2d..f3e800b 100644
90340--- a/kernel/trace/ring_buffer.c
90341+++ b/kernel/trace/ring_buffer.c
90342@@ -352,9 +352,9 @@ struct buffer_data_page {
90343 */
90344 struct buffer_page {
90345 struct list_head list; /* list of buffer pages */
90346- local_t write; /* index for next write */
90347+ local_unchecked_t write; /* index for next write */
90348 unsigned read; /* index for next read */
90349- local_t entries; /* entries on this page */
90350+ local_unchecked_t entries; /* entries on this page */
90351 unsigned long real_end; /* real end of data */
90352 struct buffer_data_page *page; /* Actual data page */
90353 };
90354@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90355 unsigned long last_overrun;
90356 local_t entries_bytes;
90357 local_t entries;
90358- local_t overrun;
90359- local_t commit_overrun;
90360+ local_unchecked_t overrun;
90361+ local_unchecked_t commit_overrun;
90362 local_t dropped_events;
90363 local_t committing;
90364 local_t commits;
90365@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90366 *
90367 * We add a counter to the write field to denote this.
90368 */
90369- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90370- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90371+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90372+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90373
90374 /*
90375 * Just make sure we have seen our old_write and synchronize
90376@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90377 * cmpxchg to only update if an interrupt did not already
90378 * do it for us. If the cmpxchg fails, we don't care.
90379 */
90380- (void)local_cmpxchg(&next_page->write, old_write, val);
90381- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90382+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90383+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90384
90385 /*
90386 * No need to worry about races with clearing out the commit.
90387@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90388
90389 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90390 {
90391- return local_read(&bpage->entries) & RB_WRITE_MASK;
90392+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90393 }
90394
90395 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90396 {
90397- return local_read(&bpage->write) & RB_WRITE_MASK;
90398+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90399 }
90400
90401 static int
90402@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90403 * bytes consumed in ring buffer from here.
90404 * Increment overrun to account for the lost events.
90405 */
90406- local_add(page_entries, &cpu_buffer->overrun);
90407+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90408 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90409 }
90410
90411@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90412 * it is our responsibility to update
90413 * the counters.
90414 */
90415- local_add(entries, &cpu_buffer->overrun);
90416+ local_add_unchecked(entries, &cpu_buffer->overrun);
90417 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90418
90419 /*
90420@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90421 if (tail == BUF_PAGE_SIZE)
90422 tail_page->real_end = 0;
90423
90424- local_sub(length, &tail_page->write);
90425+ local_sub_unchecked(length, &tail_page->write);
90426 return;
90427 }
90428
90429@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90430 rb_event_set_padding(event);
90431
90432 /* Set the write back to the previous setting */
90433- local_sub(length, &tail_page->write);
90434+ local_sub_unchecked(length, &tail_page->write);
90435 return;
90436 }
90437
90438@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90439
90440 /* Set write to end of buffer */
90441 length = (tail + length) - BUF_PAGE_SIZE;
90442- local_sub(length, &tail_page->write);
90443+ local_sub_unchecked(length, &tail_page->write);
90444 }
90445
90446 /*
90447@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90448 * about it.
90449 */
90450 if (unlikely(next_page == commit_page)) {
90451- local_inc(&cpu_buffer->commit_overrun);
90452+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90453 goto out_reset;
90454 }
90455
90456@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90457 cpu_buffer->tail_page) &&
90458 (cpu_buffer->commit_page ==
90459 cpu_buffer->reader_page))) {
90460- local_inc(&cpu_buffer->commit_overrun);
90461+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90462 goto out_reset;
90463 }
90464 }
90465@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90466 length += RB_LEN_TIME_EXTEND;
90467
90468 tail_page = cpu_buffer->tail_page;
90469- write = local_add_return(length, &tail_page->write);
90470+ write = local_add_return_unchecked(length, &tail_page->write);
90471
90472 /* set write to only the index of the write */
90473 write &= RB_WRITE_MASK;
90474@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90475 kmemcheck_annotate_bitfield(event, bitfield);
90476 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90477
90478- local_inc(&tail_page->entries);
90479+ local_inc_unchecked(&tail_page->entries);
90480
90481 /*
90482 * If this is the first commit on the page, then update
90483@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90484
90485 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90486 unsigned long write_mask =
90487- local_read(&bpage->write) & ~RB_WRITE_MASK;
90488+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90489 unsigned long event_length = rb_event_length(event);
90490 /*
90491 * This is on the tail page. It is possible that
90492@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90493 */
90494 old_index += write_mask;
90495 new_index += write_mask;
90496- index = local_cmpxchg(&bpage->write, old_index, new_index);
90497+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90498 if (index == old_index) {
90499 /* update counters */
90500 local_sub(event_length, &cpu_buffer->entries_bytes);
90501@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90502
90503 /* Do the likely case first */
90504 if (likely(bpage->page == (void *)addr)) {
90505- local_dec(&bpage->entries);
90506+ local_dec_unchecked(&bpage->entries);
90507 return;
90508 }
90509
90510@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90511 start = bpage;
90512 do {
90513 if (bpage->page == (void *)addr) {
90514- local_dec(&bpage->entries);
90515+ local_dec_unchecked(&bpage->entries);
90516 return;
90517 }
90518 rb_inc_page(cpu_buffer, &bpage);
90519@@ -3146,7 +3146,7 @@ static inline unsigned long
90520 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90521 {
90522 return local_read(&cpu_buffer->entries) -
90523- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90524+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90525 }
90526
90527 /**
90528@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90529 return 0;
90530
90531 cpu_buffer = buffer->buffers[cpu];
90532- ret = local_read(&cpu_buffer->overrun);
90533+ ret = local_read_unchecked(&cpu_buffer->overrun);
90534
90535 return ret;
90536 }
90537@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90538 return 0;
90539
90540 cpu_buffer = buffer->buffers[cpu];
90541- ret = local_read(&cpu_buffer->commit_overrun);
90542+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90543
90544 return ret;
90545 }
90546@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90547 /* if you care about this being correct, lock the buffer */
90548 for_each_buffer_cpu(buffer, cpu) {
90549 cpu_buffer = buffer->buffers[cpu];
90550- overruns += local_read(&cpu_buffer->overrun);
90551+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90552 }
90553
90554 return overruns;
90555@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90556 /*
90557 * Reset the reader page to size zero.
90558 */
90559- local_set(&cpu_buffer->reader_page->write, 0);
90560- local_set(&cpu_buffer->reader_page->entries, 0);
90561+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90562+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90563 local_set(&cpu_buffer->reader_page->page->commit, 0);
90564 cpu_buffer->reader_page->real_end = 0;
90565
90566@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90567 * want to compare with the last_overrun.
90568 */
90569 smp_mb();
90570- overwrite = local_read(&(cpu_buffer->overrun));
90571+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90572
90573 /*
90574 * Here's the tricky part.
90575@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90576
90577 cpu_buffer->head_page
90578 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90579- local_set(&cpu_buffer->head_page->write, 0);
90580- local_set(&cpu_buffer->head_page->entries, 0);
90581+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90582+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90583 local_set(&cpu_buffer->head_page->page->commit, 0);
90584
90585 cpu_buffer->head_page->read = 0;
90586@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90587
90588 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90589 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90590- local_set(&cpu_buffer->reader_page->write, 0);
90591- local_set(&cpu_buffer->reader_page->entries, 0);
90592+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90593+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90594 local_set(&cpu_buffer->reader_page->page->commit, 0);
90595 cpu_buffer->reader_page->read = 0;
90596
90597 local_set(&cpu_buffer->entries_bytes, 0);
90598- local_set(&cpu_buffer->overrun, 0);
90599- local_set(&cpu_buffer->commit_overrun, 0);
90600+ local_set_unchecked(&cpu_buffer->overrun, 0);
90601+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90602 local_set(&cpu_buffer->dropped_events, 0);
90603 local_set(&cpu_buffer->entries, 0);
90604 local_set(&cpu_buffer->committing, 0);
90605@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90606 rb_init_page(bpage);
90607 bpage = reader->page;
90608 reader->page = *data_page;
90609- local_set(&reader->write, 0);
90610- local_set(&reader->entries, 0);
90611+ local_set_unchecked(&reader->write, 0);
90612+ local_set_unchecked(&reader->entries, 0);
90613 reader->read = 0;
90614 *data_page = bpage;
90615
90616diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90617index 24c1f23..781fd73f 100644
90618--- a/kernel/trace/trace.c
90619+++ b/kernel/trace/trace.c
90620@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90621 return 0;
90622 }
90623
90624-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90625+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90626 {
90627 /* do nothing if flag is already set */
90628 if (!!(trace_flags & mask) == !!enabled)
90629diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90630index 02b592f..f971546 100644
90631--- a/kernel/trace/trace.h
90632+++ b/kernel/trace/trace.h
90633@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90634 void trace_printk_init_buffers(void);
90635 void trace_printk_start_comm(void);
90636 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90637-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90638+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90639
90640 /*
90641 * Normal trace_printk() and friends allocates special buffers
90642diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90643index 26dc348..8708ca7 100644
90644--- a/kernel/trace/trace_clock.c
90645+++ b/kernel/trace/trace_clock.c
90646@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90647 return now;
90648 }
90649
90650-static atomic64_t trace_counter;
90651+static atomic64_unchecked_t trace_counter;
90652
90653 /*
90654 * trace_clock_counter(): simply an atomic counter.
90655@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90656 */
90657 u64 notrace trace_clock_counter(void)
90658 {
90659- return atomic64_add_return(1, &trace_counter);
90660+ return atomic64_inc_return_unchecked(&trace_counter);
90661 }
90662diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90663index 7b16d40..1b2875d 100644
90664--- a/kernel/trace/trace_events.c
90665+++ b/kernel/trace/trace_events.c
90666@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90667 return 0;
90668 }
90669
90670-struct ftrace_module_file_ops;
90671 static void __add_event_to_tracers(struct ftrace_event_call *call);
90672
90673 /* Add an additional event_call dynamically */
90674diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90675index 0abd9b8..6a663a2 100644
90676--- a/kernel/trace/trace_mmiotrace.c
90677+++ b/kernel/trace/trace_mmiotrace.c
90678@@ -24,7 +24,7 @@ struct header_iter {
90679 static struct trace_array *mmio_trace_array;
90680 static bool overrun_detected;
90681 static unsigned long prev_overruns;
90682-static atomic_t dropped_count;
90683+static atomic_unchecked_t dropped_count;
90684
90685 static void mmio_reset_data(struct trace_array *tr)
90686 {
90687@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90688
90689 static unsigned long count_overruns(struct trace_iterator *iter)
90690 {
90691- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90692+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90693 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90694
90695 if (over > prev_overruns)
90696@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90697 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90698 sizeof(*entry), 0, pc);
90699 if (!event) {
90700- atomic_inc(&dropped_count);
90701+ atomic_inc_unchecked(&dropped_count);
90702 return;
90703 }
90704 entry = ring_buffer_event_data(event);
90705@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90706 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90707 sizeof(*entry), 0, pc);
90708 if (!event) {
90709- atomic_inc(&dropped_count);
90710+ atomic_inc_unchecked(&dropped_count);
90711 return;
90712 }
90713 entry = ring_buffer_event_data(event);
90714diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90715index ed32284..884d6c3 100644
90716--- a/kernel/trace/trace_output.c
90717+++ b/kernel/trace/trace_output.c
90718@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90719
90720 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90721 if (!IS_ERR(p)) {
90722- p = mangle_path(s->buffer + s->len, p, "\n");
90723+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90724 if (p) {
90725 s->len = p - s->buffer;
90726 return 1;
90727@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90728 goto out;
90729 }
90730
90731+ pax_open_kernel();
90732 if (event->funcs->trace == NULL)
90733- event->funcs->trace = trace_nop_print;
90734+ *(void **)&event->funcs->trace = trace_nop_print;
90735 if (event->funcs->raw == NULL)
90736- event->funcs->raw = trace_nop_print;
90737+ *(void **)&event->funcs->raw = trace_nop_print;
90738 if (event->funcs->hex == NULL)
90739- event->funcs->hex = trace_nop_print;
90740+ *(void **)&event->funcs->hex = trace_nop_print;
90741 if (event->funcs->binary == NULL)
90742- event->funcs->binary = trace_nop_print;
90743+ *(void **)&event->funcs->binary = trace_nop_print;
90744+ pax_close_kernel();
90745
90746 key = event->type & (EVENT_HASHSIZE - 1);
90747
90748diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90749index e6be585..d73ae5e 100644
90750--- a/kernel/trace/trace_stack.c
90751+++ b/kernel/trace/trace_stack.c
90752@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90753 return;
90754
90755 /* we do not handle interrupt stacks yet */
90756- if (!object_is_on_stack(stack))
90757+ if (!object_starts_on_stack(stack))
90758 return;
90759
90760 local_irq_save(flags);
90761diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90762index 80a57af..7f5a7ff 100644
90763--- a/kernel/user_namespace.c
90764+++ b/kernel/user_namespace.c
90765@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90766 !kgid_has_mapping(parent_ns, group))
90767 return -EPERM;
90768
90769+#ifdef CONFIG_GRKERNSEC
90770+ /*
90771+ * This doesn't really inspire confidence:
90772+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90773+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90774+ * Increases kernel attack surface in areas developers
90775+ * previously cared little about ("low importance due
90776+ * to requiring "root" capability")
90777+ * To be removed when this code receives *proper* review
90778+ */
90779+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90780+ !capable(CAP_SETGID))
90781+ return -EPERM;
90782+#endif
90783+
90784 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90785 if (!ns)
90786 return -ENOMEM;
90787@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90788 if (atomic_read(&current->mm->mm_users) > 1)
90789 return -EINVAL;
90790
90791- if (current->fs->users != 1)
90792+ if (atomic_read(&current->fs->users) != 1)
90793 return -EINVAL;
90794
90795 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90796diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90797index 4f69f9a..7c6f8f8 100644
90798--- a/kernel/utsname_sysctl.c
90799+++ b/kernel/utsname_sysctl.c
90800@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90801 static int proc_do_uts_string(ctl_table *table, int write,
90802 void __user *buffer, size_t *lenp, loff_t *ppos)
90803 {
90804- struct ctl_table uts_table;
90805+ ctl_table_no_const uts_table;
90806 int r;
90807 memcpy(&uts_table, table, sizeof(uts_table));
90808 uts_table.data = get_uts(table, write);
90809diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90810index 4431610..4265616 100644
90811--- a/kernel/watchdog.c
90812+++ b/kernel/watchdog.c
90813@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90814 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90815 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90816
90817-static struct smp_hotplug_thread watchdog_threads = {
90818+static struct smp_hotplug_thread watchdog_threads __read_only = {
90819 .store = &softlockup_watchdog,
90820 .thread_should_run = watchdog_should_run,
90821 .thread_fn = watchdog,
90822diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90823index 193e977..26dd63f 100644
90824--- a/kernel/workqueue.c
90825+++ b/kernel/workqueue.c
90826@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90827 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90828 worker_flags |= WORKER_REBOUND;
90829 worker_flags &= ~WORKER_UNBOUND;
90830- ACCESS_ONCE(worker->flags) = worker_flags;
90831+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
90832 }
90833
90834 spin_unlock_irq(&pool->lock);
90835diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90836index a48abea..e108def 100644
90837--- a/lib/Kconfig.debug
90838+++ b/lib/Kconfig.debug
90839@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
90840
90841 config DEBUG_WW_MUTEX_SLOWPATH
90842 bool "Wait/wound mutex debugging: Slowpath testing"
90843- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90844+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90845 select DEBUG_LOCK_ALLOC
90846 select DEBUG_SPINLOCK
90847 select DEBUG_MUTEXES
90848@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90849
90850 config DEBUG_LOCK_ALLOC
90851 bool "Lock debugging: detect incorrect freeing of live locks"
90852- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90853+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90854 select DEBUG_SPINLOCK
90855 select DEBUG_MUTEXES
90856 select LOCKDEP
90857@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
90858
90859 config PROVE_LOCKING
90860 bool "Lock debugging: prove locking correctness"
90861- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90862+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90863 select LOCKDEP
90864 select DEBUG_SPINLOCK
90865 select DEBUG_MUTEXES
90866@@ -932,7 +932,7 @@ config LOCKDEP
90867
90868 config LOCK_STAT
90869 bool "Lock usage statistics"
90870- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90871+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90872 select LOCKDEP
90873 select DEBUG_SPINLOCK
90874 select DEBUG_MUTEXES
90875@@ -1394,6 +1394,7 @@ config LATENCYTOP
90876 depends on DEBUG_KERNEL
90877 depends on STACKTRACE_SUPPORT
90878 depends on PROC_FS
90879+ depends on !GRKERNSEC_HIDESYM
90880 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90881 select KALLSYMS
90882 select KALLSYMS_ALL
90883@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90884 config DEBUG_STRICT_USER_COPY_CHECKS
90885 bool "Strict user copy size checks"
90886 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90887- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90888+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90889 help
90890 Enabling this option turns a certain set of sanity checks for user
90891 copy operations into compile time failures.
90892@@ -1529,7 +1530,7 @@ endmenu # runtime tests
90893
90894 config PROVIDE_OHCI1394_DMA_INIT
90895 bool "Remote debugging over FireWire early on boot"
90896- depends on PCI && X86
90897+ depends on PCI && X86 && !GRKERNSEC
90898 help
90899 If you want to debug problems which hang or crash the kernel early
90900 on boot and the crashing machine has a FireWire port, you can use
90901diff --git a/lib/Makefile b/lib/Makefile
90902index 48140e3..de854e5 100644
90903--- a/lib/Makefile
90904+++ b/lib/Makefile
90905@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90906 obj-$(CONFIG_BTREE) += btree.o
90907 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90908 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90909-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90910+obj-y += list_debug.o
90911 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90912
90913 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90914diff --git a/lib/average.c b/lib/average.c
90915index 114d1be..ab0350c 100644
90916--- a/lib/average.c
90917+++ b/lib/average.c
90918@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
90919 {
90920 unsigned long internal = ACCESS_ONCE(avg->internal);
90921
90922- ACCESS_ONCE(avg->internal) = internal ?
90923+ ACCESS_ONCE_RW(avg->internal) = internal ?
90924 (((internal << avg->weight) - internal) +
90925 (val << avg->factor)) >> avg->weight :
90926 (val << avg->factor);
90927diff --git a/lib/bitmap.c b/lib/bitmap.c
90928index 06f7e4f..f3cf2b0 100644
90929--- a/lib/bitmap.c
90930+++ b/lib/bitmap.c
90931@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90932 {
90933 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90934 u32 chunk;
90935- const char __user __force *ubuf = (const char __user __force *)buf;
90936+ const char __user *ubuf = (const char __force_user *)buf;
90937
90938 bitmap_zero(maskp, nmaskbits);
90939
90940@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90941 {
90942 if (!access_ok(VERIFY_READ, ubuf, ulen))
90943 return -EFAULT;
90944- return __bitmap_parse((const char __force *)ubuf,
90945+ return __bitmap_parse((const char __force_kernel *)ubuf,
90946 ulen, 1, maskp, nmaskbits);
90947
90948 }
90949@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90950 {
90951 unsigned a, b;
90952 int c, old_c, totaldigits;
90953- const char __user __force *ubuf = (const char __user __force *)buf;
90954+ const char __user *ubuf = (const char __force_user *)buf;
90955 int exp_digit, in_range;
90956
90957 totaldigits = c = 0;
90958@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90959 {
90960 if (!access_ok(VERIFY_READ, ubuf, ulen))
90961 return -EFAULT;
90962- return __bitmap_parselist((const char __force *)ubuf,
90963+ return __bitmap_parselist((const char __force_kernel *)ubuf,
90964 ulen, 1, maskp, nmaskbits);
90965 }
90966 EXPORT_SYMBOL(bitmap_parselist_user);
90967diff --git a/lib/bug.c b/lib/bug.c
90968index 1686034..a9c00c8 100644
90969--- a/lib/bug.c
90970+++ b/lib/bug.c
90971@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90972 return BUG_TRAP_TYPE_NONE;
90973
90974 bug = find_bug(bugaddr);
90975+ if (!bug)
90976+ return BUG_TRAP_TYPE_NONE;
90977
90978 file = NULL;
90979 line = 0;
90980diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90981index e0731c3..ad66444 100644
90982--- a/lib/debugobjects.c
90983+++ b/lib/debugobjects.c
90984@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90985 if (limit > 4)
90986 return;
90987
90988- is_on_stack = object_is_on_stack(addr);
90989+ is_on_stack = object_starts_on_stack(addr);
90990 if (is_on_stack == onstack)
90991 return;
90992
90993diff --git a/lib/devres.c b/lib/devres.c
90994index 8235331..5881053 100644
90995--- a/lib/devres.c
90996+++ b/lib/devres.c
90997@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90998 void devm_iounmap(struct device *dev, void __iomem *addr)
90999 {
91000 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91001- (void *)addr));
91002+ (void __force *)addr));
91003 iounmap(addr);
91004 }
91005 EXPORT_SYMBOL(devm_iounmap);
91006@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91007 {
91008 ioport_unmap(addr);
91009 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91010- devm_ioport_map_match, (void *)addr));
91011+ devm_ioport_map_match, (void __force *)addr));
91012 }
91013 EXPORT_SYMBOL(devm_ioport_unmap);
91014 #endif /* CONFIG_HAS_IOPORT */
91015diff --git a/lib/div64.c b/lib/div64.c
91016index 4382ad7..08aa558 100644
91017--- a/lib/div64.c
91018+++ b/lib/div64.c
91019@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91020 EXPORT_SYMBOL(__div64_32);
91021
91022 #ifndef div_s64_rem
91023-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91024+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91025 {
91026 u64 quotient;
91027
91028@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91029 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91030 */
91031 #ifndef div64_u64
91032-u64 div64_u64(u64 dividend, u64 divisor)
91033+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91034 {
91035 u32 high = divisor >> 32;
91036 u64 quot;
91037diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91038index 98f2d7e..899da5c 100644
91039--- a/lib/dma-debug.c
91040+++ b/lib/dma-debug.c
91041@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91042
91043 void dma_debug_add_bus(struct bus_type *bus)
91044 {
91045- struct notifier_block *nb;
91046+ notifier_block_no_const *nb;
91047
91048 if (global_disable)
91049 return;
91050@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91051
91052 static void check_for_stack(struct device *dev, void *addr)
91053 {
91054- if (object_is_on_stack(addr))
91055+ if (object_starts_on_stack(addr))
91056 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91057 "stack [addr=%p]\n", addr);
91058 }
91059diff --git a/lib/hash.c b/lib/hash.c
91060index fea973f..386626f 100644
91061--- a/lib/hash.c
91062+++ b/lib/hash.c
91063@@ -14,7 +14,7 @@
91064 #include <linux/hash.h>
91065 #include <linux/cache.h>
91066
91067-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91068+static struct fast_hash_ops arch_hash_ops __read_only = {
91069 .hash = jhash,
91070 .hash2 = jhash2,
91071 };
91072diff --git a/lib/inflate.c b/lib/inflate.c
91073index 013a761..c28f3fc 100644
91074--- a/lib/inflate.c
91075+++ b/lib/inflate.c
91076@@ -269,7 +269,7 @@ static void free(void *where)
91077 malloc_ptr = free_mem_ptr;
91078 }
91079 #else
91080-#define malloc(a) kmalloc(a, GFP_KERNEL)
91081+#define malloc(a) kmalloc((a), GFP_KERNEL)
91082 #define free(a) kfree(a)
91083 #endif
91084
91085diff --git a/lib/ioremap.c b/lib/ioremap.c
91086index 0c9216c..863bd89 100644
91087--- a/lib/ioremap.c
91088+++ b/lib/ioremap.c
91089@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91090 unsigned long next;
91091
91092 phys_addr -= addr;
91093- pmd = pmd_alloc(&init_mm, pud, addr);
91094+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91095 if (!pmd)
91096 return -ENOMEM;
91097 do {
91098@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91099 unsigned long next;
91100
91101 phys_addr -= addr;
91102- pud = pud_alloc(&init_mm, pgd, addr);
91103+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91104 if (!pud)
91105 return -ENOMEM;
91106 do {
91107diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91108index bd2bea9..6b3c95e 100644
91109--- a/lib/is_single_threaded.c
91110+++ b/lib/is_single_threaded.c
91111@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91112 struct task_struct *p, *t;
91113 bool ret;
91114
91115+ if (!mm)
91116+ return true;
91117+
91118 if (atomic_read(&task->signal->live) != 1)
91119 return false;
91120
91121diff --git a/lib/kobject.c b/lib/kobject.c
91122index cb14aea..8c53cdb 100644
91123--- a/lib/kobject.c
91124+++ b/lib/kobject.c
91125@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91126
91127
91128 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91129-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91130+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91131
91132-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91133+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91134 {
91135 enum kobj_ns_type type = ops->type;
91136 int error;
91137diff --git a/lib/list_debug.c b/lib/list_debug.c
91138index c24c2f7..f0296f4 100644
91139--- a/lib/list_debug.c
91140+++ b/lib/list_debug.c
91141@@ -11,7 +11,9 @@
91142 #include <linux/bug.h>
91143 #include <linux/kernel.h>
91144 #include <linux/rculist.h>
91145+#include <linux/mm.h>
91146
91147+#ifdef CONFIG_DEBUG_LIST
91148 /*
91149 * Insert a new entry between two known consecutive entries.
91150 *
91151@@ -19,21 +21,40 @@
91152 * the prev/next entries already!
91153 */
91154
91155+static bool __list_add_debug(struct list_head *new,
91156+ struct list_head *prev,
91157+ struct list_head *next)
91158+{
91159+ if (unlikely(next->prev != prev)) {
91160+ printk(KERN_ERR "list_add corruption. next->prev should be "
91161+ "prev (%p), but was %p. (next=%p).\n",
91162+ prev, next->prev, next);
91163+ BUG();
91164+ return false;
91165+ }
91166+ if (unlikely(prev->next != next)) {
91167+ printk(KERN_ERR "list_add corruption. prev->next should be "
91168+ "next (%p), but was %p. (prev=%p).\n",
91169+ next, prev->next, prev);
91170+ BUG();
91171+ return false;
91172+ }
91173+ if (unlikely(new == prev || new == next)) {
91174+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91175+ new, prev, next);
91176+ BUG();
91177+ return false;
91178+ }
91179+ return true;
91180+}
91181+
91182 void __list_add(struct list_head *new,
91183- struct list_head *prev,
91184- struct list_head *next)
91185+ struct list_head *prev,
91186+ struct list_head *next)
91187 {
91188- WARN(next->prev != prev,
91189- "list_add corruption. next->prev should be "
91190- "prev (%p), but was %p. (next=%p).\n",
91191- prev, next->prev, next);
91192- WARN(prev->next != next,
91193- "list_add corruption. prev->next should be "
91194- "next (%p), but was %p. (prev=%p).\n",
91195- next, prev->next, prev);
91196- WARN(new == prev || new == next,
91197- "list_add double add: new=%p, prev=%p, next=%p.\n",
91198- new, prev, next);
91199+ if (!__list_add_debug(new, prev, next))
91200+ return;
91201+
91202 next->prev = new;
91203 new->next = next;
91204 new->prev = prev;
91205@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91206 }
91207 EXPORT_SYMBOL(__list_add);
91208
91209-void __list_del_entry(struct list_head *entry)
91210+static bool __list_del_entry_debug(struct list_head *entry)
91211 {
91212 struct list_head *prev, *next;
91213
91214 prev = entry->prev;
91215 next = entry->next;
91216
91217- if (WARN(next == LIST_POISON1,
91218- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91219- entry, LIST_POISON1) ||
91220- WARN(prev == LIST_POISON2,
91221- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91222- entry, LIST_POISON2) ||
91223- WARN(prev->next != entry,
91224- "list_del corruption. prev->next should be %p, "
91225- "but was %p\n", entry, prev->next) ||
91226- WARN(next->prev != entry,
91227- "list_del corruption. next->prev should be %p, "
91228- "but was %p\n", entry, next->prev))
91229+ if (unlikely(next == LIST_POISON1)) {
91230+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91231+ entry, LIST_POISON1);
91232+ BUG();
91233+ return false;
91234+ }
91235+ if (unlikely(prev == LIST_POISON2)) {
91236+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91237+ entry, LIST_POISON2);
91238+ BUG();
91239+ return false;
91240+ }
91241+ if (unlikely(entry->prev->next != entry)) {
91242+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91243+ "but was %p\n", entry, prev->next);
91244+ BUG();
91245+ return false;
91246+ }
91247+ if (unlikely(entry->next->prev != entry)) {
91248+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91249+ "but was %p\n", entry, next->prev);
91250+ BUG();
91251+ return false;
91252+ }
91253+ return true;
91254+}
91255+
91256+void __list_del_entry(struct list_head *entry)
91257+{
91258+ if (!__list_del_entry_debug(entry))
91259 return;
91260
91261- __list_del(prev, next);
91262+ __list_del(entry->prev, entry->next);
91263 }
91264 EXPORT_SYMBOL(__list_del_entry);
91265
91266@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91267 void __list_add_rcu(struct list_head *new,
91268 struct list_head *prev, struct list_head *next)
91269 {
91270- WARN(next->prev != prev,
91271- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91272- prev, next->prev, next);
91273- WARN(prev->next != next,
91274- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91275- next, prev->next, prev);
91276+ if (!__list_add_debug(new, prev, next))
91277+ return;
91278+
91279 new->next = next;
91280 new->prev = prev;
91281 rcu_assign_pointer(list_next_rcu(prev), new);
91282 next->prev = new;
91283 }
91284 EXPORT_SYMBOL(__list_add_rcu);
91285+#endif
91286+
91287+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91288+{
91289+#ifdef CONFIG_DEBUG_LIST
91290+ if (!__list_add_debug(new, prev, next))
91291+ return;
91292+#endif
91293+
91294+ pax_open_kernel();
91295+ next->prev = new;
91296+ new->next = next;
91297+ new->prev = prev;
91298+ prev->next = new;
91299+ pax_close_kernel();
91300+}
91301+EXPORT_SYMBOL(__pax_list_add);
91302+
91303+void pax_list_del(struct list_head *entry)
91304+{
91305+#ifdef CONFIG_DEBUG_LIST
91306+ if (!__list_del_entry_debug(entry))
91307+ return;
91308+#endif
91309+
91310+ pax_open_kernel();
91311+ __list_del(entry->prev, entry->next);
91312+ entry->next = LIST_POISON1;
91313+ entry->prev = LIST_POISON2;
91314+ pax_close_kernel();
91315+}
91316+EXPORT_SYMBOL(pax_list_del);
91317+
91318+void pax_list_del_init(struct list_head *entry)
91319+{
91320+ pax_open_kernel();
91321+ __list_del(entry->prev, entry->next);
91322+ INIT_LIST_HEAD(entry);
91323+ pax_close_kernel();
91324+}
91325+EXPORT_SYMBOL(pax_list_del_init);
91326+
91327+void __pax_list_add_rcu(struct list_head *new,
91328+ struct list_head *prev, struct list_head *next)
91329+{
91330+#ifdef CONFIG_DEBUG_LIST
91331+ if (!__list_add_debug(new, prev, next))
91332+ return;
91333+#endif
91334+
91335+ pax_open_kernel();
91336+ new->next = next;
91337+ new->prev = prev;
91338+ rcu_assign_pointer(list_next_rcu(prev), new);
91339+ next->prev = new;
91340+ pax_close_kernel();
91341+}
91342+EXPORT_SYMBOL(__pax_list_add_rcu);
91343+
91344+void pax_list_del_rcu(struct list_head *entry)
91345+{
91346+#ifdef CONFIG_DEBUG_LIST
91347+ if (!__list_del_entry_debug(entry))
91348+ return;
91349+#endif
91350+
91351+ pax_open_kernel();
91352+ __list_del(entry->prev, entry->next);
91353+ entry->next = LIST_POISON1;
91354+ entry->prev = LIST_POISON2;
91355+ pax_close_kernel();
91356+}
91357+EXPORT_SYMBOL(pax_list_del_rcu);
91358diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91359index 963b703..438bc51 100644
91360--- a/lib/percpu-refcount.c
91361+++ b/lib/percpu-refcount.c
91362@@ -29,7 +29,7 @@
91363 * can't hit 0 before we've added up all the percpu refs.
91364 */
91365
91366-#define PCPU_COUNT_BIAS (1U << 31)
91367+#define PCPU_COUNT_BIAS (1U << 30)
91368
91369 /**
91370 * percpu_ref_init - initialize a percpu refcount
91371diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91372index bd4a8df..9e4804f 100644
91373--- a/lib/radix-tree.c
91374+++ b/lib/radix-tree.c
91375@@ -93,7 +93,7 @@ struct radix_tree_preload {
91376 int nr;
91377 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91378 };
91379-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91380+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91381
91382 static inline void *ptr_to_indirect(void *ptr)
91383 {
91384diff --git a/lib/random32.c b/lib/random32.c
91385index 6148967..009bfe8 100644
91386--- a/lib/random32.c
91387+++ b/lib/random32.c
91388@@ -44,7 +44,7 @@
91389 static void __init prandom_state_selftest(void);
91390 #endif
91391
91392-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91393+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91394
91395 /**
91396 * prandom_u32_state - seeded pseudo-random number generator.
91397diff --git a/lib/rbtree.c b/lib/rbtree.c
91398index 65f4eff..2cfa167 100644
91399--- a/lib/rbtree.c
91400+++ b/lib/rbtree.c
91401@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91402 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91403
91404 static const struct rb_augment_callbacks dummy_callbacks = {
91405- dummy_propagate, dummy_copy, dummy_rotate
91406+ .propagate = dummy_propagate,
91407+ .copy = dummy_copy,
91408+ .rotate = dummy_rotate
91409 };
91410
91411 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91412diff --git a/lib/show_mem.c b/lib/show_mem.c
91413index 0922579..9d7adb9 100644
91414--- a/lib/show_mem.c
91415+++ b/lib/show_mem.c
91416@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91417 quicklist_total_size());
91418 #endif
91419 #ifdef CONFIG_MEMORY_FAILURE
91420- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91421+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91422 #endif
91423 }
91424diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91425index bb2b201..46abaf9 100644
91426--- a/lib/strncpy_from_user.c
91427+++ b/lib/strncpy_from_user.c
91428@@ -21,7 +21,7 @@
91429 */
91430 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91431 {
91432- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91433+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91434 long res = 0;
91435
91436 /*
91437diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91438index a28df52..3d55877 100644
91439--- a/lib/strnlen_user.c
91440+++ b/lib/strnlen_user.c
91441@@ -26,7 +26,7 @@
91442 */
91443 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91444 {
91445- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91446+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91447 long align, res = 0;
91448 unsigned long c;
91449
91450diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91451index b604b83..c0547f6 100644
91452--- a/lib/swiotlb.c
91453+++ b/lib/swiotlb.c
91454@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91455
91456 void
91457 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91458- dma_addr_t dev_addr)
91459+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91460 {
91461 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91462
91463diff --git a/lib/usercopy.c b/lib/usercopy.c
91464index 4f5b1dd..7cab418 100644
91465--- a/lib/usercopy.c
91466+++ b/lib/usercopy.c
91467@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91468 WARN(1, "Buffer overflow detected!\n");
91469 }
91470 EXPORT_SYMBOL(copy_from_user_overflow);
91471+
91472+void copy_to_user_overflow(void)
91473+{
91474+ WARN(1, "Buffer overflow detected!\n");
91475+}
91476+EXPORT_SYMBOL(copy_to_user_overflow);
91477diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91478index 185b6d3..823c48c 100644
91479--- a/lib/vsprintf.c
91480+++ b/lib/vsprintf.c
91481@@ -16,6 +16,9 @@
91482 * - scnprintf and vscnprintf
91483 */
91484
91485+#ifdef CONFIG_GRKERNSEC_HIDESYM
91486+#define __INCLUDED_BY_HIDESYM 1
91487+#endif
91488 #include <stdarg.h>
91489 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91490 #include <linux/types.h>
91491@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91492 return number(buf, end, num, spec);
91493 }
91494
91495+#ifdef CONFIG_GRKERNSEC_HIDESYM
91496+int kptr_restrict __read_mostly = 2;
91497+#else
91498 int kptr_restrict __read_mostly;
91499+#endif
91500
91501 /*
91502 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91503@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91504 * - 'f' For simple symbolic function names without offset
91505 * - 'S' For symbolic direct pointers with offset
91506 * - 's' For symbolic direct pointers without offset
91507+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91508 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91509 * - 'B' For backtraced symbolic direct pointers with offset
91510 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91511@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91512
91513 if (!ptr && *fmt != 'K') {
91514 /*
91515- * Print (null) with the same width as a pointer so it makes
91516+ * Print (nil) with the same width as a pointer so it makes
91517 * tabular output look nice.
91518 */
91519 if (spec.field_width == -1)
91520 spec.field_width = default_width;
91521- return string(buf, end, "(null)", spec);
91522+ return string(buf, end, "(nil)", spec);
91523 }
91524
91525 switch (*fmt) {
91526@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91527 /* Fallthrough */
91528 case 'S':
91529 case 's':
91530+#ifdef CONFIG_GRKERNSEC_HIDESYM
91531+ break;
91532+#else
91533+ return symbol_string(buf, end, ptr, spec, fmt);
91534+#endif
91535+ case 'A':
91536 case 'B':
91537 return symbol_string(buf, end, ptr, spec, fmt);
91538 case 'R':
91539@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91540 va_end(va);
91541 return buf;
91542 }
91543+ case 'P':
91544+ break;
91545 case 'K':
91546 /*
91547 * %pK cannot be used in IRQ context because its test
91548@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91549 ((const struct file *)ptr)->f_path.dentry,
91550 spec, fmt);
91551 }
91552+
91553+#ifdef CONFIG_GRKERNSEC_HIDESYM
91554+ /* 'P' = approved pointers to copy to userland,
91555+ as in the /proc/kallsyms case, as we make it display nothing
91556+ for non-root users, and the real contents for root users
91557+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91558+ above
91559+ */
91560+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91561+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91562+ dump_stack();
91563+ ptr = NULL;
91564+ }
91565+#endif
91566+
91567 spec.flags |= SMALL;
91568 if (spec.field_width == -1) {
91569 spec.field_width = default_width;
91570@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91571 typeof(type) value; \
91572 if (sizeof(type) == 8) { \
91573 args = PTR_ALIGN(args, sizeof(u32)); \
91574- *(u32 *)&value = *(u32 *)args; \
91575- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91576+ *(u32 *)&value = *(const u32 *)args; \
91577+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91578 } else { \
91579 args = PTR_ALIGN(args, sizeof(type)); \
91580- value = *(typeof(type) *)args; \
91581+ value = *(const typeof(type) *)args; \
91582 } \
91583 args += sizeof(type); \
91584 value; \
91585@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91586 case FORMAT_TYPE_STR: {
91587 const char *str_arg = args;
91588 args += strlen(str_arg) + 1;
91589- str = string(str, end, (char *)str_arg, spec);
91590+ str = string(str, end, str_arg, spec);
91591 break;
91592 }
91593
91594diff --git a/localversion-grsec b/localversion-grsec
91595new file mode 100644
91596index 0000000..7cd6065
91597--- /dev/null
91598+++ b/localversion-grsec
91599@@ -0,0 +1 @@
91600+-grsec
91601diff --git a/mm/Kconfig b/mm/Kconfig
91602index 2888024..c15a810 100644
91603--- a/mm/Kconfig
91604+++ b/mm/Kconfig
91605@@ -326,10 +326,11 @@ config KSM
91606 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91607
91608 config DEFAULT_MMAP_MIN_ADDR
91609- int "Low address space to protect from user allocation"
91610+ int "Low address space to protect from user allocation"
91611 depends on MMU
91612- default 4096
91613- help
91614+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91615+ default 65536
91616+ help
91617 This is the portion of low virtual memory which should be protected
91618 from userspace allocation. Keeping a user from writing to low pages
91619 can help reduce the impact of kernel NULL pointer bugs.
91620@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91621
91622 config HWPOISON_INJECT
91623 tristate "HWPoison pages injector"
91624- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91625+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91626 select PROC_PAGE_MONITOR
91627
91628 config NOMMU_INITIAL_TRIM_EXCESS
91629diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91630index 09d9591..165bb75 100644
91631--- a/mm/backing-dev.c
91632+++ b/mm/backing-dev.c
91633@@ -12,7 +12,7 @@
91634 #include <linux/device.h>
91635 #include <trace/events/writeback.h>
91636
91637-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91638+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91639
91640 struct backing_dev_info default_backing_dev_info = {
91641 .name = "default",
91642@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91643 return err;
91644
91645 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91646- atomic_long_inc_return(&bdi_seq));
91647+ atomic_long_inc_return_unchecked(&bdi_seq));
91648 if (err) {
91649 bdi_destroy(bdi);
91650 return err;
91651diff --git a/mm/filemap.c b/mm/filemap.c
91652index 7a13f6a..e52e841 100644
91653--- a/mm/filemap.c
91654+++ b/mm/filemap.c
91655@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91656 struct address_space *mapping = file->f_mapping;
91657
91658 if (!mapping->a_ops->readpage)
91659- return -ENOEXEC;
91660+ return -ENODEV;
91661 file_accessed(file);
91662 vma->vm_ops = &generic_file_vm_ops;
91663 return 0;
91664@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91665
91666 while (bytes) {
91667 char __user *buf = iov->iov_base + base;
91668- int copy = min(bytes, iov->iov_len - base);
91669+ size_t copy = min(bytes, iov->iov_len - base);
91670
91671 base = 0;
91672 left = __copy_from_user_inatomic(vaddr, buf, copy);
91673@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91674 BUG_ON(!in_atomic());
91675 kaddr = kmap_atomic(page);
91676 if (likely(i->nr_segs == 1)) {
91677- int left;
91678+ size_t left;
91679 char __user *buf = i->iov->iov_base + i->iov_offset;
91680 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91681 copied = bytes - left;
91682@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91683
91684 kaddr = kmap(page);
91685 if (likely(i->nr_segs == 1)) {
91686- int left;
91687+ size_t left;
91688 char __user *buf = i->iov->iov_base + i->iov_offset;
91689 left = __copy_from_user(kaddr + offset, buf, bytes);
91690 copied = bytes - left;
91691@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91692 * zero-length segments (without overruning the iovec).
91693 */
91694 while (bytes || unlikely(i->count && !iov->iov_len)) {
91695- int copy;
91696+ size_t copy;
91697
91698 copy = min(bytes, iov->iov_len - base);
91699 BUG_ON(!i->count || i->count < copy);
91700@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91701 *pos = i_size_read(inode);
91702
91703 if (limit != RLIM_INFINITY) {
91704+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91705 if (*pos >= limit) {
91706 send_sig(SIGXFSZ, current, 0);
91707 return -EFBIG;
91708diff --git a/mm/fremap.c b/mm/fremap.c
91709index 34feba6..315fe78 100644
91710--- a/mm/fremap.c
91711+++ b/mm/fremap.c
91712@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91713 retry:
91714 vma = find_vma(mm, start);
91715
91716+#ifdef CONFIG_PAX_SEGMEXEC
91717+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91718+ goto out;
91719+#endif
91720+
91721 /*
91722 * Make sure the vma is shared, that it supports prefaulting,
91723 * and that the remapped range is valid and fully within
91724diff --git a/mm/highmem.c b/mm/highmem.c
91725index b32b70c..e512eb0 100644
91726--- a/mm/highmem.c
91727+++ b/mm/highmem.c
91728@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91729 * So no dangers, even with speculative execution.
91730 */
91731 page = pte_page(pkmap_page_table[i]);
91732+ pax_open_kernel();
91733 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91734-
91735+ pax_close_kernel();
91736 set_page_address(page, NULL);
91737 need_flush = 1;
91738 }
91739@@ -198,9 +199,11 @@ start:
91740 }
91741 }
91742 vaddr = PKMAP_ADDR(last_pkmap_nr);
91743+
91744+ pax_open_kernel();
91745 set_pte_at(&init_mm, vaddr,
91746 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91747-
91748+ pax_close_kernel();
91749 pkmap_count[last_pkmap_nr] = 1;
91750 set_page_address(page, (void *)vaddr);
91751
91752diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91753index 2de3c84..4ecaf1b 100644
91754--- a/mm/hugetlb.c
91755+++ b/mm/hugetlb.c
91756@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91757 struct hstate *h = &default_hstate;
91758 unsigned long tmp;
91759 int ret;
91760+ ctl_table_no_const hugetlb_table;
91761
91762 tmp = h->max_huge_pages;
91763
91764 if (write && h->order >= MAX_ORDER)
91765 return -EINVAL;
91766
91767- table->data = &tmp;
91768- table->maxlen = sizeof(unsigned long);
91769- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91770+ hugetlb_table = *table;
91771+ hugetlb_table.data = &tmp;
91772+ hugetlb_table.maxlen = sizeof(unsigned long);
91773+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91774 if (ret)
91775 goto out;
91776
91777@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91778 struct hstate *h = &default_hstate;
91779 unsigned long tmp;
91780 int ret;
91781+ ctl_table_no_const hugetlb_table;
91782
91783 tmp = h->nr_overcommit_huge_pages;
91784
91785 if (write && h->order >= MAX_ORDER)
91786 return -EINVAL;
91787
91788- table->data = &tmp;
91789- table->maxlen = sizeof(unsigned long);
91790- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91791+ hugetlb_table = *table;
91792+ hugetlb_table.data = &tmp;
91793+ hugetlb_table.maxlen = sizeof(unsigned long);
91794+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91795 if (ret)
91796 goto out;
91797
91798@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91799 return 1;
91800 }
91801
91802+#ifdef CONFIG_PAX_SEGMEXEC
91803+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91804+{
91805+ struct mm_struct *mm = vma->vm_mm;
91806+ struct vm_area_struct *vma_m;
91807+ unsigned long address_m;
91808+ pte_t *ptep_m;
91809+
91810+ vma_m = pax_find_mirror_vma(vma);
91811+ if (!vma_m)
91812+ return;
91813+
91814+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91815+ address_m = address + SEGMEXEC_TASK_SIZE;
91816+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91817+ get_page(page_m);
91818+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
91819+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91820+}
91821+#endif
91822+
91823 /*
91824 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91825 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91826@@ -2715,6 +2740,11 @@ retry_avoidcopy:
91827 make_huge_pte(vma, new_page, 1));
91828 page_remove_rmap(old_page);
91829 hugepage_add_new_anon_rmap(new_page, vma, address);
91830+
91831+#ifdef CONFIG_PAX_SEGMEXEC
91832+ pax_mirror_huge_pte(vma, address, new_page);
91833+#endif
91834+
91835 /* Make the old page be freed below */
91836 new_page = old_page;
91837 }
91838@@ -2879,6 +2909,10 @@ retry:
91839 && (vma->vm_flags & VM_SHARED)));
91840 set_huge_pte_at(mm, address, ptep, new_pte);
91841
91842+#ifdef CONFIG_PAX_SEGMEXEC
91843+ pax_mirror_huge_pte(vma, address, page);
91844+#endif
91845+
91846 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91847 /* Optimization, do the COW without a second fault */
91848 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91849@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91850 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91851 struct hstate *h = hstate_vma(vma);
91852
91853+#ifdef CONFIG_PAX_SEGMEXEC
91854+ struct vm_area_struct *vma_m;
91855+#endif
91856+
91857 address &= huge_page_mask(h);
91858
91859 ptep = huge_pte_offset(mm, address);
91860@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91861 VM_FAULT_SET_HINDEX(hstate_index(h));
91862 }
91863
91864+#ifdef CONFIG_PAX_SEGMEXEC
91865+ vma_m = pax_find_mirror_vma(vma);
91866+ if (vma_m) {
91867+ unsigned long address_m;
91868+
91869+ if (vma->vm_start > vma_m->vm_start) {
91870+ address_m = address;
91871+ address -= SEGMEXEC_TASK_SIZE;
91872+ vma = vma_m;
91873+ h = hstate_vma(vma);
91874+ } else
91875+ address_m = address + SEGMEXEC_TASK_SIZE;
91876+
91877+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91878+ return VM_FAULT_OOM;
91879+ address_m &= HPAGE_MASK;
91880+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91881+ }
91882+#endif
91883+
91884 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91885 if (!ptep)
91886 return VM_FAULT_OOM;
91887diff --git a/mm/internal.h b/mm/internal.h
91888index 3e91000..4741a60 100644
91889--- a/mm/internal.h
91890+++ b/mm/internal.h
91891@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91892 * in mm/page_alloc.c
91893 */
91894 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91895+extern void free_compound_page(struct page *page);
91896 extern void prep_compound_page(struct page *page, unsigned long order);
91897 #ifdef CONFIG_MEMORY_FAILURE
91898 extern bool is_free_buddy_page(struct page *page);
91899@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
91900
91901 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91902 unsigned long, unsigned long,
91903- unsigned long, unsigned long);
91904+ unsigned long, unsigned long) __intentional_overflow(-1);
91905
91906 extern void set_pageblock_order(void);
91907 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91908diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91909index 31f01c5..7015178 100644
91910--- a/mm/kmemleak.c
91911+++ b/mm/kmemleak.c
91912@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91913
91914 for (i = 0; i < object->trace_len; i++) {
91915 void *ptr = (void *)object->trace[i];
91916- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91917+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91918 }
91919 }
91920
91921@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91922 return -ENOMEM;
91923 }
91924
91925- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91926+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91927 &kmemleak_fops);
91928 if (!dentry)
91929 pr_warning("Failed to create the debugfs kmemleak file\n");
91930diff --git a/mm/maccess.c b/mm/maccess.c
91931index d53adf9..03a24bf 100644
91932--- a/mm/maccess.c
91933+++ b/mm/maccess.c
91934@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91935 set_fs(KERNEL_DS);
91936 pagefault_disable();
91937 ret = __copy_from_user_inatomic(dst,
91938- (__force const void __user *)src, size);
91939+ (const void __force_user *)src, size);
91940 pagefault_enable();
91941 set_fs(old_fs);
91942
91943@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91944
91945 set_fs(KERNEL_DS);
91946 pagefault_disable();
91947- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91948+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91949 pagefault_enable();
91950 set_fs(old_fs);
91951
91952diff --git a/mm/madvise.c b/mm/madvise.c
91953index 539eeb9..e24a987 100644
91954--- a/mm/madvise.c
91955+++ b/mm/madvise.c
91956@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91957 pgoff_t pgoff;
91958 unsigned long new_flags = vma->vm_flags;
91959
91960+#ifdef CONFIG_PAX_SEGMEXEC
91961+ struct vm_area_struct *vma_m;
91962+#endif
91963+
91964 switch (behavior) {
91965 case MADV_NORMAL:
91966 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91967@@ -126,6 +130,13 @@ success:
91968 /*
91969 * vm_flags is protected by the mmap_sem held in write mode.
91970 */
91971+
91972+#ifdef CONFIG_PAX_SEGMEXEC
91973+ vma_m = pax_find_mirror_vma(vma);
91974+ if (vma_m)
91975+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91976+#endif
91977+
91978 vma->vm_flags = new_flags;
91979
91980 out:
91981@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91982 struct vm_area_struct **prev,
91983 unsigned long start, unsigned long end)
91984 {
91985+
91986+#ifdef CONFIG_PAX_SEGMEXEC
91987+ struct vm_area_struct *vma_m;
91988+#endif
91989+
91990 *prev = vma;
91991 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91992 return -EINVAL;
91993@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91994 zap_page_range(vma, start, end - start, &details);
91995 } else
91996 zap_page_range(vma, start, end - start, NULL);
91997+
91998+#ifdef CONFIG_PAX_SEGMEXEC
91999+ vma_m = pax_find_mirror_vma(vma);
92000+ if (vma_m) {
92001+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92002+ struct zap_details details = {
92003+ .nonlinear_vma = vma_m,
92004+ .last_index = ULONG_MAX,
92005+ };
92006+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92007+ } else
92008+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92009+ }
92010+#endif
92011+
92012 return 0;
92013 }
92014
92015@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92016 if (end < start)
92017 return error;
92018
92019+#ifdef CONFIG_PAX_SEGMEXEC
92020+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92021+ if (end > SEGMEXEC_TASK_SIZE)
92022+ return error;
92023+ } else
92024+#endif
92025+
92026+ if (end > TASK_SIZE)
92027+ return error;
92028+
92029 error = 0;
92030 if (end == start)
92031 return error;
92032diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92033index 90002ea..db1452d 100644
92034--- a/mm/memory-failure.c
92035+++ b/mm/memory-failure.c
92036@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92037
92038 int sysctl_memory_failure_recovery __read_mostly = 1;
92039
92040-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92041+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92042
92043 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92044
92045@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92046 pfn, t->comm, t->pid);
92047 si.si_signo = SIGBUS;
92048 si.si_errno = 0;
92049- si.si_addr = (void *)addr;
92050+ si.si_addr = (void __user *)addr;
92051 #ifdef __ARCH_SI_TRAPNO
92052 si.si_trapno = trapno;
92053 #endif
92054@@ -762,7 +762,7 @@ static struct page_state {
92055 unsigned long res;
92056 char *msg;
92057 int (*action)(struct page *p, unsigned long pfn);
92058-} error_states[] = {
92059+} __do_const error_states[] = {
92060 { reserved, reserved, "reserved kernel", me_kernel },
92061 /*
92062 * free pages are specially detected outside this table:
92063@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92064 nr_pages = 1 << compound_order(hpage);
92065 else /* normal page or thp */
92066 nr_pages = 1;
92067- atomic_long_add(nr_pages, &num_poisoned_pages);
92068+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92069
92070 /*
92071 * We need/can do nothing about count=0 pages.
92072@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92073 if (!PageHWPoison(hpage)
92074 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92075 || (p != hpage && TestSetPageHWPoison(hpage))) {
92076- atomic_long_sub(nr_pages, &num_poisoned_pages);
92077+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92078 return 0;
92079 }
92080 set_page_hwpoison_huge_page(hpage);
92081@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92082 }
92083 if (hwpoison_filter(p)) {
92084 if (TestClearPageHWPoison(p))
92085- atomic_long_sub(nr_pages, &num_poisoned_pages);
92086+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92087 unlock_page(hpage);
92088 put_page(hpage);
92089 return 0;
92090@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92091 return 0;
92092 }
92093 if (TestClearPageHWPoison(p))
92094- atomic_long_dec(&num_poisoned_pages);
92095+ atomic_long_dec_unchecked(&num_poisoned_pages);
92096 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92097 return 0;
92098 }
92099@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92100 */
92101 if (TestClearPageHWPoison(page)) {
92102 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92103- atomic_long_sub(nr_pages, &num_poisoned_pages);
92104+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92105 freeit = 1;
92106 if (PageHuge(page))
92107 clear_page_hwpoison_huge_page(page);
92108@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92109 if (PageHuge(page)) {
92110 set_page_hwpoison_huge_page(hpage);
92111 dequeue_hwpoisoned_huge_page(hpage);
92112- atomic_long_add(1 << compound_order(hpage),
92113+ atomic_long_add_unchecked(1 << compound_order(hpage),
92114 &num_poisoned_pages);
92115 } else {
92116 SetPageHWPoison(page);
92117- atomic_long_inc(&num_poisoned_pages);
92118+ atomic_long_inc_unchecked(&num_poisoned_pages);
92119 }
92120 }
92121 return ret;
92122@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92123 put_page(page);
92124 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92125 SetPageHWPoison(page);
92126- atomic_long_inc(&num_poisoned_pages);
92127+ atomic_long_inc_unchecked(&num_poisoned_pages);
92128 return 0;
92129 }
92130
92131@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92132 if (!is_free_buddy_page(page))
92133 pr_info("soft offline: %#lx: page leaked\n",
92134 pfn);
92135- atomic_long_inc(&num_poisoned_pages);
92136+ atomic_long_inc_unchecked(&num_poisoned_pages);
92137 }
92138 } else {
92139 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92140@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92141 if (PageHuge(page)) {
92142 set_page_hwpoison_huge_page(hpage);
92143 dequeue_hwpoisoned_huge_page(hpage);
92144- atomic_long_add(1 << compound_order(hpage),
92145+ atomic_long_add_unchecked(1 << compound_order(hpage),
92146 &num_poisoned_pages);
92147 } else {
92148 SetPageHWPoison(page);
92149- atomic_long_inc(&num_poisoned_pages);
92150+ atomic_long_inc_unchecked(&num_poisoned_pages);
92151 }
92152 }
92153 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92154diff --git a/mm/memory.c b/mm/memory.c
92155index 22dfa61..90d7ec5 100644
92156--- a/mm/memory.c
92157+++ b/mm/memory.c
92158@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92159 free_pte_range(tlb, pmd, addr);
92160 } while (pmd++, addr = next, addr != end);
92161
92162+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92163 start &= PUD_MASK;
92164 if (start < floor)
92165 return;
92166@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92167 pmd = pmd_offset(pud, start);
92168 pud_clear(pud);
92169 pmd_free_tlb(tlb, pmd, start);
92170+#endif
92171+
92172 }
92173
92174 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92175@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92176 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92177 } while (pud++, addr = next, addr != end);
92178
92179+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92180 start &= PGDIR_MASK;
92181 if (start < floor)
92182 return;
92183@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92184 pud = pud_offset(pgd, start);
92185 pgd_clear(pgd);
92186 pud_free_tlb(tlb, pud, start);
92187+#endif
92188+
92189 }
92190
92191 /*
92192@@ -1636,12 +1642,6 @@ no_page_table:
92193 return page;
92194 }
92195
92196-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92197-{
92198- return stack_guard_page_start(vma, addr) ||
92199- stack_guard_page_end(vma, addr+PAGE_SIZE);
92200-}
92201-
92202 /**
92203 * __get_user_pages() - pin user pages in memory
92204 * @tsk: task_struct of target task
92205@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92206
92207 i = 0;
92208
92209- do {
92210+ while (nr_pages) {
92211 struct vm_area_struct *vma;
92212
92213- vma = find_extend_vma(mm, start);
92214+ vma = find_vma(mm, start);
92215 if (!vma && in_gate_area(mm, start)) {
92216 unsigned long pg = start & PAGE_MASK;
92217 pgd_t *pgd;
92218@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92219 goto next_page;
92220 }
92221
92222- if (!vma ||
92223+ if (!vma || start < vma->vm_start ||
92224 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92225 !(vm_flags & vma->vm_flags))
92226 return i ? : -EFAULT;
92227@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92228 int ret;
92229 unsigned int fault_flags = 0;
92230
92231- /* For mlock, just skip the stack guard page. */
92232- if (foll_flags & FOLL_MLOCK) {
92233- if (stack_guard_page(vma, start))
92234- goto next_page;
92235- }
92236 if (foll_flags & FOLL_WRITE)
92237 fault_flags |= FAULT_FLAG_WRITE;
92238 if (nonblocking)
92239@@ -1893,7 +1888,7 @@ next_page:
92240 start += page_increm * PAGE_SIZE;
92241 nr_pages -= page_increm;
92242 } while (nr_pages && start < vma->vm_end);
92243- } while (nr_pages);
92244+ }
92245 return i;
92246 }
92247 EXPORT_SYMBOL(__get_user_pages);
92248@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92249 unsigned long address, unsigned int fault_flags)
92250 {
92251 struct vm_area_struct *vma;
92252+ vm_flags_t vm_flags;
92253 int ret;
92254
92255 vma = find_extend_vma(mm, address);
92256 if (!vma || address < vma->vm_start)
92257 return -EFAULT;
92258
92259+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92260+ if (!(vm_flags & vma->vm_flags))
92261+ return -EFAULT;
92262+
92263 ret = handle_mm_fault(mm, vma, address, fault_flags);
92264 if (ret & VM_FAULT_ERROR) {
92265 if (ret & VM_FAULT_OOM)
92266@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92267 page_add_file_rmap(page);
92268 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92269
92270+#ifdef CONFIG_PAX_SEGMEXEC
92271+ pax_mirror_file_pte(vma, addr, page, ptl);
92272+#endif
92273+
92274 retval = 0;
92275 pte_unmap_unlock(pte, ptl);
92276 return retval;
92277@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92278 if (!page_count(page))
92279 return -EINVAL;
92280 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92281+
92282+#ifdef CONFIG_PAX_SEGMEXEC
92283+ struct vm_area_struct *vma_m;
92284+#endif
92285+
92286 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92287 BUG_ON(vma->vm_flags & VM_PFNMAP);
92288 vma->vm_flags |= VM_MIXEDMAP;
92289+
92290+#ifdef CONFIG_PAX_SEGMEXEC
92291+ vma_m = pax_find_mirror_vma(vma);
92292+ if (vma_m)
92293+ vma_m->vm_flags |= VM_MIXEDMAP;
92294+#endif
92295+
92296 }
92297 return insert_page(vma, addr, page, vma->vm_page_prot);
92298 }
92299@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92300 unsigned long pfn)
92301 {
92302 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92303+ BUG_ON(vma->vm_mirror);
92304
92305 if (addr < vma->vm_start || addr >= vma->vm_end)
92306 return -EFAULT;
92307@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92308
92309 BUG_ON(pud_huge(*pud));
92310
92311- pmd = pmd_alloc(mm, pud, addr);
92312+ pmd = (mm == &init_mm) ?
92313+ pmd_alloc_kernel(mm, pud, addr) :
92314+ pmd_alloc(mm, pud, addr);
92315 if (!pmd)
92316 return -ENOMEM;
92317 do {
92318@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92319 unsigned long next;
92320 int err;
92321
92322- pud = pud_alloc(mm, pgd, addr);
92323+ pud = (mm == &init_mm) ?
92324+ pud_alloc_kernel(mm, pgd, addr) :
92325+ pud_alloc(mm, pgd, addr);
92326 if (!pud)
92327 return -ENOMEM;
92328 do {
92329@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92330 copy_user_highpage(dst, src, va, vma);
92331 }
92332
92333+#ifdef CONFIG_PAX_SEGMEXEC
92334+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92335+{
92336+ struct mm_struct *mm = vma->vm_mm;
92337+ spinlock_t *ptl;
92338+ pte_t *pte, entry;
92339+
92340+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92341+ entry = *pte;
92342+ if (!pte_present(entry)) {
92343+ if (!pte_none(entry)) {
92344+ BUG_ON(pte_file(entry));
92345+ free_swap_and_cache(pte_to_swp_entry(entry));
92346+ pte_clear_not_present_full(mm, address, pte, 0);
92347+ }
92348+ } else {
92349+ struct page *page;
92350+
92351+ flush_cache_page(vma, address, pte_pfn(entry));
92352+ entry = ptep_clear_flush(vma, address, pte);
92353+ BUG_ON(pte_dirty(entry));
92354+ page = vm_normal_page(vma, address, entry);
92355+ if (page) {
92356+ update_hiwater_rss(mm);
92357+ if (PageAnon(page))
92358+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92359+ else
92360+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92361+ page_remove_rmap(page);
92362+ page_cache_release(page);
92363+ }
92364+ }
92365+ pte_unmap_unlock(pte, ptl);
92366+}
92367+
92368+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92369+ *
92370+ * the ptl of the lower mapped page is held on entry and is not released on exit
92371+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92372+ */
92373+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92374+{
92375+ struct mm_struct *mm = vma->vm_mm;
92376+ unsigned long address_m;
92377+ spinlock_t *ptl_m;
92378+ struct vm_area_struct *vma_m;
92379+ pmd_t *pmd_m;
92380+ pte_t *pte_m, entry_m;
92381+
92382+ BUG_ON(!page_m || !PageAnon(page_m));
92383+
92384+ vma_m = pax_find_mirror_vma(vma);
92385+ if (!vma_m)
92386+ return;
92387+
92388+ BUG_ON(!PageLocked(page_m));
92389+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92390+ address_m = address + SEGMEXEC_TASK_SIZE;
92391+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92392+ pte_m = pte_offset_map(pmd_m, address_m);
92393+ ptl_m = pte_lockptr(mm, pmd_m);
92394+ if (ptl != ptl_m) {
92395+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92396+ if (!pte_none(*pte_m))
92397+ goto out;
92398+ }
92399+
92400+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92401+ page_cache_get(page_m);
92402+ page_add_anon_rmap(page_m, vma_m, address_m);
92403+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92404+ set_pte_at(mm, address_m, pte_m, entry_m);
92405+ update_mmu_cache(vma_m, address_m, pte_m);
92406+out:
92407+ if (ptl != ptl_m)
92408+ spin_unlock(ptl_m);
92409+ pte_unmap(pte_m);
92410+ unlock_page(page_m);
92411+}
92412+
92413+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92414+{
92415+ struct mm_struct *mm = vma->vm_mm;
92416+ unsigned long address_m;
92417+ spinlock_t *ptl_m;
92418+ struct vm_area_struct *vma_m;
92419+ pmd_t *pmd_m;
92420+ pte_t *pte_m, entry_m;
92421+
92422+ BUG_ON(!page_m || PageAnon(page_m));
92423+
92424+ vma_m = pax_find_mirror_vma(vma);
92425+ if (!vma_m)
92426+ return;
92427+
92428+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92429+ address_m = address + SEGMEXEC_TASK_SIZE;
92430+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92431+ pte_m = pte_offset_map(pmd_m, address_m);
92432+ ptl_m = pte_lockptr(mm, pmd_m);
92433+ if (ptl != ptl_m) {
92434+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92435+ if (!pte_none(*pte_m))
92436+ goto out;
92437+ }
92438+
92439+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92440+ page_cache_get(page_m);
92441+ page_add_file_rmap(page_m);
92442+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92443+ set_pte_at(mm, address_m, pte_m, entry_m);
92444+ update_mmu_cache(vma_m, address_m, pte_m);
92445+out:
92446+ if (ptl != ptl_m)
92447+ spin_unlock(ptl_m);
92448+ pte_unmap(pte_m);
92449+}
92450+
92451+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92452+{
92453+ struct mm_struct *mm = vma->vm_mm;
92454+ unsigned long address_m;
92455+ spinlock_t *ptl_m;
92456+ struct vm_area_struct *vma_m;
92457+ pmd_t *pmd_m;
92458+ pte_t *pte_m, entry_m;
92459+
92460+ vma_m = pax_find_mirror_vma(vma);
92461+ if (!vma_m)
92462+ return;
92463+
92464+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92465+ address_m = address + SEGMEXEC_TASK_SIZE;
92466+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92467+ pte_m = pte_offset_map(pmd_m, address_m);
92468+ ptl_m = pte_lockptr(mm, pmd_m);
92469+ if (ptl != ptl_m) {
92470+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92471+ if (!pte_none(*pte_m))
92472+ goto out;
92473+ }
92474+
92475+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92476+ set_pte_at(mm, address_m, pte_m, entry_m);
92477+out:
92478+ if (ptl != ptl_m)
92479+ spin_unlock(ptl_m);
92480+ pte_unmap(pte_m);
92481+}
92482+
92483+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92484+{
92485+ struct page *page_m;
92486+ pte_t entry;
92487+
92488+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92489+ goto out;
92490+
92491+ entry = *pte;
92492+ page_m = vm_normal_page(vma, address, entry);
92493+ if (!page_m)
92494+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92495+ else if (PageAnon(page_m)) {
92496+ if (pax_find_mirror_vma(vma)) {
92497+ pte_unmap_unlock(pte, ptl);
92498+ lock_page(page_m);
92499+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92500+ if (pte_same(entry, *pte))
92501+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92502+ else
92503+ unlock_page(page_m);
92504+ }
92505+ } else
92506+ pax_mirror_file_pte(vma, address, page_m, ptl);
92507+
92508+out:
92509+ pte_unmap_unlock(pte, ptl);
92510+}
92511+#endif
92512+
92513 /*
92514 * This routine handles present pages, when users try to write
92515 * to a shared page. It is done by copying the page to a new address
92516@@ -2810,6 +3011,12 @@ gotten:
92517 */
92518 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92519 if (likely(pte_same(*page_table, orig_pte))) {
92520+
92521+#ifdef CONFIG_PAX_SEGMEXEC
92522+ if (pax_find_mirror_vma(vma))
92523+ BUG_ON(!trylock_page(new_page));
92524+#endif
92525+
92526 if (old_page) {
92527 if (!PageAnon(old_page)) {
92528 dec_mm_counter_fast(mm, MM_FILEPAGES);
92529@@ -2861,6 +3068,10 @@ gotten:
92530 page_remove_rmap(old_page);
92531 }
92532
92533+#ifdef CONFIG_PAX_SEGMEXEC
92534+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92535+#endif
92536+
92537 /* Free the old page.. */
92538 new_page = old_page;
92539 ret |= VM_FAULT_WRITE;
92540@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92541 swap_free(entry);
92542 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92543 try_to_free_swap(page);
92544+
92545+#ifdef CONFIG_PAX_SEGMEXEC
92546+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92547+#endif
92548+
92549 unlock_page(page);
92550 if (page != swapcache) {
92551 /*
92552@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92553
92554 /* No need to invalidate - it was non-present before */
92555 update_mmu_cache(vma, address, page_table);
92556+
92557+#ifdef CONFIG_PAX_SEGMEXEC
92558+ pax_mirror_anon_pte(vma, address, page, ptl);
92559+#endif
92560+
92561 unlock:
92562 pte_unmap_unlock(page_table, ptl);
92563 out:
92564@@ -3180,40 +3401,6 @@ out_release:
92565 }
92566
92567 /*
92568- * This is like a special single-page "expand_{down|up}wards()",
92569- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92570- * doesn't hit another vma.
92571- */
92572-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92573-{
92574- address &= PAGE_MASK;
92575- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92576- struct vm_area_struct *prev = vma->vm_prev;
92577-
92578- /*
92579- * Is there a mapping abutting this one below?
92580- *
92581- * That's only ok if it's the same stack mapping
92582- * that has gotten split..
92583- */
92584- if (prev && prev->vm_end == address)
92585- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92586-
92587- expand_downwards(vma, address - PAGE_SIZE);
92588- }
92589- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92590- struct vm_area_struct *next = vma->vm_next;
92591-
92592- /* As VM_GROWSDOWN but s/below/above/ */
92593- if (next && next->vm_start == address + PAGE_SIZE)
92594- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92595-
92596- expand_upwards(vma, address + PAGE_SIZE);
92597- }
92598- return 0;
92599-}
92600-
92601-/*
92602 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92603 * but allow concurrent faults), and pte mapped but not yet locked.
92604 * We return with mmap_sem still held, but pte unmapped and unlocked.
92605@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92606 unsigned long address, pte_t *page_table, pmd_t *pmd,
92607 unsigned int flags)
92608 {
92609- struct page *page;
92610+ struct page *page = NULL;
92611 spinlock_t *ptl;
92612 pte_t entry;
92613
92614- pte_unmap(page_table);
92615-
92616- /* Check if we need to add a guard page to the stack */
92617- if (check_stack_guard_page(vma, address) < 0)
92618- return VM_FAULT_SIGBUS;
92619-
92620- /* Use the zero-page for reads */
92621 if (!(flags & FAULT_FLAG_WRITE)) {
92622 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92623 vma->vm_page_prot));
92624- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92625+ ptl = pte_lockptr(mm, pmd);
92626+ spin_lock(ptl);
92627 if (!pte_none(*page_table))
92628 goto unlock;
92629 goto setpte;
92630 }
92631
92632 /* Allocate our own private page. */
92633+ pte_unmap(page_table);
92634+
92635 if (unlikely(anon_vma_prepare(vma)))
92636 goto oom;
92637 page = alloc_zeroed_user_highpage_movable(vma, address);
92638@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92639 if (!pte_none(*page_table))
92640 goto release;
92641
92642+#ifdef CONFIG_PAX_SEGMEXEC
92643+ if (pax_find_mirror_vma(vma))
92644+ BUG_ON(!trylock_page(page));
92645+#endif
92646+
92647 inc_mm_counter_fast(mm, MM_ANONPAGES);
92648 page_add_new_anon_rmap(page, vma, address);
92649 setpte:
92650@@ -3273,6 +3461,12 @@ setpte:
92651
92652 /* No need to invalidate - it was non-present before */
92653 update_mmu_cache(vma, address, page_table);
92654+
92655+#ifdef CONFIG_PAX_SEGMEXEC
92656+ if (page)
92657+ pax_mirror_anon_pte(vma, address, page, ptl);
92658+#endif
92659+
92660 unlock:
92661 pte_unmap_unlock(page_table, ptl);
92662 return 0;
92663@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92664 */
92665 /* Only go through if we didn't race with anybody else... */
92666 if (likely(pte_same(*page_table, orig_pte))) {
92667+
92668+#ifdef CONFIG_PAX_SEGMEXEC
92669+ if (anon && pax_find_mirror_vma(vma))
92670+ BUG_ON(!trylock_page(page));
92671+#endif
92672+
92673 flush_icache_page(vma, page);
92674 entry = mk_pte(page, vma->vm_page_prot);
92675 if (flags & FAULT_FLAG_WRITE)
92676@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92677
92678 /* no need to invalidate: a not-present page won't be cached */
92679 update_mmu_cache(vma, address, page_table);
92680+
92681+#ifdef CONFIG_PAX_SEGMEXEC
92682+ if (anon)
92683+ pax_mirror_anon_pte(vma, address, page, ptl);
92684+ else
92685+ pax_mirror_file_pte(vma, address, page, ptl);
92686+#endif
92687+
92688 } else {
92689 if (cow_page)
92690 mem_cgroup_uncharge_page(cow_page);
92691@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92692 if (flags & FAULT_FLAG_WRITE)
92693 flush_tlb_fix_spurious_fault(vma, address);
92694 }
92695+
92696+#ifdef CONFIG_PAX_SEGMEXEC
92697+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92698+ return 0;
92699+#endif
92700+
92701 unlock:
92702 pte_unmap_unlock(pte, ptl);
92703 return 0;
92704@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92705 pmd_t *pmd;
92706 pte_t *pte;
92707
92708+#ifdef CONFIG_PAX_SEGMEXEC
92709+ struct vm_area_struct *vma_m;
92710+#endif
92711+
92712 if (unlikely(is_vm_hugetlb_page(vma)))
92713 return hugetlb_fault(mm, vma, address, flags);
92714
92715+#ifdef CONFIG_PAX_SEGMEXEC
92716+ vma_m = pax_find_mirror_vma(vma);
92717+ if (vma_m) {
92718+ unsigned long address_m;
92719+ pgd_t *pgd_m;
92720+ pud_t *pud_m;
92721+ pmd_t *pmd_m;
92722+
92723+ if (vma->vm_start > vma_m->vm_start) {
92724+ address_m = address;
92725+ address -= SEGMEXEC_TASK_SIZE;
92726+ vma = vma_m;
92727+ } else
92728+ address_m = address + SEGMEXEC_TASK_SIZE;
92729+
92730+ pgd_m = pgd_offset(mm, address_m);
92731+ pud_m = pud_alloc(mm, pgd_m, address_m);
92732+ if (!pud_m)
92733+ return VM_FAULT_OOM;
92734+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92735+ if (!pmd_m)
92736+ return VM_FAULT_OOM;
92737+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92738+ return VM_FAULT_OOM;
92739+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92740+ }
92741+#endif
92742+
92743 pgd = pgd_offset(mm, address);
92744 pud = pud_alloc(mm, pgd, address);
92745 if (!pud)
92746@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92747 spin_unlock(&mm->page_table_lock);
92748 return 0;
92749 }
92750+
92751+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92752+{
92753+ pud_t *new = pud_alloc_one(mm, address);
92754+ if (!new)
92755+ return -ENOMEM;
92756+
92757+ smp_wmb(); /* See comment in __pte_alloc */
92758+
92759+ spin_lock(&mm->page_table_lock);
92760+ if (pgd_present(*pgd)) /* Another has populated it */
92761+ pud_free(mm, new);
92762+ else
92763+ pgd_populate_kernel(mm, pgd, new);
92764+ spin_unlock(&mm->page_table_lock);
92765+ return 0;
92766+}
92767 #endif /* __PAGETABLE_PUD_FOLDED */
92768
92769 #ifndef __PAGETABLE_PMD_FOLDED
92770@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92771 spin_unlock(&mm->page_table_lock);
92772 return 0;
92773 }
92774+
92775+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92776+{
92777+ pmd_t *new = pmd_alloc_one(mm, address);
92778+ if (!new)
92779+ return -ENOMEM;
92780+
92781+ smp_wmb(); /* See comment in __pte_alloc */
92782+
92783+ spin_lock(&mm->page_table_lock);
92784+#ifndef __ARCH_HAS_4LEVEL_HACK
92785+ if (pud_present(*pud)) /* Another has populated it */
92786+ pmd_free(mm, new);
92787+ else
92788+ pud_populate_kernel(mm, pud, new);
92789+#else
92790+ if (pgd_present(*pud)) /* Another has populated it */
92791+ pmd_free(mm, new);
92792+ else
92793+ pgd_populate_kernel(mm, pud, new);
92794+#endif /* __ARCH_HAS_4LEVEL_HACK */
92795+ spin_unlock(&mm->page_table_lock);
92796+ return 0;
92797+}
92798 #endif /* __PAGETABLE_PMD_FOLDED */
92799
92800 #if !defined(__HAVE_ARCH_GATE_AREA)
92801@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
92802 gate_vma.vm_start = FIXADDR_USER_START;
92803 gate_vma.vm_end = FIXADDR_USER_END;
92804 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92805- gate_vma.vm_page_prot = __P101;
92806+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92807
92808 return 0;
92809 }
92810@@ -4011,8 +4298,8 @@ out:
92811 return ret;
92812 }
92813
92814-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92815- void *buf, int len, int write)
92816+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92817+ void *buf, size_t len, int write)
92818 {
92819 resource_size_t phys_addr;
92820 unsigned long prot = 0;
92821@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92822 * Access another process' address space as given in mm. If non-NULL, use the
92823 * given task for page fault accounting.
92824 */
92825-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92826- unsigned long addr, void *buf, int len, int write)
92827+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92828+ unsigned long addr, void *buf, size_t len, int write)
92829 {
92830 struct vm_area_struct *vma;
92831 void *old_buf = buf;
92832@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92833 down_read(&mm->mmap_sem);
92834 /* ignore errors, just check how much was successfully transferred */
92835 while (len) {
92836- int bytes, ret, offset;
92837+ ssize_t bytes, ret, offset;
92838 void *maddr;
92839 struct page *page = NULL;
92840
92841@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92842 *
92843 * The caller must hold a reference on @mm.
92844 */
92845-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92846- void *buf, int len, int write)
92847+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92848+ void *buf, size_t len, int write)
92849 {
92850 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92851 }
92852@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92853 * Source/target buffer must be kernel space,
92854 * Do not walk the page table directly, use get_user_pages
92855 */
92856-int access_process_vm(struct task_struct *tsk, unsigned long addr,
92857- void *buf, int len, int write)
92858+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92859+ void *buf, size_t len, int write)
92860 {
92861 struct mm_struct *mm;
92862- int ret;
92863+ ssize_t ret;
92864
92865 mm = get_task_mm(tsk);
92866 if (!mm)
92867diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92868index ae3c8f3..fa4ee8e 100644
92869--- a/mm/mempolicy.c
92870+++ b/mm/mempolicy.c
92871@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92872 unsigned long vmstart;
92873 unsigned long vmend;
92874
92875+#ifdef CONFIG_PAX_SEGMEXEC
92876+ struct vm_area_struct *vma_m;
92877+#endif
92878+
92879 vma = find_vma(mm, start);
92880 if (!vma || vma->vm_start > start)
92881 return -EFAULT;
92882@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92883 err = vma_replace_policy(vma, new_pol);
92884 if (err)
92885 goto out;
92886+
92887+#ifdef CONFIG_PAX_SEGMEXEC
92888+ vma_m = pax_find_mirror_vma(vma);
92889+ if (vma_m) {
92890+ err = vma_replace_policy(vma_m, new_pol);
92891+ if (err)
92892+ goto out;
92893+ }
92894+#endif
92895+
92896 }
92897
92898 out:
92899@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92900
92901 if (end < start)
92902 return -EINVAL;
92903+
92904+#ifdef CONFIG_PAX_SEGMEXEC
92905+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92906+ if (end > SEGMEXEC_TASK_SIZE)
92907+ return -EINVAL;
92908+ } else
92909+#endif
92910+
92911+ if (end > TASK_SIZE)
92912+ return -EINVAL;
92913+
92914 if (end == start)
92915 return 0;
92916
92917@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92918 */
92919 tcred = __task_cred(task);
92920 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92921- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92922- !capable(CAP_SYS_NICE)) {
92923+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92924 rcu_read_unlock();
92925 err = -EPERM;
92926 goto out_put;
92927@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92928 goto out;
92929 }
92930
92931+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92932+ if (mm != current->mm &&
92933+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92934+ mmput(mm);
92935+ err = -EPERM;
92936+ goto out;
92937+ }
92938+#endif
92939+
92940 err = do_migrate_pages(mm, old, new,
92941 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92942
92943diff --git a/mm/migrate.c b/mm/migrate.c
92944index bed4880..a493f67 100644
92945--- a/mm/migrate.c
92946+++ b/mm/migrate.c
92947@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92948 */
92949 tcred = __task_cred(task);
92950 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92951- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92952- !capable(CAP_SYS_NICE)) {
92953+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92954 rcu_read_unlock();
92955 err = -EPERM;
92956 goto out;
92957diff --git a/mm/mlock.c b/mm/mlock.c
92958index b1eb536..091d154 100644
92959--- a/mm/mlock.c
92960+++ b/mm/mlock.c
92961@@ -14,6 +14,7 @@
92962 #include <linux/pagevec.h>
92963 #include <linux/mempolicy.h>
92964 #include <linux/syscalls.h>
92965+#include <linux/security.h>
92966 #include <linux/sched.h>
92967 #include <linux/export.h>
92968 #include <linux/rmap.h>
92969@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92970 {
92971 unsigned long nstart, end, tmp;
92972 struct vm_area_struct * vma, * prev;
92973- int error;
92974+ int error = 0;
92975
92976 VM_BUG_ON(start & ~PAGE_MASK);
92977 VM_BUG_ON(len != PAGE_ALIGN(len));
92978@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92979 return -EINVAL;
92980 if (end == start)
92981 return 0;
92982+ if (end > TASK_SIZE)
92983+ return -EINVAL;
92984+
92985 vma = find_vma(current->mm, start);
92986 if (!vma || vma->vm_start > start)
92987 return -ENOMEM;
92988@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92989 for (nstart = start ; ; ) {
92990 vm_flags_t newflags;
92991
92992+#ifdef CONFIG_PAX_SEGMEXEC
92993+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92994+ break;
92995+#endif
92996+
92997 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92998
92999 newflags = vma->vm_flags & ~VM_LOCKED;
93000@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93001 locked += current->mm->locked_vm;
93002
93003 /* check against resource limits */
93004+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93005 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93006 error = do_mlock(start, len, 1);
93007
93008@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93009 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93010 vm_flags_t newflags;
93011
93012+#ifdef CONFIG_PAX_SEGMEXEC
93013+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93014+ break;
93015+#endif
93016+
93017 newflags = vma->vm_flags & ~VM_LOCKED;
93018 if (flags & MCL_CURRENT)
93019 newflags |= VM_LOCKED;
93020@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93021 lock_limit >>= PAGE_SHIFT;
93022
93023 ret = -ENOMEM;
93024+
93025+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93026+
93027 down_write(&current->mm->mmap_sem);
93028-
93029 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93030 capable(CAP_IPC_LOCK))
93031 ret = do_mlockall(flags);
93032diff --git a/mm/mmap.c b/mm/mmap.c
93033index 20ff0c3..a9eda98 100644
93034--- a/mm/mmap.c
93035+++ b/mm/mmap.c
93036@@ -36,6 +36,7 @@
93037 #include <linux/sched/sysctl.h>
93038 #include <linux/notifier.h>
93039 #include <linux/memory.h>
93040+#include <linux/random.h>
93041
93042 #include <asm/uaccess.h>
93043 #include <asm/cacheflush.h>
93044@@ -52,6 +53,16 @@
93045 #define arch_rebalance_pgtables(addr, len) (addr)
93046 #endif
93047
93048+static inline void verify_mm_writelocked(struct mm_struct *mm)
93049+{
93050+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93051+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93052+ up_read(&mm->mmap_sem);
93053+ BUG();
93054+ }
93055+#endif
93056+}
93057+
93058 static void unmap_region(struct mm_struct *mm,
93059 struct vm_area_struct *vma, struct vm_area_struct *prev,
93060 unsigned long start, unsigned long end);
93061@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93062 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93063 *
93064 */
93065-pgprot_t protection_map[16] = {
93066+pgprot_t protection_map[16] __read_only = {
93067 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93068 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93069 };
93070
93071-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93072+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93073 {
93074- return __pgprot(pgprot_val(protection_map[vm_flags &
93075+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93076 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93077 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93078+
93079+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93080+ if (!(__supported_pte_mask & _PAGE_NX) &&
93081+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93082+ (vm_flags & (VM_READ | VM_WRITE)))
93083+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93084+#endif
93085+
93086+ return prot;
93087 }
93088 EXPORT_SYMBOL(vm_get_page_prot);
93089
93090@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93091 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93092 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93093 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93094+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93095 /*
93096 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93097 * other variables. It can be updated by several CPUs frequently.
93098@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93099 struct vm_area_struct *next = vma->vm_next;
93100
93101 might_sleep();
93102+ BUG_ON(vma->vm_mirror);
93103 if (vma->vm_ops && vma->vm_ops->close)
93104 vma->vm_ops->close(vma);
93105 if (vma->vm_file)
93106@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93107 * not page aligned -Ram Gupta
93108 */
93109 rlim = rlimit(RLIMIT_DATA);
93110+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93111 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93112 (mm->end_data - mm->start_data) > rlim)
93113 goto out;
93114@@ -940,6 +963,12 @@ static int
93115 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93116 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93117 {
93118+
93119+#ifdef CONFIG_PAX_SEGMEXEC
93120+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93121+ return 0;
93122+#endif
93123+
93124 if (is_mergeable_vma(vma, file, vm_flags) &&
93125 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93126 if (vma->vm_pgoff == vm_pgoff)
93127@@ -959,6 +988,12 @@ static int
93128 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93129 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93130 {
93131+
93132+#ifdef CONFIG_PAX_SEGMEXEC
93133+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93134+ return 0;
93135+#endif
93136+
93137 if (is_mergeable_vma(vma, file, vm_flags) &&
93138 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93139 pgoff_t vm_pglen;
93140@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93141 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93142 struct vm_area_struct *prev, unsigned long addr,
93143 unsigned long end, unsigned long vm_flags,
93144- struct anon_vma *anon_vma, struct file *file,
93145+ struct anon_vma *anon_vma, struct file *file,
93146 pgoff_t pgoff, struct mempolicy *policy)
93147 {
93148 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93149 struct vm_area_struct *area, *next;
93150 int err;
93151
93152+#ifdef CONFIG_PAX_SEGMEXEC
93153+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93154+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93155+
93156+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93157+#endif
93158+
93159 /*
93160 * We later require that vma->vm_flags == vm_flags,
93161 * so this tests vma->vm_flags & VM_SPECIAL, too.
93162@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93163 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93164 next = next->vm_next;
93165
93166+#ifdef CONFIG_PAX_SEGMEXEC
93167+ if (prev)
93168+ prev_m = pax_find_mirror_vma(prev);
93169+ if (area)
93170+ area_m = pax_find_mirror_vma(area);
93171+ if (next)
93172+ next_m = pax_find_mirror_vma(next);
93173+#endif
93174+
93175 /*
93176 * Can it merge with the predecessor?
93177 */
93178@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93179 /* cases 1, 6 */
93180 err = vma_adjust(prev, prev->vm_start,
93181 next->vm_end, prev->vm_pgoff, NULL);
93182- } else /* cases 2, 5, 7 */
93183+
93184+#ifdef CONFIG_PAX_SEGMEXEC
93185+ if (!err && prev_m)
93186+ err = vma_adjust(prev_m, prev_m->vm_start,
93187+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93188+#endif
93189+
93190+ } else { /* cases 2, 5, 7 */
93191 err = vma_adjust(prev, prev->vm_start,
93192 end, prev->vm_pgoff, NULL);
93193+
93194+#ifdef CONFIG_PAX_SEGMEXEC
93195+ if (!err && prev_m)
93196+ err = vma_adjust(prev_m, prev_m->vm_start,
93197+ end_m, prev_m->vm_pgoff, NULL);
93198+#endif
93199+
93200+ }
93201 if (err)
93202 return NULL;
93203 khugepaged_enter_vma_merge(prev);
93204@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93205 mpol_equal(policy, vma_policy(next)) &&
93206 can_vma_merge_before(next, vm_flags,
93207 anon_vma, file, pgoff+pglen)) {
93208- if (prev && addr < prev->vm_end) /* case 4 */
93209+ if (prev && addr < prev->vm_end) { /* case 4 */
93210 err = vma_adjust(prev, prev->vm_start,
93211 addr, prev->vm_pgoff, NULL);
93212- else /* cases 3, 8 */
93213+
93214+#ifdef CONFIG_PAX_SEGMEXEC
93215+ if (!err && prev_m)
93216+ err = vma_adjust(prev_m, prev_m->vm_start,
93217+ addr_m, prev_m->vm_pgoff, NULL);
93218+#endif
93219+
93220+ } else { /* cases 3, 8 */
93221 err = vma_adjust(area, addr, next->vm_end,
93222 next->vm_pgoff - pglen, NULL);
93223+
93224+#ifdef CONFIG_PAX_SEGMEXEC
93225+ if (!err && area_m)
93226+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93227+ next_m->vm_pgoff - pglen, NULL);
93228+#endif
93229+
93230+ }
93231 if (err)
93232 return NULL;
93233 khugepaged_enter_vma_merge(area);
93234@@ -1172,8 +1253,10 @@ none:
93235 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93236 struct file *file, long pages)
93237 {
93238- const unsigned long stack_flags
93239- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93240+
93241+#ifdef CONFIG_PAX_RANDMMAP
93242+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93243+#endif
93244
93245 mm->total_vm += pages;
93246
93247@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93248 mm->shared_vm += pages;
93249 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93250 mm->exec_vm += pages;
93251- } else if (flags & stack_flags)
93252+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93253 mm->stack_vm += pages;
93254 }
93255 #endif /* CONFIG_PROC_FS */
93256@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93257 locked += mm->locked_vm;
93258 lock_limit = rlimit(RLIMIT_MEMLOCK);
93259 lock_limit >>= PAGE_SHIFT;
93260+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93261 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93262 return -EAGAIN;
93263 }
93264@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93265 * (the exception is when the underlying filesystem is noexec
93266 * mounted, in which case we dont add PROT_EXEC.)
93267 */
93268- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93269+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93270 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93271 prot |= PROT_EXEC;
93272
93273@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93274 /* Obtain the address to map to. we verify (or select) it and ensure
93275 * that it represents a valid section of the address space.
93276 */
93277- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93278+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93279 if (addr & ~PAGE_MASK)
93280 return addr;
93281
93282@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93283 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93284 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93285
93286+#ifdef CONFIG_PAX_MPROTECT
93287+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93288+
93289+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93290+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93291+ mm->binfmt->handle_mmap)
93292+ mm->binfmt->handle_mmap(file);
93293+#endif
93294+
93295+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93296+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93297+ gr_log_rwxmmap(file);
93298+
93299+#ifdef CONFIG_PAX_EMUPLT
93300+ vm_flags &= ~VM_EXEC;
93301+#else
93302+ return -EPERM;
93303+#endif
93304+
93305+ }
93306+
93307+ if (!(vm_flags & VM_EXEC))
93308+ vm_flags &= ~VM_MAYEXEC;
93309+#else
93310+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93311+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93312+#endif
93313+ else
93314+ vm_flags &= ~VM_MAYWRITE;
93315+ }
93316+#endif
93317+
93318+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93319+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93320+ vm_flags &= ~VM_PAGEEXEC;
93321+#endif
93322+
93323 if (flags & MAP_LOCKED)
93324 if (!can_do_mlock())
93325 return -EPERM;
93326@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93327 vm_flags |= VM_NORESERVE;
93328 }
93329
93330+ if (!gr_acl_handle_mmap(file, prot))
93331+ return -EACCES;
93332+
93333 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93334 if (!IS_ERR_VALUE(addr) &&
93335 ((vm_flags & VM_LOCKED) ||
93336@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93337 vm_flags_t vm_flags = vma->vm_flags;
93338
93339 /* If it was private or non-writable, the write bit is already clear */
93340- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93341+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93342 return 0;
93343
93344 /* The backer wishes to know when pages are first written to? */
93345@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93346 struct rb_node **rb_link, *rb_parent;
93347 unsigned long charged = 0;
93348
93349+#ifdef CONFIG_PAX_SEGMEXEC
93350+ struct vm_area_struct *vma_m = NULL;
93351+#endif
93352+
93353+ /*
93354+ * mm->mmap_sem is required to protect against another thread
93355+ * changing the mappings in case we sleep.
93356+ */
93357+ verify_mm_writelocked(mm);
93358+
93359 /* Check against address space limit. */
93360+
93361+#ifdef CONFIG_PAX_RANDMMAP
93362+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93363+#endif
93364+
93365 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93366 unsigned long nr_pages;
93367
93368@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93369
93370 /* Clear old maps */
93371 error = -ENOMEM;
93372-munmap_back:
93373 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93374 if (do_munmap(mm, addr, len))
93375 return -ENOMEM;
93376- goto munmap_back;
93377+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93378 }
93379
93380 /*
93381@@ -1554,6 +1692,16 @@ munmap_back:
93382 goto unacct_error;
93383 }
93384
93385+#ifdef CONFIG_PAX_SEGMEXEC
93386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93387+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93388+ if (!vma_m) {
93389+ error = -ENOMEM;
93390+ goto free_vma;
93391+ }
93392+ }
93393+#endif
93394+
93395 vma->vm_mm = mm;
93396 vma->vm_start = addr;
93397 vma->vm_end = addr + len;
93398@@ -1573,6 +1721,13 @@ munmap_back:
93399 if (error)
93400 goto unmap_and_free_vma;
93401
93402+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93403+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93404+ vma->vm_flags |= VM_PAGEEXEC;
93405+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93406+ }
93407+#endif
93408+
93409 /* Can addr have changed??
93410 *
93411 * Answer: Yes, several device drivers can do it in their
93412@@ -1606,6 +1761,12 @@ munmap_back:
93413 }
93414
93415 vma_link(mm, vma, prev, rb_link, rb_parent);
93416+
93417+#ifdef CONFIG_PAX_SEGMEXEC
93418+ if (vma_m)
93419+ BUG_ON(pax_mirror_vma(vma_m, vma));
93420+#endif
93421+
93422 /* Once vma denies write, undo our temporary denial count */
93423 if (vm_flags & VM_DENYWRITE)
93424 allow_write_access(file);
93425@@ -1614,6 +1775,7 @@ out:
93426 perf_event_mmap(vma);
93427
93428 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93429+ track_exec_limit(mm, addr, addr + len, vm_flags);
93430 if (vm_flags & VM_LOCKED) {
93431 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93432 vma == get_gate_vma(current->mm)))
93433@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93434 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93435 charged = 0;
93436 free_vma:
93437+
93438+#ifdef CONFIG_PAX_SEGMEXEC
93439+ if (vma_m)
93440+ kmem_cache_free(vm_area_cachep, vma_m);
93441+#endif
93442+
93443 kmem_cache_free(vm_area_cachep, vma);
93444 unacct_error:
93445 if (charged)
93446@@ -1653,7 +1821,63 @@ unacct_error:
93447 return error;
93448 }
93449
93450-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93451+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93452+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93453+{
93454+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93455+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93456+
93457+ return 0;
93458+}
93459+#endif
93460+
93461+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93462+{
93463+ if (!vma) {
93464+#ifdef CONFIG_STACK_GROWSUP
93465+ if (addr > sysctl_heap_stack_gap)
93466+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93467+ else
93468+ vma = find_vma(current->mm, 0);
93469+ if (vma && (vma->vm_flags & VM_GROWSUP))
93470+ return false;
93471+#endif
93472+ return true;
93473+ }
93474+
93475+ if (addr + len > vma->vm_start)
93476+ return false;
93477+
93478+ if (vma->vm_flags & VM_GROWSDOWN)
93479+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93480+#ifdef CONFIG_STACK_GROWSUP
93481+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93482+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93483+#endif
93484+ else if (offset)
93485+ return offset <= vma->vm_start - addr - len;
93486+
93487+ return true;
93488+}
93489+
93490+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93491+{
93492+ if (vma->vm_start < len)
93493+ return -ENOMEM;
93494+
93495+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93496+ if (offset <= vma->vm_start - len)
93497+ return vma->vm_start - len - offset;
93498+ else
93499+ return -ENOMEM;
93500+ }
93501+
93502+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93503+ return vma->vm_start - len - sysctl_heap_stack_gap;
93504+ return -ENOMEM;
93505+}
93506+
93507+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93508 {
93509 /*
93510 * We implement the search by looking for an rbtree node that
93511@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93512 }
93513 }
93514
93515- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93516+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93517 check_current:
93518 /* Check if current node has a suitable gap */
93519 if (gap_start > high_limit)
93520 return -ENOMEM;
93521+
93522+ if (gap_end - gap_start > info->threadstack_offset)
93523+ gap_start += info->threadstack_offset;
93524+ else
93525+ gap_start = gap_end;
93526+
93527+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93528+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93529+ gap_start += sysctl_heap_stack_gap;
93530+ else
93531+ gap_start = gap_end;
93532+ }
93533+ if (vma->vm_flags & VM_GROWSDOWN) {
93534+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93535+ gap_end -= sysctl_heap_stack_gap;
93536+ else
93537+ gap_end = gap_start;
93538+ }
93539 if (gap_end >= low_limit && gap_end - gap_start >= length)
93540 goto found;
93541
93542@@ -1755,7 +1997,7 @@ found:
93543 return gap_start;
93544 }
93545
93546-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93547+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93548 {
93549 struct mm_struct *mm = current->mm;
93550 struct vm_area_struct *vma;
93551@@ -1809,6 +2051,24 @@ check_current:
93552 gap_end = vma->vm_start;
93553 if (gap_end < low_limit)
93554 return -ENOMEM;
93555+
93556+ if (gap_end - gap_start > info->threadstack_offset)
93557+ gap_end -= info->threadstack_offset;
93558+ else
93559+ gap_end = gap_start;
93560+
93561+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93562+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93563+ gap_start += sysctl_heap_stack_gap;
93564+ else
93565+ gap_start = gap_end;
93566+ }
93567+ if (vma->vm_flags & VM_GROWSDOWN) {
93568+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93569+ gap_end -= sysctl_heap_stack_gap;
93570+ else
93571+ gap_end = gap_start;
93572+ }
93573 if (gap_start <= high_limit && gap_end - gap_start >= length)
93574 goto found;
93575
93576@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93577 struct mm_struct *mm = current->mm;
93578 struct vm_area_struct *vma;
93579 struct vm_unmapped_area_info info;
93580+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93581
93582 if (len > TASK_SIZE - mmap_min_addr)
93583 return -ENOMEM;
93584@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93585 if (flags & MAP_FIXED)
93586 return addr;
93587
93588+#ifdef CONFIG_PAX_RANDMMAP
93589+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93590+#endif
93591+
93592 if (addr) {
93593 addr = PAGE_ALIGN(addr);
93594 vma = find_vma(mm, addr);
93595 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93596- (!vma || addr + len <= vma->vm_start))
93597+ check_heap_stack_gap(vma, addr, len, offset))
93598 return addr;
93599 }
93600
93601@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93602 info.low_limit = mm->mmap_base;
93603 info.high_limit = TASK_SIZE;
93604 info.align_mask = 0;
93605+ info.threadstack_offset = offset;
93606 return vm_unmapped_area(&info);
93607 }
93608 #endif
93609@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93610 struct mm_struct *mm = current->mm;
93611 unsigned long addr = addr0;
93612 struct vm_unmapped_area_info info;
93613+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93614
93615 /* requested length too big for entire address space */
93616 if (len > TASK_SIZE - mmap_min_addr)
93617@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93618 if (flags & MAP_FIXED)
93619 return addr;
93620
93621+#ifdef CONFIG_PAX_RANDMMAP
93622+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93623+#endif
93624+
93625 /* requesting a specific address */
93626 if (addr) {
93627 addr = PAGE_ALIGN(addr);
93628 vma = find_vma(mm, addr);
93629 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93630- (!vma || addr + len <= vma->vm_start))
93631+ check_heap_stack_gap(vma, addr, len, offset))
93632 return addr;
93633 }
93634
93635@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93636 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93637 info.high_limit = mm->mmap_base;
93638 info.align_mask = 0;
93639+ info.threadstack_offset = offset;
93640 addr = vm_unmapped_area(&info);
93641
93642 /*
93643@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93644 VM_BUG_ON(addr != -ENOMEM);
93645 info.flags = 0;
93646 info.low_limit = TASK_UNMAPPED_BASE;
93647+
93648+#ifdef CONFIG_PAX_RANDMMAP
93649+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93650+ info.low_limit += mm->delta_mmap;
93651+#endif
93652+
93653 info.high_limit = TASK_SIZE;
93654 addr = vm_unmapped_area(&info);
93655 }
93656@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93657 return vma;
93658 }
93659
93660+#ifdef CONFIG_PAX_SEGMEXEC
93661+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93662+{
93663+ struct vm_area_struct *vma_m;
93664+
93665+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93666+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93667+ BUG_ON(vma->vm_mirror);
93668+ return NULL;
93669+ }
93670+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93671+ vma_m = vma->vm_mirror;
93672+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93673+ BUG_ON(vma->vm_file != vma_m->vm_file);
93674+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93675+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93676+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93677+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93678+ return vma_m;
93679+}
93680+#endif
93681+
93682 /*
93683 * Verify that the stack growth is acceptable and
93684 * update accounting. This is shared with both the
93685@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93686 return -ENOMEM;
93687
93688 /* Stack limit test */
93689+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93690 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93691 return -ENOMEM;
93692
93693@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93694 locked = mm->locked_vm + grow;
93695 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93696 limit >>= PAGE_SHIFT;
93697+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93698 if (locked > limit && !capable(CAP_IPC_LOCK))
93699 return -ENOMEM;
93700 }
93701@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93702 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93703 * vma is the last one with address > vma->vm_end. Have to extend vma.
93704 */
93705+#ifndef CONFIG_IA64
93706+static
93707+#endif
93708 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93709 {
93710 int error;
93711+ bool locknext;
93712
93713 if (!(vma->vm_flags & VM_GROWSUP))
93714 return -EFAULT;
93715
93716+ /* Also guard against wrapping around to address 0. */
93717+ if (address < PAGE_ALIGN(address+1))
93718+ address = PAGE_ALIGN(address+1);
93719+ else
93720+ return -ENOMEM;
93721+
93722 /*
93723 * We must make sure the anon_vma is allocated
93724 * so that the anon_vma locking is not a noop.
93725 */
93726 if (unlikely(anon_vma_prepare(vma)))
93727 return -ENOMEM;
93728+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93729+ if (locknext && anon_vma_prepare(vma->vm_next))
93730+ return -ENOMEM;
93731 vma_lock_anon_vma(vma);
93732+ if (locknext)
93733+ vma_lock_anon_vma(vma->vm_next);
93734
93735 /*
93736 * vma->vm_start/vm_end cannot change under us because the caller
93737 * is required to hold the mmap_sem in read mode. We need the
93738- * anon_vma lock to serialize against concurrent expand_stacks.
93739- * Also guard against wrapping around to address 0.
93740+ * anon_vma locks to serialize against concurrent expand_stacks
93741+ * and expand_upwards.
93742 */
93743- if (address < PAGE_ALIGN(address+4))
93744- address = PAGE_ALIGN(address+4);
93745- else {
93746- vma_unlock_anon_vma(vma);
93747- return -ENOMEM;
93748- }
93749 error = 0;
93750
93751 /* Somebody else might have raced and expanded it already */
93752- if (address > vma->vm_end) {
93753+ 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)
93754+ error = -ENOMEM;
93755+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93756 unsigned long size, grow;
93757
93758 size = address - vma->vm_start;
93759@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93760 }
93761 }
93762 }
93763+ if (locknext)
93764+ vma_unlock_anon_vma(vma->vm_next);
93765 vma_unlock_anon_vma(vma);
93766 khugepaged_enter_vma_merge(vma);
93767 validate_mm(vma->vm_mm);
93768@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93769 unsigned long address)
93770 {
93771 int error;
93772+ bool lockprev = false;
93773+ struct vm_area_struct *prev;
93774
93775 /*
93776 * We must make sure the anon_vma is allocated
93777@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93778 if (error)
93779 return error;
93780
93781+ prev = vma->vm_prev;
93782+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93783+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93784+#endif
93785+ if (lockprev && anon_vma_prepare(prev))
93786+ return -ENOMEM;
93787+ if (lockprev)
93788+ vma_lock_anon_vma(prev);
93789+
93790 vma_lock_anon_vma(vma);
93791
93792 /*
93793@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
93794 */
93795
93796 /* Somebody else might have raced and expanded it already */
93797- if (address < vma->vm_start) {
93798+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93799+ error = -ENOMEM;
93800+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93801 unsigned long size, grow;
93802
93803+#ifdef CONFIG_PAX_SEGMEXEC
93804+ struct vm_area_struct *vma_m;
93805+
93806+ vma_m = pax_find_mirror_vma(vma);
93807+#endif
93808+
93809 size = vma->vm_end - address;
93810 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93811
93812@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
93813 vma->vm_pgoff -= grow;
93814 anon_vma_interval_tree_post_update_vma(vma);
93815 vma_gap_update(vma);
93816+
93817+#ifdef CONFIG_PAX_SEGMEXEC
93818+ if (vma_m) {
93819+ anon_vma_interval_tree_pre_update_vma(vma_m);
93820+ vma_m->vm_start -= grow << PAGE_SHIFT;
93821+ vma_m->vm_pgoff -= grow;
93822+ anon_vma_interval_tree_post_update_vma(vma_m);
93823+ vma_gap_update(vma_m);
93824+ }
93825+#endif
93826+
93827 spin_unlock(&vma->vm_mm->page_table_lock);
93828
93829+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93830 perf_event_mmap(vma);
93831 }
93832 }
93833 }
93834 vma_unlock_anon_vma(vma);
93835+ if (lockprev)
93836+ vma_unlock_anon_vma(prev);
93837 khugepaged_enter_vma_merge(vma);
93838 validate_mm(vma->vm_mm);
93839 return error;
93840@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93841 do {
93842 long nrpages = vma_pages(vma);
93843
93844+#ifdef CONFIG_PAX_SEGMEXEC
93845+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93846+ vma = remove_vma(vma);
93847+ continue;
93848+ }
93849+#endif
93850+
93851 if (vma->vm_flags & VM_ACCOUNT)
93852 nr_accounted += nrpages;
93853 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93854@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93855 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93856 vma->vm_prev = NULL;
93857 do {
93858+
93859+#ifdef CONFIG_PAX_SEGMEXEC
93860+ if (vma->vm_mirror) {
93861+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93862+ vma->vm_mirror->vm_mirror = NULL;
93863+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
93864+ vma->vm_mirror = NULL;
93865+ }
93866+#endif
93867+
93868 vma_rb_erase(vma, &mm->mm_rb);
93869 mm->map_count--;
93870 tail_vma = vma;
93871@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93872 struct vm_area_struct *new;
93873 int err = -ENOMEM;
93874
93875+#ifdef CONFIG_PAX_SEGMEXEC
93876+ struct vm_area_struct *vma_m, *new_m = NULL;
93877+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93878+#endif
93879+
93880 if (is_vm_hugetlb_page(vma) && (addr &
93881 ~(huge_page_mask(hstate_vma(vma)))))
93882 return -EINVAL;
93883
93884+#ifdef CONFIG_PAX_SEGMEXEC
93885+ vma_m = pax_find_mirror_vma(vma);
93886+#endif
93887+
93888 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93889 if (!new)
93890 goto out_err;
93891
93892+#ifdef CONFIG_PAX_SEGMEXEC
93893+ if (vma_m) {
93894+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93895+ if (!new_m) {
93896+ kmem_cache_free(vm_area_cachep, new);
93897+ goto out_err;
93898+ }
93899+ }
93900+#endif
93901+
93902 /* most fields are the same, copy all, and then fixup */
93903 *new = *vma;
93904
93905@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93906 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93907 }
93908
93909+#ifdef CONFIG_PAX_SEGMEXEC
93910+ if (vma_m) {
93911+ *new_m = *vma_m;
93912+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
93913+ new_m->vm_mirror = new;
93914+ new->vm_mirror = new_m;
93915+
93916+ if (new_below)
93917+ new_m->vm_end = addr_m;
93918+ else {
93919+ new_m->vm_start = addr_m;
93920+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93921+ }
93922+ }
93923+#endif
93924+
93925 err = vma_dup_policy(vma, new);
93926 if (err)
93927 goto out_free_vma;
93928@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93929 else
93930 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93931
93932+#ifdef CONFIG_PAX_SEGMEXEC
93933+ if (!err && vma_m) {
93934+ struct mempolicy *pol = vma_policy(new);
93935+
93936+ if (anon_vma_clone(new_m, vma_m))
93937+ goto out_free_mpol;
93938+
93939+ mpol_get(pol);
93940+ set_vma_policy(new_m, pol);
93941+
93942+ if (new_m->vm_file)
93943+ get_file(new_m->vm_file);
93944+
93945+ if (new_m->vm_ops && new_m->vm_ops->open)
93946+ new_m->vm_ops->open(new_m);
93947+
93948+ if (new_below)
93949+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93950+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93951+ else
93952+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93953+
93954+ if (err) {
93955+ if (new_m->vm_ops && new_m->vm_ops->close)
93956+ new_m->vm_ops->close(new_m);
93957+ if (new_m->vm_file)
93958+ fput(new_m->vm_file);
93959+ mpol_put(pol);
93960+ }
93961+ }
93962+#endif
93963+
93964 /* Success. */
93965 if (!err)
93966 return 0;
93967@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93968 new->vm_ops->close(new);
93969 if (new->vm_file)
93970 fput(new->vm_file);
93971- unlink_anon_vmas(new);
93972 out_free_mpol:
93973 mpol_put(vma_policy(new));
93974 out_free_vma:
93975+
93976+#ifdef CONFIG_PAX_SEGMEXEC
93977+ if (new_m) {
93978+ unlink_anon_vmas(new_m);
93979+ kmem_cache_free(vm_area_cachep, new_m);
93980+ }
93981+#endif
93982+
93983+ unlink_anon_vmas(new);
93984 kmem_cache_free(vm_area_cachep, new);
93985 out_err:
93986 return err;
93987@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93988 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93989 unsigned long addr, int new_below)
93990 {
93991+
93992+#ifdef CONFIG_PAX_SEGMEXEC
93993+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93994+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93995+ if (mm->map_count >= sysctl_max_map_count-1)
93996+ return -ENOMEM;
93997+ } else
93998+#endif
93999+
94000 if (mm->map_count >= sysctl_max_map_count)
94001 return -ENOMEM;
94002
94003@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94004 * work. This now handles partial unmappings.
94005 * Jeremy Fitzhardinge <jeremy@goop.org>
94006 */
94007+#ifdef CONFIG_PAX_SEGMEXEC
94008 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94009 {
94010+ int ret = __do_munmap(mm, start, len);
94011+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94012+ return ret;
94013+
94014+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94015+}
94016+
94017+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94018+#else
94019+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94020+#endif
94021+{
94022 unsigned long end;
94023 struct vm_area_struct *vma, *prev, *last;
94024
94025+ /*
94026+ * mm->mmap_sem is required to protect against another thread
94027+ * changing the mappings in case we sleep.
94028+ */
94029+ verify_mm_writelocked(mm);
94030+
94031 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94032 return -EINVAL;
94033
94034@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94035 /* Fix up all other VM information */
94036 remove_vma_list(mm, vma);
94037
94038+ track_exec_limit(mm, start, end, 0UL);
94039+
94040 return 0;
94041 }
94042
94043@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94044 int ret;
94045 struct mm_struct *mm = current->mm;
94046
94047+
94048+#ifdef CONFIG_PAX_SEGMEXEC
94049+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94050+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94051+ return -EINVAL;
94052+#endif
94053+
94054 down_write(&mm->mmap_sem);
94055 ret = do_munmap(mm, start, len);
94056 up_write(&mm->mmap_sem);
94057@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94058 return vm_munmap(addr, len);
94059 }
94060
94061-static inline void verify_mm_writelocked(struct mm_struct *mm)
94062-{
94063-#ifdef CONFIG_DEBUG_VM
94064- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94065- WARN_ON(1);
94066- up_read(&mm->mmap_sem);
94067- }
94068-#endif
94069-}
94070-
94071 /*
94072 * this is really a simplified "do_mmap". it only handles
94073 * anonymous maps. eventually we may be able to do some
94074@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94075 struct rb_node ** rb_link, * rb_parent;
94076 pgoff_t pgoff = addr >> PAGE_SHIFT;
94077 int error;
94078+ unsigned long charged;
94079
94080 len = PAGE_ALIGN(len);
94081 if (!len)
94082@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94083
94084 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94085
94086+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94087+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94088+ flags &= ~VM_EXEC;
94089+
94090+#ifdef CONFIG_PAX_MPROTECT
94091+ if (mm->pax_flags & MF_PAX_MPROTECT)
94092+ flags &= ~VM_MAYEXEC;
94093+#endif
94094+
94095+ }
94096+#endif
94097+
94098 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94099 if (error & ~PAGE_MASK)
94100 return error;
94101
94102+ charged = len >> PAGE_SHIFT;
94103+
94104 error = mlock_future_check(mm, mm->def_flags, len);
94105 if (error)
94106 return error;
94107@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94108 /*
94109 * Clear old maps. this also does some error checking for us
94110 */
94111- munmap_back:
94112 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94113 if (do_munmap(mm, addr, len))
94114 return -ENOMEM;
94115- goto munmap_back;
94116+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94117 }
94118
94119 /* Check against address space limits *after* clearing old maps... */
94120- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94121+ if (!may_expand_vm(mm, charged))
94122 return -ENOMEM;
94123
94124 if (mm->map_count > sysctl_max_map_count)
94125 return -ENOMEM;
94126
94127- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94128+ if (security_vm_enough_memory_mm(mm, charged))
94129 return -ENOMEM;
94130
94131 /* Can we just expand an old private anonymous mapping? */
94132@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94133 */
94134 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94135 if (!vma) {
94136- vm_unacct_memory(len >> PAGE_SHIFT);
94137+ vm_unacct_memory(charged);
94138 return -ENOMEM;
94139 }
94140
94141@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94142 vma_link(mm, vma, prev, rb_link, rb_parent);
94143 out:
94144 perf_event_mmap(vma);
94145- mm->total_vm += len >> PAGE_SHIFT;
94146+ mm->total_vm += charged;
94147 if (flags & VM_LOCKED)
94148- mm->locked_vm += (len >> PAGE_SHIFT);
94149+ mm->locked_vm += charged;
94150 vma->vm_flags |= VM_SOFTDIRTY;
94151+ track_exec_limit(mm, addr, addr + len, flags);
94152 return addr;
94153 }
94154
94155@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94156 while (vma) {
94157 if (vma->vm_flags & VM_ACCOUNT)
94158 nr_accounted += vma_pages(vma);
94159+ vma->vm_mirror = NULL;
94160 vma = remove_vma(vma);
94161 }
94162 vm_unacct_memory(nr_accounted);
94163@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94164 struct vm_area_struct *prev;
94165 struct rb_node **rb_link, *rb_parent;
94166
94167+#ifdef CONFIG_PAX_SEGMEXEC
94168+ struct vm_area_struct *vma_m = NULL;
94169+#endif
94170+
94171+ if (security_mmap_addr(vma->vm_start))
94172+ return -EPERM;
94173+
94174 /*
94175 * The vm_pgoff of a purely anonymous vma should be irrelevant
94176 * until its first write fault, when page's anon_vma and index
94177@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94178 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94179 return -ENOMEM;
94180
94181+#ifdef CONFIG_PAX_SEGMEXEC
94182+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94183+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94184+ if (!vma_m)
94185+ return -ENOMEM;
94186+ }
94187+#endif
94188+
94189 vma_link(mm, vma, prev, rb_link, rb_parent);
94190+
94191+#ifdef CONFIG_PAX_SEGMEXEC
94192+ if (vma_m)
94193+ BUG_ON(pax_mirror_vma(vma_m, vma));
94194+#endif
94195+
94196 return 0;
94197 }
94198
94199@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94200 struct rb_node **rb_link, *rb_parent;
94201 bool faulted_in_anon_vma = true;
94202
94203+ BUG_ON(vma->vm_mirror);
94204+
94205 /*
94206 * If anonymous vma has not yet been faulted, update new pgoff
94207 * to match new location, to increase its chance of merging.
94208@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94209 return NULL;
94210 }
94211
94212+#ifdef CONFIG_PAX_SEGMEXEC
94213+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94214+{
94215+ struct vm_area_struct *prev_m;
94216+ struct rb_node **rb_link_m, *rb_parent_m;
94217+ struct mempolicy *pol_m;
94218+
94219+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94220+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94221+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94222+ *vma_m = *vma;
94223+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94224+ if (anon_vma_clone(vma_m, vma))
94225+ return -ENOMEM;
94226+ pol_m = vma_policy(vma_m);
94227+ mpol_get(pol_m);
94228+ set_vma_policy(vma_m, pol_m);
94229+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94230+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94231+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94232+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94233+ if (vma_m->vm_file)
94234+ get_file(vma_m->vm_file);
94235+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94236+ vma_m->vm_ops->open(vma_m);
94237+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94238+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94239+ vma_m->vm_mirror = vma;
94240+ vma->vm_mirror = vma_m;
94241+ return 0;
94242+}
94243+#endif
94244+
94245 /*
94246 * Return true if the calling process may expand its vm space by the passed
94247 * number of pages
94248@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94249
94250 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94251
94252+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94253 if (cur + npages > lim)
94254 return 0;
94255 return 1;
94256@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94257 vma->vm_start = addr;
94258 vma->vm_end = addr + len;
94259
94260+#ifdef CONFIG_PAX_MPROTECT
94261+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94262+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94263+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94264+ return -EPERM;
94265+ if (!(vm_flags & VM_EXEC))
94266+ vm_flags &= ~VM_MAYEXEC;
94267+#else
94268+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94269+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94270+#endif
94271+ else
94272+ vm_flags &= ~VM_MAYWRITE;
94273+ }
94274+#endif
94275+
94276 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94277 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94278
94279diff --git a/mm/mprotect.c b/mm/mprotect.c
94280index 769a67a..414d24f 100644
94281--- a/mm/mprotect.c
94282+++ b/mm/mprotect.c
94283@@ -24,10 +24,18 @@
94284 #include <linux/migrate.h>
94285 #include <linux/perf_event.h>
94286 #include <linux/ksm.h>
94287+#include <linux/sched/sysctl.h>
94288+
94289+#ifdef CONFIG_PAX_MPROTECT
94290+#include <linux/elf.h>
94291+#include <linux/binfmts.h>
94292+#endif
94293+
94294 #include <asm/uaccess.h>
94295 #include <asm/pgtable.h>
94296 #include <asm/cacheflush.h>
94297 #include <asm/tlbflush.h>
94298+#include <asm/mmu_context.h>
94299
94300 #ifndef pgprot_modify
94301 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94302@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94303 return pages;
94304 }
94305
94306+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94307+/* called while holding the mmap semaphor for writing except stack expansion */
94308+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94309+{
94310+ unsigned long oldlimit, newlimit = 0UL;
94311+
94312+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94313+ return;
94314+
94315+ spin_lock(&mm->page_table_lock);
94316+ oldlimit = mm->context.user_cs_limit;
94317+ if ((prot & VM_EXEC) && oldlimit < end)
94318+ /* USER_CS limit moved up */
94319+ newlimit = end;
94320+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94321+ /* USER_CS limit moved down */
94322+ newlimit = start;
94323+
94324+ if (newlimit) {
94325+ mm->context.user_cs_limit = newlimit;
94326+
94327+#ifdef CONFIG_SMP
94328+ wmb();
94329+ cpus_clear(mm->context.cpu_user_cs_mask);
94330+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94331+#endif
94332+
94333+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94334+ }
94335+ spin_unlock(&mm->page_table_lock);
94336+ if (newlimit == end) {
94337+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94338+
94339+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94340+ if (is_vm_hugetlb_page(vma))
94341+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94342+ else
94343+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94344+ }
94345+}
94346+#endif
94347+
94348 int
94349 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94350 unsigned long start, unsigned long end, unsigned long newflags)
94351@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94352 int error;
94353 int dirty_accountable = 0;
94354
94355+#ifdef CONFIG_PAX_SEGMEXEC
94356+ struct vm_area_struct *vma_m = NULL;
94357+ unsigned long start_m, end_m;
94358+
94359+ start_m = start + SEGMEXEC_TASK_SIZE;
94360+ end_m = end + SEGMEXEC_TASK_SIZE;
94361+#endif
94362+
94363 if (newflags == oldflags) {
94364 *pprev = vma;
94365 return 0;
94366 }
94367
94368+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94369+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94370+
94371+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94372+ return -ENOMEM;
94373+
94374+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94375+ return -ENOMEM;
94376+ }
94377+
94378 /*
94379 * If we make a private mapping writable we increase our commit;
94380 * but (without finer accounting) cannot reduce our commit if we
94381@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94382 }
94383 }
94384
94385+#ifdef CONFIG_PAX_SEGMEXEC
94386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94387+ if (start != vma->vm_start) {
94388+ error = split_vma(mm, vma, start, 1);
94389+ if (error)
94390+ goto fail;
94391+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94392+ *pprev = (*pprev)->vm_next;
94393+ }
94394+
94395+ if (end != vma->vm_end) {
94396+ error = split_vma(mm, vma, end, 0);
94397+ if (error)
94398+ goto fail;
94399+ }
94400+
94401+ if (pax_find_mirror_vma(vma)) {
94402+ error = __do_munmap(mm, start_m, end_m - start_m);
94403+ if (error)
94404+ goto fail;
94405+ } else {
94406+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94407+ if (!vma_m) {
94408+ error = -ENOMEM;
94409+ goto fail;
94410+ }
94411+ vma->vm_flags = newflags;
94412+ error = pax_mirror_vma(vma_m, vma);
94413+ if (error) {
94414+ vma->vm_flags = oldflags;
94415+ goto fail;
94416+ }
94417+ }
94418+ }
94419+#endif
94420+
94421 /*
94422 * First try to merge with previous and/or next vma.
94423 */
94424@@ -277,9 +381,21 @@ success:
94425 * vm_flags and vm_page_prot are protected by the mmap_sem
94426 * held in write mode.
94427 */
94428+
94429+#ifdef CONFIG_PAX_SEGMEXEC
94430+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94431+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94432+#endif
94433+
94434 vma->vm_flags = newflags;
94435+
94436+#ifdef CONFIG_PAX_MPROTECT
94437+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94438+ mm->binfmt->handle_mprotect(vma, newflags);
94439+#endif
94440+
94441 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94442- vm_get_page_prot(newflags));
94443+ vm_get_page_prot(vma->vm_flags));
94444
94445 if (vma_wants_writenotify(vma)) {
94446 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94447@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94448 end = start + len;
94449 if (end <= start)
94450 return -ENOMEM;
94451+
94452+#ifdef CONFIG_PAX_SEGMEXEC
94453+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94454+ if (end > SEGMEXEC_TASK_SIZE)
94455+ return -EINVAL;
94456+ } else
94457+#endif
94458+
94459+ if (end > TASK_SIZE)
94460+ return -EINVAL;
94461+
94462 if (!arch_validate_prot(prot))
94463 return -EINVAL;
94464
94465@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94466 /*
94467 * Does the application expect PROT_READ to imply PROT_EXEC:
94468 */
94469- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94470+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94471 prot |= PROT_EXEC;
94472
94473 vm_flags = calc_vm_prot_bits(prot);
94474@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94475 if (start > vma->vm_start)
94476 prev = vma;
94477
94478+#ifdef CONFIG_PAX_MPROTECT
94479+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94480+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94481+#endif
94482+
94483 for (nstart = start ; ; ) {
94484 unsigned long newflags;
94485
94486@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94487
94488 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94489 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94490+ if (prot & (PROT_WRITE | PROT_EXEC))
94491+ gr_log_rwxmprotect(vma);
94492+
94493+ error = -EACCES;
94494+ goto out;
94495+ }
94496+
94497+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94498 error = -EACCES;
94499 goto out;
94500 }
94501@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94502 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94503 if (error)
94504 goto out;
94505+
94506+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94507+
94508 nstart = tmp;
94509
94510 if (nstart < prev->vm_end)
94511diff --git a/mm/mremap.c b/mm/mremap.c
94512index 0843feb..4f5b2e6 100644
94513--- a/mm/mremap.c
94514+++ b/mm/mremap.c
94515@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94516 continue;
94517 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94518 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94519+
94520+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94521+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94522+ pte = pte_exprotect(pte);
94523+#endif
94524+
94525 pte = move_soft_dirty_pte(pte);
94526 set_pte_at(mm, new_addr, new_pte, pte);
94527 }
94528@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94529 if (is_vm_hugetlb_page(vma))
94530 goto Einval;
94531
94532+#ifdef CONFIG_PAX_SEGMEXEC
94533+ if (pax_find_mirror_vma(vma))
94534+ goto Einval;
94535+#endif
94536+
94537 /* We can't remap across vm area boundaries */
94538 if (old_len > vma->vm_end - addr)
94539 goto Efault;
94540@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94541 unsigned long ret = -EINVAL;
94542 unsigned long charged = 0;
94543 unsigned long map_flags;
94544+ unsigned long pax_task_size = TASK_SIZE;
94545
94546 if (new_addr & ~PAGE_MASK)
94547 goto out;
94548
94549- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94550+#ifdef CONFIG_PAX_SEGMEXEC
94551+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94552+ pax_task_size = SEGMEXEC_TASK_SIZE;
94553+#endif
94554+
94555+ pax_task_size -= PAGE_SIZE;
94556+
94557+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94558 goto out;
94559
94560 /* Check if the location we're moving into overlaps the
94561 * old location at all, and fail if it does.
94562 */
94563- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94564- goto out;
94565-
94566- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94567+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94568 goto out;
94569
94570 ret = do_munmap(mm, new_addr, new_len);
94571@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94572 unsigned long ret = -EINVAL;
94573 unsigned long charged = 0;
94574 bool locked = false;
94575+ unsigned long pax_task_size = TASK_SIZE;
94576
94577 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94578 return ret;
94579@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94580 if (!new_len)
94581 return ret;
94582
94583+#ifdef CONFIG_PAX_SEGMEXEC
94584+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94585+ pax_task_size = SEGMEXEC_TASK_SIZE;
94586+#endif
94587+
94588+ pax_task_size -= PAGE_SIZE;
94589+
94590+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94591+ old_len > pax_task_size || addr > pax_task_size-old_len)
94592+ return ret;
94593+
94594 down_write(&current->mm->mmap_sem);
94595
94596 if (flags & MREMAP_FIXED) {
94597@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94598 new_addr = addr;
94599 }
94600 ret = addr;
94601+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94602 goto out;
94603 }
94604 }
94605@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94606 goto out;
94607 }
94608
94609+ map_flags = vma->vm_flags;
94610 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94611+ if (!(ret & ~PAGE_MASK)) {
94612+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94613+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94614+ }
94615 }
94616 out:
94617 if (ret & ~PAGE_MASK)
94618diff --git a/mm/nommu.c b/mm/nommu.c
94619index 8740213..f87e25b 100644
94620--- a/mm/nommu.c
94621+++ b/mm/nommu.c
94622@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94623 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94624 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94625 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94626-int heap_stack_gap = 0;
94627
94628 atomic_long_t mmap_pages_allocated;
94629
94630@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94631 EXPORT_SYMBOL(find_vma);
94632
94633 /*
94634- * find a VMA
94635- * - we don't extend stack VMAs under NOMMU conditions
94636- */
94637-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94638-{
94639- return find_vma(mm, addr);
94640-}
94641-
94642-/*
94643 * expand a stack to a given address
94644 * - not supported under NOMMU conditions
94645 */
94646@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94647
94648 /* most fields are the same, copy all, and then fixup */
94649 *new = *vma;
94650+ INIT_LIST_HEAD(&new->anon_vma_chain);
94651 *region = *vma->vm_region;
94652 new->vm_region = region;
94653
94654@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94655 }
94656 EXPORT_SYMBOL(generic_file_remap_pages);
94657
94658-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94659- unsigned long addr, void *buf, int len, int write)
94660+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94661+ unsigned long addr, void *buf, size_t len, int write)
94662 {
94663 struct vm_area_struct *vma;
94664
94665@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94666 *
94667 * The caller must hold a reference on @mm.
94668 */
94669-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94670- void *buf, int len, int write)
94671+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94672+ void *buf, size_t len, int write)
94673 {
94674 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94675 }
94676@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94677 * Access another process' address space.
94678 * - source/target buffer must be kernel space
94679 */
94680-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94681+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94682 {
94683 struct mm_struct *mm;
94684
94685diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94686index 7106cb1..0805f48 100644
94687--- a/mm/page-writeback.c
94688+++ b/mm/page-writeback.c
94689@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94690 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94691 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94692 */
94693-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94694+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94695 unsigned long thresh,
94696 unsigned long bg_thresh,
94697 unsigned long dirty,
94698diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94699index 7387a67..3994687 100644
94700--- a/mm/page_alloc.c
94701+++ b/mm/page_alloc.c
94702@@ -61,6 +61,7 @@
94703 #include <linux/page-debug-flags.h>
94704 #include <linux/hugetlb.h>
94705 #include <linux/sched/rt.h>
94706+#include <linux/random.h>
94707
94708 #include <asm/sections.h>
94709 #include <asm/tlbflush.h>
94710@@ -354,7 +355,7 @@ out:
94711 * This usage means that zero-order pages may not be compound.
94712 */
94713
94714-static void free_compound_page(struct page *page)
94715+void free_compound_page(struct page *page)
94716 {
94717 __free_pages_ok(page, compound_order(page));
94718 }
94719@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94720 int i;
94721 int bad = 0;
94722
94723+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94724+ unsigned long index = 1UL << order;
94725+#endif
94726+
94727 trace_mm_page_free(page, order);
94728 kmemcheck_free_shadow(page, order);
94729
94730@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94731 debug_check_no_obj_freed(page_address(page),
94732 PAGE_SIZE << order);
94733 }
94734+
94735+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94736+ for (; index; --index)
94737+ sanitize_highpage(page + index - 1);
94738+#endif
94739+
94740 arch_free_page(page, order);
94741 kernel_map_pages(page, 1 << order, 0);
94742
94743@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94744 local_irq_restore(flags);
94745 }
94746
94747+#ifdef CONFIG_PAX_LATENT_ENTROPY
94748+bool __meminitdata extra_latent_entropy;
94749+
94750+static int __init setup_pax_extra_latent_entropy(char *str)
94751+{
94752+ extra_latent_entropy = true;
94753+ return 0;
94754+}
94755+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94756+
94757+volatile u64 latent_entropy __latent_entropy;
94758+EXPORT_SYMBOL(latent_entropy);
94759+#endif
94760+
94761 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94762 {
94763 unsigned int nr_pages = 1 << order;
94764@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94765 __ClearPageReserved(p);
94766 set_page_count(p, 0);
94767
94768+#ifdef CONFIG_PAX_LATENT_ENTROPY
94769+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94770+ u64 hash = 0;
94771+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94772+ const u64 *data = lowmem_page_address(page);
94773+
94774+ for (index = 0; index < end; index++)
94775+ hash ^= hash + data[index];
94776+ latent_entropy ^= hash;
94777+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94778+ }
94779+#endif
94780+
94781 page_zone(page)->managed_pages += nr_pages;
94782 set_page_refcounted(page);
94783 __free_pages(page, order);
94784@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94785 arch_alloc_page(page, order);
94786 kernel_map_pages(page, 1 << order, 1);
94787
94788+#ifndef CONFIG_PAX_MEMORY_SANITIZE
94789 if (gfp_flags & __GFP_ZERO)
94790 prep_zero_page(page, order, gfp_flags);
94791+#endif
94792
94793 if (order && (gfp_flags & __GFP_COMP))
94794 prep_compound_page(page, order);
94795diff --git a/mm/page_io.c b/mm/page_io.c
94796index 7c59ef6..1358905 100644
94797--- a/mm/page_io.c
94798+++ b/mm/page_io.c
94799@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94800 struct file *swap_file = sis->swap_file;
94801 struct address_space *mapping = swap_file->f_mapping;
94802 struct iovec iov = {
94803- .iov_base = kmap(page),
94804+ .iov_base = (void __force_user *)kmap(page),
94805 .iov_len = PAGE_SIZE,
94806 };
94807
94808diff --git a/mm/percpu.c b/mm/percpu.c
94809index 036cfe0..980d0fa 100644
94810--- a/mm/percpu.c
94811+++ b/mm/percpu.c
94812@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94813 static unsigned int pcpu_high_unit_cpu __read_mostly;
94814
94815 /* the address of the first chunk which starts with the kernel static area */
94816-void *pcpu_base_addr __read_mostly;
94817+void *pcpu_base_addr __read_only;
94818 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94819
94820 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94821diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94822index fd26d04..0cea1b0 100644
94823--- a/mm/process_vm_access.c
94824+++ b/mm/process_vm_access.c
94825@@ -13,6 +13,7 @@
94826 #include <linux/uio.h>
94827 #include <linux/sched.h>
94828 #include <linux/highmem.h>
94829+#include <linux/security.h>
94830 #include <linux/ptrace.h>
94831 #include <linux/slab.h>
94832 #include <linux/syscalls.h>
94833@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94834 size_t iov_l_curr_offset = 0;
94835 ssize_t iov_len;
94836
94837+ return -ENOSYS; // PaX: until properly audited
94838+
94839 /*
94840 * Work out how many pages of struct pages we're going to need
94841 * when eventually calling get_user_pages
94842 */
94843 for (i = 0; i < riovcnt; i++) {
94844 iov_len = rvec[i].iov_len;
94845- if (iov_len > 0) {
94846- nr_pages_iov = ((unsigned long)rvec[i].iov_base
94847- + iov_len)
94848- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94849- / PAGE_SIZE + 1;
94850- nr_pages = max(nr_pages, nr_pages_iov);
94851- }
94852+ if (iov_len <= 0)
94853+ continue;
94854+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94855+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94856+ nr_pages = max(nr_pages, nr_pages_iov);
94857 }
94858
94859 if (nr_pages == 0)
94860@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94861 goto free_proc_pages;
94862 }
94863
94864+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94865+ rc = -EPERM;
94866+ goto put_task_struct;
94867+ }
94868+
94869 mm = mm_access(task, PTRACE_MODE_ATTACH);
94870 if (!mm || IS_ERR(mm)) {
94871 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94872diff --git a/mm/rmap.c b/mm/rmap.c
94873index d3cbac5..0788da4 100644
94874--- a/mm/rmap.c
94875+++ b/mm/rmap.c
94876@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94877 struct anon_vma *anon_vma = vma->anon_vma;
94878 struct anon_vma_chain *avc;
94879
94880+#ifdef CONFIG_PAX_SEGMEXEC
94881+ struct anon_vma_chain *avc_m = NULL;
94882+#endif
94883+
94884 might_sleep();
94885 if (unlikely(!anon_vma)) {
94886 struct mm_struct *mm = vma->vm_mm;
94887@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94888 if (!avc)
94889 goto out_enomem;
94890
94891+#ifdef CONFIG_PAX_SEGMEXEC
94892+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94893+ if (!avc_m)
94894+ goto out_enomem_free_avc;
94895+#endif
94896+
94897 anon_vma = find_mergeable_anon_vma(vma);
94898 allocated = NULL;
94899 if (!anon_vma) {
94900@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94901 /* page_table_lock to protect against threads */
94902 spin_lock(&mm->page_table_lock);
94903 if (likely(!vma->anon_vma)) {
94904+
94905+#ifdef CONFIG_PAX_SEGMEXEC
94906+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94907+
94908+ if (vma_m) {
94909+ BUG_ON(vma_m->anon_vma);
94910+ vma_m->anon_vma = anon_vma;
94911+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
94912+ avc_m = NULL;
94913+ }
94914+#endif
94915+
94916 vma->anon_vma = anon_vma;
94917 anon_vma_chain_link(vma, avc, anon_vma);
94918 allocated = NULL;
94919@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94920
94921 if (unlikely(allocated))
94922 put_anon_vma(allocated);
94923+
94924+#ifdef CONFIG_PAX_SEGMEXEC
94925+ if (unlikely(avc_m))
94926+ anon_vma_chain_free(avc_m);
94927+#endif
94928+
94929 if (unlikely(avc))
94930 anon_vma_chain_free(avc);
94931 }
94932 return 0;
94933
94934 out_enomem_free_avc:
94935+
94936+#ifdef CONFIG_PAX_SEGMEXEC
94937+ if (avc_m)
94938+ anon_vma_chain_free(avc_m);
94939+#endif
94940+
94941 anon_vma_chain_free(avc);
94942 out_enomem:
94943 return -ENOMEM;
94944@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94945 * Attach the anon_vmas from src to dst.
94946 * Returns 0 on success, -ENOMEM on failure.
94947 */
94948-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94949+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94950 {
94951 struct anon_vma_chain *avc, *pavc;
94952 struct anon_vma *root = NULL;
94953@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94954 * the corresponding VMA in the parent process is attached to.
94955 * Returns 0 on success, non-zero on failure.
94956 */
94957-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94958+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94959 {
94960 struct anon_vma_chain *avc;
94961 struct anon_vma *anon_vma;
94962@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94963 void __init anon_vma_init(void)
94964 {
94965 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94966- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94967- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94968+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94969+ anon_vma_ctor);
94970+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94971+ SLAB_PANIC|SLAB_NO_SANITIZE);
94972 }
94973
94974 /*
94975diff --git a/mm/shmem.c b/mm/shmem.c
94976index 1f18c9d..3e03d33 100644
94977--- a/mm/shmem.c
94978+++ b/mm/shmem.c
94979@@ -33,7 +33,7 @@
94980 #include <linux/swap.h>
94981 #include <linux/aio.h>
94982
94983-static struct vfsmount *shm_mnt;
94984+struct vfsmount *shm_mnt;
94985
94986 #ifdef CONFIG_SHMEM
94987 /*
94988@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94989 #define BOGO_DIRENT_SIZE 20
94990
94991 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94992-#define SHORT_SYMLINK_LEN 128
94993+#define SHORT_SYMLINK_LEN 64
94994
94995 /*
94996 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94997@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94998 static int shmem_xattr_validate(const char *name)
94999 {
95000 struct { const char *prefix; size_t len; } arr[] = {
95001+
95002+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95003+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95004+#endif
95005+
95006 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95007 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95008 };
95009@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95010 if (err)
95011 return err;
95012
95013+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95014+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95015+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95016+ return -EOPNOTSUPP;
95017+ if (size > 8)
95018+ return -EINVAL;
95019+ }
95020+#endif
95021+
95022 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95023 }
95024
95025@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95026 int err = -ENOMEM;
95027
95028 /* Round up to L1_CACHE_BYTES to resist false sharing */
95029- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95030- L1_CACHE_BYTES), GFP_KERNEL);
95031+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95032 if (!sbinfo)
95033 return -ENOMEM;
95034
95035diff --git a/mm/slab.c b/mm/slab.c
95036index b264214..83872cd 100644
95037--- a/mm/slab.c
95038+++ b/mm/slab.c
95039@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95040 if ((x)->max_freeable < i) \
95041 (x)->max_freeable = i; \
95042 } while (0)
95043-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95044-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95045-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95046-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95047+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95048+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95049+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95050+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95051+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95052+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95053 #else
95054 #define STATS_INC_ACTIVE(x) do { } while (0)
95055 #define STATS_DEC_ACTIVE(x) do { } while (0)
95056@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95057 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95058 #define STATS_INC_FREEHIT(x) do { } while (0)
95059 #define STATS_INC_FREEMISS(x) do { } while (0)
95060+#define STATS_INC_SANITIZED(x) do { } while (0)
95061+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95062 #endif
95063
95064 #if DEBUG
95065@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95066 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95067 */
95068 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95069- const struct page *page, void *obj)
95070+ const struct page *page, const void *obj)
95071 {
95072 u32 offset = (obj - page->s_mem);
95073 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95074@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95075 */
95076
95077 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95078- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95079+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95080
95081 if (INDEX_AC != INDEX_NODE)
95082 kmalloc_caches[INDEX_NODE] =
95083 create_kmalloc_cache("kmalloc-node",
95084- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95085+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95086
95087 slab_early_init = 0;
95088
95089@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95090 struct array_cache *ac = cpu_cache_get(cachep);
95091
95092 check_irq_off();
95093+
95094+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95095+ if (pax_sanitize_slab) {
95096+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95097+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95098+
95099+ if (cachep->ctor)
95100+ cachep->ctor(objp);
95101+
95102+ STATS_INC_SANITIZED(cachep);
95103+ } else
95104+ STATS_INC_NOT_SANITIZED(cachep);
95105+ }
95106+#endif
95107+
95108 kmemleak_free_recursive(objp, cachep->flags);
95109 objp = cache_free_debugcheck(cachep, objp, caller);
95110
95111@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95112
95113 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95114 return;
95115+ VM_BUG_ON(!virt_addr_valid(objp));
95116 local_irq_save(flags);
95117 kfree_debugcheck(objp);
95118 c = virt_to_cache(objp);
95119@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95120 }
95121 /* cpu stats */
95122 {
95123- unsigned long allochit = atomic_read(&cachep->allochit);
95124- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95125- unsigned long freehit = atomic_read(&cachep->freehit);
95126- unsigned long freemiss = atomic_read(&cachep->freemiss);
95127+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95128+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95129+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95130+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95131
95132 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95133 allochit, allocmiss, freehit, freemiss);
95134 }
95135+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95136+ {
95137+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95138+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95139+
95140+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95141+ }
95142+#endif
95143 #endif
95144 }
95145
95146@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95147 static int __init slab_proc_init(void)
95148 {
95149 #ifdef CONFIG_DEBUG_SLAB_LEAK
95150- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95151+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95152 #endif
95153 return 0;
95154 }
95155 module_init(slab_proc_init);
95156 #endif
95157
95158+bool is_usercopy_object(const void *ptr)
95159+{
95160+ struct page *page;
95161+ struct kmem_cache *cachep;
95162+
95163+ if (ZERO_OR_NULL_PTR(ptr))
95164+ return false;
95165+
95166+ if (!slab_is_available())
95167+ return false;
95168+
95169+ if (!virt_addr_valid(ptr))
95170+ return false;
95171+
95172+ page = virt_to_head_page(ptr);
95173+
95174+ if (!PageSlab(page))
95175+ return false;
95176+
95177+ cachep = page->slab_cache;
95178+ return cachep->flags & SLAB_USERCOPY;
95179+}
95180+
95181+#ifdef CONFIG_PAX_USERCOPY
95182+const char *check_heap_object(const void *ptr, unsigned long n)
95183+{
95184+ struct page *page;
95185+ struct kmem_cache *cachep;
95186+ unsigned int objnr;
95187+ unsigned long offset;
95188+
95189+ if (ZERO_OR_NULL_PTR(ptr))
95190+ return "<null>";
95191+
95192+ if (!virt_addr_valid(ptr))
95193+ return NULL;
95194+
95195+ page = virt_to_head_page(ptr);
95196+
95197+ if (!PageSlab(page))
95198+ return NULL;
95199+
95200+ cachep = page->slab_cache;
95201+ if (!(cachep->flags & SLAB_USERCOPY))
95202+ return cachep->name;
95203+
95204+ objnr = obj_to_index(cachep, page, ptr);
95205+ BUG_ON(objnr >= cachep->num);
95206+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95207+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95208+ return NULL;
95209+
95210+ return cachep->name;
95211+}
95212+#endif
95213+
95214 /**
95215 * ksize - get the actual amount of memory allocated for a given object
95216 * @objp: Pointer to the object
95217diff --git a/mm/slab.h b/mm/slab.h
95218index 8184a7c..ab27737 100644
95219--- a/mm/slab.h
95220+++ b/mm/slab.h
95221@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95222 /* The slab cache that manages slab cache information */
95223 extern struct kmem_cache *kmem_cache;
95224
95225+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95226+#ifdef CONFIG_X86_64
95227+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95228+#else
95229+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95230+#endif
95231+extern bool pax_sanitize_slab;
95232+#endif
95233+
95234 unsigned long calculate_alignment(unsigned long flags,
95235 unsigned long align, unsigned long size);
95236
95237@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95238
95239 /* Legal flag mask for kmem_cache_create(), for various configurations */
95240 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95241- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95242+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95243+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95244
95245 #if defined(CONFIG_DEBUG_SLAB)
95246 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95247@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95248 return s;
95249
95250 page = virt_to_head_page(x);
95251+
95252+ BUG_ON(!PageSlab(page));
95253+
95254 cachep = page->slab_cache;
95255 if (slab_equal_or_root(cachep, s))
95256 return cachep;
95257diff --git a/mm/slab_common.c b/mm/slab_common.c
95258index 1ec3c61..2067c11 100644
95259--- a/mm/slab_common.c
95260+++ b/mm/slab_common.c
95261@@ -23,11 +23,22 @@
95262
95263 #include "slab.h"
95264
95265-enum slab_state slab_state;
95266+enum slab_state slab_state __read_only;
95267 LIST_HEAD(slab_caches);
95268 DEFINE_MUTEX(slab_mutex);
95269 struct kmem_cache *kmem_cache;
95270
95271+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95272+bool pax_sanitize_slab __read_only = true;
95273+static int __init pax_sanitize_slab_setup(char *str)
95274+{
95275+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95276+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95277+ return 1;
95278+}
95279+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95280+#endif
95281+
95282 #ifdef CONFIG_DEBUG_VM
95283 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95284 size_t size)
95285@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95286 if (err)
95287 goto out_free_cache;
95288
95289- s->refcount = 1;
95290+ atomic_set(&s->refcount, 1);
95291 list_add(&s->list, &slab_caches);
95292 memcg_register_cache(s);
95293
95294@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95295
95296 get_online_cpus();
95297 mutex_lock(&slab_mutex);
95298- s->refcount--;
95299- if (!s->refcount) {
95300+ if (atomic_dec_and_test(&s->refcount)) {
95301 list_del(&s->list);
95302
95303 if (!__kmem_cache_shutdown(s)) {
95304@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95305 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95306 name, size, err);
95307
95308- s->refcount = -1; /* Exempt from merging for now */
95309+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95310 }
95311
95312 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95313@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95314
95315 create_boot_cache(s, name, size, flags);
95316 list_add(&s->list, &slab_caches);
95317- s->refcount = 1;
95318+ atomic_set(&s->refcount, 1);
95319 return s;
95320 }
95321
95322@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95323 EXPORT_SYMBOL(kmalloc_dma_caches);
95324 #endif
95325
95326+#ifdef CONFIG_PAX_USERCOPY_SLABS
95327+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95328+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95329+#endif
95330+
95331 /*
95332 * Conversion table for small slabs sizes / 8 to the index in the
95333 * kmalloc array. This is necessary for slabs < 192 since we have non power
95334@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95335 return kmalloc_dma_caches[index];
95336
95337 #endif
95338+
95339+#ifdef CONFIG_PAX_USERCOPY_SLABS
95340+ if (unlikely((flags & GFP_USERCOPY)))
95341+ return kmalloc_usercopy_caches[index];
95342+
95343+#endif
95344+
95345 return kmalloc_caches[index];
95346 }
95347
95348@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95349 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95350 if (!kmalloc_caches[i]) {
95351 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95352- 1 << i, flags);
95353+ 1 << i, SLAB_USERCOPY | flags);
95354 }
95355
95356 /*
95357@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95358 * earlier power of two caches
95359 */
95360 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95361- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95362+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95363
95364 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95365- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95366+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95367 }
95368
95369 /* Kmalloc array is now usable */
95370@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95371 }
95372 }
95373 #endif
95374+
95375+#ifdef CONFIG_PAX_USERCOPY_SLABS
95376+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95377+ struct kmem_cache *s = kmalloc_caches[i];
95378+
95379+ if (s) {
95380+ int size = kmalloc_size(i);
95381+ char *n = kasprintf(GFP_NOWAIT,
95382+ "usercopy-kmalloc-%d", size);
95383+
95384+ BUG_ON(!n);
95385+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95386+ size, SLAB_USERCOPY | flags);
95387+ }
95388+ }
95389+#endif
95390+
95391 }
95392 #endif /* !CONFIG_SLOB */
95393
95394@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95395 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95396 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95397 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95398+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95399+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95400+#endif
95401 #endif
95402 seq_putc(m, '\n');
95403 }
95404diff --git a/mm/slob.c b/mm/slob.c
95405index 4bf8809..98a6914 100644
95406--- a/mm/slob.c
95407+++ b/mm/slob.c
95408@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95409 /*
95410 * Return the size of a slob block.
95411 */
95412-static slobidx_t slob_units(slob_t *s)
95413+static slobidx_t slob_units(const slob_t *s)
95414 {
95415 if (s->units > 0)
95416 return s->units;
95417@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95418 /*
95419 * Return the next free slob block pointer after this one.
95420 */
95421-static slob_t *slob_next(slob_t *s)
95422+static slob_t *slob_next(const slob_t *s)
95423 {
95424 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95425 slobidx_t next;
95426@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95427 /*
95428 * Returns true if s is the last free block in its page.
95429 */
95430-static int slob_last(slob_t *s)
95431+static int slob_last(const slob_t *s)
95432 {
95433 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95434 }
95435
95436-static void *slob_new_pages(gfp_t gfp, int order, int node)
95437+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95438 {
95439- void *page;
95440+ struct page *page;
95441
95442 #ifdef CONFIG_NUMA
95443 if (node != NUMA_NO_NODE)
95444@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95445 if (!page)
95446 return NULL;
95447
95448- return page_address(page);
95449+ __SetPageSlab(page);
95450+ return page;
95451 }
95452
95453-static void slob_free_pages(void *b, int order)
95454+static void slob_free_pages(struct page *sp, int order)
95455 {
95456 if (current->reclaim_state)
95457 current->reclaim_state->reclaimed_slab += 1 << order;
95458- free_pages((unsigned long)b, order);
95459+ __ClearPageSlab(sp);
95460+ page_mapcount_reset(sp);
95461+ sp->private = 0;
95462+ __free_pages(sp, order);
95463 }
95464
95465 /*
95466@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95467
95468 /* Not enough space: must allocate a new page */
95469 if (!b) {
95470- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95471- if (!b)
95472+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95473+ if (!sp)
95474 return NULL;
95475- sp = virt_to_page(b);
95476- __SetPageSlab(sp);
95477+ b = page_address(sp);
95478
95479 spin_lock_irqsave(&slob_lock, flags);
95480 sp->units = SLOB_UNITS(PAGE_SIZE);
95481 sp->freelist = b;
95482+ sp->private = 0;
95483 INIT_LIST_HEAD(&sp->list);
95484 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95485 set_slob_page_free(sp, slob_list);
95486@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95487 if (slob_page_free(sp))
95488 clear_slob_page_free(sp);
95489 spin_unlock_irqrestore(&slob_lock, flags);
95490- __ClearPageSlab(sp);
95491- page_mapcount_reset(sp);
95492- slob_free_pages(b, 0);
95493+ slob_free_pages(sp, 0);
95494 return;
95495 }
95496
95497+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95498+ if (pax_sanitize_slab)
95499+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95500+#endif
95501+
95502 if (!slob_page_free(sp)) {
95503 /* This slob page is about to become partially free. Easy! */
95504 sp->units = units;
95505@@ -424,11 +431,10 @@ out:
95506 */
95507
95508 static __always_inline void *
95509-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95510+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95511 {
95512- unsigned int *m;
95513- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95514- void *ret;
95515+ slob_t *m;
95516+ void *ret = NULL;
95517
95518 gfp &= gfp_allowed_mask;
95519
95520@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95521
95522 if (!m)
95523 return NULL;
95524- *m = size;
95525+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95526+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95527+ m[0].units = size;
95528+ m[1].units = align;
95529 ret = (void *)m + align;
95530
95531 trace_kmalloc_node(caller, ret,
95532 size, size + align, gfp, node);
95533 } else {
95534 unsigned int order = get_order(size);
95535+ struct page *page;
95536
95537 if (likely(order))
95538 gfp |= __GFP_COMP;
95539- ret = slob_new_pages(gfp, order, node);
95540+ page = slob_new_pages(gfp, order, node);
95541+ if (page) {
95542+ ret = page_address(page);
95543+ page->private = size;
95544+ }
95545
95546 trace_kmalloc_node(caller, ret,
95547 size, PAGE_SIZE << order, gfp, node);
95548 }
95549
95550- kmemleak_alloc(ret, size, 1, gfp);
95551+ return ret;
95552+}
95553+
95554+static __always_inline void *
95555+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95556+{
95557+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95558+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95559+
95560+ if (!ZERO_OR_NULL_PTR(ret))
95561+ kmemleak_alloc(ret, size, 1, gfp);
95562 return ret;
95563 }
95564
95565@@ -493,34 +517,112 @@ void kfree(const void *block)
95566 return;
95567 kmemleak_free(block);
95568
95569+ VM_BUG_ON(!virt_addr_valid(block));
95570 sp = virt_to_page(block);
95571- if (PageSlab(sp)) {
95572+ VM_BUG_ON(!PageSlab(sp));
95573+ if (!sp->private) {
95574 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95575- unsigned int *m = (unsigned int *)(block - align);
95576- slob_free(m, *m + align);
95577- } else
95578+ slob_t *m = (slob_t *)(block - align);
95579+ slob_free(m, m[0].units + align);
95580+ } else {
95581+ __ClearPageSlab(sp);
95582+ page_mapcount_reset(sp);
95583+ sp->private = 0;
95584 __free_pages(sp, compound_order(sp));
95585+ }
95586 }
95587 EXPORT_SYMBOL(kfree);
95588
95589+bool is_usercopy_object(const void *ptr)
95590+{
95591+ if (!slab_is_available())
95592+ return false;
95593+
95594+ // PAX: TODO
95595+
95596+ return false;
95597+}
95598+
95599+#ifdef CONFIG_PAX_USERCOPY
95600+const char *check_heap_object(const void *ptr, unsigned long n)
95601+{
95602+ struct page *page;
95603+ const slob_t *free;
95604+ const void *base;
95605+ unsigned long flags;
95606+
95607+ if (ZERO_OR_NULL_PTR(ptr))
95608+ return "<null>";
95609+
95610+ if (!virt_addr_valid(ptr))
95611+ return NULL;
95612+
95613+ page = virt_to_head_page(ptr);
95614+ if (!PageSlab(page))
95615+ return NULL;
95616+
95617+ if (page->private) {
95618+ base = page;
95619+ if (base <= ptr && n <= page->private - (ptr - base))
95620+ return NULL;
95621+ return "<slob>";
95622+ }
95623+
95624+ /* some tricky double walking to find the chunk */
95625+ spin_lock_irqsave(&slob_lock, flags);
95626+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95627+ free = page->freelist;
95628+
95629+ while (!slob_last(free) && (void *)free <= ptr) {
95630+ base = free + slob_units(free);
95631+ free = slob_next(free);
95632+ }
95633+
95634+ while (base < (void *)free) {
95635+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95636+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95637+ int offset;
95638+
95639+ if (ptr < base + align)
95640+ break;
95641+
95642+ offset = ptr - base - align;
95643+ if (offset >= m) {
95644+ base += size;
95645+ continue;
95646+ }
95647+
95648+ if (n > m - offset)
95649+ break;
95650+
95651+ spin_unlock_irqrestore(&slob_lock, flags);
95652+ return NULL;
95653+ }
95654+
95655+ spin_unlock_irqrestore(&slob_lock, flags);
95656+ return "<slob>";
95657+}
95658+#endif
95659+
95660 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95661 size_t ksize(const void *block)
95662 {
95663 struct page *sp;
95664 int align;
95665- unsigned int *m;
95666+ slob_t *m;
95667
95668 BUG_ON(!block);
95669 if (unlikely(block == ZERO_SIZE_PTR))
95670 return 0;
95671
95672 sp = virt_to_page(block);
95673- if (unlikely(!PageSlab(sp)))
95674- return PAGE_SIZE << compound_order(sp);
95675+ VM_BUG_ON(!PageSlab(sp));
95676+ if (sp->private)
95677+ return sp->private;
95678
95679 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95680- m = (unsigned int *)(block - align);
95681- return SLOB_UNITS(*m) * SLOB_UNIT;
95682+ m = (slob_t *)(block - align);
95683+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95684 }
95685 EXPORT_SYMBOL(ksize);
95686
95687@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95688
95689 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95690 {
95691- void *b;
95692+ void *b = NULL;
95693
95694 flags &= gfp_allowed_mask;
95695
95696 lockdep_trace_alloc(flags);
95697
95698+#ifdef CONFIG_PAX_USERCOPY_SLABS
95699+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95700+#else
95701 if (c->size < PAGE_SIZE) {
95702 b = slob_alloc(c->size, flags, c->align, node);
95703 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95704 SLOB_UNITS(c->size) * SLOB_UNIT,
95705 flags, node);
95706 } else {
95707- b = slob_new_pages(flags, get_order(c->size), node);
95708+ struct page *sp;
95709+
95710+ sp = slob_new_pages(flags, get_order(c->size), node);
95711+ if (sp) {
95712+ b = page_address(sp);
95713+ sp->private = c->size;
95714+ }
95715 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95716 PAGE_SIZE << get_order(c->size),
95717 flags, node);
95718 }
95719+#endif
95720
95721 if (b && c->ctor)
95722 c->ctor(b);
95723@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95724
95725 static void __kmem_cache_free(void *b, int size)
95726 {
95727- if (size < PAGE_SIZE)
95728+ struct page *sp;
95729+
95730+ sp = virt_to_page(b);
95731+ BUG_ON(!PageSlab(sp));
95732+ if (!sp->private)
95733 slob_free(b, size);
95734 else
95735- slob_free_pages(b, get_order(size));
95736+ slob_free_pages(sp, get_order(size));
95737 }
95738
95739 static void kmem_rcu_free(struct rcu_head *head)
95740@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95741
95742 void kmem_cache_free(struct kmem_cache *c, void *b)
95743 {
95744+ int size = c->size;
95745+
95746+#ifdef CONFIG_PAX_USERCOPY_SLABS
95747+ if (size + c->align < PAGE_SIZE) {
95748+ size += c->align;
95749+ b -= c->align;
95750+ }
95751+#endif
95752+
95753 kmemleak_free_recursive(b, c->flags);
95754 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95755 struct slob_rcu *slob_rcu;
95756- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95757- slob_rcu->size = c->size;
95758+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95759+ slob_rcu->size = size;
95760 call_rcu(&slob_rcu->head, kmem_rcu_free);
95761 } else {
95762- __kmem_cache_free(b, c->size);
95763+ __kmem_cache_free(b, size);
95764 }
95765
95766+#ifdef CONFIG_PAX_USERCOPY_SLABS
95767+ trace_kfree(_RET_IP_, b);
95768+#else
95769 trace_kmem_cache_free(_RET_IP_, b);
95770+#endif
95771+
95772 }
95773 EXPORT_SYMBOL(kmem_cache_free);
95774
95775diff --git a/mm/slub.c b/mm/slub.c
95776index 25f14ad..ff4d0b7 100644
95777--- a/mm/slub.c
95778+++ b/mm/slub.c
95779@@ -207,7 +207,7 @@ struct track {
95780
95781 enum track_item { TRACK_ALLOC, TRACK_FREE };
95782
95783-#ifdef CONFIG_SYSFS
95784+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95785 static int sysfs_slab_add(struct kmem_cache *);
95786 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95787 static void sysfs_slab_remove(struct kmem_cache *);
95788@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
95789 if (!t->addr)
95790 return;
95791
95792- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95793+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95794 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95795 #ifdef CONFIG_STACKTRACE
95796 {
95797@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95798
95799 slab_free_hook(s, x);
95800
95801+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95802+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95803+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95804+ if (s->ctor)
95805+ s->ctor(x);
95806+ }
95807+#endif
95808+
95809 redo:
95810 /*
95811 * Determine the currently cpus per cpu slab.
95812@@ -2733,7 +2741,7 @@ static int slub_min_objects;
95813 * Merge control. If this is set then no merging of slab caches will occur.
95814 * (Could be removed. This was introduced to pacify the merge skeptics.)
95815 */
95816-static int slub_nomerge;
95817+static int slub_nomerge = 1;
95818
95819 /*
95820 * Calculate the order of allocation given an slab object size.
95821@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95822 s->inuse = size;
95823
95824 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95825+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95826+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95827+#endif
95828 s->ctor)) {
95829 /*
95830 * Relocate free pointer after the object if it is not
95831@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95832 EXPORT_SYMBOL(__kmalloc_node);
95833 #endif
95834
95835+bool is_usercopy_object(const void *ptr)
95836+{
95837+ struct page *page;
95838+ struct kmem_cache *s;
95839+
95840+ if (ZERO_OR_NULL_PTR(ptr))
95841+ return false;
95842+
95843+ if (!slab_is_available())
95844+ return false;
95845+
95846+ if (!virt_addr_valid(ptr))
95847+ return false;
95848+
95849+ page = virt_to_head_page(ptr);
95850+
95851+ if (!PageSlab(page))
95852+ return false;
95853+
95854+ s = page->slab_cache;
95855+ return s->flags & SLAB_USERCOPY;
95856+}
95857+
95858+#ifdef CONFIG_PAX_USERCOPY
95859+const char *check_heap_object(const void *ptr, unsigned long n)
95860+{
95861+ struct page *page;
95862+ struct kmem_cache *s;
95863+ unsigned long offset;
95864+
95865+ if (ZERO_OR_NULL_PTR(ptr))
95866+ return "<null>";
95867+
95868+ if (!virt_addr_valid(ptr))
95869+ return NULL;
95870+
95871+ page = virt_to_head_page(ptr);
95872+
95873+ if (!PageSlab(page))
95874+ return NULL;
95875+
95876+ s = page->slab_cache;
95877+ if (!(s->flags & SLAB_USERCOPY))
95878+ return s->name;
95879+
95880+ offset = (ptr - page_address(page)) % s->size;
95881+ if (offset <= s->object_size && n <= s->object_size - offset)
95882+ return NULL;
95883+
95884+ return s->name;
95885+}
95886+#endif
95887+
95888 size_t ksize(const void *object)
95889 {
95890 struct page *page;
95891@@ -3387,6 +3451,7 @@ void kfree(const void *x)
95892 if (unlikely(ZERO_OR_NULL_PTR(x)))
95893 return;
95894
95895+ VM_BUG_ON(!virt_addr_valid(x));
95896 page = virt_to_head_page(x);
95897 if (unlikely(!PageSlab(page))) {
95898 BUG_ON(!PageCompound(page));
95899@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95900 /*
95901 * We may have set a slab to be unmergeable during bootstrap.
95902 */
95903- if (s->refcount < 0)
95904+ if (atomic_read(&s->refcount) < 0)
95905 return 1;
95906
95907 return 0;
95908@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95909
95910 s = find_mergeable(memcg, size, align, flags, name, ctor);
95911 if (s) {
95912- s->refcount++;
95913+ atomic_inc(&s->refcount);
95914 /*
95915 * Adjust the object sizes so that we clear
95916 * the complete object on kzalloc.
95917@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95918 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95919
95920 if (sysfs_slab_alias(s, name)) {
95921- s->refcount--;
95922+ atomic_dec(&s->refcount);
95923 s = NULL;
95924 }
95925 }
95926@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95927 }
95928 #endif
95929
95930-#ifdef CONFIG_SYSFS
95931+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95932 static int count_inuse(struct page *page)
95933 {
95934 return page->inuse;
95935@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
95936 validate_slab_cache(kmalloc_caches[9]);
95937 }
95938 #else
95939-#ifdef CONFIG_SYSFS
95940+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95941 static void resiliency_test(void) {};
95942 #endif
95943 #endif
95944
95945-#ifdef CONFIG_SYSFS
95946+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95947 enum slab_stat_type {
95948 SL_ALL, /* All slabs */
95949 SL_PARTIAL, /* Only partially allocated slabs */
95950@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
95951
95952 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95953 {
95954- return sprintf(buf, "%d\n", s->refcount - 1);
95955+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95956 }
95957 SLAB_ATTR_RO(aliases);
95958
95959@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95960 SLAB_ATTR_RO(cache_dma);
95961 #endif
95962
95963+#ifdef CONFIG_PAX_USERCOPY_SLABS
95964+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95965+{
95966+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95967+}
95968+SLAB_ATTR_RO(usercopy);
95969+#endif
95970+
95971 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95972 {
95973 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95974@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
95975 #ifdef CONFIG_ZONE_DMA
95976 &cache_dma_attr.attr,
95977 #endif
95978+#ifdef CONFIG_PAX_USERCOPY_SLABS
95979+ &usercopy_attr.attr,
95980+#endif
95981 #ifdef CONFIG_NUMA
95982 &remote_node_defrag_ratio_attr.attr,
95983 #endif
95984@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
95985 return name;
95986 }
95987
95988+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95989 static int sysfs_slab_add(struct kmem_cache *s)
95990 {
95991 int err;
95992@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95993 kobject_del(&s->kobj);
95994 kobject_put(&s->kobj);
95995 }
95996+#endif
95997
95998 /*
95999 * Need to buffer aliases during bootup until sysfs becomes
96000@@ -5243,6 +5321,7 @@ struct saved_alias {
96001
96002 static struct saved_alias *alias_list;
96003
96004+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96005 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96006 {
96007 struct saved_alias *al;
96008@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96009 alias_list = al;
96010 return 0;
96011 }
96012+#endif
96013
96014 static int __init slab_sysfs_init(void)
96015 {
96016diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96017index 4cba9c2..b4f9fcc 100644
96018--- a/mm/sparse-vmemmap.c
96019+++ b/mm/sparse-vmemmap.c
96020@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96021 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96022 if (!p)
96023 return NULL;
96024- pud_populate(&init_mm, pud, p);
96025+ pud_populate_kernel(&init_mm, pud, p);
96026 }
96027 return pud;
96028 }
96029@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96030 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96031 if (!p)
96032 return NULL;
96033- pgd_populate(&init_mm, pgd, p);
96034+ pgd_populate_kernel(&init_mm, pgd, p);
96035 }
96036 return pgd;
96037 }
96038diff --git a/mm/sparse.c b/mm/sparse.c
96039index 63c3ea5..95c0858 100644
96040--- a/mm/sparse.c
96041+++ b/mm/sparse.c
96042@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96043
96044 for (i = 0; i < PAGES_PER_SECTION; i++) {
96045 if (PageHWPoison(&memmap[i])) {
96046- atomic_long_sub(1, &num_poisoned_pages);
96047+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96048 ClearPageHWPoison(&memmap[i]);
96049 }
96050 }
96051diff --git a/mm/swap.c b/mm/swap.c
96052index 0092097..33361ff 100644
96053--- a/mm/swap.c
96054+++ b/mm/swap.c
96055@@ -31,6 +31,7 @@
96056 #include <linux/memcontrol.h>
96057 #include <linux/gfp.h>
96058 #include <linux/uio.h>
96059+#include <linux/hugetlb.h>
96060
96061 #include "internal.h"
96062
96063@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96064
96065 __page_cache_release(page);
96066 dtor = get_compound_page_dtor(page);
96067+ if (!PageHuge(page))
96068+ BUG_ON(dtor != free_compound_page);
96069 (*dtor)(page);
96070 }
96071
96072diff --git a/mm/swapfile.c b/mm/swapfile.c
96073index 4a7f7e6..22cddf5 100644
96074--- a/mm/swapfile.c
96075+++ b/mm/swapfile.c
96076@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96077
96078 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96079 /* Activity counter to indicate that a swapon or swapoff has occurred */
96080-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96081+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96082
96083 static inline unsigned char swap_count(unsigned char ent)
96084 {
96085@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96086 spin_unlock(&swap_lock);
96087
96088 err = 0;
96089- atomic_inc(&proc_poll_event);
96090+ atomic_inc_unchecked(&proc_poll_event);
96091 wake_up_interruptible(&proc_poll_wait);
96092
96093 out_dput:
96094@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96095
96096 poll_wait(file, &proc_poll_wait, wait);
96097
96098- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96099- seq->poll_event = atomic_read(&proc_poll_event);
96100+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96101+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96102 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96103 }
96104
96105@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96106 return ret;
96107
96108 seq = file->private_data;
96109- seq->poll_event = atomic_read(&proc_poll_event);
96110+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96111 return 0;
96112 }
96113
96114@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96115 (frontswap_map) ? "FS" : "");
96116
96117 mutex_unlock(&swapon_mutex);
96118- atomic_inc(&proc_poll_event);
96119+ atomic_inc_unchecked(&proc_poll_event);
96120 wake_up_interruptible(&proc_poll_wait);
96121
96122 if (S_ISREG(inode->i_mode))
96123diff --git a/mm/util.c b/mm/util.c
96124index a24aa22..a0d41ae 100644
96125--- a/mm/util.c
96126+++ b/mm/util.c
96127@@ -297,6 +297,12 @@ done:
96128 void arch_pick_mmap_layout(struct mm_struct *mm)
96129 {
96130 mm->mmap_base = TASK_UNMAPPED_BASE;
96131+
96132+#ifdef CONFIG_PAX_RANDMMAP
96133+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96134+ mm->mmap_base += mm->delta_mmap;
96135+#endif
96136+
96137 mm->get_unmapped_area = arch_get_unmapped_area;
96138 }
96139 #endif
96140diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96141index 0fdf968..d6686e8 100644
96142--- a/mm/vmalloc.c
96143+++ b/mm/vmalloc.c
96144@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96145
96146 pte = pte_offset_kernel(pmd, addr);
96147 do {
96148- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96149- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96150+
96151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96152+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96153+ BUG_ON(!pte_exec(*pte));
96154+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96155+ continue;
96156+ }
96157+#endif
96158+
96159+ {
96160+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96161+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96162+ }
96163 } while (pte++, addr += PAGE_SIZE, addr != end);
96164 }
96165
96166@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96167 pte = pte_alloc_kernel(pmd, addr);
96168 if (!pte)
96169 return -ENOMEM;
96170+
96171+ pax_open_kernel();
96172 do {
96173 struct page *page = pages[*nr];
96174
96175- if (WARN_ON(!pte_none(*pte)))
96176+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96177+ if (pgprot_val(prot) & _PAGE_NX)
96178+#endif
96179+
96180+ if (!pte_none(*pte)) {
96181+ pax_close_kernel();
96182+ WARN_ON(1);
96183 return -EBUSY;
96184- if (WARN_ON(!page))
96185+ }
96186+ if (!page) {
96187+ pax_close_kernel();
96188+ WARN_ON(1);
96189 return -ENOMEM;
96190+ }
96191 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96192 (*nr)++;
96193 } while (pte++, addr += PAGE_SIZE, addr != end);
96194+ pax_close_kernel();
96195 return 0;
96196 }
96197
96198@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96199 pmd_t *pmd;
96200 unsigned long next;
96201
96202- pmd = pmd_alloc(&init_mm, pud, addr);
96203+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96204 if (!pmd)
96205 return -ENOMEM;
96206 do {
96207@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96208 pud_t *pud;
96209 unsigned long next;
96210
96211- pud = pud_alloc(&init_mm, pgd, addr);
96212+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96213 if (!pud)
96214 return -ENOMEM;
96215 do {
96216@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96217 if (addr >= MODULES_VADDR && addr < MODULES_END)
96218 return 1;
96219 #endif
96220+
96221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96222+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96223+ return 1;
96224+#endif
96225+
96226 return is_vmalloc_addr(x);
96227 }
96228
96229@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96230
96231 if (!pgd_none(*pgd)) {
96232 pud_t *pud = pud_offset(pgd, addr);
96233+#ifdef CONFIG_X86
96234+ if (!pud_large(*pud))
96235+#endif
96236 if (!pud_none(*pud)) {
96237 pmd_t *pmd = pmd_offset(pud, addr);
96238+#ifdef CONFIG_X86
96239+ if (!pmd_large(*pmd))
96240+#endif
96241 if (!pmd_none(*pmd)) {
96242 pte_t *ptep, pte;
96243
96244@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96245 struct vm_struct *area;
96246
96247 BUG_ON(in_interrupt());
96248+
96249+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96250+ if (flags & VM_KERNEXEC) {
96251+ if (start != VMALLOC_START || end != VMALLOC_END)
96252+ return NULL;
96253+ start = (unsigned long)MODULES_EXEC_VADDR;
96254+ end = (unsigned long)MODULES_EXEC_END;
96255+ }
96256+#endif
96257+
96258 if (flags & VM_IOREMAP)
96259 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96260
96261@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96262 if (count > totalram_pages)
96263 return NULL;
96264
96265+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96266+ if (!(pgprot_val(prot) & _PAGE_NX))
96267+ flags |= VM_KERNEXEC;
96268+#endif
96269+
96270 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96271 __builtin_return_address(0));
96272 if (!area)
96273@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96274 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96275 goto fail;
96276
96277+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96278+ if (!(pgprot_val(prot) & _PAGE_NX))
96279+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96280+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96281+ else
96282+#endif
96283+
96284 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96285 start, end, node, gfp_mask, caller);
96286 if (!area)
96287@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96288 * For tight control over page level allocator and protection flags
96289 * use __vmalloc() instead.
96290 */
96291-
96292 void *vmalloc_exec(unsigned long size)
96293 {
96294- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96295+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96296 NUMA_NO_NODE, __builtin_return_address(0));
96297 }
96298
96299@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96300 {
96301 struct vm_struct *area;
96302
96303+ BUG_ON(vma->vm_mirror);
96304+
96305 size = PAGE_ALIGN(size);
96306
96307 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96308@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96309 v->addr, v->addr + v->size, v->size);
96310
96311 if (v->caller)
96312+#ifdef CONFIG_GRKERNSEC_HIDESYM
96313+ seq_printf(m, " %pK", v->caller);
96314+#else
96315 seq_printf(m, " %pS", v->caller);
96316+#endif
96317
96318 if (v->nr_pages)
96319 seq_printf(m, " pages=%d", v->nr_pages);
96320diff --git a/mm/vmstat.c b/mm/vmstat.c
96321index def5dd2..4ce55cec 100644
96322--- a/mm/vmstat.c
96323+++ b/mm/vmstat.c
96324@@ -20,6 +20,7 @@
96325 #include <linux/writeback.h>
96326 #include <linux/compaction.h>
96327 #include <linux/mm_inline.h>
96328+#include <linux/grsecurity.h>
96329
96330 #include "internal.h"
96331
96332@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96333 *
96334 * vm_stat contains the global counters
96335 */
96336-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96337+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96338 EXPORT_SYMBOL(vm_stat);
96339
96340 #ifdef CONFIG_SMP
96341@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96342
96343 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96344 if (diff[i])
96345- atomic_long_add(diff[i], &vm_stat[i]);
96346+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96347 }
96348
96349 /*
96350@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96351 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96352 if (v) {
96353
96354- atomic_long_add(v, &zone->vm_stat[i]);
96355+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96356 global_diff[i] += v;
96357 #ifdef CONFIG_NUMA
96358 /* 3 seconds idle till flush */
96359@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96360
96361 v = p->vm_stat_diff[i];
96362 p->vm_stat_diff[i] = 0;
96363- atomic_long_add(v, &zone->vm_stat[i]);
96364+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96365 global_diff[i] += v;
96366 }
96367 }
96368@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96369 if (pset->vm_stat_diff[i]) {
96370 int v = pset->vm_stat_diff[i];
96371 pset->vm_stat_diff[i] = 0;
96372- atomic_long_add(v, &zone->vm_stat[i]);
96373- atomic_long_add(v, &vm_stat[i]);
96374+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96375+ atomic_long_add_unchecked(v, &vm_stat[i]);
96376 }
96377 }
96378 #endif
96379@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96380 stat_items_size += sizeof(struct vm_event_state);
96381 #endif
96382
96383- v = kmalloc(stat_items_size, GFP_KERNEL);
96384+ v = kzalloc(stat_items_size, GFP_KERNEL);
96385 m->private = v;
96386 if (!v)
96387 return ERR_PTR(-ENOMEM);
96388+
96389+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96390+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96391+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96392+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96393+ && !in_group_p(grsec_proc_gid)
96394+#endif
96395+ )
96396+ return (unsigned long *)m->private + *pos;
96397+#endif
96398+#endif
96399+
96400 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96401 v[i] = global_page_state(i);
96402 v += NR_VM_ZONE_STAT_ITEMS;
96403@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96404 put_online_cpus();
96405 #endif
96406 #ifdef CONFIG_PROC_FS
96407- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96408- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96409- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96410- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96411+ {
96412+ mode_t gr_mode = S_IRUGO;
96413+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96414+ gr_mode = S_IRUSR;
96415+#endif
96416+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96417+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96418+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96419+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96420+ }
96421 #endif
96422 return 0;
96423 }
96424diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96425index 175273f..1c63e05 100644
96426--- a/net/8021q/vlan.c
96427+++ b/net/8021q/vlan.c
96428@@ -474,7 +474,7 @@ out:
96429 return NOTIFY_DONE;
96430 }
96431
96432-static struct notifier_block vlan_notifier_block __read_mostly = {
96433+static struct notifier_block vlan_notifier_block = {
96434 .notifier_call = vlan_device_event,
96435 };
96436
96437@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96438 err = -EPERM;
96439 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96440 break;
96441- if ((args.u.name_type >= 0) &&
96442- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96443+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96444 struct vlan_net *vn;
96445
96446 vn = net_generic(net, vlan_net_id);
96447diff --git a/net/9p/client.c b/net/9p/client.c
96448index 9186550..e604a2f 100644
96449--- a/net/9p/client.c
96450+++ b/net/9p/client.c
96451@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96452 len - inline_len);
96453 } else {
96454 err = copy_from_user(ename + inline_len,
96455- uidata, len - inline_len);
96456+ (char __force_user *)uidata, len - inline_len);
96457 if (err) {
96458 err = -EFAULT;
96459 goto out_err;
96460@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96461 kernel_buf = 1;
96462 indata = data;
96463 } else
96464- indata = (__force char *)udata;
96465+ indata = (__force_kernel char *)udata;
96466 /*
96467 * response header len is 11
96468 * PDU Header(7) + IO Size (4)
96469@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96470 kernel_buf = 1;
96471 odata = data;
96472 } else
96473- odata = (char *)udata;
96474+ odata = (char __force_kernel *)udata;
96475 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96476 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96477 fid->fid, offset, rsize);
96478diff --git a/net/9p/mod.c b/net/9p/mod.c
96479index 6ab36ae..6f1841b 100644
96480--- a/net/9p/mod.c
96481+++ b/net/9p/mod.c
96482@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96483 void v9fs_register_trans(struct p9_trans_module *m)
96484 {
96485 spin_lock(&v9fs_trans_lock);
96486- list_add_tail(&m->list, &v9fs_trans_list);
96487+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96488 spin_unlock(&v9fs_trans_lock);
96489 }
96490 EXPORT_SYMBOL(v9fs_register_trans);
96491@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96492 void v9fs_unregister_trans(struct p9_trans_module *m)
96493 {
96494 spin_lock(&v9fs_trans_lock);
96495- list_del_init(&m->list);
96496+ pax_list_del_init((struct list_head *)&m->list);
96497 spin_unlock(&v9fs_trans_lock);
96498 }
96499 EXPORT_SYMBOL(v9fs_unregister_trans);
96500diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96501index b7bd7f2..2498bf7 100644
96502--- a/net/9p/trans_fd.c
96503+++ b/net/9p/trans_fd.c
96504@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96505 oldfs = get_fs();
96506 set_fs(get_ds());
96507 /* The cast to a user pointer is valid due to the set_fs() */
96508- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96509+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96510 set_fs(oldfs);
96511
96512 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96513diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
96514index af46bc4..f9adfcd 100644
96515--- a/net/appletalk/atalk_proc.c
96516+++ b/net/appletalk/atalk_proc.c
96517@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
96518 struct proc_dir_entry *p;
96519 int rc = -ENOMEM;
96520
96521- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
96522+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
96523 if (!atalk_proc_dir)
96524 goto out;
96525
96526diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96527index 876fbe8..8bbea9f 100644
96528--- a/net/atm/atm_misc.c
96529+++ b/net/atm/atm_misc.c
96530@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96531 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96532 return 1;
96533 atm_return(vcc, truesize);
96534- atomic_inc(&vcc->stats->rx_drop);
96535+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96536 return 0;
96537 }
96538 EXPORT_SYMBOL(atm_charge);
96539@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96540 }
96541 }
96542 atm_return(vcc, guess);
96543- atomic_inc(&vcc->stats->rx_drop);
96544+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96545 return NULL;
96546 }
96547 EXPORT_SYMBOL(atm_alloc_charge);
96548@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96549
96550 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96551 {
96552-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96553+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96554 __SONET_ITEMS
96555 #undef __HANDLE_ITEM
96556 }
96557@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96558
96559 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96560 {
96561-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96562+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96563 __SONET_ITEMS
96564 #undef __HANDLE_ITEM
96565 }
96566diff --git a/net/atm/lec.c b/net/atm/lec.c
96567index 5a2f602..9396143 100644
96568--- a/net/atm/lec.c
96569+++ b/net/atm/lec.c
96570@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96571 }
96572
96573 static struct lane2_ops lane2_ops = {
96574- lane2_resolve, /* resolve, spec 3.1.3 */
96575- lane2_associate_req, /* associate_req, spec 3.1.4 */
96576- NULL /* associate indicator, spec 3.1.5 */
96577+ .resolve = lane2_resolve,
96578+ .associate_req = lane2_associate_req,
96579+ .associate_indicator = NULL
96580 };
96581
96582 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96583diff --git a/net/atm/lec.h b/net/atm/lec.h
96584index 4149db1..f2ab682 100644
96585--- a/net/atm/lec.h
96586+++ b/net/atm/lec.h
96587@@ -48,7 +48,7 @@ struct lane2_ops {
96588 const u8 *tlvs, u32 sizeoftlvs);
96589 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96590 const u8 *tlvs, u32 sizeoftlvs);
96591-};
96592+} __no_const;
96593
96594 /*
96595 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96596diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96597index d1b2d9a..d549f7f 100644
96598--- a/net/atm/mpoa_caches.c
96599+++ b/net/atm/mpoa_caches.c
96600@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96601
96602
96603 static struct in_cache_ops ingress_ops = {
96604- in_cache_add_entry, /* add_entry */
96605- in_cache_get, /* get */
96606- in_cache_get_with_mask, /* get_with_mask */
96607- in_cache_get_by_vcc, /* get_by_vcc */
96608- in_cache_put, /* put */
96609- in_cache_remove_entry, /* remove_entry */
96610- cache_hit, /* cache_hit */
96611- clear_count_and_expired, /* clear_count */
96612- check_resolving_entries, /* check_resolving */
96613- refresh_entries, /* refresh */
96614- in_destroy_cache /* destroy_cache */
96615+ .add_entry = in_cache_add_entry,
96616+ .get = in_cache_get,
96617+ .get_with_mask = in_cache_get_with_mask,
96618+ .get_by_vcc = in_cache_get_by_vcc,
96619+ .put = in_cache_put,
96620+ .remove_entry = in_cache_remove_entry,
96621+ .cache_hit = cache_hit,
96622+ .clear_count = clear_count_and_expired,
96623+ .check_resolving = check_resolving_entries,
96624+ .refresh = refresh_entries,
96625+ .destroy_cache = in_destroy_cache
96626 };
96627
96628 static struct eg_cache_ops egress_ops = {
96629- eg_cache_add_entry, /* add_entry */
96630- eg_cache_get_by_cache_id, /* get_by_cache_id */
96631- eg_cache_get_by_tag, /* get_by_tag */
96632- eg_cache_get_by_vcc, /* get_by_vcc */
96633- eg_cache_get_by_src_ip, /* get_by_src_ip */
96634- eg_cache_put, /* put */
96635- eg_cache_remove_entry, /* remove_entry */
96636- update_eg_cache_entry, /* update */
96637- clear_expired, /* clear_expired */
96638- eg_destroy_cache /* destroy_cache */
96639+ .add_entry = eg_cache_add_entry,
96640+ .get_by_cache_id = eg_cache_get_by_cache_id,
96641+ .get_by_tag = eg_cache_get_by_tag,
96642+ .get_by_vcc = eg_cache_get_by_vcc,
96643+ .get_by_src_ip = eg_cache_get_by_src_ip,
96644+ .put = eg_cache_put,
96645+ .remove_entry = eg_cache_remove_entry,
96646+ .update = update_eg_cache_entry,
96647+ .clear_expired = clear_expired,
96648+ .destroy_cache = eg_destroy_cache
96649 };
96650
96651
96652diff --git a/net/atm/proc.c b/net/atm/proc.c
96653index bbb6461..cf04016 100644
96654--- a/net/atm/proc.c
96655+++ b/net/atm/proc.c
96656@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96657 const struct k_atm_aal_stats *stats)
96658 {
96659 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96660- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96661- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96662- atomic_read(&stats->rx_drop));
96663+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96664+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96665+ atomic_read_unchecked(&stats->rx_drop));
96666 }
96667
96668 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96669diff --git a/net/atm/resources.c b/net/atm/resources.c
96670index 0447d5d..3cf4728 100644
96671--- a/net/atm/resources.c
96672+++ b/net/atm/resources.c
96673@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96674 static void copy_aal_stats(struct k_atm_aal_stats *from,
96675 struct atm_aal_stats *to)
96676 {
96677-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96678+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96679 __AAL_STAT_ITEMS
96680 #undef __HANDLE_ITEM
96681 }
96682@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96683 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96684 struct atm_aal_stats *to)
96685 {
96686-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96687+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96688 __AAL_STAT_ITEMS
96689 #undef __HANDLE_ITEM
96690 }
96691diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96692index 919a5ce..cc6b444 100644
96693--- a/net/ax25/sysctl_net_ax25.c
96694+++ b/net/ax25/sysctl_net_ax25.c
96695@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96696 {
96697 char path[sizeof("net/ax25/") + IFNAMSIZ];
96698 int k;
96699- struct ctl_table *table;
96700+ ctl_table_no_const *table;
96701
96702 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96703 if (!table)
96704diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96705index 8323bce..a03130d 100644
96706--- a/net/batman-adv/bat_iv_ogm.c
96707+++ b/net/batman-adv/bat_iv_ogm.c
96708@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96709
96710 /* randomize initial seqno to avoid collision */
96711 get_random_bytes(&random_seqno, sizeof(random_seqno));
96712- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96713+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96714
96715 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96716 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96717@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96718 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96719
96720 /* change sequence number to network order */
96721- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96722+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96723 batadv_ogm_packet->seqno = htonl(seqno);
96724- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96725+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96726
96727 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96728
96729@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96730 return;
96731
96732 /* could be changed by schedule_own_packet() */
96733- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96734+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96735
96736 if (ogm_packet->flags & BATADV_DIRECTLINK)
96737 has_directlink_flag = true;
96738diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96739index 88df9b1..69cf7c0 100644
96740--- a/net/batman-adv/fragmentation.c
96741+++ b/net/batman-adv/fragmentation.c
96742@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96743 frag_header.packet_type = BATADV_UNICAST_FRAG;
96744 frag_header.version = BATADV_COMPAT_VERSION;
96745 frag_header.ttl = BATADV_TTL;
96746- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96747+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96748 frag_header.reserved = 0;
96749 frag_header.no = 0;
96750 frag_header.total_size = htons(skb->len);
96751diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96752index f82c267..0e56d32 100644
96753--- a/net/batman-adv/soft-interface.c
96754+++ b/net/batman-adv/soft-interface.c
96755@@ -283,7 +283,7 @@ send:
96756 primary_if->net_dev->dev_addr, ETH_ALEN);
96757
96758 /* set broadcast sequence number */
96759- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96760+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96761 bcast_packet->seqno = htonl(seqno);
96762
96763 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96764@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96765 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96766
96767 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96768- atomic_set(&bat_priv->bcast_seqno, 1);
96769+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96770 atomic_set(&bat_priv->tt.vn, 0);
96771 atomic_set(&bat_priv->tt.local_changes, 0);
96772 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96773@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96774
96775 /* randomize initial seqno to avoid collision */
96776 get_random_bytes(&random_seqno, sizeof(random_seqno));
96777- atomic_set(&bat_priv->frag_seqno, random_seqno);
96778+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96779
96780 bat_priv->primary_if = NULL;
96781 bat_priv->num_ifaces = 0;
96782diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96783index 78370ab..1cb3614 100644
96784--- a/net/batman-adv/types.h
96785+++ b/net/batman-adv/types.h
96786@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
96787 struct batadv_hard_iface_bat_iv {
96788 unsigned char *ogm_buff;
96789 int ogm_buff_len;
96790- atomic_t ogm_seqno;
96791+ atomic_unchecked_t ogm_seqno;
96792 };
96793
96794 /**
96795@@ -714,7 +714,7 @@ struct batadv_priv {
96796 atomic_t bonding;
96797 atomic_t fragmentation;
96798 atomic_t packet_size_max;
96799- atomic_t frag_seqno;
96800+ atomic_unchecked_t frag_seqno;
96801 #ifdef CONFIG_BATMAN_ADV_BLA
96802 atomic_t bridge_loop_avoidance;
96803 #endif
96804@@ -730,7 +730,7 @@ struct batadv_priv {
96805 #endif
96806 uint32_t isolation_mark;
96807 uint32_t isolation_mark_mask;
96808- atomic_t bcast_seqno;
96809+ atomic_unchecked_t bcast_seqno;
96810 atomic_t bcast_queue_left;
96811 atomic_t batman_queue_left;
96812 char num_ifaces;
96813diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96814index 7552f9e..074ce29 100644
96815--- a/net/bluetooth/hci_sock.c
96816+++ b/net/bluetooth/hci_sock.c
96817@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96818 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96819 }
96820
96821- len = min_t(unsigned int, len, sizeof(uf));
96822+ len = min((size_t)len, sizeof(uf));
96823 if (copy_from_user(&uf, optval, len)) {
96824 err = -EFAULT;
96825 break;
96826diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96827index b0ad2c7..96f6a5e 100644
96828--- a/net/bluetooth/l2cap_core.c
96829+++ b/net/bluetooth/l2cap_core.c
96830@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96831 break;
96832
96833 case L2CAP_CONF_RFC:
96834- if (olen == sizeof(rfc))
96835- memcpy(&rfc, (void *)val, olen);
96836+ if (olen != sizeof(rfc))
96837+ break;
96838+
96839+ memcpy(&rfc, (void *)val, olen);
96840
96841 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96842 rfc.mode != chan->mode)
96843diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96844index d58f76b..b69600a 100644
96845--- a/net/bluetooth/l2cap_sock.c
96846+++ b/net/bluetooth/l2cap_sock.c
96847@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96848 struct sock *sk = sock->sk;
96849 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96850 struct l2cap_options opts;
96851- int len, err = 0;
96852+ int err = 0;
96853+ size_t len = optlen;
96854 u32 opt;
96855
96856 BT_DBG("sk %p", sk);
96857@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96858 opts.max_tx = chan->max_tx;
96859 opts.txwin_size = chan->tx_win;
96860
96861- len = min_t(unsigned int, sizeof(opts), optlen);
96862+ len = min(sizeof(opts), len);
96863 if (copy_from_user((char *) &opts, optval, len)) {
96864 err = -EFAULT;
96865 break;
96866@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96867 struct bt_security sec;
96868 struct bt_power pwr;
96869 struct l2cap_conn *conn;
96870- int len, err = 0;
96871+ int err = 0;
96872+ size_t len = optlen;
96873 u32 opt;
96874
96875 BT_DBG("sk %p", sk);
96876@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96877
96878 sec.level = BT_SECURITY_LOW;
96879
96880- len = min_t(unsigned int, sizeof(sec), optlen);
96881+ len = min(sizeof(sec), len);
96882 if (copy_from_user((char *) &sec, optval, len)) {
96883 err = -EFAULT;
96884 break;
96885@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96886
96887 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96888
96889- len = min_t(unsigned int, sizeof(pwr), optlen);
96890+ len = min(sizeof(pwr), len);
96891 if (copy_from_user((char *) &pwr, optval, len)) {
96892 err = -EFAULT;
96893 break;
96894diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96895index 3c2d3e4..884855a 100644
96896--- a/net/bluetooth/rfcomm/sock.c
96897+++ b/net/bluetooth/rfcomm/sock.c
96898@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96899 struct sock *sk = sock->sk;
96900 struct bt_security sec;
96901 int err = 0;
96902- size_t len;
96903+ size_t len = optlen;
96904 u32 opt;
96905
96906 BT_DBG("sk %p", sk);
96907@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96908
96909 sec.level = BT_SECURITY_LOW;
96910
96911- len = min_t(unsigned int, sizeof(sec), optlen);
96912+ len = min(sizeof(sec), len);
96913 if (copy_from_user((char *) &sec, optval, len)) {
96914 err = -EFAULT;
96915 break;
96916diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96917index f9c0980a..fcbbfeb 100644
96918--- a/net/bluetooth/rfcomm/tty.c
96919+++ b/net/bluetooth/rfcomm/tty.c
96920@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96921 BT_DBG("tty %p id %d", tty, tty->index);
96922
96923 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96924- dev->channel, dev->port.count);
96925+ dev->channel, atomic_read(&dev->port.count));
96926
96927 err = tty_port_open(&dev->port, tty, filp);
96928 if (err)
96929@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96930 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96931
96932 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96933- dev->port.count);
96934+ atomic_read(&dev->port.count));
96935
96936 tty_port_close(&dev->port, tty, filp);
96937 }
96938diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96939index 0e474b1..fb7109c 100644
96940--- a/net/bridge/netfilter/ebtables.c
96941+++ b/net/bridge/netfilter/ebtables.c
96942@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96943 tmp.valid_hooks = t->table->valid_hooks;
96944 }
96945 mutex_unlock(&ebt_mutex);
96946- if (copy_to_user(user, &tmp, *len) != 0) {
96947+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96948 BUGPRINT("c2u Didn't work\n");
96949 ret = -EFAULT;
96950 break;
96951@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96952 goto out;
96953 tmp.valid_hooks = t->valid_hooks;
96954
96955- if (copy_to_user(user, &tmp, *len) != 0) {
96956+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96957 ret = -EFAULT;
96958 break;
96959 }
96960@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96961 tmp.entries_size = t->table->entries_size;
96962 tmp.valid_hooks = t->table->valid_hooks;
96963
96964- if (copy_to_user(user, &tmp, *len) != 0) {
96965+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96966 ret = -EFAULT;
96967 break;
96968 }
96969diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96970index 0f45522..dab651f 100644
96971--- a/net/caif/cfctrl.c
96972+++ b/net/caif/cfctrl.c
96973@@ -10,6 +10,7 @@
96974 #include <linux/spinlock.h>
96975 #include <linux/slab.h>
96976 #include <linux/pkt_sched.h>
96977+#include <linux/sched.h>
96978 #include <net/caif/caif_layer.h>
96979 #include <net/caif/cfpkt.h>
96980 #include <net/caif/cfctrl.h>
96981@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96982 memset(&dev_info, 0, sizeof(dev_info));
96983 dev_info.id = 0xff;
96984 cfsrvl_init(&this->serv, 0, &dev_info, false);
96985- atomic_set(&this->req_seq_no, 1);
96986- atomic_set(&this->rsp_seq_no, 1);
96987+ atomic_set_unchecked(&this->req_seq_no, 1);
96988+ atomic_set_unchecked(&this->rsp_seq_no, 1);
96989 this->serv.layer.receive = cfctrl_recv;
96990 sprintf(this->serv.layer.name, "ctrl");
96991 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96992@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96993 struct cfctrl_request_info *req)
96994 {
96995 spin_lock_bh(&ctrl->info_list_lock);
96996- atomic_inc(&ctrl->req_seq_no);
96997- req->sequence_no = atomic_read(&ctrl->req_seq_no);
96998+ atomic_inc_unchecked(&ctrl->req_seq_no);
96999+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97000 list_add_tail(&req->list, &ctrl->list);
97001 spin_unlock_bh(&ctrl->info_list_lock);
97002 }
97003@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97004 if (p != first)
97005 pr_warn("Requests are not received in order\n");
97006
97007- atomic_set(&ctrl->rsp_seq_no,
97008+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97009 p->sequence_no);
97010 list_del(&p->list);
97011 goto out;
97012diff --git a/net/can/af_can.c b/net/can/af_can.c
97013index a27f8aa..67174a3 100644
97014--- a/net/can/af_can.c
97015+++ b/net/can/af_can.c
97016@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97017 };
97018
97019 /* notifier block for netdevice event */
97020-static struct notifier_block can_netdev_notifier __read_mostly = {
97021+static struct notifier_block can_netdev_notifier = {
97022 .notifier_call = can_notifier,
97023 };
97024
97025diff --git a/net/can/bcm.c b/net/can/bcm.c
97026index dcb75c0..24b1b43 100644
97027--- a/net/can/bcm.c
97028+++ b/net/can/bcm.c
97029@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97030 }
97031
97032 /* create /proc/net/can-bcm directory */
97033- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97034+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97035 return 0;
97036 }
97037
97038diff --git a/net/can/gw.c b/net/can/gw.c
97039index ac31891..4799c17 100644
97040--- a/net/can/gw.c
97041+++ b/net/can/gw.c
97042@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97043 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97044
97045 static HLIST_HEAD(cgw_list);
97046-static struct notifier_block notifier;
97047
97048 static struct kmem_cache *cgw_cache __read_mostly;
97049
97050@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97051 return err;
97052 }
97053
97054+static struct notifier_block notifier = {
97055+ .notifier_call = cgw_notifier
97056+};
97057+
97058 static __init int cgw_module_init(void)
97059 {
97060 /* sanitize given module parameter */
97061@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97062 return -ENOMEM;
97063
97064 /* set notifier */
97065- notifier.notifier_call = cgw_notifier;
97066 register_netdevice_notifier(&notifier);
97067
97068 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97069diff --git a/net/can/proc.c b/net/can/proc.c
97070index b543470..d2ddae2 100644
97071--- a/net/can/proc.c
97072+++ b/net/can/proc.c
97073@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97074 void can_init_proc(void)
97075 {
97076 /* create /proc/net/can directory */
97077- can_dir = proc_mkdir("can", init_net.proc_net);
97078+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97079
97080 if (!can_dir) {
97081 printk(KERN_INFO "can: failed to create /proc/net/can . "
97082diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97083index 30efc5c..cfa1bbc 100644
97084--- a/net/ceph/messenger.c
97085+++ b/net/ceph/messenger.c
97086@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97087 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97088
97089 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97090-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97091+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97092
97093 static struct page *zero_page; /* used in certain error cases */
97094
97095@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97096 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97097 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97098
97099- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97100+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97101 s = addr_str[i];
97102
97103 switch (ss->ss_family) {
97104diff --git a/net/compat.c b/net/compat.c
97105index f50161f..94fa415 100644
97106--- a/net/compat.c
97107+++ b/net/compat.c
97108@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97109 return -EFAULT;
97110 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97111 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97112- kmsg->msg_name = compat_ptr(tmp1);
97113- kmsg->msg_iov = compat_ptr(tmp2);
97114- kmsg->msg_control = compat_ptr(tmp3);
97115+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97116+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97117+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97118 return 0;
97119 }
97120
97121@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97122
97123 if (kern_msg->msg_namelen) {
97124 if (mode == VERIFY_READ) {
97125- int err = move_addr_to_kernel(kern_msg->msg_name,
97126+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97127 kern_msg->msg_namelen,
97128 kern_address);
97129 if (err < 0)
97130@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97131 kern_msg->msg_name = NULL;
97132
97133 tot_len = iov_from_user_compat_to_kern(kern_iov,
97134- (struct compat_iovec __user *)kern_msg->msg_iov,
97135+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97136 kern_msg->msg_iovlen);
97137 if (tot_len >= 0)
97138 kern_msg->msg_iov = kern_iov;
97139@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97140
97141 #define CMSG_COMPAT_FIRSTHDR(msg) \
97142 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97143- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97144+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97145 (struct compat_cmsghdr __user *)NULL)
97146
97147 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97148 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97149 (ucmlen) <= (unsigned long) \
97150 ((mhdr)->msg_controllen - \
97151- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97152+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97153
97154 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97155 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97156 {
97157 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97158- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97159+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97160 msg->msg_controllen)
97161 return NULL;
97162 return (struct compat_cmsghdr __user *)ptr;
97163@@ -222,7 +222,7 @@ Efault:
97164
97165 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97166 {
97167- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97168+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97169 struct compat_cmsghdr cmhdr;
97170 struct compat_timeval ctv;
97171 struct compat_timespec cts[3];
97172@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97173
97174 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97175 {
97176- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97177+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97178 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97179 int fdnum = scm->fp->count;
97180 struct file **fp = scm->fp->fp;
97181@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97182 return -EFAULT;
97183 old_fs = get_fs();
97184 set_fs(KERNEL_DS);
97185- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97186+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97187 set_fs(old_fs);
97188
97189 return err;
97190@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97191 len = sizeof(ktime);
97192 old_fs = get_fs();
97193 set_fs(KERNEL_DS);
97194- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97195+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97196 set_fs(old_fs);
97197
97198 if (!err) {
97199@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97200 case MCAST_JOIN_GROUP:
97201 case MCAST_LEAVE_GROUP:
97202 {
97203- struct compat_group_req __user *gr32 = (void *)optval;
97204+ struct compat_group_req __user *gr32 = (void __user *)optval;
97205 struct group_req __user *kgr =
97206 compat_alloc_user_space(sizeof(struct group_req));
97207 u32 interface;
97208@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97209 case MCAST_BLOCK_SOURCE:
97210 case MCAST_UNBLOCK_SOURCE:
97211 {
97212- struct compat_group_source_req __user *gsr32 = (void *)optval;
97213+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97214 struct group_source_req __user *kgsr = compat_alloc_user_space(
97215 sizeof(struct group_source_req));
97216 u32 interface;
97217@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97218 }
97219 case MCAST_MSFILTER:
97220 {
97221- struct compat_group_filter __user *gf32 = (void *)optval;
97222+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97223 struct group_filter __user *kgf;
97224 u32 interface, fmode, numsrc;
97225
97226@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97227 char __user *optval, int __user *optlen,
97228 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97229 {
97230- struct compat_group_filter __user *gf32 = (void *)optval;
97231+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97232 struct group_filter __user *kgf;
97233 int __user *koptlen;
97234 u32 interface, fmode, numsrc;
97235@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97236
97237 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97238 return -EINVAL;
97239- if (copy_from_user(a, args, nas[call]))
97240+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97241 return -EFAULT;
97242 a0 = a[0];
97243 a1 = a[1];
97244diff --git a/net/core/datagram.c b/net/core/datagram.c
97245index a16ed7b..eb44d17 100644
97246--- a/net/core/datagram.c
97247+++ b/net/core/datagram.c
97248@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97249 }
97250
97251 kfree_skb(skb);
97252- atomic_inc(&sk->sk_drops);
97253+ atomic_inc_unchecked(&sk->sk_drops);
97254 sk_mem_reclaim_partial(sk);
97255
97256 return err;
97257diff --git a/net/core/dev.c b/net/core/dev.c
97258index 45fa2f1..f3e28ec 100644
97259--- a/net/core/dev.c
97260+++ b/net/core/dev.c
97261@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97262 {
97263 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97264 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97265- atomic_long_inc(&dev->rx_dropped);
97266+ atomic_long_inc_unchecked(&dev->rx_dropped);
97267 kfree_skb(skb);
97268 return NET_RX_DROP;
97269 }
97270 }
97271
97272 if (unlikely(!is_skb_forwardable(dev, skb))) {
97273- atomic_long_inc(&dev->rx_dropped);
97274+ atomic_long_inc_unchecked(&dev->rx_dropped);
97275 kfree_skb(skb);
97276 return NET_RX_DROP;
97277 }
97278@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97279
97280 struct dev_gso_cb {
97281 void (*destructor)(struct sk_buff *skb);
97282-};
97283+} __no_const;
97284
97285 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97286
97287@@ -3227,7 +3227,7 @@ enqueue:
97288
97289 local_irq_restore(flags);
97290
97291- atomic_long_inc(&skb->dev->rx_dropped);
97292+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97293 kfree_skb(skb);
97294 return NET_RX_DROP;
97295 }
97296@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97297 }
97298 EXPORT_SYMBOL(netif_rx_ni);
97299
97300-static void net_tx_action(struct softirq_action *h)
97301+static __latent_entropy void net_tx_action(void)
97302 {
97303 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97304
97305@@ -3645,7 +3645,7 @@ ncls:
97306 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97307 } else {
97308 drop:
97309- atomic_long_inc(&skb->dev->rx_dropped);
97310+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97311 kfree_skb(skb);
97312 /* Jamal, now you will not able to escape explaining
97313 * me how you were going to use this. :-)
97314@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97315 }
97316 EXPORT_SYMBOL(netif_napi_del);
97317
97318-static void net_rx_action(struct softirq_action *h)
97319+static __latent_entropy void net_rx_action(void)
97320 {
97321 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97322 unsigned long time_limit = jiffies + 2;
97323@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97324 } else {
97325 netdev_stats_to_stats64(storage, &dev->stats);
97326 }
97327- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97328+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97329 return storage;
97330 }
97331 EXPORT_SYMBOL(dev_get_stats);
97332diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97333index cf999e0..c59a975 100644
97334--- a/net/core/dev_ioctl.c
97335+++ b/net/core/dev_ioctl.c
97336@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97337 if (no_module && capable(CAP_NET_ADMIN))
97338 no_module = request_module("netdev-%s", name);
97339 if (no_module && capable(CAP_SYS_MODULE)) {
97340+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97341+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97342+#else
97343 if (!request_module("%s", name))
97344 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97345 name);
97346+#endif
97347 }
97348 }
97349 EXPORT_SYMBOL(dev_load);
97350diff --git a/net/core/filter.c b/net/core/filter.c
97351index ad30d62..21c0743 100644
97352--- a/net/core/filter.c
97353+++ b/net/core/filter.c
97354@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97355 void *ptr;
97356 u32 A = 0; /* Accumulator */
97357 u32 X = 0; /* Index Register */
97358- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97359+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97360 u32 tmp;
97361 int k;
97362
97363@@ -292,10 +292,10 @@ load_b:
97364 X = K;
97365 continue;
97366 case BPF_S_LD_MEM:
97367- A = mem[K];
97368+ A = mem[K&15];
97369 continue;
97370 case BPF_S_LDX_MEM:
97371- X = mem[K];
97372+ X = mem[K&15];
97373 continue;
97374 case BPF_S_MISC_TAX:
97375 X = A;
97376@@ -308,10 +308,10 @@ load_b:
97377 case BPF_S_RET_A:
97378 return A;
97379 case BPF_S_ST:
97380- mem[K] = A;
97381+ mem[K&15] = A;
97382 continue;
97383 case BPF_S_STX:
97384- mem[K] = X;
97385+ mem[K&15] = X;
97386 continue;
97387 case BPF_S_ANC_PROTOCOL:
97388 A = ntohs(skb->protocol);
97389@@ -355,6 +355,10 @@ load_b:
97390
97391 if (skb_is_nonlinear(skb))
97392 return 0;
97393+
97394+ if (skb->len < sizeof(struct nlattr))
97395+ return 0;
97396+
97397 if (A > skb->len - sizeof(struct nlattr))
97398 return 0;
97399
97400@@ -371,11 +375,15 @@ load_b:
97401
97402 if (skb_is_nonlinear(skb))
97403 return 0;
97404+
97405+ if (skb->len < sizeof(struct nlattr))
97406+ return 0;
97407+
97408 if (A > skb->len - sizeof(struct nlattr))
97409 return 0;
97410
97411 nla = (struct nlattr *)&skb->data[A];
97412- if (nla->nla_len > A - skb->len)
97413+ if (nla->nla_len > skb->len - A)
97414 return 0;
97415
97416 nla = nla_find_nested(nla, X);
97417@@ -391,9 +399,10 @@ load_b:
97418 continue;
97419 #endif
97420 default:
97421- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97422+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97423 fentry->code, fentry->jt,
97424 fentry->jf, fentry->k);
97425+ BUG();
97426 return 0;
97427 }
97428 }
97429@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97430 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97431 int pc, ret = 0;
97432
97433- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97434+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97435 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97436 if (!masks)
97437 return -ENOMEM;
97438@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97439 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97440 if (!fp)
97441 return -ENOMEM;
97442- memcpy(fp->insns, fprog->filter, fsize);
97443+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97444
97445 atomic_set(&fp->refcnt, 1);
97446 fp->len = fprog->len;
97447diff --git a/net/core/flow.c b/net/core/flow.c
97448index dfa602c..3103d88 100644
97449--- a/net/core/flow.c
97450+++ b/net/core/flow.c
97451@@ -61,7 +61,7 @@ struct flow_cache {
97452 struct timer_list rnd_timer;
97453 };
97454
97455-atomic_t flow_cache_genid = ATOMIC_INIT(0);
97456+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97457 EXPORT_SYMBOL(flow_cache_genid);
97458 static struct flow_cache flow_cache_global;
97459 static struct kmem_cache *flow_cachep __read_mostly;
97460@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97461
97462 static int flow_entry_valid(struct flow_cache_entry *fle)
97463 {
97464- if (atomic_read(&flow_cache_genid) != fle->genid)
97465+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97466 return 0;
97467 if (fle->object && !fle->object->ops->check(fle->object))
97468 return 0;
97469@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97470 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97471 fcp->hash_count++;
97472 }
97473- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97474+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97475 flo = fle->object;
97476 if (!flo)
97477 goto ret_object;
97478@@ -279,7 +279,7 @@ nocache:
97479 }
97480 flo = resolver(net, key, family, dir, flo, ctx);
97481 if (fle) {
97482- fle->genid = atomic_read(&flow_cache_genid);
97483+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97484 if (!IS_ERR(flo))
97485 fle->object = flo;
97486 else
97487diff --git a/net/core/iovec.c b/net/core/iovec.c
97488index b618694..192bbba 100644
97489--- a/net/core/iovec.c
97490+++ b/net/core/iovec.c
97491@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97492 if (m->msg_namelen) {
97493 if (mode == VERIFY_READ) {
97494 void __user *namep;
97495- namep = (void __user __force *) m->msg_name;
97496+ namep = (void __force_user *) m->msg_name;
97497 err = move_addr_to_kernel(namep, m->msg_namelen,
97498 address);
97499 if (err < 0)
97500@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97501 }
97502
97503 size = m->msg_iovlen * sizeof(struct iovec);
97504- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97505+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97506 return -EFAULT;
97507
97508 m->msg_iov = iov;
97509diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97510index e161290..8149aea 100644
97511--- a/net/core/neighbour.c
97512+++ b/net/core/neighbour.c
97513@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97514 void __user *buffer, size_t *lenp, loff_t *ppos)
97515 {
97516 int size, ret;
97517- struct ctl_table tmp = *ctl;
97518+ ctl_table_no_const tmp = *ctl;
97519
97520 tmp.extra1 = &zero;
97521 tmp.extra2 = &unres_qlen_max;
97522@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97523 void __user *buffer,
97524 size_t *lenp, loff_t *ppos)
97525 {
97526- struct ctl_table tmp = *ctl;
97527+ ctl_table_no_const tmp = *ctl;
97528 int ret;
97529
97530 tmp.extra1 = &zero;
97531@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97532 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97533 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97534 } else {
97535+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97536 dev_name_source = "default";
97537- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97538- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97539- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97540- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97541+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97542+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97543+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97544+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97545 }
97546
97547 if (handler) {
97548diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97549index 2bf8329..2eb1423 100644
97550--- a/net/core/net-procfs.c
97551+++ b/net/core/net-procfs.c
97552@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
97553 struct rtnl_link_stats64 temp;
97554 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
97555
97556- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97557+ if (gr_proc_is_restricted())
97558+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97559+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97560+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
97561+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
97562+ else
97563+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97564 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97565 dev->name, stats->rx_bytes, stats->rx_packets,
97566 stats->rx_errors,
97567@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
97568 return 0;
97569 }
97570
97571-static const struct seq_operations dev_seq_ops = {
97572+const struct seq_operations dev_seq_ops = {
97573 .start = dev_seq_start,
97574 .next = dev_seq_next,
97575 .stop = dev_seq_stop,
97576@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
97577
97578 static int softnet_seq_open(struct inode *inode, struct file *file)
97579 {
97580- return seq_open(file, &softnet_seq_ops);
97581+ return seq_open_restrict(file, &softnet_seq_ops);
97582 }
97583
97584 static const struct file_operations softnet_seq_fops = {
97585@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97586 else
97587 seq_printf(seq, "%04x", ntohs(pt->type));
97588
97589+#ifdef CONFIG_GRKERNSEC_HIDESYM
97590+ seq_printf(seq, " %-8s %pf\n",
97591+ pt->dev ? pt->dev->name : "", NULL);
97592+#else
97593 seq_printf(seq, " %-8s %pf\n",
97594 pt->dev ? pt->dev->name : "", pt->func);
97595+#endif
97596 }
97597
97598 return 0;
97599diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97600index 81d3a9a..a0bd7a8 100644
97601--- a/net/core/net_namespace.c
97602+++ b/net/core/net_namespace.c
97603@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97604 int error;
97605 LIST_HEAD(net_exit_list);
97606
97607- list_add_tail(&ops->list, list);
97608+ pax_list_add_tail((struct list_head *)&ops->list, list);
97609 if (ops->init || (ops->id && ops->size)) {
97610 for_each_net(net) {
97611 error = ops_init(ops, net);
97612@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97613
97614 out_undo:
97615 /* If I have an error cleanup all namespaces I initialized */
97616- list_del(&ops->list);
97617+ pax_list_del((struct list_head *)&ops->list);
97618 ops_exit_list(ops, &net_exit_list);
97619 ops_free_list(ops, &net_exit_list);
97620 return error;
97621@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97622 struct net *net;
97623 LIST_HEAD(net_exit_list);
97624
97625- list_del(&ops->list);
97626+ pax_list_del((struct list_head *)&ops->list);
97627 for_each_net(net)
97628 list_add_tail(&net->exit_list, &net_exit_list);
97629 ops_exit_list(ops, &net_exit_list);
97630@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97631 mutex_lock(&net_mutex);
97632 error = register_pernet_operations(&pernet_list, ops);
97633 if (!error && (first_device == &pernet_list))
97634- first_device = &ops->list;
97635+ first_device = (struct list_head *)&ops->list;
97636 mutex_unlock(&net_mutex);
97637 return error;
97638 }
97639diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97640index df9e6b1..6e68e4e 100644
97641--- a/net/core/netpoll.c
97642+++ b/net/core/netpoll.c
97643@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97644 struct udphdr *udph;
97645 struct iphdr *iph;
97646 struct ethhdr *eth;
97647- static atomic_t ip_ident;
97648+ static atomic_unchecked_t ip_ident;
97649 struct ipv6hdr *ip6h;
97650
97651 udp_len = len + sizeof(*udph);
97652@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97653 put_unaligned(0x45, (unsigned char *)iph);
97654 iph->tos = 0;
97655 put_unaligned(htons(ip_len), &(iph->tot_len));
97656- iph->id = htons(atomic_inc_return(&ip_ident));
97657+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97658 iph->frag_off = 0;
97659 iph->ttl = 64;
97660 iph->protocol = IPPROTO_UDP;
97661diff --git a/net/core/pktgen.c b/net/core/pktgen.c
97662index fdac61c..e5e5b46 100644
97663--- a/net/core/pktgen.c
97664+++ b/net/core/pktgen.c
97665@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
97666 pn->net = net;
97667 INIT_LIST_HEAD(&pn->pktgen_threads);
97668 pn->pktgen_exiting = false;
97669- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
97670+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
97671 if (!pn->proc_dir) {
97672 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
97673 return -ENODEV;
97674diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97675index 120eecc..cd1ec44 100644
97676--- a/net/core/rtnetlink.c
97677+++ b/net/core/rtnetlink.c
97678@@ -58,7 +58,7 @@ struct rtnl_link {
97679 rtnl_doit_func doit;
97680 rtnl_dumpit_func dumpit;
97681 rtnl_calcit_func calcit;
97682-};
97683+} __no_const;
97684
97685 static DEFINE_MUTEX(rtnl_mutex);
97686
97687@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97688 if (rtnl_link_ops_get(ops->kind))
97689 return -EEXIST;
97690
97691- if (!ops->dellink)
97692- ops->dellink = unregister_netdevice_queue;
97693+ if (!ops->dellink) {
97694+ pax_open_kernel();
97695+ *(void **)&ops->dellink = unregister_netdevice_queue;
97696+ pax_close_kernel();
97697+ }
97698
97699- list_add_tail(&ops->list, &link_ops);
97700+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97701 return 0;
97702 }
97703 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97704@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97705 for_each_net(net) {
97706 __rtnl_kill_links(net, ops);
97707 }
97708- list_del(&ops->list);
97709+ pax_list_del((struct list_head *)&ops->list);
97710 }
97711 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97712
97713diff --git a/net/core/scm.c b/net/core/scm.c
97714index b442e7e..6f5b5a2 100644
97715--- a/net/core/scm.c
97716+++ b/net/core/scm.c
97717@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97718 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97719 {
97720 struct cmsghdr __user *cm
97721- = (__force struct cmsghdr __user *)msg->msg_control;
97722+ = (struct cmsghdr __force_user *)msg->msg_control;
97723 struct cmsghdr cmhdr;
97724 int cmlen = CMSG_LEN(len);
97725 int err;
97726@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97727 err = -EFAULT;
97728 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97729 goto out;
97730- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97731+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97732 goto out;
97733 cmlen = CMSG_SPACE(len);
97734 if (msg->msg_controllen < cmlen)
97735@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97736 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97737 {
97738 struct cmsghdr __user *cm
97739- = (__force struct cmsghdr __user*)msg->msg_control;
97740+ = (struct cmsghdr __force_user *)msg->msg_control;
97741
97742 int fdmax = 0;
97743 int fdnum = scm->fp->count;
97744@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97745 if (fdnum < fdmax)
97746 fdmax = fdnum;
97747
97748- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97749+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97750 i++, cmfptr++)
97751 {
97752 struct socket *sock;
97753diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97754index 90b96a1..cd18f16d 100644
97755--- a/net/core/skbuff.c
97756+++ b/net/core/skbuff.c
97757@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97758 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97759 int len, __wsum csum)
97760 {
97761- const struct skb_checksum_ops ops = {
97762+ static const struct skb_checksum_ops ops = {
97763 .update = csum_partial_ext,
97764 .combine = csum_block_add_ext,
97765 };
97766@@ -3220,13 +3220,15 @@ void __init skb_init(void)
97767 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97768 sizeof(struct sk_buff),
97769 0,
97770- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97771+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97772+ SLAB_NO_SANITIZE,
97773 NULL);
97774 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97775 (2*sizeof(struct sk_buff)) +
97776 sizeof(atomic_t),
97777 0,
97778- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97779+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97780+ SLAB_NO_SANITIZE,
97781 NULL);
97782 }
97783
97784diff --git a/net/core/sock.c b/net/core/sock.c
97785index c0fc6bd..51d8326 100644
97786--- a/net/core/sock.c
97787+++ b/net/core/sock.c
97788@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97789 struct sk_buff_head *list = &sk->sk_receive_queue;
97790
97791 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97792- atomic_inc(&sk->sk_drops);
97793+ atomic_inc_unchecked(&sk->sk_drops);
97794 trace_sock_rcvqueue_full(sk, skb);
97795 return -ENOMEM;
97796 }
97797@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97798 return err;
97799
97800 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97801- atomic_inc(&sk->sk_drops);
97802+ atomic_inc_unchecked(&sk->sk_drops);
97803 return -ENOBUFS;
97804 }
97805
97806@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97807 skb_dst_force(skb);
97808
97809 spin_lock_irqsave(&list->lock, flags);
97810- skb->dropcount = atomic_read(&sk->sk_drops);
97811+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97812 __skb_queue_tail(list, skb);
97813 spin_unlock_irqrestore(&list->lock, flags);
97814
97815@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97816 skb->dev = NULL;
97817
97818 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97819- atomic_inc(&sk->sk_drops);
97820+ atomic_inc_unchecked(&sk->sk_drops);
97821 goto discard_and_relse;
97822 }
97823 if (nested)
97824@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97825 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97826 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97827 bh_unlock_sock(sk);
97828- atomic_inc(&sk->sk_drops);
97829+ atomic_inc_unchecked(&sk->sk_drops);
97830 goto discard_and_relse;
97831 }
97832
97833@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97834 struct timeval tm;
97835 } v;
97836
97837- int lv = sizeof(int);
97838- int len;
97839+ unsigned int lv = sizeof(int);
97840+ unsigned int len;
97841
97842 if (get_user(len, optlen))
97843 return -EFAULT;
97844- if (len < 0)
97845+ if (len > INT_MAX)
97846 return -EINVAL;
97847
97848 memset(&v, 0, sizeof(v));
97849@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97850
97851 case SO_PEERNAME:
97852 {
97853- char address[128];
97854+ char address[_K_SS_MAXSIZE];
97855
97856 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97857 return -ENOTCONN;
97858- if (lv < len)
97859+ if (lv < len || sizeof address < len)
97860 return -EINVAL;
97861 if (copy_to_user(optval, address, len))
97862 return -EFAULT;
97863@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97864
97865 if (len > lv)
97866 len = lv;
97867- if (copy_to_user(optval, &v, len))
97868+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
97869 return -EFAULT;
97870 lenout:
97871 if (put_user(len, optlen))
97872@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97873 */
97874 smp_wmb();
97875 atomic_set(&sk->sk_refcnt, 1);
97876- atomic_set(&sk->sk_drops, 0);
97877+ atomic_set_unchecked(&sk->sk_drops, 0);
97878 }
97879 EXPORT_SYMBOL(sock_init_data);
97880
97881@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97882 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97883 int level, int type)
97884 {
97885+ struct sock_extended_err ee;
97886 struct sock_exterr_skb *serr;
97887 struct sk_buff *skb, *skb2;
97888 int copied, err;
97889@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97890 sock_recv_timestamp(msg, sk, skb);
97891
97892 serr = SKB_EXT_ERR(skb);
97893- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97894+ ee = serr->ee;
97895+ put_cmsg(msg, level, type, sizeof ee, &ee);
97896
97897 msg->msg_flags |= MSG_ERRQUEUE;
97898 err = copied;
97899diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97900index a0e9cf6..ef7f9ed 100644
97901--- a/net/core/sock_diag.c
97902+++ b/net/core/sock_diag.c
97903@@ -9,26 +9,33 @@
97904 #include <linux/inet_diag.h>
97905 #include <linux/sock_diag.h>
97906
97907-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97908+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97909 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97910 static DEFINE_MUTEX(sock_diag_table_mutex);
97911
97912 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97913 {
97914+#ifndef CONFIG_GRKERNSEC_HIDESYM
97915 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97916 cookie[1] != INET_DIAG_NOCOOKIE) &&
97917 ((u32)(unsigned long)sk != cookie[0] ||
97918 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97919 return -ESTALE;
97920 else
97921+#endif
97922 return 0;
97923 }
97924 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97925
97926 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97927 {
97928+#ifdef CONFIG_GRKERNSEC_HIDESYM
97929+ cookie[0] = 0;
97930+ cookie[1] = 0;
97931+#else
97932 cookie[0] = (u32)(unsigned long)sk;
97933 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97934+#endif
97935 }
97936 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97937
97938@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97939 mutex_lock(&sock_diag_table_mutex);
97940 if (sock_diag_handlers[hndl->family])
97941 err = -EBUSY;
97942- else
97943+ else {
97944+ pax_open_kernel();
97945 sock_diag_handlers[hndl->family] = hndl;
97946+ pax_close_kernel();
97947+ }
97948 mutex_unlock(&sock_diag_table_mutex);
97949
97950 return err;
97951@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97952
97953 mutex_lock(&sock_diag_table_mutex);
97954 BUG_ON(sock_diag_handlers[family] != hnld);
97955+ pax_open_kernel();
97956 sock_diag_handlers[family] = NULL;
97957+ pax_close_kernel();
97958 mutex_unlock(&sock_diag_table_mutex);
97959 }
97960 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97961diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97962index cf9cd13..8b56af3 100644
97963--- a/net/core/sysctl_net_core.c
97964+++ b/net/core/sysctl_net_core.c
97965@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97966 {
97967 unsigned int orig_size, size;
97968 int ret, i;
97969- struct ctl_table tmp = {
97970+ ctl_table_no_const tmp = {
97971 .data = &size,
97972 .maxlen = sizeof(size),
97973 .mode = table->mode
97974@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97975 void __user *buffer, size_t *lenp, loff_t *ppos)
97976 {
97977 char id[IFNAMSIZ];
97978- struct ctl_table tbl = {
97979+ ctl_table_no_const tbl = {
97980 .data = id,
97981 .maxlen = IFNAMSIZ,
97982 };
97983@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
97984
97985 static __net_init int sysctl_core_net_init(struct net *net)
97986 {
97987- struct ctl_table *tbl;
97988+ ctl_table_no_const *tbl = NULL;
97989
97990 net->core.sysctl_somaxconn = SOMAXCONN;
97991
97992- tbl = netns_core_table;
97993 if (!net_eq(net, &init_net)) {
97994- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97995+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97996 if (tbl == NULL)
97997 goto err_dup;
97998
97999@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98000 if (net->user_ns != &init_user_ns) {
98001 tbl[0].procname = NULL;
98002 }
98003- }
98004-
98005- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98006+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98007+ } else
98008+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98009 if (net->core.sysctl_hdr == NULL)
98010 goto err_reg;
98011
98012 return 0;
98013
98014 err_reg:
98015- if (tbl != netns_core_table)
98016- kfree(tbl);
98017+ kfree(tbl);
98018 err_dup:
98019 return -ENOMEM;
98020 }
98021@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98022 kfree(tbl);
98023 }
98024
98025-static __net_initdata struct pernet_operations sysctl_core_ops = {
98026+static __net_initconst struct pernet_operations sysctl_core_ops = {
98027 .init = sysctl_core_net_init,
98028 .exit = sysctl_core_net_exit,
98029 };
98030diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98031index 4c04848..f575934 100644
98032--- a/net/decnet/af_decnet.c
98033+++ b/net/decnet/af_decnet.c
98034@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98035 .sysctl_rmem = sysctl_decnet_rmem,
98036 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98037 .obj_size = sizeof(struct dn_sock),
98038+ .slab_flags = SLAB_USERCOPY,
98039 };
98040
98041 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98042diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98043index a603823..a36ee0b 100644
98044--- a/net/decnet/dn_dev.c
98045+++ b/net/decnet/dn_dev.c
98046@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98047 .extra1 = &min_t3,
98048 .extra2 = &max_t3
98049 },
98050- {0}
98051+ { }
98052 },
98053 };
98054
98055diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98056index 5325b54..a0d4d69 100644
98057--- a/net/decnet/sysctl_net_decnet.c
98058+++ b/net/decnet/sysctl_net_decnet.c
98059@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98060
98061 if (len > *lenp) len = *lenp;
98062
98063- if (copy_to_user(buffer, addr, len))
98064+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98065 return -EFAULT;
98066
98067 *lenp = len;
98068@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98069
98070 if (len > *lenp) len = *lenp;
98071
98072- if (copy_to_user(buffer, devname, len))
98073+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98074 return -EFAULT;
98075
98076 *lenp = len;
98077diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98078index 1846c1f..96d4a9f 100644
98079--- a/net/ieee802154/dgram.c
98080+++ b/net/ieee802154/dgram.c
98081@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98082 if (saddr) {
98083 saddr->family = AF_IEEE802154;
98084 saddr->addr = mac_cb(skb)->sa;
98085+ }
98086+ if (addr_len)
98087 *addr_len = sizeof(*saddr);
98088- }
98089
98090 if (flags & MSG_TRUNC)
98091 copied = skb->len;
98092diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98093index 19ab78a..bf575c9 100644
98094--- a/net/ipv4/af_inet.c
98095+++ b/net/ipv4/af_inet.c
98096@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98097
98098 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98099
98100- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98101- if (!sysctl_local_reserved_ports)
98102- goto out;
98103-
98104 rc = proto_register(&tcp_prot, 1);
98105 if (rc)
98106- goto out_free_reserved_ports;
98107+ goto out;
98108
98109 rc = proto_register(&udp_prot, 1);
98110 if (rc)
98111@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98112 proto_unregister(&udp_prot);
98113 out_unregister_tcp_proto:
98114 proto_unregister(&tcp_prot);
98115-out_free_reserved_ports:
98116- kfree(sysctl_local_reserved_ports);
98117 goto out;
98118 }
98119
98120diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98121index bdbf68b..deb4759 100644
98122--- a/net/ipv4/devinet.c
98123+++ b/net/ipv4/devinet.c
98124@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98125 idx = 0;
98126 head = &net->dev_index_head[h];
98127 rcu_read_lock();
98128- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98129+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98130 net->dev_base_seq;
98131 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98132 if (idx < s_idx)
98133@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98134 idx = 0;
98135 head = &net->dev_index_head[h];
98136 rcu_read_lock();
98137- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98138+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98139 net->dev_base_seq;
98140 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98141 if (idx < s_idx)
98142@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98143 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98144 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98145
98146-static struct devinet_sysctl_table {
98147+static const struct devinet_sysctl_table {
98148 struct ctl_table_header *sysctl_header;
98149 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98150 } devinet_sysctl = {
98151@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98152 int err;
98153 struct ipv4_devconf *all, *dflt;
98154 #ifdef CONFIG_SYSCTL
98155- struct ctl_table *tbl = ctl_forward_entry;
98156+ ctl_table_no_const *tbl = NULL;
98157 struct ctl_table_header *forw_hdr;
98158 #endif
98159
98160@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98161 goto err_alloc_dflt;
98162
98163 #ifdef CONFIG_SYSCTL
98164- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98165+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98166 if (tbl == NULL)
98167 goto err_alloc_ctl;
98168
98169@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98170 goto err_reg_dflt;
98171
98172 err = -ENOMEM;
98173- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98174+ if (!net_eq(net, &init_net))
98175+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98176+ else
98177+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98178 if (forw_hdr == NULL)
98179 goto err_reg_ctl;
98180 net->ipv4.forw_hdr = forw_hdr;
98181@@ -2272,8 +2275,7 @@ err_reg_ctl:
98182 err_reg_dflt:
98183 __devinet_sysctl_unregister(all);
98184 err_reg_all:
98185- if (tbl != ctl_forward_entry)
98186- kfree(tbl);
98187+ kfree(tbl);
98188 err_alloc_ctl:
98189 #endif
98190 if (dflt != &ipv4_devconf_dflt)
98191diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98192index c7539e2..b455e51 100644
98193--- a/net/ipv4/fib_frontend.c
98194+++ b/net/ipv4/fib_frontend.c
98195@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98196 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98197 fib_sync_up(dev);
98198 #endif
98199- atomic_inc(&net->ipv4.dev_addr_genid);
98200+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98201 rt_cache_flush(dev_net(dev));
98202 break;
98203 case NETDEV_DOWN:
98204 fib_del_ifaddr(ifa, NULL);
98205- atomic_inc(&net->ipv4.dev_addr_genid);
98206+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98207 if (ifa->ifa_dev->ifa_list == NULL) {
98208 /* Last address was deleted from this interface.
98209 * Disable IP.
98210@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98211 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98212 fib_sync_up(dev);
98213 #endif
98214- atomic_inc(&net->ipv4.dev_addr_genid);
98215+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98216 rt_cache_flush(net);
98217 break;
98218 case NETDEV_DOWN:
98219diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98220index b53f0bf..3585b33 100644
98221--- a/net/ipv4/fib_semantics.c
98222+++ b/net/ipv4/fib_semantics.c
98223@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98224 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98225 nh->nh_gw,
98226 nh->nh_parent->fib_scope);
98227- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98228+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98229
98230 return nh->nh_saddr;
98231 }
98232diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98233index 0d1e2cb..4501a2c 100644
98234--- a/net/ipv4/inet_connection_sock.c
98235+++ b/net/ipv4/inet_connection_sock.c
98236@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98237 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98238 #endif
98239
98240-unsigned long *sysctl_local_reserved_ports;
98241+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98242 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98243
98244 void inet_get_local_port_range(struct net *net, int *low, int *high)
98245diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98246index 8b9cf27..0d8d592 100644
98247--- a/net/ipv4/inet_hashtables.c
98248+++ b/net/ipv4/inet_hashtables.c
98249@@ -18,6 +18,7 @@
98250 #include <linux/sched.h>
98251 #include <linux/slab.h>
98252 #include <linux/wait.h>
98253+#include <linux/security.h>
98254
98255 #include <net/inet_connection_sock.h>
98256 #include <net/inet_hashtables.h>
98257@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98258 return inet_ehashfn(net, laddr, lport, faddr, fport);
98259 }
98260
98261+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98262+
98263 /*
98264 * Allocate and initialize a new local port bind bucket.
98265 * The bindhash mutex for snum's hash chain must be held here.
98266@@ -554,6 +557,8 @@ ok:
98267 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98268 spin_unlock(&head->lock);
98269
98270+ gr_update_task_in_ip_table(current, inet_sk(sk));
98271+
98272 if (tw) {
98273 inet_twsk_deschedule(tw, death_row);
98274 while (twrefcnt) {
98275diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98276index 48f4244..f56d83a 100644
98277--- a/net/ipv4/inetpeer.c
98278+++ b/net/ipv4/inetpeer.c
98279@@ -496,8 +496,8 @@ relookup:
98280 if (p) {
98281 p->daddr = *daddr;
98282 atomic_set(&p->refcnt, 1);
98283- atomic_set(&p->rid, 0);
98284- atomic_set(&p->ip_id_count,
98285+ atomic_set_unchecked(&p->rid, 0);
98286+ atomic_set_unchecked(&p->ip_id_count,
98287 (daddr->family == AF_INET) ?
98288 secure_ip_id(daddr->addr.a4) :
98289 secure_ipv6_id(daddr->addr.a6));
98290diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98291index c10a3ce..dd71f84 100644
98292--- a/net/ipv4/ip_fragment.c
98293+++ b/net/ipv4/ip_fragment.c
98294@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98295 return 0;
98296
98297 start = qp->rid;
98298- end = atomic_inc_return(&peer->rid);
98299+ end = atomic_inc_return_unchecked(&peer->rid);
98300 qp->rid = end;
98301
98302 rc = qp->q.fragments && (end - start) > max;
98303@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98304
98305 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98306 {
98307- struct ctl_table *table;
98308+ ctl_table_no_const *table = NULL;
98309 struct ctl_table_header *hdr;
98310
98311- table = ip4_frags_ns_ctl_table;
98312 if (!net_eq(net, &init_net)) {
98313- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98314+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98315 if (table == NULL)
98316 goto err_alloc;
98317
98318@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98319 /* Don't export sysctls to unprivileged users */
98320 if (net->user_ns != &init_user_ns)
98321 table[0].procname = NULL;
98322- }
98323+ hdr = register_net_sysctl(net, "net/ipv4", table);
98324+ } else
98325+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98326
98327- hdr = register_net_sysctl(net, "net/ipv4", table);
98328 if (hdr == NULL)
98329 goto err_reg;
98330
98331@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98332 return 0;
98333
98334 err_reg:
98335- if (!net_eq(net, &init_net))
98336- kfree(table);
98337+ kfree(table);
98338 err_alloc:
98339 return -ENOMEM;
98340 }
98341diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98342index ec4f762..4ce3645 100644
98343--- a/net/ipv4/ip_gre.c
98344+++ b/net/ipv4/ip_gre.c
98345@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98346 module_param(log_ecn_error, bool, 0644);
98347 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98348
98349-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98350+static struct rtnl_link_ops ipgre_link_ops;
98351 static int ipgre_tunnel_init(struct net_device *dev);
98352
98353 static int ipgre_net_id __read_mostly;
98354@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98355 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98356 };
98357
98358-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98359+static struct rtnl_link_ops ipgre_link_ops = {
98360 .kind = "gre",
98361 .maxtype = IFLA_GRE_MAX,
98362 .policy = ipgre_policy,
98363@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98364 .fill_info = ipgre_fill_info,
98365 };
98366
98367-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98368+static struct rtnl_link_ops ipgre_tap_ops = {
98369 .kind = "gretap",
98370 .maxtype = IFLA_GRE_MAX,
98371 .policy = ipgre_policy,
98372diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98373index 580dd96..9fcef7e 100644
98374--- a/net/ipv4/ip_sockglue.c
98375+++ b/net/ipv4/ip_sockglue.c
98376@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98377 len = min_t(unsigned int, len, opt->optlen);
98378 if (put_user(len, optlen))
98379 return -EFAULT;
98380- if (copy_to_user(optval, opt->__data, len))
98381+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98382+ copy_to_user(optval, opt->__data, len))
98383 return -EFAULT;
98384 return 0;
98385 }
98386@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98387 if (sk->sk_type != SOCK_STREAM)
98388 return -ENOPROTOOPT;
98389
98390- msg.msg_control = optval;
98391+ msg.msg_control = (void __force_kernel *)optval;
98392 msg.msg_controllen = len;
98393 msg.msg_flags = flags;
98394
98395diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98396index 48eafae..defff53 100644
98397--- a/net/ipv4/ip_vti.c
98398+++ b/net/ipv4/ip_vti.c
98399@@ -44,7 +44,7 @@
98400 #include <net/net_namespace.h>
98401 #include <net/netns/generic.h>
98402
98403-static struct rtnl_link_ops vti_link_ops __read_mostly;
98404+static struct rtnl_link_ops vti_link_ops;
98405
98406 static int vti_net_id __read_mostly;
98407 static int vti_tunnel_init(struct net_device *dev);
98408@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98409 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98410 };
98411
98412-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98413+static struct rtnl_link_ops vti_link_ops = {
98414 .kind = "vti",
98415 .maxtype = IFLA_VTI_MAX,
98416 .policy = vti_policy,
98417diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98418index b3e86ea..18ce98c 100644
98419--- a/net/ipv4/ipconfig.c
98420+++ b/net/ipv4/ipconfig.c
98421@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98422
98423 mm_segment_t oldfs = get_fs();
98424 set_fs(get_ds());
98425- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98426+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98427 set_fs(oldfs);
98428 return res;
98429 }
98430@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98431
98432 mm_segment_t oldfs = get_fs();
98433 set_fs(get_ds());
98434- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98435+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98436 set_fs(oldfs);
98437 return res;
98438 }
98439@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98440
98441 mm_segment_t oldfs = get_fs();
98442 set_fs(get_ds());
98443- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98444+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98445 set_fs(oldfs);
98446 return res;
98447 }
98448diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98449index 812b183..56cbe9c 100644
98450--- a/net/ipv4/ipip.c
98451+++ b/net/ipv4/ipip.c
98452@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98453 static int ipip_net_id __read_mostly;
98454
98455 static int ipip_tunnel_init(struct net_device *dev);
98456-static struct rtnl_link_ops ipip_link_ops __read_mostly;
98457+static struct rtnl_link_ops ipip_link_ops;
98458
98459 static int ipip_err(struct sk_buff *skb, u32 info)
98460 {
98461@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98462 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98463 };
98464
98465-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98466+static struct rtnl_link_ops ipip_link_ops = {
98467 .kind = "ipip",
98468 .maxtype = IFLA_IPTUN_MAX,
98469 .policy = ipip_policy,
98470diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98471index 59da7cd..e318de1 100644
98472--- a/net/ipv4/netfilter/arp_tables.c
98473+++ b/net/ipv4/netfilter/arp_tables.c
98474@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98475 #endif
98476
98477 static int get_info(struct net *net, void __user *user,
98478- const int *len, int compat)
98479+ int len, int compat)
98480 {
98481 char name[XT_TABLE_MAXNAMELEN];
98482 struct xt_table *t;
98483 int ret;
98484
98485- if (*len != sizeof(struct arpt_getinfo)) {
98486- duprintf("length %u != %Zu\n", *len,
98487+ if (len != sizeof(struct arpt_getinfo)) {
98488+ duprintf("length %u != %Zu\n", len,
98489 sizeof(struct arpt_getinfo));
98490 return -EINVAL;
98491 }
98492@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98493 info.size = private->size;
98494 strcpy(info.name, name);
98495
98496- if (copy_to_user(user, &info, *len) != 0)
98497+ if (copy_to_user(user, &info, len) != 0)
98498 ret = -EFAULT;
98499 else
98500 ret = 0;
98501@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98502
98503 switch (cmd) {
98504 case ARPT_SO_GET_INFO:
98505- ret = get_info(sock_net(sk), user, len, 1);
98506+ ret = get_info(sock_net(sk), user, *len, 1);
98507 break;
98508 case ARPT_SO_GET_ENTRIES:
98509 ret = compat_get_entries(sock_net(sk), user, len);
98510@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98511
98512 switch (cmd) {
98513 case ARPT_SO_GET_INFO:
98514- ret = get_info(sock_net(sk), user, len, 0);
98515+ ret = get_info(sock_net(sk), user, *len, 0);
98516 break;
98517
98518 case ARPT_SO_GET_ENTRIES:
98519diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98520index 718dfbd..cef4152 100644
98521--- a/net/ipv4/netfilter/ip_tables.c
98522+++ b/net/ipv4/netfilter/ip_tables.c
98523@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98524 #endif
98525
98526 static int get_info(struct net *net, void __user *user,
98527- const int *len, int compat)
98528+ int len, int compat)
98529 {
98530 char name[XT_TABLE_MAXNAMELEN];
98531 struct xt_table *t;
98532 int ret;
98533
98534- if (*len != sizeof(struct ipt_getinfo)) {
98535- duprintf("length %u != %zu\n", *len,
98536+ if (len != sizeof(struct ipt_getinfo)) {
98537+ duprintf("length %u != %zu\n", len,
98538 sizeof(struct ipt_getinfo));
98539 return -EINVAL;
98540 }
98541@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98542 info.size = private->size;
98543 strcpy(info.name, name);
98544
98545- if (copy_to_user(user, &info, *len) != 0)
98546+ if (copy_to_user(user, &info, len) != 0)
98547 ret = -EFAULT;
98548 else
98549 ret = 0;
98550@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98551
98552 switch (cmd) {
98553 case IPT_SO_GET_INFO:
98554- ret = get_info(sock_net(sk), user, len, 1);
98555+ ret = get_info(sock_net(sk), user, *len, 1);
98556 break;
98557 case IPT_SO_GET_ENTRIES:
98558 ret = compat_get_entries(sock_net(sk), user, len);
98559@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98560
98561 switch (cmd) {
98562 case IPT_SO_GET_INFO:
98563- ret = get_info(sock_net(sk), user, len, 0);
98564+ ret = get_info(sock_net(sk), user, *len, 0);
98565 break;
98566
98567 case IPT_SO_GET_ENTRIES:
98568diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98569index 2510c02..cfb34fa 100644
98570--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
98571+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98572@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
98573 spin_lock_init(&cn->lock);
98574
98575 #ifdef CONFIG_PROC_FS
98576- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
98577+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
98578 if (!cn->procdir) {
98579 pr_err("Unable to proc dir entry\n");
98580 return -ENOMEM;
98581diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98582index 2d11c09..3f153f8 100644
98583--- a/net/ipv4/ping.c
98584+++ b/net/ipv4/ping.c
98585@@ -59,7 +59,7 @@ struct ping_table {
98586 };
98587
98588 static struct ping_table ping_table;
98589-struct pingv6_ops pingv6_ops;
98590+struct pingv6_ops *pingv6_ops;
98591 EXPORT_SYMBOL_GPL(pingv6_ops);
98592
98593 static u16 ping_port_rover;
98594@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98595 struct group_info *group_info = get_current_groups();
98596 int i, j, count = group_info->ngroups;
98597 kgid_t low, high;
98598+ int ret = 0;
98599
98600 inet_get_ping_group_range_net(net, &low, &high);
98601 if (gid_lte(low, group) && gid_lte(group, high))
98602- return 0;
98603+ goto out_release_group;
98604
98605 for (i = 0; i < group_info->nblocks; i++) {
98606 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98607 for (j = 0; j < cp_count; j++) {
98608 kgid_t gid = group_info->blocks[i][j];
98609 if (gid_lte(low, gid) && gid_lte(gid, high))
98610- return 0;
98611+ goto out_release_group;
98612 }
98613
98614 count -= cp_count;
98615 }
98616
98617- return -EACCES;
98618+ ret = -EACCES;
98619+
98620+out_release_group:
98621+ put_group_info(group_info);
98622+ return ret;
98623 }
98624 EXPORT_SYMBOL_GPL(ping_init_sock);
98625
98626@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98627 return -ENODEV;
98628 }
98629 }
98630- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98631+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98632 scoped);
98633 rcu_read_unlock();
98634
98635@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98636 }
98637 #if IS_ENABLED(CONFIG_IPV6)
98638 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98639- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98640+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98641 #endif
98642 }
98643
98644@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98645 info, (u8 *)icmph);
98646 #if IS_ENABLED(CONFIG_IPV6)
98647 } else if (family == AF_INET6) {
98648- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98649+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98650 info, (u8 *)icmph);
98651 #endif
98652 }
98653@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98654 {
98655 struct inet_sock *isk = inet_sk(sk);
98656 int family = sk->sk_family;
98657+ struct sockaddr_in *sin;
98658+ struct sockaddr_in6 *sin6;
98659 struct sk_buff *skb;
98660 int copied, err;
98661
98662@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98663 if (flags & MSG_OOB)
98664 goto out;
98665
98666+ if (addr_len) {
98667+ if (family == AF_INET)
98668+ *addr_len = sizeof(*sin);
98669+ else if (family == AF_INET6 && addr_len)
98670+ *addr_len = sizeof(*sin6);
98671+ }
98672+
98673 if (flags & MSG_ERRQUEUE) {
98674 if (family == AF_INET) {
98675 return ip_recv_error(sk, msg, len, addr_len);
98676 #if IS_ENABLED(CONFIG_IPV6)
98677 } else if (family == AF_INET6) {
98678- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98679+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98680 addr_len);
98681 #endif
98682 }
98683@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98684 sin->sin_port = 0 /* skb->h.uh->source */;
98685 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98686 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98687- *addr_len = sizeof(*sin);
98688 }
98689
98690 if (isk->cmsg_flags)
98691@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98692 sin6->sin6_scope_id =
98693 ipv6_iface_scope_id(&sin6->sin6_addr,
98694 IP6CB(skb)->iif);
98695- *addr_len = sizeof(*sin6);
98696 }
98697
98698 if (inet6_sk(sk)->rxopt.all)
98699- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98700+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98701 if (skb->protocol == htons(ETH_P_IPV6) &&
98702 inet6_sk(sk)->rxopt.all)
98703- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98704+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98705 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98706 ip_cmsg_recv(msg, skb);
98707 #endif
98708@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98709 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98710 0, sock_i_ino(sp),
98711 atomic_read(&sp->sk_refcnt), sp,
98712- atomic_read(&sp->sk_drops));
98713+ atomic_read_unchecked(&sp->sk_drops));
98714 }
98715
98716 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98717diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98718index c04518f..824ebe5 100644
98719--- a/net/ipv4/raw.c
98720+++ b/net/ipv4/raw.c
98721@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98722 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98723 {
98724 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98725- atomic_inc(&sk->sk_drops);
98726+ atomic_inc_unchecked(&sk->sk_drops);
98727 kfree_skb(skb);
98728 return NET_RX_DROP;
98729 }
98730@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98731 if (flags & MSG_OOB)
98732 goto out;
98733
98734+ if (addr_len)
98735+ *addr_len = sizeof(*sin);
98736+
98737 if (flags & MSG_ERRQUEUE) {
98738 err = ip_recv_error(sk, msg, len, addr_len);
98739 goto out;
98740@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98741 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98742 sin->sin_port = 0;
98743 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98744- *addr_len = sizeof(*sin);
98745 }
98746 if (inet->cmsg_flags)
98747 ip_cmsg_recv(msg, skb);
98748@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98749
98750 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98751 {
98752+ struct icmp_filter filter;
98753+
98754 if (optlen > sizeof(struct icmp_filter))
98755 optlen = sizeof(struct icmp_filter);
98756- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98757+ if (copy_from_user(&filter, optval, optlen))
98758 return -EFAULT;
98759+ raw_sk(sk)->filter = filter;
98760 return 0;
98761 }
98762
98763 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98764 {
98765 int len, ret = -EFAULT;
98766+ struct icmp_filter filter;
98767
98768 if (get_user(len, optlen))
98769 goto out;
98770@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98771 if (len > sizeof(struct icmp_filter))
98772 len = sizeof(struct icmp_filter);
98773 ret = -EFAULT;
98774- if (put_user(len, optlen) ||
98775- copy_to_user(optval, &raw_sk(sk)->filter, len))
98776+ filter = raw_sk(sk)->filter;
98777+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98778 goto out;
98779 ret = 0;
98780 out: return ret;
98781@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98782 0, 0L, 0,
98783 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98784 0, sock_i_ino(sp),
98785- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98786+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98787 }
98788
98789 static int raw_seq_show(struct seq_file *seq, void *v)
98790diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98791index 4c011ec..8fae66b 100644
98792--- a/net/ipv4/route.c
98793+++ b/net/ipv4/route.c
98794@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
98795
98796 static int rt_cache_seq_open(struct inode *inode, struct file *file)
98797 {
98798- return seq_open(file, &rt_cache_seq_ops);
98799+ return seq_open_restrict(file, &rt_cache_seq_ops);
98800 }
98801
98802 static const struct file_operations rt_cache_seq_fops = {
98803@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
98804
98805 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
98806 {
98807- return seq_open(file, &rt_cpu_seq_ops);
98808+ return seq_open_restrict(file, &rt_cpu_seq_ops);
98809 }
98810
98811 static const struct file_operations rt_cpu_seq_fops = {
98812@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
98813
98814 static int rt_acct_proc_open(struct inode *inode, struct file *file)
98815 {
98816- return single_open(file, rt_acct_proc_show, NULL);
98817+ return single_open_restrict(file, rt_acct_proc_show, NULL);
98818 }
98819
98820 static const struct file_operations rt_acct_proc_fops = {
98821@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98822 .maxlen = sizeof(int),
98823 .mode = 0200,
98824 .proc_handler = ipv4_sysctl_rtcache_flush,
98825+ .extra1 = &init_net,
98826 },
98827 { },
98828 };
98829
98830 static __net_init int sysctl_route_net_init(struct net *net)
98831 {
98832- struct ctl_table *tbl;
98833+ ctl_table_no_const *tbl = NULL;
98834
98835- tbl = ipv4_route_flush_table;
98836 if (!net_eq(net, &init_net)) {
98837- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98838+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98839 if (tbl == NULL)
98840 goto err_dup;
98841
98842 /* Don't export sysctls to unprivileged users */
98843 if (net->user_ns != &init_user_ns)
98844 tbl[0].procname = NULL;
98845- }
98846- tbl[0].extra1 = net;
98847+ tbl[0].extra1 = net;
98848+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98849+ } else
98850+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98851
98852- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98853 if (net->ipv4.route_hdr == NULL)
98854 goto err_reg;
98855 return 0;
98856
98857 err_reg:
98858- if (tbl != ipv4_route_flush_table)
98859- kfree(tbl);
98860+ kfree(tbl);
98861 err_dup:
98862 return -ENOMEM;
98863 }
98864@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98865
98866 static __net_init int rt_genid_init(struct net *net)
98867 {
98868- atomic_set(&net->ipv4.rt_genid, 0);
98869- atomic_set(&net->fnhe_genid, 0);
98870+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98871+ atomic_set_unchecked(&net->fnhe_genid, 0);
98872 get_random_bytes(&net->ipv4.dev_addr_genid,
98873 sizeof(net->ipv4.dev_addr_genid));
98874 return 0;
98875diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98876index 44eba05..b36864b 100644
98877--- a/net/ipv4/sysctl_net_ipv4.c
98878+++ b/net/ipv4/sysctl_net_ipv4.c
98879@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98880 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98881 int ret;
98882 int range[2];
98883- struct ctl_table tmp = {
98884+ ctl_table_no_const tmp = {
98885 .data = &range,
98886 .maxlen = sizeof(range),
98887 .mode = table->mode,
98888@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98889 int ret;
98890 gid_t urange[2];
98891 kgid_t low, high;
98892- struct ctl_table tmp = {
98893+ ctl_table_no_const tmp = {
98894 .data = &urange,
98895 .maxlen = sizeof(urange),
98896 .mode = table->mode,
98897@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98898 void __user *buffer, size_t *lenp, loff_t *ppos)
98899 {
98900 char val[TCP_CA_NAME_MAX];
98901- struct ctl_table tbl = {
98902+ ctl_table_no_const tbl = {
98903 .data = val,
98904 .maxlen = TCP_CA_NAME_MAX,
98905 };
98906@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98907 void __user *buffer, size_t *lenp,
98908 loff_t *ppos)
98909 {
98910- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98911+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98912 int ret;
98913
98914 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98915@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98916 void __user *buffer, size_t *lenp,
98917 loff_t *ppos)
98918 {
98919- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98920+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98921 int ret;
98922
98923 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98924@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98925 void __user *buffer, size_t *lenp,
98926 loff_t *ppos)
98927 {
98928- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98929+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98930 struct tcp_fastopen_context *ctxt;
98931 int ret;
98932 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98933@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
98934 },
98935 {
98936 .procname = "ip_local_reserved_ports",
98937- .data = NULL, /* initialized in sysctl_ipv4_init */
98938+ .data = sysctl_local_reserved_ports,
98939 .maxlen = 65536,
98940 .mode = 0644,
98941 .proc_handler = proc_do_large_bitmap,
98942@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
98943
98944 static __net_init int ipv4_sysctl_init_net(struct net *net)
98945 {
98946- struct ctl_table *table;
98947+ ctl_table_no_const *table = NULL;
98948
98949- table = ipv4_net_table;
98950 if (!net_eq(net, &init_net)) {
98951 int i;
98952
98953- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98954+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98955 if (table == NULL)
98956 goto err_alloc;
98957
98958@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98959 net->ipv4.sysctl_local_ports.range[0] = 32768;
98960 net->ipv4.sysctl_local_ports.range[1] = 61000;
98961
98962- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98963+ if (!net_eq(net, &init_net))
98964+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98965+ else
98966+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98967 if (net->ipv4.ipv4_hdr == NULL)
98968 goto err_reg;
98969
98970 return 0;
98971
98972 err_reg:
98973- if (!net_eq(net, &init_net))
98974- kfree(table);
98975+ kfree(table);
98976 err_alloc:
98977 return -ENOMEM;
98978 }
98979@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98980 static __init int sysctl_ipv4_init(void)
98981 {
98982 struct ctl_table_header *hdr;
98983- struct ctl_table *i;
98984-
98985- for (i = ipv4_table; i->procname; i++) {
98986- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98987- i->data = sysctl_local_reserved_ports;
98988- break;
98989- }
98990- }
98991- if (!i->procname)
98992- return -EINVAL;
98993
98994 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98995 if (hdr == NULL)
98996diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98997index eeaac39..dc29942 100644
98998--- a/net/ipv4/tcp_input.c
98999+++ b/net/ipv4/tcp_input.c
99000@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99001 * without any lock. We want to make sure compiler wont store
99002 * intermediate values in this location.
99003 */
99004- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99005+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99006 sk->sk_max_pacing_rate);
99007 }
99008
99009@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99010 * simplifies code)
99011 */
99012 static void
99013-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99014+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99015 struct sk_buff *head, struct sk_buff *tail,
99016 u32 start, u32 end)
99017 {
99018@@ -5562,6 +5562,7 @@ discard:
99019 tcp_paws_reject(&tp->rx_opt, 0))
99020 goto discard_and_undo;
99021
99022+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99023 if (th->syn) {
99024 /* We see SYN without ACK. It is attempt of
99025 * simultaneous connect with crossed SYNs.
99026@@ -5612,6 +5613,7 @@ discard:
99027 goto discard;
99028 #endif
99029 }
99030+#endif
99031 /* "fifth, if neither of the SYN or RST bits is set then
99032 * drop the segment and return."
99033 */
99034@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99035 goto discard;
99036
99037 if (th->syn) {
99038- if (th->fin)
99039+ if (th->fin || th->urg || th->psh)
99040 goto discard;
99041 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99042 return 1;
99043diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99044index 1e4eac7..a66fa4a 100644
99045--- a/net/ipv4/tcp_ipv4.c
99046+++ b/net/ipv4/tcp_ipv4.c
99047@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99048 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99049
99050
99051+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99052+extern int grsec_enable_blackhole;
99053+#endif
99054+
99055 #ifdef CONFIG_TCP_MD5SIG
99056 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99057 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99058@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99059 return 0;
99060
99061 reset:
99062+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99063+ if (!grsec_enable_blackhole)
99064+#endif
99065 tcp_v4_send_reset(rsk, skb);
99066 discard:
99067 kfree_skb(skb);
99068@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99069 TCP_SKB_CB(skb)->sacked = 0;
99070
99071 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99072- if (!sk)
99073+ if (!sk) {
99074+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99075+ ret = 1;
99076+#endif
99077 goto no_tcp_socket;
99078-
99079+ }
99080 process:
99081- if (sk->sk_state == TCP_TIME_WAIT)
99082+ if (sk->sk_state == TCP_TIME_WAIT) {
99083+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99084+ ret = 2;
99085+#endif
99086 goto do_time_wait;
99087+ }
99088
99089 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99090 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99091@@ -2033,6 +2047,10 @@ csum_error:
99092 bad_packet:
99093 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99094 } else {
99095+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99096+ if (!grsec_enable_blackhole || (ret == 1 &&
99097+ (skb->dev->flags & IFF_LOOPBACK)))
99098+#endif
99099 tcp_v4_send_reset(NULL, skb);
99100 }
99101
99102diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99103index 7a436c5..1b05c59 100644
99104--- a/net/ipv4/tcp_minisocks.c
99105+++ b/net/ipv4/tcp_minisocks.c
99106@@ -27,6 +27,10 @@
99107 #include <net/inet_common.h>
99108 #include <net/xfrm.h>
99109
99110+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99111+extern int grsec_enable_blackhole;
99112+#endif
99113+
99114 int sysctl_tcp_syncookies __read_mostly = 1;
99115 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99116
99117@@ -709,7 +713,10 @@ embryonic_reset:
99118 * avoid becoming vulnerable to outside attack aiming at
99119 * resetting legit local connections.
99120 */
99121- req->rsk_ops->send_reset(sk, skb);
99122+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99123+ if (!grsec_enable_blackhole)
99124+#endif
99125+ req->rsk_ops->send_reset(sk, skb);
99126 } else if (fastopen) { /* received a valid RST pkt */
99127 reqsk_fastopen_remove(sk, req, true);
99128 tcp_reset(sk);
99129diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99130index 1f2d376..01d18c4 100644
99131--- a/net/ipv4/tcp_probe.c
99132+++ b/net/ipv4/tcp_probe.c
99133@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99134 if (cnt + width >= len)
99135 break;
99136
99137- if (copy_to_user(buf + cnt, tbuf, width))
99138+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99139 return -EFAULT;
99140 cnt += width;
99141 }
99142diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99143index 64f0354..a81b39d 100644
99144--- a/net/ipv4/tcp_timer.c
99145+++ b/net/ipv4/tcp_timer.c
99146@@ -22,6 +22,10 @@
99147 #include <linux/gfp.h>
99148 #include <net/tcp.h>
99149
99150+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99151+extern int grsec_lastack_retries;
99152+#endif
99153+
99154 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99155 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99156 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99157@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99158 }
99159 }
99160
99161+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99162+ if ((sk->sk_state == TCP_LAST_ACK) &&
99163+ (grsec_lastack_retries > 0) &&
99164+ (grsec_lastack_retries < retry_until))
99165+ retry_until = grsec_lastack_retries;
99166+#endif
99167+
99168 if (retransmits_timed_out(sk, retry_until,
99169 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99170 /* Has it gone just too far? */
99171diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99172index 77bd16f..5f7174a 100644
99173--- a/net/ipv4/udp.c
99174+++ b/net/ipv4/udp.c
99175@@ -87,6 +87,7 @@
99176 #include <linux/types.h>
99177 #include <linux/fcntl.h>
99178 #include <linux/module.h>
99179+#include <linux/security.h>
99180 #include <linux/socket.h>
99181 #include <linux/sockios.h>
99182 #include <linux/igmp.h>
99183@@ -113,6 +114,10 @@
99184 #include <net/busy_poll.h>
99185 #include "udp_impl.h"
99186
99187+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99188+extern int grsec_enable_blackhole;
99189+#endif
99190+
99191 struct udp_table udp_table __read_mostly;
99192 EXPORT_SYMBOL(udp_table);
99193
99194@@ -615,6 +620,9 @@ found:
99195 return s;
99196 }
99197
99198+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99199+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99200+
99201 /*
99202 * This routine is called by the ICMP module when it gets some
99203 * sort of error condition. If err < 0 then the socket should
99204@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99205 dport = usin->sin_port;
99206 if (dport == 0)
99207 return -EINVAL;
99208+
99209+ err = gr_search_udp_sendmsg(sk, usin);
99210+ if (err)
99211+ return err;
99212 } else {
99213 if (sk->sk_state != TCP_ESTABLISHED)
99214 return -EDESTADDRREQ;
99215+
99216+ err = gr_search_udp_sendmsg(sk, NULL);
99217+ if (err)
99218+ return err;
99219+
99220 daddr = inet->inet_daddr;
99221 dport = inet->inet_dport;
99222 /* Open fast path for connected socket.
99223@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99224 IS_UDPLITE(sk));
99225 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99226 IS_UDPLITE(sk));
99227- atomic_inc(&sk->sk_drops);
99228+ atomic_inc_unchecked(&sk->sk_drops);
99229 __skb_unlink(skb, rcvq);
99230 __skb_queue_tail(&list_kill, skb);
99231 }
99232@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99233 int is_udplite = IS_UDPLITE(sk);
99234 bool slow;
99235
99236+ /*
99237+ * Check any passed addresses
99238+ */
99239+ if (addr_len)
99240+ *addr_len = sizeof(*sin);
99241+
99242 if (flags & MSG_ERRQUEUE)
99243 return ip_recv_error(sk, msg, len, addr_len);
99244
99245@@ -1243,6 +1266,10 @@ try_again:
99246 if (!skb)
99247 goto out;
99248
99249+ err = gr_search_udp_recvmsg(sk, skb);
99250+ if (err)
99251+ goto out_free;
99252+
99253 ulen = skb->len - sizeof(struct udphdr);
99254 copied = len;
99255 if (copied > ulen)
99256@@ -1276,7 +1303,7 @@ try_again:
99257 if (unlikely(err)) {
99258 trace_kfree_skb(skb, udp_recvmsg);
99259 if (!peeked) {
99260- atomic_inc(&sk->sk_drops);
99261+ atomic_inc_unchecked(&sk->sk_drops);
99262 UDP_INC_STATS_USER(sock_net(sk),
99263 UDP_MIB_INERRORS, is_udplite);
99264 }
99265@@ -1295,7 +1322,6 @@ try_again:
99266 sin->sin_port = udp_hdr(skb)->source;
99267 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99268 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99269- *addr_len = sizeof(*sin);
99270 }
99271 if (inet->cmsg_flags)
99272 ip_cmsg_recv(msg, skb);
99273@@ -1566,7 +1592,7 @@ csum_error:
99274 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99275 drop:
99276 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99277- atomic_inc(&sk->sk_drops);
99278+ atomic_inc_unchecked(&sk->sk_drops);
99279 kfree_skb(skb);
99280 return -1;
99281 }
99282@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99283 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99284
99285 if (!skb1) {
99286- atomic_inc(&sk->sk_drops);
99287+ atomic_inc_unchecked(&sk->sk_drops);
99288 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99289 IS_UDPLITE(sk));
99290 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99291@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99292 goto csum_error;
99293
99294 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99295+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99296+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99297+#endif
99298 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99299
99300 /*
99301@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99302 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99303 0, sock_i_ino(sp),
99304 atomic_read(&sp->sk_refcnt), sp,
99305- atomic_read(&sp->sk_drops));
99306+ atomic_read_unchecked(&sp->sk_drops));
99307 }
99308
99309 int udp4_seq_show(struct seq_file *seq, void *v)
99310diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99311index e1a6393..f634ce5 100644
99312--- a/net/ipv4/xfrm4_policy.c
99313+++ b/net/ipv4/xfrm4_policy.c
99314@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99315 fl4->flowi4_tos = iph->tos;
99316 }
99317
99318-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99319+static int xfrm4_garbage_collect(struct dst_ops *ops)
99320 {
99321 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99322
99323- xfrm4_policy_afinfo.garbage_collect(net);
99324+ xfrm_garbage_collect_deferred(net);
99325 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99326 }
99327
99328@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99329
99330 static int __net_init xfrm4_net_init(struct net *net)
99331 {
99332- struct ctl_table *table;
99333+ ctl_table_no_const *table = NULL;
99334 struct ctl_table_header *hdr;
99335
99336- table = xfrm4_policy_table;
99337 if (!net_eq(net, &init_net)) {
99338- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99339+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99340 if (!table)
99341 goto err_alloc;
99342
99343 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99344- }
99345-
99346- hdr = register_net_sysctl(net, "net/ipv4", table);
99347+ hdr = register_net_sysctl(net, "net/ipv4", table);
99348+ } else
99349+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99350 if (!hdr)
99351 goto err_reg;
99352
99353@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99354 return 0;
99355
99356 err_reg:
99357- if (!net_eq(net, &init_net))
99358- kfree(table);
99359+ kfree(table);
99360 err_alloc:
99361 return -ENOMEM;
99362 }
99363diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99364index 6c7fa08..285086c 100644
99365--- a/net/ipv6/addrconf.c
99366+++ b/net/ipv6/addrconf.c
99367@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99368 idx = 0;
99369 head = &net->dev_index_head[h];
99370 rcu_read_lock();
99371- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99372+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99373 net->dev_base_seq;
99374 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99375 if (idx < s_idx)
99376@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99377 p.iph.ihl = 5;
99378 p.iph.protocol = IPPROTO_IPV6;
99379 p.iph.ttl = 64;
99380- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99381+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99382
99383 if (ops->ndo_do_ioctl) {
99384 mm_segment_t oldfs = get_fs();
99385@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99386 s_ip_idx = ip_idx = cb->args[2];
99387
99388 rcu_read_lock();
99389- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99390+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99391 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99392 idx = 0;
99393 head = &net->dev_index_head[h];
99394@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99395 dst_free(&ifp->rt->dst);
99396 break;
99397 }
99398- atomic_inc(&net->ipv6.dev_addr_genid);
99399+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99400 rt_genid_bump_ipv6(net);
99401 }
99402
99403@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99404 int *valp = ctl->data;
99405 int val = *valp;
99406 loff_t pos = *ppos;
99407- struct ctl_table lctl;
99408+ ctl_table_no_const lctl;
99409 int ret;
99410
99411 /*
99412@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99413 int *valp = ctl->data;
99414 int val = *valp;
99415 loff_t pos = *ppos;
99416- struct ctl_table lctl;
99417+ ctl_table_no_const lctl;
99418 int ret;
99419
99420 /*
99421diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99422index d935889..2f64330 100644
99423--- a/net/ipv6/af_inet6.c
99424+++ b/net/ipv6/af_inet6.c
99425@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99426 net->ipv6.sysctl.bindv6only = 0;
99427 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99428 net->ipv6.sysctl.flowlabel_consistency = 1;
99429- atomic_set(&net->ipv6.rt_genid, 0);
99430+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99431
99432 err = ipv6_init_mibs(net);
99433 if (err)
99434diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99435index c3bf2d2..1f00573 100644
99436--- a/net/ipv6/datagram.c
99437+++ b/net/ipv6/datagram.c
99438@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99439 0,
99440 sock_i_ino(sp),
99441 atomic_read(&sp->sk_refcnt), sp,
99442- atomic_read(&sp->sk_drops));
99443+ atomic_read_unchecked(&sp->sk_drops));
99444 }
99445diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
99446index 7b32652..0bc348b 100644
99447--- a/net/ipv6/icmp.c
99448+++ b/net/ipv6/icmp.c
99449@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
99450
99451 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
99452 {
99453- struct ctl_table *table;
99454+ ctl_table_no_const *table;
99455
99456 table = kmemdup(ipv6_icmp_table_template,
99457 sizeof(ipv6_icmp_table_template),
99458diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
99459index f3ffb43..1172ba7 100644
99460--- a/net/ipv6/ip6_gre.c
99461+++ b/net/ipv6/ip6_gre.c
99462@@ -71,7 +71,7 @@ struct ip6gre_net {
99463 struct net_device *fb_tunnel_dev;
99464 };
99465
99466-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
99467+static struct rtnl_link_ops ip6gre_link_ops;
99468 static int ip6gre_tunnel_init(struct net_device *dev);
99469 static void ip6gre_tunnel_setup(struct net_device *dev);
99470 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
99471@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99472 }
99473
99474
99475-static struct inet6_protocol ip6gre_protocol __read_mostly = {
99476+static struct inet6_protocol ip6gre_protocol = {
99477 .handler = ip6gre_rcv,
99478 .err_handler = ip6gre_err,
99479 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99480@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99481 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99482 };
99483
99484-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99485+static struct rtnl_link_ops ip6gre_link_ops = {
99486 .kind = "ip6gre",
99487 .maxtype = IFLA_GRE_MAX,
99488 .policy = ip6gre_policy,
99489@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99490 .fill_info = ip6gre_fill_info,
99491 };
99492
99493-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99494+static struct rtnl_link_ops ip6gre_tap_ops = {
99495 .kind = "ip6gretap",
99496 .maxtype = IFLA_GRE_MAX,
99497 .policy = ip6gre_policy,
99498diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99499index 5db8d31..4a72c26 100644
99500--- a/net/ipv6/ip6_tunnel.c
99501+++ b/net/ipv6/ip6_tunnel.c
99502@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99503
99504 static int ip6_tnl_dev_init(struct net_device *dev);
99505 static void ip6_tnl_dev_setup(struct net_device *dev);
99506-static struct rtnl_link_ops ip6_link_ops __read_mostly;
99507+static struct rtnl_link_ops ip6_link_ops;
99508
99509 static int ip6_tnl_net_id __read_mostly;
99510 struct ip6_tnl_net {
99511@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99512 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99513 };
99514
99515-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99516+static struct rtnl_link_ops ip6_link_ops = {
99517 .kind = "ip6tnl",
99518 .maxtype = IFLA_IPTUN_MAX,
99519 .policy = ip6_tnl_policy,
99520diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99521index 2d19272..3a46322 100644
99522--- a/net/ipv6/ip6_vti.c
99523+++ b/net/ipv6/ip6_vti.c
99524@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99525
99526 static int vti6_dev_init(struct net_device *dev);
99527 static void vti6_dev_setup(struct net_device *dev);
99528-static struct rtnl_link_ops vti6_link_ops __read_mostly;
99529+static struct rtnl_link_ops vti6_link_ops;
99530
99531 static int vti6_net_id __read_mostly;
99532 struct vti6_net {
99533@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99534 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99535 };
99536
99537-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99538+static struct rtnl_link_ops vti6_link_ops = {
99539 .kind = "vti6",
99540 .maxtype = IFLA_VTI_MAX,
99541 .policy = vti6_policy,
99542diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99543index 0a00f44..bec42b2 100644
99544--- a/net/ipv6/ipv6_sockglue.c
99545+++ b/net/ipv6/ipv6_sockglue.c
99546@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99547 if (sk->sk_type != SOCK_STREAM)
99548 return -ENOPROTOOPT;
99549
99550- msg.msg_control = optval;
99551+ msg.msg_control = (void __force_kernel *)optval;
99552 msg.msg_controllen = len;
99553 msg.msg_flags = flags;
99554
99555diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99556index 710238f..0fd1816 100644
99557--- a/net/ipv6/netfilter/ip6_tables.c
99558+++ b/net/ipv6/netfilter/ip6_tables.c
99559@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99560 #endif
99561
99562 static int get_info(struct net *net, void __user *user,
99563- const int *len, int compat)
99564+ int len, int compat)
99565 {
99566 char name[XT_TABLE_MAXNAMELEN];
99567 struct xt_table *t;
99568 int ret;
99569
99570- if (*len != sizeof(struct ip6t_getinfo)) {
99571- duprintf("length %u != %zu\n", *len,
99572+ if (len != sizeof(struct ip6t_getinfo)) {
99573+ duprintf("length %u != %zu\n", len,
99574 sizeof(struct ip6t_getinfo));
99575 return -EINVAL;
99576 }
99577@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99578 info.size = private->size;
99579 strcpy(info.name, name);
99580
99581- if (copy_to_user(user, &info, *len) != 0)
99582+ if (copy_to_user(user, &info, len) != 0)
99583 ret = -EFAULT;
99584 else
99585 ret = 0;
99586@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99587
99588 switch (cmd) {
99589 case IP6T_SO_GET_INFO:
99590- ret = get_info(sock_net(sk), user, len, 1);
99591+ ret = get_info(sock_net(sk), user, *len, 1);
99592 break;
99593 case IP6T_SO_GET_ENTRIES:
99594 ret = compat_get_entries(sock_net(sk), user, len);
99595@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99596
99597 switch (cmd) {
99598 case IP6T_SO_GET_INFO:
99599- ret = get_info(sock_net(sk), user, len, 0);
99600+ ret = get_info(sock_net(sk), user, *len, 0);
99601 break;
99602
99603 case IP6T_SO_GET_ENTRIES:
99604diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99605index 767ab8d..c5ec70a 100644
99606--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99607+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99608@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99609
99610 static int nf_ct_frag6_sysctl_register(struct net *net)
99611 {
99612- struct ctl_table *table;
99613+ ctl_table_no_const *table = NULL;
99614 struct ctl_table_header *hdr;
99615
99616- table = nf_ct_frag6_sysctl_table;
99617 if (!net_eq(net, &init_net)) {
99618- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99619+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99620 GFP_KERNEL);
99621 if (table == NULL)
99622 goto err_alloc;
99623@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99624 table[0].data = &net->nf_frag.frags.timeout;
99625 table[1].data = &net->nf_frag.frags.low_thresh;
99626 table[2].data = &net->nf_frag.frags.high_thresh;
99627- }
99628-
99629- hdr = register_net_sysctl(net, "net/netfilter", table);
99630+ hdr = register_net_sysctl(net, "net/netfilter", table);
99631+ } else
99632+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99633 if (hdr == NULL)
99634 goto err_reg;
99635
99636@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99637 return 0;
99638
99639 err_reg:
99640- if (!net_eq(net, &init_net))
99641- kfree(table);
99642+ kfree(table);
99643 err_alloc:
99644 return -ENOMEM;
99645 }
99646diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99647index 827f795..7e28e82 100644
99648--- a/net/ipv6/output_core.c
99649+++ b/net/ipv6/output_core.c
99650@@ -9,8 +9,8 @@
99651
99652 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99653 {
99654- static atomic_t ipv6_fragmentation_id;
99655- int old, new;
99656+ static atomic_unchecked_t ipv6_fragmentation_id;
99657+ int id;
99658
99659 #if IS_ENABLED(CONFIG_IPV6)
99660 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99661@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99662 }
99663 }
99664 #endif
99665- do {
99666- old = atomic_read(&ipv6_fragmentation_id);
99667- new = old + 1;
99668- if (!new)
99669- new = 1;
99670- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99671- fhdr->identification = htonl(new);
99672+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99673+ if (!id)
99674+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99675+ fhdr->identification = htonl(id);
99676 }
99677 EXPORT_SYMBOL(ipv6_select_ident);
99678
99679diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99680index bda7429..469b26b 100644
99681--- a/net/ipv6/ping.c
99682+++ b/net/ipv6/ping.c
99683@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99684 };
99685 #endif
99686
99687+static struct pingv6_ops real_pingv6_ops = {
99688+ .ipv6_recv_error = ipv6_recv_error,
99689+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99690+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99691+ .icmpv6_err_convert = icmpv6_err_convert,
99692+ .ipv6_icmp_error = ipv6_icmp_error,
99693+ .ipv6_chk_addr = ipv6_chk_addr,
99694+};
99695+
99696+static struct pingv6_ops dummy_pingv6_ops = {
99697+ .ipv6_recv_error = dummy_ipv6_recv_error,
99698+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99699+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99700+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99701+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99702+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99703+};
99704+
99705 int __init pingv6_init(void)
99706 {
99707 #ifdef CONFIG_PROC_FS
99708@@ -253,13 +271,7 @@ int __init pingv6_init(void)
99709 if (ret)
99710 return ret;
99711 #endif
99712- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99713- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99714- pingv6_ops.ip6_datagram_recv_specific_ctl =
99715- ip6_datagram_recv_specific_ctl;
99716- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99717- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99718- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99719+ pingv6_ops = &real_pingv6_ops;
99720 return inet6_register_protosw(&pingv6_protosw);
99721 }
99722
99723@@ -268,14 +280,9 @@ int __init pingv6_init(void)
99724 */
99725 void pingv6_exit(void)
99726 {
99727- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99728- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99729- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99730- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99731- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99732- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99733 #ifdef CONFIG_PROC_FS
99734 unregister_pernet_subsys(&ping_v6_net_ops);
99735 #endif
99736+ pingv6_ops = &dummy_pingv6_ops;
99737 inet6_unregister_protosw(&pingv6_protosw);
99738 }
99739diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
99740index 091d066..139d410 100644
99741--- a/net/ipv6/proc.c
99742+++ b/net/ipv6/proc.c
99743@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
99744 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
99745 goto proc_snmp6_fail;
99746
99747- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
99748+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
99749 if (!net->mib.proc_net_devsnmp6)
99750 goto proc_dev_snmp6_fail;
99751 return 0;
99752diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99753index 1f29996..46fe0c7 100644
99754--- a/net/ipv6/raw.c
99755+++ b/net/ipv6/raw.c
99756@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99757 {
99758 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99759 skb_checksum_complete(skb)) {
99760- atomic_inc(&sk->sk_drops);
99761+ atomic_inc_unchecked(&sk->sk_drops);
99762 kfree_skb(skb);
99763 return NET_RX_DROP;
99764 }
99765@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99766 struct raw6_sock *rp = raw6_sk(sk);
99767
99768 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99769- atomic_inc(&sk->sk_drops);
99770+ atomic_inc_unchecked(&sk->sk_drops);
99771 kfree_skb(skb);
99772 return NET_RX_DROP;
99773 }
99774@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99775
99776 if (inet->hdrincl) {
99777 if (skb_checksum_complete(skb)) {
99778- atomic_inc(&sk->sk_drops);
99779+ atomic_inc_unchecked(&sk->sk_drops);
99780 kfree_skb(skb);
99781 return NET_RX_DROP;
99782 }
99783@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99784 if (flags & MSG_OOB)
99785 return -EOPNOTSUPP;
99786
99787+ if (addr_len)
99788+ *addr_len=sizeof(*sin6);
99789+
99790 if (flags & MSG_ERRQUEUE)
99791 return ipv6_recv_error(sk, msg, len, addr_len);
99792
99793@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99794 sin6->sin6_flowinfo = 0;
99795 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99796 IP6CB(skb)->iif);
99797- *addr_len = sizeof(*sin6);
99798 }
99799
99800 sock_recv_ts_and_drops(msg, sk, skb);
99801@@ -610,7 +612,7 @@ out:
99802 return err;
99803 }
99804
99805-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99806+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99807 struct flowi6 *fl6, struct dst_entry **dstp,
99808 unsigned int flags)
99809 {
99810@@ -922,12 +924,15 @@ do_confirm:
99811 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99812 char __user *optval, int optlen)
99813 {
99814+ struct icmp6_filter filter;
99815+
99816 switch (optname) {
99817 case ICMPV6_FILTER:
99818 if (optlen > sizeof(struct icmp6_filter))
99819 optlen = sizeof(struct icmp6_filter);
99820- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99821+ if (copy_from_user(&filter, optval, optlen))
99822 return -EFAULT;
99823+ raw6_sk(sk)->filter = filter;
99824 return 0;
99825 default:
99826 return -ENOPROTOOPT;
99827@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99828 char __user *optval, int __user *optlen)
99829 {
99830 int len;
99831+ struct icmp6_filter filter;
99832
99833 switch (optname) {
99834 case ICMPV6_FILTER:
99835@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99836 len = sizeof(struct icmp6_filter);
99837 if (put_user(len, optlen))
99838 return -EFAULT;
99839- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99840+ filter = raw6_sk(sk)->filter;
99841+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
99842 return -EFAULT;
99843 return 0;
99844 default:
99845diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99846index cc85a9b..526a133 100644
99847--- a/net/ipv6/reassembly.c
99848+++ b/net/ipv6/reassembly.c
99849@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99850
99851 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99852 {
99853- struct ctl_table *table;
99854+ ctl_table_no_const *table = NULL;
99855 struct ctl_table_header *hdr;
99856
99857- table = ip6_frags_ns_ctl_table;
99858 if (!net_eq(net, &init_net)) {
99859- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99860+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99861 if (table == NULL)
99862 goto err_alloc;
99863
99864@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99865 /* Don't export sysctls to unprivileged users */
99866 if (net->user_ns != &init_user_ns)
99867 table[0].procname = NULL;
99868- }
99869+ hdr = register_net_sysctl(net, "net/ipv6", table);
99870+ } else
99871+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99872
99873- hdr = register_net_sysctl(net, "net/ipv6", table);
99874 if (hdr == NULL)
99875 goto err_reg;
99876
99877@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99878 return 0;
99879
99880 err_reg:
99881- if (!net_eq(net, &init_net))
99882- kfree(table);
99883+ kfree(table);
99884 err_alloc:
99885 return -ENOMEM;
99886 }
99887diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99888index fba54a4..73e374e 100644
99889--- a/net/ipv6/route.c
99890+++ b/net/ipv6/route.c
99891@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
99892
99893 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99894 {
99895- struct ctl_table *table;
99896+ ctl_table_no_const *table;
99897
99898 table = kmemdup(ipv6_route_table_template,
99899 sizeof(ipv6_route_table_template),
99900diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99901index b4d74c8..b4f3fbe 100644
99902--- a/net/ipv6/sit.c
99903+++ b/net/ipv6/sit.c
99904@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99905 static void ipip6_dev_free(struct net_device *dev);
99906 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99907 __be32 *v4dst);
99908-static struct rtnl_link_ops sit_link_ops __read_mostly;
99909+static struct rtnl_link_ops sit_link_ops;
99910
99911 static int sit_net_id __read_mostly;
99912 struct sit_net {
99913@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99914 unregister_netdevice_queue(dev, head);
99915 }
99916
99917-static struct rtnl_link_ops sit_link_ops __read_mostly = {
99918+static struct rtnl_link_ops sit_link_ops = {
99919 .kind = "sit",
99920 .maxtype = IFLA_IPTUN_MAX,
99921 .policy = ipip6_policy,
99922diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99923index 7f405a1..eabef92 100644
99924--- a/net/ipv6/sysctl_net_ipv6.c
99925+++ b/net/ipv6/sysctl_net_ipv6.c
99926@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
99927
99928 static int __net_init ipv6_sysctl_net_init(struct net *net)
99929 {
99930- struct ctl_table *ipv6_table;
99931+ ctl_table_no_const *ipv6_table;
99932 struct ctl_table *ipv6_route_table;
99933 struct ctl_table *ipv6_icmp_table;
99934 int err;
99935diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99936index 889079b..a04512c 100644
99937--- a/net/ipv6/tcp_ipv6.c
99938+++ b/net/ipv6/tcp_ipv6.c
99939@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99940 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99941 }
99942
99943+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99944+extern int grsec_enable_blackhole;
99945+#endif
99946+
99947 static void tcp_v6_hash(struct sock *sk)
99948 {
99949 if (sk->sk_state != TCP_CLOSE) {
99950@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99951 return 0;
99952
99953 reset:
99954+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99955+ if (!grsec_enable_blackhole)
99956+#endif
99957 tcp_v6_send_reset(sk, skb);
99958 discard:
99959 if (opt_skb)
99960@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99961 TCP_SKB_CB(skb)->sacked = 0;
99962
99963 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99964- if (!sk)
99965+ if (!sk) {
99966+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99967+ ret = 1;
99968+#endif
99969 goto no_tcp_socket;
99970+ }
99971
99972 process:
99973- if (sk->sk_state == TCP_TIME_WAIT)
99974+ if (sk->sk_state == TCP_TIME_WAIT) {
99975+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99976+ ret = 2;
99977+#endif
99978 goto do_time_wait;
99979+ }
99980
99981 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99982 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99983@@ -1553,6 +1568,10 @@ csum_error:
99984 bad_packet:
99985 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99986 } else {
99987+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99988+ if (!grsec_enable_blackhole || (ret == 1 &&
99989+ (skb->dev->flags & IFF_LOOPBACK)))
99990+#endif
99991 tcp_v6_send_reset(NULL, skb);
99992 }
99993
99994diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99995index 1e586d9..384a9c9 100644
99996--- a/net/ipv6/udp.c
99997+++ b/net/ipv6/udp.c
99998@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99999 udp_ipv6_hash_secret + net_hash_mix(net));
100000 }
100001
100002+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100003+extern int grsec_enable_blackhole;
100004+#endif
100005+
100006 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100007 {
100008 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100009@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100010 int is_udp4;
100011 bool slow;
100012
100013+ if (addr_len)
100014+ *addr_len = sizeof(struct sockaddr_in6);
100015+
100016 if (flags & MSG_ERRQUEUE)
100017 return ipv6_recv_error(sk, msg, len, addr_len);
100018
100019@@ -435,7 +442,7 @@ try_again:
100020 if (unlikely(err)) {
100021 trace_kfree_skb(skb, udpv6_recvmsg);
100022 if (!peeked) {
100023- atomic_inc(&sk->sk_drops);
100024+ atomic_inc_unchecked(&sk->sk_drops);
100025 if (is_udp4)
100026 UDP_INC_STATS_USER(sock_net(sk),
100027 UDP_MIB_INERRORS,
100028@@ -475,7 +482,7 @@ try_again:
100029 ipv6_iface_scope_id(&sin6->sin6_addr,
100030 IP6CB(skb)->iif);
100031 }
100032- *addr_len = sizeof(*sin6);
100033+
100034 }
100035
100036 if (np->rxopt.all)
100037@@ -690,7 +697,7 @@ csum_error:
100038 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100039 drop:
100040 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100041- atomic_inc(&sk->sk_drops);
100042+ atomic_inc_unchecked(&sk->sk_drops);
100043 kfree_skb(skb);
100044 return -1;
100045 }
100046@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100047 if (likely(skb1 == NULL))
100048 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100049 if (!skb1) {
100050- atomic_inc(&sk->sk_drops);
100051+ atomic_inc_unchecked(&sk->sk_drops);
100052 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100053 IS_UDPLITE(sk));
100054 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100055@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100056 goto csum_error;
100057
100058 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100059+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100060+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100061+#endif
100062 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100063
100064 kfree_skb(skb);
100065diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100066index 5f8e128..865d38e 100644
100067--- a/net/ipv6/xfrm6_policy.c
100068+++ b/net/ipv6/xfrm6_policy.c
100069@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100070 }
100071 }
100072
100073-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100074+static int xfrm6_garbage_collect(struct dst_ops *ops)
100075 {
100076 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100077
100078- xfrm6_policy_afinfo.garbage_collect(net);
100079+ xfrm_garbage_collect_deferred(net);
100080 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100081 }
100082
100083@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100084
100085 static int __net_init xfrm6_net_init(struct net *net)
100086 {
100087- struct ctl_table *table;
100088+ ctl_table_no_const *table = NULL;
100089 struct ctl_table_header *hdr;
100090
100091- table = xfrm6_policy_table;
100092 if (!net_eq(net, &init_net)) {
100093- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100094+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100095 if (!table)
100096 goto err_alloc;
100097
100098 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100099- }
100100+ hdr = register_net_sysctl(net, "net/ipv6", table);
100101+ } else
100102+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100103
100104- hdr = register_net_sysctl(net, "net/ipv6", table);
100105 if (!hdr)
100106 goto err_reg;
100107
100108@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100109 return 0;
100110
100111 err_reg:
100112- if (!net_eq(net, &init_net))
100113- kfree(table);
100114+ kfree(table);
100115 err_alloc:
100116 return -ENOMEM;
100117 }
100118diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100119index e15c16a..7cf07aa 100644
100120--- a/net/ipx/ipx_proc.c
100121+++ b/net/ipx/ipx_proc.c
100122@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100123 struct proc_dir_entry *p;
100124 int rc = -ENOMEM;
100125
100126- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100127+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100128
100129 if (!ipx_proc_dir)
100130 goto out;
100131diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100132index 2ba8b97..6d33010 100644
100133--- a/net/irda/ircomm/ircomm_tty.c
100134+++ b/net/irda/ircomm/ircomm_tty.c
100135@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100136 add_wait_queue(&port->open_wait, &wait);
100137
100138 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100139- __FILE__, __LINE__, tty->driver->name, port->count);
100140+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100141
100142 spin_lock_irqsave(&port->lock, flags);
100143 if (!tty_hung_up_p(filp))
100144- port->count--;
100145+ atomic_dec(&port->count);
100146 port->blocked_open++;
100147 spin_unlock_irqrestore(&port->lock, flags);
100148
100149@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100150 }
100151
100152 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100153- __FILE__, __LINE__, tty->driver->name, port->count);
100154+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100155
100156 schedule();
100157 }
100158@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100159
100160 spin_lock_irqsave(&port->lock, flags);
100161 if (!tty_hung_up_p(filp))
100162- port->count++;
100163+ atomic_inc(&port->count);
100164 port->blocked_open--;
100165 spin_unlock_irqrestore(&port->lock, flags);
100166
100167 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100168- __FILE__, __LINE__, tty->driver->name, port->count);
100169+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100170
100171 if (!retval)
100172 port->flags |= ASYNC_NORMAL_ACTIVE;
100173@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100174
100175 /* ++ is not atomic, so this should be protected - Jean II */
100176 spin_lock_irqsave(&self->port.lock, flags);
100177- self->port.count++;
100178+ atomic_inc(&self->port.count);
100179 spin_unlock_irqrestore(&self->port.lock, flags);
100180 tty_port_tty_set(&self->port, tty);
100181
100182 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100183- self->line, self->port.count);
100184+ self->line, atomic_read(&self->port.count));
100185
100186 /* Not really used by us, but lets do it anyway */
100187 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100188@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100189 tty_kref_put(port->tty);
100190 }
100191 port->tty = NULL;
100192- port->count = 0;
100193+ atomic_set(&port->count, 0);
100194 spin_unlock_irqrestore(&port->lock, flags);
100195
100196 wake_up_interruptible(&port->open_wait);
100197@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100198 seq_putc(m, '\n');
100199
100200 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100201- seq_printf(m, "Open count: %d\n", self->port.count);
100202+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100203 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100204 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100205
100206diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100207index b9ac598..f88cc56 100644
100208--- a/net/irda/irproc.c
100209+++ b/net/irda/irproc.c
100210@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100211 {
100212 int i;
100213
100214- proc_irda = proc_mkdir("irda", init_net.proc_net);
100215+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100216 if (proc_irda == NULL)
100217 return;
100218
100219diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100220index c4b7218..3e83259 100644
100221--- a/net/iucv/af_iucv.c
100222+++ b/net/iucv/af_iucv.c
100223@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100224
100225 write_lock_bh(&iucv_sk_list.lock);
100226
100227- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100228+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100229 while (__iucv_get_sock_by_name(name)) {
100230 sprintf(name, "%08x",
100231- atomic_inc_return(&iucv_sk_list.autobind_name));
100232+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100233 }
100234
100235 write_unlock_bh(&iucv_sk_list.lock);
100236diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100237index cd5b8ec..f205e6b 100644
100238--- a/net/iucv/iucv.c
100239+++ b/net/iucv/iucv.c
100240@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100241 return NOTIFY_OK;
100242 }
100243
100244-static struct notifier_block __refdata iucv_cpu_notifier = {
100245+static struct notifier_block iucv_cpu_notifier = {
100246 .notifier_call = iucv_cpu_notify,
100247 };
100248
100249diff --git a/net/key/af_key.c b/net/key/af_key.c
100250index 7932697..a13d158 100644
100251--- a/net/key/af_key.c
100252+++ b/net/key/af_key.c
100253@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100254 static u32 get_acqseq(void)
100255 {
100256 u32 res;
100257- static atomic_t acqseq;
100258+ static atomic_unchecked_t acqseq;
100259
100260 do {
100261- res = atomic_inc_return(&acqseq);
100262+ res = atomic_inc_return_unchecked(&acqseq);
100263 } while (!res);
100264 return res;
100265 }
100266diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100267index 0b44d85..1a7f88b 100644
100268--- a/net/l2tp/l2tp_ip.c
100269+++ b/net/l2tp/l2tp_ip.c
100270@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100271 if (flags & MSG_OOB)
100272 goto out;
100273
100274+ if (addr_len)
100275+ *addr_len = sizeof(*sin);
100276+
100277 skb = skb_recv_datagram(sk, flags, noblock, &err);
100278 if (!skb)
100279 goto out;
100280@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100281 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100282 sin->sin_port = 0;
100283 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100284- *addr_len = sizeof(*sin);
100285 }
100286 if (inet->cmsg_flags)
100287 ip_cmsg_recv(msg, skb);
100288diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100289index 1a3c7e0..80f8b0c 100644
100290--- a/net/llc/llc_proc.c
100291+++ b/net/llc/llc_proc.c
100292@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100293 int rc = -ENOMEM;
100294 struct proc_dir_entry *p;
100295
100296- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100297+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100298 if (!llc_proc_dir)
100299 goto out;
100300
100301diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100302index 453e974..b3a43a5 100644
100303--- a/net/mac80211/cfg.c
100304+++ b/net/mac80211/cfg.c
100305@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100306 ret = ieee80211_vif_use_channel(sdata, chandef,
100307 IEEE80211_CHANCTX_EXCLUSIVE);
100308 }
100309- } else if (local->open_count == local->monitors) {
100310+ } else if (local_read(&local->open_count) == local->monitors) {
100311 local->_oper_chandef = *chandef;
100312 ieee80211_hw_config(local, 0);
100313 }
100314@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100315 else
100316 local->probe_req_reg--;
100317
100318- if (!local->open_count)
100319+ if (!local_read(&local->open_count))
100320 break;
100321
100322 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100323@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100324 if (chanctx_conf) {
100325 *chandef = chanctx_conf->def;
100326 ret = 0;
100327- } else if (local->open_count > 0 &&
100328- local->open_count == local->monitors &&
100329+ } else if (local_read(&local->open_count) > 0 &&
100330+ local_read(&local->open_count) == local->monitors &&
100331 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100332 if (local->use_chanctx)
100333 *chandef = local->monitor_chandef;
100334diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100335index 5e44e317..3d404a6 100644
100336--- a/net/mac80211/ieee80211_i.h
100337+++ b/net/mac80211/ieee80211_i.h
100338@@ -28,6 +28,7 @@
100339 #include <net/ieee80211_radiotap.h>
100340 #include <net/cfg80211.h>
100341 #include <net/mac80211.h>
100342+#include <asm/local.h>
100343 #include "key.h"
100344 #include "sta_info.h"
100345 #include "debug.h"
100346@@ -994,7 +995,7 @@ struct ieee80211_local {
100347 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100348 spinlock_t queue_stop_reason_lock;
100349
100350- int open_count;
100351+ local_t open_count;
100352 int monitors, cooked_mntrs;
100353 /* number of interfaces with corresponding FIF_ flags */
100354 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100355diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100356index ce1c443..6cd39e1 100644
100357--- a/net/mac80211/iface.c
100358+++ b/net/mac80211/iface.c
100359@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100360 break;
100361 }
100362
100363- if (local->open_count == 0) {
100364+ if (local_read(&local->open_count) == 0) {
100365 res = drv_start(local);
100366 if (res)
100367 goto err_del_bss;
100368@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100369 res = drv_add_interface(local, sdata);
100370 if (res)
100371 goto err_stop;
100372- } else if (local->monitors == 0 && local->open_count == 0) {
100373+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100374 res = ieee80211_add_virtual_monitor(local);
100375 if (res)
100376 goto err_stop;
100377@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100378 atomic_inc(&local->iff_promiscs);
100379
100380 if (coming_up)
100381- local->open_count++;
100382+ local_inc(&local->open_count);
100383
100384 if (hw_reconf_flags)
100385 ieee80211_hw_config(local, hw_reconf_flags);
100386@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100387 err_del_interface:
100388 drv_remove_interface(local, sdata);
100389 err_stop:
100390- if (!local->open_count)
100391+ if (!local_read(&local->open_count))
100392 drv_stop(local);
100393 err_del_bss:
100394 sdata->bss = NULL;
100395@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100396 }
100397
100398 if (going_down)
100399- local->open_count--;
100400+ local_dec(&local->open_count);
100401
100402 switch (sdata->vif.type) {
100403 case NL80211_IFTYPE_AP_VLAN:
100404@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100405 }
100406 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100407
100408- if (local->open_count == 0)
100409+ if (local_read(&local->open_count) == 0)
100410 ieee80211_clear_tx_pending(local);
100411
100412 /*
100413@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100414
100415 ieee80211_recalc_ps(local, -1);
100416
100417- if (local->open_count == 0) {
100418+ if (local_read(&local->open_count) == 0) {
100419 ieee80211_stop_device(local);
100420
100421 /* no reconfiguring after stop! */
100422@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100423 ieee80211_configure_filter(local);
100424 ieee80211_hw_config(local, hw_reconf_flags);
100425
100426- if (local->monitors == local->open_count)
100427+ if (local->monitors == local_read(&local->open_count))
100428 ieee80211_add_virtual_monitor(local);
100429 }
100430
100431diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100432index d767cfb..b4cd07d 100644
100433--- a/net/mac80211/main.c
100434+++ b/net/mac80211/main.c
100435@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100436 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100437 IEEE80211_CONF_CHANGE_POWER);
100438
100439- if (changed && local->open_count) {
100440+ if (changed && local_read(&local->open_count)) {
100441 ret = drv_config(local, changed);
100442 /*
100443 * Goal:
100444diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
100445index af64fb8..366e371 100644
100446--- a/net/mac80211/pm.c
100447+++ b/net/mac80211/pm.c
100448@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100449 struct ieee80211_sub_if_data *sdata;
100450 struct sta_info *sta;
100451
100452- if (!local->open_count)
100453+ if (!local_read(&local->open_count))
100454 goto suspend;
100455
100456 ieee80211_scan_cancel(local);
100457@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100458 cancel_work_sync(&local->dynamic_ps_enable_work);
100459 del_timer_sync(&local->dynamic_ps_timer);
100460
100461- local->wowlan = wowlan && local->open_count;
100462+ local->wowlan = wowlan && local_read(&local->open_count);
100463 if (local->wowlan) {
100464 int err = drv_suspend(local, wowlan);
100465 if (err < 0) {
100466@@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100467 WARN_ON(!list_empty(&local->chanctx_list));
100468
100469 /* stop hardware - this must stop RX */
100470- if (local->open_count)
100471+ if (local_read(&local->open_count))
100472 ieee80211_stop_device(local);
100473
100474 suspend:
100475diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
100476index 22b223f..ab70070 100644
100477--- a/net/mac80211/rate.c
100478+++ b/net/mac80211/rate.c
100479@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
100480
100481 ASSERT_RTNL();
100482
100483- if (local->open_count)
100484+ if (local_read(&local->open_count))
100485 return -EBUSY;
100486
100487 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
100488diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
100489index 6ff1346..936ca9a 100644
100490--- a/net/mac80211/rc80211_pid_debugfs.c
100491+++ b/net/mac80211/rc80211_pid_debugfs.c
100492@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
100493
100494 spin_unlock_irqrestore(&events->lock, status);
100495
100496- if (copy_to_user(buf, pb, p))
100497+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
100498 return -EFAULT;
100499
100500 return p;
100501diff --git a/net/mac80211/util.c b/net/mac80211/util.c
100502index b8700d4..89086d5 100644
100503--- a/net/mac80211/util.c
100504+++ b/net/mac80211/util.c
100505@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100506 }
100507 #endif
100508 /* everything else happens only if HW was up & running */
100509- if (!local->open_count)
100510+ if (!local_read(&local->open_count))
100511 goto wake_up;
100512
100513 /*
100514@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100515 local->in_reconfig = false;
100516 barrier();
100517
100518- if (local->monitors == local->open_count && local->monitors > 0)
100519+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
100520 ieee80211_add_virtual_monitor(local);
100521
100522 /*
100523diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100524index e9410d1..77b6378 100644
100525--- a/net/netfilter/Kconfig
100526+++ b/net/netfilter/Kconfig
100527@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
100528
100529 To compile it as a module, choose M here. If unsure, say N.
100530
100531+config NETFILTER_XT_MATCH_GRADM
100532+ tristate '"gradm" match support'
100533+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100534+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100535+ ---help---
100536+ The gradm match allows to match on grsecurity RBAC being enabled.
100537+ It is useful when iptables rules are applied early on bootup to
100538+ prevent connections to the machine (except from a trusted host)
100539+ while the RBAC system is disabled.
100540+
100541 config NETFILTER_XT_MATCH_HASHLIMIT
100542 tristate '"hashlimit" match support'
100543 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100544diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100545index bffdad7..f9317d1 100644
100546--- a/net/netfilter/Makefile
100547+++ b/net/netfilter/Makefile
100548@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100549 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100550 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100551 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100552+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100553 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100554 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100555 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100556diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100557index de770ec..3fc49d2 100644
100558--- a/net/netfilter/ipset/ip_set_core.c
100559+++ b/net/netfilter/ipset/ip_set_core.c
100560@@ -1922,7 +1922,7 @@ done:
100561 return ret;
100562 }
100563
100564-static struct nf_sockopt_ops so_set __read_mostly = {
100565+static struct nf_sockopt_ops so_set = {
100566 .pf = PF_INET,
100567 .get_optmin = SO_IP_SET,
100568 .get_optmax = SO_IP_SET + 1,
100569diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100570index a8eb0a8..86f2de4 100644
100571--- a/net/netfilter/ipvs/ip_vs_conn.c
100572+++ b/net/netfilter/ipvs/ip_vs_conn.c
100573@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100574 /* Increase the refcnt counter of the dest */
100575 ip_vs_dest_hold(dest);
100576
100577- conn_flags = atomic_read(&dest->conn_flags);
100578+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
100579 if (cp->protocol != IPPROTO_UDP)
100580 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100581 flags = cp->flags;
100582@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100583
100584 cp->control = NULL;
100585 atomic_set(&cp->n_control, 0);
100586- atomic_set(&cp->in_pkts, 0);
100587+ atomic_set_unchecked(&cp->in_pkts, 0);
100588
100589 cp->packet_xmit = NULL;
100590 cp->app = NULL;
100591@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100592
100593 /* Don't drop the entry if its number of incoming packets is not
100594 located in [0, 8] */
100595- i = atomic_read(&cp->in_pkts);
100596+ i = atomic_read_unchecked(&cp->in_pkts);
100597 if (i > 8 || i < 0) return 0;
100598
100599 if (!todrop_rate[i]) return 0;
100600diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100601index 4f26ee4..6a9d7c3 100644
100602--- a/net/netfilter/ipvs/ip_vs_core.c
100603+++ b/net/netfilter/ipvs/ip_vs_core.c
100604@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100605 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100606 /* do not touch skb anymore */
100607
100608- atomic_inc(&cp->in_pkts);
100609+ atomic_inc_unchecked(&cp->in_pkts);
100610 ip_vs_conn_put(cp);
100611 return ret;
100612 }
100613@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100614 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100615 pkts = sysctl_sync_threshold(ipvs);
100616 else
100617- pkts = atomic_add_return(1, &cp->in_pkts);
100618+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100619
100620 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100621 ip_vs_sync_conn(net, cp, pkts);
100622diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100623index 35be035..50f8834 100644
100624--- a/net/netfilter/ipvs/ip_vs_ctl.c
100625+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100626@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100627 */
100628 ip_vs_rs_hash(ipvs, dest);
100629 }
100630- atomic_set(&dest->conn_flags, conn_flags);
100631+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100632
100633 /* bind the service */
100634 old_svc = rcu_dereference_protected(dest->svc, 1);
100635@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100636 * align with netns init in ip_vs_control_net_init()
100637 */
100638
100639-static struct ctl_table vs_vars[] = {
100640+static ctl_table_no_const vs_vars[] __read_only = {
100641 {
100642 .procname = "amemthresh",
100643 .maxlen = sizeof(int),
100644@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100645 " %-7s %-6d %-10d %-10d\n",
100646 &dest->addr.in6,
100647 ntohs(dest->port),
100648- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100649+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100650 atomic_read(&dest->weight),
100651 atomic_read(&dest->activeconns),
100652 atomic_read(&dest->inactconns));
100653@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100654 "%-7s %-6d %-10d %-10d\n",
100655 ntohl(dest->addr.ip),
100656 ntohs(dest->port),
100657- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100658+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100659 atomic_read(&dest->weight),
100660 atomic_read(&dest->activeconns),
100661 atomic_read(&dest->inactconns));
100662@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100663
100664 entry.addr = dest->addr.ip;
100665 entry.port = dest->port;
100666- entry.conn_flags = atomic_read(&dest->conn_flags);
100667+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100668 entry.weight = atomic_read(&dest->weight);
100669 entry.u_threshold = dest->u_threshold;
100670 entry.l_threshold = dest->l_threshold;
100671@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100672 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100673 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100674 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100675- (atomic_read(&dest->conn_flags) &
100676+ (atomic_read_unchecked(&dest->conn_flags) &
100677 IP_VS_CONN_F_FWD_MASK)) ||
100678 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100679 atomic_read(&dest->weight)) ||
100680@@ -3580,7 +3580,7 @@ out:
100681 }
100682
100683
100684-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100685+static const struct genl_ops ip_vs_genl_ops[] = {
100686 {
100687 .cmd = IPVS_CMD_NEW_SERVICE,
100688 .flags = GENL_ADMIN_PERM,
100689@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100690 {
100691 int idx;
100692 struct netns_ipvs *ipvs = net_ipvs(net);
100693- struct ctl_table *tbl;
100694+ ctl_table_no_const *tbl;
100695
100696 atomic_set(&ipvs->dropentry, 0);
100697 spin_lock_init(&ipvs->dropentry_lock);
100698diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100699index ca056a3..9cf01ef 100644
100700--- a/net/netfilter/ipvs/ip_vs_lblc.c
100701+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100702@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100703 * IPVS LBLC sysctl table
100704 */
100705 #ifdef CONFIG_SYSCTL
100706-static struct ctl_table vs_vars_table[] = {
100707+static ctl_table_no_const vs_vars_table[] __read_only = {
100708 {
100709 .procname = "lblc_expiration",
100710 .data = NULL,
100711diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100712index 3f21a2f..a112e85 100644
100713--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100714+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100715@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100716 * IPVS LBLCR sysctl table
100717 */
100718
100719-static struct ctl_table vs_vars_table[] = {
100720+static ctl_table_no_const vs_vars_table[] __read_only = {
100721 {
100722 .procname = "lblcr_expiration",
100723 .data = NULL,
100724diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100725index db80126..ef7110e 100644
100726--- a/net/netfilter/ipvs/ip_vs_sync.c
100727+++ b/net/netfilter/ipvs/ip_vs_sync.c
100728@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100729 cp = cp->control;
100730 if (cp) {
100731 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100732- pkts = atomic_add_return(1, &cp->in_pkts);
100733+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100734 else
100735 pkts = sysctl_sync_threshold(ipvs);
100736 ip_vs_sync_conn(net, cp->control, pkts);
100737@@ -771,7 +771,7 @@ control:
100738 if (!cp)
100739 return;
100740 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100741- pkts = atomic_add_return(1, &cp->in_pkts);
100742+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100743 else
100744 pkts = sysctl_sync_threshold(ipvs);
100745 goto sloop;
100746@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100747
100748 if (opt)
100749 memcpy(&cp->in_seq, opt, sizeof(*opt));
100750- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100751+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100752 cp->state = state;
100753 cp->old_state = cp->state;
100754 /*
100755diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100756index c47444e..b0961c6 100644
100757--- a/net/netfilter/ipvs/ip_vs_xmit.c
100758+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100759@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100760 else
100761 rc = NF_ACCEPT;
100762 /* do not touch skb anymore */
100763- atomic_inc(&cp->in_pkts);
100764+ atomic_inc_unchecked(&cp->in_pkts);
100765 goto out;
100766 }
100767
100768@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100769 else
100770 rc = NF_ACCEPT;
100771 /* do not touch skb anymore */
100772- atomic_inc(&cp->in_pkts);
100773+ atomic_inc_unchecked(&cp->in_pkts);
100774 goto out;
100775 }
100776
100777diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100778index a4b5e2a..13b1de3 100644
100779--- a/net/netfilter/nf_conntrack_acct.c
100780+++ b/net/netfilter/nf_conntrack_acct.c
100781@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100782 #ifdef CONFIG_SYSCTL
100783 static int nf_conntrack_acct_init_sysctl(struct net *net)
100784 {
100785- struct ctl_table *table;
100786+ ctl_table_no_const *table;
100787
100788 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100789 GFP_KERNEL);
100790diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100791index 356bef5..99932cb 100644
100792--- a/net/netfilter/nf_conntrack_core.c
100793+++ b/net/netfilter/nf_conntrack_core.c
100794@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
100795 #define DYING_NULLS_VAL ((1<<30)+1)
100796 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100797
100798+#ifdef CONFIG_GRKERNSEC_HIDESYM
100799+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100800+#endif
100801+
100802 int nf_conntrack_init_net(struct net *net)
100803 {
100804 int ret;
100805@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
100806 goto err_stat;
100807 }
100808
100809+#ifdef CONFIG_GRKERNSEC_HIDESYM
100810+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100811+#else
100812 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100813+#endif
100814 if (!net->ct.slabname) {
100815 ret = -ENOMEM;
100816 goto err_slabname;
100817diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100818index 1df1761..ce8b88a 100644
100819--- a/net/netfilter/nf_conntrack_ecache.c
100820+++ b/net/netfilter/nf_conntrack_ecache.c
100821@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100822 #ifdef CONFIG_SYSCTL
100823 static int nf_conntrack_event_init_sysctl(struct net *net)
100824 {
100825- struct ctl_table *table;
100826+ ctl_table_no_const *table;
100827
100828 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100829 GFP_KERNEL);
100830diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100831index 974a2a4..52cc6ff 100644
100832--- a/net/netfilter/nf_conntrack_helper.c
100833+++ b/net/netfilter/nf_conntrack_helper.c
100834@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100835
100836 static int nf_conntrack_helper_init_sysctl(struct net *net)
100837 {
100838- struct ctl_table *table;
100839+ ctl_table_no_const *table;
100840
100841 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100842 GFP_KERNEL);
100843diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100844index b65d586..beec902 100644
100845--- a/net/netfilter/nf_conntrack_proto.c
100846+++ b/net/netfilter/nf_conntrack_proto.c
100847@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100848
100849 static void
100850 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100851- struct ctl_table **table,
100852+ ctl_table_no_const **table,
100853 unsigned int users)
100854 {
100855 if (users > 0)
100856diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100857index f641751..d3c5b51 100644
100858--- a/net/netfilter/nf_conntrack_standalone.c
100859+++ b/net/netfilter/nf_conntrack_standalone.c
100860@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100861
100862 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100863 {
100864- struct ctl_table *table;
100865+ ctl_table_no_const *table;
100866
100867 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100868 GFP_KERNEL);
100869diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100870index 7a394df..bd91a8a 100644
100871--- a/net/netfilter/nf_conntrack_timestamp.c
100872+++ b/net/netfilter/nf_conntrack_timestamp.c
100873@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100874 #ifdef CONFIG_SYSCTL
100875 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100876 {
100877- struct ctl_table *table;
100878+ ctl_table_no_const *table;
100879
100880 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100881 GFP_KERNEL);
100882diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100883index 85296d4..8becdec 100644
100884--- a/net/netfilter/nf_log.c
100885+++ b/net/netfilter/nf_log.c
100886@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100887
100888 #ifdef CONFIG_SYSCTL
100889 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100890-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100891+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100892
100893 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100894 void __user *buffer, size_t *lenp, loff_t *ppos)
100895@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100896 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100897 mutex_unlock(&nf_log_mutex);
100898 } else {
100899+ ctl_table_no_const nf_log_table = *table;
100900+
100901 mutex_lock(&nf_log_mutex);
100902 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100903 lockdep_is_held(&nf_log_mutex));
100904 if (!logger)
100905- table->data = "NONE";
100906+ nf_log_table.data = "NONE";
100907 else
100908- table->data = logger->name;
100909- r = proc_dostring(table, write, buffer, lenp, ppos);
100910+ nf_log_table.data = logger->name;
100911+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100912 mutex_unlock(&nf_log_mutex);
100913 }
100914
100915diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100916index f042ae5..30ea486 100644
100917--- a/net/netfilter/nf_sockopt.c
100918+++ b/net/netfilter/nf_sockopt.c
100919@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100920 }
100921 }
100922
100923- list_add(&reg->list, &nf_sockopts);
100924+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100925 out:
100926 mutex_unlock(&nf_sockopt_mutex);
100927 return ret;
100928@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100929 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100930 {
100931 mutex_lock(&nf_sockopt_mutex);
100932- list_del(&reg->list);
100933+ pax_list_del((struct list_head *)&reg->list);
100934 mutex_unlock(&nf_sockopt_mutex);
100935 }
100936 EXPORT_SYMBOL(nf_unregister_sockopt);
100937diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100938index adce01e..8d52d50 100644
100939--- a/net/netfilter/nf_tables_api.c
100940+++ b/net/netfilter/nf_tables_api.c
100941@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100942 #ifdef CONFIG_MODULES
100943 if (autoload) {
100944 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100945- request_module("nft-chain-%u-%*.s", afi->family,
100946- nla_len(nla)-1, (const char *)nla_data(nla));
100947+ request_module("nft-chain-%u-%.*s", afi->family,
100948+ nla_len(nla), (const char *)nla_data(nla));
100949 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100950 type = __nf_tables_chain_type_lookup(afi->family, nla);
100951 if (type != NULL)
100952@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100953
100954 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100955 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100956- [NFTA_SET_NAME] = { .type = NLA_STRING },
100957+ [NFTA_SET_NAME] = { .type = NLA_STRING,
100958+ .len = IFNAMSIZ - 1 },
100959 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100960 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100961 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100962diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100963index a155d19..726b0f2 100644
100964--- a/net/netfilter/nfnetlink_log.c
100965+++ b/net/netfilter/nfnetlink_log.c
100966@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100967 struct nfnl_log_net {
100968 spinlock_t instances_lock;
100969 struct hlist_head instance_table[INSTANCE_BUCKETS];
100970- atomic_t global_seq;
100971+ atomic_unchecked_t global_seq;
100972 };
100973
100974 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100975@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100976 /* global sequence number */
100977 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100978 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100979- htonl(atomic_inc_return(&log->global_seq))))
100980+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
100981 goto nla_put_failure;
100982
100983 if (data_len) {
100984diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100985index 82cb823..5685dd5 100644
100986--- a/net/netfilter/nft_compat.c
100987+++ b/net/netfilter/nft_compat.c
100988@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100989 /* We want to reuse existing compat_to_user */
100990 old_fs = get_fs();
100991 set_fs(KERNEL_DS);
100992- t->compat_to_user(out, in);
100993+ t->compat_to_user((void __force_user *)out, in);
100994 set_fs(old_fs);
100995 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100996 kfree(out);
100997@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100998 /* We want to reuse existing compat_to_user */
100999 old_fs = get_fs();
101000 set_fs(KERNEL_DS);
101001- m->compat_to_user(out, in);
101002+ m->compat_to_user((void __force_user *)out, in);
101003 set_fs(old_fs);
101004 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101005 kfree(out);
101006diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101007new file mode 100644
101008index 0000000..c566332
101009--- /dev/null
101010+++ b/net/netfilter/xt_gradm.c
101011@@ -0,0 +1,51 @@
101012+/*
101013+ * gradm match for netfilter
101014