]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/3.14.3/grsecurity-3.0-3.14.3-201405092337.patch
Auto commit, grsecurity-3.1-4.9.16-201703180820.patch added.
[thirdparty/grsecurity-scrape.git] / test / 3.14.3 / grsecurity-3.0-3.14.3-201405092337.patch
CommitLineData
076e2b2e
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/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7491index 8b06343..090483c 100644
7492--- a/arch/parisc/include/uapi/asm/resource.h
7493+++ b/arch/parisc/include/uapi/asm/resource.h
7494@@ -1,7 +1,6 @@
7495 #ifndef _ASM_PARISC_RESOURCE_H
7496 #define _ASM_PARISC_RESOURCE_H
7497
7498-#define _STK_LIM_MAX 10 * _STK_LIM
7499 #include <asm-generic/resource.h>
7500
7501 #endif
7502diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7503index 50dfafc..b9fc230 100644
7504--- a/arch/parisc/kernel/module.c
7505+++ b/arch/parisc/kernel/module.c
7506@@ -98,16 +98,38 @@
7507
7508 /* three functions to determine where in the module core
7509 * or init pieces the location is */
7510+static inline int in_init_rx(struct module *me, void *loc)
7511+{
7512+ return (loc >= me->module_init_rx &&
7513+ loc < (me->module_init_rx + me->init_size_rx));
7514+}
7515+
7516+static inline int in_init_rw(struct module *me, void *loc)
7517+{
7518+ return (loc >= me->module_init_rw &&
7519+ loc < (me->module_init_rw + me->init_size_rw));
7520+}
7521+
7522 static inline int in_init(struct module *me, void *loc)
7523 {
7524- return (loc >= me->module_init &&
7525- loc <= (me->module_init + me->init_size));
7526+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7527+}
7528+
7529+static inline int in_core_rx(struct module *me, void *loc)
7530+{
7531+ return (loc >= me->module_core_rx &&
7532+ loc < (me->module_core_rx + me->core_size_rx));
7533+}
7534+
7535+static inline int in_core_rw(struct module *me, void *loc)
7536+{
7537+ return (loc >= me->module_core_rw &&
7538+ loc < (me->module_core_rw + me->core_size_rw));
7539 }
7540
7541 static inline int in_core(struct module *me, void *loc)
7542 {
7543- return (loc >= me->module_core &&
7544- loc <= (me->module_core + me->core_size));
7545+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7546 }
7547
7548 static inline int in_local(struct module *me, void *loc)
7549@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7550 }
7551
7552 /* align things a bit */
7553- me->core_size = ALIGN(me->core_size, 16);
7554- me->arch.got_offset = me->core_size;
7555- me->core_size += gots * sizeof(struct got_entry);
7556+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7557+ me->arch.got_offset = me->core_size_rw;
7558+ me->core_size_rw += gots * sizeof(struct got_entry);
7559
7560- me->core_size = ALIGN(me->core_size, 16);
7561- me->arch.fdesc_offset = me->core_size;
7562- me->core_size += fdescs * sizeof(Elf_Fdesc);
7563+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7564+ me->arch.fdesc_offset = me->core_size_rw;
7565+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7566
7567 me->arch.got_max = gots;
7568 me->arch.fdesc_max = fdescs;
7569@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7570
7571 BUG_ON(value == 0);
7572
7573- got = me->module_core + me->arch.got_offset;
7574+ got = me->module_core_rw + me->arch.got_offset;
7575 for (i = 0; got[i].addr; i++)
7576 if (got[i].addr == value)
7577 goto out;
7578@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7579 #ifdef CONFIG_64BIT
7580 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7581 {
7582- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7583+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7584
7585 if (!value) {
7586 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7587@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7588
7589 /* Create new one */
7590 fdesc->addr = value;
7591- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7592+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7593 return (Elf_Addr)fdesc;
7594 }
7595 #endif /* CONFIG_64BIT */
7596@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7597
7598 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7599 end = table + sechdrs[me->arch.unwind_section].sh_size;
7600- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7601+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7602
7603 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7604 me->arch.unwind_section, table, end, gp);
7605diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7606index b7cadc4..bf4a32d 100644
7607--- a/arch/parisc/kernel/sys_parisc.c
7608+++ b/arch/parisc/kernel/sys_parisc.c
7609@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7610 unsigned long task_size = TASK_SIZE;
7611 int do_color_align, last_mmap;
7612 struct vm_unmapped_area_info info;
7613+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7614
7615 if (len > task_size)
7616 return -ENOMEM;
7617@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7618 goto found_addr;
7619 }
7620
7621+#ifdef CONFIG_PAX_RANDMMAP
7622+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7623+#endif
7624+
7625 if (addr) {
7626 if (do_color_align && last_mmap)
7627 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7628@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7629 info.high_limit = mmap_upper_limit();
7630 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7631 info.align_offset = shared_align_offset(last_mmap, pgoff);
7632+ info.threadstack_offset = offset;
7633 addr = vm_unmapped_area(&info);
7634
7635 found_addr:
7636@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7637 unsigned long addr = addr0;
7638 int do_color_align, last_mmap;
7639 struct vm_unmapped_area_info info;
7640+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7641
7642 #ifdef CONFIG_64BIT
7643 /* This should only ever run for 32-bit processes. */
7644@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7645 }
7646
7647 /* requesting a specific address */
7648+#ifdef CONFIG_PAX_RANDMMAP
7649+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7650+#endif
7651+
7652 if (addr) {
7653 if (do_color_align && last_mmap)
7654 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7655@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 info.high_limit = mm->mmap_base;
7657 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7658 info.align_offset = shared_align_offset(last_mmap, pgoff);
7659+ info.threadstack_offset = offset;
7660 addr = vm_unmapped_area(&info);
7661 if (!(addr & ~PAGE_MASK))
7662 goto found_addr;
7663@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7664 mm->mmap_legacy_base = mmap_legacy_base();
7665 mm->mmap_base = mmap_upper_limit();
7666
7667+#ifdef CONFIG_PAX_RANDMMAP
7668+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7669+ mm->mmap_legacy_base += mm->delta_mmap;
7670+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7671+ }
7672+#endif
7673+
7674 if (mmap_is_legacy()) {
7675 mm->mmap_base = mm->mmap_legacy_base;
7676 mm->get_unmapped_area = arch_get_unmapped_area;
7677diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7678index 1cd1d0c..44ec918 100644
7679--- a/arch/parisc/kernel/traps.c
7680+++ b/arch/parisc/kernel/traps.c
7681@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7682
7683 down_read(&current->mm->mmap_sem);
7684 vma = find_vma(current->mm,regs->iaoq[0]);
7685- if (vma && (regs->iaoq[0] >= vma->vm_start)
7686- && (vma->vm_flags & VM_EXEC)) {
7687-
7688+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7689 fault_address = regs->iaoq[0];
7690 fault_space = regs->iasq[0];
7691
7692diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7693index 9d08c71..e2b4d20 100644
7694--- a/arch/parisc/mm/fault.c
7695+++ b/arch/parisc/mm/fault.c
7696@@ -15,6 +15,7 @@
7697 #include <linux/sched.h>
7698 #include <linux/interrupt.h>
7699 #include <linux/module.h>
7700+#include <linux/unistd.h>
7701
7702 #include <asm/uaccess.h>
7703 #include <asm/traps.h>
7704@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7705 static unsigned long
7706 parisc_acctyp(unsigned long code, unsigned int inst)
7707 {
7708- if (code == 6 || code == 16)
7709+ if (code == 6 || code == 7 || code == 16)
7710 return VM_EXEC;
7711
7712 switch (inst & 0xf0000000) {
7713@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7714 }
7715 #endif
7716
7717+#ifdef CONFIG_PAX_PAGEEXEC
7718+/*
7719+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7720+ *
7721+ * returns 1 when task should be killed
7722+ * 2 when rt_sigreturn trampoline was detected
7723+ * 3 when unpatched PLT trampoline was detected
7724+ */
7725+static int pax_handle_fetch_fault(struct pt_regs *regs)
7726+{
7727+
7728+#ifdef CONFIG_PAX_EMUPLT
7729+ int err;
7730+
7731+ do { /* PaX: unpatched PLT emulation */
7732+ unsigned int bl, depwi;
7733+
7734+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7735+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7736+
7737+ if (err)
7738+ break;
7739+
7740+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7741+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7742+
7743+ err = get_user(ldw, (unsigned int *)addr);
7744+ err |= get_user(bv, (unsigned int *)(addr+4));
7745+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7746+
7747+ if (err)
7748+ break;
7749+
7750+ if (ldw == 0x0E801096U &&
7751+ bv == 0xEAC0C000U &&
7752+ ldw2 == 0x0E881095U)
7753+ {
7754+ unsigned int resolver, map;
7755+
7756+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7757+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7758+ if (err)
7759+ break;
7760+
7761+ regs->gr[20] = instruction_pointer(regs)+8;
7762+ regs->gr[21] = map;
7763+ regs->gr[22] = resolver;
7764+ regs->iaoq[0] = resolver | 3UL;
7765+ regs->iaoq[1] = regs->iaoq[0] + 4;
7766+ return 3;
7767+ }
7768+ }
7769+ } while (0);
7770+#endif
7771+
7772+#ifdef CONFIG_PAX_EMUTRAMP
7773+
7774+#ifndef CONFIG_PAX_EMUSIGRT
7775+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7776+ return 1;
7777+#endif
7778+
7779+ do { /* PaX: rt_sigreturn emulation */
7780+ unsigned int ldi1, ldi2, bel, nop;
7781+
7782+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7783+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7784+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7785+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7786+
7787+ if (err)
7788+ break;
7789+
7790+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7791+ ldi2 == 0x3414015AU &&
7792+ bel == 0xE4008200U &&
7793+ nop == 0x08000240U)
7794+ {
7795+ regs->gr[25] = (ldi1 & 2) >> 1;
7796+ regs->gr[20] = __NR_rt_sigreturn;
7797+ regs->gr[31] = regs->iaoq[1] + 16;
7798+ regs->sr[0] = regs->iasq[1];
7799+ regs->iaoq[0] = 0x100UL;
7800+ regs->iaoq[1] = regs->iaoq[0] + 4;
7801+ regs->iasq[0] = regs->sr[2];
7802+ regs->iasq[1] = regs->sr[2];
7803+ return 2;
7804+ }
7805+ } while (0);
7806+#endif
7807+
7808+ return 1;
7809+}
7810+
7811+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7812+{
7813+ unsigned long i;
7814+
7815+ printk(KERN_ERR "PAX: bytes at PC: ");
7816+ for (i = 0; i < 5; i++) {
7817+ unsigned int c;
7818+ if (get_user(c, (unsigned int *)pc+i))
7819+ printk(KERN_CONT "???????? ");
7820+ else
7821+ printk(KERN_CONT "%08x ", c);
7822+ }
7823+ printk("\n");
7824+}
7825+#endif
7826+
7827 int fixup_exception(struct pt_regs *regs)
7828 {
7829 const struct exception_table_entry *fix;
7830@@ -210,8 +321,33 @@ retry:
7831
7832 good_area:
7833
7834- if ((vma->vm_flags & acc_type) != acc_type)
7835+ if ((vma->vm_flags & acc_type) != acc_type) {
7836+
7837+#ifdef CONFIG_PAX_PAGEEXEC
7838+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7839+ (address & ~3UL) == instruction_pointer(regs))
7840+ {
7841+ up_read(&mm->mmap_sem);
7842+ switch (pax_handle_fetch_fault(regs)) {
7843+
7844+#ifdef CONFIG_PAX_EMUPLT
7845+ case 3:
7846+ return;
7847+#endif
7848+
7849+#ifdef CONFIG_PAX_EMUTRAMP
7850+ case 2:
7851+ return;
7852+#endif
7853+
7854+ }
7855+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7856+ do_group_exit(SIGKILL);
7857+ }
7858+#endif
7859+
7860 goto bad_area;
7861+ }
7862
7863 /*
7864 * If for any reason at all we couldn't handle the fault, make
7865diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7866index 957bf34..3430cc8 100644
7867--- a/arch/powerpc/Kconfig
7868+++ b/arch/powerpc/Kconfig
7869@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7870 config KEXEC
7871 bool "kexec system call"
7872 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7873+ depends on !GRKERNSEC_KMEM
7874 help
7875 kexec is a system call that implements the ability to shutdown your
7876 current kernel, and to start another kernel. It is like a reboot
7877diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7878index e3b1d41..8e81edf 100644
7879--- a/arch/powerpc/include/asm/atomic.h
7880+++ b/arch/powerpc/include/asm/atomic.h
7881@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7882 return t1;
7883 }
7884
7885+#define atomic64_read_unchecked(v) atomic64_read(v)
7886+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7887+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7888+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7889+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7890+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7891+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7892+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7893+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7894+
7895 #endif /* __powerpc64__ */
7896
7897 #endif /* __KERNEL__ */
7898diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7899index ed0afc1..0332825 100644
7900--- a/arch/powerpc/include/asm/cache.h
7901+++ b/arch/powerpc/include/asm/cache.h
7902@@ -3,6 +3,7 @@
7903
7904 #ifdef __KERNEL__
7905
7906+#include <linux/const.h>
7907
7908 /* bytes per L1 cache line */
7909 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7910@@ -22,7 +23,7 @@
7911 #define L1_CACHE_SHIFT 7
7912 #endif
7913
7914-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7915+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7916
7917 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7918
7919diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7920index 935b5e7..7001d2d 100644
7921--- a/arch/powerpc/include/asm/elf.h
7922+++ b/arch/powerpc/include/asm/elf.h
7923@@ -28,8 +28,19 @@
7924 the loader. We need to make sure that it is out of the way of the program
7925 that it will "exec", and that there is sufficient room for the brk. */
7926
7927-extern unsigned long randomize_et_dyn(unsigned long base);
7928-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7929+#define ELF_ET_DYN_BASE (0x20000000)
7930+
7931+#ifdef CONFIG_PAX_ASLR
7932+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7933+
7934+#ifdef __powerpc64__
7935+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7936+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7937+#else
7938+#define PAX_DELTA_MMAP_LEN 15
7939+#define PAX_DELTA_STACK_LEN 15
7940+#endif
7941+#endif
7942
7943 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7944
7945@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7946 (0x7ff >> (PAGE_SHIFT - 12)) : \
7947 (0x3ffff >> (PAGE_SHIFT - 12)))
7948
7949-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7950-#define arch_randomize_brk arch_randomize_brk
7951-
7952-
7953 #ifdef CONFIG_SPU_BASE
7954 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7955 #define NT_SPU 1
7956diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7957index 8196e9c..d83a9f3 100644
7958--- a/arch/powerpc/include/asm/exec.h
7959+++ b/arch/powerpc/include/asm/exec.h
7960@@ -4,6 +4,6 @@
7961 #ifndef _ASM_POWERPC_EXEC_H
7962 #define _ASM_POWERPC_EXEC_H
7963
7964-extern unsigned long arch_align_stack(unsigned long sp);
7965+#define arch_align_stack(x) ((x) & ~0xfUL)
7966
7967 #endif /* _ASM_POWERPC_EXEC_H */
7968diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7969index 5acabbd..7ea14fa 100644
7970--- a/arch/powerpc/include/asm/kmap_types.h
7971+++ b/arch/powerpc/include/asm/kmap_types.h
7972@@ -10,7 +10,7 @@
7973 * 2 of the License, or (at your option) any later version.
7974 */
7975
7976-#define KM_TYPE_NR 16
7977+#define KM_TYPE_NR 17
7978
7979 #endif /* __KERNEL__ */
7980 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7981diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
7982index b8da913..60b608a 100644
7983--- a/arch/powerpc/include/asm/local.h
7984+++ b/arch/powerpc/include/asm/local.h
7985@@ -9,15 +9,26 @@ typedef struct
7986 atomic_long_t a;
7987 } local_t;
7988
7989+typedef struct
7990+{
7991+ atomic_long_unchecked_t a;
7992+} local_unchecked_t;
7993+
7994 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7995
7996 #define local_read(l) atomic_long_read(&(l)->a)
7997+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7998 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
7999+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8000
8001 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8002+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8003 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8004+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8005 #define local_inc(l) atomic_long_inc(&(l)->a)
8006+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8007 #define local_dec(l) atomic_long_dec(&(l)->a)
8008+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8009
8010 static __inline__ long local_add_return(long a, local_t *l)
8011 {
8012@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8013
8014 return t;
8015 }
8016+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8017
8018 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8019
8020@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8021
8022 return t;
8023 }
8024+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8025
8026 static __inline__ long local_inc_return(local_t *l)
8027 {
8028@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8029
8030 #define local_cmpxchg(l, o, n) \
8031 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8032+#define local_cmpxchg_unchecked(l, o, n) \
8033+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8034 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8035
8036 /**
8037diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8038index 8565c25..2865190 100644
8039--- a/arch/powerpc/include/asm/mman.h
8040+++ b/arch/powerpc/include/asm/mman.h
8041@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8042 }
8043 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8044
8045-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8046+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8047 {
8048 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8049 }
8050diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8051index 32e4e21..62afb12 100644
8052--- a/arch/powerpc/include/asm/page.h
8053+++ b/arch/powerpc/include/asm/page.h
8054@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8055 * and needs to be executable. This means the whole heap ends
8056 * up being executable.
8057 */
8058-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8059- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8060+#define VM_DATA_DEFAULT_FLAGS32 \
8061+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8062+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8063
8064 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8065 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8066@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8067 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8068 #endif
8069
8070+#define ktla_ktva(addr) (addr)
8071+#define ktva_ktla(addr) (addr)
8072+
8073 #ifndef CONFIG_PPC_BOOK3S_64
8074 /*
8075 * Use the top bit of the higher-level page table entries to indicate whether
8076diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8077index 88693ce..ac6f9ab 100644
8078--- a/arch/powerpc/include/asm/page_64.h
8079+++ b/arch/powerpc/include/asm/page_64.h
8080@@ -153,15 +153,18 @@ do { \
8081 * stack by default, so in the absence of a PT_GNU_STACK program header
8082 * we turn execute permission off.
8083 */
8084-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8085- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8086+#define VM_STACK_DEFAULT_FLAGS32 \
8087+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8088+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8089
8090 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8091 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8092
8093+#ifndef CONFIG_PAX_PAGEEXEC
8094 #define VM_STACK_DEFAULT_FLAGS \
8095 (is_32bit_task() ? \
8096 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8097+#endif
8098
8099 #include <asm-generic/getorder.h>
8100
8101diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8102index 4b0be20..c15a27d 100644
8103--- a/arch/powerpc/include/asm/pgalloc-64.h
8104+++ b/arch/powerpc/include/asm/pgalloc-64.h
8105@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8106 #ifndef CONFIG_PPC_64K_PAGES
8107
8108 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8109+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8110
8111 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8112 {
8113@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8114 pud_set(pud, (unsigned long)pmd);
8115 }
8116
8117+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8118+{
8119+ pud_populate(mm, pud, pmd);
8120+}
8121+
8122 #define pmd_populate(mm, pmd, pte_page) \
8123 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8124 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8125@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8126 #endif
8127
8128 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8129+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8130
8131 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8132 pte_t *pte)
8133diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8134index 3ebb188..e17dddf 100644
8135--- a/arch/powerpc/include/asm/pgtable.h
8136+++ b/arch/powerpc/include/asm/pgtable.h
8137@@ -2,6 +2,7 @@
8138 #define _ASM_POWERPC_PGTABLE_H
8139 #ifdef __KERNEL__
8140
8141+#include <linux/const.h>
8142 #ifndef __ASSEMBLY__
8143 #include <linux/mmdebug.h>
8144 #include <asm/processor.h> /* For TASK_SIZE */
8145diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8146index 4aad413..85d86bf 100644
8147--- a/arch/powerpc/include/asm/pte-hash32.h
8148+++ b/arch/powerpc/include/asm/pte-hash32.h
8149@@ -21,6 +21,7 @@
8150 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8151 #define _PAGE_USER 0x004 /* usermode access allowed */
8152 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8153+#define _PAGE_EXEC _PAGE_GUARDED
8154 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8155 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8156 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8157diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8158index 90c06ec..3517221 100644
8159--- a/arch/powerpc/include/asm/reg.h
8160+++ b/arch/powerpc/include/asm/reg.h
8161@@ -248,6 +248,7 @@
8162 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8163 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8164 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8165+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8166 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8167 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8168 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8169diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8170index 084e080..9415a3d 100644
8171--- a/arch/powerpc/include/asm/smp.h
8172+++ b/arch/powerpc/include/asm/smp.h
8173@@ -51,7 +51,7 @@ struct smp_ops_t {
8174 int (*cpu_disable)(void);
8175 void (*cpu_die)(unsigned int nr);
8176 int (*cpu_bootable)(unsigned int nr);
8177-};
8178+} __no_const;
8179
8180 extern void smp_send_debugger_break(void);
8181 extern void start_secondary_resume(void);
8182diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8183index b034ecd..af7e31f 100644
8184--- a/arch/powerpc/include/asm/thread_info.h
8185+++ b/arch/powerpc/include/asm/thread_info.h
8186@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8187 #if defined(CONFIG_PPC64)
8188 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8189 #endif
8190+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8191+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8192
8193 /* as above, but as bit values */
8194 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8195@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8196 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8197 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8198 #define _TIF_NOHZ (1<<TIF_NOHZ)
8199+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8200 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8201 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8202- _TIF_NOHZ)
8203+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8204
8205 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8206 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8207diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8208index 9485b43..3bd3c16 100644
8209--- a/arch/powerpc/include/asm/uaccess.h
8210+++ b/arch/powerpc/include/asm/uaccess.h
8211@@ -58,6 +58,7 @@
8212
8213 #endif
8214
8215+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8216 #define access_ok(type, addr, size) \
8217 (__chk_user_ptr(addr), \
8218 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8219@@ -318,52 +319,6 @@ do { \
8220 extern unsigned long __copy_tofrom_user(void __user *to,
8221 const void __user *from, unsigned long size);
8222
8223-#ifndef __powerpc64__
8224-
8225-static inline unsigned long copy_from_user(void *to,
8226- const void __user *from, unsigned long n)
8227-{
8228- unsigned long over;
8229-
8230- if (access_ok(VERIFY_READ, from, n))
8231- return __copy_tofrom_user((__force void __user *)to, from, n);
8232- if ((unsigned long)from < TASK_SIZE) {
8233- over = (unsigned long)from + n - TASK_SIZE;
8234- return __copy_tofrom_user((__force void __user *)to, from,
8235- n - over) + over;
8236- }
8237- return n;
8238-}
8239-
8240-static inline unsigned long copy_to_user(void __user *to,
8241- const void *from, unsigned long n)
8242-{
8243- unsigned long over;
8244-
8245- if (access_ok(VERIFY_WRITE, to, n))
8246- return __copy_tofrom_user(to, (__force void __user *)from, n);
8247- if ((unsigned long)to < TASK_SIZE) {
8248- over = (unsigned long)to + n - TASK_SIZE;
8249- return __copy_tofrom_user(to, (__force void __user *)from,
8250- n - over) + over;
8251- }
8252- return n;
8253-}
8254-
8255-#else /* __powerpc64__ */
8256-
8257-#define __copy_in_user(to, from, size) \
8258- __copy_tofrom_user((to), (from), (size))
8259-
8260-extern unsigned long copy_from_user(void *to, const void __user *from,
8261- unsigned long n);
8262-extern unsigned long copy_to_user(void __user *to, const void *from,
8263- unsigned long n);
8264-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8265- unsigned long n);
8266-
8267-#endif /* __powerpc64__ */
8268-
8269 static inline unsigned long __copy_from_user_inatomic(void *to,
8270 const void __user *from, unsigned long n)
8271 {
8272@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8273 if (ret == 0)
8274 return 0;
8275 }
8276+
8277+ if (!__builtin_constant_p(n))
8278+ check_object_size(to, n, false);
8279+
8280 return __copy_tofrom_user((__force void __user *)to, from, n);
8281 }
8282
8283@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8284 if (ret == 0)
8285 return 0;
8286 }
8287+
8288+ if (!__builtin_constant_p(n))
8289+ check_object_size(from, n, true);
8290+
8291 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8292 }
8293
8294@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8295 return __copy_to_user_inatomic(to, from, size);
8296 }
8297
8298+#ifndef __powerpc64__
8299+
8300+static inline unsigned long __must_check copy_from_user(void *to,
8301+ const void __user *from, unsigned long n)
8302+{
8303+ unsigned long over;
8304+
8305+ if ((long)n < 0)
8306+ return n;
8307+
8308+ if (access_ok(VERIFY_READ, from, n)) {
8309+ if (!__builtin_constant_p(n))
8310+ check_object_size(to, n, false);
8311+ return __copy_tofrom_user((__force void __user *)to, from, n);
8312+ }
8313+ if ((unsigned long)from < TASK_SIZE) {
8314+ over = (unsigned long)from + n - TASK_SIZE;
8315+ if (!__builtin_constant_p(n - over))
8316+ check_object_size(to, n - over, false);
8317+ return __copy_tofrom_user((__force void __user *)to, from,
8318+ n - over) + over;
8319+ }
8320+ return n;
8321+}
8322+
8323+static inline unsigned long __must_check copy_to_user(void __user *to,
8324+ const void *from, unsigned long n)
8325+{
8326+ unsigned long over;
8327+
8328+ if ((long)n < 0)
8329+ return n;
8330+
8331+ if (access_ok(VERIFY_WRITE, to, n)) {
8332+ if (!__builtin_constant_p(n))
8333+ check_object_size(from, n, true);
8334+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8335+ }
8336+ if ((unsigned long)to < TASK_SIZE) {
8337+ over = (unsigned long)to + n - TASK_SIZE;
8338+ if (!__builtin_constant_p(n))
8339+ check_object_size(from, n - over, true);
8340+ return __copy_tofrom_user(to, (__force void __user *)from,
8341+ n - over) + over;
8342+ }
8343+ return n;
8344+}
8345+
8346+#else /* __powerpc64__ */
8347+
8348+#define __copy_in_user(to, from, size) \
8349+ __copy_tofrom_user((to), (from), (size))
8350+
8351+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8352+{
8353+ if ((long)n < 0 || n > INT_MAX)
8354+ return n;
8355+
8356+ if (!__builtin_constant_p(n))
8357+ check_object_size(to, n, false);
8358+
8359+ if (likely(access_ok(VERIFY_READ, from, n)))
8360+ n = __copy_from_user(to, from, n);
8361+ else
8362+ memset(to, 0, n);
8363+ return n;
8364+}
8365+
8366+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8367+{
8368+ if ((long)n < 0 || n > INT_MAX)
8369+ return n;
8370+
8371+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8372+ if (!__builtin_constant_p(n))
8373+ check_object_size(from, n, true);
8374+ n = __copy_to_user(to, from, n);
8375+ }
8376+ return n;
8377+}
8378+
8379+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8380+ unsigned long n);
8381+
8382+#endif /* __powerpc64__ */
8383+
8384 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8385
8386 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8387diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8388index fcc9a89..07be2bb 100644
8389--- a/arch/powerpc/kernel/Makefile
8390+++ b/arch/powerpc/kernel/Makefile
8391@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8392 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8393 endif
8394
8395+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8396+
8397 obj-y := cputable.o ptrace.o syscalls.o \
8398 irq.o align.o signal_32.o pmc.o vdso.o \
8399 process.o systbl.o idle.o \
8400diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8401index 063b65d..7a26e9d 100644
8402--- a/arch/powerpc/kernel/exceptions-64e.S
8403+++ b/arch/powerpc/kernel/exceptions-64e.S
8404@@ -771,6 +771,7 @@ storage_fault_common:
8405 std r14,_DAR(r1)
8406 std r15,_DSISR(r1)
8407 addi r3,r1,STACK_FRAME_OVERHEAD
8408+ bl .save_nvgprs
8409 mr r4,r14
8410 mr r5,r15
8411 ld r14,PACA_EXGEN+EX_R14(r13)
8412@@ -779,8 +780,7 @@ storage_fault_common:
8413 cmpdi r3,0
8414 bne- 1f
8415 b .ret_from_except_lite
8416-1: bl .save_nvgprs
8417- mr r5,r3
8418+1: mr r5,r3
8419 addi r3,r1,STACK_FRAME_OVERHEAD
8420 ld r4,_DAR(r1)
8421 bl .bad_page_fault
8422diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8423index 38d5073..f00af8d 100644
8424--- a/arch/powerpc/kernel/exceptions-64s.S
8425+++ b/arch/powerpc/kernel/exceptions-64s.S
8426@@ -1584,10 +1584,10 @@ handle_page_fault:
8427 11: ld r4,_DAR(r1)
8428 ld r5,_DSISR(r1)
8429 addi r3,r1,STACK_FRAME_OVERHEAD
8430+ bl .save_nvgprs
8431 bl .do_page_fault
8432 cmpdi r3,0
8433 beq+ 12f
8434- bl .save_nvgprs
8435 mr r5,r3
8436 addi r3,r1,STACK_FRAME_OVERHEAD
8437 lwz r4,_DAR(r1)
8438diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8439index 6cff040..74ac5d1 100644
8440--- a/arch/powerpc/kernel/module_32.c
8441+++ b/arch/powerpc/kernel/module_32.c
8442@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8443 me->arch.core_plt_section = i;
8444 }
8445 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8446- printk("Module doesn't contain .plt or .init.plt sections.\n");
8447+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8448 return -ENOEXEC;
8449 }
8450
8451@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8452
8453 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8454 /* Init, or core PLT? */
8455- if (location >= mod->module_core
8456- && location < mod->module_core + mod->core_size)
8457+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8458+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8459 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8460- else
8461+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8462+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8463 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8464+ else {
8465+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8466+ return ~0UL;
8467+ }
8468
8469 /* Find this entry, or if that fails, the next avail. entry */
8470 while (entry->jump[0]) {
8471@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8472 }
8473 #ifdef CONFIG_DYNAMIC_FTRACE
8474 module->arch.tramp =
8475- do_plt_call(module->module_core,
8476+ do_plt_call(module->module_core_rx,
8477 (unsigned long)ftrace_caller,
8478 sechdrs, module);
8479 #endif
8480diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8481index af064d2..ce56147 100644
8482--- a/arch/powerpc/kernel/process.c
8483+++ b/arch/powerpc/kernel/process.c
8484@@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8485 * Lookup NIP late so we have the best change of getting the
8486 * above info out without failing
8487 */
8488- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8489- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8490+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8491+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8492 #endif
8493 show_stack(current, (unsigned long *) regs->gpr[1]);
8494 if (!user_mode(regs))
8495@@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8496 newsp = stack[0];
8497 ip = stack[STACK_FRAME_LR_SAVE];
8498 if (!firstframe || ip != lr) {
8499- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8500+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8501 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8502 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8503- printk(" (%pS)",
8504+ printk(" (%pA)",
8505 (void *)current->ret_stack[curr_frame].ret);
8506 curr_frame--;
8507 }
8508@@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8509 struct pt_regs *regs = (struct pt_regs *)
8510 (sp + STACK_FRAME_OVERHEAD);
8511 lr = regs->link;
8512- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8513+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8514 regs->trap, (void *)regs->nip, (void *)lr);
8515 firstframe = 1;
8516 }
8517@@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8518 mtspr(SPRN_CTRLT, ctrl);
8519 }
8520 #endif /* CONFIG_PPC64 */
8521-
8522-unsigned long arch_align_stack(unsigned long sp)
8523-{
8524- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8525- sp -= get_random_int() & ~PAGE_MASK;
8526- return sp & ~0xf;
8527-}
8528-
8529-static inline unsigned long brk_rnd(void)
8530-{
8531- unsigned long rnd = 0;
8532-
8533- /* 8MB for 32bit, 1GB for 64bit */
8534- if (is_32bit_task())
8535- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8536- else
8537- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8538-
8539- return rnd << PAGE_SHIFT;
8540-}
8541-
8542-unsigned long arch_randomize_brk(struct mm_struct *mm)
8543-{
8544- unsigned long base = mm->brk;
8545- unsigned long ret;
8546-
8547-#ifdef CONFIG_PPC_STD_MMU_64
8548- /*
8549- * If we are using 1TB segments and we are allowed to randomise
8550- * the heap, we can put it above 1TB so it is backed by a 1TB
8551- * segment. Otherwise the heap will be in the bottom 1TB
8552- * which always uses 256MB segments and this may result in a
8553- * performance penalty.
8554- */
8555- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8556- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8557-#endif
8558-
8559- ret = PAGE_ALIGN(base + brk_rnd());
8560-
8561- if (ret < mm->brk)
8562- return mm->brk;
8563-
8564- return ret;
8565-}
8566-
8567-unsigned long randomize_et_dyn(unsigned long base)
8568-{
8569- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8570-
8571- if (ret < base)
8572- return base;
8573-
8574- return ret;
8575-}
8576diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8577index 2e3d2bf..35df241 100644
8578--- a/arch/powerpc/kernel/ptrace.c
8579+++ b/arch/powerpc/kernel/ptrace.c
8580@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8581 return ret;
8582 }
8583
8584+#ifdef CONFIG_GRKERNSEC_SETXID
8585+extern void gr_delayed_cred_worker(void);
8586+#endif
8587+
8588 /*
8589 * We must return the syscall number to actually look up in the table.
8590 * This can be -1L to skip running any syscall at all.
8591@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8592
8593 secure_computing_strict(regs->gpr[0]);
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 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8601 tracehook_report_syscall_entry(regs))
8602 /*
8603@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8604 {
8605 int step;
8606
8607+#ifdef CONFIG_GRKERNSEC_SETXID
8608+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8609+ gr_delayed_cred_worker();
8610+#endif
8611+
8612 audit_syscall_exit(regs);
8613
8614 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8615diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8616index a67e00a..f71d8c7 100644
8617--- a/arch/powerpc/kernel/signal_32.c
8618+++ b/arch/powerpc/kernel/signal_32.c
8619@@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8620 /* Save user registers on the stack */
8621 frame = &rt_sf->uc.uc_mcontext;
8622 addr = frame;
8623- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8624+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8625 sigret = 0;
8626 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8627 } else {
8628diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8629index 8d253c2..405b337 100644
8630--- a/arch/powerpc/kernel/signal_64.c
8631+++ b/arch/powerpc/kernel/signal_64.c
8632@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8633 current->thread.fp_state.fpscr = 0;
8634
8635 /* Set up to return from userspace. */
8636- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8637+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8638 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8639 } else {
8640 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8641diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8642index 33cd7a0..d615344 100644
8643--- a/arch/powerpc/kernel/traps.c
8644+++ b/arch/powerpc/kernel/traps.c
8645@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8646 return flags;
8647 }
8648
8649+extern void gr_handle_kernel_exploit(void);
8650+
8651 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8652 int signr)
8653 {
8654@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8655 panic("Fatal exception in interrupt");
8656 if (panic_on_oops)
8657 panic("Fatal exception");
8658+
8659+ gr_handle_kernel_exploit();
8660+
8661 do_exit(signr);
8662 }
8663
8664diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8665index 094e45c..d82b848 100644
8666--- a/arch/powerpc/kernel/vdso.c
8667+++ b/arch/powerpc/kernel/vdso.c
8668@@ -35,6 +35,7 @@
8669 #include <asm/vdso.h>
8670 #include <asm/vdso_datapage.h>
8671 #include <asm/setup.h>
8672+#include <asm/mman.h>
8673
8674 #undef DEBUG
8675
8676@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8677 vdso_base = VDSO32_MBASE;
8678 #endif
8679
8680- current->mm->context.vdso_base = 0;
8681+ current->mm->context.vdso_base = ~0UL;
8682
8683 /* vDSO has a problem and was disabled, just don't "enable" it for the
8684 * process
8685@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8686 vdso_base = get_unmapped_area(NULL, vdso_base,
8687 (vdso_pages << PAGE_SHIFT) +
8688 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8689- 0, 0);
8690+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8691 if (IS_ERR_VALUE(vdso_base)) {
8692 rc = vdso_base;
8693 goto fail_mmapsem;
8694diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8695index 3cf541a..ab2d825 100644
8696--- a/arch/powerpc/kvm/powerpc.c
8697+++ b/arch/powerpc/kvm/powerpc.c
8698@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8699 }
8700 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8701
8702-int kvm_arch_init(void *opaque)
8703+int kvm_arch_init(const void *opaque)
8704 {
8705 return 0;
8706 }
8707diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8708index 5eea6f3..5d10396 100644
8709--- a/arch/powerpc/lib/usercopy_64.c
8710+++ b/arch/powerpc/lib/usercopy_64.c
8711@@ -9,22 +9,6 @@
8712 #include <linux/module.h>
8713 #include <asm/uaccess.h>
8714
8715-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8716-{
8717- if (likely(access_ok(VERIFY_READ, from, n)))
8718- n = __copy_from_user(to, from, n);
8719- else
8720- memset(to, 0, n);
8721- return n;
8722-}
8723-
8724-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8725-{
8726- if (likely(access_ok(VERIFY_WRITE, to, n)))
8727- n = __copy_to_user(to, from, n);
8728- return n;
8729-}
8730-
8731 unsigned long copy_in_user(void __user *to, const void __user *from,
8732 unsigned long n)
8733 {
8734@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8735 return n;
8736 }
8737
8738-EXPORT_SYMBOL(copy_from_user);
8739-EXPORT_SYMBOL(copy_to_user);
8740 EXPORT_SYMBOL(copy_in_user);
8741
8742diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8743index 51ab9e7..7d3c78b 100644
8744--- a/arch/powerpc/mm/fault.c
8745+++ b/arch/powerpc/mm/fault.c
8746@@ -33,6 +33,10 @@
8747 #include <linux/magic.h>
8748 #include <linux/ratelimit.h>
8749 #include <linux/context_tracking.h>
8750+#include <linux/slab.h>
8751+#include <linux/pagemap.h>
8752+#include <linux/compiler.h>
8753+#include <linux/unistd.h>
8754
8755 #include <asm/firmware.h>
8756 #include <asm/page.h>
8757@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8758 }
8759 #endif
8760
8761+#ifdef CONFIG_PAX_PAGEEXEC
8762+/*
8763+ * PaX: decide what to do with offenders (regs->nip = fault address)
8764+ *
8765+ * returns 1 when task should be killed
8766+ */
8767+static int pax_handle_fetch_fault(struct pt_regs *regs)
8768+{
8769+ return 1;
8770+}
8771+
8772+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8773+{
8774+ unsigned long i;
8775+
8776+ printk(KERN_ERR "PAX: bytes at PC: ");
8777+ for (i = 0; i < 5; i++) {
8778+ unsigned int c;
8779+ if (get_user(c, (unsigned int __user *)pc+i))
8780+ printk(KERN_CONT "???????? ");
8781+ else
8782+ printk(KERN_CONT "%08x ", c);
8783+ }
8784+ printk("\n");
8785+}
8786+#endif
8787+
8788 /*
8789 * Check whether the instruction at regs->nip is a store using
8790 * an update addressing form which will update r1.
8791@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8792 * indicate errors in DSISR but can validly be set in SRR1.
8793 */
8794 if (trap == 0x400)
8795- error_code &= 0x48200000;
8796+ error_code &= 0x58200000;
8797 else
8798 is_write = error_code & DSISR_ISSTORE;
8799 #else
8800@@ -378,7 +409,7 @@ good_area:
8801 * "undefined". Of those that can be set, this is the only
8802 * one which seems bad.
8803 */
8804- if (error_code & 0x10000000)
8805+ if (error_code & DSISR_GUARDED)
8806 /* Guarded storage error. */
8807 goto bad_area;
8808 #endif /* CONFIG_8xx */
8809@@ -393,7 +424,7 @@ good_area:
8810 * processors use the same I/D cache coherency mechanism
8811 * as embedded.
8812 */
8813- if (error_code & DSISR_PROTFAULT)
8814+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8815 goto bad_area;
8816 #endif /* CONFIG_PPC_STD_MMU */
8817
8818@@ -483,6 +514,23 @@ bad_area:
8819 bad_area_nosemaphore:
8820 /* User mode accesses cause a SIGSEGV */
8821 if (user_mode(regs)) {
8822+
8823+#ifdef CONFIG_PAX_PAGEEXEC
8824+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8825+#ifdef CONFIG_PPC_STD_MMU
8826+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8827+#else
8828+ if (is_exec && regs->nip == address) {
8829+#endif
8830+ switch (pax_handle_fetch_fault(regs)) {
8831+ }
8832+
8833+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8834+ do_group_exit(SIGKILL);
8835+ }
8836+ }
8837+#endif
8838+
8839 _exception(SIGSEGV, regs, code, address);
8840 goto bail;
8841 }
8842diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8843index cb8bdbe..cde4bc7 100644
8844--- a/arch/powerpc/mm/mmap.c
8845+++ b/arch/powerpc/mm/mmap.c
8846@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8847 return sysctl_legacy_va_layout;
8848 }
8849
8850-static unsigned long mmap_rnd(void)
8851+static unsigned long mmap_rnd(struct mm_struct *mm)
8852 {
8853 unsigned long rnd = 0;
8854
8855+#ifdef CONFIG_PAX_RANDMMAP
8856+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8857+#endif
8858+
8859 if (current->flags & PF_RANDOMIZE) {
8860 /* 8MB for 32bit, 1GB for 64bit */
8861 if (is_32bit_task())
8862@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8863 return rnd << PAGE_SHIFT;
8864 }
8865
8866-static inline unsigned long mmap_base(void)
8867+static inline unsigned long mmap_base(struct mm_struct *mm)
8868 {
8869 unsigned long gap = rlimit(RLIMIT_STACK);
8870
8871@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8872 else if (gap > MAX_GAP)
8873 gap = MAX_GAP;
8874
8875- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8876+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8877 }
8878
8879 /*
8880@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8881 */
8882 if (mmap_is_legacy()) {
8883 mm->mmap_base = TASK_UNMAPPED_BASE;
8884+
8885+#ifdef CONFIG_PAX_RANDMMAP
8886+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8887+ mm->mmap_base += mm->delta_mmap;
8888+#endif
8889+
8890 mm->get_unmapped_area = arch_get_unmapped_area;
8891 } else {
8892- mm->mmap_base = mmap_base();
8893+ mm->mmap_base = mmap_base(mm);
8894+
8895+#ifdef CONFIG_PAX_RANDMMAP
8896+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8897+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8898+#endif
8899+
8900 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8901 }
8902 }
8903diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8904index b0c75cc..ef7fb93 100644
8905--- a/arch/powerpc/mm/slice.c
8906+++ b/arch/powerpc/mm/slice.c
8907@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8908 if ((mm->task_size - len) < addr)
8909 return 0;
8910 vma = find_vma(mm, addr);
8911- return (!vma || (addr + len) <= vma->vm_start);
8912+ return check_heap_stack_gap(vma, addr, len, 0);
8913 }
8914
8915 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8916@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8917 info.align_offset = 0;
8918
8919 addr = TASK_UNMAPPED_BASE;
8920+
8921+#ifdef CONFIG_PAX_RANDMMAP
8922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8923+ addr += mm->delta_mmap;
8924+#endif
8925+
8926 while (addr < TASK_SIZE) {
8927 info.low_limit = addr;
8928 if (!slice_scan_available(addr, available, 1, &addr))
8929@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8930 if (fixed && addr > (mm->task_size - len))
8931 return -ENOMEM;
8932
8933+#ifdef CONFIG_PAX_RANDMMAP
8934+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8935+ addr = 0;
8936+#endif
8937+
8938 /* If hint, make sure it matches our alignment restrictions */
8939 if (!fixed && addr) {
8940 addr = _ALIGN_UP(addr, 1ul << pshift);
8941diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8942index 4278acf..67fd0e6 100644
8943--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8944+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8945@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8946 }
8947
8948 static struct pci_ops scc_pciex_pci_ops = {
8949- scc_pciex_read_config,
8950- scc_pciex_write_config,
8951+ .read = scc_pciex_read_config,
8952+ .write = scc_pciex_write_config,
8953 };
8954
8955 static void pciex_clear_intr_all(unsigned int __iomem *base)
8956diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8957index 9098692..3d54cd1 100644
8958--- a/arch/powerpc/platforms/cell/spufs/file.c
8959+++ b/arch/powerpc/platforms/cell/spufs/file.c
8960@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8961 return VM_FAULT_NOPAGE;
8962 }
8963
8964-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8965+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8966 unsigned long address,
8967- void *buf, int len, int write)
8968+ void *buf, size_t len, int write)
8969 {
8970 struct spu_context *ctx = vma->vm_file->private_data;
8971 unsigned long offset = address - vma->vm_start;
8972diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8973index 1d47061..0714963 100644
8974--- a/arch/s390/include/asm/atomic.h
8975+++ b/arch/s390/include/asm/atomic.h
8976@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8977 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8978 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8979
8980+#define atomic64_read_unchecked(v) atomic64_read(v)
8981+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8982+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8983+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8984+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8985+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8986+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8987+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8988+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8989+
8990 #define smp_mb__before_atomic_dec() smp_mb()
8991 #define smp_mb__after_atomic_dec() smp_mb()
8992 #define smp_mb__before_atomic_inc() smp_mb()
8993diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8994index 4d7ccac..d03d0ad 100644
8995--- a/arch/s390/include/asm/cache.h
8996+++ b/arch/s390/include/asm/cache.h
8997@@ -9,8 +9,10 @@
8998 #ifndef __ARCH_S390_CACHE_H
8999 #define __ARCH_S390_CACHE_H
9000
9001-#define L1_CACHE_BYTES 256
9002+#include <linux/const.h>
9003+
9004 #define L1_CACHE_SHIFT 8
9005+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9006 #define NET_SKB_PAD 32
9007
9008 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9009diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9010index 78f4f87..598ce39 100644
9011--- a/arch/s390/include/asm/elf.h
9012+++ b/arch/s390/include/asm/elf.h
9013@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9014 the loader. We need to make sure that it is out of the way of the program
9015 that it will "exec", and that there is sufficient room for the brk. */
9016
9017-extern unsigned long randomize_et_dyn(unsigned long base);
9018-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9019+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9020+
9021+#ifdef CONFIG_PAX_ASLR
9022+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9023+
9024+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9025+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9026+#endif
9027
9028 /* This yields a mask that user programs can use to figure out what
9029 instruction set this CPU supports. */
9030@@ -222,9 +228,6 @@ struct linux_binprm;
9031 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9032 int arch_setup_additional_pages(struct linux_binprm *, int);
9033
9034-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9035-#define arch_randomize_brk arch_randomize_brk
9036-
9037 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9038
9039 #endif
9040diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9041index c4a93d6..4d2a9b4 100644
9042--- a/arch/s390/include/asm/exec.h
9043+++ b/arch/s390/include/asm/exec.h
9044@@ -7,6 +7,6 @@
9045 #ifndef __ASM_EXEC_H
9046 #define __ASM_EXEC_H
9047
9048-extern unsigned long arch_align_stack(unsigned long sp);
9049+#define arch_align_stack(x) ((x) & ~0xfUL)
9050
9051 #endif /* __ASM_EXEC_H */
9052diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9053index 79330af..254cf37 100644
9054--- a/arch/s390/include/asm/uaccess.h
9055+++ b/arch/s390/include/asm/uaccess.h
9056@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9057 __range_ok((unsigned long)(addr), (size)); \
9058 })
9059
9060+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9061 #define access_ok(type, addr, size) __access_ok(addr, size)
9062
9063 /*
9064@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9065 copy_to_user(void __user *to, const void *from, unsigned long n)
9066 {
9067 might_fault();
9068+
9069+ if ((long)n < 0)
9070+ return n;
9071+
9072 return __copy_to_user(to, from, n);
9073 }
9074
9075@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9076 static inline unsigned long __must_check
9077 __copy_from_user(void *to, const void __user *from, unsigned long n)
9078 {
9079+ if ((long)n < 0)
9080+ return n;
9081+
9082 return uaccess.copy_from_user(n, from, to);
9083 }
9084
9085@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9086 static inline unsigned long __must_check
9087 copy_from_user(void *to, const void __user *from, unsigned long n)
9088 {
9089- unsigned int sz = __compiletime_object_size(to);
9090+ size_t sz = __compiletime_object_size(to);
9091
9092 might_fault();
9093- if (unlikely(sz != -1 && sz < n)) {
9094+
9095+ if ((long)n < 0)
9096+ return n;
9097+
9098+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9099 copy_from_user_overflow();
9100 return n;
9101 }
9102diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9103index b89b591..fd9609d 100644
9104--- a/arch/s390/kernel/module.c
9105+++ b/arch/s390/kernel/module.c
9106@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9107
9108 /* Increase core size by size of got & plt and set start
9109 offsets for got and plt. */
9110- me->core_size = ALIGN(me->core_size, 4);
9111- me->arch.got_offset = me->core_size;
9112- me->core_size += me->arch.got_size;
9113- me->arch.plt_offset = me->core_size;
9114- me->core_size += me->arch.plt_size;
9115+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9116+ me->arch.got_offset = me->core_size_rw;
9117+ me->core_size_rw += me->arch.got_size;
9118+ me->arch.plt_offset = me->core_size_rx;
9119+ me->core_size_rx += me->arch.plt_size;
9120 return 0;
9121 }
9122
9123@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9124 if (info->got_initialized == 0) {
9125 Elf_Addr *gotent;
9126
9127- gotent = me->module_core + me->arch.got_offset +
9128+ gotent = me->module_core_rw + me->arch.got_offset +
9129 info->got_offset;
9130 *gotent = val;
9131 info->got_initialized = 1;
9132@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9133 rc = apply_rela_bits(loc, val, 0, 64, 0);
9134 else if (r_type == R_390_GOTENT ||
9135 r_type == R_390_GOTPLTENT) {
9136- val += (Elf_Addr) me->module_core - loc;
9137+ val += (Elf_Addr) me->module_core_rw - loc;
9138 rc = apply_rela_bits(loc, val, 1, 32, 1);
9139 }
9140 break;
9141@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9142 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9143 if (info->plt_initialized == 0) {
9144 unsigned int *ip;
9145- ip = me->module_core + me->arch.plt_offset +
9146+ ip = me->module_core_rx + me->arch.plt_offset +
9147 info->plt_offset;
9148 #ifndef CONFIG_64BIT
9149 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9150@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9151 val - loc + 0xffffUL < 0x1ffffeUL) ||
9152 (r_type == R_390_PLT32DBL &&
9153 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9154- val = (Elf_Addr) me->module_core +
9155+ val = (Elf_Addr) me->module_core_rx +
9156 me->arch.plt_offset +
9157 info->plt_offset;
9158 val += rela->r_addend - loc;
9159@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9160 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9161 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9162 val = val + rela->r_addend -
9163- ((Elf_Addr) me->module_core + me->arch.got_offset);
9164+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9165 if (r_type == R_390_GOTOFF16)
9166 rc = apply_rela_bits(loc, val, 0, 16, 0);
9167 else if (r_type == R_390_GOTOFF32)
9168@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9169 break;
9170 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9171 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9172- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9173+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9174 rela->r_addend - loc;
9175 if (r_type == R_390_GOTPC)
9176 rc = apply_rela_bits(loc, val, 1, 32, 0);
9177diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9178index dd14532..1dfc145 100644
9179--- a/arch/s390/kernel/process.c
9180+++ b/arch/s390/kernel/process.c
9181@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9182 }
9183 return 0;
9184 }
9185-
9186-unsigned long arch_align_stack(unsigned long sp)
9187-{
9188- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9189- sp -= get_random_int() & ~PAGE_MASK;
9190- return sp & ~0xf;
9191-}
9192-
9193-static inline unsigned long brk_rnd(void)
9194-{
9195- /* 8MB for 32bit, 1GB for 64bit */
9196- if (is_32bit_task())
9197- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9198- else
9199- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9200-}
9201-
9202-unsigned long arch_randomize_brk(struct mm_struct *mm)
9203-{
9204- unsigned long ret;
9205-
9206- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9207- return (ret > mm->brk) ? ret : mm->brk;
9208-}
9209-
9210-unsigned long randomize_et_dyn(unsigned long base)
9211-{
9212- unsigned long ret;
9213-
9214- if (!(current->flags & PF_RANDOMIZE))
9215- return base;
9216- ret = PAGE_ALIGN(base + brk_rnd());
9217- return (ret > base) ? ret : base;
9218-}
9219diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9220index 9b436c2..54fbf0a 100644
9221--- a/arch/s390/mm/mmap.c
9222+++ b/arch/s390/mm/mmap.c
9223@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9224 */
9225 if (mmap_is_legacy()) {
9226 mm->mmap_base = mmap_base_legacy();
9227+
9228+#ifdef CONFIG_PAX_RANDMMAP
9229+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9230+ mm->mmap_base += mm->delta_mmap;
9231+#endif
9232+
9233 mm->get_unmapped_area = arch_get_unmapped_area;
9234 } else {
9235 mm->mmap_base = mmap_base();
9236+
9237+#ifdef CONFIG_PAX_RANDMMAP
9238+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9239+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9240+#endif
9241+
9242 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9243 }
9244 }
9245@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9246 */
9247 if (mmap_is_legacy()) {
9248 mm->mmap_base = mmap_base_legacy();
9249+
9250+#ifdef CONFIG_PAX_RANDMMAP
9251+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9252+ mm->mmap_base += mm->delta_mmap;
9253+#endif
9254+
9255 mm->get_unmapped_area = s390_get_unmapped_area;
9256 } else {
9257 mm->mmap_base = mmap_base();
9258+
9259+#ifdef CONFIG_PAX_RANDMMAP
9260+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9261+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9262+#endif
9263+
9264 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9265 }
9266 }
9267diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9268index ae3d59f..f65f075 100644
9269--- a/arch/score/include/asm/cache.h
9270+++ b/arch/score/include/asm/cache.h
9271@@ -1,7 +1,9 @@
9272 #ifndef _ASM_SCORE_CACHE_H
9273 #define _ASM_SCORE_CACHE_H
9274
9275+#include <linux/const.h>
9276+
9277 #define L1_CACHE_SHIFT 4
9278-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9279+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9280
9281 #endif /* _ASM_SCORE_CACHE_H */
9282diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9283index f9f3cd5..58ff438 100644
9284--- a/arch/score/include/asm/exec.h
9285+++ b/arch/score/include/asm/exec.h
9286@@ -1,6 +1,6 @@
9287 #ifndef _ASM_SCORE_EXEC_H
9288 #define _ASM_SCORE_EXEC_H
9289
9290-extern unsigned long arch_align_stack(unsigned long sp);
9291+#define arch_align_stack(x) (x)
9292
9293 #endif /* _ASM_SCORE_EXEC_H */
9294diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9295index a1519ad3..e8ac1ff 100644
9296--- a/arch/score/kernel/process.c
9297+++ b/arch/score/kernel/process.c
9298@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9299
9300 return task_pt_regs(task)->cp0_epc;
9301 }
9302-
9303-unsigned long arch_align_stack(unsigned long sp)
9304-{
9305- return sp;
9306-}
9307diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9308index ef9e555..331bd29 100644
9309--- a/arch/sh/include/asm/cache.h
9310+++ b/arch/sh/include/asm/cache.h
9311@@ -9,10 +9,11 @@
9312 #define __ASM_SH_CACHE_H
9313 #ifdef __KERNEL__
9314
9315+#include <linux/const.h>
9316 #include <linux/init.h>
9317 #include <cpu/cache.h>
9318
9319-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9320+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9321
9322 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9323
9324diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9325index 6777177..cb5e44f 100644
9326--- a/arch/sh/mm/mmap.c
9327+++ b/arch/sh/mm/mmap.c
9328@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9329 struct mm_struct *mm = current->mm;
9330 struct vm_area_struct *vma;
9331 int do_colour_align;
9332+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9333 struct vm_unmapped_area_info info;
9334
9335 if (flags & MAP_FIXED) {
9336@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9337 if (filp || (flags & MAP_SHARED))
9338 do_colour_align = 1;
9339
9340+#ifdef CONFIG_PAX_RANDMMAP
9341+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9342+#endif
9343+
9344 if (addr) {
9345 if (do_colour_align)
9346 addr = COLOUR_ALIGN(addr, pgoff);
9347@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9348 addr = PAGE_ALIGN(addr);
9349
9350 vma = find_vma(mm, addr);
9351- if (TASK_SIZE - len >= addr &&
9352- (!vma || addr + len <= vma->vm_start))
9353+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9354 return addr;
9355 }
9356
9357 info.flags = 0;
9358 info.length = len;
9359- info.low_limit = TASK_UNMAPPED_BASE;
9360+ info.low_limit = mm->mmap_base;
9361 info.high_limit = TASK_SIZE;
9362 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9363 info.align_offset = pgoff << PAGE_SHIFT;
9364@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9365 struct mm_struct *mm = current->mm;
9366 unsigned long addr = addr0;
9367 int do_colour_align;
9368+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9369 struct vm_unmapped_area_info info;
9370
9371 if (flags & MAP_FIXED) {
9372@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9373 if (filp || (flags & MAP_SHARED))
9374 do_colour_align = 1;
9375
9376+#ifdef CONFIG_PAX_RANDMMAP
9377+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9378+#endif
9379+
9380 /* requesting a specific address */
9381 if (addr) {
9382 if (do_colour_align)
9383@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9384 addr = PAGE_ALIGN(addr);
9385
9386 vma = find_vma(mm, addr);
9387- if (TASK_SIZE - len >= addr &&
9388- (!vma || addr + len <= vma->vm_start))
9389+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9390 return addr;
9391 }
9392
9393@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9394 VM_BUG_ON(addr != -ENOMEM);
9395 info.flags = 0;
9396 info.low_limit = TASK_UNMAPPED_BASE;
9397+
9398+#ifdef CONFIG_PAX_RANDMMAP
9399+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9400+ info.low_limit += mm->delta_mmap;
9401+#endif
9402+
9403 info.high_limit = TASK_SIZE;
9404 addr = vm_unmapped_area(&info);
9405 }
9406diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9407index be56a24..443328f 100644
9408--- a/arch/sparc/include/asm/atomic_64.h
9409+++ b/arch/sparc/include/asm/atomic_64.h
9410@@ -14,18 +14,40 @@
9411 #define ATOMIC64_INIT(i) { (i) }
9412
9413 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9414+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9415+{
9416+ return v->counter;
9417+}
9418 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9419+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9420+{
9421+ return v->counter;
9422+}
9423
9424 #define atomic_set(v, i) (((v)->counter) = i)
9425+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9426+{
9427+ v->counter = i;
9428+}
9429 #define atomic64_set(v, i) (((v)->counter) = i)
9430+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9431+{
9432+ v->counter = i;
9433+}
9434
9435 extern void atomic_add(int, atomic_t *);
9436+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9437 extern void atomic64_add(long, atomic64_t *);
9438+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9439 extern void atomic_sub(int, atomic_t *);
9440+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9441 extern void atomic64_sub(long, atomic64_t *);
9442+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9443
9444 extern int atomic_add_ret(int, atomic_t *);
9445+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9446 extern long atomic64_add_ret(long, atomic64_t *);
9447+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9448 extern int atomic_sub_ret(int, atomic_t *);
9449 extern long atomic64_sub_ret(long, atomic64_t *);
9450
9451@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9452 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9453
9454 #define atomic_inc_return(v) atomic_add_ret(1, v)
9455+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9456+{
9457+ return atomic_add_ret_unchecked(1, v);
9458+}
9459 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9460+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9461+{
9462+ return atomic64_add_ret_unchecked(1, v);
9463+}
9464
9465 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9466 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9467
9468 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9469+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9470+{
9471+ return atomic_add_ret_unchecked(i, v);
9472+}
9473 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9474+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9475+{
9476+ return atomic64_add_ret_unchecked(i, v);
9477+}
9478
9479 /*
9480 * atomic_inc_and_test - increment and test
9481@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9482 * other cases.
9483 */
9484 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9485+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9486+{
9487+ return atomic_inc_return_unchecked(v) == 0;
9488+}
9489 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9490
9491 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9492@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9493 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9494
9495 #define atomic_inc(v) atomic_add(1, v)
9496+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9497+{
9498+ atomic_add_unchecked(1, v);
9499+}
9500 #define atomic64_inc(v) atomic64_add(1, v)
9501+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9502+{
9503+ atomic64_add_unchecked(1, v);
9504+}
9505
9506 #define atomic_dec(v) atomic_sub(1, v)
9507+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9508+{
9509+ atomic_sub_unchecked(1, v);
9510+}
9511 #define atomic64_dec(v) atomic64_sub(1, v)
9512+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9513+{
9514+ atomic64_sub_unchecked(1, v);
9515+}
9516
9517 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9518 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9519
9520 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9521+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9522+{
9523+ return cmpxchg(&v->counter, old, new);
9524+}
9525 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9526+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9527+{
9528+ return xchg(&v->counter, new);
9529+}
9530
9531 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9532 {
9533- int c, old;
9534+ int c, old, new;
9535 c = atomic_read(v);
9536 for (;;) {
9537- if (unlikely(c == (u)))
9538+ if (unlikely(c == u))
9539 break;
9540- old = atomic_cmpxchg((v), c, c + (a));
9541+
9542+ asm volatile("addcc %2, %0, %0\n"
9543+
9544+#ifdef CONFIG_PAX_REFCOUNT
9545+ "tvs %%icc, 6\n"
9546+#endif
9547+
9548+ : "=r" (new)
9549+ : "0" (c), "ir" (a)
9550+ : "cc");
9551+
9552+ old = atomic_cmpxchg(v, c, new);
9553 if (likely(old == c))
9554 break;
9555 c = old;
9556@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9557 #define atomic64_cmpxchg(v, o, n) \
9558 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9559 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9560+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9561+{
9562+ return xchg(&v->counter, new);
9563+}
9564
9565 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9566 {
9567- long c, old;
9568+ long c, old, new;
9569 c = atomic64_read(v);
9570 for (;;) {
9571- if (unlikely(c == (u)))
9572+ if (unlikely(c == u))
9573 break;
9574- old = atomic64_cmpxchg((v), c, c + (a));
9575+
9576+ asm volatile("addcc %2, %0, %0\n"
9577+
9578+#ifdef CONFIG_PAX_REFCOUNT
9579+ "tvs %%xcc, 6\n"
9580+#endif
9581+
9582+ : "=r" (new)
9583+ : "0" (c), "ir" (a)
9584+ : "cc");
9585+
9586+ old = atomic64_cmpxchg(v, c, new);
9587 if (likely(old == c))
9588 break;
9589 c = old;
9590 }
9591- return c != (u);
9592+ return c != u;
9593 }
9594
9595 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9596diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9597index 5bb6991..5c2132e 100644
9598--- a/arch/sparc/include/asm/cache.h
9599+++ b/arch/sparc/include/asm/cache.h
9600@@ -7,10 +7,12 @@
9601 #ifndef _SPARC_CACHE_H
9602 #define _SPARC_CACHE_H
9603
9604+#include <linux/const.h>
9605+
9606 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9607
9608 #define L1_CACHE_SHIFT 5
9609-#define L1_CACHE_BYTES 32
9610+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9611
9612 #ifdef CONFIG_SPARC32
9613 #define SMP_CACHE_BYTES_SHIFT 5
9614diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9615index a24e41f..47677ff 100644
9616--- a/arch/sparc/include/asm/elf_32.h
9617+++ b/arch/sparc/include/asm/elf_32.h
9618@@ -114,6 +114,13 @@ typedef struct {
9619
9620 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9621
9622+#ifdef CONFIG_PAX_ASLR
9623+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9624+
9625+#define PAX_DELTA_MMAP_LEN 16
9626+#define PAX_DELTA_STACK_LEN 16
9627+#endif
9628+
9629 /* This yields a mask that user programs can use to figure out what
9630 instruction set this cpu supports. This can NOT be done in userspace
9631 on Sparc. */
9632diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9633index 370ca1e..d4f4a98 100644
9634--- a/arch/sparc/include/asm/elf_64.h
9635+++ b/arch/sparc/include/asm/elf_64.h
9636@@ -189,6 +189,13 @@ typedef struct {
9637 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9638 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9639
9640+#ifdef CONFIG_PAX_ASLR
9641+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9642+
9643+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9644+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9645+#endif
9646+
9647 extern unsigned long sparc64_elf_hwcap;
9648 #define ELF_HWCAP sparc64_elf_hwcap
9649
9650diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9651index 9b1c36d..209298b 100644
9652--- a/arch/sparc/include/asm/pgalloc_32.h
9653+++ b/arch/sparc/include/asm/pgalloc_32.h
9654@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9655 }
9656
9657 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9658+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9659
9660 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9661 unsigned long address)
9662diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9663index bcfe063..b333142 100644
9664--- a/arch/sparc/include/asm/pgalloc_64.h
9665+++ b/arch/sparc/include/asm/pgalloc_64.h
9666@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9667 }
9668
9669 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9670+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9671
9672 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9673 {
9674diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9675index 59ba6f6..4518128 100644
9676--- a/arch/sparc/include/asm/pgtable.h
9677+++ b/arch/sparc/include/asm/pgtable.h
9678@@ -5,4 +5,8 @@
9679 #else
9680 #include <asm/pgtable_32.h>
9681 #endif
9682+
9683+#define ktla_ktva(addr) (addr)
9684+#define ktva_ktla(addr) (addr)
9685+
9686 #endif
9687diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9688index 502f632..da1917f 100644
9689--- a/arch/sparc/include/asm/pgtable_32.h
9690+++ b/arch/sparc/include/asm/pgtable_32.h
9691@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9692 #define PAGE_SHARED SRMMU_PAGE_SHARED
9693 #define PAGE_COPY SRMMU_PAGE_COPY
9694 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9695+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9696+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9697+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9698 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9699
9700 /* Top-level page directory - dummy used by init-mm.
9701@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9702
9703 /* xwr */
9704 #define __P000 PAGE_NONE
9705-#define __P001 PAGE_READONLY
9706-#define __P010 PAGE_COPY
9707-#define __P011 PAGE_COPY
9708+#define __P001 PAGE_READONLY_NOEXEC
9709+#define __P010 PAGE_COPY_NOEXEC
9710+#define __P011 PAGE_COPY_NOEXEC
9711 #define __P100 PAGE_READONLY
9712 #define __P101 PAGE_READONLY
9713 #define __P110 PAGE_COPY
9714 #define __P111 PAGE_COPY
9715
9716 #define __S000 PAGE_NONE
9717-#define __S001 PAGE_READONLY
9718-#define __S010 PAGE_SHARED
9719-#define __S011 PAGE_SHARED
9720+#define __S001 PAGE_READONLY_NOEXEC
9721+#define __S010 PAGE_SHARED_NOEXEC
9722+#define __S011 PAGE_SHARED_NOEXEC
9723 #define __S100 PAGE_READONLY
9724 #define __S101 PAGE_READONLY
9725 #define __S110 PAGE_SHARED
9726diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9727index 79da178..c2eede8 100644
9728--- a/arch/sparc/include/asm/pgtsrmmu.h
9729+++ b/arch/sparc/include/asm/pgtsrmmu.h
9730@@ -115,6 +115,11 @@
9731 SRMMU_EXEC | SRMMU_REF)
9732 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9733 SRMMU_EXEC | SRMMU_REF)
9734+
9735+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9736+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9737+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9738+
9739 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9740 SRMMU_DIRTY | SRMMU_REF)
9741
9742diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9743index 9689176..63c18ea 100644
9744--- a/arch/sparc/include/asm/spinlock_64.h
9745+++ b/arch/sparc/include/asm/spinlock_64.h
9746@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9747
9748 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9749
9750-static void inline arch_read_lock(arch_rwlock_t *lock)
9751+static inline void arch_read_lock(arch_rwlock_t *lock)
9752 {
9753 unsigned long tmp1, tmp2;
9754
9755 __asm__ __volatile__ (
9756 "1: ldsw [%2], %0\n"
9757 " brlz,pn %0, 2f\n"
9758-"4: add %0, 1, %1\n"
9759+"4: addcc %0, 1, %1\n"
9760+
9761+#ifdef CONFIG_PAX_REFCOUNT
9762+" tvs %%icc, 6\n"
9763+#endif
9764+
9765 " cas [%2], %0, %1\n"
9766 " cmp %0, %1\n"
9767 " bne,pn %%icc, 1b\n"
9768@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9769 " .previous"
9770 : "=&r" (tmp1), "=&r" (tmp2)
9771 : "r" (lock)
9772- : "memory");
9773+ : "memory", "cc");
9774 }
9775
9776-static int inline arch_read_trylock(arch_rwlock_t *lock)
9777+static inline int arch_read_trylock(arch_rwlock_t *lock)
9778 {
9779 int tmp1, tmp2;
9780
9781@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9782 "1: ldsw [%2], %0\n"
9783 " brlz,a,pn %0, 2f\n"
9784 " mov 0, %0\n"
9785-" add %0, 1, %1\n"
9786+" addcc %0, 1, %1\n"
9787+
9788+#ifdef CONFIG_PAX_REFCOUNT
9789+" tvs %%icc, 6\n"
9790+#endif
9791+
9792 " cas [%2], %0, %1\n"
9793 " cmp %0, %1\n"
9794 " bne,pn %%icc, 1b\n"
9795@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9796 return tmp1;
9797 }
9798
9799-static void inline arch_read_unlock(arch_rwlock_t *lock)
9800+static inline void arch_read_unlock(arch_rwlock_t *lock)
9801 {
9802 unsigned long tmp1, tmp2;
9803
9804 __asm__ __volatile__(
9805 "1: lduw [%2], %0\n"
9806-" sub %0, 1, %1\n"
9807+" subcc %0, 1, %1\n"
9808+
9809+#ifdef CONFIG_PAX_REFCOUNT
9810+" tvs %%icc, 6\n"
9811+#endif
9812+
9813 " cas [%2], %0, %1\n"
9814 " cmp %0, %1\n"
9815 " bne,pn %%xcc, 1b\n"
9816@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9817 : "memory");
9818 }
9819
9820-static void inline arch_write_lock(arch_rwlock_t *lock)
9821+static inline void arch_write_lock(arch_rwlock_t *lock)
9822 {
9823 unsigned long mask, tmp1, tmp2;
9824
9825@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9826 : "memory");
9827 }
9828
9829-static void inline arch_write_unlock(arch_rwlock_t *lock)
9830+static inline void arch_write_unlock(arch_rwlock_t *lock)
9831 {
9832 __asm__ __volatile__(
9833 " stw %%g0, [%0]"
9834@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9835 : "memory");
9836 }
9837
9838-static int inline arch_write_trylock(arch_rwlock_t *lock)
9839+static inline int arch_write_trylock(arch_rwlock_t *lock)
9840 {
9841 unsigned long mask, tmp1, tmp2, result;
9842
9843diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9844index 96efa7a..16858bf 100644
9845--- a/arch/sparc/include/asm/thread_info_32.h
9846+++ b/arch/sparc/include/asm/thread_info_32.h
9847@@ -49,6 +49,8 @@ struct thread_info {
9848 unsigned long w_saved;
9849
9850 struct restart_block restart_block;
9851+
9852+ unsigned long lowest_stack;
9853 };
9854
9855 /*
9856diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9857index a5f01ac..703b554 100644
9858--- a/arch/sparc/include/asm/thread_info_64.h
9859+++ b/arch/sparc/include/asm/thread_info_64.h
9860@@ -63,6 +63,8 @@ struct thread_info {
9861 struct pt_regs *kern_una_regs;
9862 unsigned int kern_una_insn;
9863
9864+ unsigned long lowest_stack;
9865+
9866 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9867 };
9868
9869@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9870 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9871 /* flag bit 4 is available */
9872 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9873-/* flag bit 6 is available */
9874+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9875 #define TIF_32BIT 7 /* 32-bit binary */
9876 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9877 #define TIF_SECCOMP 9 /* secure computing */
9878 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9879 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9880+
9881 /* NOTE: Thread flags >= 12 should be ones we have no interest
9882 * in using in assembly, else we can't use the mask as
9883 * an immediate value in instructions such as andcc.
9884@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9885 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9886 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9887 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9888+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9889
9890 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9891 _TIF_DO_NOTIFY_RESUME_MASK | \
9892 _TIF_NEED_RESCHED)
9893 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9894
9895+#define _TIF_WORK_SYSCALL \
9896+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9897+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9898+
9899+
9900 /*
9901 * Thread-synchronous status.
9902 *
9903diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9904index 0167d26..767bb0c 100644
9905--- a/arch/sparc/include/asm/uaccess.h
9906+++ b/arch/sparc/include/asm/uaccess.h
9907@@ -1,5 +1,6 @@
9908 #ifndef ___ASM_SPARC_UACCESS_H
9909 #define ___ASM_SPARC_UACCESS_H
9910+
9911 #if defined(__sparc__) && defined(__arch64__)
9912 #include <asm/uaccess_64.h>
9913 #else
9914diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9915index 53a28dd..50c38c3 100644
9916--- a/arch/sparc/include/asm/uaccess_32.h
9917+++ b/arch/sparc/include/asm/uaccess_32.h
9918@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9919
9920 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9921 {
9922- if (n && __access_ok((unsigned long) to, n))
9923+ if ((long)n < 0)
9924+ return n;
9925+
9926+ if (n && __access_ok((unsigned long) to, n)) {
9927+ if (!__builtin_constant_p(n))
9928+ check_object_size(from, n, true);
9929 return __copy_user(to, (__force void __user *) from, n);
9930- else
9931+ } else
9932 return n;
9933 }
9934
9935 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9936 {
9937+ if ((long)n < 0)
9938+ return n;
9939+
9940+ if (!__builtin_constant_p(n))
9941+ check_object_size(from, n, true);
9942+
9943 return __copy_user(to, (__force void __user *) from, n);
9944 }
9945
9946 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9947 {
9948- if (n && __access_ok((unsigned long) from, n))
9949+ if ((long)n < 0)
9950+ return n;
9951+
9952+ if (n && __access_ok((unsigned long) from, n)) {
9953+ if (!__builtin_constant_p(n))
9954+ check_object_size(to, n, false);
9955 return __copy_user((__force void __user *) to, from, n);
9956- else
9957+ } else
9958 return n;
9959 }
9960
9961 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9962 {
9963+ if ((long)n < 0)
9964+ return n;
9965+
9966 return __copy_user((__force void __user *) to, from, n);
9967 }
9968
9969diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9970index ad7e178..c9e7423 100644
9971--- a/arch/sparc/include/asm/uaccess_64.h
9972+++ b/arch/sparc/include/asm/uaccess_64.h
9973@@ -10,6 +10,7 @@
9974 #include <linux/compiler.h>
9975 #include <linux/string.h>
9976 #include <linux/thread_info.h>
9977+#include <linux/kernel.h>
9978 #include <asm/asi.h>
9979 #include <asm/spitfire.h>
9980 #include <asm-generic/uaccess-unaligned.h>
9981@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9982 static inline unsigned long __must_check
9983 copy_from_user(void *to, const void __user *from, unsigned long size)
9984 {
9985- unsigned long ret = ___copy_from_user(to, from, size);
9986+ unsigned long ret;
9987
9988+ if ((long)size < 0 || size > INT_MAX)
9989+ return size;
9990+
9991+ if (!__builtin_constant_p(size))
9992+ check_object_size(to, size, false);
9993+
9994+ ret = ___copy_from_user(to, from, size);
9995 if (unlikely(ret))
9996 ret = copy_from_user_fixup(to, from, size);
9997
9998@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9999 static inline unsigned long __must_check
10000 copy_to_user(void __user *to, const void *from, unsigned long size)
10001 {
10002- unsigned long ret = ___copy_to_user(to, from, size);
10003+ unsigned long ret;
10004
10005+ if ((long)size < 0 || size > INT_MAX)
10006+ return size;
10007+
10008+ if (!__builtin_constant_p(size))
10009+ check_object_size(from, size, true);
10010+
10011+ ret = ___copy_to_user(to, from, size);
10012 if (unlikely(ret))
10013 ret = copy_to_user_fixup(to, from, size);
10014 return ret;
10015diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10016index d15cc17..d0ae796 100644
10017--- a/arch/sparc/kernel/Makefile
10018+++ b/arch/sparc/kernel/Makefile
10019@@ -4,7 +4,7 @@
10020 #
10021
10022 asflags-y := -ansi
10023-ccflags-y := -Werror
10024+#ccflags-y := -Werror
10025
10026 extra-y := head_$(BITS).o
10027
10028diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10029index 510baec..9ff2607 100644
10030--- a/arch/sparc/kernel/process_32.c
10031+++ b/arch/sparc/kernel/process_32.c
10032@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10033
10034 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10035 r->psr, r->pc, r->npc, r->y, print_tainted());
10036- printk("PC: <%pS>\n", (void *) r->pc);
10037+ printk("PC: <%pA>\n", (void *) r->pc);
10038 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10039 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10040 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10041 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10042 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10043 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10044- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10045+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10046
10047 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10048 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10049@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10050 rw = (struct reg_window32 *) fp;
10051 pc = rw->ins[7];
10052 printk("[%08lx : ", pc);
10053- printk("%pS ] ", (void *) pc);
10054+ printk("%pA ] ", (void *) pc);
10055 fp = rw->ins[6];
10056 } while (++count < 16);
10057 printk("\n");
10058diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10059index d7b4967..2edf827 100644
10060--- a/arch/sparc/kernel/process_64.c
10061+++ b/arch/sparc/kernel/process_64.c
10062@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10063 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10064 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10065 if (regs->tstate & TSTATE_PRIV)
10066- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10067+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10068 }
10069
10070 void show_regs(struct pt_regs *regs)
10071@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10072
10073 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10074 regs->tpc, regs->tnpc, regs->y, print_tainted());
10075- printk("TPC: <%pS>\n", (void *) regs->tpc);
10076+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10077 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10078 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10079 regs->u_regs[3]);
10080@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10081 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10082 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10083 regs->u_regs[15]);
10084- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10085+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10086 show_regwindow(regs);
10087 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10088 }
10089@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10090 ((tp && tp->task) ? tp->task->pid : -1));
10091
10092 if (gp->tstate & TSTATE_PRIV) {
10093- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10094+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10095 (void *) gp->tpc,
10096 (void *) gp->o7,
10097 (void *) gp->i7,
10098diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10099index 79cc0d1..ec62734 100644
10100--- a/arch/sparc/kernel/prom_common.c
10101+++ b/arch/sparc/kernel/prom_common.c
10102@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10103
10104 unsigned int prom_early_allocated __initdata;
10105
10106-static struct of_pdt_ops prom_sparc_ops __initdata = {
10107+static struct of_pdt_ops prom_sparc_ops __initconst = {
10108 .nextprop = prom_common_nextprop,
10109 .getproplen = prom_getproplen,
10110 .getproperty = prom_getproperty,
10111diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10112index c13c9f2..d572c34 100644
10113--- a/arch/sparc/kernel/ptrace_64.c
10114+++ b/arch/sparc/kernel/ptrace_64.c
10115@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10116 return ret;
10117 }
10118
10119+#ifdef CONFIG_GRKERNSEC_SETXID
10120+extern void gr_delayed_cred_worker(void);
10121+#endif
10122+
10123 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10124 {
10125 int ret = 0;
10126@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(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 if (test_thread_flag(TIF_SYSCALL_TRACE))
10136 ret = tracehook_report_syscall_entry(regs);
10137
10138@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10139 if (test_thread_flag(TIF_NOHZ))
10140 user_exit();
10141
10142+#ifdef CONFIG_GRKERNSEC_SETXID
10143+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10144+ gr_delayed_cred_worker();
10145+#endif
10146+
10147 audit_syscall_exit(regs);
10148
10149 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10150diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10151index b085311..6f885f7 100644
10152--- a/arch/sparc/kernel/smp_64.c
10153+++ b/arch/sparc/kernel/smp_64.c
10154@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10155 extern unsigned long xcall_flush_dcache_page_spitfire;
10156
10157 #ifdef CONFIG_DEBUG_DCFLUSH
10158-extern atomic_t dcpage_flushes;
10159-extern atomic_t dcpage_flushes_xcall;
10160+extern atomic_unchecked_t dcpage_flushes;
10161+extern atomic_unchecked_t dcpage_flushes_xcall;
10162 #endif
10163
10164 static inline void __local_flush_dcache_page(struct page *page)
10165@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10166 return;
10167
10168 #ifdef CONFIG_DEBUG_DCFLUSH
10169- atomic_inc(&dcpage_flushes);
10170+ atomic_inc_unchecked(&dcpage_flushes);
10171 #endif
10172
10173 this_cpu = get_cpu();
10174@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10175 xcall_deliver(data0, __pa(pg_addr),
10176 (u64) pg_addr, cpumask_of(cpu));
10177 #ifdef CONFIG_DEBUG_DCFLUSH
10178- atomic_inc(&dcpage_flushes_xcall);
10179+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10180 #endif
10181 }
10182 }
10183@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10184 preempt_disable();
10185
10186 #ifdef CONFIG_DEBUG_DCFLUSH
10187- atomic_inc(&dcpage_flushes);
10188+ atomic_inc_unchecked(&dcpage_flushes);
10189 #endif
10190 data0 = 0;
10191 pg_addr = page_address(page);
10192@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10193 xcall_deliver(data0, __pa(pg_addr),
10194 (u64) pg_addr, cpu_online_mask);
10195 #ifdef CONFIG_DEBUG_DCFLUSH
10196- atomic_inc(&dcpage_flushes_xcall);
10197+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10198 #endif
10199 }
10200 __local_flush_dcache_page(page);
10201diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10202index 3a8d184..49498a8 100644
10203--- a/arch/sparc/kernel/sys_sparc_32.c
10204+++ b/arch/sparc/kernel/sys_sparc_32.c
10205@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10206 if (len > TASK_SIZE - PAGE_SIZE)
10207 return -ENOMEM;
10208 if (!addr)
10209- addr = TASK_UNMAPPED_BASE;
10210+ addr = current->mm->mmap_base;
10211
10212 info.flags = 0;
10213 info.length = len;
10214diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10215index beb0b5a..5a153f7 100644
10216--- a/arch/sparc/kernel/sys_sparc_64.c
10217+++ b/arch/sparc/kernel/sys_sparc_64.c
10218@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10219 struct vm_area_struct * vma;
10220 unsigned long task_size = TASK_SIZE;
10221 int do_color_align;
10222+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10223 struct vm_unmapped_area_info info;
10224
10225 if (flags & MAP_FIXED) {
10226 /* We do not accept a shared mapping if it would violate
10227 * cache aliasing constraints.
10228 */
10229- if ((flags & MAP_SHARED) &&
10230+ if ((filp || (flags & MAP_SHARED)) &&
10231 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10232 return -EINVAL;
10233 return addr;
10234@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10235 if (filp || (flags & MAP_SHARED))
10236 do_color_align = 1;
10237
10238+#ifdef CONFIG_PAX_RANDMMAP
10239+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10240+#endif
10241+
10242 if (addr) {
10243 if (do_color_align)
10244 addr = COLOR_ALIGN(addr, pgoff);
10245@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10246 addr = PAGE_ALIGN(addr);
10247
10248 vma = find_vma(mm, addr);
10249- if (task_size - len >= addr &&
10250- (!vma || addr + len <= vma->vm_start))
10251+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10252 return addr;
10253 }
10254
10255 info.flags = 0;
10256 info.length = len;
10257- info.low_limit = TASK_UNMAPPED_BASE;
10258+ info.low_limit = mm->mmap_base;
10259 info.high_limit = min(task_size, VA_EXCLUDE_START);
10260 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10261 info.align_offset = pgoff << PAGE_SHIFT;
10262+ info.threadstack_offset = offset;
10263 addr = vm_unmapped_area(&info);
10264
10265 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10266 VM_BUG_ON(addr != -ENOMEM);
10267 info.low_limit = VA_EXCLUDE_END;
10268+
10269+#ifdef CONFIG_PAX_RANDMMAP
10270+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10271+ info.low_limit += mm->delta_mmap;
10272+#endif
10273+
10274 info.high_limit = task_size;
10275 addr = vm_unmapped_area(&info);
10276 }
10277@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10278 unsigned long task_size = STACK_TOP32;
10279 unsigned long addr = addr0;
10280 int do_color_align;
10281+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10282 struct vm_unmapped_area_info info;
10283
10284 /* This should only ever run for 32-bit processes. */
10285@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10286 /* We do not accept a shared mapping if it would violate
10287 * cache aliasing constraints.
10288 */
10289- if ((flags & MAP_SHARED) &&
10290+ if ((filp || (flags & MAP_SHARED)) &&
10291 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10292 return -EINVAL;
10293 return addr;
10294@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10295 if (filp || (flags & MAP_SHARED))
10296 do_color_align = 1;
10297
10298+#ifdef CONFIG_PAX_RANDMMAP
10299+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10300+#endif
10301+
10302 /* requesting a specific address */
10303 if (addr) {
10304 if (do_color_align)
10305@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10306 addr = PAGE_ALIGN(addr);
10307
10308 vma = find_vma(mm, addr);
10309- if (task_size - len >= addr &&
10310- (!vma || addr + len <= vma->vm_start))
10311+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10312 return addr;
10313 }
10314
10315@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10316 info.high_limit = mm->mmap_base;
10317 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10318 info.align_offset = pgoff << PAGE_SHIFT;
10319+ info.threadstack_offset = offset;
10320 addr = vm_unmapped_area(&info);
10321
10322 /*
10323@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10324 VM_BUG_ON(addr != -ENOMEM);
10325 info.flags = 0;
10326 info.low_limit = TASK_UNMAPPED_BASE;
10327+
10328+#ifdef CONFIG_PAX_RANDMMAP
10329+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10330+ info.low_limit += mm->delta_mmap;
10331+#endif
10332+
10333 info.high_limit = STACK_TOP32;
10334 addr = vm_unmapped_area(&info);
10335 }
10336@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10337 EXPORT_SYMBOL(get_fb_unmapped_area);
10338
10339 /* Essentially the same as PowerPC. */
10340-static unsigned long mmap_rnd(void)
10341+static unsigned long mmap_rnd(struct mm_struct *mm)
10342 {
10343 unsigned long rnd = 0UL;
10344
10345+#ifdef CONFIG_PAX_RANDMMAP
10346+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10347+#endif
10348+
10349 if (current->flags & PF_RANDOMIZE) {
10350 unsigned long val = get_random_int();
10351 if (test_thread_flag(TIF_32BIT))
10352@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10353
10354 void arch_pick_mmap_layout(struct mm_struct *mm)
10355 {
10356- unsigned long random_factor = mmap_rnd();
10357+ unsigned long random_factor = mmap_rnd(mm);
10358 unsigned long gap;
10359
10360 /*
10361@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10362 gap == RLIM_INFINITY ||
10363 sysctl_legacy_va_layout) {
10364 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10365+
10366+#ifdef CONFIG_PAX_RANDMMAP
10367+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10368+ mm->mmap_base += mm->delta_mmap;
10369+#endif
10370+
10371 mm->get_unmapped_area = arch_get_unmapped_area;
10372 } else {
10373 /* We know it's 32-bit */
10374@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10375 gap = (task_size / 6 * 5);
10376
10377 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10378+
10379+#ifdef CONFIG_PAX_RANDMMAP
10380+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10381+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10382+#endif
10383+
10384 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10385 }
10386 }
10387diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10388index 33a17e7..d87fb1f 100644
10389--- a/arch/sparc/kernel/syscalls.S
10390+++ b/arch/sparc/kernel/syscalls.S
10391@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10392 #endif
10393 .align 32
10394 1: ldx [%g6 + TI_FLAGS], %l5
10395- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10396+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10397 be,pt %icc, rtrap
10398 nop
10399 call syscall_trace_leave
10400@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10401
10402 srl %i3, 0, %o3 ! IEU0
10403 srl %i2, 0, %o2 ! IEU0 Group
10404- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10405+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10406 bne,pn %icc, linux_syscall_trace32 ! CTI
10407 mov %i0, %l5 ! IEU1
10408 5: call %l7 ! CTI Group brk forced
10409@@ -208,7 +208,7 @@ linux_sparc_syscall:
10410
10411 mov %i3, %o3 ! IEU1
10412 mov %i4, %o4 ! IEU0 Group
10413- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10414+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10415 bne,pn %icc, linux_syscall_trace ! CTI Group
10416 mov %i0, %l5 ! IEU0
10417 2: call %l7 ! CTI Group brk forced
10418@@ -223,7 +223,7 @@ ret_sys_call:
10419
10420 cmp %o0, -ERESTART_RESTARTBLOCK
10421 bgeu,pn %xcc, 1f
10422- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10423+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10424 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10425
10426 2:
10427diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10428index 6629829..036032d 100644
10429--- a/arch/sparc/kernel/traps_32.c
10430+++ b/arch/sparc/kernel/traps_32.c
10431@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10432 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10433 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10434
10435+extern void gr_handle_kernel_exploit(void);
10436+
10437 void die_if_kernel(char *str, struct pt_regs *regs)
10438 {
10439 static int die_counter;
10440@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10441 count++ < 30 &&
10442 (((unsigned long) rw) >= PAGE_OFFSET) &&
10443 !(((unsigned long) rw) & 0x7)) {
10444- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10445+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10446 (void *) rw->ins[7]);
10447 rw = (struct reg_window32 *)rw->ins[6];
10448 }
10449 }
10450 printk("Instruction DUMP:");
10451 instruction_dump ((unsigned long *) regs->pc);
10452- if(regs->psr & PSR_PS)
10453+ if(regs->psr & PSR_PS) {
10454+ gr_handle_kernel_exploit();
10455 do_exit(SIGKILL);
10456+ }
10457 do_exit(SIGSEGV);
10458 }
10459
10460diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10461index 4ced92f..965eeed 100644
10462--- a/arch/sparc/kernel/traps_64.c
10463+++ b/arch/sparc/kernel/traps_64.c
10464@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10465 i + 1,
10466 p->trapstack[i].tstate, p->trapstack[i].tpc,
10467 p->trapstack[i].tnpc, p->trapstack[i].tt);
10468- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10469+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10470 }
10471 }
10472
10473@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10474
10475 lvl -= 0x100;
10476 if (regs->tstate & TSTATE_PRIV) {
10477+
10478+#ifdef CONFIG_PAX_REFCOUNT
10479+ if (lvl == 6)
10480+ pax_report_refcount_overflow(regs);
10481+#endif
10482+
10483 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10484 die_if_kernel(buffer, regs);
10485 }
10486@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10487 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10488 {
10489 char buffer[32];
10490-
10491+
10492 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10493 0, lvl, SIGTRAP) == NOTIFY_STOP)
10494 return;
10495
10496+#ifdef CONFIG_PAX_REFCOUNT
10497+ if (lvl == 6)
10498+ pax_report_refcount_overflow(regs);
10499+#endif
10500+
10501 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10502
10503 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10504@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10505 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10506 printk("%s" "ERROR(%d): ",
10507 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10508- printk("TPC<%pS>\n", (void *) regs->tpc);
10509+ printk("TPC<%pA>\n", (void *) regs->tpc);
10510 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10511 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10512 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10513@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10514 smp_processor_id(),
10515 (type & 0x1) ? 'I' : 'D',
10516 regs->tpc);
10517- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10518+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10519 panic("Irrecoverable Cheetah+ parity error.");
10520 }
10521
10522@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10523 smp_processor_id(),
10524 (type & 0x1) ? 'I' : 'D',
10525 regs->tpc);
10526- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10527+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10528 }
10529
10530 struct sun4v_error_entry {
10531@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10532 /*0x38*/u64 reserved_5;
10533 };
10534
10535-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10536-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10537+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10538+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10539
10540 static const char *sun4v_err_type_to_str(u8 type)
10541 {
10542@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10543 }
10544
10545 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10546- int cpu, const char *pfx, atomic_t *ocnt)
10547+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10548 {
10549 u64 *raw_ptr = (u64 *) ent;
10550 u32 attrs;
10551@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10552
10553 show_regs(regs);
10554
10555- if ((cnt = atomic_read(ocnt)) != 0) {
10556- atomic_set(ocnt, 0);
10557+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10558+ atomic_set_unchecked(ocnt, 0);
10559 wmb();
10560 printk("%s: Queue overflowed %d times.\n",
10561 pfx, cnt);
10562@@ -2046,7 +2057,7 @@ out:
10563 */
10564 void sun4v_resum_overflow(struct pt_regs *regs)
10565 {
10566- atomic_inc(&sun4v_resum_oflow_cnt);
10567+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10568 }
10569
10570 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10571@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10572 /* XXX Actually even this can make not that much sense. Perhaps
10573 * XXX we should just pull the plug and panic directly from here?
10574 */
10575- atomic_inc(&sun4v_nonresum_oflow_cnt);
10576+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10577 }
10578
10579 unsigned long sun4v_err_itlb_vaddr;
10580@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10581
10582 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10583 regs->tpc, tl);
10584- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10585+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10586 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10587- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10588+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10589 (void *) regs->u_regs[UREG_I7]);
10590 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10591 "pte[%lx] error[%lx]\n",
10592@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10593
10594 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10595 regs->tpc, tl);
10596- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10597+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10598 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10599- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10600+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10601 (void *) regs->u_regs[UREG_I7]);
10602 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10603 "pte[%lx] error[%lx]\n",
10604@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10605 fp = (unsigned long)sf->fp + STACK_BIAS;
10606 }
10607
10608- printk(" [%016lx] %pS\n", pc, (void *) pc);
10609+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10610 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10611 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10612 int index = tsk->curr_ret_stack;
10613 if (tsk->ret_stack && index >= graph) {
10614 pc = tsk->ret_stack[index - graph].ret;
10615- printk(" [%016lx] %pS\n", pc, (void *) pc);
10616+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10617 graph++;
10618 }
10619 }
10620@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10621 return (struct reg_window *) (fp + STACK_BIAS);
10622 }
10623
10624+extern void gr_handle_kernel_exploit(void);
10625+
10626 void die_if_kernel(char *str, struct pt_regs *regs)
10627 {
10628 static int die_counter;
10629@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10630 while (rw &&
10631 count++ < 30 &&
10632 kstack_valid(tp, (unsigned long) rw)) {
10633- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10634+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10635 (void *) rw->ins[7]);
10636
10637 rw = kernel_stack_up(rw);
10638@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10639 }
10640 user_instruction_dump ((unsigned int __user *) regs->tpc);
10641 }
10642- if (regs->tstate & TSTATE_PRIV)
10643+ if (regs->tstate & TSTATE_PRIV) {
10644+ gr_handle_kernel_exploit();
10645 do_exit(SIGKILL);
10646+ }
10647 do_exit(SIGSEGV);
10648 }
10649 EXPORT_SYMBOL(die_if_kernel);
10650diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10651index 3c1a7cb..73e1923 100644
10652--- a/arch/sparc/kernel/unaligned_64.c
10653+++ b/arch/sparc/kernel/unaligned_64.c
10654@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10655 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10656
10657 if (__ratelimit(&ratelimit)) {
10658- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10659+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10660 regs->tpc, (void *) regs->tpc);
10661 }
10662 }
10663diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10664index dbe119b..089c7c1 100644
10665--- a/arch/sparc/lib/Makefile
10666+++ b/arch/sparc/lib/Makefile
10667@@ -2,7 +2,7 @@
10668 #
10669
10670 asflags-y := -ansi -DST_DIV0=0x02
10671-ccflags-y := -Werror
10672+#ccflags-y := -Werror
10673
10674 lib-$(CONFIG_SPARC32) += ashrdi3.o
10675 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10676diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10677index 85c233d..68500e0 100644
10678--- a/arch/sparc/lib/atomic_64.S
10679+++ b/arch/sparc/lib/atomic_64.S
10680@@ -17,7 +17,12 @@
10681 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10682 BACKOFF_SETUP(%o2)
10683 1: lduw [%o1], %g1
10684- add %g1, %o0, %g7
10685+ addcc %g1, %o0, %g7
10686+
10687+#ifdef CONFIG_PAX_REFCOUNT
10688+ tvs %icc, 6
10689+#endif
10690+
10691 cas [%o1], %g1, %g7
10692 cmp %g1, %g7
10693 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10694@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10695 2: BACKOFF_SPIN(%o2, %o3, 1b)
10696 ENDPROC(atomic_add)
10697
10698+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10699+ BACKOFF_SETUP(%o2)
10700+1: lduw [%o1], %g1
10701+ add %g1, %o0, %g7
10702+ cas [%o1], %g1, %g7
10703+ cmp %g1, %g7
10704+ bne,pn %icc, 2f
10705+ nop
10706+ retl
10707+ nop
10708+2: BACKOFF_SPIN(%o2, %o3, 1b)
10709+ENDPROC(atomic_add_unchecked)
10710+
10711 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10712 BACKOFF_SETUP(%o2)
10713 1: lduw [%o1], %g1
10714- sub %g1, %o0, %g7
10715+ subcc %g1, %o0, %g7
10716+
10717+#ifdef CONFIG_PAX_REFCOUNT
10718+ tvs %icc, 6
10719+#endif
10720+
10721 cas [%o1], %g1, %g7
10722 cmp %g1, %g7
10723 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10724@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10725 2: BACKOFF_SPIN(%o2, %o3, 1b)
10726 ENDPROC(atomic_sub)
10727
10728+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10729+ BACKOFF_SETUP(%o2)
10730+1: lduw [%o1], %g1
10731+ sub %g1, %o0, %g7
10732+ cas [%o1], %g1, %g7
10733+ cmp %g1, %g7
10734+ bne,pn %icc, 2f
10735+ nop
10736+ retl
10737+ nop
10738+2: BACKOFF_SPIN(%o2, %o3, 1b)
10739+ENDPROC(atomic_sub_unchecked)
10740+
10741 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10742 BACKOFF_SETUP(%o2)
10743 1: lduw [%o1], %g1
10744- add %g1, %o0, %g7
10745+ addcc %g1, %o0, %g7
10746+
10747+#ifdef CONFIG_PAX_REFCOUNT
10748+ tvs %icc, 6
10749+#endif
10750+
10751 cas [%o1], %g1, %g7
10752 cmp %g1, %g7
10753 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10754@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10755 2: BACKOFF_SPIN(%o2, %o3, 1b)
10756 ENDPROC(atomic_add_ret)
10757
10758+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10759+ BACKOFF_SETUP(%o2)
10760+1: lduw [%o1], %g1
10761+ addcc %g1, %o0, %g7
10762+ cas [%o1], %g1, %g7
10763+ cmp %g1, %g7
10764+ bne,pn %icc, 2f
10765+ add %g7, %o0, %g7
10766+ sra %g7, 0, %o0
10767+ retl
10768+ nop
10769+2: BACKOFF_SPIN(%o2, %o3, 1b)
10770+ENDPROC(atomic_add_ret_unchecked)
10771+
10772 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10773 BACKOFF_SETUP(%o2)
10774 1: lduw [%o1], %g1
10775- sub %g1, %o0, %g7
10776+ subcc %g1, %o0, %g7
10777+
10778+#ifdef CONFIG_PAX_REFCOUNT
10779+ tvs %icc, 6
10780+#endif
10781+
10782 cas [%o1], %g1, %g7
10783 cmp %g1, %g7
10784 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10785@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10786 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10787 BACKOFF_SETUP(%o2)
10788 1: ldx [%o1], %g1
10789- add %g1, %o0, %g7
10790+ addcc %g1, %o0, %g7
10791+
10792+#ifdef CONFIG_PAX_REFCOUNT
10793+ tvs %xcc, 6
10794+#endif
10795+
10796 casx [%o1], %g1, %g7
10797 cmp %g1, %g7
10798 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10799@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10800 2: BACKOFF_SPIN(%o2, %o3, 1b)
10801 ENDPROC(atomic64_add)
10802
10803+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10804+ BACKOFF_SETUP(%o2)
10805+1: ldx [%o1], %g1
10806+ addcc %g1, %o0, %g7
10807+ casx [%o1], %g1, %g7
10808+ cmp %g1, %g7
10809+ bne,pn %xcc, 2f
10810+ nop
10811+ retl
10812+ nop
10813+2: BACKOFF_SPIN(%o2, %o3, 1b)
10814+ENDPROC(atomic64_add_unchecked)
10815+
10816 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10817 BACKOFF_SETUP(%o2)
10818 1: ldx [%o1], %g1
10819- sub %g1, %o0, %g7
10820+ subcc %g1, %o0, %g7
10821+
10822+#ifdef CONFIG_PAX_REFCOUNT
10823+ tvs %xcc, 6
10824+#endif
10825+
10826 casx [%o1], %g1, %g7
10827 cmp %g1, %g7
10828 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10829@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10830 2: BACKOFF_SPIN(%o2, %o3, 1b)
10831 ENDPROC(atomic64_sub)
10832
10833+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10834+ BACKOFF_SETUP(%o2)
10835+1: ldx [%o1], %g1
10836+ subcc %g1, %o0, %g7
10837+ casx [%o1], %g1, %g7
10838+ cmp %g1, %g7
10839+ bne,pn %xcc, 2f
10840+ nop
10841+ retl
10842+ nop
10843+2: BACKOFF_SPIN(%o2, %o3, 1b)
10844+ENDPROC(atomic64_sub_unchecked)
10845+
10846 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10847 BACKOFF_SETUP(%o2)
10848 1: ldx [%o1], %g1
10849- add %g1, %o0, %g7
10850+ addcc %g1, %o0, %g7
10851+
10852+#ifdef CONFIG_PAX_REFCOUNT
10853+ tvs %xcc, 6
10854+#endif
10855+
10856 casx [%o1], %g1, %g7
10857 cmp %g1, %g7
10858 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10859@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10860 2: BACKOFF_SPIN(%o2, %o3, 1b)
10861 ENDPROC(atomic64_add_ret)
10862
10863+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10864+ BACKOFF_SETUP(%o2)
10865+1: ldx [%o1], %g1
10866+ addcc %g1, %o0, %g7
10867+ casx [%o1], %g1, %g7
10868+ cmp %g1, %g7
10869+ bne,pn %xcc, 2f
10870+ add %g7, %o0, %g7
10871+ mov %g7, %o0
10872+ retl
10873+ nop
10874+2: BACKOFF_SPIN(%o2, %o3, 1b)
10875+ENDPROC(atomic64_add_ret_unchecked)
10876+
10877 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10878 BACKOFF_SETUP(%o2)
10879 1: ldx [%o1], %g1
10880- sub %g1, %o0, %g7
10881+ subcc %g1, %o0, %g7
10882+
10883+#ifdef CONFIG_PAX_REFCOUNT
10884+ tvs %xcc, 6
10885+#endif
10886+
10887 casx [%o1], %g1, %g7
10888 cmp %g1, %g7
10889 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10890diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10891index 323335b..ed85ea2 100644
10892--- a/arch/sparc/lib/ksyms.c
10893+++ b/arch/sparc/lib/ksyms.c
10894@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10895
10896 /* Atomic counter implementation. */
10897 EXPORT_SYMBOL(atomic_add);
10898+EXPORT_SYMBOL(atomic_add_unchecked);
10899 EXPORT_SYMBOL(atomic_add_ret);
10900+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10901 EXPORT_SYMBOL(atomic_sub);
10902+EXPORT_SYMBOL(atomic_sub_unchecked);
10903 EXPORT_SYMBOL(atomic_sub_ret);
10904 EXPORT_SYMBOL(atomic64_add);
10905+EXPORT_SYMBOL(atomic64_add_unchecked);
10906 EXPORT_SYMBOL(atomic64_add_ret);
10907+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10908 EXPORT_SYMBOL(atomic64_sub);
10909+EXPORT_SYMBOL(atomic64_sub_unchecked);
10910 EXPORT_SYMBOL(atomic64_sub_ret);
10911 EXPORT_SYMBOL(atomic64_dec_if_positive);
10912
10913diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10914index 30c3ecc..736f015 100644
10915--- a/arch/sparc/mm/Makefile
10916+++ b/arch/sparc/mm/Makefile
10917@@ -2,7 +2,7 @@
10918 #
10919
10920 asflags-y := -ansi
10921-ccflags-y := -Werror
10922+#ccflags-y := -Werror
10923
10924 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10925 obj-y += fault_$(BITS).o
10926diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10927index 59dbd46..1dd7f5e 100644
10928--- a/arch/sparc/mm/fault_32.c
10929+++ b/arch/sparc/mm/fault_32.c
10930@@ -21,6 +21,9 @@
10931 #include <linux/perf_event.h>
10932 #include <linux/interrupt.h>
10933 #include <linux/kdebug.h>
10934+#include <linux/slab.h>
10935+#include <linux/pagemap.h>
10936+#include <linux/compiler.h>
10937
10938 #include <asm/page.h>
10939 #include <asm/pgtable.h>
10940@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10941 return safe_compute_effective_address(regs, insn);
10942 }
10943
10944+#ifdef CONFIG_PAX_PAGEEXEC
10945+#ifdef CONFIG_PAX_DLRESOLVE
10946+static void pax_emuplt_close(struct vm_area_struct *vma)
10947+{
10948+ vma->vm_mm->call_dl_resolve = 0UL;
10949+}
10950+
10951+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10952+{
10953+ unsigned int *kaddr;
10954+
10955+ vmf->page = alloc_page(GFP_HIGHUSER);
10956+ if (!vmf->page)
10957+ return VM_FAULT_OOM;
10958+
10959+ kaddr = kmap(vmf->page);
10960+ memset(kaddr, 0, PAGE_SIZE);
10961+ kaddr[0] = 0x9DE3BFA8U; /* save */
10962+ flush_dcache_page(vmf->page);
10963+ kunmap(vmf->page);
10964+ return VM_FAULT_MAJOR;
10965+}
10966+
10967+static const struct vm_operations_struct pax_vm_ops = {
10968+ .close = pax_emuplt_close,
10969+ .fault = pax_emuplt_fault
10970+};
10971+
10972+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10973+{
10974+ int ret;
10975+
10976+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10977+ vma->vm_mm = current->mm;
10978+ vma->vm_start = addr;
10979+ vma->vm_end = addr + PAGE_SIZE;
10980+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10981+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10982+ vma->vm_ops = &pax_vm_ops;
10983+
10984+ ret = insert_vm_struct(current->mm, vma);
10985+ if (ret)
10986+ return ret;
10987+
10988+ ++current->mm->total_vm;
10989+ return 0;
10990+}
10991+#endif
10992+
10993+/*
10994+ * PaX: decide what to do with offenders (regs->pc = fault address)
10995+ *
10996+ * returns 1 when task should be killed
10997+ * 2 when patched PLT trampoline was detected
10998+ * 3 when unpatched PLT trampoline was detected
10999+ */
11000+static int pax_handle_fetch_fault(struct pt_regs *regs)
11001+{
11002+
11003+#ifdef CONFIG_PAX_EMUPLT
11004+ int err;
11005+
11006+ do { /* PaX: patched PLT emulation #1 */
11007+ unsigned int sethi1, sethi2, jmpl;
11008+
11009+ err = get_user(sethi1, (unsigned int *)regs->pc);
11010+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11011+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11012+
11013+ if (err)
11014+ break;
11015+
11016+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11017+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11018+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11019+ {
11020+ unsigned int addr;
11021+
11022+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11023+ addr = regs->u_regs[UREG_G1];
11024+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11025+ regs->pc = addr;
11026+ regs->npc = addr+4;
11027+ return 2;
11028+ }
11029+ } while (0);
11030+
11031+ do { /* PaX: patched PLT emulation #2 */
11032+ unsigned int ba;
11033+
11034+ err = get_user(ba, (unsigned int *)regs->pc);
11035+
11036+ if (err)
11037+ break;
11038+
11039+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11040+ unsigned int addr;
11041+
11042+ if ((ba & 0xFFC00000U) == 0x30800000U)
11043+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11044+ else
11045+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11046+ regs->pc = addr;
11047+ regs->npc = addr+4;
11048+ return 2;
11049+ }
11050+ } while (0);
11051+
11052+ do { /* PaX: patched PLT emulation #3 */
11053+ unsigned int sethi, bajmpl, nop;
11054+
11055+ err = get_user(sethi, (unsigned int *)regs->pc);
11056+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11057+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11058+
11059+ if (err)
11060+ break;
11061+
11062+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11063+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11064+ nop == 0x01000000U)
11065+ {
11066+ unsigned int addr;
11067+
11068+ addr = (sethi & 0x003FFFFFU) << 10;
11069+ regs->u_regs[UREG_G1] = addr;
11070+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11071+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11072+ else
11073+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11074+ regs->pc = addr;
11075+ regs->npc = addr+4;
11076+ return 2;
11077+ }
11078+ } while (0);
11079+
11080+ do { /* PaX: unpatched PLT emulation step 1 */
11081+ unsigned int sethi, ba, nop;
11082+
11083+ err = get_user(sethi, (unsigned int *)regs->pc);
11084+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11085+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11086+
11087+ if (err)
11088+ break;
11089+
11090+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11091+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11092+ nop == 0x01000000U)
11093+ {
11094+ unsigned int addr, save, call;
11095+
11096+ if ((ba & 0xFFC00000U) == 0x30800000U)
11097+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11098+ else
11099+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11100+
11101+ err = get_user(save, (unsigned int *)addr);
11102+ err |= get_user(call, (unsigned int *)(addr+4));
11103+ err |= get_user(nop, (unsigned int *)(addr+8));
11104+ if (err)
11105+ break;
11106+
11107+#ifdef CONFIG_PAX_DLRESOLVE
11108+ if (save == 0x9DE3BFA8U &&
11109+ (call & 0xC0000000U) == 0x40000000U &&
11110+ nop == 0x01000000U)
11111+ {
11112+ struct vm_area_struct *vma;
11113+ unsigned long call_dl_resolve;
11114+
11115+ down_read(&current->mm->mmap_sem);
11116+ call_dl_resolve = current->mm->call_dl_resolve;
11117+ up_read(&current->mm->mmap_sem);
11118+ if (likely(call_dl_resolve))
11119+ goto emulate;
11120+
11121+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11122+
11123+ down_write(&current->mm->mmap_sem);
11124+ if (current->mm->call_dl_resolve) {
11125+ call_dl_resolve = current->mm->call_dl_resolve;
11126+ up_write(&current->mm->mmap_sem);
11127+ if (vma)
11128+ kmem_cache_free(vm_area_cachep, vma);
11129+ goto emulate;
11130+ }
11131+
11132+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11133+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11134+ up_write(&current->mm->mmap_sem);
11135+ if (vma)
11136+ kmem_cache_free(vm_area_cachep, vma);
11137+ return 1;
11138+ }
11139+
11140+ if (pax_insert_vma(vma, call_dl_resolve)) {
11141+ up_write(&current->mm->mmap_sem);
11142+ kmem_cache_free(vm_area_cachep, vma);
11143+ return 1;
11144+ }
11145+
11146+ current->mm->call_dl_resolve = call_dl_resolve;
11147+ up_write(&current->mm->mmap_sem);
11148+
11149+emulate:
11150+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11151+ regs->pc = call_dl_resolve;
11152+ regs->npc = addr+4;
11153+ return 3;
11154+ }
11155+#endif
11156+
11157+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11158+ if ((save & 0xFFC00000U) == 0x05000000U &&
11159+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11160+ nop == 0x01000000U)
11161+ {
11162+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11163+ regs->u_regs[UREG_G2] = addr + 4;
11164+ addr = (save & 0x003FFFFFU) << 10;
11165+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11166+ regs->pc = addr;
11167+ regs->npc = addr+4;
11168+ return 3;
11169+ }
11170+ }
11171+ } while (0);
11172+
11173+ do { /* PaX: unpatched PLT emulation step 2 */
11174+ unsigned int save, call, nop;
11175+
11176+ err = get_user(save, (unsigned int *)(regs->pc-4));
11177+ err |= get_user(call, (unsigned int *)regs->pc);
11178+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11179+ if (err)
11180+ break;
11181+
11182+ if (save == 0x9DE3BFA8U &&
11183+ (call & 0xC0000000U) == 0x40000000U &&
11184+ nop == 0x01000000U)
11185+ {
11186+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11187+
11188+ regs->u_regs[UREG_RETPC] = regs->pc;
11189+ regs->pc = dl_resolve;
11190+ regs->npc = dl_resolve+4;
11191+ return 3;
11192+ }
11193+ } while (0);
11194+#endif
11195+
11196+ return 1;
11197+}
11198+
11199+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11200+{
11201+ unsigned long i;
11202+
11203+ printk(KERN_ERR "PAX: bytes at PC: ");
11204+ for (i = 0; i < 8; i++) {
11205+ unsigned int c;
11206+ if (get_user(c, (unsigned int *)pc+i))
11207+ printk(KERN_CONT "???????? ");
11208+ else
11209+ printk(KERN_CONT "%08x ", c);
11210+ }
11211+ printk("\n");
11212+}
11213+#endif
11214+
11215 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11216 int text_fault)
11217 {
11218@@ -229,6 +503,24 @@ good_area:
11219 if (!(vma->vm_flags & VM_WRITE))
11220 goto bad_area;
11221 } else {
11222+
11223+#ifdef CONFIG_PAX_PAGEEXEC
11224+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11225+ up_read(&mm->mmap_sem);
11226+ switch (pax_handle_fetch_fault(regs)) {
11227+
11228+#ifdef CONFIG_PAX_EMUPLT
11229+ case 2:
11230+ case 3:
11231+ return;
11232+#endif
11233+
11234+ }
11235+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11236+ do_group_exit(SIGKILL);
11237+ }
11238+#endif
11239+
11240 /* Allow reads even for write-only mappings */
11241 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11242 goto bad_area;
11243diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11244index 69bb818..6ca35c8 100644
11245--- a/arch/sparc/mm/fault_64.c
11246+++ b/arch/sparc/mm/fault_64.c
11247@@ -22,6 +22,9 @@
11248 #include <linux/kdebug.h>
11249 #include <linux/percpu.h>
11250 #include <linux/context_tracking.h>
11251+#include <linux/slab.h>
11252+#include <linux/pagemap.h>
11253+#include <linux/compiler.h>
11254
11255 #include <asm/page.h>
11256 #include <asm/pgtable.h>
11257@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11258 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11259 regs->tpc);
11260 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11261- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11262+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11263 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11264 dump_stack();
11265 unhandled_fault(regs->tpc, current, regs);
11266@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11267 show_regs(regs);
11268 }
11269
11270+#ifdef CONFIG_PAX_PAGEEXEC
11271+#ifdef CONFIG_PAX_DLRESOLVE
11272+static void pax_emuplt_close(struct vm_area_struct *vma)
11273+{
11274+ vma->vm_mm->call_dl_resolve = 0UL;
11275+}
11276+
11277+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11278+{
11279+ unsigned int *kaddr;
11280+
11281+ vmf->page = alloc_page(GFP_HIGHUSER);
11282+ if (!vmf->page)
11283+ return VM_FAULT_OOM;
11284+
11285+ kaddr = kmap(vmf->page);
11286+ memset(kaddr, 0, PAGE_SIZE);
11287+ kaddr[0] = 0x9DE3BFA8U; /* save */
11288+ flush_dcache_page(vmf->page);
11289+ kunmap(vmf->page);
11290+ return VM_FAULT_MAJOR;
11291+}
11292+
11293+static const struct vm_operations_struct pax_vm_ops = {
11294+ .close = pax_emuplt_close,
11295+ .fault = pax_emuplt_fault
11296+};
11297+
11298+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11299+{
11300+ int ret;
11301+
11302+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11303+ vma->vm_mm = current->mm;
11304+ vma->vm_start = addr;
11305+ vma->vm_end = addr + PAGE_SIZE;
11306+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11307+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11308+ vma->vm_ops = &pax_vm_ops;
11309+
11310+ ret = insert_vm_struct(current->mm, vma);
11311+ if (ret)
11312+ return ret;
11313+
11314+ ++current->mm->total_vm;
11315+ return 0;
11316+}
11317+#endif
11318+
11319+/*
11320+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11321+ *
11322+ * returns 1 when task should be killed
11323+ * 2 when patched PLT trampoline was detected
11324+ * 3 when unpatched PLT trampoline was detected
11325+ */
11326+static int pax_handle_fetch_fault(struct pt_regs *regs)
11327+{
11328+
11329+#ifdef CONFIG_PAX_EMUPLT
11330+ int err;
11331+
11332+ do { /* PaX: patched PLT emulation #1 */
11333+ unsigned int sethi1, sethi2, jmpl;
11334+
11335+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11336+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11337+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11338+
11339+ if (err)
11340+ break;
11341+
11342+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11343+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11344+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11345+ {
11346+ unsigned long addr;
11347+
11348+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11349+ addr = regs->u_regs[UREG_G1];
11350+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11351+
11352+ if (test_thread_flag(TIF_32BIT))
11353+ addr &= 0xFFFFFFFFUL;
11354+
11355+ regs->tpc = addr;
11356+ regs->tnpc = addr+4;
11357+ return 2;
11358+ }
11359+ } while (0);
11360+
11361+ do { /* PaX: patched PLT emulation #2 */
11362+ unsigned int ba;
11363+
11364+ err = get_user(ba, (unsigned int *)regs->tpc);
11365+
11366+ if (err)
11367+ break;
11368+
11369+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11370+ unsigned long addr;
11371+
11372+ if ((ba & 0xFFC00000U) == 0x30800000U)
11373+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11374+ else
11375+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11376+
11377+ if (test_thread_flag(TIF_32BIT))
11378+ addr &= 0xFFFFFFFFUL;
11379+
11380+ regs->tpc = addr;
11381+ regs->tnpc = addr+4;
11382+ return 2;
11383+ }
11384+ } while (0);
11385+
11386+ do { /* PaX: patched PLT emulation #3 */
11387+ unsigned int sethi, bajmpl, nop;
11388+
11389+ err = get_user(sethi, (unsigned int *)regs->tpc);
11390+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11391+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11392+
11393+ if (err)
11394+ break;
11395+
11396+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11397+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11398+ nop == 0x01000000U)
11399+ {
11400+ unsigned long addr;
11401+
11402+ addr = (sethi & 0x003FFFFFU) << 10;
11403+ regs->u_regs[UREG_G1] = addr;
11404+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11405+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11406+ else
11407+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11408+
11409+ if (test_thread_flag(TIF_32BIT))
11410+ addr &= 0xFFFFFFFFUL;
11411+
11412+ regs->tpc = addr;
11413+ regs->tnpc = addr+4;
11414+ return 2;
11415+ }
11416+ } while (0);
11417+
11418+ do { /* PaX: patched PLT emulation #4 */
11419+ unsigned int sethi, mov1, call, mov2;
11420+
11421+ err = get_user(sethi, (unsigned int *)regs->tpc);
11422+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11423+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11424+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11425+
11426+ if (err)
11427+ break;
11428+
11429+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11430+ mov1 == 0x8210000FU &&
11431+ (call & 0xC0000000U) == 0x40000000U &&
11432+ mov2 == 0x9E100001U)
11433+ {
11434+ unsigned long addr;
11435+
11436+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11437+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11438+
11439+ if (test_thread_flag(TIF_32BIT))
11440+ addr &= 0xFFFFFFFFUL;
11441+
11442+ regs->tpc = addr;
11443+ regs->tnpc = addr+4;
11444+ return 2;
11445+ }
11446+ } while (0);
11447+
11448+ do { /* PaX: patched PLT emulation #5 */
11449+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11450+
11451+ err = get_user(sethi, (unsigned int *)regs->tpc);
11452+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11453+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11454+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11455+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11456+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11457+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11458+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11459+
11460+ if (err)
11461+ break;
11462+
11463+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11464+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11465+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11466+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11467+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11468+ sllx == 0x83287020U &&
11469+ jmpl == 0x81C04005U &&
11470+ nop == 0x01000000U)
11471+ {
11472+ unsigned long addr;
11473+
11474+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11475+ regs->u_regs[UREG_G1] <<= 32;
11476+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11477+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11478+ regs->tpc = addr;
11479+ regs->tnpc = addr+4;
11480+ return 2;
11481+ }
11482+ } while (0);
11483+
11484+ do { /* PaX: patched PLT emulation #6 */
11485+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11486+
11487+ err = get_user(sethi, (unsigned int *)regs->tpc);
11488+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11489+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11490+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11491+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11492+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11493+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11494+
11495+ if (err)
11496+ break;
11497+
11498+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11499+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11500+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11501+ sllx == 0x83287020U &&
11502+ (or & 0xFFFFE000U) == 0x8A116000U &&
11503+ jmpl == 0x81C04005U &&
11504+ nop == 0x01000000U)
11505+ {
11506+ unsigned long addr;
11507+
11508+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11509+ regs->u_regs[UREG_G1] <<= 32;
11510+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11511+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11512+ regs->tpc = addr;
11513+ regs->tnpc = addr+4;
11514+ return 2;
11515+ }
11516+ } while (0);
11517+
11518+ do { /* PaX: unpatched PLT emulation step 1 */
11519+ unsigned int sethi, ba, nop;
11520+
11521+ err = get_user(sethi, (unsigned int *)regs->tpc);
11522+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11523+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11524+
11525+ if (err)
11526+ break;
11527+
11528+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11529+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11530+ nop == 0x01000000U)
11531+ {
11532+ unsigned long addr;
11533+ unsigned int save, call;
11534+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11535+
11536+ if ((ba & 0xFFC00000U) == 0x30800000U)
11537+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11538+ else
11539+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11540+
11541+ if (test_thread_flag(TIF_32BIT))
11542+ addr &= 0xFFFFFFFFUL;
11543+
11544+ err = get_user(save, (unsigned int *)addr);
11545+ err |= get_user(call, (unsigned int *)(addr+4));
11546+ err |= get_user(nop, (unsigned int *)(addr+8));
11547+ if (err)
11548+ break;
11549+
11550+#ifdef CONFIG_PAX_DLRESOLVE
11551+ if (save == 0x9DE3BFA8U &&
11552+ (call & 0xC0000000U) == 0x40000000U &&
11553+ nop == 0x01000000U)
11554+ {
11555+ struct vm_area_struct *vma;
11556+ unsigned long call_dl_resolve;
11557+
11558+ down_read(&current->mm->mmap_sem);
11559+ call_dl_resolve = current->mm->call_dl_resolve;
11560+ up_read(&current->mm->mmap_sem);
11561+ if (likely(call_dl_resolve))
11562+ goto emulate;
11563+
11564+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11565+
11566+ down_write(&current->mm->mmap_sem);
11567+ if (current->mm->call_dl_resolve) {
11568+ call_dl_resolve = current->mm->call_dl_resolve;
11569+ up_write(&current->mm->mmap_sem);
11570+ if (vma)
11571+ kmem_cache_free(vm_area_cachep, vma);
11572+ goto emulate;
11573+ }
11574+
11575+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11576+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11577+ up_write(&current->mm->mmap_sem);
11578+ if (vma)
11579+ kmem_cache_free(vm_area_cachep, vma);
11580+ return 1;
11581+ }
11582+
11583+ if (pax_insert_vma(vma, call_dl_resolve)) {
11584+ up_write(&current->mm->mmap_sem);
11585+ kmem_cache_free(vm_area_cachep, vma);
11586+ return 1;
11587+ }
11588+
11589+ current->mm->call_dl_resolve = call_dl_resolve;
11590+ up_write(&current->mm->mmap_sem);
11591+
11592+emulate:
11593+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11594+ regs->tpc = call_dl_resolve;
11595+ regs->tnpc = addr+4;
11596+ return 3;
11597+ }
11598+#endif
11599+
11600+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11601+ if ((save & 0xFFC00000U) == 0x05000000U &&
11602+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11603+ nop == 0x01000000U)
11604+ {
11605+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11606+ regs->u_regs[UREG_G2] = addr + 4;
11607+ addr = (save & 0x003FFFFFU) << 10;
11608+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11609+
11610+ if (test_thread_flag(TIF_32BIT))
11611+ addr &= 0xFFFFFFFFUL;
11612+
11613+ regs->tpc = addr;
11614+ regs->tnpc = addr+4;
11615+ return 3;
11616+ }
11617+
11618+ /* PaX: 64-bit PLT stub */
11619+ err = get_user(sethi1, (unsigned int *)addr);
11620+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11621+ err |= get_user(or1, (unsigned int *)(addr+8));
11622+ err |= get_user(or2, (unsigned int *)(addr+12));
11623+ err |= get_user(sllx, (unsigned int *)(addr+16));
11624+ err |= get_user(add, (unsigned int *)(addr+20));
11625+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11626+ err |= get_user(nop, (unsigned int *)(addr+28));
11627+ if (err)
11628+ break;
11629+
11630+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11631+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11632+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11633+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11634+ sllx == 0x89293020U &&
11635+ add == 0x8A010005U &&
11636+ jmpl == 0x89C14000U &&
11637+ nop == 0x01000000U)
11638+ {
11639+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11640+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11641+ regs->u_regs[UREG_G4] <<= 32;
11642+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11643+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11644+ regs->u_regs[UREG_G4] = addr + 24;
11645+ addr = regs->u_regs[UREG_G5];
11646+ regs->tpc = addr;
11647+ regs->tnpc = addr+4;
11648+ return 3;
11649+ }
11650+ }
11651+ } while (0);
11652+
11653+#ifdef CONFIG_PAX_DLRESOLVE
11654+ do { /* PaX: unpatched PLT emulation step 2 */
11655+ unsigned int save, call, nop;
11656+
11657+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11658+ err |= get_user(call, (unsigned int *)regs->tpc);
11659+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11660+ if (err)
11661+ break;
11662+
11663+ if (save == 0x9DE3BFA8U &&
11664+ (call & 0xC0000000U) == 0x40000000U &&
11665+ nop == 0x01000000U)
11666+ {
11667+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11668+
11669+ if (test_thread_flag(TIF_32BIT))
11670+ dl_resolve &= 0xFFFFFFFFUL;
11671+
11672+ regs->u_regs[UREG_RETPC] = regs->tpc;
11673+ regs->tpc = dl_resolve;
11674+ regs->tnpc = dl_resolve+4;
11675+ return 3;
11676+ }
11677+ } while (0);
11678+#endif
11679+
11680+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11681+ unsigned int sethi, ba, nop;
11682+
11683+ err = get_user(sethi, (unsigned int *)regs->tpc);
11684+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11685+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11686+
11687+ if (err)
11688+ break;
11689+
11690+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11691+ (ba & 0xFFF00000U) == 0x30600000U &&
11692+ nop == 0x01000000U)
11693+ {
11694+ unsigned long addr;
11695+
11696+ addr = (sethi & 0x003FFFFFU) << 10;
11697+ regs->u_regs[UREG_G1] = addr;
11698+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11699+
11700+ if (test_thread_flag(TIF_32BIT))
11701+ addr &= 0xFFFFFFFFUL;
11702+
11703+ regs->tpc = addr;
11704+ regs->tnpc = addr+4;
11705+ return 2;
11706+ }
11707+ } while (0);
11708+
11709+#endif
11710+
11711+ return 1;
11712+}
11713+
11714+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11715+{
11716+ unsigned long i;
11717+
11718+ printk(KERN_ERR "PAX: bytes at PC: ");
11719+ for (i = 0; i < 8; i++) {
11720+ unsigned int c;
11721+ if (get_user(c, (unsigned int *)pc+i))
11722+ printk(KERN_CONT "???????? ");
11723+ else
11724+ printk(KERN_CONT "%08x ", c);
11725+ }
11726+ printk("\n");
11727+}
11728+#endif
11729+
11730 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11731 {
11732 enum ctx_state prev_state = exception_enter();
11733@@ -344,6 +807,29 @@ retry:
11734 if (!vma)
11735 goto bad_area;
11736
11737+#ifdef CONFIG_PAX_PAGEEXEC
11738+ /* PaX: detect ITLB misses on non-exec pages */
11739+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11740+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11741+ {
11742+ if (address != regs->tpc)
11743+ goto good_area;
11744+
11745+ up_read(&mm->mmap_sem);
11746+ switch (pax_handle_fetch_fault(regs)) {
11747+
11748+#ifdef CONFIG_PAX_EMUPLT
11749+ case 2:
11750+ case 3:
11751+ return;
11752+#endif
11753+
11754+ }
11755+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11756+ do_group_exit(SIGKILL);
11757+ }
11758+#endif
11759+
11760 /* Pure DTLB misses do not tell us whether the fault causing
11761 * load/store/atomic was a write or not, it only says that there
11762 * was no match. So in such a case we (carefully) read the
11763diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11764index 9bd9ce8..dc84852 100644
11765--- a/arch/sparc/mm/hugetlbpage.c
11766+++ b/arch/sparc/mm/hugetlbpage.c
11767@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11768 unsigned long addr,
11769 unsigned long len,
11770 unsigned long pgoff,
11771- unsigned long flags)
11772+ unsigned long flags,
11773+ unsigned long offset)
11774 {
11775+ struct mm_struct *mm = current->mm;
11776 unsigned long task_size = TASK_SIZE;
11777 struct vm_unmapped_area_info info;
11778
11779@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11780
11781 info.flags = 0;
11782 info.length = len;
11783- info.low_limit = TASK_UNMAPPED_BASE;
11784+ info.low_limit = mm->mmap_base;
11785 info.high_limit = min(task_size, VA_EXCLUDE_START);
11786 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11787 info.align_offset = 0;
11788+ info.threadstack_offset = offset;
11789 addr = vm_unmapped_area(&info);
11790
11791 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11792 VM_BUG_ON(addr != -ENOMEM);
11793 info.low_limit = VA_EXCLUDE_END;
11794+
11795+#ifdef CONFIG_PAX_RANDMMAP
11796+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11797+ info.low_limit += mm->delta_mmap;
11798+#endif
11799+
11800 info.high_limit = task_size;
11801 addr = vm_unmapped_area(&info);
11802 }
11803@@ -55,7 +64,8 @@ static unsigned long
11804 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11805 const unsigned long len,
11806 const unsigned long pgoff,
11807- const unsigned long flags)
11808+ const unsigned long flags,
11809+ const unsigned long offset)
11810 {
11811 struct mm_struct *mm = current->mm;
11812 unsigned long addr = addr0;
11813@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11814 info.high_limit = mm->mmap_base;
11815 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11816 info.align_offset = 0;
11817+ info.threadstack_offset = offset;
11818 addr = vm_unmapped_area(&info);
11819
11820 /*
11821@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11822 VM_BUG_ON(addr != -ENOMEM);
11823 info.flags = 0;
11824 info.low_limit = TASK_UNMAPPED_BASE;
11825+
11826+#ifdef CONFIG_PAX_RANDMMAP
11827+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11828+ info.low_limit += mm->delta_mmap;
11829+#endif
11830+
11831 info.high_limit = STACK_TOP32;
11832 addr = vm_unmapped_area(&info);
11833 }
11834@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11835 struct mm_struct *mm = current->mm;
11836 struct vm_area_struct *vma;
11837 unsigned long task_size = TASK_SIZE;
11838+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11839
11840 if (test_thread_flag(TIF_32BIT))
11841 task_size = STACK_TOP32;
11842@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11843 return addr;
11844 }
11845
11846+#ifdef CONFIG_PAX_RANDMMAP
11847+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11848+#endif
11849+
11850 if (addr) {
11851 addr = ALIGN(addr, HPAGE_SIZE);
11852 vma = find_vma(mm, addr);
11853- if (task_size - len >= addr &&
11854- (!vma || addr + len <= vma->vm_start))
11855+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11856 return addr;
11857 }
11858 if (mm->get_unmapped_area == arch_get_unmapped_area)
11859 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11860- pgoff, flags);
11861+ pgoff, flags, offset);
11862 else
11863 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11864- pgoff, flags);
11865+ pgoff, flags, offset);
11866 }
11867
11868 pte_t *huge_pte_alloc(struct mm_struct *mm,
11869diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11870index eafbc65..5a8070d 100644
11871--- a/arch/sparc/mm/init_64.c
11872+++ b/arch/sparc/mm/init_64.c
11873@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11874 int num_kernel_image_mappings;
11875
11876 #ifdef CONFIG_DEBUG_DCFLUSH
11877-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11878+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11879 #ifdef CONFIG_SMP
11880-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11881+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11882 #endif
11883 #endif
11884
11885@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11886 {
11887 BUG_ON(tlb_type == hypervisor);
11888 #ifdef CONFIG_DEBUG_DCFLUSH
11889- atomic_inc(&dcpage_flushes);
11890+ atomic_inc_unchecked(&dcpage_flushes);
11891 #endif
11892
11893 #ifdef DCACHE_ALIASING_POSSIBLE
11894@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11895
11896 #ifdef CONFIG_DEBUG_DCFLUSH
11897 seq_printf(m, "DCPageFlushes\t: %d\n",
11898- atomic_read(&dcpage_flushes));
11899+ atomic_read_unchecked(&dcpage_flushes));
11900 #ifdef CONFIG_SMP
11901 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11902- atomic_read(&dcpage_flushes_xcall));
11903+ atomic_read_unchecked(&dcpage_flushes_xcall));
11904 #endif /* CONFIG_SMP */
11905 #endif /* CONFIG_DEBUG_DCFLUSH */
11906 }
11907diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11908index b3692ce..e4517c9 100644
11909--- a/arch/tile/Kconfig
11910+++ b/arch/tile/Kconfig
11911@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11912
11913 config KEXEC
11914 bool "kexec system call"
11915+ depends on !GRKERNSEC_KMEM
11916 ---help---
11917 kexec is a system call that implements the ability to shutdown your
11918 current kernel, and to start another kernel. It is like a reboot
11919diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11920index ad220ee..2f537b3 100644
11921--- a/arch/tile/include/asm/atomic_64.h
11922+++ b/arch/tile/include/asm/atomic_64.h
11923@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11924
11925 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11926
11927+#define atomic64_read_unchecked(v) atomic64_read(v)
11928+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11929+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11930+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11931+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11932+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11933+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11934+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11935+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11936+
11937 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11938 #define smp_mb__before_atomic_dec() smp_mb()
11939 #define smp_mb__after_atomic_dec() smp_mb()
11940diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11941index 6160761..00cac88 100644
11942--- a/arch/tile/include/asm/cache.h
11943+++ b/arch/tile/include/asm/cache.h
11944@@ -15,11 +15,12 @@
11945 #ifndef _ASM_TILE_CACHE_H
11946 #define _ASM_TILE_CACHE_H
11947
11948+#include <linux/const.h>
11949 #include <arch/chip.h>
11950
11951 /* bytes per L1 data cache line */
11952 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11953-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11954+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11955
11956 /* bytes per L2 cache line */
11957 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11958diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11959index b6cde32..c0cb736 100644
11960--- a/arch/tile/include/asm/uaccess.h
11961+++ b/arch/tile/include/asm/uaccess.h
11962@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11963 const void __user *from,
11964 unsigned long n)
11965 {
11966- int sz = __compiletime_object_size(to);
11967+ size_t sz = __compiletime_object_size(to);
11968
11969- if (likely(sz == -1 || sz >= n))
11970+ if (likely(sz == (size_t)-1 || sz >= n))
11971 n = _copy_from_user(to, from, n);
11972 else
11973 copy_from_user_overflow();
11974diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11975index 0cb3bba..7338b2d 100644
11976--- a/arch/tile/mm/hugetlbpage.c
11977+++ b/arch/tile/mm/hugetlbpage.c
11978@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11979 info.high_limit = TASK_SIZE;
11980 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11981 info.align_offset = 0;
11982+ info.threadstack_offset = 0;
11983 return vm_unmapped_area(&info);
11984 }
11985
11986@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11987 info.high_limit = current->mm->mmap_base;
11988 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11989 info.align_offset = 0;
11990+ info.threadstack_offset = 0;
11991 addr = vm_unmapped_area(&info);
11992
11993 /*
11994diff --git a/arch/um/Makefile b/arch/um/Makefile
11995index 36e658a..71a5c5a 100644
11996--- a/arch/um/Makefile
11997+++ b/arch/um/Makefile
11998@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11999 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12000 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12001
12002+ifdef CONSTIFY_PLUGIN
12003+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12004+endif
12005+
12006 #This will adjust *FLAGS accordingly to the platform.
12007 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12008
12009diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12010index 19e1bdd..3665b77 100644
12011--- a/arch/um/include/asm/cache.h
12012+++ b/arch/um/include/asm/cache.h
12013@@ -1,6 +1,7 @@
12014 #ifndef __UM_CACHE_H
12015 #define __UM_CACHE_H
12016
12017+#include <linux/const.h>
12018
12019 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12020 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12021@@ -12,6 +13,6 @@
12022 # define L1_CACHE_SHIFT 5
12023 #endif
12024
12025-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12026+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12027
12028 #endif
12029diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12030index 2e0a6b1..a64d0f5 100644
12031--- a/arch/um/include/asm/kmap_types.h
12032+++ b/arch/um/include/asm/kmap_types.h
12033@@ -8,6 +8,6 @@
12034
12035 /* No more #include "asm/arch/kmap_types.h" ! */
12036
12037-#define KM_TYPE_NR 14
12038+#define KM_TYPE_NR 15
12039
12040 #endif
12041diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12042index 5ff53d9..5850cdf 100644
12043--- a/arch/um/include/asm/page.h
12044+++ b/arch/um/include/asm/page.h
12045@@ -14,6 +14,9 @@
12046 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12047 #define PAGE_MASK (~(PAGE_SIZE-1))
12048
12049+#define ktla_ktva(addr) (addr)
12050+#define ktva_ktla(addr) (addr)
12051+
12052 #ifndef __ASSEMBLY__
12053
12054 struct page;
12055diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12056index 0032f92..cd151e0 100644
12057--- a/arch/um/include/asm/pgtable-3level.h
12058+++ b/arch/um/include/asm/pgtable-3level.h
12059@@ -58,6 +58,7 @@
12060 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12061 #define pud_populate(mm, pud, pmd) \
12062 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12063+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12064
12065 #ifdef CONFIG_64BIT
12066 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12067diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12068index eecc414..48adb87 100644
12069--- a/arch/um/kernel/process.c
12070+++ b/arch/um/kernel/process.c
12071@@ -356,22 +356,6 @@ int singlestepping(void * t)
12072 return 2;
12073 }
12074
12075-/*
12076- * Only x86 and x86_64 have an arch_align_stack().
12077- * All other arches have "#define arch_align_stack(x) (x)"
12078- * in their asm/system.h
12079- * As this is included in UML from asm-um/system-generic.h,
12080- * we can use it to behave as the subarch does.
12081- */
12082-#ifndef arch_align_stack
12083-unsigned long arch_align_stack(unsigned long sp)
12084-{
12085- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12086- sp -= get_random_int() % 8192;
12087- return sp & ~0xf;
12088-}
12089-#endif
12090-
12091 unsigned long get_wchan(struct task_struct *p)
12092 {
12093 unsigned long stack_page, sp, ip;
12094diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12095index ad8f795..2c7eec6 100644
12096--- a/arch/unicore32/include/asm/cache.h
12097+++ b/arch/unicore32/include/asm/cache.h
12098@@ -12,8 +12,10 @@
12099 #ifndef __UNICORE_CACHE_H__
12100 #define __UNICORE_CACHE_H__
12101
12102-#define L1_CACHE_SHIFT (5)
12103-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12104+#include <linux/const.h>
12105+
12106+#define L1_CACHE_SHIFT 5
12107+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12108
12109 /*
12110 * Memory returned by kmalloc() may be used for DMA, so we must make
12111diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12112index 0af5250..59f9597 100644
12113--- a/arch/x86/Kconfig
12114+++ b/arch/x86/Kconfig
12115@@ -126,7 +126,7 @@ config X86
12116 select RTC_LIB
12117 select HAVE_DEBUG_STACKOVERFLOW
12118 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12119- select HAVE_CC_STACKPROTECTOR
12120+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12121
12122 config INSTRUCTION_DECODER
12123 def_bool y
12124@@ -251,7 +251,7 @@ config X86_HT
12125
12126 config X86_32_LAZY_GS
12127 def_bool y
12128- depends on X86_32 && !CC_STACKPROTECTOR
12129+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12130
12131 config ARCH_HWEIGHT_CFLAGS
12132 string
12133@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12134
12135 menuconfig HYPERVISOR_GUEST
12136 bool "Linux guest support"
12137+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12138 ---help---
12139 Say Y here to enable options for running Linux under various hyper-
12140 visors. This option enables basic hypervisor detection and platform
12141@@ -1111,7 +1112,7 @@ choice
12142
12143 config NOHIGHMEM
12144 bool "off"
12145- depends on !X86_NUMAQ
12146+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12147 ---help---
12148 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12149 However, the address space of 32-bit x86 processors is only 4
12150@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12151
12152 config HIGHMEM4G
12153 bool "4GB"
12154- depends on !X86_NUMAQ
12155+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12156 ---help---
12157 Select this if you have a 32-bit processor and between 1 and 4
12158 gigabytes of physical RAM.
12159@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12160 hex
12161 default 0xB0000000 if VMSPLIT_3G_OPT
12162 default 0x80000000 if VMSPLIT_2G
12163- default 0x78000000 if VMSPLIT_2G_OPT
12164+ default 0x70000000 if VMSPLIT_2G_OPT
12165 default 0x40000000 if VMSPLIT_1G
12166 default 0xC0000000
12167 depends on X86_32
12168@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12169
12170 config KEXEC
12171 bool "kexec system call"
12172+ depends on !GRKERNSEC_KMEM
12173 ---help---
12174 kexec is a system call that implements the ability to shutdown your
12175 current kernel, and to start another kernel. It is like a reboot
12176@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12177
12178 config PHYSICAL_ALIGN
12179 hex "Alignment value to which kernel should be aligned"
12180- default "0x200000"
12181+ default "0x1000000"
12182+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12183+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12184 range 0x2000 0x1000000 if X86_32
12185 range 0x200000 0x1000000 if X86_64
12186 ---help---
12187@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12188 If unsure, say N.
12189
12190 config COMPAT_VDSO
12191- def_bool y
12192+ def_bool n
12193 prompt "Compat VDSO support"
12194 depends on X86_32 || IA32_EMULATION
12195+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12196 ---help---
12197 Map the 32-bit VDSO to the predictable old-style address too.
12198
12199diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12200index f3aaf23..a1d3c49 100644
12201--- a/arch/x86/Kconfig.cpu
12202+++ b/arch/x86/Kconfig.cpu
12203@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12204
12205 config X86_F00F_BUG
12206 def_bool y
12207- depends on M586MMX || M586TSC || M586 || M486
12208+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12209
12210 config X86_INVD_BUG
12211 def_bool y
12212@@ -327,7 +327,7 @@ config X86_INVD_BUG
12213
12214 config X86_ALIGNMENT_16
12215 def_bool y
12216- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12217+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12218
12219 config X86_INTEL_USERCOPY
12220 def_bool y
12221@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12222 # generates cmov.
12223 config X86_CMOV
12224 def_bool y
12225- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12226+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12227
12228 config X86_MINIMUM_CPU_FAMILY
12229 int
12230diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12231index 321a52c..3d51a5e 100644
12232--- a/arch/x86/Kconfig.debug
12233+++ b/arch/x86/Kconfig.debug
12234@@ -84,7 +84,7 @@ config X86_PTDUMP
12235 config DEBUG_RODATA
12236 bool "Write protect kernel read-only data structures"
12237 default y
12238- depends on DEBUG_KERNEL
12239+ depends on DEBUG_KERNEL && BROKEN
12240 ---help---
12241 Mark the kernel read-only data as write-protected in the pagetables,
12242 in order to catch accidental (and incorrect) writes to such const
12243@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12244
12245 config DEBUG_SET_MODULE_RONX
12246 bool "Set loadable kernel module data as NX and text as RO"
12247- depends on MODULES
12248+ depends on MODULES && BROKEN
12249 ---help---
12250 This option helps catch unintended modifications to loadable
12251 kernel module's text and read-only data. It also prevents execution
12252diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12253index f8842c4..e893775 100644
12254--- a/arch/x86/Makefile
12255+++ b/arch/x86/Makefile
12256@@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12257 # CPU-specific tuning. Anything which can be shared with UML should go here.
12258 include $(srctree)/arch/x86/Makefile_32.cpu
12259 KBUILD_CFLAGS += $(cflags-y)
12260-
12261- # temporary until string.h is fixed
12262- KBUILD_CFLAGS += -ffreestanding
12263 else
12264 BITS := 64
12265 UTS_MACHINE := x86_64
12266 CHECKFLAGS += -D__x86_64__ -m64
12267
12268+ biarch := $(call cc-option,-m64)
12269 KBUILD_AFLAGS += -m64
12270 KBUILD_CFLAGS += -m64
12271
12272@@ -111,6 +109,9 @@ else
12273 KBUILD_CFLAGS += -maccumulate-outgoing-args
12274 endif
12275
12276+# temporary until string.h is fixed
12277+KBUILD_CFLAGS += -ffreestanding
12278+
12279 # Make sure compiler does not have buggy stack-protector support.
12280 ifdef CONFIG_CC_STACKPROTECTOR
12281 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12282@@ -268,3 +269,12 @@ define archhelp
12283 echo ' FDINITRD=file initrd for the booted kernel'
12284 echo ' kvmconfig - Enable additional options for guest kernel support'
12285 endef
12286+
12287+define OLD_LD
12288+
12289+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12290+*** Please upgrade your binutils to 2.18 or newer
12291+endef
12292+
12293+archprepare:
12294+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12295diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12296index 878df7e..a803913 100644
12297--- a/arch/x86/boot/Makefile
12298+++ b/arch/x86/boot/Makefile
12299@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12300 # ---------------------------------------------------------------------------
12301
12302 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12303+ifdef CONSTIFY_PLUGIN
12304+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12305+endif
12306 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12307 GCOV_PROFILE := n
12308
12309diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12310index 878e4b9..20537ab 100644
12311--- a/arch/x86/boot/bitops.h
12312+++ b/arch/x86/boot/bitops.h
12313@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12314 u8 v;
12315 const u32 *p = (const u32 *)addr;
12316
12317- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12318+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12319 return v;
12320 }
12321
12322@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12323
12324 static inline void set_bit(int nr, void *addr)
12325 {
12326- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12327+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12328 }
12329
12330 #endif /* BOOT_BITOPS_H */
12331diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12332index 50f8c5e..4f84fff 100644
12333--- a/arch/x86/boot/boot.h
12334+++ b/arch/x86/boot/boot.h
12335@@ -84,7 +84,7 @@ static inline void io_delay(void)
12336 static inline u16 ds(void)
12337 {
12338 u16 seg;
12339- asm("movw %%ds,%0" : "=rm" (seg));
12340+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12341 return seg;
12342 }
12343
12344@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12345 static inline int memcmp(const void *s1, const void *s2, size_t len)
12346 {
12347 u8 diff;
12348- asm("repe; cmpsb; setnz %0"
12349+ asm volatile("repe; cmpsb; setnz %0"
12350 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12351 return diff;
12352 }
12353diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12354index 0fcd913..3bb5c42 100644
12355--- a/arch/x86/boot/compressed/Makefile
12356+++ b/arch/x86/boot/compressed/Makefile
12357@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12358 KBUILD_CFLAGS += -mno-mmx -mno-sse
12359 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12360 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12361+ifdef CONSTIFY_PLUGIN
12362+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12363+endif
12364
12365 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12366 GCOV_PROFILE := n
12367diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12368index a53440e..c3dbf1e 100644
12369--- a/arch/x86/boot/compressed/efi_stub_32.S
12370+++ b/arch/x86/boot/compressed/efi_stub_32.S
12371@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12372 * parameter 2, ..., param n. To make things easy, we save the return
12373 * address of efi_call_phys in a global variable.
12374 */
12375- popl %ecx
12376- movl %ecx, saved_return_addr(%edx)
12377- /* get the function pointer into ECX*/
12378- popl %ecx
12379- movl %ecx, efi_rt_function_ptr(%edx)
12380+ popl saved_return_addr(%edx)
12381+ popl efi_rt_function_ptr(%edx)
12382
12383 /*
12384 * 3. Call the physical function.
12385 */
12386- call *%ecx
12387+ call *efi_rt_function_ptr(%edx)
12388
12389 /*
12390 * 4. Balance the stack. And because EAX contain the return value,
12391@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12392 1: popl %edx
12393 subl $1b, %edx
12394
12395- movl efi_rt_function_ptr(%edx), %ecx
12396- pushl %ecx
12397+ pushl efi_rt_function_ptr(%edx)
12398
12399 /*
12400 * 10. Push the saved return address onto the stack and return.
12401 */
12402- movl saved_return_addr(%edx), %ecx
12403- pushl %ecx
12404- ret
12405+ jmpl *saved_return_addr(%edx)
12406 ENDPROC(efi_call_phys)
12407 .previous
12408
12409diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12410index f45ab7a..ebc015f 100644
12411--- a/arch/x86/boot/compressed/head_32.S
12412+++ b/arch/x86/boot/compressed/head_32.S
12413@@ -119,10 +119,10 @@ preferred_addr:
12414 addl %eax, %ebx
12415 notl %eax
12416 andl %eax, %ebx
12417- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12418+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12419 jge 1f
12420 #endif
12421- movl $LOAD_PHYSICAL_ADDR, %ebx
12422+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12423 1:
12424
12425 /* Target address to relocate to for decompression */
12426diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12427index b10fa66..5ee0472 100644
12428--- a/arch/x86/boot/compressed/head_64.S
12429+++ b/arch/x86/boot/compressed/head_64.S
12430@@ -94,10 +94,10 @@ ENTRY(startup_32)
12431 addl %eax, %ebx
12432 notl %eax
12433 andl %eax, %ebx
12434- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12435+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12436 jge 1f
12437 #endif
12438- movl $LOAD_PHYSICAL_ADDR, %ebx
12439+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12440 1:
12441
12442 /* Target address to relocate to for decompression */
12443@@ -268,10 +268,10 @@ preferred_addr:
12444 addq %rax, %rbp
12445 notq %rax
12446 andq %rax, %rbp
12447- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12448+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12449 jge 1f
12450 #endif
12451- movq $LOAD_PHYSICAL_ADDR, %rbp
12452+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12453 1:
12454
12455 /* Target address to relocate to for decompression */
12456@@ -363,8 +363,8 @@ gdt:
12457 .long gdt
12458 .word 0
12459 .quad 0x0000000000000000 /* NULL descriptor */
12460- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12461- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12462+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12463+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12464 .quad 0x0080890000000000 /* TS descriptor */
12465 .quad 0x0000000000000000 /* TS continued */
12466 gdt_end:
12467diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12468index 196eaf3..c96716d 100644
12469--- a/arch/x86/boot/compressed/misc.c
12470+++ b/arch/x86/boot/compressed/misc.c
12471@@ -218,7 +218,7 @@ void __putstr(const char *s)
12472
12473 void *memset(void *s, int c, size_t n)
12474 {
12475- int i;
12476+ size_t i;
12477 char *ss = s;
12478
12479 for (i = 0; i < n; i++)
12480@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12481 * Calculate the delta between where vmlinux was linked to load
12482 * and where it was actually loaded.
12483 */
12484- delta = min_addr - LOAD_PHYSICAL_ADDR;
12485+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12486 if (!delta) {
12487 debug_putstr("No relocation needed... ");
12488 return;
12489@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12490 Elf32_Ehdr ehdr;
12491 Elf32_Phdr *phdrs, *phdr;
12492 #endif
12493- void *dest;
12494+ void *dest, *prev;
12495 int i;
12496
12497 memcpy(&ehdr, output, sizeof(ehdr));
12498@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12499 case PT_LOAD:
12500 #ifdef CONFIG_RELOCATABLE
12501 dest = output;
12502- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12503+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12504 #else
12505 dest = (void *)(phdr->p_paddr);
12506 #endif
12507 memcpy(dest,
12508 output + phdr->p_offset,
12509 phdr->p_filesz);
12510+ if (i)
12511+ memset(prev, 0xff, dest - prev);
12512+ prev = dest + phdr->p_filesz;
12513 break;
12514 default: /* Ignore other PT_* */ break;
12515 }
12516@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12517 error("Destination address too large");
12518 #endif
12519 #ifndef CONFIG_RELOCATABLE
12520- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12521+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12522 error("Wrong destination address");
12523 #endif
12524
12525diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12526index 100a9a1..bb3bdb0 100644
12527--- a/arch/x86/boot/cpucheck.c
12528+++ b/arch/x86/boot/cpucheck.c
12529@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12530 u32 ecx = MSR_K7_HWCR;
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 << 15);
12536- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12537+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12538
12539 get_cpuflags(); /* Make sure it really did something */
12540 err = check_cpuflags();
12541@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12542 u32 ecx = MSR_VIA_FCR;
12543 u32 eax, edx;
12544
12545- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12546+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12547 eax |= (1<<1)|(1<<7);
12548- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12549+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12550
12551 set_bit(X86_FEATURE_CX8, cpu.flags);
12552 err = check_cpuflags();
12553@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12554 u32 eax, edx;
12555 u32 level = 1;
12556
12557- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12558- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12559- asm("cpuid"
12560+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12561+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12562+ asm volatile("cpuid"
12563 : "+a" (level), "=d" (cpu.flags[0])
12564 : : "ecx", "ebx");
12565- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12566+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12567
12568 err = check_cpuflags();
12569 }
12570diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12571index ec3b8ba..6a0db1f 100644
12572--- a/arch/x86/boot/header.S
12573+++ b/arch/x86/boot/header.S
12574@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12575 # single linked list of
12576 # struct setup_data
12577
12578-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12579+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12580
12581 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12582+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12583+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12584+#else
12585 #define VO_INIT_SIZE (VO__end - VO__text)
12586+#endif
12587 #if ZO_INIT_SIZE > VO_INIT_SIZE
12588 #define INIT_SIZE ZO_INIT_SIZE
12589 #else
12590diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12591index db75d07..8e6d0af 100644
12592--- a/arch/x86/boot/memory.c
12593+++ b/arch/x86/boot/memory.c
12594@@ -19,7 +19,7 @@
12595
12596 static int detect_memory_e820(void)
12597 {
12598- int count = 0;
12599+ unsigned int count = 0;
12600 struct biosregs ireg, oreg;
12601 struct e820entry *desc = boot_params.e820_map;
12602 static struct e820entry buf; /* static so it is zeroed */
12603diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12604index 11e8c6e..fdbb1ed 100644
12605--- a/arch/x86/boot/video-vesa.c
12606+++ b/arch/x86/boot/video-vesa.c
12607@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12608
12609 boot_params.screen_info.vesapm_seg = oreg.es;
12610 boot_params.screen_info.vesapm_off = oreg.di;
12611+ boot_params.screen_info.vesapm_size = oreg.cx;
12612 }
12613
12614 /*
12615diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12616index 43eda28..5ab5fdb 100644
12617--- a/arch/x86/boot/video.c
12618+++ b/arch/x86/boot/video.c
12619@@ -96,7 +96,7 @@ static void store_mode_params(void)
12620 static unsigned int get_entry(void)
12621 {
12622 char entry_buf[4];
12623- int i, len = 0;
12624+ unsigned int i, len = 0;
12625 int key;
12626 unsigned int v;
12627
12628diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12629index 9105655..41779c1 100644
12630--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12631+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12632@@ -8,6 +8,8 @@
12633 * including this sentence is retained in full.
12634 */
12635
12636+#include <asm/alternative-asm.h>
12637+
12638 .extern crypto_ft_tab
12639 .extern crypto_it_tab
12640 .extern crypto_fl_tab
12641@@ -70,6 +72,8 @@
12642 je B192; \
12643 leaq 32(r9),r9;
12644
12645+#define ret pax_force_retaddr; ret
12646+
12647 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12648 movq r1,r2; \
12649 movq r3,r4; \
12650diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12651index 477e9d7..c92c7d8 100644
12652--- a/arch/x86/crypto/aesni-intel_asm.S
12653+++ b/arch/x86/crypto/aesni-intel_asm.S
12654@@ -31,6 +31,7 @@
12655
12656 #include <linux/linkage.h>
12657 #include <asm/inst.h>
12658+#include <asm/alternative-asm.h>
12659
12660 #ifdef __x86_64__
12661 .data
12662@@ -205,7 +206,7 @@ enc: .octa 0x2
12663 * num_initial_blocks = b mod 4
12664 * encrypt the initial num_initial_blocks blocks and apply ghash on
12665 * the ciphertext
12666-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12667+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12668 * are clobbered
12669 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12670 */
12671@@ -214,8 +215,8 @@ enc: .octa 0x2
12672 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12673 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12674 mov arg7, %r10 # %r10 = AAD
12675- mov arg8, %r12 # %r12 = aadLen
12676- mov %r12, %r11
12677+ mov arg8, %r15 # %r15 = aadLen
12678+ mov %r15, %r11
12679 pxor %xmm\i, %xmm\i
12680 _get_AAD_loop\num_initial_blocks\operation:
12681 movd (%r10), \TMP1
12682@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12683 psrldq $4, %xmm\i
12684 pxor \TMP1, %xmm\i
12685 add $4, %r10
12686- sub $4, %r12
12687+ sub $4, %r15
12688 jne _get_AAD_loop\num_initial_blocks\operation
12689 cmp $16, %r11
12690 je _get_AAD_loop2_done\num_initial_blocks\operation
12691- mov $16, %r12
12692+ mov $16, %r15
12693 _get_AAD_loop2\num_initial_blocks\operation:
12694 psrldq $4, %xmm\i
12695- sub $4, %r12
12696- cmp %r11, %r12
12697+ sub $4, %r15
12698+ cmp %r11, %r15
12699 jne _get_AAD_loop2\num_initial_blocks\operation
12700 _get_AAD_loop2_done\num_initial_blocks\operation:
12701 movdqa SHUF_MASK(%rip), %xmm14
12702@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12703 * num_initial_blocks = b mod 4
12704 * encrypt the initial num_initial_blocks blocks and apply ghash on
12705 * the ciphertext
12706-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12707+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12708 * are clobbered
12709 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12710 */
12711@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12712 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12713 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12714 mov arg7, %r10 # %r10 = AAD
12715- mov arg8, %r12 # %r12 = aadLen
12716- mov %r12, %r11
12717+ mov arg8, %r15 # %r15 = aadLen
12718+ mov %r15, %r11
12719 pxor %xmm\i, %xmm\i
12720 _get_AAD_loop\num_initial_blocks\operation:
12721 movd (%r10), \TMP1
12722@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12723 psrldq $4, %xmm\i
12724 pxor \TMP1, %xmm\i
12725 add $4, %r10
12726- sub $4, %r12
12727+ sub $4, %r15
12728 jne _get_AAD_loop\num_initial_blocks\operation
12729 cmp $16, %r11
12730 je _get_AAD_loop2_done\num_initial_blocks\operation
12731- mov $16, %r12
12732+ mov $16, %r15
12733 _get_AAD_loop2\num_initial_blocks\operation:
12734 psrldq $4, %xmm\i
12735- sub $4, %r12
12736- cmp %r11, %r12
12737+ sub $4, %r15
12738+ cmp %r11, %r15
12739 jne _get_AAD_loop2\num_initial_blocks\operation
12740 _get_AAD_loop2_done\num_initial_blocks\operation:
12741 movdqa SHUF_MASK(%rip), %xmm14
12742@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12743 *
12744 *****************************************************************************/
12745 ENTRY(aesni_gcm_dec)
12746- push %r12
12747+ push %r15
12748 push %r13
12749 push %r14
12750 mov %rsp, %r14
12751@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12752 */
12753 sub $VARIABLE_OFFSET, %rsp
12754 and $~63, %rsp # align rsp to 64 bytes
12755- mov %arg6, %r12
12756- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12757+ mov %arg6, %r15
12758+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12759 movdqa SHUF_MASK(%rip), %xmm2
12760 PSHUFB_XMM %xmm2, %xmm13
12761
12762@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12763 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12764 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12765 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12766- mov %r13, %r12
12767- and $(3<<4), %r12
12768+ mov %r13, %r15
12769+ and $(3<<4), %r15
12770 jz _initial_num_blocks_is_0_decrypt
12771- cmp $(2<<4), %r12
12772+ cmp $(2<<4), %r15
12773 jb _initial_num_blocks_is_1_decrypt
12774 je _initial_num_blocks_is_2_decrypt
12775 _initial_num_blocks_is_3_decrypt:
12776@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12777 sub $16, %r11
12778 add %r13, %r11
12779 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12780- lea SHIFT_MASK+16(%rip), %r12
12781- sub %r13, %r12
12782+ lea SHIFT_MASK+16(%rip), %r15
12783+ sub %r13, %r15
12784 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12785 # (%r13 is the number of bytes in plaintext mod 16)
12786- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12787+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12788 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12789
12790 movdqa %xmm1, %xmm2
12791 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12792- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12793+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12794 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12795 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12796 pand %xmm1, %xmm2
12797@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12798 sub $1, %r13
12799 jne _less_than_8_bytes_left_decrypt
12800 _multiple_of_16_bytes_decrypt:
12801- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12802- shl $3, %r12 # convert into number of bits
12803- movd %r12d, %xmm15 # len(A) in %xmm15
12804+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12805+ shl $3, %r15 # convert into number of bits
12806+ movd %r15d, %xmm15 # len(A) in %xmm15
12807 shl $3, %arg4 # len(C) in bits (*128)
12808 MOVQ_R64_XMM %arg4, %xmm1
12809 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12810@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12811 mov %r14, %rsp
12812 pop %r14
12813 pop %r13
12814- pop %r12
12815+ pop %r15
12816+ pax_force_retaddr
12817 ret
12818 ENDPROC(aesni_gcm_dec)
12819
12820@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12821 * poly = x^128 + x^127 + x^126 + x^121 + 1
12822 ***************************************************************************/
12823 ENTRY(aesni_gcm_enc)
12824- push %r12
12825+ push %r15
12826 push %r13
12827 push %r14
12828 mov %rsp, %r14
12829@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12830 #
12831 sub $VARIABLE_OFFSET, %rsp
12832 and $~63, %rsp
12833- mov %arg6, %r12
12834- movdqu (%r12), %xmm13
12835+ mov %arg6, %r15
12836+ movdqu (%r15), %xmm13
12837 movdqa SHUF_MASK(%rip), %xmm2
12838 PSHUFB_XMM %xmm2, %xmm13
12839
12840@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12841 movdqa %xmm13, HashKey(%rsp)
12842 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12843 and $-16, %r13
12844- mov %r13, %r12
12845+ mov %r13, %r15
12846
12847 # Encrypt first few blocks
12848
12849- and $(3<<4), %r12
12850+ and $(3<<4), %r15
12851 jz _initial_num_blocks_is_0_encrypt
12852- cmp $(2<<4), %r12
12853+ cmp $(2<<4), %r15
12854 jb _initial_num_blocks_is_1_encrypt
12855 je _initial_num_blocks_is_2_encrypt
12856 _initial_num_blocks_is_3_encrypt:
12857@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12858 sub $16, %r11
12859 add %r13, %r11
12860 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12861- lea SHIFT_MASK+16(%rip), %r12
12862- sub %r13, %r12
12863+ lea SHIFT_MASK+16(%rip), %r15
12864+ sub %r13, %r15
12865 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12866 # (%r13 is the number of bytes in plaintext mod 16)
12867- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12868+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12869 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12870 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12871- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12872+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12873 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12874 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12875 movdqa SHUF_MASK(%rip), %xmm10
12876@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12877 sub $1, %r13
12878 jne _less_than_8_bytes_left_encrypt
12879 _multiple_of_16_bytes_encrypt:
12880- mov arg8, %r12 # %r12 = addLen (number of bytes)
12881- shl $3, %r12
12882- movd %r12d, %xmm15 # len(A) in %xmm15
12883+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12884+ shl $3, %r15
12885+ movd %r15d, %xmm15 # len(A) in %xmm15
12886 shl $3, %arg4 # len(C) in bits (*128)
12887 MOVQ_R64_XMM %arg4, %xmm1
12888 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12889@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12890 mov %r14, %rsp
12891 pop %r14
12892 pop %r13
12893- pop %r12
12894+ pop %r15
12895+ pax_force_retaddr
12896 ret
12897 ENDPROC(aesni_gcm_enc)
12898
12899@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12900 pxor %xmm1, %xmm0
12901 movaps %xmm0, (TKEYP)
12902 add $0x10, TKEYP
12903+ pax_force_retaddr
12904 ret
12905 ENDPROC(_key_expansion_128)
12906 ENDPROC(_key_expansion_256a)
12907@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12908 shufps $0b01001110, %xmm2, %xmm1
12909 movaps %xmm1, 0x10(TKEYP)
12910 add $0x20, TKEYP
12911+ pax_force_retaddr
12912 ret
12913 ENDPROC(_key_expansion_192a)
12914
12915@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12916
12917 movaps %xmm0, (TKEYP)
12918 add $0x10, TKEYP
12919+ pax_force_retaddr
12920 ret
12921 ENDPROC(_key_expansion_192b)
12922
12923@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12924 pxor %xmm1, %xmm2
12925 movaps %xmm2, (TKEYP)
12926 add $0x10, TKEYP
12927+ pax_force_retaddr
12928 ret
12929 ENDPROC(_key_expansion_256b)
12930
12931@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12932 #ifndef __x86_64__
12933 popl KEYP
12934 #endif
12935+ pax_force_retaddr
12936 ret
12937 ENDPROC(aesni_set_key)
12938
12939@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12940 popl KLEN
12941 popl KEYP
12942 #endif
12943+ pax_force_retaddr
12944 ret
12945 ENDPROC(aesni_enc)
12946
12947@@ -1974,6 +1983,7 @@ _aesni_enc1:
12948 AESENC KEY STATE
12949 movaps 0x70(TKEYP), KEY
12950 AESENCLAST KEY STATE
12951+ pax_force_retaddr
12952 ret
12953 ENDPROC(_aesni_enc1)
12954
12955@@ -2083,6 +2093,7 @@ _aesni_enc4:
12956 AESENCLAST KEY STATE2
12957 AESENCLAST KEY STATE3
12958 AESENCLAST KEY STATE4
12959+ pax_force_retaddr
12960 ret
12961 ENDPROC(_aesni_enc4)
12962
12963@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12964 popl KLEN
12965 popl KEYP
12966 #endif
12967+ pax_force_retaddr
12968 ret
12969 ENDPROC(aesni_dec)
12970
12971@@ -2164,6 +2176,7 @@ _aesni_dec1:
12972 AESDEC KEY STATE
12973 movaps 0x70(TKEYP), KEY
12974 AESDECLAST KEY STATE
12975+ pax_force_retaddr
12976 ret
12977 ENDPROC(_aesni_dec1)
12978
12979@@ -2273,6 +2286,7 @@ _aesni_dec4:
12980 AESDECLAST KEY STATE2
12981 AESDECLAST KEY STATE3
12982 AESDECLAST KEY STATE4
12983+ pax_force_retaddr
12984 ret
12985 ENDPROC(_aesni_dec4)
12986
12987@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12988 popl KEYP
12989 popl LEN
12990 #endif
12991+ pax_force_retaddr
12992 ret
12993 ENDPROC(aesni_ecb_enc)
12994
12995@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12996 popl KEYP
12997 popl LEN
12998 #endif
12999+ pax_force_retaddr
13000 ret
13001 ENDPROC(aesni_ecb_dec)
13002
13003@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13004 popl LEN
13005 popl IVP
13006 #endif
13007+ pax_force_retaddr
13008 ret
13009 ENDPROC(aesni_cbc_enc)
13010
13011@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13012 popl LEN
13013 popl IVP
13014 #endif
13015+ pax_force_retaddr
13016 ret
13017 ENDPROC(aesni_cbc_dec)
13018
13019@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13020 mov $1, TCTR_LOW
13021 MOVQ_R64_XMM TCTR_LOW INC
13022 MOVQ_R64_XMM CTR TCTR_LOW
13023+ pax_force_retaddr
13024 ret
13025 ENDPROC(_aesni_inc_init)
13026
13027@@ -2579,6 +2598,7 @@ _aesni_inc:
13028 .Linc_low:
13029 movaps CTR, IV
13030 PSHUFB_XMM BSWAP_MASK IV
13031+ pax_force_retaddr
13032 ret
13033 ENDPROC(_aesni_inc)
13034
13035@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13036 .Lctr_enc_ret:
13037 movups IV, (IVP)
13038 .Lctr_enc_just_ret:
13039+ pax_force_retaddr
13040 ret
13041 ENDPROC(aesni_ctr_enc)
13042
13043@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13044 pxor INC, STATE4
13045 movdqu STATE4, 0x70(OUTP)
13046
13047+ pax_force_retaddr
13048 ret
13049 ENDPROC(aesni_xts_crypt8)
13050
13051diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13052index 246c670..466e2d6 100644
13053--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13054+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13055@@ -21,6 +21,7 @@
13056 */
13057
13058 #include <linux/linkage.h>
13059+#include <asm/alternative-asm.h>
13060
13061 .file "blowfish-x86_64-asm.S"
13062 .text
13063@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13064 jnz .L__enc_xor;
13065
13066 write_block();
13067+ pax_force_retaddr
13068 ret;
13069 .L__enc_xor:
13070 xor_block();
13071+ pax_force_retaddr
13072 ret;
13073 ENDPROC(__blowfish_enc_blk)
13074
13075@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13076
13077 movq %r11, %rbp;
13078
13079+ pax_force_retaddr
13080 ret;
13081 ENDPROC(blowfish_dec_blk)
13082
13083@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13084
13085 popq %rbx;
13086 popq %rbp;
13087+ pax_force_retaddr
13088 ret;
13089
13090 .L__enc_xor4:
13091@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13092
13093 popq %rbx;
13094 popq %rbp;
13095+ pax_force_retaddr
13096 ret;
13097 ENDPROC(__blowfish_enc_blk_4way)
13098
13099@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13100 popq %rbx;
13101 popq %rbp;
13102
13103+ pax_force_retaddr
13104 ret;
13105 ENDPROC(blowfish_dec_blk_4way)
13106diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13107index ce71f92..1dce7ec 100644
13108--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13109+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13110@@ -16,6 +16,7 @@
13111 */
13112
13113 #include <linux/linkage.h>
13114+#include <asm/alternative-asm.h>
13115
13116 #define CAMELLIA_TABLE_BYTE_LEN 272
13117
13118@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13119 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13120 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13121 %rcx, (%r9));
13122+ pax_force_retaddr
13123 ret;
13124 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13125
13126@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13127 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13128 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13129 %rax, (%r9));
13130+ pax_force_retaddr
13131 ret;
13132 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13133
13134@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13135 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13136 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13137
13138+ pax_force_retaddr
13139 ret;
13140
13141 .align 8
13142@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13143 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13144 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13145
13146+ pax_force_retaddr
13147 ret;
13148
13149 .align 8
13150@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13151 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13152 %xmm8, %rsi);
13153
13154+ pax_force_retaddr
13155 ret;
13156 ENDPROC(camellia_ecb_enc_16way)
13157
13158@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13159 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13160 %xmm8, %rsi);
13161
13162+ pax_force_retaddr
13163 ret;
13164 ENDPROC(camellia_ecb_dec_16way)
13165
13166@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13167 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13168 %xmm8, %rsi);
13169
13170+ pax_force_retaddr
13171 ret;
13172 ENDPROC(camellia_cbc_dec_16way)
13173
13174@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13175 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13176 %xmm8, %rsi);
13177
13178+ pax_force_retaddr
13179 ret;
13180 ENDPROC(camellia_ctr_16way)
13181
13182@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13183 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13184 %xmm8, %rsi);
13185
13186+ pax_force_retaddr
13187 ret;
13188 ENDPROC(camellia_xts_crypt_16way)
13189
13190diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13191index 0e0b886..5a3123c 100644
13192--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13193+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13194@@ -11,6 +11,7 @@
13195 */
13196
13197 #include <linux/linkage.h>
13198+#include <asm/alternative-asm.h>
13199
13200 #define CAMELLIA_TABLE_BYTE_LEN 272
13201
13202@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13203 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13204 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13205 %rcx, (%r9));
13206+ pax_force_retaddr
13207 ret;
13208 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13209
13210@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13211 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13212 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13213 %rax, (%r9));
13214+ pax_force_retaddr
13215 ret;
13216 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13217
13218@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13219 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13220 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13221
13222+ pax_force_retaddr
13223 ret;
13224
13225 .align 8
13226@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13227 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13228 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13229
13230+ pax_force_retaddr
13231 ret;
13232
13233 .align 8
13234@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13235
13236 vzeroupper;
13237
13238+ pax_force_retaddr
13239 ret;
13240 ENDPROC(camellia_ecb_enc_32way)
13241
13242@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13243
13244 vzeroupper;
13245
13246+ pax_force_retaddr
13247 ret;
13248 ENDPROC(camellia_ecb_dec_32way)
13249
13250@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13251
13252 vzeroupper;
13253
13254+ pax_force_retaddr
13255 ret;
13256 ENDPROC(camellia_cbc_dec_32way)
13257
13258@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13259
13260 vzeroupper;
13261
13262+ pax_force_retaddr
13263 ret;
13264 ENDPROC(camellia_ctr_32way)
13265
13266@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13267
13268 vzeroupper;
13269
13270+ pax_force_retaddr
13271 ret;
13272 ENDPROC(camellia_xts_crypt_32way)
13273
13274diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13275index 310319c..db3d7b5 100644
13276--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13277+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13278@@ -21,6 +21,7 @@
13279 */
13280
13281 #include <linux/linkage.h>
13282+#include <asm/alternative-asm.h>
13283
13284 .file "camellia-x86_64-asm_64.S"
13285 .text
13286@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13287 enc_outunpack(mov, RT1);
13288
13289 movq RRBP, %rbp;
13290+ pax_force_retaddr
13291 ret;
13292
13293 .L__enc_xor:
13294 enc_outunpack(xor, RT1);
13295
13296 movq RRBP, %rbp;
13297+ pax_force_retaddr
13298 ret;
13299 ENDPROC(__camellia_enc_blk)
13300
13301@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13302 dec_outunpack();
13303
13304 movq RRBP, %rbp;
13305+ pax_force_retaddr
13306 ret;
13307 ENDPROC(camellia_dec_blk)
13308
13309@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13310
13311 movq RRBP, %rbp;
13312 popq %rbx;
13313+ pax_force_retaddr
13314 ret;
13315
13316 .L__enc2_xor:
13317@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13318
13319 movq RRBP, %rbp;
13320 popq %rbx;
13321+ pax_force_retaddr
13322 ret;
13323 ENDPROC(__camellia_enc_blk_2way)
13324
13325@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13326
13327 movq RRBP, %rbp;
13328 movq RXOR, %rbx;
13329+ pax_force_retaddr
13330 ret;
13331 ENDPROC(camellia_dec_blk_2way)
13332diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13333index c35fd5d..2d8c7db 100644
13334--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13335+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13336@@ -24,6 +24,7 @@
13337 */
13338
13339 #include <linux/linkage.h>
13340+#include <asm/alternative-asm.h>
13341
13342 .file "cast5-avx-x86_64-asm_64.S"
13343
13344@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13345 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13346 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13347
13348+ pax_force_retaddr
13349 ret;
13350 ENDPROC(__cast5_enc_blk16)
13351
13352@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13353 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13354 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13355
13356+ pax_force_retaddr
13357 ret;
13358
13359 .L__skip_dec:
13360@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13361 vmovdqu RR4, (6*4*4)(%r11);
13362 vmovdqu RL4, (7*4*4)(%r11);
13363
13364+ pax_force_retaddr
13365 ret;
13366 ENDPROC(cast5_ecb_enc_16way)
13367
13368@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13369 vmovdqu RR4, (6*4*4)(%r11);
13370 vmovdqu RL4, (7*4*4)(%r11);
13371
13372+ pax_force_retaddr
13373 ret;
13374 ENDPROC(cast5_ecb_dec_16way)
13375
13376@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13377 * %rdx: src
13378 */
13379
13380- pushq %r12;
13381+ pushq %r14;
13382
13383 movq %rsi, %r11;
13384- movq %rdx, %r12;
13385+ movq %rdx, %r14;
13386
13387 vmovdqu (0*16)(%rdx), RL1;
13388 vmovdqu (1*16)(%rdx), RR1;
13389@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13390 call __cast5_dec_blk16;
13391
13392 /* xor with src */
13393- vmovq (%r12), RX;
13394+ vmovq (%r14), RX;
13395 vpshufd $0x4f, RX, RX;
13396 vpxor RX, RR1, RR1;
13397- vpxor 0*16+8(%r12), RL1, RL1;
13398- vpxor 1*16+8(%r12), RR2, RR2;
13399- vpxor 2*16+8(%r12), RL2, RL2;
13400- vpxor 3*16+8(%r12), RR3, RR3;
13401- vpxor 4*16+8(%r12), RL3, RL3;
13402- vpxor 5*16+8(%r12), RR4, RR4;
13403- vpxor 6*16+8(%r12), RL4, RL4;
13404+ vpxor 0*16+8(%r14), RL1, RL1;
13405+ vpxor 1*16+8(%r14), RR2, RR2;
13406+ vpxor 2*16+8(%r14), RL2, RL2;
13407+ vpxor 3*16+8(%r14), RR3, RR3;
13408+ vpxor 4*16+8(%r14), RL3, RL3;
13409+ vpxor 5*16+8(%r14), RR4, RR4;
13410+ vpxor 6*16+8(%r14), RL4, RL4;
13411
13412 vmovdqu RR1, (0*16)(%r11);
13413 vmovdqu RL1, (1*16)(%r11);
13414@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13415 vmovdqu RR4, (6*16)(%r11);
13416 vmovdqu RL4, (7*16)(%r11);
13417
13418- popq %r12;
13419+ popq %r14;
13420
13421+ pax_force_retaddr
13422 ret;
13423 ENDPROC(cast5_cbc_dec_16way)
13424
13425@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13426 * %rcx: iv (big endian, 64bit)
13427 */
13428
13429- pushq %r12;
13430+ pushq %r14;
13431
13432 movq %rsi, %r11;
13433- movq %rdx, %r12;
13434+ movq %rdx, %r14;
13435
13436 vpcmpeqd RTMP, RTMP, RTMP;
13437 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13438@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13439 call __cast5_enc_blk16;
13440
13441 /* dst = src ^ iv */
13442- vpxor (0*16)(%r12), RR1, RR1;
13443- vpxor (1*16)(%r12), RL1, RL1;
13444- vpxor (2*16)(%r12), RR2, RR2;
13445- vpxor (3*16)(%r12), RL2, RL2;
13446- vpxor (4*16)(%r12), RR3, RR3;
13447- vpxor (5*16)(%r12), RL3, RL3;
13448- vpxor (6*16)(%r12), RR4, RR4;
13449- vpxor (7*16)(%r12), RL4, RL4;
13450+ vpxor (0*16)(%r14), RR1, RR1;
13451+ vpxor (1*16)(%r14), RL1, RL1;
13452+ vpxor (2*16)(%r14), RR2, RR2;
13453+ vpxor (3*16)(%r14), RL2, RL2;
13454+ vpxor (4*16)(%r14), RR3, RR3;
13455+ vpxor (5*16)(%r14), RL3, RL3;
13456+ vpxor (6*16)(%r14), RR4, RR4;
13457+ vpxor (7*16)(%r14), RL4, RL4;
13458 vmovdqu RR1, (0*16)(%r11);
13459 vmovdqu RL1, (1*16)(%r11);
13460 vmovdqu RR2, (2*16)(%r11);
13461@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13462 vmovdqu RR4, (6*16)(%r11);
13463 vmovdqu RL4, (7*16)(%r11);
13464
13465- popq %r12;
13466+ popq %r14;
13467
13468+ pax_force_retaddr
13469 ret;
13470 ENDPROC(cast5_ctr_16way)
13471diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13472index e3531f8..e123f35 100644
13473--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13474+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13475@@ -24,6 +24,7 @@
13476 */
13477
13478 #include <linux/linkage.h>
13479+#include <asm/alternative-asm.h>
13480 #include "glue_helper-asm-avx.S"
13481
13482 .file "cast6-avx-x86_64-asm_64.S"
13483@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13484 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13485 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13486
13487+ pax_force_retaddr
13488 ret;
13489 ENDPROC(__cast6_enc_blk8)
13490
13491@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13492 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13493 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13494
13495+ pax_force_retaddr
13496 ret;
13497 ENDPROC(__cast6_dec_blk8)
13498
13499@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13500
13501 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13502
13503+ pax_force_retaddr
13504 ret;
13505 ENDPROC(cast6_ecb_enc_8way)
13506
13507@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13508
13509 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13510
13511+ pax_force_retaddr
13512 ret;
13513 ENDPROC(cast6_ecb_dec_8way)
13514
13515@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13516 * %rdx: src
13517 */
13518
13519- pushq %r12;
13520+ pushq %r14;
13521
13522 movq %rsi, %r11;
13523- movq %rdx, %r12;
13524+ movq %rdx, %r14;
13525
13526 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13527
13528 call __cast6_dec_blk8;
13529
13530- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13531+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13532
13533- popq %r12;
13534+ popq %r14;
13535
13536+ pax_force_retaddr
13537 ret;
13538 ENDPROC(cast6_cbc_dec_8way)
13539
13540@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13541 * %rcx: iv (little endian, 128bit)
13542 */
13543
13544- pushq %r12;
13545+ pushq %r14;
13546
13547 movq %rsi, %r11;
13548- movq %rdx, %r12;
13549+ movq %rdx, %r14;
13550
13551 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13552 RD2, RX, RKR, RKM);
13553
13554 call __cast6_enc_blk8;
13555
13556- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13557+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13558
13559- popq %r12;
13560+ popq %r14;
13561
13562+ pax_force_retaddr
13563 ret;
13564 ENDPROC(cast6_ctr_8way)
13565
13566@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13567 /* dst <= regs xor IVs(in dst) */
13568 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13569
13570+ pax_force_retaddr
13571 ret;
13572 ENDPROC(cast6_xts_enc_8way)
13573
13574@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13575 /* dst <= regs xor IVs(in dst) */
13576 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13577
13578+ pax_force_retaddr
13579 ret;
13580 ENDPROC(cast6_xts_dec_8way)
13581diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13582index dbc4339..de6e120 100644
13583--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13584+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13585@@ -45,6 +45,7 @@
13586
13587 #include <asm/inst.h>
13588 #include <linux/linkage.h>
13589+#include <asm/alternative-asm.h>
13590
13591 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13592
13593@@ -312,6 +313,7 @@ do_return:
13594 popq %rsi
13595 popq %rdi
13596 popq %rbx
13597+ pax_force_retaddr
13598 ret
13599
13600 ################################################################
13601diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13602index 185fad4..ff4cd36 100644
13603--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13604+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13605@@ -18,6 +18,7 @@
13606
13607 #include <linux/linkage.h>
13608 #include <asm/inst.h>
13609+#include <asm/alternative-asm.h>
13610
13611 .data
13612
13613@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13614 psrlq $1, T2
13615 pxor T2, T1
13616 pxor T1, DATA
13617+ pax_force_retaddr
13618 ret
13619 ENDPROC(__clmul_gf128mul_ble)
13620
13621@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13622 call __clmul_gf128mul_ble
13623 PSHUFB_XMM BSWAP DATA
13624 movups DATA, (%rdi)
13625+ pax_force_retaddr
13626 ret
13627 ENDPROC(clmul_ghash_mul)
13628
13629@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13630 PSHUFB_XMM BSWAP DATA
13631 movups DATA, (%rdi)
13632 .Lupdate_just_ret:
13633+ pax_force_retaddr
13634 ret
13635 ENDPROC(clmul_ghash_update)
13636diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13637index 9279e0b..c4b3d2c 100644
13638--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13639+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13640@@ -1,4 +1,5 @@
13641 #include <linux/linkage.h>
13642+#include <asm/alternative-asm.h>
13643
13644 # enter salsa20_encrypt_bytes
13645 ENTRY(salsa20_encrypt_bytes)
13646@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13647 add %r11,%rsp
13648 mov %rdi,%rax
13649 mov %rsi,%rdx
13650+ pax_force_retaddr
13651 ret
13652 # bytesatleast65:
13653 ._bytesatleast65:
13654@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13655 add %r11,%rsp
13656 mov %rdi,%rax
13657 mov %rsi,%rdx
13658+ pax_force_retaddr
13659 ret
13660 ENDPROC(salsa20_keysetup)
13661
13662@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13663 add %r11,%rsp
13664 mov %rdi,%rax
13665 mov %rsi,%rdx
13666+ pax_force_retaddr
13667 ret
13668 ENDPROC(salsa20_ivsetup)
13669diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13670index 2f202f4..d9164d6 100644
13671--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13672+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13673@@ -24,6 +24,7 @@
13674 */
13675
13676 #include <linux/linkage.h>
13677+#include <asm/alternative-asm.h>
13678 #include "glue_helper-asm-avx.S"
13679
13680 .file "serpent-avx-x86_64-asm_64.S"
13681@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13682 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13683 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13684
13685+ pax_force_retaddr
13686 ret;
13687 ENDPROC(__serpent_enc_blk8_avx)
13688
13689@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13690 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13691 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13692
13693+ pax_force_retaddr
13694 ret;
13695 ENDPROC(__serpent_dec_blk8_avx)
13696
13697@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13698
13699 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13700
13701+ pax_force_retaddr
13702 ret;
13703 ENDPROC(serpent_ecb_enc_8way_avx)
13704
13705@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13706
13707 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13708
13709+ pax_force_retaddr
13710 ret;
13711 ENDPROC(serpent_ecb_dec_8way_avx)
13712
13713@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13714
13715 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13716
13717+ pax_force_retaddr
13718 ret;
13719 ENDPROC(serpent_cbc_dec_8way_avx)
13720
13721@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13722
13723 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13724
13725+ pax_force_retaddr
13726 ret;
13727 ENDPROC(serpent_ctr_8way_avx)
13728
13729@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13730 /* dst <= regs xor IVs(in dst) */
13731 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13732
13733+ pax_force_retaddr
13734 ret;
13735 ENDPROC(serpent_xts_enc_8way_avx)
13736
13737@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13738 /* dst <= regs xor IVs(in dst) */
13739 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13740
13741+ pax_force_retaddr
13742 ret;
13743 ENDPROC(serpent_xts_dec_8way_avx)
13744diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13745index b222085..abd483c 100644
13746--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13747+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13748@@ -15,6 +15,7 @@
13749 */
13750
13751 #include <linux/linkage.h>
13752+#include <asm/alternative-asm.h>
13753 #include "glue_helper-asm-avx2.S"
13754
13755 .file "serpent-avx2-asm_64.S"
13756@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13757 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13758 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13759
13760+ pax_force_retaddr
13761 ret;
13762 ENDPROC(__serpent_enc_blk16)
13763
13764@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13765 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13766 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13767
13768+ pax_force_retaddr
13769 ret;
13770 ENDPROC(__serpent_dec_blk16)
13771
13772@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13773
13774 vzeroupper;
13775
13776+ pax_force_retaddr
13777 ret;
13778 ENDPROC(serpent_ecb_enc_16way)
13779
13780@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13781
13782 vzeroupper;
13783
13784+ pax_force_retaddr
13785 ret;
13786 ENDPROC(serpent_ecb_dec_16way)
13787
13788@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13789
13790 vzeroupper;
13791
13792+ pax_force_retaddr
13793 ret;
13794 ENDPROC(serpent_cbc_dec_16way)
13795
13796@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13797
13798 vzeroupper;
13799
13800+ pax_force_retaddr
13801 ret;
13802 ENDPROC(serpent_ctr_16way)
13803
13804@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13805
13806 vzeroupper;
13807
13808+ pax_force_retaddr
13809 ret;
13810 ENDPROC(serpent_xts_enc_16way)
13811
13812@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13813
13814 vzeroupper;
13815
13816+ pax_force_retaddr
13817 ret;
13818 ENDPROC(serpent_xts_dec_16way)
13819diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13820index acc066c..1559cc4 100644
13821--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13822+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13823@@ -25,6 +25,7 @@
13824 */
13825
13826 #include <linux/linkage.h>
13827+#include <asm/alternative-asm.h>
13828
13829 .file "serpent-sse2-x86_64-asm_64.S"
13830 .text
13831@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13832 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13833 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13834
13835+ pax_force_retaddr
13836 ret;
13837
13838 .L__enc_xor8:
13839 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13840 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13841
13842+ pax_force_retaddr
13843 ret;
13844 ENDPROC(__serpent_enc_blk_8way)
13845
13846@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13847 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13848 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13849
13850+ pax_force_retaddr
13851 ret;
13852 ENDPROC(serpent_dec_blk_8way)
13853diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13854index a410950..9dfe7ad 100644
13855--- a/arch/x86/crypto/sha1_ssse3_asm.S
13856+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13857@@ -29,6 +29,7 @@
13858 */
13859
13860 #include <linux/linkage.h>
13861+#include <asm/alternative-asm.h>
13862
13863 #define CTX %rdi // arg1
13864 #define BUF %rsi // arg2
13865@@ -75,9 +76,9 @@
13866
13867 push %rbx
13868 push %rbp
13869- push %r12
13870+ push %r14
13871
13872- mov %rsp, %r12
13873+ mov %rsp, %r14
13874 sub $64, %rsp # allocate workspace
13875 and $~15, %rsp # align stack
13876
13877@@ -99,11 +100,12 @@
13878 xor %rax, %rax
13879 rep stosq
13880
13881- mov %r12, %rsp # deallocate workspace
13882+ mov %r14, %rsp # deallocate workspace
13883
13884- pop %r12
13885+ pop %r14
13886 pop %rbp
13887 pop %rbx
13888+ pax_force_retaddr
13889 ret
13890
13891 ENDPROC(\name)
13892diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13893index 642f156..51a513c 100644
13894--- a/arch/x86/crypto/sha256-avx-asm.S
13895+++ b/arch/x86/crypto/sha256-avx-asm.S
13896@@ -49,6 +49,7 @@
13897
13898 #ifdef CONFIG_AS_AVX
13899 #include <linux/linkage.h>
13900+#include <asm/alternative-asm.h>
13901
13902 ## assume buffers not aligned
13903 #define VMOVDQ vmovdqu
13904@@ -460,6 +461,7 @@ done_hash:
13905 popq %r13
13906 popq %rbp
13907 popq %rbx
13908+ pax_force_retaddr
13909 ret
13910 ENDPROC(sha256_transform_avx)
13911
13912diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13913index 9e86944..3795e6a 100644
13914--- a/arch/x86/crypto/sha256-avx2-asm.S
13915+++ b/arch/x86/crypto/sha256-avx2-asm.S
13916@@ -50,6 +50,7 @@
13917
13918 #ifdef CONFIG_AS_AVX2
13919 #include <linux/linkage.h>
13920+#include <asm/alternative-asm.h>
13921
13922 ## assume buffers not aligned
13923 #define VMOVDQ vmovdqu
13924@@ -720,6 +721,7 @@ done_hash:
13925 popq %r12
13926 popq %rbp
13927 popq %rbx
13928+ pax_force_retaddr
13929 ret
13930 ENDPROC(sha256_transform_rorx)
13931
13932diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13933index f833b74..8c62a9e 100644
13934--- a/arch/x86/crypto/sha256-ssse3-asm.S
13935+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13936@@ -47,6 +47,7 @@
13937 ########################################################################
13938
13939 #include <linux/linkage.h>
13940+#include <asm/alternative-asm.h>
13941
13942 ## assume buffers not aligned
13943 #define MOVDQ movdqu
13944@@ -471,6 +472,7 @@ done_hash:
13945 popq %rbp
13946 popq %rbx
13947
13948+ pax_force_retaddr
13949 ret
13950 ENDPROC(sha256_transform_ssse3)
13951
13952diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13953index 974dde9..a823ff9 100644
13954--- a/arch/x86/crypto/sha512-avx-asm.S
13955+++ b/arch/x86/crypto/sha512-avx-asm.S
13956@@ -49,6 +49,7 @@
13957
13958 #ifdef CONFIG_AS_AVX
13959 #include <linux/linkage.h>
13960+#include <asm/alternative-asm.h>
13961
13962 .text
13963
13964@@ -364,6 +365,7 @@ updateblock:
13965 mov frame_RSPSAVE(%rsp), %rsp
13966
13967 nowork:
13968+ pax_force_retaddr
13969 ret
13970 ENDPROC(sha512_transform_avx)
13971
13972diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13973index 568b961..ed20c37 100644
13974--- a/arch/x86/crypto/sha512-avx2-asm.S
13975+++ b/arch/x86/crypto/sha512-avx2-asm.S
13976@@ -51,6 +51,7 @@
13977
13978 #ifdef CONFIG_AS_AVX2
13979 #include <linux/linkage.h>
13980+#include <asm/alternative-asm.h>
13981
13982 .text
13983
13984@@ -678,6 +679,7 @@ done_hash:
13985
13986 # Restore Stack Pointer
13987 mov frame_RSPSAVE(%rsp), %rsp
13988+ pax_force_retaddr
13989 ret
13990 ENDPROC(sha512_transform_rorx)
13991
13992diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13993index fb56855..6edd768 100644
13994--- a/arch/x86/crypto/sha512-ssse3-asm.S
13995+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13996@@ -48,6 +48,7 @@
13997 ########################################################################
13998
13999 #include <linux/linkage.h>
14000+#include <asm/alternative-asm.h>
14001
14002 .text
14003
14004@@ -363,6 +364,7 @@ updateblock:
14005 mov frame_RSPSAVE(%rsp), %rsp
14006
14007 nowork:
14008+ pax_force_retaddr
14009 ret
14010 ENDPROC(sha512_transform_ssse3)
14011
14012diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14013index 0505813..b067311 100644
14014--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14015+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14016@@ -24,6 +24,7 @@
14017 */
14018
14019 #include <linux/linkage.h>
14020+#include <asm/alternative-asm.h>
14021 #include "glue_helper-asm-avx.S"
14022
14023 .file "twofish-avx-x86_64-asm_64.S"
14024@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14025 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14026 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14027
14028+ pax_force_retaddr
14029 ret;
14030 ENDPROC(__twofish_enc_blk8)
14031
14032@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14033 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14034 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14035
14036+ pax_force_retaddr
14037 ret;
14038 ENDPROC(__twofish_dec_blk8)
14039
14040@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14041
14042 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14043
14044+ pax_force_retaddr
14045 ret;
14046 ENDPROC(twofish_ecb_enc_8way)
14047
14048@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14049
14050 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14051
14052+ pax_force_retaddr
14053 ret;
14054 ENDPROC(twofish_ecb_dec_8way)
14055
14056@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14057 * %rdx: src
14058 */
14059
14060- pushq %r12;
14061+ pushq %r14;
14062
14063 movq %rsi, %r11;
14064- movq %rdx, %r12;
14065+ movq %rdx, %r14;
14066
14067 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14068
14069 call __twofish_dec_blk8;
14070
14071- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14072+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14073
14074- popq %r12;
14075+ popq %r14;
14076
14077+ pax_force_retaddr
14078 ret;
14079 ENDPROC(twofish_cbc_dec_8way)
14080
14081@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14082 * %rcx: iv (little endian, 128bit)
14083 */
14084
14085- pushq %r12;
14086+ pushq %r14;
14087
14088 movq %rsi, %r11;
14089- movq %rdx, %r12;
14090+ movq %rdx, %r14;
14091
14092 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14093 RD2, RX0, RX1, RY0);
14094
14095 call __twofish_enc_blk8;
14096
14097- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14098+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14099
14100- popq %r12;
14101+ popq %r14;
14102
14103+ pax_force_retaddr
14104 ret;
14105 ENDPROC(twofish_ctr_8way)
14106
14107@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14108 /* dst <= regs xor IVs(in dst) */
14109 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14110
14111+ pax_force_retaddr
14112 ret;
14113 ENDPROC(twofish_xts_enc_8way)
14114
14115@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14116 /* dst <= regs xor IVs(in dst) */
14117 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14118
14119+ pax_force_retaddr
14120 ret;
14121 ENDPROC(twofish_xts_dec_8way)
14122diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14123index 1c3b7ce..02f578d 100644
14124--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14125+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14126@@ -21,6 +21,7 @@
14127 */
14128
14129 #include <linux/linkage.h>
14130+#include <asm/alternative-asm.h>
14131
14132 .file "twofish-x86_64-asm-3way.S"
14133 .text
14134@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14135 popq %r13;
14136 popq %r14;
14137 popq %r15;
14138+ pax_force_retaddr
14139 ret;
14140
14141 .L__enc_xor3:
14142@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14143 popq %r13;
14144 popq %r14;
14145 popq %r15;
14146+ pax_force_retaddr
14147 ret;
14148 ENDPROC(__twofish_enc_blk_3way)
14149
14150@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14151 popq %r13;
14152 popq %r14;
14153 popq %r15;
14154+ pax_force_retaddr
14155 ret;
14156 ENDPROC(twofish_dec_blk_3way)
14157diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14158index a039d21..524b8b2 100644
14159--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14160+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14161@@ -22,6 +22,7 @@
14162
14163 #include <linux/linkage.h>
14164 #include <asm/asm-offsets.h>
14165+#include <asm/alternative-asm.h>
14166
14167 #define a_offset 0
14168 #define b_offset 4
14169@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14170
14171 popq R1
14172 movq $1,%rax
14173+ pax_force_retaddr
14174 ret
14175 ENDPROC(twofish_enc_blk)
14176
14177@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14178
14179 popq R1
14180 movq $1,%rax
14181+ pax_force_retaddr
14182 ret
14183 ENDPROC(twofish_dec_blk)
14184diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14185index d21ff89..6da8e6e 100644
14186--- a/arch/x86/ia32/ia32_aout.c
14187+++ b/arch/x86/ia32/ia32_aout.c
14188@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14189 unsigned long dump_start, dump_size;
14190 struct user32 dump;
14191
14192+ memset(&dump, 0, sizeof(dump));
14193+
14194 fs = get_fs();
14195 set_fs(KERNEL_DS);
14196 has_dumped = 1;
14197diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14198index 2206757..85cbcfa 100644
14199--- a/arch/x86/ia32/ia32_signal.c
14200+++ b/arch/x86/ia32/ia32_signal.c
14201@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14202 if (__get_user(set.sig[0], &frame->sc.oldmask)
14203 || (_COMPAT_NSIG_WORDS > 1
14204 && __copy_from_user((((char *) &set.sig) + 4),
14205- &frame->extramask,
14206+ frame->extramask,
14207 sizeof(frame->extramask))))
14208 goto badframe;
14209
14210@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14211 sp -= frame_size;
14212 /* Align the stack pointer according to the i386 ABI,
14213 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14214- sp = ((sp + 4) & -16ul) - 4;
14215+ sp = ((sp - 12) & -16ul) - 4;
14216 return (void __user *) sp;
14217 }
14218
14219@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14220 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14221 sigreturn);
14222 else
14223- restorer = &frame->retcode;
14224+ restorer = frame->retcode;
14225 }
14226
14227 put_user_try {
14228@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14229 * These are actually not used anymore, but left because some
14230 * gdb versions depend on them as a marker.
14231 */
14232- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14233+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14234 } put_user_catch(err);
14235
14236 if (err)
14237@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14238 0xb8,
14239 __NR_ia32_rt_sigreturn,
14240 0x80cd,
14241- 0,
14242+ 0
14243 };
14244
14245 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14246@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14247
14248 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14249 restorer = ksig->ka.sa.sa_restorer;
14250+ else if (current->mm->context.vdso)
14251+ /* Return stub is in 32bit vsyscall page */
14252+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14253 else
14254- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14255- rt_sigreturn);
14256+ restorer = frame->retcode;
14257 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14258
14259 /*
14260 * Not actually used anymore, but left because some gdb
14261 * versions need it.
14262 */
14263- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14264+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14265 } put_user_catch(err);
14266
14267 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14268diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14269index 4299eb0..c0687a7 100644
14270--- a/arch/x86/ia32/ia32entry.S
14271+++ b/arch/x86/ia32/ia32entry.S
14272@@ -15,8 +15,10 @@
14273 #include <asm/irqflags.h>
14274 #include <asm/asm.h>
14275 #include <asm/smap.h>
14276+#include <asm/pgtable.h>
14277 #include <linux/linkage.h>
14278 #include <linux/err.h>
14279+#include <asm/alternative-asm.h>
14280
14281 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14282 #include <linux/elf-em.h>
14283@@ -62,12 +64,12 @@
14284 */
14285 .macro LOAD_ARGS32 offset, _r9=0
14286 .if \_r9
14287- movl \offset+16(%rsp),%r9d
14288+ movl \offset+R9(%rsp),%r9d
14289 .endif
14290- movl \offset+40(%rsp),%ecx
14291- movl \offset+48(%rsp),%edx
14292- movl \offset+56(%rsp),%esi
14293- movl \offset+64(%rsp),%edi
14294+ movl \offset+RCX(%rsp),%ecx
14295+ movl \offset+RDX(%rsp),%edx
14296+ movl \offset+RSI(%rsp),%esi
14297+ movl \offset+RDI(%rsp),%edi
14298 movl %eax,%eax /* zero extension */
14299 .endm
14300
14301@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14302 ENDPROC(native_irq_enable_sysexit)
14303 #endif
14304
14305+ .macro pax_enter_kernel_user
14306+ pax_set_fptr_mask
14307+#ifdef CONFIG_PAX_MEMORY_UDEREF
14308+ call pax_enter_kernel_user
14309+#endif
14310+ .endm
14311+
14312+ .macro pax_exit_kernel_user
14313+#ifdef CONFIG_PAX_MEMORY_UDEREF
14314+ call pax_exit_kernel_user
14315+#endif
14316+#ifdef CONFIG_PAX_RANDKSTACK
14317+ pushq %rax
14318+ pushq %r11
14319+ call pax_randomize_kstack
14320+ popq %r11
14321+ popq %rax
14322+#endif
14323+ .endm
14324+
14325+ .macro pax_erase_kstack
14326+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14327+ call pax_erase_kstack
14328+#endif
14329+ .endm
14330+
14331 /*
14332 * 32bit SYSENTER instruction entry.
14333 *
14334@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14335 CFI_REGISTER rsp,rbp
14336 SWAPGS_UNSAFE_STACK
14337 movq PER_CPU_VAR(kernel_stack), %rsp
14338- addq $(KERNEL_STACK_OFFSET),%rsp
14339- /*
14340- * No need to follow this irqs on/off section: the syscall
14341- * disabled irqs, here we enable it straight after entry:
14342- */
14343- ENABLE_INTERRUPTS(CLBR_NONE)
14344 movl %ebp,%ebp /* zero extension */
14345 pushq_cfi $__USER32_DS
14346 /*CFI_REL_OFFSET ss,0*/
14347@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14348 CFI_REL_OFFSET rsp,0
14349 pushfq_cfi
14350 /*CFI_REL_OFFSET rflags,0*/
14351- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14352- CFI_REGISTER rip,r10
14353+ orl $X86_EFLAGS_IF,(%rsp)
14354+ GET_THREAD_INFO(%r11)
14355+ movl TI_sysenter_return(%r11), %r11d
14356+ CFI_REGISTER rip,r11
14357 pushq_cfi $__USER32_CS
14358 /*CFI_REL_OFFSET cs,0*/
14359 movl %eax, %eax
14360- pushq_cfi %r10
14361+ pushq_cfi %r11
14362 CFI_REL_OFFSET rip,0
14363 pushq_cfi %rax
14364 cld
14365 SAVE_ARGS 0,1,0
14366+ pax_enter_kernel_user
14367+
14368+#ifdef CONFIG_PAX_RANDKSTACK
14369+ pax_erase_kstack
14370+#endif
14371+
14372+ /*
14373+ * No need to follow this irqs on/off section: the syscall
14374+ * disabled irqs, here we enable it straight after entry:
14375+ */
14376+ ENABLE_INTERRUPTS(CLBR_NONE)
14377 /* no need to do an access_ok check here because rbp has been
14378 32bit zero extended */
14379+
14380+#ifdef CONFIG_PAX_MEMORY_UDEREF
14381+ addq pax_user_shadow_base,%rbp
14382+ ASM_PAX_OPEN_USERLAND
14383+#endif
14384+
14385 ASM_STAC
14386 1: movl (%rbp),%ebp
14387 _ASM_EXTABLE(1b,ia32_badarg)
14388 ASM_CLAC
14389- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14390- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14391+
14392+#ifdef CONFIG_PAX_MEMORY_UDEREF
14393+ ASM_PAX_CLOSE_USERLAND
14394+#endif
14395+
14396+ GET_THREAD_INFO(%r11)
14397+ orl $TS_COMPAT,TI_status(%r11)
14398+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14399 CFI_REMEMBER_STATE
14400 jnz sysenter_tracesys
14401 cmpq $(IA32_NR_syscalls-1),%rax
14402@@ -162,15 +209,18 @@ sysenter_do_call:
14403 sysenter_dispatch:
14404 call *ia32_sys_call_table(,%rax,8)
14405 movq %rax,RAX-ARGOFFSET(%rsp)
14406+ GET_THREAD_INFO(%r11)
14407 DISABLE_INTERRUPTS(CLBR_NONE)
14408 TRACE_IRQS_OFF
14409- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14410+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14411 jnz sysexit_audit
14412 sysexit_from_sys_call:
14413- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14414+ pax_exit_kernel_user
14415+ pax_erase_kstack
14416+ andl $~TS_COMPAT,TI_status(%r11)
14417 /* clear IF, that popfq doesn't enable interrupts early */
14418- andl $~0x200,EFLAGS-R11(%rsp)
14419- movl RIP-R11(%rsp),%edx /* User %eip */
14420+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14421+ movl RIP(%rsp),%edx /* User %eip */
14422 CFI_REGISTER rip,rdx
14423 RESTORE_ARGS 0,24,0,0,0,0
14424 xorq %r8,%r8
14425@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14426 movl %eax,%esi /* 2nd arg: syscall number */
14427 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14428 call __audit_syscall_entry
14429+
14430+ pax_erase_kstack
14431+
14432 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14433 cmpq $(IA32_NR_syscalls-1),%rax
14434 ja ia32_badsys
14435@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14436 .endm
14437
14438 .macro auditsys_exit exit
14439- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14440+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14441 jnz ia32_ret_from_sys_call
14442 TRACE_IRQS_ON
14443 ENABLE_INTERRUPTS(CLBR_NONE)
14444@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14445 1: setbe %al /* 1 if error, 0 if not */
14446 movzbl %al,%edi /* zero-extend that into %edi */
14447 call __audit_syscall_exit
14448+ GET_THREAD_INFO(%r11)
14449 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14450 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14451 DISABLE_INTERRUPTS(CLBR_NONE)
14452 TRACE_IRQS_OFF
14453- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14454+ testl %edi,TI_flags(%r11)
14455 jz \exit
14456 CLEAR_RREGS -ARGOFFSET
14457 jmp int_with_check
14458@@ -237,7 +291,7 @@ sysexit_audit:
14459
14460 sysenter_tracesys:
14461 #ifdef CONFIG_AUDITSYSCALL
14462- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14463+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14464 jz sysenter_auditsys
14465 #endif
14466 SAVE_REST
14467@@ -249,6 +303,9 @@ sysenter_tracesys:
14468 RESTORE_REST
14469 cmpq $(IA32_NR_syscalls-1),%rax
14470 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14471+
14472+ pax_erase_kstack
14473+
14474 jmp sysenter_do_call
14475 CFI_ENDPROC
14476 ENDPROC(ia32_sysenter_target)
14477@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14478 ENTRY(ia32_cstar_target)
14479 CFI_STARTPROC32 simple
14480 CFI_SIGNAL_FRAME
14481- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14482+ CFI_DEF_CFA rsp,0
14483 CFI_REGISTER rip,rcx
14484 /*CFI_REGISTER rflags,r11*/
14485 SWAPGS_UNSAFE_STACK
14486 movl %esp,%r8d
14487 CFI_REGISTER rsp,r8
14488 movq PER_CPU_VAR(kernel_stack),%rsp
14489+ SAVE_ARGS 8*6,0,0
14490+ pax_enter_kernel_user
14491+
14492+#ifdef CONFIG_PAX_RANDKSTACK
14493+ pax_erase_kstack
14494+#endif
14495+
14496 /*
14497 * No need to follow this irqs on/off section: the syscall
14498 * disabled irqs and here we enable it straight after entry:
14499 */
14500 ENABLE_INTERRUPTS(CLBR_NONE)
14501- SAVE_ARGS 8,0,0
14502 movl %eax,%eax /* zero extension */
14503 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14504 movq %rcx,RIP-ARGOFFSET(%rsp)
14505@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14506 /* no need to do an access_ok check here because r8 has been
14507 32bit zero extended */
14508 /* hardware stack frame is complete now */
14509+
14510+#ifdef CONFIG_PAX_MEMORY_UDEREF
14511+ ASM_PAX_OPEN_USERLAND
14512+ movq pax_user_shadow_base,%r8
14513+ addq RSP-ARGOFFSET(%rsp),%r8
14514+#endif
14515+
14516 ASM_STAC
14517 1: movl (%r8),%r9d
14518 _ASM_EXTABLE(1b,ia32_badarg)
14519 ASM_CLAC
14520- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14521- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14522+
14523+#ifdef CONFIG_PAX_MEMORY_UDEREF
14524+ ASM_PAX_CLOSE_USERLAND
14525+#endif
14526+
14527+ GET_THREAD_INFO(%r11)
14528+ orl $TS_COMPAT,TI_status(%r11)
14529+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14530 CFI_REMEMBER_STATE
14531 jnz cstar_tracesys
14532 cmpq $IA32_NR_syscalls-1,%rax
14533@@ -319,13 +395,16 @@ cstar_do_call:
14534 cstar_dispatch:
14535 call *ia32_sys_call_table(,%rax,8)
14536 movq %rax,RAX-ARGOFFSET(%rsp)
14537+ GET_THREAD_INFO(%r11)
14538 DISABLE_INTERRUPTS(CLBR_NONE)
14539 TRACE_IRQS_OFF
14540- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14541+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14542 jnz sysretl_audit
14543 sysretl_from_sys_call:
14544- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14545- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14546+ pax_exit_kernel_user
14547+ pax_erase_kstack
14548+ andl $~TS_COMPAT,TI_status(%r11)
14549+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14550 movl RIP-ARGOFFSET(%rsp),%ecx
14551 CFI_REGISTER rip,rcx
14552 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14553@@ -352,7 +431,7 @@ sysretl_audit:
14554
14555 cstar_tracesys:
14556 #ifdef CONFIG_AUDITSYSCALL
14557- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14558+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14559 jz cstar_auditsys
14560 #endif
14561 xchgl %r9d,%ebp
14562@@ -366,11 +445,19 @@ cstar_tracesys:
14563 xchgl %ebp,%r9d
14564 cmpq $(IA32_NR_syscalls-1),%rax
14565 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14566+
14567+ pax_erase_kstack
14568+
14569 jmp cstar_do_call
14570 END(ia32_cstar_target)
14571
14572 ia32_badarg:
14573 ASM_CLAC
14574+
14575+#ifdef CONFIG_PAX_MEMORY_UDEREF
14576+ ASM_PAX_CLOSE_USERLAND
14577+#endif
14578+
14579 movq $-EFAULT,%rax
14580 jmp ia32_sysret
14581 CFI_ENDPROC
14582@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14583 CFI_REL_OFFSET rip,RIP-RIP
14584 PARAVIRT_ADJUST_EXCEPTION_FRAME
14585 SWAPGS
14586- /*
14587- * No need to follow this irqs on/off section: the syscall
14588- * disabled irqs and here we enable it straight after entry:
14589- */
14590- ENABLE_INTERRUPTS(CLBR_NONE)
14591 movl %eax,%eax
14592 pushq_cfi %rax
14593 cld
14594 /* note the registers are not zero extended to the sf.
14595 this could be a problem. */
14596 SAVE_ARGS 0,1,0
14597- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14598- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14599+ pax_enter_kernel_user
14600+
14601+#ifdef CONFIG_PAX_RANDKSTACK
14602+ pax_erase_kstack
14603+#endif
14604+
14605+ /*
14606+ * No need to follow this irqs on/off section: the syscall
14607+ * disabled irqs and here we enable it straight after entry:
14608+ */
14609+ ENABLE_INTERRUPTS(CLBR_NONE)
14610+ GET_THREAD_INFO(%r11)
14611+ orl $TS_COMPAT,TI_status(%r11)
14612+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14613 jnz ia32_tracesys
14614 cmpq $(IA32_NR_syscalls-1),%rax
14615 ja ia32_badsys
14616@@ -442,6 +536,9 @@ ia32_tracesys:
14617 RESTORE_REST
14618 cmpq $(IA32_NR_syscalls-1),%rax
14619 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14620+
14621+ pax_erase_kstack
14622+
14623 jmp ia32_do_call
14624 END(ia32_syscall)
14625
14626diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14627index 8e0ceec..af13504 100644
14628--- a/arch/x86/ia32/sys_ia32.c
14629+++ b/arch/x86/ia32/sys_ia32.c
14630@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14631 */
14632 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14633 {
14634- typeof(ubuf->st_uid) uid = 0;
14635- typeof(ubuf->st_gid) gid = 0;
14636+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14637+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14638 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14639 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14640 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14641diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14642index 372231c..51b537d 100644
14643--- a/arch/x86/include/asm/alternative-asm.h
14644+++ b/arch/x86/include/asm/alternative-asm.h
14645@@ -18,6 +18,45 @@
14646 .endm
14647 #endif
14648
14649+#ifdef KERNEXEC_PLUGIN
14650+ .macro pax_force_retaddr_bts rip=0
14651+ btsq $63,\rip(%rsp)
14652+ .endm
14653+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14654+ .macro pax_force_retaddr rip=0, reload=0
14655+ btsq $63,\rip(%rsp)
14656+ .endm
14657+ .macro pax_force_fptr ptr
14658+ btsq $63,\ptr
14659+ .endm
14660+ .macro pax_set_fptr_mask
14661+ .endm
14662+#endif
14663+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14664+ .macro pax_force_retaddr rip=0, reload=0
14665+ .if \reload
14666+ pax_set_fptr_mask
14667+ .endif
14668+ orq %r12,\rip(%rsp)
14669+ .endm
14670+ .macro pax_force_fptr ptr
14671+ orq %r12,\ptr
14672+ .endm
14673+ .macro pax_set_fptr_mask
14674+ movabs $0x8000000000000000,%r12
14675+ .endm
14676+#endif
14677+#else
14678+ .macro pax_force_retaddr rip=0, reload=0
14679+ .endm
14680+ .macro pax_force_fptr ptr
14681+ .endm
14682+ .macro pax_force_retaddr_bts rip=0
14683+ .endm
14684+ .macro pax_set_fptr_mask
14685+ .endm
14686+#endif
14687+
14688 .macro altinstruction_entry orig alt feature orig_len alt_len
14689 .long \orig - .
14690 .long \alt - .
14691diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14692index 0a3f9c9..c9d081d 100644
14693--- a/arch/x86/include/asm/alternative.h
14694+++ b/arch/x86/include/asm/alternative.h
14695@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14696 ".pushsection .discard,\"aw\",@progbits\n" \
14697 DISCARD_ENTRY(1) \
14698 ".popsection\n" \
14699- ".pushsection .altinstr_replacement, \"ax\"\n" \
14700+ ".pushsection .altinstr_replacement, \"a\"\n" \
14701 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14702 ".popsection"
14703
14704@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14705 DISCARD_ENTRY(1) \
14706 DISCARD_ENTRY(2) \
14707 ".popsection\n" \
14708- ".pushsection .altinstr_replacement, \"ax\"\n" \
14709+ ".pushsection .altinstr_replacement, \"a\"\n" \
14710 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14711 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14712 ".popsection"
14713diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14714index 1d2091a..f5074c1 100644
14715--- a/arch/x86/include/asm/apic.h
14716+++ b/arch/x86/include/asm/apic.h
14717@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14718
14719 #ifdef CONFIG_X86_LOCAL_APIC
14720
14721-extern unsigned int apic_verbosity;
14722+extern int apic_verbosity;
14723 extern int local_apic_timer_c2_ok;
14724
14725 extern int disable_apic;
14726diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14727index 20370c6..a2eb9b0 100644
14728--- a/arch/x86/include/asm/apm.h
14729+++ b/arch/x86/include/asm/apm.h
14730@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14731 __asm__ __volatile__(APM_DO_ZERO_SEGS
14732 "pushl %%edi\n\t"
14733 "pushl %%ebp\n\t"
14734- "lcall *%%cs:apm_bios_entry\n\t"
14735+ "lcall *%%ss:apm_bios_entry\n\t"
14736 "setc %%al\n\t"
14737 "popl %%ebp\n\t"
14738 "popl %%edi\n\t"
14739@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14740 __asm__ __volatile__(APM_DO_ZERO_SEGS
14741 "pushl %%edi\n\t"
14742 "pushl %%ebp\n\t"
14743- "lcall *%%cs:apm_bios_entry\n\t"
14744+ "lcall *%%ss:apm_bios_entry\n\t"
14745 "setc %%bl\n\t"
14746 "popl %%ebp\n\t"
14747 "popl %%edi\n\t"
14748diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14749index b17f4f4..9620151 100644
14750--- a/arch/x86/include/asm/atomic.h
14751+++ b/arch/x86/include/asm/atomic.h
14752@@ -23,7 +23,18 @@
14753 */
14754 static inline int atomic_read(const atomic_t *v)
14755 {
14756- return (*(volatile int *)&(v)->counter);
14757+ return (*(volatile const int *)&(v)->counter);
14758+}
14759+
14760+/**
14761+ * atomic_read_unchecked - read atomic variable
14762+ * @v: pointer of type atomic_unchecked_t
14763+ *
14764+ * Atomically reads the value of @v.
14765+ */
14766+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14767+{
14768+ return (*(volatile const int *)&(v)->counter);
14769 }
14770
14771 /**
14772@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14773 }
14774
14775 /**
14776+ * atomic_set_unchecked - set atomic variable
14777+ * @v: pointer of type atomic_unchecked_t
14778+ * @i: required value
14779+ *
14780+ * Atomically sets the value of @v to @i.
14781+ */
14782+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14783+{
14784+ v->counter = i;
14785+}
14786+
14787+/**
14788 * atomic_add - add integer to atomic variable
14789 * @i: integer value to add
14790 * @v: pointer of type atomic_t
14791@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14792 */
14793 static inline void atomic_add(int i, atomic_t *v)
14794 {
14795- asm volatile(LOCK_PREFIX "addl %1,%0"
14796+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14797+
14798+#ifdef CONFIG_PAX_REFCOUNT
14799+ "jno 0f\n"
14800+ LOCK_PREFIX "subl %1,%0\n"
14801+ "int $4\n0:\n"
14802+ _ASM_EXTABLE(0b, 0b)
14803+#endif
14804+
14805+ : "+m" (v->counter)
14806+ : "ir" (i));
14807+}
14808+
14809+/**
14810+ * atomic_add_unchecked - add integer to atomic variable
14811+ * @i: integer value to add
14812+ * @v: pointer of type atomic_unchecked_t
14813+ *
14814+ * Atomically adds @i to @v.
14815+ */
14816+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14817+{
14818+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14819 : "+m" (v->counter)
14820 : "ir" (i));
14821 }
14822@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14823 */
14824 static inline void atomic_sub(int i, atomic_t *v)
14825 {
14826- asm volatile(LOCK_PREFIX "subl %1,%0"
14827+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14828+
14829+#ifdef CONFIG_PAX_REFCOUNT
14830+ "jno 0f\n"
14831+ LOCK_PREFIX "addl %1,%0\n"
14832+ "int $4\n0:\n"
14833+ _ASM_EXTABLE(0b, 0b)
14834+#endif
14835+
14836+ : "+m" (v->counter)
14837+ : "ir" (i));
14838+}
14839+
14840+/**
14841+ * atomic_sub_unchecked - subtract integer from atomic variable
14842+ * @i: integer value to subtract
14843+ * @v: pointer of type atomic_unchecked_t
14844+ *
14845+ * Atomically subtracts @i from @v.
14846+ */
14847+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14848+{
14849+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14850 : "+m" (v->counter)
14851 : "ir" (i));
14852 }
14853@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14854 */
14855 static inline int atomic_sub_and_test(int i, atomic_t *v)
14856 {
14857- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14858+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14859 }
14860
14861 /**
14862@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14863 */
14864 static inline void atomic_inc(atomic_t *v)
14865 {
14866- asm volatile(LOCK_PREFIX "incl %0"
14867+ asm volatile(LOCK_PREFIX "incl %0\n"
14868+
14869+#ifdef CONFIG_PAX_REFCOUNT
14870+ "jno 0f\n"
14871+ LOCK_PREFIX "decl %0\n"
14872+ "int $4\n0:\n"
14873+ _ASM_EXTABLE(0b, 0b)
14874+#endif
14875+
14876+ : "+m" (v->counter));
14877+}
14878+
14879+/**
14880+ * atomic_inc_unchecked - increment atomic variable
14881+ * @v: pointer of type atomic_unchecked_t
14882+ *
14883+ * Atomically increments @v by 1.
14884+ */
14885+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14886+{
14887+ asm volatile(LOCK_PREFIX "incl %0\n"
14888 : "+m" (v->counter));
14889 }
14890
14891@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14892 */
14893 static inline void atomic_dec(atomic_t *v)
14894 {
14895- asm volatile(LOCK_PREFIX "decl %0"
14896+ asm volatile(LOCK_PREFIX "decl %0\n"
14897+
14898+#ifdef CONFIG_PAX_REFCOUNT
14899+ "jno 0f\n"
14900+ LOCK_PREFIX "incl %0\n"
14901+ "int $4\n0:\n"
14902+ _ASM_EXTABLE(0b, 0b)
14903+#endif
14904+
14905+ : "+m" (v->counter));
14906+}
14907+
14908+/**
14909+ * atomic_dec_unchecked - decrement atomic variable
14910+ * @v: pointer of type atomic_unchecked_t
14911+ *
14912+ * Atomically decrements @v by 1.
14913+ */
14914+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14915+{
14916+ asm volatile(LOCK_PREFIX "decl %0\n"
14917 : "+m" (v->counter));
14918 }
14919
14920@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14921 */
14922 static inline int atomic_dec_and_test(atomic_t *v)
14923 {
14924- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14925+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14926 }
14927
14928 /**
14929@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14930 */
14931 static inline int atomic_inc_and_test(atomic_t *v)
14932 {
14933- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14934+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14935+}
14936+
14937+/**
14938+ * atomic_inc_and_test_unchecked - increment and test
14939+ * @v: pointer of type atomic_unchecked_t
14940+ *
14941+ * Atomically increments @v by 1
14942+ * and returns true if the result is zero, or false for all
14943+ * other cases.
14944+ */
14945+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14946+{
14947+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14948 }
14949
14950 /**
14951@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14952 */
14953 static inline int atomic_add_negative(int i, atomic_t *v)
14954 {
14955- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14956+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14957 }
14958
14959 /**
14960@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14961 */
14962 static inline int atomic_add_return(int i, atomic_t *v)
14963 {
14964+ return i + xadd_check_overflow(&v->counter, i);
14965+}
14966+
14967+/**
14968+ * atomic_add_return_unchecked - add integer and return
14969+ * @i: integer value to add
14970+ * @v: pointer of type atomic_unchecked_t
14971+ *
14972+ * Atomically adds @i to @v and returns @i + @v
14973+ */
14974+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14975+{
14976 return i + xadd(&v->counter, i);
14977 }
14978
14979@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14980 }
14981
14982 #define atomic_inc_return(v) (atomic_add_return(1, v))
14983+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14984+{
14985+ return atomic_add_return_unchecked(1, v);
14986+}
14987 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14988
14989-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14990+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14991+{
14992+ return cmpxchg(&v->counter, old, new);
14993+}
14994+
14995+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14996 {
14997 return cmpxchg(&v->counter, old, new);
14998 }
14999@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15000 return xchg(&v->counter, new);
15001 }
15002
15003+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15004+{
15005+ return xchg(&v->counter, new);
15006+}
15007+
15008 /**
15009 * __atomic_add_unless - add unless the number is already a given value
15010 * @v: pointer of type atomic_t
15011@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15012 * Atomically adds @a to @v, so long as @v was not already @u.
15013 * Returns the old value of @v.
15014 */
15015-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15016+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15017 {
15018- int c, old;
15019+ int c, old, new;
15020 c = atomic_read(v);
15021 for (;;) {
15022- if (unlikely(c == (u)))
15023+ if (unlikely(c == u))
15024 break;
15025- old = atomic_cmpxchg((v), c, c + (a));
15026+
15027+ asm volatile("addl %2,%0\n"
15028+
15029+#ifdef CONFIG_PAX_REFCOUNT
15030+ "jno 0f\n"
15031+ "subl %2,%0\n"
15032+ "int $4\n0:\n"
15033+ _ASM_EXTABLE(0b, 0b)
15034+#endif
15035+
15036+ : "=r" (new)
15037+ : "0" (c), "ir" (a));
15038+
15039+ old = atomic_cmpxchg(v, c, new);
15040 if (likely(old == c))
15041 break;
15042 c = old;
15043@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15044 }
15045
15046 /**
15047+ * atomic_inc_not_zero_hint - increment if not null
15048+ * @v: pointer of type atomic_t
15049+ * @hint: probable value of the atomic before the increment
15050+ *
15051+ * This version of atomic_inc_not_zero() gives a hint of probable
15052+ * value of the atomic. This helps processor to not read the memory
15053+ * before doing the atomic read/modify/write cycle, lowering
15054+ * number of bus transactions on some arches.
15055+ *
15056+ * Returns: 0 if increment was not done, 1 otherwise.
15057+ */
15058+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15059+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15060+{
15061+ int val, c = hint, new;
15062+
15063+ /* sanity test, should be removed by compiler if hint is a constant */
15064+ if (!hint)
15065+ return __atomic_add_unless(v, 1, 0);
15066+
15067+ do {
15068+ asm volatile("incl %0\n"
15069+
15070+#ifdef CONFIG_PAX_REFCOUNT
15071+ "jno 0f\n"
15072+ "decl %0\n"
15073+ "int $4\n0:\n"
15074+ _ASM_EXTABLE(0b, 0b)
15075+#endif
15076+
15077+ : "=r" (new)
15078+ : "0" (c));
15079+
15080+ val = atomic_cmpxchg(v, c, new);
15081+ if (val == c)
15082+ return 1;
15083+ c = val;
15084+ } while (c);
15085+
15086+ return 0;
15087+}
15088+
15089+/**
15090 * atomic_inc_short - increment of a short integer
15091 * @v: pointer to type int
15092 *
15093@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15094 #endif
15095
15096 /* These are x86-specific, used by some header files */
15097-#define atomic_clear_mask(mask, addr) \
15098- asm volatile(LOCK_PREFIX "andl %0,%1" \
15099- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15100+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15101+{
15102+ asm volatile(LOCK_PREFIX "andl %1,%0"
15103+ : "+m" (v->counter)
15104+ : "r" (~(mask))
15105+ : "memory");
15106+}
15107
15108-#define atomic_set_mask(mask, addr) \
15109- asm volatile(LOCK_PREFIX "orl %0,%1" \
15110- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15111- : "memory")
15112+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15113+{
15114+ asm volatile(LOCK_PREFIX "andl %1,%0"
15115+ : "+m" (v->counter)
15116+ : "r" (~(mask))
15117+ : "memory");
15118+}
15119+
15120+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15121+{
15122+ asm volatile(LOCK_PREFIX "orl %1,%0"
15123+ : "+m" (v->counter)
15124+ : "r" (mask)
15125+ : "memory");
15126+}
15127+
15128+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15129+{
15130+ asm volatile(LOCK_PREFIX "orl %1,%0"
15131+ : "+m" (v->counter)
15132+ : "r" (mask)
15133+ : "memory");
15134+}
15135
15136 /* Atomic operations are already serializing on x86 */
15137 #define smp_mb__before_atomic_dec() barrier()
15138diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15139index b154de7..bf18a5a 100644
15140--- a/arch/x86/include/asm/atomic64_32.h
15141+++ b/arch/x86/include/asm/atomic64_32.h
15142@@ -12,6 +12,14 @@ typedef struct {
15143 u64 __aligned(8) counter;
15144 } atomic64_t;
15145
15146+#ifdef CONFIG_PAX_REFCOUNT
15147+typedef struct {
15148+ u64 __aligned(8) counter;
15149+} atomic64_unchecked_t;
15150+#else
15151+typedef atomic64_t atomic64_unchecked_t;
15152+#endif
15153+
15154 #define ATOMIC64_INIT(val) { (val) }
15155
15156 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15157@@ -37,21 +45,31 @@ typedef struct {
15158 ATOMIC64_DECL_ONE(sym##_386)
15159
15160 ATOMIC64_DECL_ONE(add_386);
15161+ATOMIC64_DECL_ONE(add_unchecked_386);
15162 ATOMIC64_DECL_ONE(sub_386);
15163+ATOMIC64_DECL_ONE(sub_unchecked_386);
15164 ATOMIC64_DECL_ONE(inc_386);
15165+ATOMIC64_DECL_ONE(inc_unchecked_386);
15166 ATOMIC64_DECL_ONE(dec_386);
15167+ATOMIC64_DECL_ONE(dec_unchecked_386);
15168 #endif
15169
15170 #define alternative_atomic64(f, out, in...) \
15171 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15172
15173 ATOMIC64_DECL(read);
15174+ATOMIC64_DECL(read_unchecked);
15175 ATOMIC64_DECL(set);
15176+ATOMIC64_DECL(set_unchecked);
15177 ATOMIC64_DECL(xchg);
15178 ATOMIC64_DECL(add_return);
15179+ATOMIC64_DECL(add_return_unchecked);
15180 ATOMIC64_DECL(sub_return);
15181+ATOMIC64_DECL(sub_return_unchecked);
15182 ATOMIC64_DECL(inc_return);
15183+ATOMIC64_DECL(inc_return_unchecked);
15184 ATOMIC64_DECL(dec_return);
15185+ATOMIC64_DECL(dec_return_unchecked);
15186 ATOMIC64_DECL(dec_if_positive);
15187 ATOMIC64_DECL(inc_not_zero);
15188 ATOMIC64_DECL(add_unless);
15189@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15190 }
15191
15192 /**
15193+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15194+ * @p: pointer to type atomic64_unchecked_t
15195+ * @o: expected value
15196+ * @n: new value
15197+ *
15198+ * Atomically sets @v to @n if it was equal to @o and returns
15199+ * the old value.
15200+ */
15201+
15202+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15203+{
15204+ return cmpxchg64(&v->counter, o, n);
15205+}
15206+
15207+/**
15208 * atomic64_xchg - xchg atomic64 variable
15209 * @v: pointer to type atomic64_t
15210 * @n: value to assign
15211@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15212 }
15213
15214 /**
15215+ * atomic64_set_unchecked - set atomic64 variable
15216+ * @v: pointer to type atomic64_unchecked_t
15217+ * @n: value to assign
15218+ *
15219+ * Atomically sets the value of @v to @n.
15220+ */
15221+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15222+{
15223+ unsigned high = (unsigned)(i >> 32);
15224+ unsigned low = (unsigned)i;
15225+ alternative_atomic64(set, /* no output */,
15226+ "S" (v), "b" (low), "c" (high)
15227+ : "eax", "edx", "memory");
15228+}
15229+
15230+/**
15231 * atomic64_read - read atomic64 variable
15232 * @v: pointer to type atomic64_t
15233 *
15234@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15235 }
15236
15237 /**
15238+ * atomic64_read_unchecked - read atomic64 variable
15239+ * @v: pointer to type atomic64_unchecked_t
15240+ *
15241+ * Atomically reads the value of @v and returns it.
15242+ */
15243+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15244+{
15245+ long long r;
15246+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15247+ return r;
15248+ }
15249+
15250+/**
15251 * atomic64_add_return - add and return
15252 * @i: integer value to add
15253 * @v: pointer to type atomic64_t
15254@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15255 return i;
15256 }
15257
15258+/**
15259+ * atomic64_add_return_unchecked - add and return
15260+ * @i: integer value to add
15261+ * @v: pointer to type atomic64_unchecked_t
15262+ *
15263+ * Atomically adds @i to @v and returns @i + *@v
15264+ */
15265+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15266+{
15267+ alternative_atomic64(add_return_unchecked,
15268+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15269+ ASM_NO_INPUT_CLOBBER("memory"));
15270+ return i;
15271+}
15272+
15273 /*
15274 * Other variants with different arithmetic operators:
15275 */
15276@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15277 return a;
15278 }
15279
15280+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15281+{
15282+ long long a;
15283+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15284+ "S" (v) : "memory", "ecx");
15285+ return a;
15286+}
15287+
15288 static inline long long atomic64_dec_return(atomic64_t *v)
15289 {
15290 long long a;
15291@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15292 }
15293
15294 /**
15295+ * atomic64_add_unchecked - add integer to atomic64 variable
15296+ * @i: integer value to add
15297+ * @v: pointer to type atomic64_unchecked_t
15298+ *
15299+ * Atomically adds @i to @v.
15300+ */
15301+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15302+{
15303+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15304+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15305+ ASM_NO_INPUT_CLOBBER("memory"));
15306+ return i;
15307+}
15308+
15309+/**
15310 * atomic64_sub - subtract the atomic64 variable
15311 * @i: integer value to subtract
15312 * @v: pointer to type atomic64_t
15313diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15314index 46e9052..ae45136 100644
15315--- a/arch/x86/include/asm/atomic64_64.h
15316+++ b/arch/x86/include/asm/atomic64_64.h
15317@@ -18,7 +18,19 @@
15318 */
15319 static inline long atomic64_read(const atomic64_t *v)
15320 {
15321- return (*(volatile long *)&(v)->counter);
15322+ return (*(volatile const long *)&(v)->counter);
15323+}
15324+
15325+/**
15326+ * atomic64_read_unchecked - read atomic64 variable
15327+ * @v: pointer of type atomic64_unchecked_t
15328+ *
15329+ * Atomically reads the value of @v.
15330+ * Doesn't imply a read memory barrier.
15331+ */
15332+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15333+{
15334+ return (*(volatile const long *)&(v)->counter);
15335 }
15336
15337 /**
15338@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15339 }
15340
15341 /**
15342+ * atomic64_set_unchecked - set atomic64 variable
15343+ * @v: pointer to type atomic64_unchecked_t
15344+ * @i: required value
15345+ *
15346+ * Atomically sets the value of @v to @i.
15347+ */
15348+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15349+{
15350+ v->counter = i;
15351+}
15352+
15353+/**
15354 * atomic64_add - add integer to atomic64 variable
15355 * @i: integer value to add
15356 * @v: pointer to type atomic64_t
15357@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15358 */
15359 static inline void atomic64_add(long i, atomic64_t *v)
15360 {
15361+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15362+
15363+#ifdef CONFIG_PAX_REFCOUNT
15364+ "jno 0f\n"
15365+ LOCK_PREFIX "subq %1,%0\n"
15366+ "int $4\n0:\n"
15367+ _ASM_EXTABLE(0b, 0b)
15368+#endif
15369+
15370+ : "=m" (v->counter)
15371+ : "er" (i), "m" (v->counter));
15372+}
15373+
15374+/**
15375+ * atomic64_add_unchecked - add integer to atomic64 variable
15376+ * @i: integer value to add
15377+ * @v: pointer to type atomic64_unchecked_t
15378+ *
15379+ * Atomically adds @i to @v.
15380+ */
15381+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15382+{
15383 asm volatile(LOCK_PREFIX "addq %1,%0"
15384 : "=m" (v->counter)
15385 : "er" (i), "m" (v->counter));
15386@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15387 */
15388 static inline void atomic64_sub(long i, atomic64_t *v)
15389 {
15390- asm volatile(LOCK_PREFIX "subq %1,%0"
15391+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15392+
15393+#ifdef CONFIG_PAX_REFCOUNT
15394+ "jno 0f\n"
15395+ LOCK_PREFIX "addq %1,%0\n"
15396+ "int $4\n0:\n"
15397+ _ASM_EXTABLE(0b, 0b)
15398+#endif
15399+
15400+ : "=m" (v->counter)
15401+ : "er" (i), "m" (v->counter));
15402+}
15403+
15404+/**
15405+ * atomic64_sub_unchecked - subtract the atomic64 variable
15406+ * @i: integer value to subtract
15407+ * @v: pointer to type atomic64_unchecked_t
15408+ *
15409+ * Atomically subtracts @i from @v.
15410+ */
15411+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15412+{
15413+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15414 : "=m" (v->counter)
15415 : "er" (i), "m" (v->counter));
15416 }
15417@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15418 */
15419 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15420 {
15421- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15422+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15423 }
15424
15425 /**
15426@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15427 */
15428 static inline void atomic64_inc(atomic64_t *v)
15429 {
15430+ asm volatile(LOCK_PREFIX "incq %0\n"
15431+
15432+#ifdef CONFIG_PAX_REFCOUNT
15433+ "jno 0f\n"
15434+ LOCK_PREFIX "decq %0\n"
15435+ "int $4\n0:\n"
15436+ _ASM_EXTABLE(0b, 0b)
15437+#endif
15438+
15439+ : "=m" (v->counter)
15440+ : "m" (v->counter));
15441+}
15442+
15443+/**
15444+ * atomic64_inc_unchecked - increment atomic64 variable
15445+ * @v: pointer to type atomic64_unchecked_t
15446+ *
15447+ * Atomically increments @v by 1.
15448+ */
15449+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15450+{
15451 asm volatile(LOCK_PREFIX "incq %0"
15452 : "=m" (v->counter)
15453 : "m" (v->counter));
15454@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15455 */
15456 static inline void atomic64_dec(atomic64_t *v)
15457 {
15458- asm volatile(LOCK_PREFIX "decq %0"
15459+ asm volatile(LOCK_PREFIX "decq %0\n"
15460+
15461+#ifdef CONFIG_PAX_REFCOUNT
15462+ "jno 0f\n"
15463+ LOCK_PREFIX "incq %0\n"
15464+ "int $4\n0:\n"
15465+ _ASM_EXTABLE(0b, 0b)
15466+#endif
15467+
15468+ : "=m" (v->counter)
15469+ : "m" (v->counter));
15470+}
15471+
15472+/**
15473+ * atomic64_dec_unchecked - decrement atomic64 variable
15474+ * @v: pointer to type atomic64_t
15475+ *
15476+ * Atomically decrements @v by 1.
15477+ */
15478+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15479+{
15480+ asm volatile(LOCK_PREFIX "decq %0\n"
15481 : "=m" (v->counter)
15482 : "m" (v->counter));
15483 }
15484@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15485 */
15486 static inline int atomic64_dec_and_test(atomic64_t *v)
15487 {
15488- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15489+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15490 }
15491
15492 /**
15493@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15494 */
15495 static inline int atomic64_inc_and_test(atomic64_t *v)
15496 {
15497- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15498+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15499 }
15500
15501 /**
15502@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15503 */
15504 static inline int atomic64_add_negative(long i, atomic64_t *v)
15505 {
15506- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15507+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15508 }
15509
15510 /**
15511@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15512 */
15513 static inline long atomic64_add_return(long i, atomic64_t *v)
15514 {
15515+ return i + xadd_check_overflow(&v->counter, i);
15516+}
15517+
15518+/**
15519+ * atomic64_add_return_unchecked - add and return
15520+ * @i: integer value to add
15521+ * @v: pointer to type atomic64_unchecked_t
15522+ *
15523+ * Atomically adds @i to @v and returns @i + @v
15524+ */
15525+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15526+{
15527 return i + xadd(&v->counter, i);
15528 }
15529
15530@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15531 }
15532
15533 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15534+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15535+{
15536+ return atomic64_add_return_unchecked(1, v);
15537+}
15538 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15539
15540 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15541@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15542 return cmpxchg(&v->counter, old, new);
15543 }
15544
15545+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15546+{
15547+ return cmpxchg(&v->counter, old, new);
15548+}
15549+
15550 static inline long atomic64_xchg(atomic64_t *v, long new)
15551 {
15552 return xchg(&v->counter, new);
15553@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15554 */
15555 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15556 {
15557- long c, old;
15558+ long c, old, new;
15559 c = atomic64_read(v);
15560 for (;;) {
15561- if (unlikely(c == (u)))
15562+ if (unlikely(c == u))
15563 break;
15564- old = atomic64_cmpxchg((v), c, c + (a));
15565+
15566+ asm volatile("add %2,%0\n"
15567+
15568+#ifdef CONFIG_PAX_REFCOUNT
15569+ "jno 0f\n"
15570+ "sub %2,%0\n"
15571+ "int $4\n0:\n"
15572+ _ASM_EXTABLE(0b, 0b)
15573+#endif
15574+
15575+ : "=r" (new)
15576+ : "0" (c), "ir" (a));
15577+
15578+ old = atomic64_cmpxchg(v, c, new);
15579 if (likely(old == c))
15580 break;
15581 c = old;
15582 }
15583- return c != (u);
15584+ return c != u;
15585 }
15586
15587 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15588diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15589index 9fc1af7..fc71228 100644
15590--- a/arch/x86/include/asm/bitops.h
15591+++ b/arch/x86/include/asm/bitops.h
15592@@ -49,7 +49,7 @@
15593 * a mask operation on a byte.
15594 */
15595 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15596-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15597+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15598 #define CONST_MASK(nr) (1 << ((nr) & 7))
15599
15600 /**
15601@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15602 */
15603 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15604 {
15605- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15606+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15607 }
15608
15609 /**
15610@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15611 */
15612 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15613 {
15614- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15615+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15616 }
15617
15618 /**
15619@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15620 */
15621 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15622 {
15623- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15624+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15625 }
15626
15627 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15628@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15629 *
15630 * Undefined if no bit exists, so code should check against 0 first.
15631 */
15632-static inline unsigned long __ffs(unsigned long word)
15633+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15634 {
15635 asm("rep; bsf %1,%0"
15636 : "=r" (word)
15637@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15638 *
15639 * Undefined if no zero exists, so code should check against ~0UL first.
15640 */
15641-static inline unsigned long ffz(unsigned long word)
15642+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15643 {
15644 asm("rep; bsf %1,%0"
15645 : "=r" (word)
15646@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15647 *
15648 * Undefined if no set bit exists, so code should check against 0 first.
15649 */
15650-static inline unsigned long __fls(unsigned long word)
15651+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15652 {
15653 asm("bsr %1,%0"
15654 : "=r" (word)
15655@@ -436,7 +436,7 @@ static inline int ffs(int x)
15656 * set bit if value is nonzero. The last (most significant) bit is
15657 * at position 32.
15658 */
15659-static inline int fls(int x)
15660+static inline int __intentional_overflow(-1) fls(int x)
15661 {
15662 int r;
15663
15664@@ -478,7 +478,7 @@ static inline int fls(int x)
15665 * at position 64.
15666 */
15667 #ifdef CONFIG_X86_64
15668-static __always_inline int fls64(__u64 x)
15669+static __always_inline long fls64(__u64 x)
15670 {
15671 int bitpos = -1;
15672 /*
15673diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15674index 4fa687a..60f2d39 100644
15675--- a/arch/x86/include/asm/boot.h
15676+++ b/arch/x86/include/asm/boot.h
15677@@ -6,10 +6,15 @@
15678 #include <uapi/asm/boot.h>
15679
15680 /* Physical address where kernel should be loaded. */
15681-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15682+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15683 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15684 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15685
15686+#ifndef __ASSEMBLY__
15687+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15688+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15689+#endif
15690+
15691 /* Minimum kernel alignment, as a power of two */
15692 #ifdef CONFIG_X86_64
15693 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15694diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15695index 48f99f1..d78ebf9 100644
15696--- a/arch/x86/include/asm/cache.h
15697+++ b/arch/x86/include/asm/cache.h
15698@@ -5,12 +5,13 @@
15699
15700 /* L1 cache line size */
15701 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15702-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15703+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15704
15705 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15706+#define __read_only __attribute__((__section__(".data..read_only")))
15707
15708 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15709-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15710+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15711
15712 #ifdef CONFIG_X86_VSMP
15713 #ifdef CONFIG_SMP
15714diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15715index 9863ee3..4a1f8e1 100644
15716--- a/arch/x86/include/asm/cacheflush.h
15717+++ b/arch/x86/include/asm/cacheflush.h
15718@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15719 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15720
15721 if (pg_flags == _PGMT_DEFAULT)
15722- return -1;
15723+ return ~0UL;
15724 else if (pg_flags == _PGMT_WC)
15725 return _PAGE_CACHE_WC;
15726 else if (pg_flags == _PGMT_UC_MINUS)
15727diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15728index cb4c73b..c473c29 100644
15729--- a/arch/x86/include/asm/calling.h
15730+++ b/arch/x86/include/asm/calling.h
15731@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15732 #define RSP 152
15733 #define SS 160
15734
15735-#define ARGOFFSET R11
15736-#define SWFRAME ORIG_RAX
15737+#define ARGOFFSET R15
15738
15739 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15740- subq $9*8+\addskip, %rsp
15741- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15742- movq_cfi rdi, 8*8
15743- movq_cfi rsi, 7*8
15744- movq_cfi rdx, 6*8
15745+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15746+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15747+ movq_cfi rdi, RDI
15748+ movq_cfi rsi, RSI
15749+ movq_cfi rdx, RDX
15750
15751 .if \save_rcx
15752- movq_cfi rcx, 5*8
15753+ movq_cfi rcx, RCX
15754 .endif
15755
15756- movq_cfi rax, 4*8
15757+ movq_cfi rax, RAX
15758
15759 .if \save_r891011
15760- movq_cfi r8, 3*8
15761- movq_cfi r9, 2*8
15762- movq_cfi r10, 1*8
15763- movq_cfi r11, 0*8
15764+ movq_cfi r8, R8
15765+ movq_cfi r9, R9
15766+ movq_cfi r10, R10
15767+ movq_cfi r11, R11
15768 .endif
15769
15770+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15771+ movq_cfi r12, R12
15772+#endif
15773+
15774 .endm
15775
15776-#define ARG_SKIP (9*8)
15777+#define ARG_SKIP ORIG_RAX
15778
15779 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15780 rstor_r8910=1, rstor_rdx=1
15781+
15782+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15783+ movq_cfi_restore R12, r12
15784+#endif
15785+
15786 .if \rstor_r11
15787- movq_cfi_restore 0*8, r11
15788+ movq_cfi_restore R11, r11
15789 .endif
15790
15791 .if \rstor_r8910
15792- movq_cfi_restore 1*8, r10
15793- movq_cfi_restore 2*8, r9
15794- movq_cfi_restore 3*8, r8
15795+ movq_cfi_restore R10, r10
15796+ movq_cfi_restore R9, r9
15797+ movq_cfi_restore R8, r8
15798 .endif
15799
15800 .if \rstor_rax
15801- movq_cfi_restore 4*8, rax
15802+ movq_cfi_restore RAX, rax
15803 .endif
15804
15805 .if \rstor_rcx
15806- movq_cfi_restore 5*8, rcx
15807+ movq_cfi_restore RCX, rcx
15808 .endif
15809
15810 .if \rstor_rdx
15811- movq_cfi_restore 6*8, rdx
15812+ movq_cfi_restore RDX, rdx
15813 .endif
15814
15815- movq_cfi_restore 7*8, rsi
15816- movq_cfi_restore 8*8, rdi
15817+ movq_cfi_restore RSI, rsi
15818+ movq_cfi_restore RDI, rdi
15819
15820- .if ARG_SKIP+\addskip > 0
15821- addq $ARG_SKIP+\addskip, %rsp
15822- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15823+ .if ORIG_RAX+\addskip > 0
15824+ addq $ORIG_RAX+\addskip, %rsp
15825+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15826 .endif
15827 .endm
15828
15829- .macro LOAD_ARGS offset, skiprax=0
15830- movq \offset(%rsp), %r11
15831- movq \offset+8(%rsp), %r10
15832- movq \offset+16(%rsp), %r9
15833- movq \offset+24(%rsp), %r8
15834- movq \offset+40(%rsp), %rcx
15835- movq \offset+48(%rsp), %rdx
15836- movq \offset+56(%rsp), %rsi
15837- movq \offset+64(%rsp), %rdi
15838+ .macro LOAD_ARGS skiprax=0
15839+ movq R11(%rsp), %r11
15840+ movq R10(%rsp), %r10
15841+ movq R9(%rsp), %r9
15842+ movq R8(%rsp), %r8
15843+ movq RCX(%rsp), %rcx
15844+ movq RDX(%rsp), %rdx
15845+ movq RSI(%rsp), %rsi
15846+ movq RDI(%rsp), %rdi
15847 .if \skiprax
15848 .else
15849- movq \offset+72(%rsp), %rax
15850+ movq RAX(%rsp), %rax
15851 .endif
15852 .endm
15853
15854-#define REST_SKIP (6*8)
15855-
15856 .macro SAVE_REST
15857- subq $REST_SKIP, %rsp
15858- CFI_ADJUST_CFA_OFFSET REST_SKIP
15859- movq_cfi rbx, 5*8
15860- movq_cfi rbp, 4*8
15861- movq_cfi r12, 3*8
15862- movq_cfi r13, 2*8
15863- movq_cfi r14, 1*8
15864- movq_cfi r15, 0*8
15865+ movq_cfi rbx, RBX
15866+ movq_cfi rbp, RBP
15867+
15868+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15869+ movq_cfi r12, R12
15870+#endif
15871+
15872+ movq_cfi r13, R13
15873+ movq_cfi r14, R14
15874+ movq_cfi r15, R15
15875 .endm
15876
15877 .macro RESTORE_REST
15878- movq_cfi_restore 0*8, r15
15879- movq_cfi_restore 1*8, r14
15880- movq_cfi_restore 2*8, r13
15881- movq_cfi_restore 3*8, r12
15882- movq_cfi_restore 4*8, rbp
15883- movq_cfi_restore 5*8, rbx
15884- addq $REST_SKIP, %rsp
15885- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15886+ movq_cfi_restore R15, r15
15887+ movq_cfi_restore R14, r14
15888+ movq_cfi_restore R13, r13
15889+
15890+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15891+ movq_cfi_restore R12, r12
15892+#endif
15893+
15894+ movq_cfi_restore RBP, rbp
15895+ movq_cfi_restore RBX, rbx
15896 .endm
15897
15898 .macro SAVE_ALL
15899diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15900index f50de69..2b0a458 100644
15901--- a/arch/x86/include/asm/checksum_32.h
15902+++ b/arch/x86/include/asm/checksum_32.h
15903@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15904 int len, __wsum sum,
15905 int *src_err_ptr, int *dst_err_ptr);
15906
15907+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15908+ int len, __wsum sum,
15909+ int *src_err_ptr, int *dst_err_ptr);
15910+
15911+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15912+ int len, __wsum sum,
15913+ int *src_err_ptr, int *dst_err_ptr);
15914+
15915 /*
15916 * Note: when you get a NULL pointer exception here this means someone
15917 * passed in an incorrect kernel address to one of these functions.
15918@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15919
15920 might_sleep();
15921 stac();
15922- ret = csum_partial_copy_generic((__force void *)src, dst,
15923+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15924 len, sum, err_ptr, NULL);
15925 clac();
15926
15927@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15928 might_sleep();
15929 if (access_ok(VERIFY_WRITE, dst, len)) {
15930 stac();
15931- ret = csum_partial_copy_generic(src, (__force void *)dst,
15932+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15933 len, sum, NULL, err_ptr);
15934 clac();
15935 return ret;
15936diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15937index d47786a..2d8883e 100644
15938--- a/arch/x86/include/asm/cmpxchg.h
15939+++ b/arch/x86/include/asm/cmpxchg.h
15940@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15941 __compiletime_error("Bad argument size for cmpxchg");
15942 extern void __xadd_wrong_size(void)
15943 __compiletime_error("Bad argument size for xadd");
15944+extern void __xadd_check_overflow_wrong_size(void)
15945+ __compiletime_error("Bad argument size for xadd_check_overflow");
15946 extern void __add_wrong_size(void)
15947 __compiletime_error("Bad argument size for add");
15948+extern void __add_check_overflow_wrong_size(void)
15949+ __compiletime_error("Bad argument size for add_check_overflow");
15950
15951 /*
15952 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15953@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
15954 __ret; \
15955 })
15956
15957+#ifdef CONFIG_PAX_REFCOUNT
15958+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15959+ ({ \
15960+ __typeof__ (*(ptr)) __ret = (arg); \
15961+ switch (sizeof(*(ptr))) { \
15962+ case __X86_CASE_L: \
15963+ asm volatile (lock #op "l %0, %1\n" \
15964+ "jno 0f\n" \
15965+ "mov %0,%1\n" \
15966+ "int $4\n0:\n" \
15967+ _ASM_EXTABLE(0b, 0b) \
15968+ : "+r" (__ret), "+m" (*(ptr)) \
15969+ : : "memory", "cc"); \
15970+ break; \
15971+ case __X86_CASE_Q: \
15972+ asm volatile (lock #op "q %q0, %1\n" \
15973+ "jno 0f\n" \
15974+ "mov %0,%1\n" \
15975+ "int $4\n0:\n" \
15976+ _ASM_EXTABLE(0b, 0b) \
15977+ : "+r" (__ret), "+m" (*(ptr)) \
15978+ : : "memory", "cc"); \
15979+ break; \
15980+ default: \
15981+ __ ## op ## _check_overflow_wrong_size(); \
15982+ } \
15983+ __ret; \
15984+ })
15985+#else
15986+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
15987+#endif
15988+
15989 /*
15990 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15991 * Since this is generally used to protect other memory information, we
15992@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
15993 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15994 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15995
15996+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15997+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15998+
15999 #define __add(ptr, inc, lock) \
16000 ({ \
16001 __typeof__ (*(ptr)) __ret = (inc); \
16002diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16003index 59c6c40..5e0b22c 100644
16004--- a/arch/x86/include/asm/compat.h
16005+++ b/arch/x86/include/asm/compat.h
16006@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16007 typedef u32 compat_uint_t;
16008 typedef u32 compat_ulong_t;
16009 typedef u64 __attribute__((aligned(4))) compat_u64;
16010-typedef u32 compat_uptr_t;
16011+typedef u32 __user compat_uptr_t;
16012
16013 struct compat_timespec {
16014 compat_time_t tv_sec;
16015diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16016index 5f12968..a383517 100644
16017--- a/arch/x86/include/asm/cpufeature.h
16018+++ b/arch/x86/include/asm/cpufeature.h
16019@@ -203,7 +203,7 @@
16020 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16021 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16022 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16023-
16024+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16025
16026 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16027 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16028@@ -211,7 +211,7 @@
16029 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16030 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16031 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16032-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16033+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16034 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16035 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16036 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16037@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16038 #undef cpu_has_centaur_mcr
16039 #define cpu_has_centaur_mcr 0
16040
16041+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16042 #endif /* CONFIG_X86_64 */
16043
16044 #if __GNUC__ >= 4
16045@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16046
16047 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16048 t_warn:
16049- warn_pre_alternatives();
16050+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16051+ warn_pre_alternatives();
16052 return false;
16053 #endif
16054
16055@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16056 ".section .discard,\"aw\",@progbits\n"
16057 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16058 ".previous\n"
16059- ".section .altinstr_replacement,\"ax\"\n"
16060+ ".section .altinstr_replacement,\"a\"\n"
16061 "3: movb $1,%0\n"
16062 "4:\n"
16063 ".previous\n"
16064@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16065 " .byte 2b - 1b\n" /* src len */
16066 " .byte 4f - 3f\n" /* repl len */
16067 ".previous\n"
16068- ".section .altinstr_replacement,\"ax\"\n"
16069+ ".section .altinstr_replacement,\"a\"\n"
16070 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16071 "4:\n"
16072 ".previous\n"
16073@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16074 ".section .discard,\"aw\",@progbits\n"
16075 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16076 ".previous\n"
16077- ".section .altinstr_replacement,\"ax\"\n"
16078+ ".section .altinstr_replacement,\"a\"\n"
16079 "3: movb $0,%0\n"
16080 "4:\n"
16081 ".previous\n"
16082@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16083 ".section .discard,\"aw\",@progbits\n"
16084 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16085 ".previous\n"
16086- ".section .altinstr_replacement,\"ax\"\n"
16087+ ".section .altinstr_replacement,\"a\"\n"
16088 "5: movb $1,%0\n"
16089 "6:\n"
16090 ".previous\n"
16091diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16092index 50d033a..37deb26 100644
16093--- a/arch/x86/include/asm/desc.h
16094+++ b/arch/x86/include/asm/desc.h
16095@@ -4,6 +4,7 @@
16096 #include <asm/desc_defs.h>
16097 #include <asm/ldt.h>
16098 #include <asm/mmu.h>
16099+#include <asm/pgtable.h>
16100
16101 #include <linux/smp.h>
16102 #include <linux/percpu.h>
16103@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16104
16105 desc->type = (info->read_exec_only ^ 1) << 1;
16106 desc->type |= info->contents << 2;
16107+ desc->type |= info->seg_not_present ^ 1;
16108
16109 desc->s = 1;
16110 desc->dpl = 0x3;
16111@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16112 }
16113
16114 extern struct desc_ptr idt_descr;
16115-extern gate_desc idt_table[];
16116-extern struct desc_ptr debug_idt_descr;
16117-extern gate_desc debug_idt_table[];
16118-
16119-struct gdt_page {
16120- struct desc_struct gdt[GDT_ENTRIES];
16121-} __attribute__((aligned(PAGE_SIZE)));
16122-
16123-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16124+extern gate_desc idt_table[IDT_ENTRIES];
16125+extern const struct desc_ptr debug_idt_descr;
16126+extern gate_desc debug_idt_table[IDT_ENTRIES];
16127
16128+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16129 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16130 {
16131- return per_cpu(gdt_page, cpu).gdt;
16132+ return cpu_gdt_table[cpu];
16133 }
16134
16135 #ifdef CONFIG_X86_64
16136@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16137 unsigned long base, unsigned dpl, unsigned flags,
16138 unsigned short seg)
16139 {
16140- gate->a = (seg << 16) | (base & 0xffff);
16141- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16142+ gate->gate.offset_low = base;
16143+ gate->gate.seg = seg;
16144+ gate->gate.reserved = 0;
16145+ gate->gate.type = type;
16146+ gate->gate.s = 0;
16147+ gate->gate.dpl = dpl;
16148+ gate->gate.p = 1;
16149+ gate->gate.offset_high = base >> 16;
16150 }
16151
16152 #endif
16153@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16154
16155 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16156 {
16157+ pax_open_kernel();
16158 memcpy(&idt[entry], gate, sizeof(*gate));
16159+ pax_close_kernel();
16160 }
16161
16162 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16163 {
16164+ pax_open_kernel();
16165 memcpy(&ldt[entry], desc, 8);
16166+ pax_close_kernel();
16167 }
16168
16169 static inline void
16170@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16171 default: size = sizeof(*gdt); break;
16172 }
16173
16174+ pax_open_kernel();
16175 memcpy(&gdt[entry], desc, size);
16176+ pax_close_kernel();
16177 }
16178
16179 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16180@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16181
16182 static inline void native_load_tr_desc(void)
16183 {
16184+ pax_open_kernel();
16185 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16186+ pax_close_kernel();
16187 }
16188
16189 static inline void native_load_gdt(const struct desc_ptr *dtr)
16190@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16191 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16192 unsigned int i;
16193
16194+ pax_open_kernel();
16195 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16196 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16197+ pax_close_kernel();
16198 }
16199
16200 #define _LDT_empty(info) \
16201@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16202 preempt_enable();
16203 }
16204
16205-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16206+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16207 {
16208 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16209 }
16210@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16211 }
16212
16213 #ifdef CONFIG_X86_64
16214-static inline void set_nmi_gate(int gate, void *addr)
16215+static inline void set_nmi_gate(int gate, const void *addr)
16216 {
16217 gate_desc s;
16218
16219@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16220 #endif
16221
16222 #ifdef CONFIG_TRACING
16223-extern struct desc_ptr trace_idt_descr;
16224-extern gate_desc trace_idt_table[];
16225+extern const struct desc_ptr trace_idt_descr;
16226+extern gate_desc trace_idt_table[IDT_ENTRIES];
16227 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16228 {
16229 write_idt_entry(trace_idt_table, entry, gate);
16230 }
16231
16232-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16233+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16234 unsigned dpl, unsigned ist, unsigned seg)
16235 {
16236 gate_desc s;
16237@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16238 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16239 #endif
16240
16241-static inline void _set_gate(int gate, unsigned type, void *addr,
16242+static inline void _set_gate(int gate, unsigned type, const void *addr,
16243 unsigned dpl, unsigned ist, unsigned seg)
16244 {
16245 gate_desc s;
16246@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16247 #define set_intr_gate(n, addr) \
16248 do { \
16249 BUG_ON((unsigned)n > 0xFF); \
16250- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16251+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16252 __KERNEL_CS); \
16253- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16254+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16255 0, 0, __KERNEL_CS); \
16256 } while (0)
16257
16258@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16259 /*
16260 * This routine sets up an interrupt gate at directory privilege level 3.
16261 */
16262-static inline void set_system_intr_gate(unsigned int n, void *addr)
16263+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16264 {
16265 BUG_ON((unsigned)n > 0xFF);
16266 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16267 }
16268
16269-static inline void set_system_trap_gate(unsigned int n, void *addr)
16270+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16271 {
16272 BUG_ON((unsigned)n > 0xFF);
16273 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16274 }
16275
16276-static inline void set_trap_gate(unsigned int n, void *addr)
16277+static inline void set_trap_gate(unsigned int n, const void *addr)
16278 {
16279 BUG_ON((unsigned)n > 0xFF);
16280 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16281@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16282 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16283 {
16284 BUG_ON((unsigned)n > 0xFF);
16285- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16286+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16287 }
16288
16289-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16290+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16291 {
16292 BUG_ON((unsigned)n > 0xFF);
16293 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16294 }
16295
16296-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16297+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16298 {
16299 BUG_ON((unsigned)n > 0xFF);
16300 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16301@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16302 else
16303 load_idt((const struct desc_ptr *)&idt_descr);
16304 }
16305+
16306+#ifdef CONFIG_X86_32
16307+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16308+{
16309+ struct desc_struct d;
16310+
16311+ if (likely(limit))
16312+ limit = (limit - 1UL) >> PAGE_SHIFT;
16313+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16314+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16315+}
16316+#endif
16317+
16318 #endif /* _ASM_X86_DESC_H */
16319diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16320index 278441f..b95a174 100644
16321--- a/arch/x86/include/asm/desc_defs.h
16322+++ b/arch/x86/include/asm/desc_defs.h
16323@@ -31,6 +31,12 @@ struct desc_struct {
16324 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16325 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16326 };
16327+ struct {
16328+ u16 offset_low;
16329+ u16 seg;
16330+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16331+ unsigned offset_high: 16;
16332+ } gate;
16333 };
16334 } __attribute__((packed));
16335
16336diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16337index ced283a..ffe04cc 100644
16338--- a/arch/x86/include/asm/div64.h
16339+++ b/arch/x86/include/asm/div64.h
16340@@ -39,7 +39,7 @@
16341 __mod; \
16342 })
16343
16344-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16345+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16346 {
16347 union {
16348 u64 v64;
16349diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16350index 9c999c1..3860cb8 100644
16351--- a/arch/x86/include/asm/elf.h
16352+++ b/arch/x86/include/asm/elf.h
16353@@ -243,7 +243,25 @@ extern int force_personality32;
16354 the loader. We need to make sure that it is out of the way of the program
16355 that it will "exec", and that there is sufficient room for the brk. */
16356
16357+#ifdef CONFIG_PAX_SEGMEXEC
16358+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16359+#else
16360 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16361+#endif
16362+
16363+#ifdef CONFIG_PAX_ASLR
16364+#ifdef CONFIG_X86_32
16365+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16366+
16367+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16368+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16369+#else
16370+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16371+
16372+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16373+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16374+#endif
16375+#endif
16376
16377 /* This yields a mask that user programs can use to figure out what
16378 instruction set this CPU supports. This could be done in user space,
16379@@ -296,16 +314,12 @@ do { \
16380
16381 #define ARCH_DLINFO \
16382 do { \
16383- if (vdso_enabled) \
16384- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16385- (unsigned long)current->mm->context.vdso); \
16386+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16387 } while (0)
16388
16389 #define ARCH_DLINFO_X32 \
16390 do { \
16391- if (vdso_enabled) \
16392- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16393- (unsigned long)current->mm->context.vdso); \
16394+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16395 } while (0)
16396
16397 #define AT_SYSINFO 32
16398@@ -320,7 +334,7 @@ else \
16399
16400 #endif /* !CONFIG_X86_32 */
16401
16402-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16403+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16404
16405 #define VDSO_ENTRY \
16406 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16407@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16408 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16409 #define compat_arch_setup_additional_pages syscall32_setup_pages
16410
16411-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16412-#define arch_randomize_brk arch_randomize_brk
16413-
16414 /*
16415 * True on X86_32 or when emulating IA32 on X86_64
16416 */
16417diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16418index 77a99ac..39ff7f5 100644
16419--- a/arch/x86/include/asm/emergency-restart.h
16420+++ b/arch/x86/include/asm/emergency-restart.h
16421@@ -1,6 +1,6 @@
16422 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16423 #define _ASM_X86_EMERGENCY_RESTART_H
16424
16425-extern void machine_emergency_restart(void);
16426+extern void machine_emergency_restart(void) __noreturn;
16427
16428 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16429diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16430index d3d7469..677ef72 100644
16431--- a/arch/x86/include/asm/floppy.h
16432+++ b/arch/x86/include/asm/floppy.h
16433@@ -229,18 +229,18 @@ static struct fd_routine_l {
16434 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16435 } fd_routine[] = {
16436 {
16437- request_dma,
16438- free_dma,
16439- get_dma_residue,
16440- dma_mem_alloc,
16441- hard_dma_setup
16442+ ._request_dma = request_dma,
16443+ ._free_dma = free_dma,
16444+ ._get_dma_residue = get_dma_residue,
16445+ ._dma_mem_alloc = dma_mem_alloc,
16446+ ._dma_setup = hard_dma_setup
16447 },
16448 {
16449- vdma_request_dma,
16450- vdma_nop,
16451- vdma_get_dma_residue,
16452- vdma_mem_alloc,
16453- vdma_dma_setup
16454+ ._request_dma = vdma_request_dma,
16455+ ._free_dma = vdma_nop,
16456+ ._get_dma_residue = vdma_get_dma_residue,
16457+ ._dma_mem_alloc = vdma_mem_alloc,
16458+ ._dma_setup = vdma_dma_setup
16459 }
16460 };
16461
16462diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16463index cea1c76..6c0d79b 100644
16464--- a/arch/x86/include/asm/fpu-internal.h
16465+++ b/arch/x86/include/asm/fpu-internal.h
16466@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16467 #define user_insn(insn, output, input...) \
16468 ({ \
16469 int err; \
16470+ pax_open_userland(); \
16471 asm volatile(ASM_STAC "\n" \
16472- "1:" #insn "\n\t" \
16473+ "1:" \
16474+ __copyuser_seg \
16475+ #insn "\n\t" \
16476 "2: " ASM_CLAC "\n" \
16477 ".section .fixup,\"ax\"\n" \
16478 "3: movl $-1,%[err]\n" \
16479@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16480 _ASM_EXTABLE(1b, 3b) \
16481 : [err] "=r" (err), output \
16482 : "0"(0), input); \
16483+ pax_close_userland(); \
16484 err; \
16485 })
16486
16487@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16488 "fnclex\n\t"
16489 "emms\n\t"
16490 "fildl %P[addr]" /* set F?P to defined value */
16491- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16492+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16493 }
16494
16495 return fpu_restore_checking(&tsk->thread.fpu);
16496diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16497index b4c1f54..e290c08 100644
16498--- a/arch/x86/include/asm/futex.h
16499+++ b/arch/x86/include/asm/futex.h
16500@@ -12,6 +12,7 @@
16501 #include <asm/smap.h>
16502
16503 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16504+ typecheck(u32 __user *, uaddr); \
16505 asm volatile("\t" ASM_STAC "\n" \
16506 "1:\t" insn "\n" \
16507 "2:\t" ASM_CLAC "\n" \
16508@@ -20,15 +21,16 @@
16509 "\tjmp\t2b\n" \
16510 "\t.previous\n" \
16511 _ASM_EXTABLE(1b, 3b) \
16512- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16513+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16514 : "i" (-EFAULT), "0" (oparg), "1" (0))
16515
16516 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16517+ typecheck(u32 __user *, uaddr); \
16518 asm volatile("\t" ASM_STAC "\n" \
16519 "1:\tmovl %2, %0\n" \
16520 "\tmovl\t%0, %3\n" \
16521 "\t" insn "\n" \
16522- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16523+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16524 "\tjnz\t1b\n" \
16525 "3:\t" ASM_CLAC "\n" \
16526 "\t.section .fixup,\"ax\"\n" \
16527@@ -38,7 +40,7 @@
16528 _ASM_EXTABLE(1b, 4b) \
16529 _ASM_EXTABLE(2b, 4b) \
16530 : "=&a" (oldval), "=&r" (ret), \
16531- "+m" (*uaddr), "=&r" (tem) \
16532+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16533 : "r" (oparg), "i" (-EFAULT), "1" (0))
16534
16535 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16536@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16537
16538 pagefault_disable();
16539
16540+ pax_open_userland();
16541 switch (op) {
16542 case FUTEX_OP_SET:
16543- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16544+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16545 break;
16546 case FUTEX_OP_ADD:
16547- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16548+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16549 uaddr, oparg);
16550 break;
16551 case FUTEX_OP_OR:
16552@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16553 default:
16554 ret = -ENOSYS;
16555 }
16556+ pax_close_userland();
16557
16558 pagefault_enable();
16559
16560diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16561index 67d69b8..50e4b77 100644
16562--- a/arch/x86/include/asm/hw_irq.h
16563+++ b/arch/x86/include/asm/hw_irq.h
16564@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16565 extern void enable_IO_APIC(void);
16566
16567 /* Statistics */
16568-extern atomic_t irq_err_count;
16569-extern atomic_t irq_mis_count;
16570+extern atomic_unchecked_t irq_err_count;
16571+extern atomic_unchecked_t irq_mis_count;
16572
16573 /* EISA */
16574 extern void eisa_set_level_irq(unsigned int irq);
16575diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16576index a203659..9889f1c 100644
16577--- a/arch/x86/include/asm/i8259.h
16578+++ b/arch/x86/include/asm/i8259.h
16579@@ -62,7 +62,7 @@ struct legacy_pic {
16580 void (*init)(int auto_eoi);
16581 int (*irq_pending)(unsigned int irq);
16582 void (*make_irq)(unsigned int irq);
16583-};
16584+} __do_const;
16585
16586 extern struct legacy_pic *legacy_pic;
16587 extern struct legacy_pic null_legacy_pic;
16588diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16589index 91d9c69..dfae7d0 100644
16590--- a/arch/x86/include/asm/io.h
16591+++ b/arch/x86/include/asm/io.h
16592@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16593 "m" (*(volatile type __force *)addr) barrier); }
16594
16595 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16596-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16597-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16598+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16599+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16600
16601 build_mmio_read(__readb, "b", unsigned char, "=q", )
16602-build_mmio_read(__readw, "w", unsigned short, "=r", )
16603-build_mmio_read(__readl, "l", unsigned int, "=r", )
16604+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16605+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16606
16607 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16608 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16609@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16610 return ioremap_nocache(offset, size);
16611 }
16612
16613-extern void iounmap(volatile void __iomem *addr);
16614+extern void iounmap(const volatile void __iomem *addr);
16615
16616 extern void set_iounmap_nonlazy(void);
16617
16618@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16619
16620 #include <linux/vmalloc.h>
16621
16622+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16623+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16624+{
16625+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16626+}
16627+
16628+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16629+{
16630+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16631+}
16632+
16633 /*
16634 * Convert a virtual cached pointer to an uncached pointer
16635 */
16636diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16637index bba3cf8..06bc8da 100644
16638--- a/arch/x86/include/asm/irqflags.h
16639+++ b/arch/x86/include/asm/irqflags.h
16640@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16641 sti; \
16642 sysexit
16643
16644+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16645+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16646+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16647+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16648+
16649 #else
16650 #define INTERRUPT_RETURN iret
16651 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16652diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16653index 9454c16..e4100e3 100644
16654--- a/arch/x86/include/asm/kprobes.h
16655+++ b/arch/x86/include/asm/kprobes.h
16656@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16657 #define RELATIVEJUMP_SIZE 5
16658 #define RELATIVECALL_OPCODE 0xe8
16659 #define RELATIVE_ADDR_SIZE 4
16660-#define MAX_STACK_SIZE 64
16661-#define MIN_STACK_SIZE(ADDR) \
16662- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16663- THREAD_SIZE - (unsigned long)(ADDR))) \
16664- ? (MAX_STACK_SIZE) \
16665- : (((unsigned long)current_thread_info()) + \
16666- THREAD_SIZE - (unsigned long)(ADDR)))
16667+#define MAX_STACK_SIZE 64UL
16668+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16669
16670 #define flush_insn_slot(p) do { } while (0)
16671
16672diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16673index 4ad6560..75c7bdd 100644
16674--- a/arch/x86/include/asm/local.h
16675+++ b/arch/x86/include/asm/local.h
16676@@ -10,33 +10,97 @@ typedef struct {
16677 atomic_long_t a;
16678 } local_t;
16679
16680+typedef struct {
16681+ atomic_long_unchecked_t a;
16682+} local_unchecked_t;
16683+
16684 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16685
16686 #define local_read(l) atomic_long_read(&(l)->a)
16687+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16688 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16689+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16690
16691 static inline void local_inc(local_t *l)
16692 {
16693- asm volatile(_ASM_INC "%0"
16694+ asm volatile(_ASM_INC "%0\n"
16695+
16696+#ifdef CONFIG_PAX_REFCOUNT
16697+ "jno 0f\n"
16698+ _ASM_DEC "%0\n"
16699+ "int $4\n0:\n"
16700+ _ASM_EXTABLE(0b, 0b)
16701+#endif
16702+
16703+ : "+m" (l->a.counter));
16704+}
16705+
16706+static inline void local_inc_unchecked(local_unchecked_t *l)
16707+{
16708+ asm volatile(_ASM_INC "%0\n"
16709 : "+m" (l->a.counter));
16710 }
16711
16712 static inline void local_dec(local_t *l)
16713 {
16714- asm volatile(_ASM_DEC "%0"
16715+ asm volatile(_ASM_DEC "%0\n"
16716+
16717+#ifdef CONFIG_PAX_REFCOUNT
16718+ "jno 0f\n"
16719+ _ASM_INC "%0\n"
16720+ "int $4\n0:\n"
16721+ _ASM_EXTABLE(0b, 0b)
16722+#endif
16723+
16724+ : "+m" (l->a.counter));
16725+}
16726+
16727+static inline void local_dec_unchecked(local_unchecked_t *l)
16728+{
16729+ asm volatile(_ASM_DEC "%0\n"
16730 : "+m" (l->a.counter));
16731 }
16732
16733 static inline void local_add(long i, local_t *l)
16734 {
16735- asm volatile(_ASM_ADD "%1,%0"
16736+ asm volatile(_ASM_ADD "%1,%0\n"
16737+
16738+#ifdef CONFIG_PAX_REFCOUNT
16739+ "jno 0f\n"
16740+ _ASM_SUB "%1,%0\n"
16741+ "int $4\n0:\n"
16742+ _ASM_EXTABLE(0b, 0b)
16743+#endif
16744+
16745+ : "+m" (l->a.counter)
16746+ : "ir" (i));
16747+}
16748+
16749+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16750+{
16751+ asm volatile(_ASM_ADD "%1,%0\n"
16752 : "+m" (l->a.counter)
16753 : "ir" (i));
16754 }
16755
16756 static inline void local_sub(long i, local_t *l)
16757 {
16758- asm volatile(_ASM_SUB "%1,%0"
16759+ asm volatile(_ASM_SUB "%1,%0\n"
16760+
16761+#ifdef CONFIG_PAX_REFCOUNT
16762+ "jno 0f\n"
16763+ _ASM_ADD "%1,%0\n"
16764+ "int $4\n0:\n"
16765+ _ASM_EXTABLE(0b, 0b)
16766+#endif
16767+
16768+ : "+m" (l->a.counter)
16769+ : "ir" (i));
16770+}
16771+
16772+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16773+{
16774+ asm volatile(_ASM_SUB "%1,%0\n"
16775 : "+m" (l->a.counter)
16776 : "ir" (i));
16777 }
16778@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16779 */
16780 static inline int local_sub_and_test(long i, local_t *l)
16781 {
16782- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16783+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16784 }
16785
16786 /**
16787@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16788 */
16789 static inline int local_dec_and_test(local_t *l)
16790 {
16791- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16792+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16793 }
16794
16795 /**
16796@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16797 */
16798 static inline int local_inc_and_test(local_t *l)
16799 {
16800- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16801+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16802 }
16803
16804 /**
16805@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16806 */
16807 static inline int local_add_negative(long i, local_t *l)
16808 {
16809- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16810+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16811 }
16812
16813 /**
16814@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16815 static inline long local_add_return(long i, local_t *l)
16816 {
16817 long __i = i;
16818+ asm volatile(_ASM_XADD "%0, %1\n"
16819+
16820+#ifdef CONFIG_PAX_REFCOUNT
16821+ "jno 0f\n"
16822+ _ASM_MOV "%0,%1\n"
16823+ "int $4\n0:\n"
16824+ _ASM_EXTABLE(0b, 0b)
16825+#endif
16826+
16827+ : "+r" (i), "+m" (l->a.counter)
16828+ : : "memory");
16829+ return i + __i;
16830+}
16831+
16832+/**
16833+ * local_add_return_unchecked - add and return
16834+ * @i: integer value to add
16835+ * @l: pointer to type local_unchecked_t
16836+ *
16837+ * Atomically adds @i to @l and returns @i + @l
16838+ */
16839+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16840+{
16841+ long __i = i;
16842 asm volatile(_ASM_XADD "%0, %1;"
16843 : "+r" (i), "+m" (l->a.counter)
16844 : : "memory");
16845@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16846
16847 #define local_cmpxchg(l, o, n) \
16848 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16849+#define local_cmpxchg_unchecked(l, o, n) \
16850+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16851 /* Always has a lock prefix */
16852 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16853
16854diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16855new file mode 100644
16856index 0000000..2bfd3ba
16857--- /dev/null
16858+++ b/arch/x86/include/asm/mman.h
16859@@ -0,0 +1,15 @@
16860+#ifndef _X86_MMAN_H
16861+#define _X86_MMAN_H
16862+
16863+#include <uapi/asm/mman.h>
16864+
16865+#ifdef __KERNEL__
16866+#ifndef __ASSEMBLY__
16867+#ifdef CONFIG_X86_32
16868+#define arch_mmap_check i386_mmap_check
16869+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16870+#endif
16871+#endif
16872+#endif
16873+
16874+#endif /* X86_MMAN_H */
16875diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16876index 5f55e69..e20bfb1 100644
16877--- a/arch/x86/include/asm/mmu.h
16878+++ b/arch/x86/include/asm/mmu.h
16879@@ -9,7 +9,7 @@
16880 * we put the segment information here.
16881 */
16882 typedef struct {
16883- void *ldt;
16884+ struct desc_struct *ldt;
16885 int size;
16886
16887 #ifdef CONFIG_X86_64
16888@@ -18,7 +18,19 @@ typedef struct {
16889 #endif
16890
16891 struct mutex lock;
16892- void *vdso;
16893+ unsigned long vdso;
16894+
16895+#ifdef CONFIG_X86_32
16896+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16897+ unsigned long user_cs_base;
16898+ unsigned long user_cs_limit;
16899+
16900+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16901+ cpumask_t cpu_user_cs_mask;
16902+#endif
16903+
16904+#endif
16905+#endif
16906 } mm_context_t;
16907
16908 #ifdef CONFIG_SMP
16909diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16910index be12c53..4d24039 100644
16911--- a/arch/x86/include/asm/mmu_context.h
16912+++ b/arch/x86/include/asm/mmu_context.h
16913@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16914
16915 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16916 {
16917+
16918+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16919+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
16920+ unsigned int i;
16921+ pgd_t *pgd;
16922+
16923+ pax_open_kernel();
16924+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
16925+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16926+ set_pgd_batched(pgd+i, native_make_pgd(0));
16927+ pax_close_kernel();
16928+ }
16929+#endif
16930+
16931 #ifdef CONFIG_SMP
16932 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16933 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16934@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16935 struct task_struct *tsk)
16936 {
16937 unsigned cpu = smp_processor_id();
16938+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16939+ int tlbstate = TLBSTATE_OK;
16940+#endif
16941
16942 if (likely(prev != next)) {
16943 #ifdef CONFIG_SMP
16944+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16945+ tlbstate = this_cpu_read(cpu_tlbstate.state);
16946+#endif
16947 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16948 this_cpu_write(cpu_tlbstate.active_mm, next);
16949 #endif
16950 cpumask_set_cpu(cpu, mm_cpumask(next));
16951
16952 /* Re-load page tables */
16953+#ifdef CONFIG_PAX_PER_CPU_PGD
16954+ pax_open_kernel();
16955+
16956+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16957+ if (static_cpu_has(X86_FEATURE_PCID))
16958+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16959+ else
16960+#endif
16961+
16962+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16963+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16964+ pax_close_kernel();
16965+ 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));
16966+
16967+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16968+ if (static_cpu_has(X86_FEATURE_PCID)) {
16969+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
16970+ u64 descriptor[2];
16971+ descriptor[0] = PCID_USER;
16972+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16973+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16974+ descriptor[0] = PCID_KERNEL;
16975+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16976+ }
16977+ } else {
16978+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16979+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16980+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16981+ else
16982+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16983+ }
16984+ } else
16985+#endif
16986+
16987+ load_cr3(get_cpu_pgd(cpu, kernel));
16988+#else
16989 load_cr3(next->pgd);
16990+#endif
16991
16992 /* Stop flush ipis for the previous mm */
16993 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16994@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16995 /* Load the LDT, if the LDT is different: */
16996 if (unlikely(prev->context.ldt != next->context.ldt))
16997 load_LDT_nolock(&next->context);
16998+
16999+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17000+ if (!(__supported_pte_mask & _PAGE_NX)) {
17001+ smp_mb__before_clear_bit();
17002+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17003+ smp_mb__after_clear_bit();
17004+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17005+ }
17006+#endif
17007+
17008+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17009+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17010+ prev->context.user_cs_limit != next->context.user_cs_limit))
17011+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17012+#ifdef CONFIG_SMP
17013+ else if (unlikely(tlbstate != TLBSTATE_OK))
17014+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17015+#endif
17016+#endif
17017+
17018 }
17019+ else {
17020+
17021+#ifdef CONFIG_PAX_PER_CPU_PGD
17022+ pax_open_kernel();
17023+
17024+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17025+ if (static_cpu_has(X86_FEATURE_PCID))
17026+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17027+ else
17028+#endif
17029+
17030+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17031+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17032+ pax_close_kernel();
17033+ 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));
17034+
17035+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17036+ if (static_cpu_has(X86_FEATURE_PCID)) {
17037+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17038+ u64 descriptor[2];
17039+ descriptor[0] = PCID_USER;
17040+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17041+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17042+ descriptor[0] = PCID_KERNEL;
17043+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17044+ }
17045+ } else {
17046+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17047+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17048+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17049+ else
17050+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17051+ }
17052+ } else
17053+#endif
17054+
17055+ load_cr3(get_cpu_pgd(cpu, kernel));
17056+#endif
17057+
17058 #ifdef CONFIG_SMP
17059- else {
17060 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17061 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17062
17063@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17064 * tlb flush IPI delivery. We must reload CR3
17065 * to make sure to use no freed page tables.
17066 */
17067+
17068+#ifndef CONFIG_PAX_PER_CPU_PGD
17069 load_cr3(next->pgd);
17070+#endif
17071+
17072 load_LDT_nolock(&next->context);
17073+
17074+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17075+ if (!(__supported_pte_mask & _PAGE_NX))
17076+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17077+#endif
17078+
17079+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17080+#ifdef CONFIG_PAX_PAGEEXEC
17081+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17082+#endif
17083+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17084+#endif
17085+
17086 }
17087+#endif
17088 }
17089-#endif
17090 }
17091
17092 #define activate_mm(prev, next) \
17093diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17094index e3b7819..b257c64 100644
17095--- a/arch/x86/include/asm/module.h
17096+++ b/arch/x86/include/asm/module.h
17097@@ -5,6 +5,7 @@
17098
17099 #ifdef CONFIG_X86_64
17100 /* X86_64 does not define MODULE_PROC_FAMILY */
17101+#define MODULE_PROC_FAMILY ""
17102 #elif defined CONFIG_M486
17103 #define MODULE_PROC_FAMILY "486 "
17104 #elif defined CONFIG_M586
17105@@ -57,8 +58,20 @@
17106 #error unknown processor family
17107 #endif
17108
17109-#ifdef CONFIG_X86_32
17110-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17111+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17112+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17113+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17114+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17115+#else
17116+#define MODULE_PAX_KERNEXEC ""
17117 #endif
17118
17119+#ifdef CONFIG_PAX_MEMORY_UDEREF
17120+#define MODULE_PAX_UDEREF "UDEREF "
17121+#else
17122+#define MODULE_PAX_UDEREF ""
17123+#endif
17124+
17125+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17126+
17127 #endif /* _ASM_X86_MODULE_H */
17128diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17129index 86f9301..b365cda 100644
17130--- a/arch/x86/include/asm/nmi.h
17131+++ b/arch/x86/include/asm/nmi.h
17132@@ -40,11 +40,11 @@ struct nmiaction {
17133 nmi_handler_t handler;
17134 unsigned long flags;
17135 const char *name;
17136-};
17137+} __do_const;
17138
17139 #define register_nmi_handler(t, fn, fg, n, init...) \
17140 ({ \
17141- static struct nmiaction init fn##_na = { \
17142+ static const struct nmiaction init fn##_na = { \
17143 .handler = (fn), \
17144 .name = (n), \
17145 .flags = (fg), \
17146@@ -52,7 +52,7 @@ struct nmiaction {
17147 __register_nmi_handler((t), &fn##_na); \
17148 })
17149
17150-int __register_nmi_handler(unsigned int, struct nmiaction *);
17151+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17152
17153 void unregister_nmi_handler(unsigned int, const char *);
17154
17155diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17156index 775873d..de5f0304 100644
17157--- a/arch/x86/include/asm/page.h
17158+++ b/arch/x86/include/asm/page.h
17159@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17160 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17161
17162 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17163+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17164
17165 #define __boot_va(x) __va(x)
17166 #define __boot_pa(x) __pa(x)
17167diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17168index 0f1ddee..e2fc3d1 100644
17169--- a/arch/x86/include/asm/page_64.h
17170+++ b/arch/x86/include/asm/page_64.h
17171@@ -7,9 +7,9 @@
17172
17173 /* duplicated to the one in bootmem.h */
17174 extern unsigned long max_pfn;
17175-extern unsigned long phys_base;
17176+extern const unsigned long phys_base;
17177
17178-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17179+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17180 {
17181 unsigned long y = x - __START_KERNEL_map;
17182
17183diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17184index cd6e1610..70f4418 100644
17185--- a/arch/x86/include/asm/paravirt.h
17186+++ b/arch/x86/include/asm/paravirt.h
17187@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17188 return (pmd_t) { ret };
17189 }
17190
17191-static inline pmdval_t pmd_val(pmd_t pmd)
17192+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17193 {
17194 pmdval_t ret;
17195
17196@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17197 val);
17198 }
17199
17200+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17201+{
17202+ pgdval_t val = native_pgd_val(pgd);
17203+
17204+ if (sizeof(pgdval_t) > sizeof(long))
17205+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17206+ val, (u64)val >> 32);
17207+ else
17208+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17209+ val);
17210+}
17211+
17212 static inline void pgd_clear(pgd_t *pgdp)
17213 {
17214 set_pgd(pgdp, __pgd(0));
17215@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17216 pv_mmu_ops.set_fixmap(idx, phys, flags);
17217 }
17218
17219+#ifdef CONFIG_PAX_KERNEXEC
17220+static inline unsigned long pax_open_kernel(void)
17221+{
17222+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17223+}
17224+
17225+static inline unsigned long pax_close_kernel(void)
17226+{
17227+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17228+}
17229+#else
17230+static inline unsigned long pax_open_kernel(void) { return 0; }
17231+static inline unsigned long pax_close_kernel(void) { return 0; }
17232+#endif
17233+
17234 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17235
17236 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17237@@ -906,7 +933,7 @@ extern void default_banner(void);
17238
17239 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17240 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17241-#define PARA_INDIRECT(addr) *%cs:addr
17242+#define PARA_INDIRECT(addr) *%ss:addr
17243 #endif
17244
17245 #define INTERRUPT_RETURN \
17246@@ -981,6 +1008,21 @@ extern void default_banner(void);
17247 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17248 CLBR_NONE, \
17249 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17250+
17251+#define GET_CR0_INTO_RDI \
17252+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17253+ mov %rax,%rdi
17254+
17255+#define SET_RDI_INTO_CR0 \
17256+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17257+
17258+#define GET_CR3_INTO_RDI \
17259+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17260+ mov %rax,%rdi
17261+
17262+#define SET_RDI_INTO_CR3 \
17263+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17264+
17265 #endif /* CONFIG_X86_32 */
17266
17267 #endif /* __ASSEMBLY__ */
17268diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17269index 7549b8b..f0edfda 100644
17270--- a/arch/x86/include/asm/paravirt_types.h
17271+++ b/arch/x86/include/asm/paravirt_types.h
17272@@ -84,7 +84,7 @@ struct pv_init_ops {
17273 */
17274 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17275 unsigned long addr, unsigned len);
17276-};
17277+} __no_const __no_randomize_layout;
17278
17279
17280 struct pv_lazy_ops {
17281@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17282 void (*enter)(void);
17283 void (*leave)(void);
17284 void (*flush)(void);
17285-};
17286+} __no_randomize_layout;
17287
17288 struct pv_time_ops {
17289 unsigned long long (*sched_clock)(void);
17290 unsigned long long (*steal_clock)(int cpu);
17291 unsigned long (*get_tsc_khz)(void);
17292-};
17293+} __no_const __no_randomize_layout;
17294
17295 struct pv_cpu_ops {
17296 /* hooks for various privileged instructions */
17297@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17298
17299 void (*start_context_switch)(struct task_struct *prev);
17300 void (*end_context_switch)(struct task_struct *next);
17301-};
17302+} __no_const __no_randomize_layout;
17303
17304 struct pv_irq_ops {
17305 /*
17306@@ -215,7 +215,7 @@ struct pv_irq_ops {
17307 #ifdef CONFIG_X86_64
17308 void (*adjust_exception_frame)(void);
17309 #endif
17310-};
17311+} __no_randomize_layout;
17312
17313 struct pv_apic_ops {
17314 #ifdef CONFIG_X86_LOCAL_APIC
17315@@ -223,7 +223,7 @@ struct pv_apic_ops {
17316 unsigned long start_eip,
17317 unsigned long start_esp);
17318 #endif
17319-};
17320+} __no_const __no_randomize_layout;
17321
17322 struct pv_mmu_ops {
17323 unsigned long (*read_cr2)(void);
17324@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17325 struct paravirt_callee_save make_pud;
17326
17327 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17328+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17329 #endif /* PAGETABLE_LEVELS == 4 */
17330 #endif /* PAGETABLE_LEVELS >= 3 */
17331
17332@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17333 an mfn. We can tell which is which from the index. */
17334 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17335 phys_addr_t phys, pgprot_t flags);
17336-};
17337+
17338+#ifdef CONFIG_PAX_KERNEXEC
17339+ unsigned long (*pax_open_kernel)(void);
17340+ unsigned long (*pax_close_kernel)(void);
17341+#endif
17342+
17343+} __no_randomize_layout;
17344
17345 struct arch_spinlock;
17346 #ifdef CONFIG_SMP
17347@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17348 struct pv_lock_ops {
17349 struct paravirt_callee_save lock_spinning;
17350 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17351-};
17352+} __no_randomize_layout;
17353
17354 /* This contains all the paravirt structures: we get a convenient
17355 * number for each function using the offset which we use to indicate
17356- * what to patch. */
17357+ * what to patch.
17358+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17359+ */
17360+
17361 struct paravirt_patch_template {
17362 struct pv_init_ops pv_init_ops;
17363 struct pv_time_ops pv_time_ops;
17364@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17365 struct pv_apic_ops pv_apic_ops;
17366 struct pv_mmu_ops pv_mmu_ops;
17367 struct pv_lock_ops pv_lock_ops;
17368-};
17369+} __no_randomize_layout;
17370
17371 extern struct pv_info pv_info;
17372 extern struct pv_init_ops pv_init_ops;
17373diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17374index c4412e9..90e88c5 100644
17375--- a/arch/x86/include/asm/pgalloc.h
17376+++ b/arch/x86/include/asm/pgalloc.h
17377@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17378 pmd_t *pmd, pte_t *pte)
17379 {
17380 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17381+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17382+}
17383+
17384+static inline void pmd_populate_user(struct mm_struct *mm,
17385+ pmd_t *pmd, pte_t *pte)
17386+{
17387+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17388 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17389 }
17390
17391@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17392
17393 #ifdef CONFIG_X86_PAE
17394 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17395+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17396+{
17397+ pud_populate(mm, pudp, pmd);
17398+}
17399 #else /* !CONFIG_X86_PAE */
17400 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17401 {
17402 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17403 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17404 }
17405+
17406+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17407+{
17408+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17409+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17410+}
17411 #endif /* CONFIG_X86_PAE */
17412
17413 #if PAGETABLE_LEVELS > 3
17414@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17415 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17416 }
17417
17418+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17419+{
17420+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17421+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17422+}
17423+
17424 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17425 {
17426 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17427diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17428index 0d193e2..bf59aeb 100644
17429--- a/arch/x86/include/asm/pgtable-2level.h
17430+++ b/arch/x86/include/asm/pgtable-2level.h
17431@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17432
17433 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17434 {
17435+ pax_open_kernel();
17436 *pmdp = pmd;
17437+ pax_close_kernel();
17438 }
17439
17440 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17441diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17442index 81bb91b..9392125 100644
17443--- a/arch/x86/include/asm/pgtable-3level.h
17444+++ b/arch/x86/include/asm/pgtable-3level.h
17445@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17446
17447 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17448 {
17449+ pax_open_kernel();
17450 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17451+ pax_close_kernel();
17452 }
17453
17454 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17455 {
17456+ pax_open_kernel();
17457 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17458+ pax_close_kernel();
17459 }
17460
17461 /*
17462diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17463index bbc8b12..f228861 100644
17464--- a/arch/x86/include/asm/pgtable.h
17465+++ b/arch/x86/include/asm/pgtable.h
17466@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17467
17468 #ifndef __PAGETABLE_PUD_FOLDED
17469 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17470+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17471 #define pgd_clear(pgd) native_pgd_clear(pgd)
17472 #endif
17473
17474@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17475
17476 #define arch_end_context_switch(prev) do {} while(0)
17477
17478+#define pax_open_kernel() native_pax_open_kernel()
17479+#define pax_close_kernel() native_pax_close_kernel()
17480 #endif /* CONFIG_PARAVIRT */
17481
17482+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17483+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17484+
17485+#ifdef CONFIG_PAX_KERNEXEC
17486+static inline unsigned long native_pax_open_kernel(void)
17487+{
17488+ unsigned long cr0;
17489+
17490+ preempt_disable();
17491+ barrier();
17492+ cr0 = read_cr0() ^ X86_CR0_WP;
17493+ BUG_ON(cr0 & X86_CR0_WP);
17494+ write_cr0(cr0);
17495+ return cr0 ^ X86_CR0_WP;
17496+}
17497+
17498+static inline unsigned long native_pax_close_kernel(void)
17499+{
17500+ unsigned long cr0;
17501+
17502+ cr0 = read_cr0() ^ X86_CR0_WP;
17503+ BUG_ON(!(cr0 & X86_CR0_WP));
17504+ write_cr0(cr0);
17505+ barrier();
17506+ preempt_enable_no_resched();
17507+ return cr0 ^ X86_CR0_WP;
17508+}
17509+#else
17510+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17511+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17512+#endif
17513+
17514 /*
17515 * The following only work if pte_present() is true.
17516 * Undefined behaviour if not..
17517 */
17518+static inline int pte_user(pte_t pte)
17519+{
17520+ return pte_val(pte) & _PAGE_USER;
17521+}
17522+
17523 static inline int pte_dirty(pte_t pte)
17524 {
17525 return pte_flags(pte) & _PAGE_DIRTY;
17526@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17527 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17528 }
17529
17530+static inline unsigned long pgd_pfn(pgd_t pgd)
17531+{
17532+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17533+}
17534+
17535 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17536
17537 static inline int pmd_large(pmd_t pte)
17538@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17539 return pte_clear_flags(pte, _PAGE_RW);
17540 }
17541
17542+static inline pte_t pte_mkread(pte_t pte)
17543+{
17544+ return __pte(pte_val(pte) | _PAGE_USER);
17545+}
17546+
17547 static inline pte_t pte_mkexec(pte_t pte)
17548 {
17549- return pte_clear_flags(pte, _PAGE_NX);
17550+#ifdef CONFIG_X86_PAE
17551+ if (__supported_pte_mask & _PAGE_NX)
17552+ return pte_clear_flags(pte, _PAGE_NX);
17553+ else
17554+#endif
17555+ return pte_set_flags(pte, _PAGE_USER);
17556+}
17557+
17558+static inline pte_t pte_exprotect(pte_t pte)
17559+{
17560+#ifdef CONFIG_X86_PAE
17561+ if (__supported_pte_mask & _PAGE_NX)
17562+ return pte_set_flags(pte, _PAGE_NX);
17563+ else
17564+#endif
17565+ return pte_clear_flags(pte, _PAGE_USER);
17566 }
17567
17568 static inline pte_t pte_mkdirty(pte_t pte)
17569@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17570 #endif
17571
17572 #ifndef __ASSEMBLY__
17573+
17574+#ifdef CONFIG_PAX_PER_CPU_PGD
17575+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17576+enum cpu_pgd_type {kernel = 0, user = 1};
17577+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17578+{
17579+ return cpu_pgd[cpu][type];
17580+}
17581+#endif
17582+
17583 #include <linux/mm_types.h>
17584 #include <linux/mmdebug.h>
17585 #include <linux/log2.h>
17586@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17587 * Currently stuck as a macro due to indirect forward reference to
17588 * linux/mmzone.h's __section_mem_map_addr() definition:
17589 */
17590-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17591+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17592
17593 /* Find an entry in the second-level page table.. */
17594 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17595@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17596 * Currently stuck as a macro due to indirect forward reference to
17597 * linux/mmzone.h's __section_mem_map_addr() definition:
17598 */
17599-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17600+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17601
17602 /* to find an entry in a page-table-directory. */
17603 static inline unsigned long pud_index(unsigned long address)
17604@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17605
17606 static inline int pgd_bad(pgd_t pgd)
17607 {
17608- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17609+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17610 }
17611
17612 static inline int pgd_none(pgd_t pgd)
17613@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17614 * pgd_offset() returns a (pgd_t *)
17615 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17616 */
17617-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17618+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17619+
17620+#ifdef CONFIG_PAX_PER_CPU_PGD
17621+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17622+#endif
17623+
17624 /*
17625 * a shortcut which implies the use of the kernel's pgd, instead
17626 * of a process's
17627@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17628 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17629 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17630
17631+#ifdef CONFIG_X86_32
17632+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17633+#else
17634+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17635+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17636+
17637+#ifdef CONFIG_PAX_MEMORY_UDEREF
17638+#ifdef __ASSEMBLY__
17639+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17640+#else
17641+extern unsigned long pax_user_shadow_base;
17642+extern pgdval_t clone_pgd_mask;
17643+#endif
17644+#endif
17645+
17646+#endif
17647+
17648 #ifndef __ASSEMBLY__
17649
17650 extern int direct_gbpages;
17651@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17652 * dst and src can be on the same page, but the range must not overlap,
17653 * and must not cross a page boundary.
17654 */
17655-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17656+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17657 {
17658- memcpy(dst, src, count * sizeof(pgd_t));
17659+ pax_open_kernel();
17660+ while (count--)
17661+ *dst++ = *src++;
17662+ pax_close_kernel();
17663 }
17664
17665+#ifdef CONFIG_PAX_PER_CPU_PGD
17666+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17667+#endif
17668+
17669+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17670+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17671+#else
17672+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17673+#endif
17674+
17675 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17676 static inline int page_level_shift(enum pg_level level)
17677 {
17678diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17679index 9ee3221..b979c6b 100644
17680--- a/arch/x86/include/asm/pgtable_32.h
17681+++ b/arch/x86/include/asm/pgtable_32.h
17682@@ -25,9 +25,6 @@
17683 struct mm_struct;
17684 struct vm_area_struct;
17685
17686-extern pgd_t swapper_pg_dir[1024];
17687-extern pgd_t initial_page_table[1024];
17688-
17689 static inline void pgtable_cache_init(void) { }
17690 static inline void check_pgt_cache(void) { }
17691 void paging_init(void);
17692@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17693 # include <asm/pgtable-2level.h>
17694 #endif
17695
17696+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17697+extern pgd_t initial_page_table[PTRS_PER_PGD];
17698+#ifdef CONFIG_X86_PAE
17699+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17700+#endif
17701+
17702 #if defined(CONFIG_HIGHPTE)
17703 #define pte_offset_map(dir, address) \
17704 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17705@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17706 /* Clear a kernel PTE and flush it from the TLB */
17707 #define kpte_clear_flush(ptep, vaddr) \
17708 do { \
17709+ pax_open_kernel(); \
17710 pte_clear(&init_mm, (vaddr), (ptep)); \
17711+ pax_close_kernel(); \
17712 __flush_tlb_one((vaddr)); \
17713 } while (0)
17714
17715 #endif /* !__ASSEMBLY__ */
17716
17717+#define HAVE_ARCH_UNMAPPED_AREA
17718+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17719+
17720 /*
17721 * kern_addr_valid() is (1) for FLATMEM and (0) for
17722 * SPARSEMEM and DISCONTIGMEM
17723diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17724index ed5903b..c7fe163 100644
17725--- a/arch/x86/include/asm/pgtable_32_types.h
17726+++ b/arch/x86/include/asm/pgtable_32_types.h
17727@@ -8,7 +8,7 @@
17728 */
17729 #ifdef CONFIG_X86_PAE
17730 # include <asm/pgtable-3level_types.h>
17731-# define PMD_SIZE (1UL << PMD_SHIFT)
17732+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17733 # define PMD_MASK (~(PMD_SIZE - 1))
17734 #else
17735 # include <asm/pgtable-2level_types.h>
17736@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17737 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17738 #endif
17739
17740+#ifdef CONFIG_PAX_KERNEXEC
17741+#ifndef __ASSEMBLY__
17742+extern unsigned char MODULES_EXEC_VADDR[];
17743+extern unsigned char MODULES_EXEC_END[];
17744+#endif
17745+#include <asm/boot.h>
17746+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17747+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17748+#else
17749+#define ktla_ktva(addr) (addr)
17750+#define ktva_ktla(addr) (addr)
17751+#endif
17752+
17753 #define MODULES_VADDR VMALLOC_START
17754 #define MODULES_END VMALLOC_END
17755 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17756diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17757index e22c1db..23a625a 100644
17758--- a/arch/x86/include/asm/pgtable_64.h
17759+++ b/arch/x86/include/asm/pgtable_64.h
17760@@ -16,10 +16,14 @@
17761
17762 extern pud_t level3_kernel_pgt[512];
17763 extern pud_t level3_ident_pgt[512];
17764+extern pud_t level3_vmalloc_start_pgt[512];
17765+extern pud_t level3_vmalloc_end_pgt[512];
17766+extern pud_t level3_vmemmap_pgt[512];
17767+extern pud_t level2_vmemmap_pgt[512];
17768 extern pmd_t level2_kernel_pgt[512];
17769 extern pmd_t level2_fixmap_pgt[512];
17770-extern pmd_t level2_ident_pgt[512];
17771-extern pgd_t init_level4_pgt[];
17772+extern pmd_t level2_ident_pgt[512*2];
17773+extern pgd_t init_level4_pgt[512];
17774
17775 #define swapper_pg_dir init_level4_pgt
17776
17777@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17778
17779 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17780 {
17781+ pax_open_kernel();
17782 *pmdp = pmd;
17783+ pax_close_kernel();
17784 }
17785
17786 static inline void native_pmd_clear(pmd_t *pmd)
17787@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17788
17789 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17790 {
17791+ pax_open_kernel();
17792 *pudp = pud;
17793+ pax_close_kernel();
17794 }
17795
17796 static inline void native_pud_clear(pud_t *pud)
17797@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17798
17799 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17800 {
17801+ pax_open_kernel();
17802+ *pgdp = pgd;
17803+ pax_close_kernel();
17804+}
17805+
17806+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17807+{
17808 *pgdp = pgd;
17809 }
17810
17811diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17812index c883bf7..19970b3 100644
17813--- a/arch/x86/include/asm/pgtable_64_types.h
17814+++ b/arch/x86/include/asm/pgtable_64_types.h
17815@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17816 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17817 #define MODULES_END _AC(0xffffffffff000000, UL)
17818 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17819+#define MODULES_EXEC_VADDR MODULES_VADDR
17820+#define MODULES_EXEC_END MODULES_END
17821+
17822+#define ktla_ktva(addr) (addr)
17823+#define ktva_ktla(addr) (addr)
17824
17825 #define EARLY_DYNAMIC_PAGE_TABLES 64
17826
17827diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17828index 94e40f1..ebd03e4 100644
17829--- a/arch/x86/include/asm/pgtable_types.h
17830+++ b/arch/x86/include/asm/pgtable_types.h
17831@@ -16,13 +16,12 @@
17832 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17833 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17834 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17835-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17836+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17837 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17838 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17839 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17840-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17841-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17842-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17843+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17844+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17845 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17846
17847 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17848@@ -40,7 +39,6 @@
17849 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17850 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17851 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17852-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17853 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17854 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17855 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17856@@ -87,8 +85,10 @@
17857
17858 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17859 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17860-#else
17861+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17862 #define _PAGE_NX (_AT(pteval_t, 0))
17863+#else
17864+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17865 #endif
17866
17867 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17868@@ -147,6 +147,9 @@
17869 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17870 _PAGE_ACCESSED)
17871
17872+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17873+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17874+
17875 #define __PAGE_KERNEL_EXEC \
17876 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17877 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17878@@ -157,7 +160,7 @@
17879 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17880 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17881 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17882-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17883+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17884 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17885 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17886 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17887@@ -219,8 +222,8 @@
17888 * bits are combined, this will alow user to access the high address mapped
17889 * VDSO in the presence of CONFIG_COMPAT_VDSO
17890 */
17891-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17892-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17893+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17894+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17895 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17896 #endif
17897
17898@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17899 {
17900 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17901 }
17902+#endif
17903
17904+#if PAGETABLE_LEVELS == 3
17905+#include <asm-generic/pgtable-nopud.h>
17906+#endif
17907+
17908+#if PAGETABLE_LEVELS == 2
17909+#include <asm-generic/pgtable-nopmd.h>
17910+#endif
17911+
17912+#ifndef __ASSEMBLY__
17913 #if PAGETABLE_LEVELS > 3
17914 typedef struct { pudval_t pud; } pud_t;
17915
17916@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17917 return pud.pud;
17918 }
17919 #else
17920-#include <asm-generic/pgtable-nopud.h>
17921-
17922 static inline pudval_t native_pud_val(pud_t pud)
17923 {
17924 return native_pgd_val(pud.pgd);
17925@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17926 return pmd.pmd;
17927 }
17928 #else
17929-#include <asm-generic/pgtable-nopmd.h>
17930-
17931 static inline pmdval_t native_pmd_val(pmd_t pmd)
17932 {
17933 return native_pgd_val(pmd.pud.pgd);
17934@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17935
17936 extern pteval_t __supported_pte_mask;
17937 extern void set_nx(void);
17938-extern int nx_enabled;
17939
17940 #define pgprot_writecombine pgprot_writecombine
17941 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17942diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17943index c8b0519..fd29e73 100644
17944--- a/arch/x86/include/asm/preempt.h
17945+++ b/arch/x86/include/asm/preempt.h
17946@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17947 */
17948 static __always_inline bool __preempt_count_dec_and_test(void)
17949 {
17950- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17951+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17952 }
17953
17954 /*
17955diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17956index fdedd38..95c02c2 100644
17957--- a/arch/x86/include/asm/processor.h
17958+++ b/arch/x86/include/asm/processor.h
17959@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17960 /* Index into per_cpu list: */
17961 u16 cpu_index;
17962 u32 microcode;
17963-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17964+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17965
17966 #define X86_VENDOR_INTEL 0
17967 #define X86_VENDOR_CYRIX 1
17968@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17969 : "memory");
17970 }
17971
17972+/* invpcid (%rdx),%rax */
17973+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17974+
17975+#define INVPCID_SINGLE_ADDRESS 0UL
17976+#define INVPCID_SINGLE_CONTEXT 1UL
17977+#define INVPCID_ALL_GLOBAL 2UL
17978+#define INVPCID_ALL_MONGLOBAL 3UL
17979+
17980+#define PCID_KERNEL 0UL
17981+#define PCID_USER 1UL
17982+#define PCID_NOFLUSH (1UL << 63)
17983+
17984 static inline void load_cr3(pgd_t *pgdir)
17985 {
17986- write_cr3(__pa(pgdir));
17987+ write_cr3(__pa(pgdir) | PCID_KERNEL);
17988 }
17989
17990 #ifdef CONFIG_X86_32
17991@@ -283,7 +295,7 @@ struct tss_struct {
17992
17993 } ____cacheline_aligned;
17994
17995-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17996+extern struct tss_struct init_tss[NR_CPUS];
17997
17998 /*
17999 * Save the original ist values for checking stack pointers during debugging
18000@@ -470,6 +482,7 @@ struct thread_struct {
18001 unsigned short ds;
18002 unsigned short fsindex;
18003 unsigned short gsindex;
18004+ unsigned short ss;
18005 #endif
18006 #ifdef CONFIG_X86_32
18007 unsigned long ip;
18008@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18009 extern unsigned long mmu_cr4_features;
18010 extern u32 *trampoline_cr4_features;
18011
18012-static inline void set_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-
18024-static inline void clear_in_cr4(unsigned long mask)
18025-{
18026- unsigned long cr4;
18027-
18028- mmu_cr4_features &= ~mask;
18029- if (trampoline_cr4_features)
18030- *trampoline_cr4_features = mmu_cr4_features;
18031- cr4 = read_cr4();
18032- cr4 &= ~mask;
18033- write_cr4(cr4);
18034-}
18035+extern void set_in_cr4(unsigned long mask);
18036+extern void clear_in_cr4(unsigned long mask);
18037
18038 typedef struct {
18039 unsigned long seg;
18040@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18041 */
18042 #define TASK_SIZE PAGE_OFFSET
18043 #define TASK_SIZE_MAX TASK_SIZE
18044+
18045+#ifdef CONFIG_PAX_SEGMEXEC
18046+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18047+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18048+#else
18049 #define STACK_TOP TASK_SIZE
18050-#define STACK_TOP_MAX STACK_TOP
18051+#endif
18052+
18053+#define STACK_TOP_MAX TASK_SIZE
18054
18055 #define INIT_THREAD { \
18056- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18057+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18058 .vm86_info = NULL, \
18059 .sysenter_cs = __KERNEL_CS, \
18060 .io_bitmap_ptr = NULL, \
18061@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18062 */
18063 #define INIT_TSS { \
18064 .x86_tss = { \
18065- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18066+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18067 .ss0 = __KERNEL_DS, \
18068 .ss1 = __KERNEL_CS, \
18069 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18070@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18071 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18072
18073 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18074-#define KSTK_TOP(info) \
18075-({ \
18076- unsigned long *__ptr = (unsigned long *)(info); \
18077- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18078-})
18079+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18080
18081 /*
18082 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18083@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18084 #define task_pt_regs(task) \
18085 ({ \
18086 struct pt_regs *__regs__; \
18087- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18088+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18089 __regs__ - 1; \
18090 })
18091
18092@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18093 /*
18094 * User space process size. 47bits minus one guard page.
18095 */
18096-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18097+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18098
18099 /* This decides where the kernel will search for a free chunk of vm
18100 * space during mmap's.
18101 */
18102 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18103- 0xc0000000 : 0xFFFFe000)
18104+ 0xc0000000 : 0xFFFFf000)
18105
18106 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18107 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18108@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18109 #define STACK_TOP_MAX TASK_SIZE_MAX
18110
18111 #define INIT_THREAD { \
18112- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18113+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18114 }
18115
18116 #define INIT_TSS { \
18117- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18118+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18119 }
18120
18121 /*
18122@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18123 */
18124 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18125
18126+#ifdef CONFIG_PAX_SEGMEXEC
18127+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18128+#endif
18129+
18130 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18131
18132 /* Get/set a process' ability to use the timestamp counter instruction */
18133@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18134 return 0;
18135 }
18136
18137-extern unsigned long arch_align_stack(unsigned long sp);
18138+#define arch_align_stack(x) ((x) & ~0xfUL)
18139 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18140
18141 void default_idle(void);
18142@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18143 #define xen_set_default_idle 0
18144 #endif
18145
18146-void stop_this_cpu(void *dummy);
18147+void stop_this_cpu(void *dummy) __noreturn;
18148 void df_debug(struct pt_regs *regs, long error_code);
18149 #endif /* _ASM_X86_PROCESSOR_H */
18150diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18151index 14fd6fd..6740420 100644
18152--- a/arch/x86/include/asm/ptrace.h
18153+++ b/arch/x86/include/asm/ptrace.h
18154@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18155 }
18156
18157 /*
18158- * user_mode_vm(regs) determines whether a register set came from user mode.
18159+ * user_mode(regs) determines whether a register set came from user mode.
18160 * This is true if V8086 mode was enabled OR if the register set was from
18161 * protected mode with RPL-3 CS value. This tricky test checks that with
18162 * one comparison. Many places in the kernel can bypass this full check
18163- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18164+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18165+ * be used.
18166 */
18167-static inline int user_mode(struct pt_regs *regs)
18168+static inline int user_mode_novm(struct pt_regs *regs)
18169 {
18170 #ifdef CONFIG_X86_32
18171 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18172 #else
18173- return !!(regs->cs & 3);
18174+ return !!(regs->cs & SEGMENT_RPL_MASK);
18175 #endif
18176 }
18177
18178-static inline int user_mode_vm(struct pt_regs *regs)
18179+static inline int user_mode(struct pt_regs *regs)
18180 {
18181 #ifdef CONFIG_X86_32
18182 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18183 USER_RPL;
18184 #else
18185- return user_mode(regs);
18186+ return user_mode_novm(regs);
18187 #endif
18188 }
18189
18190@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18191 #ifdef CONFIG_X86_64
18192 static inline bool user_64bit_mode(struct pt_regs *regs)
18193 {
18194+ unsigned long cs = regs->cs & 0xffff;
18195 #ifndef CONFIG_PARAVIRT
18196 /*
18197 * On non-paravirt systems, this is the only long mode CPL 3
18198 * selector. We do not allow long mode selectors in the LDT.
18199 */
18200- return regs->cs == __USER_CS;
18201+ return cs == __USER_CS;
18202 #else
18203 /* Headers are too twisted for this to go in paravirt.h. */
18204- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18205+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18206 #endif
18207 }
18208
18209@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18210 * Traps from the kernel do not save sp and ss.
18211 * Use the helper function to retrieve sp.
18212 */
18213- if (offset == offsetof(struct pt_regs, sp) &&
18214- regs->cs == __KERNEL_CS)
18215- return kernel_stack_pointer(regs);
18216+ if (offset == offsetof(struct pt_regs, sp)) {
18217+ unsigned long cs = regs->cs & 0xffff;
18218+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18219+ return kernel_stack_pointer(regs);
18220+ }
18221 #endif
18222 return *(unsigned long *)((unsigned long)regs + offset);
18223 }
18224diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18225index 9c6b890..5305f53 100644
18226--- a/arch/x86/include/asm/realmode.h
18227+++ b/arch/x86/include/asm/realmode.h
18228@@ -22,16 +22,14 @@ struct real_mode_header {
18229 #endif
18230 /* APM/BIOS reboot */
18231 u32 machine_real_restart_asm;
18232-#ifdef CONFIG_X86_64
18233 u32 machine_real_restart_seg;
18234-#endif
18235 };
18236
18237 /* This must match data at trampoline_32/64.S */
18238 struct trampoline_header {
18239 #ifdef CONFIG_X86_32
18240 u32 start;
18241- u16 gdt_pad;
18242+ u16 boot_cs;
18243 u16 gdt_limit;
18244 u32 gdt_base;
18245 #else
18246diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18247index a82c4f1..ac45053 100644
18248--- a/arch/x86/include/asm/reboot.h
18249+++ b/arch/x86/include/asm/reboot.h
18250@@ -6,13 +6,13 @@
18251 struct pt_regs;
18252
18253 struct machine_ops {
18254- void (*restart)(char *cmd);
18255- void (*halt)(void);
18256- void (*power_off)(void);
18257+ void (* __noreturn restart)(char *cmd);
18258+ void (* __noreturn halt)(void);
18259+ void (* __noreturn power_off)(void);
18260 void (*shutdown)(void);
18261 void (*crash_shutdown)(struct pt_regs *);
18262- void (*emergency_restart)(void);
18263-};
18264+ void (* __noreturn emergency_restart)(void);
18265+} __no_const;
18266
18267 extern struct machine_ops machine_ops;
18268
18269diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18270index 8f7866a..e442f20 100644
18271--- a/arch/x86/include/asm/rmwcc.h
18272+++ b/arch/x86/include/asm/rmwcc.h
18273@@ -3,7 +3,34 @@
18274
18275 #ifdef CC_HAVE_ASM_GOTO
18276
18277-#define __GEN_RMWcc(fullop, var, cc, ...) \
18278+#ifdef CONFIG_PAX_REFCOUNT
18279+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18280+do { \
18281+ asm_volatile_goto (fullop \
18282+ ";jno 0f\n" \
18283+ fullantiop \
18284+ ";int $4\n0:\n" \
18285+ _ASM_EXTABLE(0b, 0b) \
18286+ ";j" cc " %l[cc_label]" \
18287+ : : "m" (var), ## __VA_ARGS__ \
18288+ : "memory" : cc_label); \
18289+ return 0; \
18290+cc_label: \
18291+ return 1; \
18292+} while (0)
18293+#else
18294+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18295+do { \
18296+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18297+ : : "m" (var), ## __VA_ARGS__ \
18298+ : "memory" : cc_label); \
18299+ return 0; \
18300+cc_label: \
18301+ return 1; \
18302+} while (0)
18303+#endif
18304+
18305+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18306 do { \
18307 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18308 : : "m" (var), ## __VA_ARGS__ \
18309@@ -13,15 +40,46 @@ cc_label: \
18310 return 1; \
18311 } while (0)
18312
18313-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18314- __GEN_RMWcc(op " " arg0, var, cc)
18315+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18316+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18317
18318-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18319- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18320+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18321+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18322+
18323+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18324+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18325+
18326+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18327+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18328
18329 #else /* !CC_HAVE_ASM_GOTO */
18330
18331-#define __GEN_RMWcc(fullop, var, cc, ...) \
18332+#ifdef CONFIG_PAX_REFCOUNT
18333+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18334+do { \
18335+ char c; \
18336+ asm volatile (fullop \
18337+ ";jno 0f\n" \
18338+ fullantiop \
18339+ ";int $4\n0:\n" \
18340+ _ASM_EXTABLE(0b, 0b) \
18341+ "; set" cc " %1" \
18342+ : "+m" (var), "=qm" (c) \
18343+ : __VA_ARGS__ : "memory"); \
18344+ return c != 0; \
18345+} while (0)
18346+#else
18347+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18348+do { \
18349+ char c; \
18350+ asm volatile (fullop "; set" cc " %1" \
18351+ : "+m" (var), "=qm" (c) \
18352+ : __VA_ARGS__ : "memory"); \
18353+ return c != 0; \
18354+} while (0)
18355+#endif
18356+
18357+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18358 do { \
18359 char c; \
18360 asm volatile (fullop "; set" cc " %1" \
18361@@ -30,11 +88,17 @@ do { \
18362 return c != 0; \
18363 } while (0)
18364
18365-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18366- __GEN_RMWcc(op " " arg0, var, cc)
18367+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18368+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18369+
18370+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18371+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18372+
18373+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18374+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18375
18376-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18377- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18378+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18379+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18380
18381 #endif /* CC_HAVE_ASM_GOTO */
18382
18383diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18384index cad82c9..2e5c5c1 100644
18385--- a/arch/x86/include/asm/rwsem.h
18386+++ b/arch/x86/include/asm/rwsem.h
18387@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18388 {
18389 asm volatile("# beginning down_read\n\t"
18390 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18391+
18392+#ifdef CONFIG_PAX_REFCOUNT
18393+ "jno 0f\n"
18394+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18395+ "int $4\n0:\n"
18396+ _ASM_EXTABLE(0b, 0b)
18397+#endif
18398+
18399 /* adds 0x00000001 */
18400 " jns 1f\n"
18401 " call call_rwsem_down_read_failed\n"
18402@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18403 "1:\n\t"
18404 " mov %1,%2\n\t"
18405 " add %3,%2\n\t"
18406+
18407+#ifdef CONFIG_PAX_REFCOUNT
18408+ "jno 0f\n"
18409+ "sub %3,%2\n"
18410+ "int $4\n0:\n"
18411+ _ASM_EXTABLE(0b, 0b)
18412+#endif
18413+
18414 " jle 2f\n\t"
18415 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18416 " jnz 1b\n\t"
18417@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18418 long tmp;
18419 asm volatile("# beginning down_write\n\t"
18420 LOCK_PREFIX " xadd %1,(%2)\n\t"
18421+
18422+#ifdef CONFIG_PAX_REFCOUNT
18423+ "jno 0f\n"
18424+ "mov %1,(%2)\n"
18425+ "int $4\n0:\n"
18426+ _ASM_EXTABLE(0b, 0b)
18427+#endif
18428+
18429 /* adds 0xffff0001, returns the old value */
18430 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18431 /* was the active mask 0 before? */
18432@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18433 long tmp;
18434 asm volatile("# beginning __up_read\n\t"
18435 LOCK_PREFIX " xadd %1,(%2)\n\t"
18436+
18437+#ifdef CONFIG_PAX_REFCOUNT
18438+ "jno 0f\n"
18439+ "mov %1,(%2)\n"
18440+ "int $4\n0:\n"
18441+ _ASM_EXTABLE(0b, 0b)
18442+#endif
18443+
18444 /* subtracts 1, returns the old value */
18445 " jns 1f\n\t"
18446 " call call_rwsem_wake\n" /* expects old value in %edx */
18447@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18448 long tmp;
18449 asm volatile("# beginning __up_write\n\t"
18450 LOCK_PREFIX " xadd %1,(%2)\n\t"
18451+
18452+#ifdef CONFIG_PAX_REFCOUNT
18453+ "jno 0f\n"
18454+ "mov %1,(%2)\n"
18455+ "int $4\n0:\n"
18456+ _ASM_EXTABLE(0b, 0b)
18457+#endif
18458+
18459 /* subtracts 0xffff0001, returns the old value */
18460 " jns 1f\n\t"
18461 " call call_rwsem_wake\n" /* expects old value in %edx */
18462@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18463 {
18464 asm volatile("# beginning __downgrade_write\n\t"
18465 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18466+
18467+#ifdef CONFIG_PAX_REFCOUNT
18468+ "jno 0f\n"
18469+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18470+ "int $4\n0:\n"
18471+ _ASM_EXTABLE(0b, 0b)
18472+#endif
18473+
18474 /*
18475 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18476 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18477@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18478 */
18479 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18480 {
18481- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18482+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18483+
18484+#ifdef CONFIG_PAX_REFCOUNT
18485+ "jno 0f\n"
18486+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18487+ "int $4\n0:\n"
18488+ _ASM_EXTABLE(0b, 0b)
18489+#endif
18490+
18491 : "+m" (sem->count)
18492 : "er" (delta));
18493 }
18494@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18495 */
18496 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18497 {
18498- return delta + xadd(&sem->count, delta);
18499+ return delta + xadd_check_overflow(&sem->count, delta);
18500 }
18501
18502 #endif /* __KERNEL__ */
18503diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18504index 6f1c3a8..7744f19 100644
18505--- a/arch/x86/include/asm/segment.h
18506+++ b/arch/x86/include/asm/segment.h
18507@@ -64,10 +64,15 @@
18508 * 26 - ESPFIX small SS
18509 * 27 - per-cpu [ offset to per-cpu data area ]
18510 * 28 - stack_canary-20 [ for stack protector ]
18511- * 29 - unused
18512- * 30 - unused
18513+ * 29 - PCI BIOS CS
18514+ * 30 - PCI BIOS DS
18515 * 31 - TSS for double fault handler
18516 */
18517+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18518+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18519+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18520+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18521+
18522 #define GDT_ENTRY_TLS_MIN 6
18523 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18524
18525@@ -79,6 +84,8 @@
18526
18527 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18528
18529+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18530+
18531 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18532
18533 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18534@@ -104,6 +111,12 @@
18535 #define __KERNEL_STACK_CANARY 0
18536 #endif
18537
18538+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18539+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18540+
18541+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18542+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18543+
18544 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18545
18546 /*
18547@@ -141,7 +154,7 @@
18548 */
18549
18550 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18551-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18552+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18553
18554
18555 #else
18556@@ -165,6 +178,8 @@
18557 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18558 #define __USER32_DS __USER_DS
18559
18560+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18561+
18562 #define GDT_ENTRY_TSS 8 /* needs two entries */
18563 #define GDT_ENTRY_LDT 10 /* needs two entries */
18564 #define GDT_ENTRY_TLS_MIN 12
18565@@ -173,6 +188,8 @@
18566 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18567 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18568
18569+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18570+
18571 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18572 #define FS_TLS 0
18573 #define GS_TLS 1
18574@@ -180,12 +197,14 @@
18575 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18576 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18577
18578-#define GDT_ENTRIES 16
18579+#define GDT_ENTRIES 17
18580
18581 #endif
18582
18583 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18584+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18585 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18586+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18587 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18588 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18589 #ifndef CONFIG_PARAVIRT
18590@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18591 {
18592 unsigned long __limit;
18593 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18594- return __limit + 1;
18595+ return __limit;
18596 }
18597
18598 #endif /* !__ASSEMBLY__ */
18599diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18600index 8d3120f..352b440 100644
18601--- a/arch/x86/include/asm/smap.h
18602+++ b/arch/x86/include/asm/smap.h
18603@@ -25,11 +25,40 @@
18604
18605 #include <asm/alternative-asm.h>
18606
18607+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18608+#define ASM_PAX_OPEN_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_open_userland; \
18617+ popq %rax; \
18618+ 663:
18619+
18620+#define ASM_PAX_CLOSE_USERLAND \
18621+ 661: jmp 663f; \
18622+ .pushsection .altinstr_replacement, "a" ; \
18623+ 662: pushq %rax; nop; \
18624+ .popsection; \
18625+ .pushsection .altinstructions, "a" ; \
18626+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18627+ .popsection; \
18628+ call __pax_close_userland; \
18629+ popq %rax; \
18630+ 663:
18631+#else
18632+#define ASM_PAX_OPEN_USERLAND
18633+#define ASM_PAX_CLOSE_USERLAND
18634+#endif
18635+
18636 #ifdef CONFIG_X86_SMAP
18637
18638 #define ASM_CLAC \
18639 661: ASM_NOP3 ; \
18640- .pushsection .altinstr_replacement, "ax" ; \
18641+ .pushsection .altinstr_replacement, "a" ; \
18642 662: __ASM_CLAC ; \
18643 .popsection ; \
18644 .pushsection .altinstructions, "a" ; \
18645@@ -38,7 +67,7 @@
18646
18647 #define ASM_STAC \
18648 661: ASM_NOP3 ; \
18649- .pushsection .altinstr_replacement, "ax" ; \
18650+ .pushsection .altinstr_replacement, "a" ; \
18651 662: __ASM_STAC ; \
18652 .popsection ; \
18653 .pushsection .altinstructions, "a" ; \
18654@@ -56,6 +85,37 @@
18655
18656 #include <asm/alternative.h>
18657
18658+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18659+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18660+
18661+extern void __pax_open_userland(void);
18662+static __always_inline unsigned long pax_open_userland(void)
18663+{
18664+
18665+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18666+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18667+ :
18668+ : [open] "i" (__pax_open_userland)
18669+ : "memory", "rax");
18670+#endif
18671+
18672+ return 0;
18673+}
18674+
18675+extern void __pax_close_userland(void);
18676+static __always_inline unsigned long pax_close_userland(void)
18677+{
18678+
18679+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18680+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18681+ :
18682+ : [close] "i" (__pax_close_userland)
18683+ : "memory", "rax");
18684+#endif
18685+
18686+ return 0;
18687+}
18688+
18689 #ifdef CONFIG_X86_SMAP
18690
18691 static __always_inline void clac(void)
18692diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18693index 8cd27e0..7f05ec8 100644
18694--- a/arch/x86/include/asm/smp.h
18695+++ b/arch/x86/include/asm/smp.h
18696@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18697 /* cpus sharing the last level cache: */
18698 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18699 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18700-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18701+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18702
18703 static inline struct cpumask *cpu_sibling_mask(int cpu)
18704 {
18705@@ -78,7 +78,7 @@ struct smp_ops {
18706
18707 void (*send_call_func_ipi)(const struct cpumask *mask);
18708 void (*send_call_func_single_ipi)(int cpu);
18709-};
18710+} __no_const;
18711
18712 /* Globals due to paravirt */
18713 extern void set_cpu_sibling_map(int cpu);
18714@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18715 extern int safe_smp_processor_id(void);
18716
18717 #elif defined(CONFIG_X86_64_SMP)
18718-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18719-
18720-#define stack_smp_processor_id() \
18721-({ \
18722- struct thread_info *ti; \
18723- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18724- ti->cpu; \
18725-})
18726+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18727+#define stack_smp_processor_id() raw_smp_processor_id()
18728 #define safe_smp_processor_id() smp_processor_id()
18729
18730 #endif
18731diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18732index 0f62f54..cb5d0dd 100644
18733--- a/arch/x86/include/asm/spinlock.h
18734+++ b/arch/x86/include/asm/spinlock.h
18735@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18736 static inline void arch_read_lock(arch_rwlock_t *rw)
18737 {
18738 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18739+
18740+#ifdef CONFIG_PAX_REFCOUNT
18741+ "jno 0f\n"
18742+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18743+ "int $4\n0:\n"
18744+ _ASM_EXTABLE(0b, 0b)
18745+#endif
18746+
18747 "jns 1f\n"
18748 "call __read_lock_failed\n\t"
18749 "1:\n"
18750@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18751 static inline void arch_write_lock(arch_rwlock_t *rw)
18752 {
18753 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18754+
18755+#ifdef CONFIG_PAX_REFCOUNT
18756+ "jno 0f\n"
18757+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18758+ "int $4\n0:\n"
18759+ _ASM_EXTABLE(0b, 0b)
18760+#endif
18761+
18762 "jz 1f\n"
18763 "call __write_lock_failed\n\t"
18764 "1:\n"
18765@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18766
18767 static inline void arch_read_unlock(arch_rwlock_t *rw)
18768 {
18769- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18770+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18771+
18772+#ifdef CONFIG_PAX_REFCOUNT
18773+ "jno 0f\n"
18774+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18775+ "int $4\n0:\n"
18776+ _ASM_EXTABLE(0b, 0b)
18777+#endif
18778+
18779 :"+m" (rw->lock) : : "memory");
18780 }
18781
18782 static inline void arch_write_unlock(arch_rwlock_t *rw)
18783 {
18784- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18785+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18786+
18787+#ifdef CONFIG_PAX_REFCOUNT
18788+ "jno 0f\n"
18789+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18790+ "int $4\n0:\n"
18791+ _ASM_EXTABLE(0b, 0b)
18792+#endif
18793+
18794 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18795 }
18796
18797diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18798index 6a99859..03cb807 100644
18799--- a/arch/x86/include/asm/stackprotector.h
18800+++ b/arch/x86/include/asm/stackprotector.h
18801@@ -47,7 +47,7 @@
18802 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18803 */
18804 #define GDT_STACK_CANARY_INIT \
18805- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18806+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18807
18808 /*
18809 * Initialize the stackprotector canary value.
18810@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18811
18812 static inline void load_stack_canary_segment(void)
18813 {
18814-#ifdef CONFIG_X86_32
18815+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18816 asm volatile ("mov %0, %%gs" : : "r" (0));
18817 #endif
18818 }
18819diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18820index 70bbe39..4ae2bd4 100644
18821--- a/arch/x86/include/asm/stacktrace.h
18822+++ b/arch/x86/include/asm/stacktrace.h
18823@@ -11,28 +11,20 @@
18824
18825 extern int kstack_depth_to_print;
18826
18827-struct thread_info;
18828+struct task_struct;
18829 struct stacktrace_ops;
18830
18831-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18832- unsigned long *stack,
18833- unsigned long bp,
18834- const struct stacktrace_ops *ops,
18835- void *data,
18836- unsigned long *end,
18837- int *graph);
18838+typedef unsigned long walk_stack_t(struct task_struct *task,
18839+ void *stack_start,
18840+ unsigned long *stack,
18841+ unsigned long bp,
18842+ const struct stacktrace_ops *ops,
18843+ void *data,
18844+ unsigned long *end,
18845+ int *graph);
18846
18847-extern unsigned long
18848-print_context_stack(struct thread_info *tinfo,
18849- unsigned long *stack, unsigned long bp,
18850- const struct stacktrace_ops *ops, void *data,
18851- unsigned long *end, int *graph);
18852-
18853-extern unsigned long
18854-print_context_stack_bp(struct thread_info *tinfo,
18855- unsigned long *stack, unsigned long bp,
18856- const struct stacktrace_ops *ops, void *data,
18857- unsigned long *end, int *graph);
18858+extern walk_stack_t print_context_stack;
18859+extern walk_stack_t print_context_stack_bp;
18860
18861 /* Generic stack tracer with callbacks */
18862
18863@@ -40,7 +32,7 @@ struct stacktrace_ops {
18864 void (*address)(void *data, unsigned long address, int reliable);
18865 /* On negative return stop dumping */
18866 int (*stack)(void *data, char *name);
18867- walk_stack_t walk_stack;
18868+ walk_stack_t *walk_stack;
18869 };
18870
18871 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18872diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18873index d7f3b3b..3cc39f1 100644
18874--- a/arch/x86/include/asm/switch_to.h
18875+++ b/arch/x86/include/asm/switch_to.h
18876@@ -108,7 +108,7 @@ do { \
18877 "call __switch_to\n\t" \
18878 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18879 __switch_canary \
18880- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18881+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18882 "movq %%rax,%%rdi\n\t" \
18883 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18884 "jnz ret_from_fork\n\t" \
18885@@ -119,7 +119,7 @@ do { \
18886 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18887 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18888 [_tif_fork] "i" (_TIF_FORK), \
18889- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18890+ [thread_info] "m" (current_tinfo), \
18891 [current_task] "m" (current_task) \
18892 __switch_canary_iparam \
18893 : "memory", "cc" __EXTRA_CLOBBER)
18894diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18895index e1940c0..ac50dd8 100644
18896--- a/arch/x86/include/asm/thread_info.h
18897+++ b/arch/x86/include/asm/thread_info.h
18898@@ -10,6 +10,7 @@
18899 #include <linux/compiler.h>
18900 #include <asm/page.h>
18901 #include <asm/types.h>
18902+#include <asm/percpu.h>
18903
18904 /*
18905 * low level task data that entry.S needs immediate access to
18906@@ -23,7 +24,6 @@ struct exec_domain;
18907 #include <linux/atomic.h>
18908
18909 struct thread_info {
18910- struct task_struct *task; /* main task structure */
18911 struct exec_domain *exec_domain; /* execution domain */
18912 __u32 flags; /* low level flags */
18913 __u32 status; /* thread synchronous flags */
18914@@ -32,19 +32,13 @@ struct thread_info {
18915 mm_segment_t addr_limit;
18916 struct restart_block restart_block;
18917 void __user *sysenter_return;
18918-#ifdef CONFIG_X86_32
18919- unsigned long previous_esp; /* ESP of the previous stack in
18920- case of nested (IRQ) stacks
18921- */
18922- __u8 supervisor_stack[0];
18923-#endif
18924+ unsigned long lowest_stack;
18925 unsigned int sig_on_uaccess_error:1;
18926 unsigned int uaccess_err:1; /* uaccess failed */
18927 };
18928
18929-#define INIT_THREAD_INFO(tsk) \
18930+#define INIT_THREAD_INFO \
18931 { \
18932- .task = &tsk, \
18933 .exec_domain = &default_exec_domain, \
18934 .flags = 0, \
18935 .cpu = 0, \
18936@@ -55,7 +49,7 @@ struct thread_info {
18937 }, \
18938 }
18939
18940-#define init_thread_info (init_thread_union.thread_info)
18941+#define init_thread_info (init_thread_union.stack)
18942 #define init_stack (init_thread_union.stack)
18943
18944 #else /* !__ASSEMBLY__ */
18945@@ -95,6 +89,7 @@ struct thread_info {
18946 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18947 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18948 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18949+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18950
18951 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18952 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18953@@ -118,17 +113,18 @@ struct thread_info {
18954 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18955 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18956 #define _TIF_X32 (1 << TIF_X32)
18957+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18958
18959 /* work to do in syscall_trace_enter() */
18960 #define _TIF_WORK_SYSCALL_ENTRY \
18961 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18962 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18963- _TIF_NOHZ)
18964+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18965
18966 /* work to do in syscall_trace_leave() */
18967 #define _TIF_WORK_SYSCALL_EXIT \
18968 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18969- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18970+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18971
18972 /* work to do on interrupt/exception return */
18973 #define _TIF_WORK_MASK \
18974@@ -139,7 +135,7 @@ struct thread_info {
18975 /* work to do on any return to user space */
18976 #define _TIF_ALLWORK_MASK \
18977 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18978- _TIF_NOHZ)
18979+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
18980
18981 /* Only used for 64 bit */
18982 #define _TIF_DO_NOTIFY_MASK \
18983@@ -153,6 +149,23 @@ struct thread_info {
18984 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18985 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18986
18987+#ifdef __ASSEMBLY__
18988+/* how to get the thread information struct from ASM */
18989+#define GET_THREAD_INFO(reg) \
18990+ mov PER_CPU_VAR(current_tinfo), reg
18991+
18992+/* use this one if reg already contains %esp */
18993+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18994+#else
18995+/* how to get the thread information struct from C */
18996+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18997+
18998+static __always_inline struct thread_info *current_thread_info(void)
18999+{
19000+ return this_cpu_read_stable(current_tinfo);
19001+}
19002+#endif
19003+
19004 #ifdef CONFIG_X86_32
19005
19006 #define STACK_WARN (THREAD_SIZE/8)
19007@@ -169,31 +182,10 @@ struct thread_info {
19008 sp; \
19009 })
19010
19011-/* how to get the thread information struct from C */
19012-static inline struct thread_info *current_thread_info(void)
19013-{
19014- return (struct thread_info *)
19015- (current_stack_pointer & ~(THREAD_SIZE - 1));
19016-}
19017-
19018-#else /* !__ASSEMBLY__ */
19019-
19020-/* how to get the thread information struct from ASM */
19021-#define GET_THREAD_INFO(reg) \
19022- movl $-THREAD_SIZE, reg; \
19023- andl %esp, reg
19024-
19025-/* use this one if reg already contains %esp */
19026-#define GET_THREAD_INFO_WITH_ESP(reg) \
19027- andl $-THREAD_SIZE, reg
19028-
19029 #endif
19030
19031 #else /* X86_32 */
19032
19033-#include <asm/percpu.h>
19034-#define KERNEL_STACK_OFFSET (5*8)
19035-
19036 /*
19037 * macros/functions for gaining access to the thread information structure
19038 * preempt_count needs to be 1 initially, until the scheduler is functional.
19039@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19040 #ifndef __ASSEMBLY__
19041 DECLARE_PER_CPU(unsigned long, kernel_stack);
19042
19043-static inline struct thread_info *current_thread_info(void)
19044-{
19045- struct thread_info *ti;
19046- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19047- KERNEL_STACK_OFFSET - THREAD_SIZE);
19048- return ti;
19049-}
19050-
19051-#else /* !__ASSEMBLY__ */
19052-
19053-/* how to get the thread information struct from ASM */
19054-#define GET_THREAD_INFO(reg) \
19055- movq PER_CPU_VAR(kernel_stack),reg ; \
19056- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19057-
19058-/*
19059- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19060- * a certain register (to be used in assembler memory operands).
19061- */
19062-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19063-
19064+/* how to get the current stack pointer from C */
19065+register unsigned long current_stack_pointer asm("rsp") __used;
19066 #endif
19067
19068 #endif /* !X86_32 */
19069@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19070 extern void arch_task_cache_init(void);
19071 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19072 extern void arch_release_task_struct(struct task_struct *tsk);
19073+
19074+#define __HAVE_THREAD_FUNCTIONS
19075+#define task_thread_info(task) (&(task)->tinfo)
19076+#define task_stack_page(task) ((task)->stack)
19077+#define setup_thread_stack(p, org) do {} while (0)
19078+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19079+
19080 #endif
19081 #endif /* _ASM_X86_THREAD_INFO_H */
19082diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19083index 04905bf..49203ca 100644
19084--- a/arch/x86/include/asm/tlbflush.h
19085+++ b/arch/x86/include/asm/tlbflush.h
19086@@ -17,18 +17,44 @@
19087
19088 static inline void __native_flush_tlb(void)
19089 {
19090+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19091+ u64 descriptor[2];
19092+
19093+ descriptor[0] = PCID_KERNEL;
19094+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19095+ return;
19096+ }
19097+
19098+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19099+ if (static_cpu_has(X86_FEATURE_PCID)) {
19100+ unsigned int cpu = raw_get_cpu();
19101+
19102+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19103+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19104+ raw_put_cpu_no_resched();
19105+ return;
19106+ }
19107+#endif
19108+
19109 native_write_cr3(native_read_cr3());
19110 }
19111
19112 static inline void __native_flush_tlb_global_irq_disabled(void)
19113 {
19114- unsigned long cr4;
19115+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19116+ u64 descriptor[2];
19117
19118- cr4 = native_read_cr4();
19119- /* clear PGE */
19120- native_write_cr4(cr4 & ~X86_CR4_PGE);
19121- /* write old PGE again and flush TLBs */
19122- native_write_cr4(cr4);
19123+ descriptor[0] = PCID_KERNEL;
19124+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19125+ } else {
19126+ unsigned long cr4;
19127+
19128+ cr4 = native_read_cr4();
19129+ /* clear PGE */
19130+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19131+ /* write old PGE again and flush TLBs */
19132+ native_write_cr4(cr4);
19133+ }
19134 }
19135
19136 static inline void __native_flush_tlb_global(void)
19137@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19138
19139 static inline void __native_flush_tlb_single(unsigned long addr)
19140 {
19141+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19142+ u64 descriptor[2];
19143+
19144+ descriptor[0] = PCID_KERNEL;
19145+ descriptor[1] = addr;
19146+
19147+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19148+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19149+ if (addr < TASK_SIZE_MAX)
19150+ descriptor[1] += pax_user_shadow_base;
19151+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19152+ }
19153+
19154+ descriptor[0] = PCID_USER;
19155+ descriptor[1] = addr;
19156+#endif
19157+
19158+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19159+ return;
19160+ }
19161+
19162+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19163+ if (static_cpu_has(X86_FEATURE_PCID)) {
19164+ unsigned int cpu = raw_get_cpu();
19165+
19166+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19167+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19168+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19169+ raw_put_cpu_no_resched();
19170+
19171+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19172+ addr += pax_user_shadow_base;
19173+ }
19174+#endif
19175+
19176 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19177 }
19178
19179diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19180index 0d592e0..f58a222 100644
19181--- a/arch/x86/include/asm/uaccess.h
19182+++ b/arch/x86/include/asm/uaccess.h
19183@@ -7,6 +7,7 @@
19184 #include <linux/compiler.h>
19185 #include <linux/thread_info.h>
19186 #include <linux/string.h>
19187+#include <linux/spinlock.h>
19188 #include <asm/asm.h>
19189 #include <asm/page.h>
19190 #include <asm/smap.h>
19191@@ -29,7 +30,12 @@
19192
19193 #define get_ds() (KERNEL_DS)
19194 #define get_fs() (current_thread_info()->addr_limit)
19195+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19196+void __set_fs(mm_segment_t x);
19197+void set_fs(mm_segment_t x);
19198+#else
19199 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19200+#endif
19201
19202 #define segment_eq(a, b) ((a).seg == (b).seg)
19203
19204@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19205 * checks that the pointer is in the user space range - after calling
19206 * this function, memory access functions may still return -EFAULT.
19207 */
19208-#define access_ok(type, addr, size) \
19209- likely(!__range_not_ok(addr, size, user_addr_max()))
19210+extern int _cond_resched(void);
19211+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19212+#define access_ok(type, addr, size) \
19213+({ \
19214+ long __size = size; \
19215+ unsigned long __addr = (unsigned long)addr; \
19216+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19217+ unsigned long __end_ao = __addr + __size - 1; \
19218+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19219+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19220+ while(__addr_ao <= __end_ao) { \
19221+ char __c_ao; \
19222+ __addr_ao += PAGE_SIZE; \
19223+ if (__size > PAGE_SIZE) \
19224+ _cond_resched(); \
19225+ if (__get_user(__c_ao, (char __user *)__addr)) \
19226+ break; \
19227+ if (type != VERIFY_WRITE) { \
19228+ __addr = __addr_ao; \
19229+ continue; \
19230+ } \
19231+ if (__put_user(__c_ao, (char __user *)__addr)) \
19232+ break; \
19233+ __addr = __addr_ao; \
19234+ } \
19235+ } \
19236+ __ret_ao; \
19237+})
19238
19239 /*
19240 * The exception table consists of pairs of addresses relative to the
19241@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19242 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19243 __chk_user_ptr(ptr); \
19244 might_fault(); \
19245+ pax_open_userland(); \
19246 asm volatile("call __get_user_%P3" \
19247 : "=a" (__ret_gu), "=r" (__val_gu) \
19248 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19249 (x) = (__typeof__(*(ptr))) __val_gu; \
19250+ pax_close_userland(); \
19251 __ret_gu; \
19252 })
19253
19254@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19255 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19256 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19257
19258-
19259+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19260+#define __copyuser_seg "gs;"
19261+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19262+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19263+#else
19264+#define __copyuser_seg
19265+#define __COPYUSER_SET_ES
19266+#define __COPYUSER_RESTORE_ES
19267+#endif
19268
19269 #ifdef CONFIG_X86_32
19270 #define __put_user_asm_u64(x, addr, err, errret) \
19271 asm volatile(ASM_STAC "\n" \
19272- "1: movl %%eax,0(%2)\n" \
19273- "2: movl %%edx,4(%2)\n" \
19274+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19275+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19276 "3: " ASM_CLAC "\n" \
19277 ".section .fixup,\"ax\"\n" \
19278 "4: movl %3,%0\n" \
19279@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19280
19281 #define __put_user_asm_ex_u64(x, addr) \
19282 asm volatile(ASM_STAC "\n" \
19283- "1: movl %%eax,0(%1)\n" \
19284- "2: movl %%edx,4(%1)\n" \
19285+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19286+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19287 "3: " ASM_CLAC "\n" \
19288 _ASM_EXTABLE_EX(1b, 2b) \
19289 _ASM_EXTABLE_EX(2b, 3b) \
19290@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19291 __typeof__(*(ptr)) __pu_val; \
19292 __chk_user_ptr(ptr); \
19293 might_fault(); \
19294- __pu_val = x; \
19295+ __pu_val = (x); \
19296+ pax_open_userland(); \
19297 switch (sizeof(*(ptr))) { \
19298 case 1: \
19299 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19300@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19301 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19302 break; \
19303 } \
19304+ pax_close_userland(); \
19305 __ret_pu; \
19306 })
19307
19308@@ -355,8 +399,10 @@ do { \
19309 } while (0)
19310
19311 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19312+do { \
19313+ pax_open_userland(); \
19314 asm volatile(ASM_STAC "\n" \
19315- "1: mov"itype" %2,%"rtype"1\n" \
19316+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19317 "2: " ASM_CLAC "\n" \
19318 ".section .fixup,\"ax\"\n" \
19319 "3: mov %3,%0\n" \
19320@@ -364,8 +410,10 @@ do { \
19321 " jmp 2b\n" \
19322 ".previous\n" \
19323 _ASM_EXTABLE(1b, 3b) \
19324- : "=r" (err), ltype(x) \
19325- : "m" (__m(addr)), "i" (errret), "0" (err))
19326+ : "=r" (err), ltype (x) \
19327+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19328+ pax_close_userland(); \
19329+} while (0)
19330
19331 #define __get_user_size_ex(x, ptr, size) \
19332 do { \
19333@@ -389,7 +437,7 @@ do { \
19334 } while (0)
19335
19336 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19337- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19338+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19339 "2:\n" \
19340 _ASM_EXTABLE_EX(1b, 2b) \
19341 : ltype(x) : "m" (__m(addr)))
19342@@ -406,13 +454,24 @@ do { \
19343 int __gu_err; \
19344 unsigned long __gu_val; \
19345 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19346- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19347+ (x) = (__typeof__(*(ptr)))__gu_val; \
19348 __gu_err; \
19349 })
19350
19351 /* FIXME: this hack is definitely wrong -AK */
19352 struct __large_struct { unsigned long buf[100]; };
19353-#define __m(x) (*(struct __large_struct __user *)(x))
19354+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19355+#define ____m(x) \
19356+({ \
19357+ unsigned long ____x = (unsigned long)(x); \
19358+ if (____x < pax_user_shadow_base) \
19359+ ____x += pax_user_shadow_base; \
19360+ (typeof(x))____x; \
19361+})
19362+#else
19363+#define ____m(x) (x)
19364+#endif
19365+#define __m(x) (*(struct __large_struct __user *)____m(x))
19366
19367 /*
19368 * Tell gcc we read from memory instead of writing: this is because
19369@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19370 * aliasing issues.
19371 */
19372 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19373+do { \
19374+ pax_open_userland(); \
19375 asm volatile(ASM_STAC "\n" \
19376- "1: mov"itype" %"rtype"1,%2\n" \
19377+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19378 "2: " ASM_CLAC "\n" \
19379 ".section .fixup,\"ax\"\n" \
19380 "3: mov %3,%0\n" \
19381@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19382 ".previous\n" \
19383 _ASM_EXTABLE(1b, 3b) \
19384 : "=r"(err) \
19385- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19386+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19387+ pax_close_userland(); \
19388+} while (0)
19389
19390 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19391- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19392+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19393 "2:\n" \
19394 _ASM_EXTABLE_EX(1b, 2b) \
19395 : : ltype(x), "m" (__m(addr)))
19396@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19397 */
19398 #define uaccess_try do { \
19399 current_thread_info()->uaccess_err = 0; \
19400+ pax_open_userland(); \
19401 stac(); \
19402 barrier();
19403
19404 #define uaccess_catch(err) \
19405 clac(); \
19406+ pax_close_userland(); \
19407 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19408 } while (0)
19409
19410@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19411 * On error, the variable @x is set to zero.
19412 */
19413
19414+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19415+#define __get_user(x, ptr) get_user((x), (ptr))
19416+#else
19417 #define __get_user(x, ptr) \
19418 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19419+#endif
19420
19421 /**
19422 * __put_user: - Write a simple value into user space, with less checking.
19423@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19424 * Returns zero on success, or -EFAULT on error.
19425 */
19426
19427+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19428+#define __put_user(x, ptr) put_user((x), (ptr))
19429+#else
19430 #define __put_user(x, ptr) \
19431 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19432+#endif
19433
19434 #define __get_user_unaligned __get_user
19435 #define __put_user_unaligned __put_user
19436@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19437 #define get_user_ex(x, ptr) do { \
19438 unsigned long __gue_val; \
19439 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19440- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19441+ (x) = (__typeof__(*(ptr)))__gue_val; \
19442 } while (0)
19443
19444 #define put_user_try uaccess_try
19445@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19446 __typeof__(ptr) __uval = (uval); \
19447 __typeof__(*(ptr)) __old = (old); \
19448 __typeof__(*(ptr)) __new = (new); \
19449+ pax_open_userland(); \
19450 switch (size) { \
19451 case 1: \
19452 { \
19453 asm volatile("\t" ASM_STAC "\n" \
19454- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19455+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19456 "2:\t" ASM_CLAC "\n" \
19457 "\t.section .fixup, \"ax\"\n" \
19458 "3:\tmov %3, %0\n" \
19459 "\tjmp 2b\n" \
19460 "\t.previous\n" \
19461 _ASM_EXTABLE(1b, 3b) \
19462- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19463+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19464 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19465 : "memory" \
19466 ); \
19467@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19468 case 2: \
19469 { \
19470 asm volatile("\t" ASM_STAC "\n" \
19471- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19472+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19473 "2:\t" ASM_CLAC "\n" \
19474 "\t.section .fixup, \"ax\"\n" \
19475 "3:\tmov %3, %0\n" \
19476 "\tjmp 2b\n" \
19477 "\t.previous\n" \
19478 _ASM_EXTABLE(1b, 3b) \
19479- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19480+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19481 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19482 : "memory" \
19483 ); \
19484@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19485 case 4: \
19486 { \
19487 asm volatile("\t" ASM_STAC "\n" \
19488- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19489+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19490 "2:\t" ASM_CLAC "\n" \
19491 "\t.section .fixup, \"ax\"\n" \
19492 "3:\tmov %3, %0\n" \
19493 "\tjmp 2b\n" \
19494 "\t.previous\n" \
19495 _ASM_EXTABLE(1b, 3b) \
19496- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19497+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19498 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19499 : "memory" \
19500 ); \
19501@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19502 __cmpxchg_wrong_size(); \
19503 \
19504 asm volatile("\t" ASM_STAC "\n" \
19505- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19506+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19507 "2:\t" ASM_CLAC "\n" \
19508 "\t.section .fixup, \"ax\"\n" \
19509 "3:\tmov %3, %0\n" \
19510 "\tjmp 2b\n" \
19511 "\t.previous\n" \
19512 _ASM_EXTABLE(1b, 3b) \
19513- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19514+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19515 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19516 : "memory" \
19517 ); \
19518@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19519 default: \
19520 __cmpxchg_wrong_size(); \
19521 } \
19522+ pax_close_userland(); \
19523 *__uval = __old; \
19524 __ret; \
19525 })
19526@@ -636,17 +711,6 @@ extern struct movsl_mask {
19527
19528 #define ARCH_HAS_NOCACHE_UACCESS 1
19529
19530-#ifdef CONFIG_X86_32
19531-# include <asm/uaccess_32.h>
19532-#else
19533-# include <asm/uaccess_64.h>
19534-#endif
19535-
19536-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19537- unsigned n);
19538-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19539- unsigned n);
19540-
19541 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19542 # define copy_user_diag __compiletime_error
19543 #else
19544@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19545 extern void copy_user_diag("copy_from_user() buffer size is too small")
19546 copy_from_user_overflow(void);
19547 extern void copy_user_diag("copy_to_user() buffer size is too small")
19548-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19549+copy_to_user_overflow(void);
19550
19551 #undef copy_user_diag
19552
19553@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19554
19555 extern void
19556 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19557-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19558+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19559 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19560
19561 #else
19562@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19563
19564 #endif
19565
19566+#ifdef CONFIG_X86_32
19567+# include <asm/uaccess_32.h>
19568+#else
19569+# include <asm/uaccess_64.h>
19570+#endif
19571+
19572 static inline unsigned long __must_check
19573 copy_from_user(void *to, const void __user *from, unsigned long n)
19574 {
19575- int sz = __compiletime_object_size(to);
19576+ size_t sz = __compiletime_object_size(to);
19577
19578 might_fault();
19579
19580@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19581 * case, and do only runtime checking for non-constant sizes.
19582 */
19583
19584- if (likely(sz < 0 || sz >= n))
19585- n = _copy_from_user(to, from, n);
19586- else if(__builtin_constant_p(n))
19587- copy_from_user_overflow();
19588- else
19589- __copy_from_user_overflow(sz, n);
19590+ if (likely(sz != (size_t)-1 && sz < n)) {
19591+ if(__builtin_constant_p(n))
19592+ copy_from_user_overflow();
19593+ else
19594+ __copy_from_user_overflow(sz, n);
19595+ } if (access_ok(VERIFY_READ, from, n))
19596+ n = __copy_from_user(to, from, n);
19597+ else if ((long)n > 0)
19598+ memset(to, 0, n);
19599
19600 return n;
19601 }
19602@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19603 static inline unsigned long __must_check
19604 copy_to_user(void __user *to, const void *from, unsigned long n)
19605 {
19606- int sz = __compiletime_object_size(from);
19607+ size_t sz = __compiletime_object_size(from);
19608
19609 might_fault();
19610
19611 /* See the comment in copy_from_user() above. */
19612- if (likely(sz < 0 || sz >= n))
19613- n = _copy_to_user(to, from, n);
19614- else if(__builtin_constant_p(n))
19615- copy_to_user_overflow();
19616- else
19617- __copy_to_user_overflow(sz, n);
19618+ if (likely(sz != (size_t)-1 && sz < n)) {
19619+ if(__builtin_constant_p(n))
19620+ copy_to_user_overflow();
19621+ else
19622+ __copy_to_user_overflow(sz, n);
19623+ } else if (access_ok(VERIFY_WRITE, to, n))
19624+ n = __copy_to_user(to, from, n);
19625
19626 return n;
19627 }
19628diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19629index 3c03a5d..1071638 100644
19630--- a/arch/x86/include/asm/uaccess_32.h
19631+++ b/arch/x86/include/asm/uaccess_32.h
19632@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19633 static __always_inline unsigned long __must_check
19634 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19635 {
19636+ if ((long)n < 0)
19637+ return n;
19638+
19639+ check_object_size(from, n, true);
19640+
19641 if (__builtin_constant_p(n)) {
19642 unsigned long ret;
19643
19644@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19645 __copy_to_user(void __user *to, const void *from, unsigned long n)
19646 {
19647 might_fault();
19648+
19649 return __copy_to_user_inatomic(to, from, n);
19650 }
19651
19652 static __always_inline unsigned long
19653 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19654 {
19655+ if ((long)n < 0)
19656+ return n;
19657+
19658 /* Avoid zeroing the tail if the copy fails..
19659 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19660 * but as the zeroing behaviour is only significant when n is not
19661@@ -137,6 +146,12 @@ static __always_inline unsigned long
19662 __copy_from_user(void *to, const void __user *from, unsigned long n)
19663 {
19664 might_fault();
19665+
19666+ if ((long)n < 0)
19667+ return n;
19668+
19669+ check_object_size(to, n, false);
19670+
19671 if (__builtin_constant_p(n)) {
19672 unsigned long ret;
19673
19674@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19675 const void __user *from, unsigned long n)
19676 {
19677 might_fault();
19678+
19679+ if ((long)n < 0)
19680+ return n;
19681+
19682 if (__builtin_constant_p(n)) {
19683 unsigned long ret;
19684
19685@@ -181,7 +200,10 @@ static __always_inline unsigned long
19686 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19687 unsigned long n)
19688 {
19689- return __copy_from_user_ll_nocache_nozero(to, from, n);
19690+ if ((long)n < 0)
19691+ return n;
19692+
19693+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19694 }
19695
19696 #endif /* _ASM_X86_UACCESS_32_H */
19697diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19698index 12a26b9..206c200 100644
19699--- a/arch/x86/include/asm/uaccess_64.h
19700+++ b/arch/x86/include/asm/uaccess_64.h
19701@@ -10,6 +10,9 @@
19702 #include <asm/alternative.h>
19703 #include <asm/cpufeature.h>
19704 #include <asm/page.h>
19705+#include <asm/pgtable.h>
19706+
19707+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19708
19709 /*
19710 * Copy To/From Userspace
19711@@ -17,14 +20,14 @@
19712
19713 /* Handles exceptions in both to and from, but doesn't do access_ok */
19714 __must_check unsigned long
19715-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19716+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19717 __must_check unsigned long
19718-copy_user_generic_string(void *to, const void *from, unsigned len);
19719+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19720 __must_check unsigned long
19721-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19722+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19723
19724 static __always_inline __must_check unsigned long
19725-copy_user_generic(void *to, const void *from, unsigned len)
19726+copy_user_generic(void *to, const void *from, unsigned long len)
19727 {
19728 unsigned ret;
19729
19730@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19731 }
19732
19733 __must_check unsigned long
19734-copy_in_user(void __user *to, const void __user *from, unsigned len);
19735+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19736
19737 static __always_inline __must_check
19738-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19739+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19740 {
19741- int ret = 0;
19742+ size_t sz = __compiletime_object_size(dst);
19743+ unsigned ret = 0;
19744+
19745+ if (size > INT_MAX)
19746+ return size;
19747+
19748+ check_object_size(dst, size, false);
19749+
19750+#ifdef CONFIG_PAX_MEMORY_UDEREF
19751+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19752+ return size;
19753+#endif
19754+
19755+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19756+ if(__builtin_constant_p(size))
19757+ copy_from_user_overflow();
19758+ else
19759+ __copy_from_user_overflow(sz, size);
19760+ return size;
19761+ }
19762
19763 if (!__builtin_constant_p(size))
19764- return copy_user_generic(dst, (__force void *)src, size);
19765+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19766 switch (size) {
19767- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19768+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19769 ret, "b", "b", "=q", 1);
19770 return ret;
19771- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19772+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19773 ret, "w", "w", "=r", 2);
19774 return ret;
19775- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19776+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19777 ret, "l", "k", "=r", 4);
19778 return ret;
19779- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19780+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19781 ret, "q", "", "=r", 8);
19782 return ret;
19783 case 10:
19784- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19785+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19786 ret, "q", "", "=r", 10);
19787 if (unlikely(ret))
19788 return ret;
19789 __get_user_asm(*(u16 *)(8 + (char *)dst),
19790- (u16 __user *)(8 + (char __user *)src),
19791+ (const u16 __user *)(8 + (const char __user *)src),
19792 ret, "w", "w", "=r", 2);
19793 return ret;
19794 case 16:
19795- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19796+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19797 ret, "q", "", "=r", 16);
19798 if (unlikely(ret))
19799 return ret;
19800 __get_user_asm(*(u64 *)(8 + (char *)dst),
19801- (u64 __user *)(8 + (char __user *)src),
19802+ (const u64 __user *)(8 + (const char __user *)src),
19803 ret, "q", "", "=r", 8);
19804 return ret;
19805 default:
19806- return copy_user_generic(dst, (__force void *)src, size);
19807+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19808 }
19809 }
19810
19811 static __always_inline __must_check
19812-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19813+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19814 {
19815 might_fault();
19816 return __copy_from_user_nocheck(dst, src, size);
19817 }
19818
19819 static __always_inline __must_check
19820-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19821+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19822 {
19823- int ret = 0;
19824+ size_t sz = __compiletime_object_size(src);
19825+ unsigned ret = 0;
19826+
19827+ if (size > INT_MAX)
19828+ return size;
19829+
19830+ check_object_size(src, size, true);
19831+
19832+#ifdef CONFIG_PAX_MEMORY_UDEREF
19833+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19834+ return size;
19835+#endif
19836+
19837+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19838+ if(__builtin_constant_p(size))
19839+ copy_to_user_overflow();
19840+ else
19841+ __copy_to_user_overflow(sz, size);
19842+ return size;
19843+ }
19844
19845 if (!__builtin_constant_p(size))
19846- return copy_user_generic((__force void *)dst, src, size);
19847+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19848 switch (size) {
19849- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19850+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19851 ret, "b", "b", "iq", 1);
19852 return ret;
19853- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19854+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19855 ret, "w", "w", "ir", 2);
19856 return ret;
19857- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19858+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19859 ret, "l", "k", "ir", 4);
19860 return ret;
19861- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19862+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19863 ret, "q", "", "er", 8);
19864 return ret;
19865 case 10:
19866- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19867+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19868 ret, "q", "", "er", 10);
19869 if (unlikely(ret))
19870 return ret;
19871 asm("":::"memory");
19872- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19873+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19874 ret, "w", "w", "ir", 2);
19875 return ret;
19876 case 16:
19877- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19878+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19879 ret, "q", "", "er", 16);
19880 if (unlikely(ret))
19881 return ret;
19882 asm("":::"memory");
19883- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19884+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19885 ret, "q", "", "er", 8);
19886 return ret;
19887 default:
19888- return copy_user_generic((__force void *)dst, src, size);
19889+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19890 }
19891 }
19892
19893 static __always_inline __must_check
19894-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19895+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19896 {
19897 might_fault();
19898 return __copy_to_user_nocheck(dst, src, size);
19899 }
19900
19901 static __always_inline __must_check
19902-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19903+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19904 {
19905- int ret = 0;
19906+ unsigned ret = 0;
19907
19908 might_fault();
19909+
19910+ if (size > INT_MAX)
19911+ return size;
19912+
19913+#ifdef CONFIG_PAX_MEMORY_UDEREF
19914+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19915+ return size;
19916+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19917+ return size;
19918+#endif
19919+
19920 if (!__builtin_constant_p(size))
19921- return copy_user_generic((__force void *)dst,
19922- (__force void *)src, size);
19923+ return copy_user_generic((__force_kernel void *)____m(dst),
19924+ (__force_kernel const void *)____m(src), size);
19925 switch (size) {
19926 case 1: {
19927 u8 tmp;
19928- __get_user_asm(tmp, (u8 __user *)src,
19929+ __get_user_asm(tmp, (const u8 __user *)src,
19930 ret, "b", "b", "=q", 1);
19931 if (likely(!ret))
19932 __put_user_asm(tmp, (u8 __user *)dst,
19933@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19934 }
19935 case 2: {
19936 u16 tmp;
19937- __get_user_asm(tmp, (u16 __user *)src,
19938+ __get_user_asm(tmp, (const u16 __user *)src,
19939 ret, "w", "w", "=r", 2);
19940 if (likely(!ret))
19941 __put_user_asm(tmp, (u16 __user *)dst,
19942@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19943
19944 case 4: {
19945 u32 tmp;
19946- __get_user_asm(tmp, (u32 __user *)src,
19947+ __get_user_asm(tmp, (const u32 __user *)src,
19948 ret, "l", "k", "=r", 4);
19949 if (likely(!ret))
19950 __put_user_asm(tmp, (u32 __user *)dst,
19951@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19952 }
19953 case 8: {
19954 u64 tmp;
19955- __get_user_asm(tmp, (u64 __user *)src,
19956+ __get_user_asm(tmp, (const u64 __user *)src,
19957 ret, "q", "", "=r", 8);
19958 if (likely(!ret))
19959 __put_user_asm(tmp, (u64 __user *)dst,
19960@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19961 return ret;
19962 }
19963 default:
19964- return copy_user_generic((__force void *)dst,
19965- (__force void *)src, size);
19966+ return copy_user_generic((__force_kernel void *)____m(dst),
19967+ (__force_kernel const void *)____m(src), size);
19968 }
19969 }
19970
19971-static __must_check __always_inline int
19972-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19973+static __must_check __always_inline unsigned long
19974+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19975 {
19976 return __copy_from_user_nocheck(dst, src, size);
19977 }
19978
19979-static __must_check __always_inline int
19980-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19981+static __must_check __always_inline unsigned long
19982+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19983 {
19984 return __copy_to_user_nocheck(dst, src, size);
19985 }
19986
19987-extern long __copy_user_nocache(void *dst, const void __user *src,
19988- unsigned size, int zerorest);
19989+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19990+ unsigned long size, int zerorest);
19991
19992-static inline int
19993-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19994+static inline unsigned long
19995+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19996 {
19997 might_fault();
19998+
19999+ if (size > INT_MAX)
20000+ return size;
20001+
20002+#ifdef CONFIG_PAX_MEMORY_UDEREF
20003+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20004+ return size;
20005+#endif
20006+
20007 return __copy_user_nocache(dst, src, size, 1);
20008 }
20009
20010-static inline int
20011+static inline unsigned long
20012 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20013- unsigned size)
20014+ unsigned long size)
20015 {
20016+ if (size > INT_MAX)
20017+ return size;
20018+
20019+#ifdef CONFIG_PAX_MEMORY_UDEREF
20020+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20021+ return size;
20022+#endif
20023+
20024 return __copy_user_nocache(dst, src, size, 0);
20025 }
20026
20027 unsigned long
20028-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20029+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20030
20031 #endif /* _ASM_X86_UACCESS_64_H */
20032diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20033index 5b238981..77fdd78 100644
20034--- a/arch/x86/include/asm/word-at-a-time.h
20035+++ b/arch/x86/include/asm/word-at-a-time.h
20036@@ -11,7 +11,7 @@
20037 * and shift, for example.
20038 */
20039 struct word_at_a_time {
20040- const unsigned long one_bits, high_bits;
20041+ unsigned long one_bits, high_bits;
20042 };
20043
20044 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20045diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20046index e45e4da..44e8572 100644
20047--- a/arch/x86/include/asm/x86_init.h
20048+++ b/arch/x86/include/asm/x86_init.h
20049@@ -129,7 +129,7 @@ struct x86_init_ops {
20050 struct x86_init_timers timers;
20051 struct x86_init_iommu iommu;
20052 struct x86_init_pci pci;
20053-};
20054+} __no_const;
20055
20056 /**
20057 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20058@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20059 void (*setup_percpu_clockev)(void);
20060 void (*early_percpu_clock_init)(void);
20061 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20062-};
20063+} __no_const;
20064
20065 struct timespec;
20066
20067@@ -168,7 +168,7 @@ struct x86_platform_ops {
20068 void (*save_sched_clock_state)(void);
20069 void (*restore_sched_clock_state)(void);
20070 void (*apic_post_init)(void);
20071-};
20072+} __no_const;
20073
20074 struct pci_dev;
20075 struct msi_msg;
20076@@ -185,7 +185,7 @@ struct x86_msi_ops {
20077 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20078 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20079 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20080-};
20081+} __no_const;
20082
20083 struct IO_APIC_route_entry;
20084 struct io_apic_irq_attr;
20085@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20086 unsigned int destination, int vector,
20087 struct io_apic_irq_attr *attr);
20088 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20089-};
20090+} __no_const;
20091
20092 extern struct x86_init_ops x86_init;
20093 extern struct x86_cpuinit_ops x86_cpuinit;
20094diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20095index 3e276eb..2eb3c30 100644
20096--- a/arch/x86/include/asm/xen/page.h
20097+++ b/arch/x86/include/asm/xen/page.h
20098@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20099 extern struct page *m2p_find_override(unsigned long mfn);
20100 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20101
20102-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20103+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20104 {
20105 unsigned long mfn;
20106
20107diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20108index 6c1d741..39e6ecf 100644
20109--- a/arch/x86/include/asm/xsave.h
20110+++ b/arch/x86/include/asm/xsave.h
20111@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20112 if (unlikely(err))
20113 return -EFAULT;
20114
20115+ pax_open_userland();
20116 __asm__ __volatile__(ASM_STAC "\n"
20117- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20118+ "1:"
20119+ __copyuser_seg
20120+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20121 "2: " ASM_CLAC "\n"
20122 ".section .fixup,\"ax\"\n"
20123 "3: movl $-1,%[err]\n"
20124@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20125 : [err] "=r" (err)
20126 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20127 : "memory");
20128+ pax_close_userland();
20129 return err;
20130 }
20131
20132 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20133 {
20134 int err;
20135- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20136+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20137 u32 lmask = mask;
20138 u32 hmask = mask >> 32;
20139
20140+ pax_open_userland();
20141 __asm__ __volatile__(ASM_STAC "\n"
20142- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20143+ "1:"
20144+ __copyuser_seg
20145+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20146 "2: " ASM_CLAC "\n"
20147 ".section .fixup,\"ax\"\n"
20148 "3: movl $-1,%[err]\n"
20149@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20150 : [err] "=r" (err)
20151 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20152 : "memory"); /* memory required? */
20153+ pax_close_userland();
20154 return err;
20155 }
20156
20157diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20158index bbae024..e1528f9 100644
20159--- a/arch/x86/include/uapi/asm/e820.h
20160+++ b/arch/x86/include/uapi/asm/e820.h
20161@@ -63,7 +63,7 @@ struct e820map {
20162 #define ISA_START_ADDRESS 0xa0000
20163 #define ISA_END_ADDRESS 0x100000
20164
20165-#define BIOS_BEGIN 0x000a0000
20166+#define BIOS_BEGIN 0x000c0000
20167 #define BIOS_END 0x00100000
20168
20169 #define BIOS_ROM_BASE 0xffe00000
20170diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20171index 7b0a55a..ad115bf 100644
20172--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20173+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20174@@ -49,7 +49,6 @@
20175 #define EFLAGS 144
20176 #define RSP 152
20177 #define SS 160
20178-#define ARGOFFSET R11
20179 #endif /* __ASSEMBLY__ */
20180
20181 /* top of stack page */
20182diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20183index cb648c8..91cb07e 100644
20184--- a/arch/x86/kernel/Makefile
20185+++ b/arch/x86/kernel/Makefile
20186@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20187 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20188 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20189 obj-y += probe_roms.o
20190-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20191+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20192 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20193 obj-y += syscall_$(BITS).o
20194 obj-$(CONFIG_X86_64) += vsyscall_64.o
20195diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20196index 1dac942..19c8b0c 100644
20197--- a/arch/x86/kernel/acpi/boot.c
20198+++ b/arch/x86/kernel/acpi/boot.c
20199@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20200 * If your system is blacklisted here, but you find that acpi=force
20201 * works for you, please contact linux-acpi@vger.kernel.org
20202 */
20203-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20204+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20205 /*
20206 * Boxes that need ACPI disabled
20207 */
20208@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20209 };
20210
20211 /* second table for DMI checks that should run after early-quirks */
20212-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20213+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20214 /*
20215 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20216 * which includes some code which overrides all temperature
20217diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20218index 3a2ae4c..9db31d6 100644
20219--- a/arch/x86/kernel/acpi/sleep.c
20220+++ b/arch/x86/kernel/acpi/sleep.c
20221@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20222 #else /* CONFIG_64BIT */
20223 #ifdef CONFIG_SMP
20224 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20225+
20226+ pax_open_kernel();
20227 early_gdt_descr.address =
20228 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20229+ pax_close_kernel();
20230+
20231 initial_gs = per_cpu_offset(smp_processor_id());
20232 #endif
20233 initial_code = (unsigned long)wakeup_long64;
20234diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20235index 665c6b7..eae4d56 100644
20236--- a/arch/x86/kernel/acpi/wakeup_32.S
20237+++ b/arch/x86/kernel/acpi/wakeup_32.S
20238@@ -29,13 +29,11 @@ wakeup_pmode_return:
20239 # and restore the stack ... but you need gdt for this to work
20240 movl saved_context_esp, %esp
20241
20242- movl %cs:saved_magic, %eax
20243- cmpl $0x12345678, %eax
20244+ cmpl $0x12345678, saved_magic
20245 jne bogus_magic
20246
20247 # jump to place where we left off
20248- movl saved_eip, %eax
20249- jmp *%eax
20250+ jmp *(saved_eip)
20251
20252 bogus_magic:
20253 jmp bogus_magic
20254diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20255index df94598..f3b29bf 100644
20256--- a/arch/x86/kernel/alternative.c
20257+++ b/arch/x86/kernel/alternative.c
20258@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20259 */
20260 for (a = start; a < end; a++) {
20261 instr = (u8 *)&a->instr_offset + a->instr_offset;
20262+
20263+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20264+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20265+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20266+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20267+#endif
20268+
20269 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20270 BUG_ON(a->replacementlen > a->instrlen);
20271 BUG_ON(a->instrlen > sizeof(insnbuf));
20272@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20273 for (poff = start; poff < end; poff++) {
20274 u8 *ptr = (u8 *)poff + *poff;
20275
20276+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20277+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20278+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20279+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20280+#endif
20281+
20282 if (!*poff || ptr < text || ptr >= text_end)
20283 continue;
20284 /* turn DS segment override prefix into lock prefix */
20285- if (*ptr == 0x3e)
20286+ if (*ktla_ktva(ptr) == 0x3e)
20287 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20288 }
20289 mutex_unlock(&text_mutex);
20290@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20291 for (poff = start; poff < end; poff++) {
20292 u8 *ptr = (u8 *)poff + *poff;
20293
20294+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20295+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20296+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20297+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20298+#endif
20299+
20300 if (!*poff || ptr < text || ptr >= text_end)
20301 continue;
20302 /* turn lock prefix into DS segment override prefix */
20303- if (*ptr == 0xf0)
20304+ if (*ktla_ktva(ptr) == 0xf0)
20305 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20306 }
20307 mutex_unlock(&text_mutex);
20308@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20309
20310 BUG_ON(p->len > MAX_PATCH_LEN);
20311 /* prep the buffer with the original instructions */
20312- memcpy(insnbuf, p->instr, p->len);
20313+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20314 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20315 (unsigned long)p->instr, p->len);
20316
20317@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20318 if (!uniproc_patched || num_possible_cpus() == 1)
20319 free_init_pages("SMP alternatives",
20320 (unsigned long)__smp_locks,
20321- (unsigned long)__smp_locks_end);
20322+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20323 #endif
20324
20325 apply_paravirt(__parainstructions, __parainstructions_end);
20326@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20327 * instructions. And on the local CPU you need to be protected again NMI or MCE
20328 * handlers seeing an inconsistent instruction while you patch.
20329 */
20330-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20331+void *__kprobes text_poke_early(void *addr, const void *opcode,
20332 size_t len)
20333 {
20334 unsigned long flags;
20335 local_irq_save(flags);
20336- memcpy(addr, opcode, len);
20337+
20338+ pax_open_kernel();
20339+ memcpy(ktla_ktva(addr), opcode, len);
20340 sync_core();
20341+ pax_close_kernel();
20342+
20343 local_irq_restore(flags);
20344 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20345 that causes hangs on some VIA CPUs. */
20346@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20347 */
20348 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20349 {
20350- unsigned long flags;
20351- char *vaddr;
20352+ unsigned char *vaddr = ktla_ktva(addr);
20353 struct page *pages[2];
20354- int i;
20355+ size_t i;
20356
20357 if (!core_kernel_text((unsigned long)addr)) {
20358- pages[0] = vmalloc_to_page(addr);
20359- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20360+ pages[0] = vmalloc_to_page(vaddr);
20361+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20362 } else {
20363- pages[0] = virt_to_page(addr);
20364+ pages[0] = virt_to_page(vaddr);
20365 WARN_ON(!PageReserved(pages[0]));
20366- pages[1] = virt_to_page(addr + PAGE_SIZE);
20367+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20368 }
20369 BUG_ON(!pages[0]);
20370- local_irq_save(flags);
20371- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20372- if (pages[1])
20373- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20374- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20375- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20376- clear_fixmap(FIX_TEXT_POKE0);
20377- if (pages[1])
20378- clear_fixmap(FIX_TEXT_POKE1);
20379- local_flush_tlb();
20380- sync_core();
20381- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20382- that causes hangs on some VIA CPUs. */
20383+ text_poke_early(addr, opcode, len);
20384 for (i = 0; i < len; i++)
20385- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20386- local_irq_restore(flags);
20387+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20388 return addr;
20389 }
20390
20391@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20392 if (likely(!bp_patching_in_progress))
20393 return 0;
20394
20395- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20396+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20397 return 0;
20398
20399 /* set up the specified breakpoint handler */
20400@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20401 */
20402 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20403 {
20404- unsigned char int3 = 0xcc;
20405+ const unsigned char int3 = 0xcc;
20406
20407 bp_int3_handler = handler;
20408 bp_int3_addr = (u8 *)addr + sizeof(int3);
20409diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20410index 7f26c9a..694544e 100644
20411--- a/arch/x86/kernel/apic/apic.c
20412+++ b/arch/x86/kernel/apic/apic.c
20413@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20414 /*
20415 * Debug level, exported for io_apic.c
20416 */
20417-unsigned int apic_verbosity;
20418+int apic_verbosity;
20419
20420 int pic_mode;
20421
20422@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20423 apic_write(APIC_ESR, 0);
20424 v = apic_read(APIC_ESR);
20425 ack_APIC_irq();
20426- atomic_inc(&irq_err_count);
20427+ atomic_inc_unchecked(&irq_err_count);
20428
20429 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20430 smp_processor_id(), v);
20431diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20432index 2c621a6..fa2b1ae 100644
20433--- a/arch/x86/kernel/apic/apic_flat_64.c
20434+++ b/arch/x86/kernel/apic/apic_flat_64.c
20435@@ -154,7 +154,7 @@ static int flat_probe(void)
20436 return 1;
20437 }
20438
20439-static struct apic apic_flat = {
20440+static struct apic apic_flat __read_only = {
20441 .name = "flat",
20442 .probe = flat_probe,
20443 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20444@@ -268,7 +268,7 @@ static int physflat_probe(void)
20445 return 0;
20446 }
20447
20448-static struct apic apic_physflat = {
20449+static struct apic apic_physflat __read_only = {
20450
20451 .name = "physical flat",
20452 .probe = physflat_probe,
20453diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20454index 191ce75..2db6d63 100644
20455--- a/arch/x86/kernel/apic/apic_noop.c
20456+++ b/arch/x86/kernel/apic/apic_noop.c
20457@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20458 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20459 }
20460
20461-struct apic apic_noop = {
20462+struct apic apic_noop __read_only = {
20463 .name = "noop",
20464 .probe = noop_probe,
20465 .acpi_madt_oem_check = NULL,
20466diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20467index d50e364..543bee3 100644
20468--- a/arch/x86/kernel/apic/bigsmp_32.c
20469+++ b/arch/x86/kernel/apic/bigsmp_32.c
20470@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20471 return dmi_bigsmp;
20472 }
20473
20474-static struct apic apic_bigsmp = {
20475+static struct apic apic_bigsmp __read_only = {
20476
20477 .name = "bigsmp",
20478 .probe = probe_bigsmp,
20479diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20480index c552247..587a316 100644
20481--- a/arch/x86/kernel/apic/es7000_32.c
20482+++ b/arch/x86/kernel/apic/es7000_32.c
20483@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20484 return ret && es7000_apic_is_cluster();
20485 }
20486
20487-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20488-static struct apic __refdata apic_es7000_cluster = {
20489+static struct apic apic_es7000_cluster __read_only = {
20490
20491 .name = "es7000",
20492 .probe = probe_es7000,
20493@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20494 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20495 };
20496
20497-static struct apic __refdata apic_es7000 = {
20498+static struct apic apic_es7000 __read_only = {
20499
20500 .name = "es7000",
20501 .probe = probe_es7000,
20502diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20503index 6ad4658..38a7b5c 100644
20504--- a/arch/x86/kernel/apic/io_apic.c
20505+++ b/arch/x86/kernel/apic/io_apic.c
20506@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20507 }
20508 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20509
20510-void lock_vector_lock(void)
20511+void lock_vector_lock(void) __acquires(vector_lock)
20512 {
20513 /* Used to the online set of cpus does not change
20514 * during assign_irq_vector.
20515@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20516 raw_spin_lock(&vector_lock);
20517 }
20518
20519-void unlock_vector_lock(void)
20520+void unlock_vector_lock(void) __releases(vector_lock)
20521 {
20522 raw_spin_unlock(&vector_lock);
20523 }
20524@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20525 ack_APIC_irq();
20526 }
20527
20528-atomic_t irq_mis_count;
20529+atomic_unchecked_t irq_mis_count;
20530
20531 #ifdef CONFIG_GENERIC_PENDING_IRQ
20532 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20533@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20534 * at the cpu.
20535 */
20536 if (!(v & (1 << (i & 0x1f)))) {
20537- atomic_inc(&irq_mis_count);
20538+ atomic_inc_unchecked(&irq_mis_count);
20539
20540 eoi_ioapic_irq(irq, cfg);
20541 }
20542diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20543index 1e42e8f..daacf44 100644
20544--- a/arch/x86/kernel/apic/numaq_32.c
20545+++ b/arch/x86/kernel/apic/numaq_32.c
20546@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20547 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20548 }
20549
20550-/* Use __refdata to keep false positive warning calm. */
20551-static struct apic __refdata apic_numaq = {
20552+static struct apic apic_numaq __read_only = {
20553
20554 .name = "NUMAQ",
20555 .probe = probe_numaq,
20556diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20557index eb35ef9..f184a21 100644
20558--- a/arch/x86/kernel/apic/probe_32.c
20559+++ b/arch/x86/kernel/apic/probe_32.c
20560@@ -72,7 +72,7 @@ static int probe_default(void)
20561 return 1;
20562 }
20563
20564-static struct apic apic_default = {
20565+static struct apic apic_default __read_only = {
20566
20567 .name = "default",
20568 .probe = probe_default,
20569diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20570index 00146f9..5e299b8 100644
20571--- a/arch/x86/kernel/apic/summit_32.c
20572+++ b/arch/x86/kernel/apic/summit_32.c
20573@@ -485,7 +485,7 @@ void setup_summit(void)
20574 }
20575 #endif
20576
20577-static struct apic apic_summit = {
20578+static struct apic apic_summit __read_only = {
20579
20580 .name = "summit",
20581 .probe = probe_summit,
20582diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20583index cac85ee..01fa741 100644
20584--- a/arch/x86/kernel/apic/x2apic_cluster.c
20585+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20586@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20587 return notifier_from_errno(err);
20588 }
20589
20590-static struct notifier_block __refdata x2apic_cpu_notifier = {
20591+static struct notifier_block x2apic_cpu_notifier = {
20592 .notifier_call = update_clusterinfo,
20593 };
20594
20595@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20596 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20597 }
20598
20599-static struct apic apic_x2apic_cluster = {
20600+static struct apic apic_x2apic_cluster __read_only = {
20601
20602 .name = "cluster x2apic",
20603 .probe = x2apic_cluster_probe,
20604diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20605index de231e3..1d1b2ee 100644
20606--- a/arch/x86/kernel/apic/x2apic_phys.c
20607+++ b/arch/x86/kernel/apic/x2apic_phys.c
20608@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20609 return apic == &apic_x2apic_phys;
20610 }
20611
20612-static struct apic apic_x2apic_phys = {
20613+static struct apic apic_x2apic_phys __read_only = {
20614
20615 .name = "physical x2apic",
20616 .probe = x2apic_phys_probe,
20617diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20618index d263b13..963258b 100644
20619--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20620+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20621@@ -350,7 +350,7 @@ static int uv_probe(void)
20622 return apic == &apic_x2apic_uv_x;
20623 }
20624
20625-static struct apic __refdata apic_x2apic_uv_x = {
20626+static struct apic apic_x2apic_uv_x __read_only = {
20627
20628 .name = "UV large system",
20629 .probe = uv_probe,
20630diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20631index 3ab0343..814c4787 100644
20632--- a/arch/x86/kernel/apm_32.c
20633+++ b/arch/x86/kernel/apm_32.c
20634@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20635 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20636 * even though they are called in protected mode.
20637 */
20638-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20639+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20640 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20641
20642 static const char driver_version[] = "1.16ac"; /* no spaces */
20643@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20644 BUG_ON(cpu != 0);
20645 gdt = get_cpu_gdt_table(cpu);
20646 save_desc_40 = gdt[0x40 / 8];
20647+
20648+ pax_open_kernel();
20649 gdt[0x40 / 8] = bad_bios_desc;
20650+ pax_close_kernel();
20651
20652 apm_irq_save(flags);
20653 APM_DO_SAVE_SEGS;
20654@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20655 &call->esi);
20656 APM_DO_RESTORE_SEGS;
20657 apm_irq_restore(flags);
20658+
20659+ pax_open_kernel();
20660 gdt[0x40 / 8] = save_desc_40;
20661+ pax_close_kernel();
20662+
20663 put_cpu();
20664
20665 return call->eax & 0xff;
20666@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20667 BUG_ON(cpu != 0);
20668 gdt = get_cpu_gdt_table(cpu);
20669 save_desc_40 = gdt[0x40 / 8];
20670+
20671+ pax_open_kernel();
20672 gdt[0x40 / 8] = bad_bios_desc;
20673+ pax_close_kernel();
20674
20675 apm_irq_save(flags);
20676 APM_DO_SAVE_SEGS;
20677@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20678 &call->eax);
20679 APM_DO_RESTORE_SEGS;
20680 apm_irq_restore(flags);
20681+
20682+ pax_open_kernel();
20683 gdt[0x40 / 8] = save_desc_40;
20684+ pax_close_kernel();
20685+
20686 put_cpu();
20687 return error;
20688 }
20689@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20690 * code to that CPU.
20691 */
20692 gdt = get_cpu_gdt_table(0);
20693+
20694+ pax_open_kernel();
20695 set_desc_base(&gdt[APM_CS >> 3],
20696 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20697 set_desc_base(&gdt[APM_CS_16 >> 3],
20698 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20699 set_desc_base(&gdt[APM_DS >> 3],
20700 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20701+ pax_close_kernel();
20702
20703 proc_create("apm", 0, NULL, &apm_file_ops);
20704
20705diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20706index 9f6b934..cf5ffb3 100644
20707--- a/arch/x86/kernel/asm-offsets.c
20708+++ b/arch/x86/kernel/asm-offsets.c
20709@@ -32,6 +32,8 @@ void common(void) {
20710 OFFSET(TI_flags, thread_info, flags);
20711 OFFSET(TI_status, thread_info, status);
20712 OFFSET(TI_addr_limit, thread_info, addr_limit);
20713+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20714+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20715
20716 BLANK();
20717 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20718@@ -52,8 +54,26 @@ void common(void) {
20719 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20720 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20721 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20722+
20723+#ifdef CONFIG_PAX_KERNEXEC
20724+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20725 #endif
20726
20727+#ifdef CONFIG_PAX_MEMORY_UDEREF
20728+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20729+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20730+#ifdef CONFIG_X86_64
20731+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20732+#endif
20733+#endif
20734+
20735+#endif
20736+
20737+ BLANK();
20738+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20739+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20740+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20741+
20742 #ifdef CONFIG_XEN
20743 BLANK();
20744 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20745diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20746index e7c798b..2b2019b 100644
20747--- a/arch/x86/kernel/asm-offsets_64.c
20748+++ b/arch/x86/kernel/asm-offsets_64.c
20749@@ -77,6 +77,7 @@ int main(void)
20750 BLANK();
20751 #undef ENTRY
20752
20753+ DEFINE(TSS_size, sizeof(struct tss_struct));
20754 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20755 BLANK();
20756
20757diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20758index 7fd54f0..0691410 100644
20759--- a/arch/x86/kernel/cpu/Makefile
20760+++ b/arch/x86/kernel/cpu/Makefile
20761@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20762 CFLAGS_REMOVE_perf_event.o = -pg
20763 endif
20764
20765-# Make sure load_percpu_segment has no stackprotector
20766-nostackp := $(call cc-option, -fno-stack-protector)
20767-CFLAGS_common.o := $(nostackp)
20768-
20769 obj-y := intel_cacheinfo.o scattered.o topology.o
20770 obj-y += proc.o capflags.o powerflags.o common.o
20771 obj-y += rdrand.o
20772diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20773index c67ffa6..f41fbbf 100644
20774--- a/arch/x86/kernel/cpu/amd.c
20775+++ b/arch/x86/kernel/cpu/amd.c
20776@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20777 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20778 {
20779 /* AMD errata T13 (order #21922) */
20780- if ((c->x86 == 6)) {
20781+ if (c->x86 == 6) {
20782 /* Duron Rev A0 */
20783 if (c->x86_model == 3 && c->x86_mask == 0)
20784 size = 64;
20785diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20786index 8e28bf2..bf5c0d2 100644
20787--- a/arch/x86/kernel/cpu/common.c
20788+++ b/arch/x86/kernel/cpu/common.c
20789@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20790
20791 static const struct cpu_dev *this_cpu = &default_cpu;
20792
20793-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20794-#ifdef CONFIG_X86_64
20795- /*
20796- * We need valid kernel segments for data and code in long mode too
20797- * IRET will check the segment types kkeil 2000/10/28
20798- * Also sysret mandates a special GDT layout
20799- *
20800- * TLS descriptors are currently at a different place compared to i386.
20801- * Hopefully nobody expects them at a fixed place (Wine?)
20802- */
20803- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20804- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20805- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20806- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20807- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20808- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20809-#else
20810- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20811- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20812- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20813- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20814- /*
20815- * Segments used for calling PnP BIOS have byte granularity.
20816- * They code segments and data segments have fixed 64k limits,
20817- * the transfer segment sizes are set at run time.
20818- */
20819- /* 32-bit code */
20820- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20821- /* 16-bit code */
20822- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20823- /* 16-bit data */
20824- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20825- /* 16-bit data */
20826- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20827- /* 16-bit data */
20828- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20829- /*
20830- * The APM segments have byte granularity and their bases
20831- * are set at run time. All have 64k limits.
20832- */
20833- /* 32-bit code */
20834- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20835- /* 16-bit code */
20836- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20837- /* data */
20838- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20839-
20840- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20841- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20842- GDT_STACK_CANARY_INIT
20843-#endif
20844-} };
20845-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20846-
20847 static int __init x86_xsave_setup(char *s)
20848 {
20849 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20850@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20851 }
20852 }
20853
20854+#ifdef CONFIG_X86_64
20855+static __init int setup_disable_pcid(char *arg)
20856+{
20857+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20858+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20859+
20860+#ifdef CONFIG_PAX_MEMORY_UDEREF
20861+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20862+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20863+#endif
20864+
20865+ return 1;
20866+}
20867+__setup("nopcid", setup_disable_pcid);
20868+
20869+static void setup_pcid(struct cpuinfo_x86 *c)
20870+{
20871+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20872+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20873+
20874+#ifdef CONFIG_PAX_MEMORY_UDEREF
20875+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20876+ pax_open_kernel();
20877+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20878+ pax_close_kernel();
20879+ printk("PAX: slow and weak UDEREF enabled\n");
20880+ } else
20881+ printk("PAX: UDEREF disabled\n");
20882+#endif
20883+
20884+ return;
20885+ }
20886+
20887+ printk("PAX: PCID detected\n");
20888+ set_in_cr4(X86_CR4_PCIDE);
20889+
20890+#ifdef CONFIG_PAX_MEMORY_UDEREF
20891+ pax_open_kernel();
20892+ clone_pgd_mask = ~(pgdval_t)0UL;
20893+ pax_close_kernel();
20894+ if (pax_user_shadow_base)
20895+ printk("PAX: weak UDEREF enabled\n");
20896+ else {
20897+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20898+ printk("PAX: strong UDEREF enabled\n");
20899+ }
20900+#endif
20901+
20902+ if (cpu_has(c, X86_FEATURE_INVPCID))
20903+ printk("PAX: INVPCID detected\n");
20904+}
20905+#endif
20906+
20907 /*
20908 * Some CPU features depend on higher CPUID levels, which may not always
20909 * be available due to CPUID level capping or broken virtualization
20910@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20911 {
20912 struct desc_ptr gdt_descr;
20913
20914- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20915+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20916 gdt_descr.size = GDT_SIZE - 1;
20917 load_gdt(&gdt_descr);
20918 /* Reload the per-cpu base */
20919@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20920 setup_smep(c);
20921 setup_smap(c);
20922
20923+#ifdef CONFIG_X86_64
20924+ setup_pcid(c);
20925+#endif
20926+
20927 /*
20928 * The vendor-specific functions might have changed features.
20929 * Now we do "generic changes."
20930@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20931 /* Filter out anything that depends on CPUID levels we don't have */
20932 filter_cpuid_features(c, true);
20933
20934+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20935+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20936+#endif
20937+
20938 /* If the model name is still unset, do table lookup. */
20939 if (!c->x86_model_id[0]) {
20940 const char *p;
20941@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20942 }
20943 __setup("clearcpuid=", setup_disablecpuid);
20944
20945+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20946+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20947+
20948 #ifdef CONFIG_X86_64
20949-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20950-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20951- (unsigned long) debug_idt_table };
20952+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20953+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20954
20955 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20956 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20957@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20958 EXPORT_PER_CPU_SYMBOL(current_task);
20959
20960 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20961- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20962+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20963 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20964
20965 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20966@@ -1245,7 +1254,7 @@ void cpu_init(void)
20967 load_ucode_ap();
20968
20969 cpu = stack_smp_processor_id();
20970- t = &per_cpu(init_tss, cpu);
20971+ t = init_tss + cpu;
20972 oist = &per_cpu(orig_ist, cpu);
20973
20974 #ifdef CONFIG_NUMA
20975@@ -1280,7 +1289,6 @@ void cpu_init(void)
20976 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20977 barrier();
20978
20979- x86_configure_nx();
20980 enable_x2apic();
20981
20982 /*
20983@@ -1332,7 +1340,7 @@ void cpu_init(void)
20984 {
20985 int cpu = smp_processor_id();
20986 struct task_struct *curr = current;
20987- struct tss_struct *t = &per_cpu(init_tss, cpu);
20988+ struct tss_struct *t = init_tss + cpu;
20989 struct thread_struct *thread = &curr->thread;
20990
20991 show_ucode_info_early();
20992diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20993index 0641113..06f5ba4 100644
20994--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20995+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20996@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20997 };
20998
20999 #ifdef CONFIG_AMD_NB
21000+static struct attribute *default_attrs_amd_nb[] = {
21001+ &type.attr,
21002+ &level.attr,
21003+ &coherency_line_size.attr,
21004+ &physical_line_partition.attr,
21005+ &ways_of_associativity.attr,
21006+ &number_of_sets.attr,
21007+ &size.attr,
21008+ &shared_cpu_map.attr,
21009+ &shared_cpu_list.attr,
21010+ NULL,
21011+ NULL,
21012+ NULL,
21013+ NULL
21014+};
21015+
21016 static struct attribute **amd_l3_attrs(void)
21017 {
21018 static struct attribute **attrs;
21019@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21020
21021 n = ARRAY_SIZE(default_attrs);
21022
21023- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21024- n += 2;
21025-
21026- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21027- n += 1;
21028-
21029- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21030- if (attrs == NULL)
21031- return attrs = default_attrs;
21032-
21033- for (n = 0; default_attrs[n]; n++)
21034- attrs[n] = default_attrs[n];
21035+ attrs = default_attrs_amd_nb;
21036
21037 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21038 attrs[n++] = &cache_disable_0.attr;
21039@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21040 .default_attrs = default_attrs,
21041 };
21042
21043+#ifdef CONFIG_AMD_NB
21044+static struct kobj_type ktype_cache_amd_nb = {
21045+ .sysfs_ops = &sysfs_ops,
21046+ .default_attrs = default_attrs_amd_nb,
21047+};
21048+#endif
21049+
21050 static struct kobj_type ktype_percpu_entry = {
21051 .sysfs_ops = &sysfs_ops,
21052 };
21053@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21054 return retval;
21055 }
21056
21057+#ifdef CONFIG_AMD_NB
21058+ amd_l3_attrs();
21059+#endif
21060+
21061 for (i = 0; i < num_cache_leaves; i++) {
21062+ struct kobj_type *ktype;
21063+
21064 this_object = INDEX_KOBJECT_PTR(cpu, i);
21065 this_object->cpu = cpu;
21066 this_object->index = i;
21067
21068 this_leaf = CPUID4_INFO_IDX(cpu, i);
21069
21070- ktype_cache.default_attrs = default_attrs;
21071+ ktype = &ktype_cache;
21072 #ifdef CONFIG_AMD_NB
21073 if (this_leaf->base.nb)
21074- ktype_cache.default_attrs = amd_l3_attrs();
21075+ ktype = &ktype_cache_amd_nb;
21076 #endif
21077 retval = kobject_init_and_add(&(this_object->kobj),
21078- &ktype_cache,
21079+ ktype,
21080 per_cpu(ici_cache_kobject, cpu),
21081 "index%1lu", i);
21082 if (unlikely(retval)) {
21083diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21084index 4d5419b..95f11bb 100644
21085--- a/arch/x86/kernel/cpu/mcheck/mce.c
21086+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21087@@ -45,6 +45,7 @@
21088 #include <asm/processor.h>
21089 #include <asm/mce.h>
21090 #include <asm/msr.h>
21091+#include <asm/local.h>
21092
21093 #include "mce-internal.h"
21094
21095@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21096 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21097 m->cs, m->ip);
21098
21099- if (m->cs == __KERNEL_CS)
21100+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21101 print_symbol("{%s}", m->ip);
21102 pr_cont("\n");
21103 }
21104@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21105
21106 #define PANIC_TIMEOUT 5 /* 5 seconds */
21107
21108-static atomic_t mce_paniced;
21109+static atomic_unchecked_t mce_paniced;
21110
21111 static int fake_panic;
21112-static atomic_t mce_fake_paniced;
21113+static atomic_unchecked_t mce_fake_paniced;
21114
21115 /* Panic in progress. Enable interrupts and wait for final IPI */
21116 static void wait_for_panic(void)
21117@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21118 /*
21119 * Make sure only one CPU runs in machine check panic
21120 */
21121- if (atomic_inc_return(&mce_paniced) > 1)
21122+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21123 wait_for_panic();
21124 barrier();
21125
21126@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21127 console_verbose();
21128 } else {
21129 /* Don't log too much for fake panic */
21130- if (atomic_inc_return(&mce_fake_paniced) > 1)
21131+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21132 return;
21133 }
21134 /* First print corrected ones that are still unlogged */
21135@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21136 if (!fake_panic) {
21137 if (panic_timeout == 0)
21138 panic_timeout = mca_cfg.panic_timeout;
21139- panic(msg);
21140+ panic("%s", msg);
21141 } else
21142 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21143 }
21144@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21145 * might have been modified by someone else.
21146 */
21147 rmb();
21148- if (atomic_read(&mce_paniced))
21149+ if (atomic_read_unchecked(&mce_paniced))
21150 wait_for_panic();
21151 if (!mca_cfg.monarch_timeout)
21152 goto out;
21153@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21154 }
21155
21156 /* Call the installed machine check handler for this CPU setup. */
21157-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21158+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21159 unexpected_machine_check;
21160
21161 /*
21162@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21163 return;
21164 }
21165
21166+ pax_open_kernel();
21167 machine_check_vector = do_machine_check;
21168+ pax_close_kernel();
21169
21170 __mcheck_cpu_init_generic();
21171 __mcheck_cpu_init_vendor(c);
21172@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21173 */
21174
21175 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21176-static int mce_chrdev_open_count; /* #times opened */
21177+static local_t mce_chrdev_open_count; /* #times opened */
21178 static int mce_chrdev_open_exclu; /* already open exclusive? */
21179
21180 static int mce_chrdev_open(struct inode *inode, struct file *file)
21181@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21182 spin_lock(&mce_chrdev_state_lock);
21183
21184 if (mce_chrdev_open_exclu ||
21185- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21186+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21187 spin_unlock(&mce_chrdev_state_lock);
21188
21189 return -EBUSY;
21190@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21191
21192 if (file->f_flags & O_EXCL)
21193 mce_chrdev_open_exclu = 1;
21194- mce_chrdev_open_count++;
21195+ local_inc(&mce_chrdev_open_count);
21196
21197 spin_unlock(&mce_chrdev_state_lock);
21198
21199@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21200 {
21201 spin_lock(&mce_chrdev_state_lock);
21202
21203- mce_chrdev_open_count--;
21204+ local_dec(&mce_chrdev_open_count);
21205 mce_chrdev_open_exclu = 0;
21206
21207 spin_unlock(&mce_chrdev_state_lock);
21208@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21209
21210 for (i = 0; i < mca_cfg.banks; i++) {
21211 struct mce_bank *b = &mce_banks[i];
21212- struct device_attribute *a = &b->attr;
21213+ device_attribute_no_const *a = &b->attr;
21214
21215 sysfs_attr_init(&a->attr);
21216 a->attr.name = b->attrname;
21217@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21218 static void mce_reset(void)
21219 {
21220 cpu_missing = 0;
21221- atomic_set(&mce_fake_paniced, 0);
21222+ atomic_set_unchecked(&mce_fake_paniced, 0);
21223 atomic_set(&mce_executing, 0);
21224 atomic_set(&mce_callin, 0);
21225 atomic_set(&global_nwo, 0);
21226diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21227index a304298..49b6d06 100644
21228--- a/arch/x86/kernel/cpu/mcheck/p5.c
21229+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21230@@ -10,6 +10,7 @@
21231 #include <asm/processor.h>
21232 #include <asm/mce.h>
21233 #include <asm/msr.h>
21234+#include <asm/pgtable.h>
21235
21236 /* By default disabled */
21237 int mce_p5_enabled __read_mostly;
21238@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21239 if (!cpu_has(c, X86_FEATURE_MCE))
21240 return;
21241
21242+ pax_open_kernel();
21243 machine_check_vector = pentium_machine_check;
21244+ pax_close_kernel();
21245 /* Make sure the vector pointer is visible before we enable MCEs: */
21246 wmb();
21247
21248diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21249index 7dc5564..1273569 100644
21250--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21251+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21252@@ -9,6 +9,7 @@
21253 #include <asm/processor.h>
21254 #include <asm/mce.h>
21255 #include <asm/msr.h>
21256+#include <asm/pgtable.h>
21257
21258 /* Machine check handler for WinChip C6: */
21259 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21260@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21261 {
21262 u32 lo, hi;
21263
21264+ pax_open_kernel();
21265 machine_check_vector = winchip_machine_check;
21266+ pax_close_kernel();
21267 /* Make sure the vector pointer is visible before we enable MCEs: */
21268 wmb();
21269
21270diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21271index 15c9876..0a43909 100644
21272--- a/arch/x86/kernel/cpu/microcode/core.c
21273+++ b/arch/x86/kernel/cpu/microcode/core.c
21274@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21275 return NOTIFY_OK;
21276 }
21277
21278-static struct notifier_block __refdata mc_cpu_notifier = {
21279+static struct notifier_block mc_cpu_notifier = {
21280 .notifier_call = mc_cpu_callback,
21281 };
21282
21283diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21284index a276fa7..e66810f 100644
21285--- a/arch/x86/kernel/cpu/microcode/intel.c
21286+++ b/arch/x86/kernel/cpu/microcode/intel.c
21287@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21288
21289 static int get_ucode_user(void *to, const void *from, size_t n)
21290 {
21291- return copy_from_user(to, from, n);
21292+ return copy_from_user(to, (const void __force_user *)from, n);
21293 }
21294
21295 static enum ucode_state
21296 request_microcode_user(int cpu, const void __user *buf, size_t size)
21297 {
21298- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21299+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21300 }
21301
21302 static void microcode_fini_cpu(int cpu)
21303diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21304index f961de9..8a9d332 100644
21305--- a/arch/x86/kernel/cpu/mtrr/main.c
21306+++ b/arch/x86/kernel/cpu/mtrr/main.c
21307@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21308 u64 size_or_mask, size_and_mask;
21309 static bool mtrr_aps_delayed_init;
21310
21311-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21312+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21313
21314 const struct mtrr_ops *mtrr_if;
21315
21316diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21317index df5e41f..816c719 100644
21318--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21319+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21320@@ -25,7 +25,7 @@ struct mtrr_ops {
21321 int (*validate_add_page)(unsigned long base, unsigned long size,
21322 unsigned int type);
21323 int (*have_wrcomb)(void);
21324-};
21325+} __do_const;
21326
21327 extern int generic_get_free_region(unsigned long base, unsigned long size,
21328 int replace_reg);
21329diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21330index 79f9f84..38ace52 100644
21331--- a/arch/x86/kernel/cpu/perf_event.c
21332+++ b/arch/x86/kernel/cpu/perf_event.c
21333@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21334 pr_info("no hardware sampling interrupt available.\n");
21335 }
21336
21337-static struct attribute_group x86_pmu_format_group = {
21338+static attribute_group_no_const x86_pmu_format_group = {
21339 .name = "format",
21340 .attrs = NULL,
21341 };
21342@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21343 NULL,
21344 };
21345
21346-static struct attribute_group x86_pmu_events_group = {
21347+static attribute_group_no_const x86_pmu_events_group = {
21348 .name = "events",
21349 .attrs = events_attr,
21350 };
21351@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21352 if (idx > GDT_ENTRIES)
21353 return 0;
21354
21355- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21356+ desc = get_cpu_gdt_table(smp_processor_id());
21357 }
21358
21359 return get_desc_base(desc + idx);
21360@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21361 break;
21362
21363 perf_callchain_store(entry, frame.return_address);
21364- fp = frame.next_frame;
21365+ fp = (const void __force_user *)frame.next_frame;
21366 }
21367 }
21368
21369diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21370index 639d128..e92d7e5 100644
21371--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21372+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21373@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21374 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21375 {
21376 struct attribute **attrs;
21377- struct attribute_group *attr_group;
21378+ attribute_group_no_const *attr_group;
21379 int i = 0, j;
21380
21381 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21382diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21383index aa333d9..f9db700 100644
21384--- a/arch/x86/kernel/cpu/perf_event_intel.c
21385+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21386@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21387 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21388
21389 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21390- u64 capabilities;
21391+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21392
21393- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21394- x86_pmu.intel_cap.capabilities = capabilities;
21395+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21396+ x86_pmu.intel_cap.capabilities = capabilities;
21397 }
21398
21399 intel_ds_init();
21400diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21401index 5ad35ad..e0a3960 100644
21402--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21403+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21404@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21405 NULL,
21406 };
21407
21408-static struct attribute_group rapl_pmu_events_group = {
21409+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21410 .name = "events",
21411 .attrs = NULL, /* patched at runtime */
21412 };
21413diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21414index 047f540..afdeba0 100644
21415--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21416+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21417@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21418 static int __init uncore_type_init(struct intel_uncore_type *type)
21419 {
21420 struct intel_uncore_pmu *pmus;
21421- struct attribute_group *attr_group;
21422+ attribute_group_no_const *attr_group;
21423 struct attribute **attrs;
21424 int i, j;
21425
21426diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21427index a80ab71..4089da5 100644
21428--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21429+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21430@@ -498,7 +498,7 @@ struct intel_uncore_box {
21431 struct uncore_event_desc {
21432 struct kobj_attribute attr;
21433 const char *config;
21434-};
21435+} __do_const;
21436
21437 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21438 { \
21439diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21440index 7d9481c..99c7e4b 100644
21441--- a/arch/x86/kernel/cpuid.c
21442+++ b/arch/x86/kernel/cpuid.c
21443@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21444 return notifier_from_errno(err);
21445 }
21446
21447-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21448+static struct notifier_block cpuid_class_cpu_notifier =
21449 {
21450 .notifier_call = cpuid_class_cpu_callback,
21451 };
21452diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21453index a57902e..ebaae2a 100644
21454--- a/arch/x86/kernel/crash.c
21455+++ b/arch/x86/kernel/crash.c
21456@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21457 {
21458 #ifdef CONFIG_X86_32
21459 struct pt_regs fixed_regs;
21460-#endif
21461
21462-#ifdef CONFIG_X86_32
21463- if (!user_mode_vm(regs)) {
21464+ if (!user_mode(regs)) {
21465 crash_fixup_ss_esp(&fixed_regs, regs);
21466 regs = &fixed_regs;
21467 }
21468diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21469index afa64ad..dce67dd 100644
21470--- a/arch/x86/kernel/crash_dump_64.c
21471+++ b/arch/x86/kernel/crash_dump_64.c
21472@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21473 return -ENOMEM;
21474
21475 if (userbuf) {
21476- if (copy_to_user(buf, vaddr + offset, csize)) {
21477+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21478 iounmap(vaddr);
21479 return -EFAULT;
21480 }
21481diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21482index f6dfd93..892ade4 100644
21483--- a/arch/x86/kernel/doublefault.c
21484+++ b/arch/x86/kernel/doublefault.c
21485@@ -12,7 +12,7 @@
21486
21487 #define DOUBLEFAULT_STACKSIZE (1024)
21488 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21489-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21490+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21491
21492 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21493
21494@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21495 unsigned long gdt, tss;
21496
21497 native_store_gdt(&gdt_desc);
21498- gdt = gdt_desc.address;
21499+ gdt = (unsigned long)gdt_desc.address;
21500
21501 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21502
21503@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21504 /* 0x2 bit is always set */
21505 .flags = X86_EFLAGS_SF | 0x2,
21506 .sp = STACK_START,
21507- .es = __USER_DS,
21508+ .es = __KERNEL_DS,
21509 .cs = __KERNEL_CS,
21510 .ss = __KERNEL_DS,
21511- .ds = __USER_DS,
21512+ .ds = __KERNEL_DS,
21513 .fs = __KERNEL_PERCPU,
21514
21515 .__cr3 = __pa_nodebug(swapper_pg_dir),
21516diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21517index d9c12d3..7858b62 100644
21518--- a/arch/x86/kernel/dumpstack.c
21519+++ b/arch/x86/kernel/dumpstack.c
21520@@ -2,6 +2,9 @@
21521 * Copyright (C) 1991, 1992 Linus Torvalds
21522 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21523 */
21524+#ifdef CONFIG_GRKERNSEC_HIDESYM
21525+#define __INCLUDED_BY_HIDESYM 1
21526+#endif
21527 #include <linux/kallsyms.h>
21528 #include <linux/kprobes.h>
21529 #include <linux/uaccess.h>
21530@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21531 static void
21532 print_ftrace_graph_addr(unsigned long addr, void *data,
21533 const struct stacktrace_ops *ops,
21534- struct thread_info *tinfo, int *graph)
21535+ struct task_struct *task, int *graph)
21536 {
21537- struct task_struct *task;
21538 unsigned long ret_addr;
21539 int index;
21540
21541 if (addr != (unsigned long)return_to_handler)
21542 return;
21543
21544- task = tinfo->task;
21545 index = task->curr_ret_stack;
21546
21547 if (!task->ret_stack || index < *graph)
21548@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21549 static inline void
21550 print_ftrace_graph_addr(unsigned long addr, void *data,
21551 const struct stacktrace_ops *ops,
21552- struct thread_info *tinfo, int *graph)
21553+ struct task_struct *task, int *graph)
21554 { }
21555 #endif
21556
21557@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21558 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21559 */
21560
21561-static inline int valid_stack_ptr(struct thread_info *tinfo,
21562- void *p, unsigned int size, void *end)
21563+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21564 {
21565- void *t = tinfo;
21566 if (end) {
21567 if (p < end && p >= (end-THREAD_SIZE))
21568 return 1;
21569@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21570 }
21571
21572 unsigned long
21573-print_context_stack(struct thread_info *tinfo,
21574+print_context_stack(struct task_struct *task, void *stack_start,
21575 unsigned long *stack, unsigned long bp,
21576 const struct stacktrace_ops *ops, void *data,
21577 unsigned long *end, int *graph)
21578 {
21579 struct stack_frame *frame = (struct stack_frame *)bp;
21580
21581- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21582+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21583 unsigned long addr;
21584
21585 addr = *stack;
21586@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21587 } else {
21588 ops->address(data, addr, 0);
21589 }
21590- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21591+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21592 }
21593 stack++;
21594 }
21595@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21596 EXPORT_SYMBOL_GPL(print_context_stack);
21597
21598 unsigned long
21599-print_context_stack_bp(struct thread_info *tinfo,
21600+print_context_stack_bp(struct task_struct *task, void *stack_start,
21601 unsigned long *stack, unsigned long bp,
21602 const struct stacktrace_ops *ops, void *data,
21603 unsigned long *end, int *graph)
21604@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21605 struct stack_frame *frame = (struct stack_frame *)bp;
21606 unsigned long *ret_addr = &frame->return_address;
21607
21608- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21609+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21610 unsigned long addr = *ret_addr;
21611
21612 if (!__kernel_text_address(addr))
21613@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21614 ops->address(data, addr, 1);
21615 frame = frame->next_frame;
21616 ret_addr = &frame->return_address;
21617- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21618+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21619 }
21620
21621 return (unsigned long)frame;
21622@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21623 static void print_trace_address(void *data, unsigned long addr, int reliable)
21624 {
21625 touch_nmi_watchdog();
21626- printk(data);
21627+ printk("%s", (char *)data);
21628 printk_stack_address(addr, reliable);
21629 }
21630
21631@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21632 }
21633 EXPORT_SYMBOL_GPL(oops_begin);
21634
21635+extern void gr_handle_kernel_exploit(void);
21636+
21637 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21638 {
21639 if (regs && kexec_should_crash(current))
21640@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21641 panic("Fatal exception in interrupt");
21642 if (panic_on_oops)
21643 panic("Fatal exception");
21644- do_exit(signr);
21645+
21646+ gr_handle_kernel_exploit();
21647+
21648+ do_group_exit(signr);
21649 }
21650
21651 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21652@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21653 print_modules();
21654 show_regs(regs);
21655 #ifdef CONFIG_X86_32
21656- if (user_mode_vm(regs)) {
21657+ if (user_mode(regs)) {
21658 sp = regs->sp;
21659 ss = regs->ss & 0xffff;
21660 } else {
21661@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21662 unsigned long flags = oops_begin();
21663 int sig = SIGSEGV;
21664
21665- if (!user_mode_vm(regs))
21666+ if (!user_mode(regs))
21667 report_bug(regs->ip, regs);
21668
21669 if (__die(str, regs, err))
21670diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21671index f2a1770..540657f 100644
21672--- a/arch/x86/kernel/dumpstack_32.c
21673+++ b/arch/x86/kernel/dumpstack_32.c
21674@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21675 bp = stack_frame(task, regs);
21676
21677 for (;;) {
21678- struct thread_info *context;
21679+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21680
21681- context = (struct thread_info *)
21682- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21683- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21684+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21685
21686- stack = (unsigned long *)context->previous_esp;
21687- if (!stack)
21688+ if (stack_start == task_stack_page(task))
21689 break;
21690+ stack = *(unsigned long **)stack_start;
21691 if (ops->stack(data, "IRQ") < 0)
21692 break;
21693 touch_nmi_watchdog();
21694@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21695 int i;
21696
21697 show_regs_print_info(KERN_EMERG);
21698- __show_regs(regs, !user_mode_vm(regs));
21699+ __show_regs(regs, !user_mode(regs));
21700
21701 /*
21702 * When in-kernel, we also print out the stack and code at the
21703 * time of the fault..
21704 */
21705- if (!user_mode_vm(regs)) {
21706+ if (!user_mode(regs)) {
21707 unsigned int code_prologue = code_bytes * 43 / 64;
21708 unsigned int code_len = code_bytes;
21709 unsigned char c;
21710 u8 *ip;
21711+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21712
21713 pr_emerg("Stack:\n");
21714 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21715
21716 pr_emerg("Code:");
21717
21718- ip = (u8 *)regs->ip - code_prologue;
21719+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21720 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21721 /* try starting at IP */
21722- ip = (u8 *)regs->ip;
21723+ ip = (u8 *)regs->ip + cs_base;
21724 code_len = code_len - code_prologue + 1;
21725 }
21726 for (i = 0; i < code_len; i++, ip++) {
21727@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21728 pr_cont(" Bad EIP value.");
21729 break;
21730 }
21731- if (ip == (u8 *)regs->ip)
21732+ if (ip == (u8 *)regs->ip + cs_base)
21733 pr_cont(" <%02x>", c);
21734 else
21735 pr_cont(" %02x", c);
21736@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21737 {
21738 unsigned short ud2;
21739
21740+ ip = ktla_ktva(ip);
21741 if (ip < PAGE_OFFSET)
21742 return 0;
21743 if (probe_kernel_address((unsigned short *)ip, ud2))
21744@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21745
21746 return ud2 == 0x0b0f;
21747 }
21748+
21749+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21750+void pax_check_alloca(unsigned long size)
21751+{
21752+ unsigned long sp = (unsigned long)&sp, stack_left;
21753+
21754+ /* all kernel stacks are of the same size */
21755+ stack_left = sp & (THREAD_SIZE - 1);
21756+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21757+}
21758+EXPORT_SYMBOL(pax_check_alloca);
21759+#endif
21760diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21761index addb207..99635fa 100644
21762--- a/arch/x86/kernel/dumpstack_64.c
21763+++ b/arch/x86/kernel/dumpstack_64.c
21764@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21765 unsigned long *irq_stack_end =
21766 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21767 unsigned used = 0;
21768- struct thread_info *tinfo;
21769 int graph = 0;
21770 unsigned long dummy;
21771+ void *stack_start;
21772
21773 if (!task)
21774 task = current;
21775@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21776 * current stack address. If the stacks consist of nested
21777 * exceptions
21778 */
21779- tinfo = task_thread_info(task);
21780 for (;;) {
21781 char *id;
21782 unsigned long *estack_end;
21783+
21784 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21785 &used, &id);
21786
21787@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21788 if (ops->stack(data, id) < 0)
21789 break;
21790
21791- bp = ops->walk_stack(tinfo, stack, bp, ops,
21792+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21793 data, estack_end, &graph);
21794 ops->stack(data, "<EOE>");
21795 /*
21796@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21797 * second-to-last pointer (index -2 to end) in the
21798 * exception stack:
21799 */
21800+ if ((u16)estack_end[-1] != __KERNEL_DS)
21801+ goto out;
21802 stack = (unsigned long *) estack_end[-2];
21803 continue;
21804 }
21805@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21806 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21807 if (ops->stack(data, "IRQ") < 0)
21808 break;
21809- bp = ops->walk_stack(tinfo, stack, bp,
21810+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21811 ops, data, irq_stack_end, &graph);
21812 /*
21813 * We link to the next stack (which would be
21814@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21815 /*
21816 * This handles the process stack:
21817 */
21818- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21819+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21820+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21821+out:
21822 put_cpu();
21823 }
21824 EXPORT_SYMBOL(dump_trace);
21825@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21826
21827 return ud2 == 0x0b0f;
21828 }
21829+
21830+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21831+void pax_check_alloca(unsigned long size)
21832+{
21833+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21834+ unsigned cpu, used;
21835+ char *id;
21836+
21837+ /* check the process stack first */
21838+ stack_start = (unsigned long)task_stack_page(current);
21839+ stack_end = stack_start + THREAD_SIZE;
21840+ if (likely(stack_start <= sp && sp < stack_end)) {
21841+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21842+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21843+ return;
21844+ }
21845+
21846+ cpu = get_cpu();
21847+
21848+ /* check the irq stacks */
21849+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21850+ stack_start = stack_end - IRQ_STACK_SIZE;
21851+ if (stack_start <= sp && sp < stack_end) {
21852+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21853+ put_cpu();
21854+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21855+ return;
21856+ }
21857+
21858+ /* check the exception stacks */
21859+ used = 0;
21860+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21861+ stack_start = stack_end - EXCEPTION_STKSZ;
21862+ if (stack_end && stack_start <= sp && sp < stack_end) {
21863+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21864+ put_cpu();
21865+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21866+ return;
21867+ }
21868+
21869+ put_cpu();
21870+
21871+ /* unknown stack */
21872+ BUG();
21873+}
21874+EXPORT_SYMBOL(pax_check_alloca);
21875+#endif
21876diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21877index 988c00a..4f673b6 100644
21878--- a/arch/x86/kernel/e820.c
21879+++ b/arch/x86/kernel/e820.c
21880@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21881
21882 static void early_panic(char *msg)
21883 {
21884- early_printk(msg);
21885- panic(msg);
21886+ early_printk("%s", msg);
21887+ panic("%s", msg);
21888 }
21889
21890 static int userdef __initdata;
21891diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21892index 01d1c18..8073693 100644
21893--- a/arch/x86/kernel/early_printk.c
21894+++ b/arch/x86/kernel/early_printk.c
21895@@ -7,6 +7,7 @@
21896 #include <linux/pci_regs.h>
21897 #include <linux/pci_ids.h>
21898 #include <linux/errno.h>
21899+#include <linux/sched.h>
21900 #include <asm/io.h>
21901 #include <asm/processor.h>
21902 #include <asm/fcntl.h>
21903diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21904index a2a4f46..6cab058 100644
21905--- a/arch/x86/kernel/entry_32.S
21906+++ b/arch/x86/kernel/entry_32.S
21907@@ -177,13 +177,153 @@
21908 /*CFI_REL_OFFSET gs, PT_GS*/
21909 .endm
21910 .macro SET_KERNEL_GS reg
21911+
21912+#ifdef CONFIG_CC_STACKPROTECTOR
21913 movl $(__KERNEL_STACK_CANARY), \reg
21914+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21915+ movl $(__USER_DS), \reg
21916+#else
21917+ xorl \reg, \reg
21918+#endif
21919+
21920 movl \reg, %gs
21921 .endm
21922
21923 #endif /* CONFIG_X86_32_LAZY_GS */
21924
21925-.macro SAVE_ALL
21926+.macro pax_enter_kernel
21927+#ifdef CONFIG_PAX_KERNEXEC
21928+ call pax_enter_kernel
21929+#endif
21930+.endm
21931+
21932+.macro pax_exit_kernel
21933+#ifdef CONFIG_PAX_KERNEXEC
21934+ call pax_exit_kernel
21935+#endif
21936+.endm
21937+
21938+#ifdef CONFIG_PAX_KERNEXEC
21939+ENTRY(pax_enter_kernel)
21940+#ifdef CONFIG_PARAVIRT
21941+ pushl %eax
21942+ pushl %ecx
21943+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21944+ mov %eax, %esi
21945+#else
21946+ mov %cr0, %esi
21947+#endif
21948+ bts $16, %esi
21949+ jnc 1f
21950+ mov %cs, %esi
21951+ cmp $__KERNEL_CS, %esi
21952+ jz 3f
21953+ ljmp $__KERNEL_CS, $3f
21954+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21955+2:
21956+#ifdef CONFIG_PARAVIRT
21957+ mov %esi, %eax
21958+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21959+#else
21960+ mov %esi, %cr0
21961+#endif
21962+3:
21963+#ifdef CONFIG_PARAVIRT
21964+ popl %ecx
21965+ popl %eax
21966+#endif
21967+ ret
21968+ENDPROC(pax_enter_kernel)
21969+
21970+ENTRY(pax_exit_kernel)
21971+#ifdef CONFIG_PARAVIRT
21972+ pushl %eax
21973+ pushl %ecx
21974+#endif
21975+ mov %cs, %esi
21976+ cmp $__KERNEXEC_KERNEL_CS, %esi
21977+ jnz 2f
21978+#ifdef CONFIG_PARAVIRT
21979+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21980+ mov %eax, %esi
21981+#else
21982+ mov %cr0, %esi
21983+#endif
21984+ btr $16, %esi
21985+ ljmp $__KERNEL_CS, $1f
21986+1:
21987+#ifdef CONFIG_PARAVIRT
21988+ mov %esi, %eax
21989+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21990+#else
21991+ mov %esi, %cr0
21992+#endif
21993+2:
21994+#ifdef CONFIG_PARAVIRT
21995+ popl %ecx
21996+ popl %eax
21997+#endif
21998+ ret
21999+ENDPROC(pax_exit_kernel)
22000+#endif
22001+
22002+ .macro pax_erase_kstack
22003+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22004+ call pax_erase_kstack
22005+#endif
22006+ .endm
22007+
22008+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22009+/*
22010+ * ebp: thread_info
22011+ */
22012+ENTRY(pax_erase_kstack)
22013+ pushl %edi
22014+ pushl %ecx
22015+ pushl %eax
22016+
22017+ mov TI_lowest_stack(%ebp), %edi
22018+ mov $-0xBEEF, %eax
22019+ std
22020+
22021+1: mov %edi, %ecx
22022+ and $THREAD_SIZE_asm - 1, %ecx
22023+ shr $2, %ecx
22024+ repne scasl
22025+ jecxz 2f
22026+
22027+ cmp $2*16, %ecx
22028+ jc 2f
22029+
22030+ mov $2*16, %ecx
22031+ repe scasl
22032+ jecxz 2f
22033+ jne 1b
22034+
22035+2: cld
22036+ mov %esp, %ecx
22037+ sub %edi, %ecx
22038+
22039+ cmp $THREAD_SIZE_asm, %ecx
22040+ jb 3f
22041+ ud2
22042+3:
22043+
22044+ shr $2, %ecx
22045+ rep stosl
22046+
22047+ mov TI_task_thread_sp0(%ebp), %edi
22048+ sub $128, %edi
22049+ mov %edi, TI_lowest_stack(%ebp)
22050+
22051+ popl %eax
22052+ popl %ecx
22053+ popl %edi
22054+ ret
22055+ENDPROC(pax_erase_kstack)
22056+#endif
22057+
22058+.macro __SAVE_ALL _DS
22059 cld
22060 PUSH_GS
22061 pushl_cfi %fs
22062@@ -206,7 +346,7 @@
22063 CFI_REL_OFFSET ecx, 0
22064 pushl_cfi %ebx
22065 CFI_REL_OFFSET ebx, 0
22066- movl $(__USER_DS), %edx
22067+ movl $\_DS, %edx
22068 movl %edx, %ds
22069 movl %edx, %es
22070 movl $(__KERNEL_PERCPU), %edx
22071@@ -214,6 +354,15 @@
22072 SET_KERNEL_GS %edx
22073 .endm
22074
22075+.macro SAVE_ALL
22076+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22077+ __SAVE_ALL __KERNEL_DS
22078+ pax_enter_kernel
22079+#else
22080+ __SAVE_ALL __USER_DS
22081+#endif
22082+.endm
22083+
22084 .macro RESTORE_INT_REGS
22085 popl_cfi %ebx
22086 CFI_RESTORE ebx
22087@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22088 popfl_cfi
22089 jmp syscall_exit
22090 CFI_ENDPROC
22091-END(ret_from_fork)
22092+ENDPROC(ret_from_fork)
22093
22094 ENTRY(ret_from_kernel_thread)
22095 CFI_STARTPROC
22096@@ -344,7 +493,15 @@ ret_from_intr:
22097 andl $SEGMENT_RPL_MASK, %eax
22098 #endif
22099 cmpl $USER_RPL, %eax
22100+
22101+#ifdef CONFIG_PAX_KERNEXEC
22102+ jae resume_userspace
22103+
22104+ pax_exit_kernel
22105+ jmp resume_kernel
22106+#else
22107 jb resume_kernel # not returning to v8086 or userspace
22108+#endif
22109
22110 ENTRY(resume_userspace)
22111 LOCKDEP_SYS_EXIT
22112@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22113 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22114 # int/exception return?
22115 jne work_pending
22116- jmp restore_all
22117-END(ret_from_exception)
22118+ jmp restore_all_pax
22119+ENDPROC(ret_from_exception)
22120
22121 #ifdef CONFIG_PREEMPT
22122 ENTRY(resume_kernel)
22123@@ -369,7 +526,7 @@ need_resched:
22124 jz restore_all
22125 call preempt_schedule_irq
22126 jmp need_resched
22127-END(resume_kernel)
22128+ENDPROC(resume_kernel)
22129 #endif
22130 CFI_ENDPROC
22131 /*
22132@@ -403,30 +560,45 @@ sysenter_past_esp:
22133 /*CFI_REL_OFFSET cs, 0*/
22134 /*
22135 * Push current_thread_info()->sysenter_return to the stack.
22136- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22137- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22138 */
22139- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22140+ pushl_cfi $0
22141 CFI_REL_OFFSET eip, 0
22142
22143 pushl_cfi %eax
22144 SAVE_ALL
22145+ GET_THREAD_INFO(%ebp)
22146+ movl TI_sysenter_return(%ebp),%ebp
22147+ movl %ebp,PT_EIP(%esp)
22148 ENABLE_INTERRUPTS(CLBR_NONE)
22149
22150 /*
22151 * Load the potential sixth argument from user stack.
22152 * Careful about security.
22153 */
22154+ movl PT_OLDESP(%esp),%ebp
22155+
22156+#ifdef CONFIG_PAX_MEMORY_UDEREF
22157+ mov PT_OLDSS(%esp),%ds
22158+1: movl %ds:(%ebp),%ebp
22159+ push %ss
22160+ pop %ds
22161+#else
22162 cmpl $__PAGE_OFFSET-3,%ebp
22163 jae syscall_fault
22164 ASM_STAC
22165 1: movl (%ebp),%ebp
22166 ASM_CLAC
22167+#endif
22168+
22169 movl %ebp,PT_EBP(%esp)
22170 _ASM_EXTABLE(1b,syscall_fault)
22171
22172 GET_THREAD_INFO(%ebp)
22173
22174+#ifdef CONFIG_PAX_RANDKSTACK
22175+ pax_erase_kstack
22176+#endif
22177+
22178 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22179 jnz sysenter_audit
22180 sysenter_do_call:
22181@@ -441,12 +613,24 @@ sysenter_do_call:
22182 testl $_TIF_ALLWORK_MASK, %ecx
22183 jne sysexit_audit
22184 sysenter_exit:
22185+
22186+#ifdef CONFIG_PAX_RANDKSTACK
22187+ pushl_cfi %eax
22188+ movl %esp, %eax
22189+ call pax_randomize_kstack
22190+ popl_cfi %eax
22191+#endif
22192+
22193+ pax_erase_kstack
22194+
22195 /* if something modifies registers it must also disable sysexit */
22196 movl PT_EIP(%esp), %edx
22197 movl PT_OLDESP(%esp), %ecx
22198 xorl %ebp,%ebp
22199 TRACE_IRQS_ON
22200 1: mov PT_FS(%esp), %fs
22201+2: mov PT_DS(%esp), %ds
22202+3: mov PT_ES(%esp), %es
22203 PTGS_TO_GS
22204 ENABLE_INTERRUPTS_SYSEXIT
22205
22206@@ -463,6 +647,9 @@ sysenter_audit:
22207 movl %eax,%edx /* 2nd arg: syscall number */
22208 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22209 call __audit_syscall_entry
22210+
22211+ pax_erase_kstack
22212+
22213 pushl_cfi %ebx
22214 movl PT_EAX(%esp),%eax /* reload syscall number */
22215 jmp sysenter_do_call
22216@@ -488,10 +675,16 @@ sysexit_audit:
22217
22218 CFI_ENDPROC
22219 .pushsection .fixup,"ax"
22220-2: movl $0,PT_FS(%esp)
22221+4: movl $0,PT_FS(%esp)
22222+ jmp 1b
22223+5: movl $0,PT_DS(%esp)
22224+ jmp 1b
22225+6: movl $0,PT_ES(%esp)
22226 jmp 1b
22227 .popsection
22228- _ASM_EXTABLE(1b,2b)
22229+ _ASM_EXTABLE(1b,4b)
22230+ _ASM_EXTABLE(2b,5b)
22231+ _ASM_EXTABLE(3b,6b)
22232 PTGS_TO_GS_EX
22233 ENDPROC(ia32_sysenter_target)
22234
22235@@ -506,6 +699,11 @@ ENTRY(system_call)
22236 pushl_cfi %eax # save orig_eax
22237 SAVE_ALL
22238 GET_THREAD_INFO(%ebp)
22239+
22240+#ifdef CONFIG_PAX_RANDKSTACK
22241+ pax_erase_kstack
22242+#endif
22243+
22244 # system call tracing in operation / emulation
22245 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22246 jnz syscall_trace_entry
22247@@ -524,6 +722,15 @@ syscall_exit:
22248 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22249 jne syscall_exit_work
22250
22251+restore_all_pax:
22252+
22253+#ifdef CONFIG_PAX_RANDKSTACK
22254+ movl %esp, %eax
22255+ call pax_randomize_kstack
22256+#endif
22257+
22258+ pax_erase_kstack
22259+
22260 restore_all:
22261 TRACE_IRQS_IRET
22262 restore_all_notrace:
22263@@ -580,14 +787,34 @@ ldt_ss:
22264 * compensating for the offset by changing to the ESPFIX segment with
22265 * a base address that matches for the difference.
22266 */
22267-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22268+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22269 mov %esp, %edx /* load kernel esp */
22270 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22271 mov %dx, %ax /* eax: new kernel esp */
22272 sub %eax, %edx /* offset (low word is 0) */
22273+#ifdef CONFIG_SMP
22274+ movl PER_CPU_VAR(cpu_number), %ebx
22275+ shll $PAGE_SHIFT_asm, %ebx
22276+ addl $cpu_gdt_table, %ebx
22277+#else
22278+ movl $cpu_gdt_table, %ebx
22279+#endif
22280 shr $16, %edx
22281- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22282- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22283+
22284+#ifdef CONFIG_PAX_KERNEXEC
22285+ mov %cr0, %esi
22286+ btr $16, %esi
22287+ mov %esi, %cr0
22288+#endif
22289+
22290+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22291+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22292+
22293+#ifdef CONFIG_PAX_KERNEXEC
22294+ bts $16, %esi
22295+ mov %esi, %cr0
22296+#endif
22297+
22298 pushl_cfi $__ESPFIX_SS
22299 pushl_cfi %eax /* new kernel esp */
22300 /* Disable interrupts, but do not irqtrace this section: we
22301@@ -616,20 +843,18 @@ work_resched:
22302 movl TI_flags(%ebp), %ecx
22303 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22304 # than syscall tracing?
22305- jz restore_all
22306+ jz restore_all_pax
22307 testb $_TIF_NEED_RESCHED, %cl
22308 jnz work_resched
22309
22310 work_notifysig: # deal with pending signals and
22311 # notify-resume requests
22312+ movl %esp, %eax
22313 #ifdef CONFIG_VM86
22314 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22315- movl %esp, %eax
22316 jne work_notifysig_v86 # returning to kernel-space or
22317 # vm86-space
22318 1:
22319-#else
22320- movl %esp, %eax
22321 #endif
22322 TRACE_IRQS_ON
22323 ENABLE_INTERRUPTS(CLBR_NONE)
22324@@ -650,7 +875,7 @@ work_notifysig_v86:
22325 movl %eax, %esp
22326 jmp 1b
22327 #endif
22328-END(work_pending)
22329+ENDPROC(work_pending)
22330
22331 # perform syscall exit tracing
22332 ALIGN
22333@@ -658,11 +883,14 @@ syscall_trace_entry:
22334 movl $-ENOSYS,PT_EAX(%esp)
22335 movl %esp, %eax
22336 call syscall_trace_enter
22337+
22338+ pax_erase_kstack
22339+
22340 /* What it returned is what we'll actually use. */
22341 cmpl $(NR_syscalls), %eax
22342 jnae syscall_call
22343 jmp syscall_exit
22344-END(syscall_trace_entry)
22345+ENDPROC(syscall_trace_entry)
22346
22347 # perform syscall exit tracing
22348 ALIGN
22349@@ -675,21 +903,25 @@ syscall_exit_work:
22350 movl %esp, %eax
22351 call syscall_trace_leave
22352 jmp resume_userspace
22353-END(syscall_exit_work)
22354+ENDPROC(syscall_exit_work)
22355 CFI_ENDPROC
22356
22357 RING0_INT_FRAME # can't unwind into user space anyway
22358 syscall_fault:
22359+#ifdef CONFIG_PAX_MEMORY_UDEREF
22360+ push %ss
22361+ pop %ds
22362+#endif
22363 ASM_CLAC
22364 GET_THREAD_INFO(%ebp)
22365 movl $-EFAULT,PT_EAX(%esp)
22366 jmp resume_userspace
22367-END(syscall_fault)
22368+ENDPROC(syscall_fault)
22369
22370 syscall_badsys:
22371 movl $-ENOSYS,PT_EAX(%esp)
22372 jmp resume_userspace
22373-END(syscall_badsys)
22374+ENDPROC(syscall_badsys)
22375 CFI_ENDPROC
22376 /*
22377 * End of kprobes section
22378@@ -705,8 +937,15 @@ END(syscall_badsys)
22379 * normal stack and adjusts ESP with the matching offset.
22380 */
22381 /* fixup the stack */
22382- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22383- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22384+#ifdef CONFIG_SMP
22385+ movl PER_CPU_VAR(cpu_number), %ebx
22386+ shll $PAGE_SHIFT_asm, %ebx
22387+ addl $cpu_gdt_table, %ebx
22388+#else
22389+ movl $cpu_gdt_table, %ebx
22390+#endif
22391+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22392+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22393 shl $16, %eax
22394 addl %esp, %eax /* the adjusted stack pointer */
22395 pushl_cfi $__KERNEL_DS
22396@@ -759,7 +998,7 @@ vector=vector+1
22397 .endr
22398 2: jmp common_interrupt
22399 .endr
22400-END(irq_entries_start)
22401+ENDPROC(irq_entries_start)
22402
22403 .previous
22404 END(interrupt)
22405@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22406 pushl_cfi $do_coprocessor_error
22407 jmp error_code
22408 CFI_ENDPROC
22409-END(coprocessor_error)
22410+ENDPROC(coprocessor_error)
22411
22412 ENTRY(simd_coprocessor_error)
22413 RING0_INT_FRAME
22414@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22415 .section .altinstructions,"a"
22416 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22417 .previous
22418-.section .altinstr_replacement,"ax"
22419+.section .altinstr_replacement,"a"
22420 663: pushl $do_simd_coprocessor_error
22421 664:
22422 .previous
22423@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22424 #endif
22425 jmp error_code
22426 CFI_ENDPROC
22427-END(simd_coprocessor_error)
22428+ENDPROC(simd_coprocessor_error)
22429
22430 ENTRY(device_not_available)
22431 RING0_INT_FRAME
22432@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22433 pushl_cfi $do_device_not_available
22434 jmp error_code
22435 CFI_ENDPROC
22436-END(device_not_available)
22437+ENDPROC(device_not_available)
22438
22439 #ifdef CONFIG_PARAVIRT
22440 ENTRY(native_iret)
22441 iret
22442 _ASM_EXTABLE(native_iret, iret_exc)
22443-END(native_iret)
22444+ENDPROC(native_iret)
22445
22446 ENTRY(native_irq_enable_sysexit)
22447 sti
22448 sysexit
22449-END(native_irq_enable_sysexit)
22450+ENDPROC(native_irq_enable_sysexit)
22451 #endif
22452
22453 ENTRY(overflow)
22454@@ -872,7 +1111,7 @@ ENTRY(overflow)
22455 pushl_cfi $do_overflow
22456 jmp error_code
22457 CFI_ENDPROC
22458-END(overflow)
22459+ENDPROC(overflow)
22460
22461 ENTRY(bounds)
22462 RING0_INT_FRAME
22463@@ -881,7 +1120,7 @@ ENTRY(bounds)
22464 pushl_cfi $do_bounds
22465 jmp error_code
22466 CFI_ENDPROC
22467-END(bounds)
22468+ENDPROC(bounds)
22469
22470 ENTRY(invalid_op)
22471 RING0_INT_FRAME
22472@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22473 pushl_cfi $do_invalid_op
22474 jmp error_code
22475 CFI_ENDPROC
22476-END(invalid_op)
22477+ENDPROC(invalid_op)
22478
22479 ENTRY(coprocessor_segment_overrun)
22480 RING0_INT_FRAME
22481@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22482 pushl_cfi $do_coprocessor_segment_overrun
22483 jmp error_code
22484 CFI_ENDPROC
22485-END(coprocessor_segment_overrun)
22486+ENDPROC(coprocessor_segment_overrun)
22487
22488 ENTRY(invalid_TSS)
22489 RING0_EC_FRAME
22490@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22491 pushl_cfi $do_invalid_TSS
22492 jmp error_code
22493 CFI_ENDPROC
22494-END(invalid_TSS)
22495+ENDPROC(invalid_TSS)
22496
22497 ENTRY(segment_not_present)
22498 RING0_EC_FRAME
22499@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22500 pushl_cfi $do_segment_not_present
22501 jmp error_code
22502 CFI_ENDPROC
22503-END(segment_not_present)
22504+ENDPROC(segment_not_present)
22505
22506 ENTRY(stack_segment)
22507 RING0_EC_FRAME
22508@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22509 pushl_cfi $do_stack_segment
22510 jmp error_code
22511 CFI_ENDPROC
22512-END(stack_segment)
22513+ENDPROC(stack_segment)
22514
22515 ENTRY(alignment_check)
22516 RING0_EC_FRAME
22517@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22518 pushl_cfi $do_alignment_check
22519 jmp error_code
22520 CFI_ENDPROC
22521-END(alignment_check)
22522+ENDPROC(alignment_check)
22523
22524 ENTRY(divide_error)
22525 RING0_INT_FRAME
22526@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22527 pushl_cfi $do_divide_error
22528 jmp error_code
22529 CFI_ENDPROC
22530-END(divide_error)
22531+ENDPROC(divide_error)
22532
22533 #ifdef CONFIG_X86_MCE
22534 ENTRY(machine_check)
22535@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22536 pushl_cfi machine_check_vector
22537 jmp error_code
22538 CFI_ENDPROC
22539-END(machine_check)
22540+ENDPROC(machine_check)
22541 #endif
22542
22543 ENTRY(spurious_interrupt_bug)
22544@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22545 pushl_cfi $do_spurious_interrupt_bug
22546 jmp error_code
22547 CFI_ENDPROC
22548-END(spurious_interrupt_bug)
22549+ENDPROC(spurious_interrupt_bug)
22550 /*
22551 * End of kprobes section
22552 */
22553@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22554
22555 ENTRY(mcount)
22556 ret
22557-END(mcount)
22558+ENDPROC(mcount)
22559
22560 ENTRY(ftrace_caller)
22561 cmpl $0, function_trace_stop
22562@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22563 .globl ftrace_stub
22564 ftrace_stub:
22565 ret
22566-END(ftrace_caller)
22567+ENDPROC(ftrace_caller)
22568
22569 ENTRY(ftrace_regs_caller)
22570 pushf /* push flags before compare (in cs location) */
22571@@ -1207,7 +1446,7 @@ trace:
22572 popl %ecx
22573 popl %eax
22574 jmp ftrace_stub
22575-END(mcount)
22576+ENDPROC(mcount)
22577 #endif /* CONFIG_DYNAMIC_FTRACE */
22578 #endif /* CONFIG_FUNCTION_TRACER */
22579
22580@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22581 popl %ecx
22582 popl %eax
22583 ret
22584-END(ftrace_graph_caller)
22585+ENDPROC(ftrace_graph_caller)
22586
22587 .globl return_to_handler
22588 return_to_handler:
22589@@ -1291,15 +1530,18 @@ error_code:
22590 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22591 REG_TO_PTGS %ecx
22592 SET_KERNEL_GS %ecx
22593- movl $(__USER_DS), %ecx
22594+ movl $(__KERNEL_DS), %ecx
22595 movl %ecx, %ds
22596 movl %ecx, %es
22597+
22598+ pax_enter_kernel
22599+
22600 TRACE_IRQS_OFF
22601 movl %esp,%eax # pt_regs pointer
22602 call *%edi
22603 jmp ret_from_exception
22604 CFI_ENDPROC
22605-END(page_fault)
22606+ENDPROC(page_fault)
22607
22608 /*
22609 * Debug traps and NMI can happen at the one SYSENTER instruction
22610@@ -1342,7 +1584,7 @@ debug_stack_correct:
22611 call do_debug
22612 jmp ret_from_exception
22613 CFI_ENDPROC
22614-END(debug)
22615+ENDPROC(debug)
22616
22617 /*
22618 * NMI is doubly nasty. It can happen _while_ we're handling
22619@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22620 xorl %edx,%edx # zero error code
22621 movl %esp,%eax # pt_regs pointer
22622 call do_nmi
22623+
22624+ pax_exit_kernel
22625+
22626 jmp restore_all_notrace
22627 CFI_ENDPROC
22628
22629@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22630 FIXUP_ESPFIX_STACK # %eax == %esp
22631 xorl %edx,%edx # zero error code
22632 call do_nmi
22633+
22634+ pax_exit_kernel
22635+
22636 RESTORE_REGS
22637 lss 12+4(%esp), %esp # back to espfix stack
22638 CFI_ADJUST_CFA_OFFSET -24
22639 jmp irq_return
22640 CFI_ENDPROC
22641-END(nmi)
22642+ENDPROC(nmi)
22643
22644 ENTRY(int3)
22645 RING0_INT_FRAME
22646@@ -1434,14 +1682,14 @@ ENTRY(int3)
22647 call do_int3
22648 jmp ret_from_exception
22649 CFI_ENDPROC
22650-END(int3)
22651+ENDPROC(int3)
22652
22653 ENTRY(general_protection)
22654 RING0_EC_FRAME
22655 pushl_cfi $do_general_protection
22656 jmp error_code
22657 CFI_ENDPROC
22658-END(general_protection)
22659+ENDPROC(general_protection)
22660
22661 #ifdef CONFIG_KVM_GUEST
22662 ENTRY(async_page_fault)
22663@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22664 pushl_cfi $do_async_page_fault
22665 jmp error_code
22666 CFI_ENDPROC
22667-END(async_page_fault)
22668+ENDPROC(async_page_fault)
22669 #endif
22670
22671 /*
22672diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22673index 1e96c36..3ff710a 100644
22674--- a/arch/x86/kernel/entry_64.S
22675+++ b/arch/x86/kernel/entry_64.S
22676@@ -59,6 +59,8 @@
22677 #include <asm/context_tracking.h>
22678 #include <asm/smap.h>
22679 #include <linux/err.h>
22680+#include <asm/pgtable.h>
22681+#include <asm/alternative-asm.h>
22682
22683 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22684 #include <linux/elf-em.h>
22685@@ -80,8 +82,9 @@
22686 #ifdef CONFIG_DYNAMIC_FTRACE
22687
22688 ENTRY(function_hook)
22689+ pax_force_retaddr
22690 retq
22691-END(function_hook)
22692+ENDPROC(function_hook)
22693
22694 /* skip is set if stack has been adjusted */
22695 .macro ftrace_caller_setup skip=0
22696@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22697 #endif
22698
22699 GLOBAL(ftrace_stub)
22700+ pax_force_retaddr
22701 retq
22702-END(ftrace_caller)
22703+ENDPROC(ftrace_caller)
22704
22705 ENTRY(ftrace_regs_caller)
22706 /* Save the current flags before compare (in SS location)*/
22707@@ -191,7 +195,7 @@ ftrace_restore_flags:
22708 popfq
22709 jmp ftrace_stub
22710
22711-END(ftrace_regs_caller)
22712+ENDPROC(ftrace_regs_caller)
22713
22714
22715 #else /* ! CONFIG_DYNAMIC_FTRACE */
22716@@ -212,6 +216,7 @@ ENTRY(function_hook)
22717 #endif
22718
22719 GLOBAL(ftrace_stub)
22720+ pax_force_retaddr
22721 retq
22722
22723 trace:
22724@@ -225,12 +230,13 @@ trace:
22725 #endif
22726 subq $MCOUNT_INSN_SIZE, %rdi
22727
22728+ pax_force_fptr ftrace_trace_function
22729 call *ftrace_trace_function
22730
22731 MCOUNT_RESTORE_FRAME
22732
22733 jmp ftrace_stub
22734-END(function_hook)
22735+ENDPROC(function_hook)
22736 #endif /* CONFIG_DYNAMIC_FTRACE */
22737 #endif /* CONFIG_FUNCTION_TRACER */
22738
22739@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22740
22741 MCOUNT_RESTORE_FRAME
22742
22743+ pax_force_retaddr
22744 retq
22745-END(ftrace_graph_caller)
22746+ENDPROC(ftrace_graph_caller)
22747
22748 GLOBAL(return_to_handler)
22749 subq $24, %rsp
22750@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22751 movq 8(%rsp), %rdx
22752 movq (%rsp), %rax
22753 addq $24, %rsp
22754+ pax_force_fptr %rdi
22755 jmp *%rdi
22756+ENDPROC(return_to_handler)
22757 #endif
22758
22759
22760@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22761 ENDPROC(native_usergs_sysret64)
22762 #endif /* CONFIG_PARAVIRT */
22763
22764+ .macro ljmpq sel, off
22765+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22766+ .byte 0x48; ljmp *1234f(%rip)
22767+ .pushsection .rodata
22768+ .align 16
22769+ 1234: .quad \off; .word \sel
22770+ .popsection
22771+#else
22772+ pushq $\sel
22773+ pushq $\off
22774+ lretq
22775+#endif
22776+ .endm
22777+
22778+ .macro pax_enter_kernel
22779+ pax_set_fptr_mask
22780+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22781+ call pax_enter_kernel
22782+#endif
22783+ .endm
22784+
22785+ .macro pax_exit_kernel
22786+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22787+ call pax_exit_kernel
22788+#endif
22789+
22790+ .endm
22791+
22792+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22793+ENTRY(pax_enter_kernel)
22794+ pushq %rdi
22795+
22796+#ifdef CONFIG_PARAVIRT
22797+ PV_SAVE_REGS(CLBR_RDI)
22798+#endif
22799+
22800+#ifdef CONFIG_PAX_KERNEXEC
22801+ GET_CR0_INTO_RDI
22802+ bts $16,%rdi
22803+ jnc 3f
22804+ mov %cs,%edi
22805+ cmp $__KERNEL_CS,%edi
22806+ jnz 2f
22807+1:
22808+#endif
22809+
22810+#ifdef CONFIG_PAX_MEMORY_UDEREF
22811+ 661: jmp 111f
22812+ .pushsection .altinstr_replacement, "a"
22813+ 662: ASM_NOP2
22814+ .popsection
22815+ .pushsection .altinstructions, "a"
22816+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22817+ .popsection
22818+ GET_CR3_INTO_RDI
22819+ cmp $0,%dil
22820+ jnz 112f
22821+ mov $__KERNEL_DS,%edi
22822+ mov %edi,%ss
22823+ jmp 111f
22824+112: cmp $1,%dil
22825+ jz 113f
22826+ ud2
22827+113: sub $4097,%rdi
22828+ bts $63,%rdi
22829+ SET_RDI_INTO_CR3
22830+ mov $__UDEREF_KERNEL_DS,%edi
22831+ mov %edi,%ss
22832+111:
22833+#endif
22834+
22835+#ifdef CONFIG_PARAVIRT
22836+ PV_RESTORE_REGS(CLBR_RDI)
22837+#endif
22838+
22839+ popq %rdi
22840+ pax_force_retaddr
22841+ retq
22842+
22843+#ifdef CONFIG_PAX_KERNEXEC
22844+2: ljmpq __KERNEL_CS,1b
22845+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22846+4: SET_RDI_INTO_CR0
22847+ jmp 1b
22848+#endif
22849+ENDPROC(pax_enter_kernel)
22850+
22851+ENTRY(pax_exit_kernel)
22852+ pushq %rdi
22853+
22854+#ifdef CONFIG_PARAVIRT
22855+ PV_SAVE_REGS(CLBR_RDI)
22856+#endif
22857+
22858+#ifdef CONFIG_PAX_KERNEXEC
22859+ mov %cs,%rdi
22860+ cmp $__KERNEXEC_KERNEL_CS,%edi
22861+ jz 2f
22862+ GET_CR0_INTO_RDI
22863+ bts $16,%rdi
22864+ jnc 4f
22865+1:
22866+#endif
22867+
22868+#ifdef CONFIG_PAX_MEMORY_UDEREF
22869+ 661: jmp 111f
22870+ .pushsection .altinstr_replacement, "a"
22871+ 662: ASM_NOP2
22872+ .popsection
22873+ .pushsection .altinstructions, "a"
22874+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22875+ .popsection
22876+ mov %ss,%edi
22877+ cmp $__UDEREF_KERNEL_DS,%edi
22878+ jnz 111f
22879+ GET_CR3_INTO_RDI
22880+ cmp $0,%dil
22881+ jz 112f
22882+ ud2
22883+112: add $4097,%rdi
22884+ bts $63,%rdi
22885+ SET_RDI_INTO_CR3
22886+ mov $__KERNEL_DS,%edi
22887+ mov %edi,%ss
22888+111:
22889+#endif
22890+
22891+#ifdef CONFIG_PARAVIRT
22892+ PV_RESTORE_REGS(CLBR_RDI);
22893+#endif
22894+
22895+ popq %rdi
22896+ pax_force_retaddr
22897+ retq
22898+
22899+#ifdef CONFIG_PAX_KERNEXEC
22900+2: GET_CR0_INTO_RDI
22901+ btr $16,%rdi
22902+ jnc 4f
22903+ ljmpq __KERNEL_CS,3f
22904+3: SET_RDI_INTO_CR0
22905+ jmp 1b
22906+4: ud2
22907+ jmp 4b
22908+#endif
22909+ENDPROC(pax_exit_kernel)
22910+#endif
22911+
22912+ .macro pax_enter_kernel_user
22913+ pax_set_fptr_mask
22914+#ifdef CONFIG_PAX_MEMORY_UDEREF
22915+ call pax_enter_kernel_user
22916+#endif
22917+ .endm
22918+
22919+ .macro pax_exit_kernel_user
22920+#ifdef CONFIG_PAX_MEMORY_UDEREF
22921+ call pax_exit_kernel_user
22922+#endif
22923+#ifdef CONFIG_PAX_RANDKSTACK
22924+ pushq %rax
22925+ pushq %r11
22926+ call pax_randomize_kstack
22927+ popq %r11
22928+ popq %rax
22929+#endif
22930+ .endm
22931+
22932+#ifdef CONFIG_PAX_MEMORY_UDEREF
22933+ENTRY(pax_enter_kernel_user)
22934+ pushq %rdi
22935+ pushq %rbx
22936+
22937+#ifdef CONFIG_PARAVIRT
22938+ PV_SAVE_REGS(CLBR_RDI)
22939+#endif
22940+
22941+ 661: jmp 111f
22942+ .pushsection .altinstr_replacement, "a"
22943+ 662: ASM_NOP2
22944+ .popsection
22945+ .pushsection .altinstructions, "a"
22946+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22947+ .popsection
22948+ GET_CR3_INTO_RDI
22949+ cmp $1,%dil
22950+ jnz 4f
22951+ sub $4097,%rdi
22952+ bts $63,%rdi
22953+ SET_RDI_INTO_CR3
22954+ jmp 3f
22955+111:
22956+
22957+ GET_CR3_INTO_RDI
22958+ mov %rdi,%rbx
22959+ add $__START_KERNEL_map,%rbx
22960+ sub phys_base(%rip),%rbx
22961+
22962+#ifdef CONFIG_PARAVIRT
22963+ cmpl $0, pv_info+PARAVIRT_enabled
22964+ jz 1f
22965+ pushq %rdi
22966+ i = 0
22967+ .rept USER_PGD_PTRS
22968+ mov i*8(%rbx),%rsi
22969+ mov $0,%sil
22970+ lea i*8(%rbx),%rdi
22971+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22972+ i = i + 1
22973+ .endr
22974+ popq %rdi
22975+ jmp 2f
22976+1:
22977+#endif
22978+
22979+ i = 0
22980+ .rept USER_PGD_PTRS
22981+ movb $0,i*8(%rbx)
22982+ i = i + 1
22983+ .endr
22984+
22985+2: SET_RDI_INTO_CR3
22986+
22987+#ifdef CONFIG_PAX_KERNEXEC
22988+ GET_CR0_INTO_RDI
22989+ bts $16,%rdi
22990+ SET_RDI_INTO_CR0
22991+#endif
22992+
22993+3:
22994+
22995+#ifdef CONFIG_PARAVIRT
22996+ PV_RESTORE_REGS(CLBR_RDI)
22997+#endif
22998+
22999+ popq %rbx
23000+ popq %rdi
23001+ pax_force_retaddr
23002+ retq
23003+4: ud2
23004+ENDPROC(pax_enter_kernel_user)
23005+
23006+ENTRY(pax_exit_kernel_user)
23007+ pushq %rdi
23008+ pushq %rbx
23009+
23010+#ifdef CONFIG_PARAVIRT
23011+ PV_SAVE_REGS(CLBR_RDI)
23012+#endif
23013+
23014+ GET_CR3_INTO_RDI
23015+ 661: jmp 1f
23016+ .pushsection .altinstr_replacement, "a"
23017+ 662: ASM_NOP2
23018+ .popsection
23019+ .pushsection .altinstructions, "a"
23020+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23021+ .popsection
23022+ cmp $0,%dil
23023+ jnz 3f
23024+ add $4097,%rdi
23025+ bts $63,%rdi
23026+ SET_RDI_INTO_CR3
23027+ jmp 2f
23028+1:
23029+
23030+ mov %rdi,%rbx
23031+
23032+#ifdef CONFIG_PAX_KERNEXEC
23033+ GET_CR0_INTO_RDI
23034+ btr $16,%rdi
23035+ jnc 3f
23036+ SET_RDI_INTO_CR0
23037+#endif
23038+
23039+ add $__START_KERNEL_map,%rbx
23040+ sub phys_base(%rip),%rbx
23041+
23042+#ifdef CONFIG_PARAVIRT
23043+ cmpl $0, pv_info+PARAVIRT_enabled
23044+ jz 1f
23045+ i = 0
23046+ .rept USER_PGD_PTRS
23047+ mov i*8(%rbx),%rsi
23048+ mov $0x67,%sil
23049+ lea i*8(%rbx),%rdi
23050+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23051+ i = i + 1
23052+ .endr
23053+ jmp 2f
23054+1:
23055+#endif
23056+
23057+ i = 0
23058+ .rept USER_PGD_PTRS
23059+ movb $0x67,i*8(%rbx)
23060+ i = i + 1
23061+ .endr
23062+2:
23063+
23064+#ifdef CONFIG_PARAVIRT
23065+ PV_RESTORE_REGS(CLBR_RDI)
23066+#endif
23067+
23068+ popq %rbx
23069+ popq %rdi
23070+ pax_force_retaddr
23071+ retq
23072+3: ud2
23073+ENDPROC(pax_exit_kernel_user)
23074+#endif
23075+
23076+ .macro pax_enter_kernel_nmi
23077+ pax_set_fptr_mask
23078+
23079+#ifdef CONFIG_PAX_KERNEXEC
23080+ GET_CR0_INTO_RDI
23081+ bts $16,%rdi
23082+ jc 110f
23083+ SET_RDI_INTO_CR0
23084+ or $2,%ebx
23085+110:
23086+#endif
23087+
23088+#ifdef CONFIG_PAX_MEMORY_UDEREF
23089+ 661: jmp 111f
23090+ .pushsection .altinstr_replacement, "a"
23091+ 662: ASM_NOP2
23092+ .popsection
23093+ .pushsection .altinstructions, "a"
23094+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23095+ .popsection
23096+ GET_CR3_INTO_RDI
23097+ cmp $0,%dil
23098+ jz 111f
23099+ sub $4097,%rdi
23100+ or $4,%ebx
23101+ bts $63,%rdi
23102+ SET_RDI_INTO_CR3
23103+ mov $__UDEREF_KERNEL_DS,%edi
23104+ mov %edi,%ss
23105+111:
23106+#endif
23107+ .endm
23108+
23109+ .macro pax_exit_kernel_nmi
23110+#ifdef CONFIG_PAX_KERNEXEC
23111+ btr $1,%ebx
23112+ jnc 110f
23113+ GET_CR0_INTO_RDI
23114+ btr $16,%rdi
23115+ SET_RDI_INTO_CR0
23116+110:
23117+#endif
23118+
23119+#ifdef CONFIG_PAX_MEMORY_UDEREF
23120+ btr $2,%ebx
23121+ jnc 111f
23122+ GET_CR3_INTO_RDI
23123+ add $4097,%rdi
23124+ bts $63,%rdi
23125+ SET_RDI_INTO_CR3
23126+ mov $__KERNEL_DS,%edi
23127+ mov %edi,%ss
23128+111:
23129+#endif
23130+ .endm
23131+
23132+ .macro pax_erase_kstack
23133+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23134+ call pax_erase_kstack
23135+#endif
23136+ .endm
23137+
23138+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23139+ENTRY(pax_erase_kstack)
23140+ pushq %rdi
23141+ pushq %rcx
23142+ pushq %rax
23143+ pushq %r11
23144+
23145+ GET_THREAD_INFO(%r11)
23146+ mov TI_lowest_stack(%r11), %rdi
23147+ mov $-0xBEEF, %rax
23148+ std
23149+
23150+1: mov %edi, %ecx
23151+ and $THREAD_SIZE_asm - 1, %ecx
23152+ shr $3, %ecx
23153+ repne scasq
23154+ jecxz 2f
23155+
23156+ cmp $2*8, %ecx
23157+ jc 2f
23158+
23159+ mov $2*8, %ecx
23160+ repe scasq
23161+ jecxz 2f
23162+ jne 1b
23163+
23164+2: cld
23165+ mov %esp, %ecx
23166+ sub %edi, %ecx
23167+
23168+ cmp $THREAD_SIZE_asm, %rcx
23169+ jb 3f
23170+ ud2
23171+3:
23172+
23173+ shr $3, %ecx
23174+ rep stosq
23175+
23176+ mov TI_task_thread_sp0(%r11), %rdi
23177+ sub $256, %rdi
23178+ mov %rdi, TI_lowest_stack(%r11)
23179+
23180+ popq %r11
23181+ popq %rax
23182+ popq %rcx
23183+ popq %rdi
23184+ pax_force_retaddr
23185+ ret
23186+ENDPROC(pax_erase_kstack)
23187+#endif
23188
23189 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23190 #ifdef CONFIG_TRACE_IRQFLAGS
23191@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23192 .endm
23193
23194 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23195- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23196+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23197 jnc 1f
23198 TRACE_IRQS_ON_DEBUG
23199 1:
23200@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23201 movq \tmp,R11+\offset(%rsp)
23202 .endm
23203
23204- .macro FAKE_STACK_FRAME child_rip
23205- /* push in order ss, rsp, eflags, cs, rip */
23206- xorl %eax, %eax
23207- pushq_cfi $__KERNEL_DS /* ss */
23208- /*CFI_REL_OFFSET ss,0*/
23209- pushq_cfi %rax /* rsp */
23210- CFI_REL_OFFSET rsp,0
23211- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23212- /*CFI_REL_OFFSET rflags,0*/
23213- pushq_cfi $__KERNEL_CS /* cs */
23214- /*CFI_REL_OFFSET cs,0*/
23215- pushq_cfi \child_rip /* rip */
23216- CFI_REL_OFFSET rip,0
23217- pushq_cfi %rax /* orig rax */
23218- .endm
23219-
23220- .macro UNFAKE_STACK_FRAME
23221- addq $8*6, %rsp
23222- CFI_ADJUST_CFA_OFFSET -(6*8)
23223- .endm
23224-
23225 /*
23226 * initial frame state for interrupts (and exceptions without error code)
23227 */
23228@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23229 /* save partial stack frame */
23230 .macro SAVE_ARGS_IRQ
23231 cld
23232- /* start from rbp in pt_regs and jump over */
23233- movq_cfi rdi, (RDI-RBP)
23234- movq_cfi rsi, (RSI-RBP)
23235- movq_cfi rdx, (RDX-RBP)
23236- movq_cfi rcx, (RCX-RBP)
23237- movq_cfi rax, (RAX-RBP)
23238- movq_cfi r8, (R8-RBP)
23239- movq_cfi r9, (R9-RBP)
23240- movq_cfi r10, (R10-RBP)
23241- movq_cfi r11, (R11-RBP)
23242+ /* start from r15 in pt_regs and jump over */
23243+ movq_cfi rdi, RDI
23244+ movq_cfi rsi, RSI
23245+ movq_cfi rdx, RDX
23246+ movq_cfi rcx, RCX
23247+ movq_cfi rax, RAX
23248+ movq_cfi r8, R8
23249+ movq_cfi r9, R9
23250+ movq_cfi r10, R10
23251+ movq_cfi r11, R11
23252+ movq_cfi r12, R12
23253
23254 /* Save rbp so that we can unwind from get_irq_regs() */
23255- movq_cfi rbp, 0
23256+ movq_cfi rbp, RBP
23257
23258 /* Save previous stack value */
23259 movq %rsp, %rsi
23260
23261- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23262- testl $3, CS-RBP(%rsi)
23263+ movq %rsp,%rdi /* arg1 for handler */
23264+ testb $3, CS(%rsi)
23265 je 1f
23266 SWAPGS
23267 /*
23268@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23269 0x06 /* DW_OP_deref */, \
23270 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23271 0x22 /* DW_OP_plus */
23272+
23273+#ifdef CONFIG_PAX_MEMORY_UDEREF
23274+ testb $3, CS(%rdi)
23275+ jnz 1f
23276+ pax_enter_kernel
23277+ jmp 2f
23278+1: pax_enter_kernel_user
23279+2:
23280+#else
23281+ pax_enter_kernel
23282+#endif
23283+
23284 /* We entered an interrupt context - irqs are off: */
23285 TRACE_IRQS_OFF
23286 .endm
23287@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23288 js 1f /* negative -> in kernel */
23289 SWAPGS
23290 xorl %ebx,%ebx
23291-1: ret
23292+1:
23293+#ifdef CONFIG_PAX_MEMORY_UDEREF
23294+ testb $3, CS+8(%rsp)
23295+ jnz 1f
23296+ pax_enter_kernel
23297+ jmp 2f
23298+1: pax_enter_kernel_user
23299+2:
23300+#else
23301+ pax_enter_kernel
23302+#endif
23303+ pax_force_retaddr
23304+ ret
23305 CFI_ENDPROC
23306-END(save_paranoid)
23307+ENDPROC(save_paranoid)
23308+
23309+ENTRY(save_paranoid_nmi)
23310+ XCPT_FRAME 1 RDI+8
23311+ cld
23312+ movq_cfi rdi, RDI+8
23313+ movq_cfi rsi, RSI+8
23314+ movq_cfi rdx, RDX+8
23315+ movq_cfi rcx, RCX+8
23316+ movq_cfi rax, RAX+8
23317+ movq_cfi r8, R8+8
23318+ movq_cfi r9, R9+8
23319+ movq_cfi r10, R10+8
23320+ movq_cfi r11, R11+8
23321+ movq_cfi rbx, RBX+8
23322+ movq_cfi rbp, RBP+8
23323+ movq_cfi r12, R12+8
23324+ movq_cfi r13, R13+8
23325+ movq_cfi r14, R14+8
23326+ movq_cfi r15, R15+8
23327+ movl $1,%ebx
23328+ movl $MSR_GS_BASE,%ecx
23329+ rdmsr
23330+ testl %edx,%edx
23331+ js 1f /* negative -> in kernel */
23332+ SWAPGS
23333+ xorl %ebx,%ebx
23334+1: pax_enter_kernel_nmi
23335+ pax_force_retaddr
23336+ ret
23337+ CFI_ENDPROC
23338+ENDPROC(save_paranoid_nmi)
23339 .popsection
23340
23341 /*
23342@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23343
23344 RESTORE_REST
23345
23346- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23347+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23348 jz 1f
23349
23350 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23351@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23352 jmp ret_from_sys_call # go to the SYSRET fastpath
23353
23354 1:
23355- subq $REST_SKIP, %rsp # leave space for volatiles
23356- CFI_ADJUST_CFA_OFFSET REST_SKIP
23357 movq %rbp, %rdi
23358 call *%rbx
23359 movl $0, RAX(%rsp)
23360 RESTORE_REST
23361 jmp int_ret_from_sys_call
23362 CFI_ENDPROC
23363-END(ret_from_fork)
23364+ENDPROC(ret_from_fork)
23365
23366 /*
23367 * System call entry. Up to 6 arguments in registers are supported.
23368@@ -593,7 +1059,7 @@ END(ret_from_fork)
23369 ENTRY(system_call)
23370 CFI_STARTPROC simple
23371 CFI_SIGNAL_FRAME
23372- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23373+ CFI_DEF_CFA rsp,0
23374 CFI_REGISTER rip,rcx
23375 /*CFI_REGISTER rflags,r11*/
23376 SWAPGS_UNSAFE_STACK
23377@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23378
23379 movq %rsp,PER_CPU_VAR(old_rsp)
23380 movq PER_CPU_VAR(kernel_stack),%rsp
23381+ SAVE_ARGS 8*6,0
23382+ pax_enter_kernel_user
23383+
23384+#ifdef CONFIG_PAX_RANDKSTACK
23385+ pax_erase_kstack
23386+#endif
23387+
23388 /*
23389 * No need to follow this irqs off/on section - it's straight
23390 * and short:
23391 */
23392 ENABLE_INTERRUPTS(CLBR_NONE)
23393- SAVE_ARGS 8,0
23394 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23395 movq %rcx,RIP-ARGOFFSET(%rsp)
23396 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23397- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23398+ GET_THREAD_INFO(%rcx)
23399+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23400 jnz tracesys
23401 system_call_fastpath:
23402 #if __SYSCALL_MASK == ~0
23403@@ -639,10 +1112,13 @@ sysret_check:
23404 LOCKDEP_SYS_EXIT
23405 DISABLE_INTERRUPTS(CLBR_NONE)
23406 TRACE_IRQS_OFF
23407- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23408+ GET_THREAD_INFO(%rcx)
23409+ movl TI_flags(%rcx),%edx
23410 andl %edi,%edx
23411 jnz sysret_careful
23412 CFI_REMEMBER_STATE
23413+ pax_exit_kernel_user
23414+ pax_erase_kstack
23415 /*
23416 * sysretq will re-enable interrupts:
23417 */
23418@@ -701,6 +1177,9 @@ auditsys:
23419 movq %rax,%rsi /* 2nd arg: syscall number */
23420 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23421 call __audit_syscall_entry
23422+
23423+ pax_erase_kstack
23424+
23425 LOAD_ARGS 0 /* reload call-clobbered registers */
23426 jmp system_call_fastpath
23427
23428@@ -722,7 +1201,7 @@ sysret_audit:
23429 /* Do syscall tracing */
23430 tracesys:
23431 #ifdef CONFIG_AUDITSYSCALL
23432- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23433+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23434 jz auditsys
23435 #endif
23436 SAVE_REST
23437@@ -730,12 +1209,15 @@ tracesys:
23438 FIXUP_TOP_OF_STACK %rdi
23439 movq %rsp,%rdi
23440 call syscall_trace_enter
23441+
23442+ pax_erase_kstack
23443+
23444 /*
23445 * Reload arg registers from stack in case ptrace changed them.
23446 * We don't reload %rax because syscall_trace_enter() returned
23447 * the value it wants us to use in the table lookup.
23448 */
23449- LOAD_ARGS ARGOFFSET, 1
23450+ LOAD_ARGS 1
23451 RESTORE_REST
23452 #if __SYSCALL_MASK == ~0
23453 cmpq $__NR_syscall_max,%rax
23454@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23455 andl %edi,%edx
23456 jnz int_careful
23457 andl $~TS_COMPAT,TI_status(%rcx)
23458- jmp retint_swapgs
23459+ pax_exit_kernel_user
23460+ pax_erase_kstack
23461+ jmp retint_swapgs_pax
23462
23463 /* Either reschedule or signal or syscall exit tracking needed. */
23464 /* First do a reschedule test. */
23465@@ -811,7 +1295,7 @@ int_restore_rest:
23466 TRACE_IRQS_OFF
23467 jmp int_with_check
23468 CFI_ENDPROC
23469-END(system_call)
23470+ENDPROC(system_call)
23471
23472 .macro FORK_LIKE func
23473 ENTRY(stub_\func)
23474@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23475 DEFAULT_FRAME 0 8 /* offset 8: return address */
23476 call sys_\func
23477 RESTORE_TOP_OF_STACK %r11, 8
23478- ret $REST_SKIP /* pop extended registers */
23479+ pax_force_retaddr
23480+ ret
23481 CFI_ENDPROC
23482-END(stub_\func)
23483+ENDPROC(stub_\func)
23484 .endm
23485
23486 .macro FIXED_FRAME label,func
23487@@ -836,9 +1321,10 @@ ENTRY(\label)
23488 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23489 call \func
23490 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23491+ pax_force_retaddr
23492 ret
23493 CFI_ENDPROC
23494-END(\label)
23495+ENDPROC(\label)
23496 .endm
23497
23498 FORK_LIKE clone
23499@@ -846,19 +1332,6 @@ END(\label)
23500 FORK_LIKE vfork
23501 FIXED_FRAME stub_iopl, sys_iopl
23502
23503-ENTRY(ptregscall_common)
23504- DEFAULT_FRAME 1 8 /* offset 8: return address */
23505- RESTORE_TOP_OF_STACK %r11, 8
23506- movq_cfi_restore R15+8, r15
23507- movq_cfi_restore R14+8, r14
23508- movq_cfi_restore R13+8, r13
23509- movq_cfi_restore R12+8, r12
23510- movq_cfi_restore RBP+8, rbp
23511- movq_cfi_restore RBX+8, rbx
23512- ret $REST_SKIP /* pop extended registers */
23513- CFI_ENDPROC
23514-END(ptregscall_common)
23515-
23516 ENTRY(stub_execve)
23517 CFI_STARTPROC
23518 addq $8, %rsp
23519@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23520 RESTORE_REST
23521 jmp int_ret_from_sys_call
23522 CFI_ENDPROC
23523-END(stub_execve)
23524+ENDPROC(stub_execve)
23525
23526 /*
23527 * sigreturn is special because it needs to restore all registers on return.
23528@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23529 RESTORE_REST
23530 jmp int_ret_from_sys_call
23531 CFI_ENDPROC
23532-END(stub_rt_sigreturn)
23533+ENDPROC(stub_rt_sigreturn)
23534
23535 #ifdef CONFIG_X86_X32_ABI
23536 ENTRY(stub_x32_rt_sigreturn)
23537@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23538 RESTORE_REST
23539 jmp int_ret_from_sys_call
23540 CFI_ENDPROC
23541-END(stub_x32_rt_sigreturn)
23542+ENDPROC(stub_x32_rt_sigreturn)
23543
23544 ENTRY(stub_x32_execve)
23545 CFI_STARTPROC
23546@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23547 RESTORE_REST
23548 jmp int_ret_from_sys_call
23549 CFI_ENDPROC
23550-END(stub_x32_execve)
23551+ENDPROC(stub_x32_execve)
23552
23553 #endif
23554
23555@@ -952,7 +1425,7 @@ vector=vector+1
23556 2: jmp common_interrupt
23557 .endr
23558 CFI_ENDPROC
23559-END(irq_entries_start)
23560+ENDPROC(irq_entries_start)
23561
23562 .previous
23563 END(interrupt)
23564@@ -969,8 +1442,8 @@ END(interrupt)
23565 /* 0(%rsp): ~(interrupt number) */
23566 .macro interrupt func
23567 /* reserve pt_regs for scratch regs and rbp */
23568- subq $ORIG_RAX-RBP, %rsp
23569- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23570+ subq $ORIG_RAX, %rsp
23571+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23572 SAVE_ARGS_IRQ
23573 call \func
23574 .endm
23575@@ -997,14 +1470,14 @@ ret_from_intr:
23576
23577 /* Restore saved previous stack */
23578 popq %rsi
23579- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23580- leaq ARGOFFSET-RBP(%rsi), %rsp
23581+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23582+ movq %rsi, %rsp
23583 CFI_DEF_CFA_REGISTER rsp
23584- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23585+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23586
23587 exit_intr:
23588 GET_THREAD_INFO(%rcx)
23589- testl $3,CS-ARGOFFSET(%rsp)
23590+ testb $3,CS-ARGOFFSET(%rsp)
23591 je retint_kernel
23592
23593 /* Interrupt came from user space */
23594@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23595 * The iretq could re-enable interrupts:
23596 */
23597 DISABLE_INTERRUPTS(CLBR_ANY)
23598+ pax_exit_kernel_user
23599+retint_swapgs_pax:
23600 TRACE_IRQS_IRETQ
23601 SWAPGS
23602 jmp restore_args
23603
23604 retint_restore_args: /* return to kernel space */
23605 DISABLE_INTERRUPTS(CLBR_ANY)
23606+ pax_exit_kernel
23607+ pax_force_retaddr (RIP-ARGOFFSET)
23608 /*
23609 * The iretq could re-enable interrupts:
23610 */
23611@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23612 #endif
23613
23614 CFI_ENDPROC
23615-END(common_interrupt)
23616+ENDPROC(common_interrupt)
23617 /*
23618 * End of kprobes section
23619 */
23620@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23621 interrupt \do_sym
23622 jmp ret_from_intr
23623 CFI_ENDPROC
23624-END(\sym)
23625+ENDPROC(\sym)
23626 .endm
23627
23628 #ifdef CONFIG_TRACING
23629@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23630 call \do_sym
23631 jmp error_exit /* %ebx: no swapgs flag */
23632 CFI_ENDPROC
23633-END(\sym)
23634+ENDPROC(\sym)
23635 .endm
23636
23637 .macro paranoidzeroentry sym do_sym
23638@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23639 call \do_sym
23640 jmp paranoid_exit /* %ebx: no swapgs flag */
23641 CFI_ENDPROC
23642-END(\sym)
23643+ENDPROC(\sym)
23644 .endm
23645
23646-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23647+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23648 .macro paranoidzeroentry_ist sym do_sym ist
23649 ENTRY(\sym)
23650 INTR_FRAME
23651@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23652 TRACE_IRQS_OFF_DEBUG
23653 movq %rsp,%rdi /* pt_regs pointer */
23654 xorl %esi,%esi /* no error code */
23655+#ifdef CONFIG_SMP
23656+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23657+ lea init_tss(%r13), %r13
23658+#else
23659+ lea init_tss(%rip), %r13
23660+#endif
23661 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23662 call \do_sym
23663 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23664 jmp paranoid_exit /* %ebx: no swapgs flag */
23665 CFI_ENDPROC
23666-END(\sym)
23667+ENDPROC(\sym)
23668 .endm
23669
23670 .macro errorentry sym do_sym
23671@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23672 call \do_sym
23673 jmp error_exit /* %ebx: no swapgs flag */
23674 CFI_ENDPROC
23675-END(\sym)
23676+ENDPROC(\sym)
23677 .endm
23678
23679 #ifdef CONFIG_TRACING
23680@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23681 call \do_sym
23682 jmp paranoid_exit /* %ebx: no swapgs flag */
23683 CFI_ENDPROC
23684-END(\sym)
23685+ENDPROC(\sym)
23686 .endm
23687
23688 zeroentry divide_error do_divide_error
23689@@ -1336,9 +1819,10 @@ gs_change:
23690 2: mfence /* workaround */
23691 SWAPGS
23692 popfq_cfi
23693+ pax_force_retaddr
23694 ret
23695 CFI_ENDPROC
23696-END(native_load_gs_index)
23697+ENDPROC(native_load_gs_index)
23698
23699 _ASM_EXTABLE(gs_change,bad_gs)
23700 .section .fixup,"ax"
23701@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23702 CFI_DEF_CFA_REGISTER rsp
23703 CFI_ADJUST_CFA_OFFSET -8
23704 decl PER_CPU_VAR(irq_count)
23705+ pax_force_retaddr
23706 ret
23707 CFI_ENDPROC
23708-END(do_softirq_own_stack)
23709+ENDPROC(do_softirq_own_stack)
23710
23711 #ifdef CONFIG_XEN
23712 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23713@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23714 decl PER_CPU_VAR(irq_count)
23715 jmp error_exit
23716 CFI_ENDPROC
23717-END(xen_do_hypervisor_callback)
23718+ENDPROC(xen_do_hypervisor_callback)
23719
23720 /*
23721 * Hypervisor uses this for application faults while it executes.
23722@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23723 SAVE_ALL
23724 jmp error_exit
23725 CFI_ENDPROC
23726-END(xen_failsafe_callback)
23727+ENDPROC(xen_failsafe_callback)
23728
23729 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23730 xen_hvm_callback_vector xen_evtchn_do_upcall
23731@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23732 DEFAULT_FRAME
23733 DISABLE_INTERRUPTS(CLBR_NONE)
23734 TRACE_IRQS_OFF_DEBUG
23735- testl %ebx,%ebx /* swapgs needed? */
23736+ testl $1,%ebx /* swapgs needed? */
23737 jnz paranoid_restore
23738- testl $3,CS(%rsp)
23739+ testb $3,CS(%rsp)
23740 jnz paranoid_userspace
23741+#ifdef CONFIG_PAX_MEMORY_UDEREF
23742+ pax_exit_kernel
23743+ TRACE_IRQS_IRETQ 0
23744+ SWAPGS_UNSAFE_STACK
23745+ RESTORE_ALL 8
23746+ pax_force_retaddr_bts
23747+ jmp irq_return
23748+#endif
23749 paranoid_swapgs:
23750+#ifdef CONFIG_PAX_MEMORY_UDEREF
23751+ pax_exit_kernel_user
23752+#else
23753+ pax_exit_kernel
23754+#endif
23755 TRACE_IRQS_IRETQ 0
23756 SWAPGS_UNSAFE_STACK
23757 RESTORE_ALL 8
23758 jmp irq_return
23759 paranoid_restore:
23760+ pax_exit_kernel
23761 TRACE_IRQS_IRETQ_DEBUG 0
23762 RESTORE_ALL 8
23763+ pax_force_retaddr_bts
23764 jmp irq_return
23765 paranoid_userspace:
23766 GET_THREAD_INFO(%rcx)
23767@@ -1557,7 +2057,7 @@ paranoid_schedule:
23768 TRACE_IRQS_OFF
23769 jmp paranoid_userspace
23770 CFI_ENDPROC
23771-END(paranoid_exit)
23772+ENDPROC(paranoid_exit)
23773
23774 /*
23775 * Exception entry point. This expects an error code/orig_rax on the stack.
23776@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23777 movq_cfi r14, R14+8
23778 movq_cfi r15, R15+8
23779 xorl %ebx,%ebx
23780- testl $3,CS+8(%rsp)
23781+ testb $3,CS+8(%rsp)
23782 je error_kernelspace
23783 error_swapgs:
23784 SWAPGS
23785 error_sti:
23786+#ifdef CONFIG_PAX_MEMORY_UDEREF
23787+ testb $3, CS+8(%rsp)
23788+ jnz 1f
23789+ pax_enter_kernel
23790+ jmp 2f
23791+1: pax_enter_kernel_user
23792+2:
23793+#else
23794+ pax_enter_kernel
23795+#endif
23796 TRACE_IRQS_OFF
23797+ pax_force_retaddr
23798 ret
23799
23800 /*
23801@@ -1616,7 +2127,7 @@ bstep_iret:
23802 movq %rcx,RIP+8(%rsp)
23803 jmp error_swapgs
23804 CFI_ENDPROC
23805-END(error_entry)
23806+ENDPROC(error_entry)
23807
23808
23809 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23810@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23811 DISABLE_INTERRUPTS(CLBR_NONE)
23812 TRACE_IRQS_OFF
23813 GET_THREAD_INFO(%rcx)
23814- testl %eax,%eax
23815+ testl $1,%eax
23816 jne retint_kernel
23817 LOCKDEP_SYS_EXIT_IRQ
23818 movl TI_flags(%rcx),%edx
23819@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23820 jnz retint_careful
23821 jmp retint_swapgs
23822 CFI_ENDPROC
23823-END(error_exit)
23824+ENDPROC(error_exit)
23825
23826 /*
23827 * Test if a given stack is an NMI stack or not.
23828@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23829 * If %cs was not the kernel segment, then the NMI triggered in user
23830 * space, which means it is definitely not nested.
23831 */
23832+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23833+ je 1f
23834 cmpl $__KERNEL_CS, 16(%rsp)
23835 jne first_nmi
23836-
23837+1:
23838 /*
23839 * Check the special variable on the stack to see if NMIs are
23840 * executing.
23841@@ -1730,8 +2243,7 @@ nested_nmi:
23842
23843 1:
23844 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23845- leaq -1*8(%rsp), %rdx
23846- movq %rdx, %rsp
23847+ subq $8, %rsp
23848 CFI_ADJUST_CFA_OFFSET 1*8
23849 leaq -10*8(%rsp), %rdx
23850 pushq_cfi $__KERNEL_DS
23851@@ -1749,6 +2261,7 @@ nested_nmi_out:
23852 CFI_RESTORE rdx
23853
23854 /* No need to check faults here */
23855+# pax_force_retaddr_bts
23856 INTERRUPT_RETURN
23857
23858 CFI_RESTORE_STATE
23859@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23860 subq $ORIG_RAX-R15, %rsp
23861 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23862 /*
23863- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23864+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23865 * as we should not be calling schedule in NMI context.
23866 * Even with normal interrupts enabled. An NMI should not be
23867 * setting NEED_RESCHED or anything that normal interrupts and
23868 * exceptions might do.
23869 */
23870- call save_paranoid
23871+ call save_paranoid_nmi
23872 DEFAULT_FRAME 0
23873
23874 /*
23875@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23876 * NMI itself takes a page fault, the page fault that was preempted
23877 * will read the information from the NMI page fault and not the
23878 * origin fault. Save it off and restore it if it changes.
23879- * Use the r12 callee-saved register.
23880+ * Use the r13 callee-saved register.
23881 */
23882- movq %cr2, %r12
23883+ movq %cr2, %r13
23884
23885 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23886 movq %rsp,%rdi
23887@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23888
23889 /* Did the NMI take a page fault? Restore cr2 if it did */
23890 movq %cr2, %rcx
23891- cmpq %rcx, %r12
23892+ cmpq %rcx, %r13
23893 je 1f
23894- movq %r12, %cr2
23895+ movq %r13, %cr2
23896 1:
23897
23898- testl %ebx,%ebx /* swapgs needed? */
23899+ testl $1,%ebx /* swapgs needed? */
23900 jnz nmi_restore
23901 nmi_swapgs:
23902 SWAPGS_UNSAFE_STACK
23903 nmi_restore:
23904+ pax_exit_kernel_nmi
23905 /* Pop the extra iret frame at once */
23906 RESTORE_ALL 6*8
23907+ testb $3, 8(%rsp)
23908+ jnz 1f
23909+ pax_force_retaddr_bts
23910+1:
23911
23912 /* Clear the NMI executing stack variable */
23913 movq $0, 5*8(%rsp)
23914 jmp irq_return
23915 CFI_ENDPROC
23916-END(nmi)
23917+ENDPROC(nmi)
23918
23919 ENTRY(ignore_sysret)
23920 CFI_STARTPROC
23921 mov $-ENOSYS,%eax
23922 sysret
23923 CFI_ENDPROC
23924-END(ignore_sysret)
23925+ENDPROC(ignore_sysret)
23926
23927 /*
23928 * End of kprobes section
23929diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23930index 1ffc32d..e52c745 100644
23931--- a/arch/x86/kernel/ftrace.c
23932+++ b/arch/x86/kernel/ftrace.c
23933@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23934 {
23935 unsigned char replaced[MCOUNT_INSN_SIZE];
23936
23937+ ip = ktla_ktva(ip);
23938+
23939 /*
23940 * Note: Due to modules and __init, code can
23941 * disappear and change, we need to protect against faulting
23942@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23943 unsigned char old[MCOUNT_INSN_SIZE];
23944 int ret;
23945
23946- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23947+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23948
23949 ftrace_update_func = ip;
23950 /* Make sure the breakpoints see the ftrace_update_func update */
23951@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23952 * kernel identity mapping to modify code.
23953 */
23954 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23955- ip = (unsigned long)__va(__pa_symbol(ip));
23956+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23957
23958 return probe_kernel_write((void *)ip, val, size);
23959 }
23960@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23961 unsigned char replaced[MCOUNT_INSN_SIZE];
23962 unsigned char brk = BREAKPOINT_INSTRUCTION;
23963
23964- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23965+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23966 return -EFAULT;
23967
23968 /* Make sure it is what we expect it to be */
23969@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23970 return ret;
23971
23972 fail_update:
23973- probe_kernel_write((void *)ip, &old_code[0], 1);
23974+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23975 goto out;
23976 }
23977
23978diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23979index 85126cc..1bbce17 100644
23980--- a/arch/x86/kernel/head64.c
23981+++ b/arch/x86/kernel/head64.c
23982@@ -67,12 +67,12 @@ again:
23983 pgd = *pgd_p;
23984
23985 /*
23986- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23987- * critical -- __PAGE_OFFSET would point us back into the dynamic
23988+ * The use of __early_va rather than __va here is critical:
23989+ * __va would point us back into the dynamic
23990 * range and we might end up looping forever...
23991 */
23992 if (pgd)
23993- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23994+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23995 else {
23996 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23997 reset_early_page_tables();
23998@@ -82,13 +82,13 @@ again:
23999 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24000 for (i = 0; i < PTRS_PER_PUD; i++)
24001 pud_p[i] = 0;
24002- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24003+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24004 }
24005 pud_p += pud_index(address);
24006 pud = *pud_p;
24007
24008 if (pud)
24009- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24010+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24011 else {
24012 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24013 reset_early_page_tables();
24014@@ -98,7 +98,7 @@ again:
24015 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24016 for (i = 0; i < PTRS_PER_PMD; i++)
24017 pmd_p[i] = 0;
24018- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24019+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24020 }
24021 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24022 pmd_p[pmd_index(address)] = pmd;
24023@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24024 if (console_loglevel == 10)
24025 early_printk("Kernel alive\n");
24026
24027- clear_page(init_level4_pgt);
24028 /* set init_level4_pgt kernel high mapping*/
24029 init_level4_pgt[511] = early_level4_pgt[511];
24030
24031diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24032index f36bd42..56ee1534 100644
24033--- a/arch/x86/kernel/head_32.S
24034+++ b/arch/x86/kernel/head_32.S
24035@@ -26,6 +26,12 @@
24036 /* Physical address */
24037 #define pa(X) ((X) - __PAGE_OFFSET)
24038
24039+#ifdef CONFIG_PAX_KERNEXEC
24040+#define ta(X) (X)
24041+#else
24042+#define ta(X) ((X) - __PAGE_OFFSET)
24043+#endif
24044+
24045 /*
24046 * References to members of the new_cpu_data structure.
24047 */
24048@@ -55,11 +61,7 @@
24049 * and small than max_low_pfn, otherwise will waste some page table entries
24050 */
24051
24052-#if PTRS_PER_PMD > 1
24053-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24054-#else
24055-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24056-#endif
24057+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24058
24059 /* Number of possible pages in the lowmem region */
24060 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24061@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24062 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24063
24064 /*
24065+ * Real beginning of normal "text" segment
24066+ */
24067+ENTRY(stext)
24068+ENTRY(_stext)
24069+
24070+/*
24071 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24072 * %esi points to the real-mode code as a 32-bit pointer.
24073 * CS and DS must be 4 GB flat segments, but we don't depend on
24074@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24075 * can.
24076 */
24077 __HEAD
24078+
24079+#ifdef CONFIG_PAX_KERNEXEC
24080+ jmp startup_32
24081+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24082+.fill PAGE_SIZE-5,1,0xcc
24083+#endif
24084+
24085 ENTRY(startup_32)
24086 movl pa(stack_start),%ecx
24087
24088@@ -106,6 +121,59 @@ ENTRY(startup_32)
24089 2:
24090 leal -__PAGE_OFFSET(%ecx),%esp
24091
24092+#ifdef CONFIG_SMP
24093+ movl $pa(cpu_gdt_table),%edi
24094+ movl $__per_cpu_load,%eax
24095+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24096+ rorl $16,%eax
24097+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24098+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24099+ movl $__per_cpu_end - 1,%eax
24100+ subl $__per_cpu_start,%eax
24101+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24102+#endif
24103+
24104+#ifdef CONFIG_PAX_MEMORY_UDEREF
24105+ movl $NR_CPUS,%ecx
24106+ movl $pa(cpu_gdt_table),%edi
24107+1:
24108+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24109+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24110+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24111+ addl $PAGE_SIZE_asm,%edi
24112+ loop 1b
24113+#endif
24114+
24115+#ifdef CONFIG_PAX_KERNEXEC
24116+ movl $pa(boot_gdt),%edi
24117+ movl $__LOAD_PHYSICAL_ADDR,%eax
24118+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24119+ rorl $16,%eax
24120+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24121+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24122+ rorl $16,%eax
24123+
24124+ ljmp $(__BOOT_CS),$1f
24125+1:
24126+
24127+ movl $NR_CPUS,%ecx
24128+ movl $pa(cpu_gdt_table),%edi
24129+ addl $__PAGE_OFFSET,%eax
24130+1:
24131+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24132+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24133+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24134+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24135+ rorl $16,%eax
24136+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24137+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24138+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24139+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24140+ rorl $16,%eax
24141+ addl $PAGE_SIZE_asm,%edi
24142+ loop 1b
24143+#endif
24144+
24145 /*
24146 * Clear BSS first so that there are no surprises...
24147 */
24148@@ -201,8 +269,11 @@ ENTRY(startup_32)
24149 movl %eax, pa(max_pfn_mapped)
24150
24151 /* Do early initialization of the fixmap area */
24152- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24153- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24154+#ifdef CONFIG_COMPAT_VDSO
24155+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24156+#else
24157+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24158+#endif
24159 #else /* Not PAE */
24160
24161 page_pde_offset = (__PAGE_OFFSET >> 20);
24162@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24163 movl %eax, pa(max_pfn_mapped)
24164
24165 /* Do early initialization of the fixmap area */
24166- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24167- movl %eax,pa(initial_page_table+0xffc)
24168+#ifdef CONFIG_COMPAT_VDSO
24169+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24170+#else
24171+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24172+#endif
24173 #endif
24174
24175 #ifdef CONFIG_PARAVIRT
24176@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24177 cmpl $num_subarch_entries, %eax
24178 jae bad_subarch
24179
24180- movl pa(subarch_entries)(,%eax,4), %eax
24181- subl $__PAGE_OFFSET, %eax
24182- jmp *%eax
24183+ jmp *pa(subarch_entries)(,%eax,4)
24184
24185 bad_subarch:
24186 WEAK(lguest_entry)
24187@@ -261,10 +333,10 @@ WEAK(xen_entry)
24188 __INITDATA
24189
24190 subarch_entries:
24191- .long default_entry /* normal x86/PC */
24192- .long lguest_entry /* lguest hypervisor */
24193- .long xen_entry /* Xen hypervisor */
24194- .long default_entry /* Moorestown MID */
24195+ .long ta(default_entry) /* normal x86/PC */
24196+ .long ta(lguest_entry) /* lguest hypervisor */
24197+ .long ta(xen_entry) /* Xen hypervisor */
24198+ .long ta(default_entry) /* Moorestown MID */
24199 num_subarch_entries = (. - subarch_entries) / 4
24200 .previous
24201 #else
24202@@ -354,6 +426,7 @@ default_entry:
24203 movl pa(mmu_cr4_features),%eax
24204 movl %eax,%cr4
24205
24206+#ifdef CONFIG_X86_PAE
24207 testb $X86_CR4_PAE, %al # check if PAE is enabled
24208 jz enable_paging
24209
24210@@ -382,6 +455,9 @@ default_entry:
24211 /* Make changes effective */
24212 wrmsr
24213
24214+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24215+#endif
24216+
24217 enable_paging:
24218
24219 /*
24220@@ -449,14 +525,20 @@ is486:
24221 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24222 movl %eax,%ss # after changing gdt.
24223
24224- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24225+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24226 movl %eax,%ds
24227 movl %eax,%es
24228
24229 movl $(__KERNEL_PERCPU), %eax
24230 movl %eax,%fs # set this cpu's percpu
24231
24232+#ifdef CONFIG_CC_STACKPROTECTOR
24233 movl $(__KERNEL_STACK_CANARY),%eax
24234+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24235+ movl $(__USER_DS),%eax
24236+#else
24237+ xorl %eax,%eax
24238+#endif
24239 movl %eax,%gs
24240
24241 xorl %eax,%eax # Clear LDT
24242@@ -512,8 +594,11 @@ setup_once:
24243 * relocation. Manually set base address in stack canary
24244 * segment descriptor.
24245 */
24246- movl $gdt_page,%eax
24247+ movl $cpu_gdt_table,%eax
24248 movl $stack_canary,%ecx
24249+#ifdef CONFIG_SMP
24250+ addl $__per_cpu_load,%ecx
24251+#endif
24252 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24253 shrl $16, %ecx
24254 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24255@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24256 cmpl $2,(%esp) # X86_TRAP_NMI
24257 je is_nmi # Ignore NMI
24258
24259- cmpl $2,%ss:early_recursion_flag
24260+ cmpl $1,%ss:early_recursion_flag
24261 je hlt_loop
24262 incl %ss:early_recursion_flag
24263
24264@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24265 pushl (20+6*4)(%esp) /* trapno */
24266 pushl $fault_msg
24267 call printk
24268-#endif
24269 call dump_stack
24270+#endif
24271 hlt_loop:
24272 hlt
24273 jmp hlt_loop
24274@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24275 /* This is the default interrupt "handler" :-) */
24276 ALIGN
24277 ignore_int:
24278- cld
24279 #ifdef CONFIG_PRINTK
24280+ cmpl $2,%ss:early_recursion_flag
24281+ je hlt_loop
24282+ incl %ss:early_recursion_flag
24283+ cld
24284 pushl %eax
24285 pushl %ecx
24286 pushl %edx
24287@@ -617,9 +705,6 @@ ignore_int:
24288 movl $(__KERNEL_DS),%eax
24289 movl %eax,%ds
24290 movl %eax,%es
24291- cmpl $2,early_recursion_flag
24292- je hlt_loop
24293- incl early_recursion_flag
24294 pushl 16(%esp)
24295 pushl 24(%esp)
24296 pushl 32(%esp)
24297@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24298 /*
24299 * BSS section
24300 */
24301-__PAGE_ALIGNED_BSS
24302- .align PAGE_SIZE
24303 #ifdef CONFIG_X86_PAE
24304+.section .initial_pg_pmd,"a",@progbits
24305 initial_pg_pmd:
24306 .fill 1024*KPMDS,4,0
24307 #else
24308+.section .initial_page_table,"a",@progbits
24309 ENTRY(initial_page_table)
24310 .fill 1024,4,0
24311 #endif
24312+.section .initial_pg_fixmap,"a",@progbits
24313 initial_pg_fixmap:
24314 .fill 1024,4,0
24315+.section .empty_zero_page,"a",@progbits
24316 ENTRY(empty_zero_page)
24317 .fill 4096,1,0
24318+.section .swapper_pg_dir,"a",@progbits
24319 ENTRY(swapper_pg_dir)
24320+#ifdef CONFIG_X86_PAE
24321+ .fill 4,8,0
24322+#else
24323 .fill 1024,4,0
24324+#endif
24325
24326 /*
24327 * This starts the data section.
24328 */
24329 #ifdef CONFIG_X86_PAE
24330-__PAGE_ALIGNED_DATA
24331- /* Page-aligned for the benefit of paravirt? */
24332- .align PAGE_SIZE
24333+.section .initial_page_table,"a",@progbits
24334 ENTRY(initial_page_table)
24335 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24336 # if KPMDS == 3
24337@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24338 # error "Kernel PMDs should be 1, 2 or 3"
24339 # endif
24340 .align PAGE_SIZE /* needs to be page-sized too */
24341+
24342+#ifdef CONFIG_PAX_PER_CPU_PGD
24343+ENTRY(cpu_pgd)
24344+ .rept 2*NR_CPUS
24345+ .fill 4,8,0
24346+ .endr
24347+#endif
24348+
24349 #endif
24350
24351 .data
24352 .balign 4
24353 ENTRY(stack_start)
24354- .long init_thread_union+THREAD_SIZE
24355+ .long init_thread_union+THREAD_SIZE-8
24356
24357 __INITRODATA
24358 int_msg:
24359@@ -727,7 +825,7 @@ fault_msg:
24360 * segment size, and 32-bit linear address value:
24361 */
24362
24363- .data
24364+.section .rodata,"a",@progbits
24365 .globl boot_gdt_descr
24366 .globl idt_descr
24367
24368@@ -736,7 +834,7 @@ fault_msg:
24369 .word 0 # 32 bit align gdt_desc.address
24370 boot_gdt_descr:
24371 .word __BOOT_DS+7
24372- .long boot_gdt - __PAGE_OFFSET
24373+ .long pa(boot_gdt)
24374
24375 .word 0 # 32-bit align idt_desc.address
24376 idt_descr:
24377@@ -747,7 +845,7 @@ idt_descr:
24378 .word 0 # 32 bit align gdt_desc.address
24379 ENTRY(early_gdt_descr)
24380 .word GDT_ENTRIES*8-1
24381- .long gdt_page /* Overwritten for secondary CPUs */
24382+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24383
24384 /*
24385 * The boot_gdt must mirror the equivalent in setup.S and is
24386@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24387 .align L1_CACHE_BYTES
24388 ENTRY(boot_gdt)
24389 .fill GDT_ENTRY_BOOT_CS,8,0
24390- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24391- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24392+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24393+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24394+
24395+ .align PAGE_SIZE_asm
24396+ENTRY(cpu_gdt_table)
24397+ .rept NR_CPUS
24398+ .quad 0x0000000000000000 /* NULL descriptor */
24399+ .quad 0x0000000000000000 /* 0x0b reserved */
24400+ .quad 0x0000000000000000 /* 0x13 reserved */
24401+ .quad 0x0000000000000000 /* 0x1b reserved */
24402+
24403+#ifdef CONFIG_PAX_KERNEXEC
24404+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24405+#else
24406+ .quad 0x0000000000000000 /* 0x20 unused */
24407+#endif
24408+
24409+ .quad 0x0000000000000000 /* 0x28 unused */
24410+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24411+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24412+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24413+ .quad 0x0000000000000000 /* 0x4b reserved */
24414+ .quad 0x0000000000000000 /* 0x53 reserved */
24415+ .quad 0x0000000000000000 /* 0x5b reserved */
24416+
24417+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24418+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24419+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24420+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24421+
24422+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24423+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24424+
24425+ /*
24426+ * Segments used for calling PnP BIOS have byte granularity.
24427+ * The code segments and data segments have fixed 64k limits,
24428+ * the transfer segment sizes are set at run time.
24429+ */
24430+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24431+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24432+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24433+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24434+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24435+
24436+ /*
24437+ * The APM segments have byte granularity and their bases
24438+ * are set at run time. All have 64k limits.
24439+ */
24440+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24441+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24442+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24443+
24444+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24445+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24446+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24447+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24448+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24449+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24450+
24451+ /* Be sure this is zeroed to avoid false validations in Xen */
24452+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24453+ .endr
24454diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24455index a468c0a..c7dec74 100644
24456--- a/arch/x86/kernel/head_64.S
24457+++ b/arch/x86/kernel/head_64.S
24458@@ -20,6 +20,8 @@
24459 #include <asm/processor-flags.h>
24460 #include <asm/percpu.h>
24461 #include <asm/nops.h>
24462+#include <asm/cpufeature.h>
24463+#include <asm/alternative-asm.h>
24464
24465 #ifdef CONFIG_PARAVIRT
24466 #include <asm/asm-offsets.h>
24467@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24468 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24469 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24470 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24471+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24472+L3_VMALLOC_START = pud_index(VMALLOC_START)
24473+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24474+L3_VMALLOC_END = pud_index(VMALLOC_END)
24475+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24476+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24477
24478 .text
24479 __HEAD
24480@@ -89,11 +97,24 @@ startup_64:
24481 * Fixup the physical addresses in the page table
24482 */
24483 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24484+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24485+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24486+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24487+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24488+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24489
24490- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24491- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24492+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24493+#ifndef CONFIG_XEN
24494+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24495+#endif
24496+
24497+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24498+
24499+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24500+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24501
24502 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24503+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24504
24505 /*
24506 * Set up the identity mapping for the switchover. These
24507@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24508 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24509 1:
24510
24511- /* Enable PAE mode and PGE */
24512- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24513+ /* Enable PAE mode and PSE/PGE */
24514+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24515 movq %rcx, %cr4
24516
24517 /* Setup early boot stage 4 level pagetables. */
24518@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24519 movl $MSR_EFER, %ecx
24520 rdmsr
24521 btsl $_EFER_SCE, %eax /* Enable System Call */
24522- btl $20,%edi /* No Execute supported? */
24523+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24524 jnc 1f
24525 btsl $_EFER_NX, %eax
24526 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24527+#ifndef CONFIG_EFI
24528+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24529+#endif
24530+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24531+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24532+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24533+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24534+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24535+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24536 1: wrmsr /* Make changes effective */
24537
24538 /* Setup cr0 */
24539@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24540 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24541 * address given in m16:64.
24542 */
24543+ pax_set_fptr_mask
24544 movq initial_code(%rip),%rax
24545 pushq $0 # fake return address to stop unwinder
24546 pushq $__KERNEL_CS # set correct cs
24547@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24548 .quad INIT_PER_CPU_VAR(irq_stack_union)
24549
24550 GLOBAL(stack_start)
24551- .quad init_thread_union+THREAD_SIZE-8
24552+ .quad init_thread_union+THREAD_SIZE-16
24553 .word 0
24554 __FINITDATA
24555
24556@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24557 call dump_stack
24558 #ifdef CONFIG_KALLSYMS
24559 leaq early_idt_ripmsg(%rip),%rdi
24560- movq 40(%rsp),%rsi # %rip again
24561+ movq 88(%rsp),%rsi # %rip again
24562 call __print_symbol
24563 #endif
24564 #endif /* EARLY_PRINTK */
24565@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24566 early_recursion_flag:
24567 .long 0
24568
24569+ .section .rodata,"a",@progbits
24570 #ifdef CONFIG_EARLY_PRINTK
24571 early_idt_msg:
24572 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24573@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24574 NEXT_PAGE(early_dynamic_pgts)
24575 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24576
24577- .data
24578+ .section .rodata,"a",@progbits
24579
24580-#ifndef CONFIG_XEN
24581 NEXT_PAGE(init_level4_pgt)
24582- .fill 512,8,0
24583-#else
24584-NEXT_PAGE(init_level4_pgt)
24585- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24586 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24587 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24588+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24589+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24590+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24591+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24593+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24594 .org init_level4_pgt + L4_START_KERNEL*8, 0
24595 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24596 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24597
24598+#ifdef CONFIG_PAX_PER_CPU_PGD
24599+NEXT_PAGE(cpu_pgd)
24600+ .rept 2*NR_CPUS
24601+ .fill 512,8,0
24602+ .endr
24603+#endif
24604+
24605 NEXT_PAGE(level3_ident_pgt)
24606 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24607+#ifdef CONFIG_XEN
24608 .fill 511, 8, 0
24609+#else
24610+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24611+ .fill 510,8,0
24612+#endif
24613+
24614+NEXT_PAGE(level3_vmalloc_start_pgt)
24615+ .fill 512,8,0
24616+
24617+NEXT_PAGE(level3_vmalloc_end_pgt)
24618+ .fill 512,8,0
24619+
24620+NEXT_PAGE(level3_vmemmap_pgt)
24621+ .fill L3_VMEMMAP_START,8,0
24622+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24623+
24624 NEXT_PAGE(level2_ident_pgt)
24625- /* Since I easily can, map the first 1G.
24626+ /* Since I easily can, map the first 2G.
24627 * Don't set NX because code runs from these pages.
24628 */
24629- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24630-#endif
24631+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24632
24633 NEXT_PAGE(level3_kernel_pgt)
24634 .fill L3_START_KERNEL,8,0
24635@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24636 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24637 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24638
24639+NEXT_PAGE(level2_vmemmap_pgt)
24640+ .fill 512,8,0
24641+
24642 NEXT_PAGE(level2_kernel_pgt)
24643 /*
24644 * 512 MB kernel mapping. We spend a full page on this pagetable
24645@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24646 NEXT_PAGE(level2_fixmap_pgt)
24647 .fill 506,8,0
24648 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24649- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24650- .fill 5,8,0
24651+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24652+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24653+ .fill 4,8,0
24654
24655 NEXT_PAGE(level1_fixmap_pgt)
24656 .fill 512,8,0
24657
24658+NEXT_PAGE(level1_vsyscall_pgt)
24659+ .fill 512,8,0
24660+
24661 #undef PMDS
24662
24663- .data
24664+ .align PAGE_SIZE
24665+ENTRY(cpu_gdt_table)
24666+ .rept NR_CPUS
24667+ .quad 0x0000000000000000 /* NULL descriptor */
24668+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24669+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24670+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24671+ .quad 0x00cffb000000ffff /* __USER32_CS */
24672+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24673+ .quad 0x00affb000000ffff /* __USER_CS */
24674+
24675+#ifdef CONFIG_PAX_KERNEXEC
24676+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24677+#else
24678+ .quad 0x0 /* unused */
24679+#endif
24680+
24681+ .quad 0,0 /* TSS */
24682+ .quad 0,0 /* LDT */
24683+ .quad 0,0,0 /* three TLS descriptors */
24684+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24685+ /* asm/segment.h:GDT_ENTRIES must match this */
24686+
24687+#ifdef CONFIG_PAX_MEMORY_UDEREF
24688+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24689+#else
24690+ .quad 0x0 /* unused */
24691+#endif
24692+
24693+ /* zero the remaining page */
24694+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24695+ .endr
24696+
24697 .align 16
24698 .globl early_gdt_descr
24699 early_gdt_descr:
24700 .word GDT_ENTRIES*8-1
24701 early_gdt_descr_base:
24702- .quad INIT_PER_CPU_VAR(gdt_page)
24703+ .quad cpu_gdt_table
24704
24705 ENTRY(phys_base)
24706 /* This must match the first entry in level2_kernel_pgt */
24707 .quad 0x0000000000000000
24708
24709 #include "../../x86/xen/xen-head.S"
24710-
24711- __PAGE_ALIGNED_BSS
24712+
24713+ .section .rodata,"a",@progbits
24714 NEXT_PAGE(empty_zero_page)
24715 .skip PAGE_SIZE
24716diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24717index 05fd74f..c3548b1 100644
24718--- a/arch/x86/kernel/i386_ksyms_32.c
24719+++ b/arch/x86/kernel/i386_ksyms_32.c
24720@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24721 EXPORT_SYMBOL(cmpxchg8b_emu);
24722 #endif
24723
24724+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24725+
24726 /* Networking helper routines. */
24727 EXPORT_SYMBOL(csum_partial_copy_generic);
24728+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24729+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24730
24731 EXPORT_SYMBOL(__get_user_1);
24732 EXPORT_SYMBOL(__get_user_2);
24733@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24734 EXPORT_SYMBOL(___preempt_schedule_context);
24735 #endif
24736 #endif
24737+
24738+#ifdef CONFIG_PAX_KERNEXEC
24739+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24740+#endif
24741+
24742+#ifdef CONFIG_PAX_PER_CPU_PGD
24743+EXPORT_SYMBOL(cpu_pgd);
24744+#endif
24745diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24746index d5dd808..b6432cf 100644
24747--- a/arch/x86/kernel/i387.c
24748+++ b/arch/x86/kernel/i387.c
24749@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24750 static inline bool interrupted_user_mode(void)
24751 {
24752 struct pt_regs *regs = get_irq_regs();
24753- return regs && user_mode_vm(regs);
24754+ return regs && user_mode(regs);
24755 }
24756
24757 /*
24758diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24759index 2e977b5..5f2c273 100644
24760--- a/arch/x86/kernel/i8259.c
24761+++ b/arch/x86/kernel/i8259.c
24762@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24763 static void make_8259A_irq(unsigned int irq)
24764 {
24765 disable_irq_nosync(irq);
24766- io_apic_irqs &= ~(1<<irq);
24767+ io_apic_irqs &= ~(1UL<<irq);
24768 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24769 i8259A_chip.name);
24770 enable_irq(irq);
24771@@ -209,7 +209,7 @@ spurious_8259A_irq:
24772 "spurious 8259A interrupt: IRQ%d.\n", irq);
24773 spurious_irq_mask |= irqmask;
24774 }
24775- atomic_inc(&irq_err_count);
24776+ atomic_inc_unchecked(&irq_err_count);
24777 /*
24778 * Theoretically we do not have to handle this IRQ,
24779 * but in Linux this does not cause problems and is
24780@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24781 /* (slave's support for AEOI in flat mode is to be investigated) */
24782 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24783
24784+ pax_open_kernel();
24785 if (auto_eoi)
24786 /*
24787 * In AEOI mode we just have to mask the interrupt
24788 * when acking.
24789 */
24790- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24791+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24792 else
24793- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24794+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24795+ pax_close_kernel();
24796
24797 udelay(100); /* wait for 8259A to initialize */
24798
24799diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24800index a979b5b..1d6db75 100644
24801--- a/arch/x86/kernel/io_delay.c
24802+++ b/arch/x86/kernel/io_delay.c
24803@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24804 * Quirk table for systems that misbehave (lock up, etc.) if port
24805 * 0x80 is used:
24806 */
24807-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24808+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24809 {
24810 .callback = dmi_io_delay_0xed_port,
24811 .ident = "Compaq Presario V6000",
24812diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24813index 4ddaf66..49d5c18 100644
24814--- a/arch/x86/kernel/ioport.c
24815+++ b/arch/x86/kernel/ioport.c
24816@@ -6,6 +6,7 @@
24817 #include <linux/sched.h>
24818 #include <linux/kernel.h>
24819 #include <linux/capability.h>
24820+#include <linux/security.h>
24821 #include <linux/errno.h>
24822 #include <linux/types.h>
24823 #include <linux/ioport.h>
24824@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24825 return -EINVAL;
24826 if (turn_on && !capable(CAP_SYS_RAWIO))
24827 return -EPERM;
24828+#ifdef CONFIG_GRKERNSEC_IO
24829+ if (turn_on && grsec_disable_privio) {
24830+ gr_handle_ioperm();
24831+ return -ENODEV;
24832+ }
24833+#endif
24834
24835 /*
24836 * If it's the first ioperm() call in this thread's lifetime, set the
24837@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24838 * because the ->io_bitmap_max value must match the bitmap
24839 * contents:
24840 */
24841- tss = &per_cpu(init_tss, get_cpu());
24842+ tss = init_tss + get_cpu();
24843
24844 if (turn_on)
24845 bitmap_clear(t->io_bitmap_ptr, from, num);
24846@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24847 if (level > old) {
24848 if (!capable(CAP_SYS_RAWIO))
24849 return -EPERM;
24850+#ifdef CONFIG_GRKERNSEC_IO
24851+ if (grsec_disable_privio) {
24852+ gr_handle_iopl();
24853+ return -ENODEV;
24854+ }
24855+#endif
24856 }
24857 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24858 t->iopl = level << 12;
24859diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24860index d99f31d..1c0f466 100644
24861--- a/arch/x86/kernel/irq.c
24862+++ b/arch/x86/kernel/irq.c
24863@@ -21,7 +21,7 @@
24864 #define CREATE_TRACE_POINTS
24865 #include <asm/trace/irq_vectors.h>
24866
24867-atomic_t irq_err_count;
24868+atomic_unchecked_t irq_err_count;
24869
24870 /* Function pointer for generic interrupt vector handling */
24871 void (*x86_platform_ipi_callback)(void) = NULL;
24872@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24873 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24874 seq_printf(p, " Machine check polls\n");
24875 #endif
24876- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24877+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24878 #if defined(CONFIG_X86_IO_APIC)
24879- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24880+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24881 #endif
24882 return 0;
24883 }
24884@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24885
24886 u64 arch_irq_stat(void)
24887 {
24888- u64 sum = atomic_read(&irq_err_count);
24889+ u64 sum = atomic_read_unchecked(&irq_err_count);
24890 return sum;
24891 }
24892
24893diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24894index d7fcbed..1f747f7 100644
24895--- a/arch/x86/kernel/irq_32.c
24896+++ b/arch/x86/kernel/irq_32.c
24897@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24898 __asm__ __volatile__("andl %%esp,%0" :
24899 "=r" (sp) : "0" (THREAD_SIZE - 1));
24900
24901- return sp < (sizeof(struct thread_info) + STACK_WARN);
24902+ return sp < STACK_WARN;
24903 }
24904
24905 static void print_stack_overflow(void)
24906@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24907 * per-CPU IRQ handling contexts (thread information and stack)
24908 */
24909 union irq_ctx {
24910- struct thread_info tinfo;
24911- u32 stack[THREAD_SIZE/sizeof(u32)];
24912+ unsigned long previous_esp;
24913+ u32 stack[THREAD_SIZE/sizeof(u32)];
24914 } __attribute__((aligned(THREAD_SIZE)));
24915
24916 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24917@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24918 static inline int
24919 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24920 {
24921- union irq_ctx *curctx, *irqctx;
24922+ union irq_ctx *irqctx;
24923 u32 *isp, arg1, arg2;
24924
24925- curctx = (union irq_ctx *) current_thread_info();
24926 irqctx = __this_cpu_read(hardirq_ctx);
24927
24928 /*
24929@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24930 * handler) we can't do that and just have to keep using the
24931 * current stack (which is the irq stack already after all)
24932 */
24933- if (unlikely(curctx == irqctx))
24934+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24935 return 0;
24936
24937 /* build the stack frame on the IRQ stack */
24938- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24939- irqctx->tinfo.task = curctx->tinfo.task;
24940- irqctx->tinfo.previous_esp = current_stack_pointer;
24941+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24942+ irqctx->previous_esp = current_stack_pointer;
24943+
24944+#ifdef CONFIG_PAX_MEMORY_UDEREF
24945+ __set_fs(MAKE_MM_SEG(0));
24946+#endif
24947
24948 if (unlikely(overflow))
24949 call_on_stack(print_stack_overflow, isp);
24950@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24951 : "0" (irq), "1" (desc), "2" (isp),
24952 "D" (desc->handle_irq)
24953 : "memory", "cc", "ecx");
24954+
24955+#ifdef CONFIG_PAX_MEMORY_UDEREF
24956+ __set_fs(current_thread_info()->addr_limit);
24957+#endif
24958+
24959 return 1;
24960 }
24961
24962@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24963 */
24964 void irq_ctx_init(int cpu)
24965 {
24966- union irq_ctx *irqctx;
24967-
24968 if (per_cpu(hardirq_ctx, cpu))
24969 return;
24970
24971- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24972- THREADINFO_GFP,
24973- THREAD_SIZE_ORDER));
24974- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24975- irqctx->tinfo.cpu = cpu;
24976- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24977-
24978- per_cpu(hardirq_ctx, cpu) = irqctx;
24979-
24980- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24981- THREADINFO_GFP,
24982- THREAD_SIZE_ORDER));
24983- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24984- irqctx->tinfo.cpu = cpu;
24985- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24986-
24987- per_cpu(softirq_ctx, cpu) = irqctx;
24988-
24989- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24990- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24991+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24992+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24993 }
24994
24995 void do_softirq_own_stack(void)
24996 {
24997- struct thread_info *curctx;
24998 union irq_ctx *irqctx;
24999 u32 *isp;
25000
25001- curctx = current_thread_info();
25002 irqctx = __this_cpu_read(softirq_ctx);
25003- irqctx->tinfo.task = curctx->task;
25004- irqctx->tinfo.previous_esp = current_stack_pointer;
25005+ irqctx->previous_esp = current_stack_pointer;
25006
25007 /* build the stack frame on the softirq stack */
25008- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25009+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25010+
25011+#ifdef CONFIG_PAX_MEMORY_UDEREF
25012+ __set_fs(MAKE_MM_SEG(0));
25013+#endif
25014
25015 call_on_stack(__do_softirq, isp);
25016+
25017+#ifdef CONFIG_PAX_MEMORY_UDEREF
25018+ __set_fs(current_thread_info()->addr_limit);
25019+#endif
25020+
25021 }
25022
25023 bool handle_irq(unsigned irq, struct pt_regs *regs)
25024@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25025 if (unlikely(!desc))
25026 return false;
25027
25028- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25029+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25030 if (unlikely(overflow))
25031 print_stack_overflow();
25032 desc->handle_irq(irq, desc);
25033diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25034index 4d1c746..232961d 100644
25035--- a/arch/x86/kernel/irq_64.c
25036+++ b/arch/x86/kernel/irq_64.c
25037@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25038 u64 estack_top, estack_bottom;
25039 u64 curbase = (u64)task_stack_page(current);
25040
25041- if (user_mode_vm(regs))
25042+ if (user_mode(regs))
25043 return;
25044
25045 if (regs->sp >= curbase + sizeof(struct thread_info) +
25046diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25047index 26d5a55..a01160a 100644
25048--- a/arch/x86/kernel/jump_label.c
25049+++ b/arch/x86/kernel/jump_label.c
25050@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25051 * Jump label is enabled for the first time.
25052 * So we expect a default_nop...
25053 */
25054- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25055+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25056 != 0))
25057 bug_at((void *)entry->code, __LINE__);
25058 } else {
25059@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25060 * ...otherwise expect an ideal_nop. Otherwise
25061 * something went horribly wrong.
25062 */
25063- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25064+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25065 != 0))
25066 bug_at((void *)entry->code, __LINE__);
25067 }
25068@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25069 * are converting the default nop to the ideal nop.
25070 */
25071 if (init) {
25072- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25073+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25074 bug_at((void *)entry->code, __LINE__);
25075 } else {
25076 code.jump = 0xe9;
25077 code.offset = entry->target -
25078 (entry->code + JUMP_LABEL_NOP_SIZE);
25079- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25080+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25081 bug_at((void *)entry->code, __LINE__);
25082 }
25083 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25084diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25085index 7ec1d5f..5a7d130 100644
25086--- a/arch/x86/kernel/kgdb.c
25087+++ b/arch/x86/kernel/kgdb.c
25088@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25089 #ifdef CONFIG_X86_32
25090 switch (regno) {
25091 case GDB_SS:
25092- if (!user_mode_vm(regs))
25093+ if (!user_mode(regs))
25094 *(unsigned long *)mem = __KERNEL_DS;
25095 break;
25096 case GDB_SP:
25097- if (!user_mode_vm(regs))
25098+ if (!user_mode(regs))
25099 *(unsigned long *)mem = kernel_stack_pointer(regs);
25100 break;
25101 case GDB_GS:
25102@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25103 bp->attr.bp_addr = breakinfo[breakno].addr;
25104 bp->attr.bp_len = breakinfo[breakno].len;
25105 bp->attr.bp_type = breakinfo[breakno].type;
25106- info->address = breakinfo[breakno].addr;
25107+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25108+ info->address = ktla_ktva(breakinfo[breakno].addr);
25109+ else
25110+ info->address = breakinfo[breakno].addr;
25111 info->len = breakinfo[breakno].len;
25112 info->type = breakinfo[breakno].type;
25113 val = arch_install_hw_breakpoint(bp);
25114@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25115 case 'k':
25116 /* clear the trace bit */
25117 linux_regs->flags &= ~X86_EFLAGS_TF;
25118- atomic_set(&kgdb_cpu_doing_single_step, -1);
25119+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25120
25121 /* set the trace bit if we're stepping */
25122 if (remcomInBuffer[0] == 's') {
25123 linux_regs->flags |= X86_EFLAGS_TF;
25124- atomic_set(&kgdb_cpu_doing_single_step,
25125+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25126 raw_smp_processor_id());
25127 }
25128
25129@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25130
25131 switch (cmd) {
25132 case DIE_DEBUG:
25133- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25134+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25135 if (user_mode(regs))
25136 return single_step_cont(regs, args);
25137 break;
25138@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25139 #endif /* CONFIG_DEBUG_RODATA */
25140
25141 bpt->type = BP_BREAKPOINT;
25142- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25143+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25144 BREAK_INSTR_SIZE);
25145 if (err)
25146 return err;
25147- err = probe_kernel_write((char *)bpt->bpt_addr,
25148+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25149 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25150 #ifdef CONFIG_DEBUG_RODATA
25151 if (!err)
25152@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25153 return -EBUSY;
25154 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25155 BREAK_INSTR_SIZE);
25156- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25157+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25158 if (err)
25159 return err;
25160 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25161@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25162 if (mutex_is_locked(&text_mutex))
25163 goto knl_write;
25164 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25165- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25166+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25167 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25168 goto knl_write;
25169 return err;
25170 knl_write:
25171 #endif /* CONFIG_DEBUG_RODATA */
25172- return probe_kernel_write((char *)bpt->bpt_addr,
25173+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25174 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25175 }
25176
25177diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25178index 79a3f96..6ba030a 100644
25179--- a/arch/x86/kernel/kprobes/core.c
25180+++ b/arch/x86/kernel/kprobes/core.c
25181@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25182 s32 raddr;
25183 } __packed *insn;
25184
25185- insn = (struct __arch_relative_insn *)from;
25186+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25187+
25188+ pax_open_kernel();
25189 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25190 insn->op = op;
25191+ pax_close_kernel();
25192 }
25193
25194 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25195@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25196 kprobe_opcode_t opcode;
25197 kprobe_opcode_t *orig_opcodes = opcodes;
25198
25199- if (search_exception_tables((unsigned long)opcodes))
25200+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25201 return 0; /* Page fault may occur on this address. */
25202
25203 retry:
25204@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25205 * for the first byte, we can recover the original instruction
25206 * from it and kp->opcode.
25207 */
25208- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25209+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25210 buf[0] = kp->opcode;
25211- return (unsigned long)buf;
25212+ return ktva_ktla((unsigned long)buf);
25213 }
25214
25215 /*
25216@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25217 /* Another subsystem puts a breakpoint, failed to recover */
25218 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25219 return 0;
25220+ pax_open_kernel();
25221 memcpy(dest, insn.kaddr, insn.length);
25222+ pax_close_kernel();
25223
25224 #ifdef CONFIG_X86_64
25225 if (insn_rip_relative(&insn)) {
25226@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25227 return 0;
25228 }
25229 disp = (u8 *) dest + insn_offset_displacement(&insn);
25230+ pax_open_kernel();
25231 *(s32 *) disp = (s32) newdisp;
25232+ pax_close_kernel();
25233 }
25234 #endif
25235 return insn.length;
25236@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25237 * nor set current_kprobe, because it doesn't use single
25238 * stepping.
25239 */
25240- regs->ip = (unsigned long)p->ainsn.insn;
25241+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25242 preempt_enable_no_resched();
25243 return;
25244 }
25245@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25246 regs->flags &= ~X86_EFLAGS_IF;
25247 /* single step inline if the instruction is an int3 */
25248 if (p->opcode == BREAKPOINT_INSTRUCTION)
25249- regs->ip = (unsigned long)p->addr;
25250+ regs->ip = ktla_ktva((unsigned long)p->addr);
25251 else
25252- regs->ip = (unsigned long)p->ainsn.insn;
25253+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25254 }
25255
25256 /*
25257@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25258 setup_singlestep(p, regs, kcb, 0);
25259 return 1;
25260 }
25261- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25262+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25263 /*
25264 * The breakpoint instruction was removed right
25265 * after we hit it. Another cpu has removed
25266@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25267 " movq %rax, 152(%rsp)\n"
25268 RESTORE_REGS_STRING
25269 " popfq\n"
25270+#ifdef KERNEXEC_PLUGIN
25271+ " btsq $63,(%rsp)\n"
25272+#endif
25273 #else
25274 " pushf\n"
25275 SAVE_REGS_STRING
25276@@ -779,7 +789,7 @@ static void __kprobes
25277 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25278 {
25279 unsigned long *tos = stack_addr(regs);
25280- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25281+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25282 unsigned long orig_ip = (unsigned long)p->addr;
25283 kprobe_opcode_t *insn = p->ainsn.insn;
25284
25285@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25286 struct die_args *args = data;
25287 int ret = NOTIFY_DONE;
25288
25289- if (args->regs && user_mode_vm(args->regs))
25290+ if (args->regs && user_mode(args->regs))
25291 return ret;
25292
25293 switch (val) {
25294diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25295index 898160b..758cde8 100644
25296--- a/arch/x86/kernel/kprobes/opt.c
25297+++ b/arch/x86/kernel/kprobes/opt.c
25298@@ -79,6 +79,7 @@ found:
25299 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25300 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25301 {
25302+ pax_open_kernel();
25303 #ifdef CONFIG_X86_64
25304 *addr++ = 0x48;
25305 *addr++ = 0xbf;
25306@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25307 *addr++ = 0xb8;
25308 #endif
25309 *(unsigned long *)addr = val;
25310+ pax_close_kernel();
25311 }
25312
25313 asm (
25314@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25315 * Verify if the address gap is in 2GB range, because this uses
25316 * a relative jump.
25317 */
25318- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25319+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25320 if (abs(rel) > 0x7fffffff)
25321 return -ERANGE;
25322
25323@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25324 op->optinsn.size = ret;
25325
25326 /* Copy arch-dep-instance from template */
25327- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25328+ pax_open_kernel();
25329+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25330+ pax_close_kernel();
25331
25332 /* Set probe information */
25333 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25334
25335 /* Set probe function call */
25336- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25337+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25338
25339 /* Set returning jmp instruction at the tail of out-of-line buffer */
25340- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25341+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25342 (u8 *)op->kp.addr + op->optinsn.size);
25343
25344 flush_icache_range((unsigned long) buf,
25345@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25346 WARN_ON(kprobe_disabled(&op->kp));
25347
25348 /* Backup instructions which will be replaced by jump address */
25349- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25350+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25351 RELATIVE_ADDR_SIZE);
25352
25353 insn_buf[0] = RELATIVEJUMP_OPCODE;
25354@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25355 /* This kprobe is really able to run optimized path. */
25356 op = container_of(p, struct optimized_kprobe, kp);
25357 /* Detour through copied instructions */
25358- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25359+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25360 if (!reenter)
25361 reset_current_kprobe();
25362 preempt_enable_no_resched();
25363diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25364index c2bedae..25e7ab6 100644
25365--- a/arch/x86/kernel/ksysfs.c
25366+++ b/arch/x86/kernel/ksysfs.c
25367@@ -184,7 +184,7 @@ out:
25368
25369 static struct kobj_attribute type_attr = __ATTR_RO(type);
25370
25371-static struct bin_attribute data_attr = {
25372+static bin_attribute_no_const data_attr __read_only = {
25373 .attr = {
25374 .name = "data",
25375 .mode = S_IRUGO,
25376diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25377index af1d14a..37b8776 100644
25378--- a/arch/x86/kernel/ldt.c
25379+++ b/arch/x86/kernel/ldt.c
25380@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25381 if (reload) {
25382 #ifdef CONFIG_SMP
25383 preempt_disable();
25384- load_LDT(pc);
25385+ load_LDT_nolock(pc);
25386 if (!cpumask_equal(mm_cpumask(current->mm),
25387 cpumask_of(smp_processor_id())))
25388 smp_call_function(flush_ldt, current->mm, 1);
25389 preempt_enable();
25390 #else
25391- load_LDT(pc);
25392+ load_LDT_nolock(pc);
25393 #endif
25394 }
25395 if (oldsize) {
25396@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25397 return err;
25398
25399 for (i = 0; i < old->size; i++)
25400- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25401+ write_ldt_entry(new->ldt, i, old->ldt + i);
25402 return 0;
25403 }
25404
25405@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25406 retval = copy_ldt(&mm->context, &old_mm->context);
25407 mutex_unlock(&old_mm->context.lock);
25408 }
25409+
25410+ if (tsk == current) {
25411+ mm->context.vdso = 0;
25412+
25413+#ifdef CONFIG_X86_32
25414+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25415+ mm->context.user_cs_base = 0UL;
25416+ mm->context.user_cs_limit = ~0UL;
25417+
25418+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25419+ cpus_clear(mm->context.cpu_user_cs_mask);
25420+#endif
25421+
25422+#endif
25423+#endif
25424+
25425+ }
25426+
25427 return retval;
25428 }
25429
25430@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25431 }
25432 }
25433
25434+#ifdef CONFIG_PAX_SEGMEXEC
25435+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25436+ error = -EINVAL;
25437+ goto out_unlock;
25438+ }
25439+#endif
25440+
25441 /*
25442 * On x86-64 we do not support 16-bit segments due to
25443 * IRET leaking the high bits of the kernel stack address.
25444diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25445index 1667b1d..16492c5 100644
25446--- a/arch/x86/kernel/machine_kexec_32.c
25447+++ b/arch/x86/kernel/machine_kexec_32.c
25448@@ -25,7 +25,7 @@
25449 #include <asm/cacheflush.h>
25450 #include <asm/debugreg.h>
25451
25452-static void set_idt(void *newidt, __u16 limit)
25453+static void set_idt(struct desc_struct *newidt, __u16 limit)
25454 {
25455 struct desc_ptr curidt;
25456
25457@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25458 }
25459
25460
25461-static void set_gdt(void *newgdt, __u16 limit)
25462+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25463 {
25464 struct desc_ptr curgdt;
25465
25466@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25467 }
25468
25469 control_page = page_address(image->control_code_page);
25470- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25471+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25472
25473 relocate_kernel_ptr = control_page;
25474 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25475diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25476index 18be189..4a9fe40 100644
25477--- a/arch/x86/kernel/module.c
25478+++ b/arch/x86/kernel/module.c
25479@@ -43,15 +43,60 @@ do { \
25480 } while (0)
25481 #endif
25482
25483-void *module_alloc(unsigned long size)
25484+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25485 {
25486- if (PAGE_ALIGN(size) > MODULES_LEN)
25487+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25488 return NULL;
25489 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25490- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25491+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25492 NUMA_NO_NODE, __builtin_return_address(0));
25493 }
25494
25495+void *module_alloc(unsigned long size)
25496+{
25497+
25498+#ifdef CONFIG_PAX_KERNEXEC
25499+ return __module_alloc(size, PAGE_KERNEL);
25500+#else
25501+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25502+#endif
25503+
25504+}
25505+
25506+#ifdef CONFIG_PAX_KERNEXEC
25507+#ifdef CONFIG_X86_32
25508+void *module_alloc_exec(unsigned long size)
25509+{
25510+ struct vm_struct *area;
25511+
25512+ if (size == 0)
25513+ return NULL;
25514+
25515+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25516+ return area ? area->addr : NULL;
25517+}
25518+EXPORT_SYMBOL(module_alloc_exec);
25519+
25520+void module_free_exec(struct module *mod, void *module_region)
25521+{
25522+ vunmap(module_region);
25523+}
25524+EXPORT_SYMBOL(module_free_exec);
25525+#else
25526+void module_free_exec(struct module *mod, void *module_region)
25527+{
25528+ module_free(mod, module_region);
25529+}
25530+EXPORT_SYMBOL(module_free_exec);
25531+
25532+void *module_alloc_exec(unsigned long size)
25533+{
25534+ return __module_alloc(size, PAGE_KERNEL_RX);
25535+}
25536+EXPORT_SYMBOL(module_alloc_exec);
25537+#endif
25538+#endif
25539+
25540 #ifdef CONFIG_X86_32
25541 int apply_relocate(Elf32_Shdr *sechdrs,
25542 const char *strtab,
25543@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25544 unsigned int i;
25545 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25546 Elf32_Sym *sym;
25547- uint32_t *location;
25548+ uint32_t *plocation, location;
25549
25550 DEBUGP("Applying relocate section %u to %u\n",
25551 relsec, sechdrs[relsec].sh_info);
25552 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25553 /* This is where to make the change */
25554- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25555- + rel[i].r_offset;
25556+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25557+ location = (uint32_t)plocation;
25558+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25559+ plocation = ktla_ktva((void *)plocation);
25560 /* This is the symbol it is referring to. Note that all
25561 undefined symbols have been resolved. */
25562 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25563@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25564 switch (ELF32_R_TYPE(rel[i].r_info)) {
25565 case R_386_32:
25566 /* We add the value into the location given */
25567- *location += sym->st_value;
25568+ pax_open_kernel();
25569+ *plocation += sym->st_value;
25570+ pax_close_kernel();
25571 break;
25572 case R_386_PC32:
25573 /* Add the value, subtract its position */
25574- *location += sym->st_value - (uint32_t)location;
25575+ pax_open_kernel();
25576+ *plocation += sym->st_value - location;
25577+ pax_close_kernel();
25578 break;
25579 default:
25580 pr_err("%s: Unknown relocation: %u\n",
25581@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25582 case R_X86_64_NONE:
25583 break;
25584 case R_X86_64_64:
25585+ pax_open_kernel();
25586 *(u64 *)loc = val;
25587+ pax_close_kernel();
25588 break;
25589 case R_X86_64_32:
25590+ pax_open_kernel();
25591 *(u32 *)loc = val;
25592+ pax_close_kernel();
25593 if (val != *(u32 *)loc)
25594 goto overflow;
25595 break;
25596 case R_X86_64_32S:
25597+ pax_open_kernel();
25598 *(s32 *)loc = val;
25599+ pax_close_kernel();
25600 if ((s64)val != *(s32 *)loc)
25601 goto overflow;
25602 break;
25603 case R_X86_64_PC32:
25604 val -= (u64)loc;
25605+ pax_open_kernel();
25606 *(u32 *)loc = val;
25607+ pax_close_kernel();
25608+
25609 #if 0
25610 if ((s64)val != *(s32 *)loc)
25611 goto overflow;
25612diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25613index 05266b5..3432443 100644
25614--- a/arch/x86/kernel/msr.c
25615+++ b/arch/x86/kernel/msr.c
25616@@ -37,6 +37,7 @@
25617 #include <linux/notifier.h>
25618 #include <linux/uaccess.h>
25619 #include <linux/gfp.h>
25620+#include <linux/grsecurity.h>
25621
25622 #include <asm/processor.h>
25623 #include <asm/msr.h>
25624@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25625 int err = 0;
25626 ssize_t bytes = 0;
25627
25628+#ifdef CONFIG_GRKERNSEC_KMEM
25629+ gr_handle_msr_write();
25630+ return -EPERM;
25631+#endif
25632+
25633 if (count % 8)
25634 return -EINVAL; /* Invalid chunk size */
25635
25636@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25637 err = -EBADF;
25638 break;
25639 }
25640+#ifdef CONFIG_GRKERNSEC_KMEM
25641+ gr_handle_msr_write();
25642+ return -EPERM;
25643+#endif
25644 if (copy_from_user(&regs, uregs, sizeof regs)) {
25645 err = -EFAULT;
25646 break;
25647@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25648 return notifier_from_errno(err);
25649 }
25650
25651-static struct notifier_block __refdata msr_class_cpu_notifier = {
25652+static struct notifier_block msr_class_cpu_notifier = {
25653 .notifier_call = msr_class_cpu_callback,
25654 };
25655
25656diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25657index 6fcb49c..5b3f4ff 100644
25658--- a/arch/x86/kernel/nmi.c
25659+++ b/arch/x86/kernel/nmi.c
25660@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25661 return handled;
25662 }
25663
25664-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25665+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25666 {
25667 struct nmi_desc *desc = nmi_to_desc(type);
25668 unsigned long flags;
25669@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25670 * event confuses some handlers (kdump uses this flag)
25671 */
25672 if (action->flags & NMI_FLAG_FIRST)
25673- list_add_rcu(&action->list, &desc->head);
25674+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25675 else
25676- list_add_tail_rcu(&action->list, &desc->head);
25677+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25678
25679 spin_unlock_irqrestore(&desc->lock, flags);
25680 return 0;
25681@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25682 if (!strcmp(n->name, name)) {
25683 WARN(in_nmi(),
25684 "Trying to free NMI (%s) from NMI context!\n", n->name);
25685- list_del_rcu(&n->list);
25686+ pax_list_del_rcu((struct list_head *)&n->list);
25687 break;
25688 }
25689 }
25690@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25691 dotraplinkage notrace __kprobes void
25692 do_nmi(struct pt_regs *regs, long error_code)
25693 {
25694+
25695+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25696+ if (!user_mode(regs)) {
25697+ unsigned long cs = regs->cs & 0xFFFF;
25698+ unsigned long ip = ktva_ktla(regs->ip);
25699+
25700+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25701+ regs->ip = ip;
25702+ }
25703+#endif
25704+
25705 nmi_nesting_preprocess(regs);
25706
25707 nmi_enter();
25708diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25709index 6d9582e..f746287 100644
25710--- a/arch/x86/kernel/nmi_selftest.c
25711+++ b/arch/x86/kernel/nmi_selftest.c
25712@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25713 {
25714 /* trap all the unknown NMIs we may generate */
25715 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25716- __initdata);
25717+ __initconst);
25718 }
25719
25720 static void __init cleanup_nmi_testsuite(void)
25721@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25722 unsigned long timeout;
25723
25724 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25725- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25726+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25727 nmi_fail = FAILURE;
25728 return;
25729 }
25730diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25731index bbb6c73..24a58ef 100644
25732--- a/arch/x86/kernel/paravirt-spinlocks.c
25733+++ b/arch/x86/kernel/paravirt-spinlocks.c
25734@@ -8,7 +8,7 @@
25735
25736 #include <asm/paravirt.h>
25737
25738-struct pv_lock_ops pv_lock_ops = {
25739+struct pv_lock_ops pv_lock_ops __read_only = {
25740 #ifdef CONFIG_SMP
25741 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25742 .unlock_kick = paravirt_nop,
25743diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25744index 1b10af8..0b58cbc 100644
25745--- a/arch/x86/kernel/paravirt.c
25746+++ b/arch/x86/kernel/paravirt.c
25747@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25748 {
25749 return x;
25750 }
25751+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25752+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25753+#endif
25754
25755 void __init default_banner(void)
25756 {
25757@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25758 if (opfunc == NULL)
25759 /* If there's no function, patch it with a ud2a (BUG) */
25760 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25761- else if (opfunc == _paravirt_nop)
25762+ else if (opfunc == (void *)_paravirt_nop)
25763 /* If the operation is a nop, then nop the callsite */
25764 ret = paravirt_patch_nop();
25765
25766 /* identity functions just return their single argument */
25767- else if (opfunc == _paravirt_ident_32)
25768+ else if (opfunc == (void *)_paravirt_ident_32)
25769 ret = paravirt_patch_ident_32(insnbuf, len);
25770- else if (opfunc == _paravirt_ident_64)
25771+ else if (opfunc == (void *)_paravirt_ident_64)
25772 ret = paravirt_patch_ident_64(insnbuf, len);
25773+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25774+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25775+ ret = paravirt_patch_ident_64(insnbuf, len);
25776+#endif
25777
25778 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25779 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25780@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25781 if (insn_len > len || start == NULL)
25782 insn_len = len;
25783 else
25784- memcpy(insnbuf, start, insn_len);
25785+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25786
25787 return insn_len;
25788 }
25789@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25790 return this_cpu_read(paravirt_lazy_mode);
25791 }
25792
25793-struct pv_info pv_info = {
25794+struct pv_info pv_info __read_only = {
25795 .name = "bare hardware",
25796 .paravirt_enabled = 0,
25797 .kernel_rpl = 0,
25798@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25799 #endif
25800 };
25801
25802-struct pv_init_ops pv_init_ops = {
25803+struct pv_init_ops pv_init_ops __read_only = {
25804 .patch = native_patch,
25805 };
25806
25807-struct pv_time_ops pv_time_ops = {
25808+struct pv_time_ops pv_time_ops __read_only = {
25809 .sched_clock = native_sched_clock,
25810 .steal_clock = native_steal_clock,
25811 };
25812
25813-__visible struct pv_irq_ops pv_irq_ops = {
25814+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25815 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25816 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25817 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25818@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25819 #endif
25820 };
25821
25822-__visible struct pv_cpu_ops pv_cpu_ops = {
25823+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25824 .cpuid = native_cpuid,
25825 .get_debugreg = native_get_debugreg,
25826 .set_debugreg = native_set_debugreg,
25827@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25828 .end_context_switch = paravirt_nop,
25829 };
25830
25831-struct pv_apic_ops pv_apic_ops = {
25832+struct pv_apic_ops pv_apic_ops __read_only= {
25833 #ifdef CONFIG_X86_LOCAL_APIC
25834 .startup_ipi_hook = paravirt_nop,
25835 #endif
25836 };
25837
25838-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25839+#ifdef CONFIG_X86_32
25840+#ifdef CONFIG_X86_PAE
25841+/* 64-bit pagetable entries */
25842+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25843+#else
25844 /* 32-bit pagetable entries */
25845 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25846+#endif
25847 #else
25848 /* 64-bit pagetable entries */
25849 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25850 #endif
25851
25852-struct pv_mmu_ops pv_mmu_ops = {
25853+struct pv_mmu_ops pv_mmu_ops __read_only = {
25854
25855 .read_cr2 = native_read_cr2,
25856 .write_cr2 = native_write_cr2,
25857@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25858 .make_pud = PTE_IDENT,
25859
25860 .set_pgd = native_set_pgd,
25861+ .set_pgd_batched = native_set_pgd_batched,
25862 #endif
25863 #endif /* PAGETABLE_LEVELS >= 3 */
25864
25865@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25866 },
25867
25868 .set_fixmap = native_set_fixmap,
25869+
25870+#ifdef CONFIG_PAX_KERNEXEC
25871+ .pax_open_kernel = native_pax_open_kernel,
25872+ .pax_close_kernel = native_pax_close_kernel,
25873+#endif
25874+
25875 };
25876
25877 EXPORT_SYMBOL_GPL(pv_time_ops);
25878diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25879index 299d493..2ccb0ee 100644
25880--- a/arch/x86/kernel/pci-calgary_64.c
25881+++ b/arch/x86/kernel/pci-calgary_64.c
25882@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25883 tce_space = be64_to_cpu(readq(target));
25884 tce_space = tce_space & TAR_SW_BITS;
25885
25886- tce_space = tce_space & (~specified_table_size);
25887+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25888 info->tce_space = (u64 *)__va(tce_space);
25889 }
25890 }
25891diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25892index 35ccf75..7a15747 100644
25893--- a/arch/x86/kernel/pci-iommu_table.c
25894+++ b/arch/x86/kernel/pci-iommu_table.c
25895@@ -2,7 +2,7 @@
25896 #include <asm/iommu_table.h>
25897 #include <linux/string.h>
25898 #include <linux/kallsyms.h>
25899-
25900+#include <linux/sched.h>
25901
25902 #define DEBUG 1
25903
25904diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25905index 6c483ba..d10ce2f 100644
25906--- a/arch/x86/kernel/pci-swiotlb.c
25907+++ b/arch/x86/kernel/pci-swiotlb.c
25908@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25909 void *vaddr, dma_addr_t dma_addr,
25910 struct dma_attrs *attrs)
25911 {
25912- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25913+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25914 }
25915
25916 static struct dma_map_ops swiotlb_dma_ops = {
25917diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25918index ca7f0d5..8996469 100644
25919--- a/arch/x86/kernel/preempt.S
25920+++ b/arch/x86/kernel/preempt.S
25921@@ -3,12 +3,14 @@
25922 #include <asm/dwarf2.h>
25923 #include <asm/asm.h>
25924 #include <asm/calling.h>
25925+#include <asm/alternative-asm.h>
25926
25927 ENTRY(___preempt_schedule)
25928 CFI_STARTPROC
25929 SAVE_ALL
25930 call preempt_schedule
25931 RESTORE_ALL
25932+ pax_force_retaddr
25933 ret
25934 CFI_ENDPROC
25935
25936@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25937 SAVE_ALL
25938 call preempt_schedule_context
25939 RESTORE_ALL
25940+ pax_force_retaddr
25941 ret
25942 CFI_ENDPROC
25943
25944diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25945index 3fb8d95..254dc51 100644
25946--- a/arch/x86/kernel/process.c
25947+++ b/arch/x86/kernel/process.c
25948@@ -36,7 +36,8 @@
25949 * section. Since TSS's are completely CPU-local, we want them
25950 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25951 */
25952-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25953+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25954+EXPORT_SYMBOL(init_tss);
25955
25956 #ifdef CONFIG_X86_64
25957 static DEFINE_PER_CPU(unsigned char, is_idle);
25958@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25959 task_xstate_cachep =
25960 kmem_cache_create("task_xstate", xstate_size,
25961 __alignof__(union thread_xstate),
25962- SLAB_PANIC | SLAB_NOTRACK, NULL);
25963+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25964 }
25965
25966 /*
25967@@ -105,7 +106,7 @@ void exit_thread(void)
25968 unsigned long *bp = t->io_bitmap_ptr;
25969
25970 if (bp) {
25971- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25972+ struct tss_struct *tss = init_tss + get_cpu();
25973
25974 t->io_bitmap_ptr = NULL;
25975 clear_thread_flag(TIF_IO_BITMAP);
25976@@ -125,6 +126,9 @@ void flush_thread(void)
25977 {
25978 struct task_struct *tsk = current;
25979
25980+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25981+ loadsegment(gs, 0);
25982+#endif
25983 flush_ptrace_hw_breakpoint(tsk);
25984 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25985 drop_init_fpu(tsk);
25986@@ -271,7 +275,7 @@ static void __exit_idle(void)
25987 void exit_idle(void)
25988 {
25989 /* idle loop has pid 0 */
25990- if (current->pid)
25991+ if (task_pid_nr(current))
25992 return;
25993 __exit_idle();
25994 }
25995@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25996 return ret;
25997 }
25998 #endif
25999-void stop_this_cpu(void *dummy)
26000+__noreturn void stop_this_cpu(void *dummy)
26001 {
26002 local_irq_disable();
26003 /*
26004@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26005 }
26006 early_param("idle", idle_setup);
26007
26008-unsigned long arch_align_stack(unsigned long sp)
26009+#ifdef CONFIG_PAX_RANDKSTACK
26010+void pax_randomize_kstack(struct pt_regs *regs)
26011 {
26012- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26013- sp -= get_random_int() % 8192;
26014- return sp & ~0xf;
26015-}
26016+ struct thread_struct *thread = &current->thread;
26017+ unsigned long time;
26018
26019-unsigned long arch_randomize_brk(struct mm_struct *mm)
26020-{
26021- unsigned long range_end = mm->brk + 0x02000000;
26022- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26023-}
26024+ if (!randomize_va_space)
26025+ return;
26026+
26027+ if (v8086_mode(regs))
26028+ return;
26029
26030+ rdtscl(time);
26031+
26032+ /* P4 seems to return a 0 LSB, ignore it */
26033+#ifdef CONFIG_MPENTIUM4
26034+ time &= 0x3EUL;
26035+ time <<= 2;
26036+#elif defined(CONFIG_X86_64)
26037+ time &= 0xFUL;
26038+ time <<= 4;
26039+#else
26040+ time &= 0x1FUL;
26041+ time <<= 3;
26042+#endif
26043+
26044+ thread->sp0 ^= time;
26045+ load_sp0(init_tss + smp_processor_id(), thread);
26046+
26047+#ifdef CONFIG_X86_64
26048+ this_cpu_write(kernel_stack, thread->sp0);
26049+#endif
26050+}
26051+#endif
26052diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26053index 0de43e9..056b840 100644
26054--- a/arch/x86/kernel/process_32.c
26055+++ b/arch/x86/kernel/process_32.c
26056@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26057 unsigned long thread_saved_pc(struct task_struct *tsk)
26058 {
26059 return ((unsigned long *)tsk->thread.sp)[3];
26060+//XXX return tsk->thread.eip;
26061 }
26062
26063 void __show_regs(struct pt_regs *regs, int all)
26064@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26065 unsigned long sp;
26066 unsigned short ss, gs;
26067
26068- if (user_mode_vm(regs)) {
26069+ if (user_mode(regs)) {
26070 sp = regs->sp;
26071 ss = regs->ss & 0xffff;
26072- gs = get_user_gs(regs);
26073 } else {
26074 sp = kernel_stack_pointer(regs);
26075 savesegment(ss, ss);
26076- savesegment(gs, gs);
26077 }
26078+ gs = get_user_gs(regs);
26079
26080 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26081 (u16)regs->cs, regs->ip, regs->flags,
26082- smp_processor_id());
26083+ raw_smp_processor_id());
26084 print_symbol("EIP is at %s\n", regs->ip);
26085
26086 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26087@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26088 int copy_thread(unsigned long clone_flags, unsigned long sp,
26089 unsigned long arg, struct task_struct *p)
26090 {
26091- struct pt_regs *childregs = task_pt_regs(p);
26092+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26093 struct task_struct *tsk;
26094 int err;
26095
26096 p->thread.sp = (unsigned long) childregs;
26097 p->thread.sp0 = (unsigned long) (childregs+1);
26098+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26099
26100 if (unlikely(p->flags & PF_KTHREAD)) {
26101 /* kernel thread */
26102 memset(childregs, 0, sizeof(struct pt_regs));
26103 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26104- task_user_gs(p) = __KERNEL_STACK_CANARY;
26105- childregs->ds = __USER_DS;
26106- childregs->es = __USER_DS;
26107+ savesegment(gs, childregs->gs);
26108+ childregs->ds = __KERNEL_DS;
26109+ childregs->es = __KERNEL_DS;
26110 childregs->fs = __KERNEL_PERCPU;
26111 childregs->bx = sp; /* function */
26112 childregs->bp = arg;
26113@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26114 struct thread_struct *prev = &prev_p->thread,
26115 *next = &next_p->thread;
26116 int cpu = smp_processor_id();
26117- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26118+ struct tss_struct *tss = init_tss + cpu;
26119 fpu_switch_t fpu;
26120
26121 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26122@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26123 */
26124 lazy_save_gs(prev->gs);
26125
26126+#ifdef CONFIG_PAX_MEMORY_UDEREF
26127+ __set_fs(task_thread_info(next_p)->addr_limit);
26128+#endif
26129+
26130 /*
26131 * Load the per-thread Thread-Local Storage descriptor.
26132 */
26133@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26134 */
26135 arch_end_context_switch(next_p);
26136
26137+ this_cpu_write(current_task, next_p);
26138+ this_cpu_write(current_tinfo, &next_p->tinfo);
26139+
26140 /*
26141 * Restore %gs if needed (which is common)
26142 */
26143@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26144
26145 switch_fpu_finish(next_p, fpu);
26146
26147- this_cpu_write(current_task, next_p);
26148-
26149 return prev_p;
26150 }
26151
26152@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26153 } while (count++ < 16);
26154 return 0;
26155 }
26156-
26157diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26158index 9c0280f..5bbb1c0 100644
26159--- a/arch/x86/kernel/process_64.c
26160+++ b/arch/x86/kernel/process_64.c
26161@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26162 struct pt_regs *childregs;
26163 struct task_struct *me = current;
26164
26165- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26166+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26167 childregs = task_pt_regs(p);
26168 p->thread.sp = (unsigned long) childregs;
26169 p->thread.usersp = me->thread.usersp;
26170+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26171 set_tsk_thread_flag(p, TIF_FORK);
26172 p->thread.fpu_counter = 0;
26173 p->thread.io_bitmap_ptr = NULL;
26174@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26175 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26176 savesegment(es, p->thread.es);
26177 savesegment(ds, p->thread.ds);
26178+ savesegment(ss, p->thread.ss);
26179+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26180 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26181
26182 if (unlikely(p->flags & PF_KTHREAD)) {
26183@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26184 struct thread_struct *prev = &prev_p->thread;
26185 struct thread_struct *next = &next_p->thread;
26186 int cpu = smp_processor_id();
26187- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26188+ struct tss_struct *tss = init_tss + cpu;
26189 unsigned fsindex, gsindex;
26190 fpu_switch_t fpu;
26191
26192@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26193 if (unlikely(next->ds | prev->ds))
26194 loadsegment(ds, next->ds);
26195
26196+ savesegment(ss, prev->ss);
26197+ if (unlikely(next->ss != prev->ss))
26198+ loadsegment(ss, next->ss);
26199
26200 /* We must save %fs and %gs before load_TLS() because
26201 * %fs and %gs may be cleared by load_TLS().
26202@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26203 prev->usersp = this_cpu_read(old_rsp);
26204 this_cpu_write(old_rsp, next->usersp);
26205 this_cpu_write(current_task, next_p);
26206+ this_cpu_write(current_tinfo, &next_p->tinfo);
26207
26208 /*
26209 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26210@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26211 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26212 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26213
26214- this_cpu_write(kernel_stack,
26215- (unsigned long)task_stack_page(next_p) +
26216- THREAD_SIZE - KERNEL_STACK_OFFSET);
26217+ this_cpu_write(kernel_stack, next->sp0);
26218
26219 /*
26220 * Now maybe reload the debug registers and handle I/O bitmaps
26221@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26222 if (!p || p == current || p->state == TASK_RUNNING)
26223 return 0;
26224 stack = (unsigned long)task_stack_page(p);
26225- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26226+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26227 return 0;
26228 fp = *(u64 *)(p->thread.sp);
26229 do {
26230- if (fp < (unsigned long)stack ||
26231- fp >= (unsigned long)stack+THREAD_SIZE)
26232+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26233 return 0;
26234 ip = *(u64 *)(fp+8);
26235 if (!in_sched_functions(ip))
26236diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26237index 7461f50..1334029 100644
26238--- a/arch/x86/kernel/ptrace.c
26239+++ b/arch/x86/kernel/ptrace.c
26240@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26241 {
26242 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26243 unsigned long sp = (unsigned long)&regs->sp;
26244- struct thread_info *tinfo;
26245
26246- if (context == (sp & ~(THREAD_SIZE - 1)))
26247+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26248 return sp;
26249
26250- tinfo = (struct thread_info *)context;
26251- if (tinfo->previous_esp)
26252- return tinfo->previous_esp;
26253+ sp = *(unsigned long *)context;
26254+ if (sp)
26255+ return sp;
26256
26257 return (unsigned long)regs;
26258 }
26259@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26260 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26261 {
26262 int i;
26263- int dr7 = 0;
26264+ unsigned long dr7 = 0;
26265 struct arch_hw_breakpoint *info;
26266
26267 for (i = 0; i < HBP_NUM; i++) {
26268@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26269 unsigned long addr, unsigned long data)
26270 {
26271 int ret;
26272- unsigned long __user *datap = (unsigned long __user *)data;
26273+ unsigned long __user *datap = (__force unsigned long __user *)data;
26274
26275 switch (request) {
26276 /* read the word at location addr in the USER area. */
26277@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26278 if ((int) addr < 0)
26279 return -EIO;
26280 ret = do_get_thread_area(child, addr,
26281- (struct user_desc __user *)data);
26282+ (__force struct user_desc __user *) data);
26283 break;
26284
26285 case PTRACE_SET_THREAD_AREA:
26286 if ((int) addr < 0)
26287 return -EIO;
26288 ret = do_set_thread_area(child, addr,
26289- (struct user_desc __user *)data, 0);
26290+ (__force struct user_desc __user *) data, 0);
26291 break;
26292 #endif
26293
26294@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26295
26296 #ifdef CONFIG_X86_64
26297
26298-static struct user_regset x86_64_regsets[] __read_mostly = {
26299+static user_regset_no_const x86_64_regsets[] __read_only = {
26300 [REGSET_GENERAL] = {
26301 .core_note_type = NT_PRSTATUS,
26302 .n = sizeof(struct user_regs_struct) / sizeof(long),
26303@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26304 #endif /* CONFIG_X86_64 */
26305
26306 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26307-static struct user_regset x86_32_regsets[] __read_mostly = {
26308+static user_regset_no_const x86_32_regsets[] __read_only = {
26309 [REGSET_GENERAL] = {
26310 .core_note_type = NT_PRSTATUS,
26311 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26312@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26313 */
26314 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26315
26316-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26317+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26318 {
26319 #ifdef CONFIG_X86_64
26320 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26321@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26322 memset(info, 0, sizeof(*info));
26323 info->si_signo = SIGTRAP;
26324 info->si_code = si_code;
26325- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26326+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26327 }
26328
26329 void user_single_step_siginfo(struct task_struct *tsk,
26330@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26331 # define IS_IA32 0
26332 #endif
26333
26334+#ifdef CONFIG_GRKERNSEC_SETXID
26335+extern void gr_delayed_cred_worker(void);
26336+#endif
26337+
26338 /*
26339 * We must return the syscall number to actually look up in the table.
26340 * This can be -1L to skip running any syscall at all.
26341@@ -1460,6 +1463,11 @@ long syscall_trace_enter(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 /*
26351 * If we stepped into a sysenter/syscall insn, it trapped in
26352 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26353@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26354 */
26355 user_exit();
26356
26357+#ifdef CONFIG_GRKERNSEC_SETXID
26358+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26359+ gr_delayed_cred_worker();
26360+#endif
26361+
26362 audit_syscall_exit(regs);
26363
26364 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26365diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26366index 2f355d2..e75ed0a 100644
26367--- a/arch/x86/kernel/pvclock.c
26368+++ b/arch/x86/kernel/pvclock.c
26369@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26370 reset_hung_task_detector();
26371 }
26372
26373-static atomic64_t last_value = ATOMIC64_INIT(0);
26374+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26375
26376 void pvclock_resume(void)
26377 {
26378- atomic64_set(&last_value, 0);
26379+ atomic64_set_unchecked(&last_value, 0);
26380 }
26381
26382 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26383@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26384 * updating at the same time, and one of them could be slightly behind,
26385 * making the assumption that last_value always go forward fail to hold.
26386 */
26387- last = atomic64_read(&last_value);
26388+ last = atomic64_read_unchecked(&last_value);
26389 do {
26390 if (ret < last)
26391 return last;
26392- last = atomic64_cmpxchg(&last_value, last, ret);
26393+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26394 } while (unlikely(last != ret));
26395
26396 return ret;
26397diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26398index c752cb4..866c432 100644
26399--- a/arch/x86/kernel/reboot.c
26400+++ b/arch/x86/kernel/reboot.c
26401@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26402
26403 void __noreturn machine_real_restart(unsigned int type)
26404 {
26405+
26406+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26407+ struct desc_struct *gdt;
26408+#endif
26409+
26410 local_irq_disable();
26411
26412 /*
26413@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26414
26415 /* Jump to the identity-mapped low memory code */
26416 #ifdef CONFIG_X86_32
26417- asm volatile("jmpl *%0" : :
26418+
26419+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26420+ gdt = get_cpu_gdt_table(smp_processor_id());
26421+ pax_open_kernel();
26422+#ifdef CONFIG_PAX_MEMORY_UDEREF
26423+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26424+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26425+ loadsegment(ds, __KERNEL_DS);
26426+ loadsegment(es, __KERNEL_DS);
26427+ loadsegment(ss, __KERNEL_DS);
26428+#endif
26429+#ifdef CONFIG_PAX_KERNEXEC
26430+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26431+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26432+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26433+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26434+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26435+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26436+#endif
26437+ pax_close_kernel();
26438+#endif
26439+
26440+ asm volatile("ljmpl *%0" : :
26441 "rm" (real_mode_header->machine_real_restart_asm),
26442 "a" (type));
26443 #else
26444@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26445 * try to force a triple fault and then cycle between hitting the keyboard
26446 * controller and doing that
26447 */
26448-static void native_machine_emergency_restart(void)
26449+static void __noreturn native_machine_emergency_restart(void)
26450 {
26451 int i;
26452 int attempt = 0;
26453@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26454 #endif
26455 }
26456
26457-static void __machine_emergency_restart(int emergency)
26458+static void __noreturn __machine_emergency_restart(int emergency)
26459 {
26460 reboot_emergency = emergency;
26461 machine_ops.emergency_restart();
26462 }
26463
26464-static void native_machine_restart(char *__unused)
26465+static void __noreturn native_machine_restart(char *__unused)
26466 {
26467 pr_notice("machine restart\n");
26468
26469@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26470 __machine_emergency_restart(0);
26471 }
26472
26473-static void native_machine_halt(void)
26474+static void __noreturn native_machine_halt(void)
26475 {
26476 /* Stop other cpus and apics */
26477 machine_shutdown();
26478@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26479 stop_this_cpu(NULL);
26480 }
26481
26482-static void native_machine_power_off(void)
26483+static void __noreturn native_machine_power_off(void)
26484 {
26485 if (pm_power_off) {
26486 if (!reboot_force)
26487@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26488 }
26489 /* A fallback in case there is no PM info available */
26490 tboot_shutdown(TB_SHUTDOWN_HALT);
26491+ unreachable();
26492 }
26493
26494-struct machine_ops machine_ops = {
26495+struct machine_ops machine_ops __read_only = {
26496 .power_off = native_machine_power_off,
26497 .shutdown = native_machine_shutdown,
26498 .emergency_restart = native_machine_emergency_restart,
26499diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26500index c8e41e9..64049ef 100644
26501--- a/arch/x86/kernel/reboot_fixups_32.c
26502+++ b/arch/x86/kernel/reboot_fixups_32.c
26503@@ -57,7 +57,7 @@ struct device_fixup {
26504 unsigned int vendor;
26505 unsigned int device;
26506 void (*reboot_fixup)(struct pci_dev *);
26507-};
26508+} __do_const;
26509
26510 /*
26511 * PCI ids solely used for fixups_table go here
26512diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26513index 3fd2c69..a444264 100644
26514--- a/arch/x86/kernel/relocate_kernel_64.S
26515+++ b/arch/x86/kernel/relocate_kernel_64.S
26516@@ -96,8 +96,7 @@ relocate_kernel:
26517
26518 /* jump to identity mapped page */
26519 addq $(identity_mapped - relocate_kernel), %r8
26520- pushq %r8
26521- ret
26522+ jmp *%r8
26523
26524 identity_mapped:
26525 /* set return address to 0 if not preserving context */
26526diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26527index ce72964..be8aea7 100644
26528--- a/arch/x86/kernel/setup.c
26529+++ b/arch/x86/kernel/setup.c
26530@@ -110,6 +110,7 @@
26531 #include <asm/mce.h>
26532 #include <asm/alternative.h>
26533 #include <asm/prom.h>
26534+#include <asm/boot.h>
26535
26536 /*
26537 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26538@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26539 #endif
26540
26541
26542-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26543-__visible unsigned long mmu_cr4_features;
26544+#ifdef CONFIG_X86_64
26545+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26546+#elif defined(CONFIG_X86_PAE)
26547+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26548 #else
26549-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26550+__visible unsigned long mmu_cr4_features __read_only;
26551 #endif
26552
26553+void set_in_cr4(unsigned long mask)
26554+{
26555+ unsigned long cr4 = read_cr4();
26556+
26557+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26558+ return;
26559+
26560+ pax_open_kernel();
26561+ mmu_cr4_features |= mask;
26562+ pax_close_kernel();
26563+
26564+ if (trampoline_cr4_features)
26565+ *trampoline_cr4_features = mmu_cr4_features;
26566+ cr4 |= mask;
26567+ write_cr4(cr4);
26568+}
26569+EXPORT_SYMBOL(set_in_cr4);
26570+
26571+void clear_in_cr4(unsigned long mask)
26572+{
26573+ unsigned long cr4 = read_cr4();
26574+
26575+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26576+ return;
26577+
26578+ pax_open_kernel();
26579+ mmu_cr4_features &= ~mask;
26580+ pax_close_kernel();
26581+
26582+ if (trampoline_cr4_features)
26583+ *trampoline_cr4_features = mmu_cr4_features;
26584+ cr4 &= ~mask;
26585+ write_cr4(cr4);
26586+}
26587+EXPORT_SYMBOL(clear_in_cr4);
26588+
26589 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26590 int bootloader_type, bootloader_version;
26591
26592@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26593 * area (640->1Mb) as ram even though it is not.
26594 * take them out.
26595 */
26596- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26597+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26598
26599 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26600 }
26601@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26602 /* called before trim_bios_range() to spare extra sanitize */
26603 static void __init e820_add_kernel_range(void)
26604 {
26605- u64 start = __pa_symbol(_text);
26606+ u64 start = __pa_symbol(ktla_ktva(_text));
26607 u64 size = __pa_symbol(_end) - start;
26608
26609 /*
26610@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26611
26612 void __init setup_arch(char **cmdline_p)
26613 {
26614+#ifdef CONFIG_X86_32
26615+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26616+#else
26617 memblock_reserve(__pa_symbol(_text),
26618 (unsigned long)__bss_stop - (unsigned long)_text);
26619+#endif
26620
26621 early_reserve_initrd();
26622
26623@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26624
26625 if (!boot_params.hdr.root_flags)
26626 root_mountflags &= ~MS_RDONLY;
26627- init_mm.start_code = (unsigned long) _text;
26628- init_mm.end_code = (unsigned long) _etext;
26629+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26630+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26631 init_mm.end_data = (unsigned long) _edata;
26632 init_mm.brk = _brk_end;
26633
26634- code_resource.start = __pa_symbol(_text);
26635- code_resource.end = __pa_symbol(_etext)-1;
26636- data_resource.start = __pa_symbol(_etext);
26637+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26638+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26639+ data_resource.start = __pa_symbol(_sdata);
26640 data_resource.end = __pa_symbol(_edata)-1;
26641 bss_resource.start = __pa_symbol(__bss_start);
26642 bss_resource.end = __pa_symbol(__bss_stop)-1;
26643diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26644index 5cdff03..80fa283 100644
26645--- a/arch/x86/kernel/setup_percpu.c
26646+++ b/arch/x86/kernel/setup_percpu.c
26647@@ -21,19 +21,17 @@
26648 #include <asm/cpu.h>
26649 #include <asm/stackprotector.h>
26650
26651-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26652+#ifdef CONFIG_SMP
26653+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26654 EXPORT_PER_CPU_SYMBOL(cpu_number);
26655+#endif
26656
26657-#ifdef CONFIG_X86_64
26658 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26659-#else
26660-#define BOOT_PERCPU_OFFSET 0
26661-#endif
26662
26663 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26664 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26665
26666-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26667+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26668 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26669 };
26670 EXPORT_SYMBOL(__per_cpu_offset);
26671@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26672 {
26673 #ifdef CONFIG_NEED_MULTIPLE_NODES
26674 pg_data_t *last = NULL;
26675- unsigned int cpu;
26676+ int cpu;
26677
26678 for_each_possible_cpu(cpu) {
26679 int node = early_cpu_to_node(cpu);
26680@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26681 {
26682 #ifdef CONFIG_X86_32
26683 struct desc_struct gdt;
26684+ unsigned long base = per_cpu_offset(cpu);
26685
26686- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26687- 0x2 | DESCTYPE_S, 0x8);
26688- gdt.s = 1;
26689+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26690+ 0x83 | DESCTYPE_S, 0xC);
26691 write_gdt_entry(get_cpu_gdt_table(cpu),
26692 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26693 #endif
26694@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26695 /* alrighty, percpu areas up and running */
26696 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26697 for_each_possible_cpu(cpu) {
26698+#ifdef CONFIG_CC_STACKPROTECTOR
26699+#ifdef CONFIG_X86_32
26700+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26701+#endif
26702+#endif
26703 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26704 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26705 per_cpu(cpu_number, cpu) = cpu;
26706@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26707 */
26708 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26709 #endif
26710+#ifdef CONFIG_CC_STACKPROTECTOR
26711+#ifdef CONFIG_X86_32
26712+ if (!cpu)
26713+ per_cpu(stack_canary.canary, cpu) = canary;
26714+#endif
26715+#endif
26716 /*
26717 * Up to this point, the boot CPU has been using .init.data
26718 * area. Reload any changed state for the boot CPU.
26719diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26720index 9e5de68..16c53cb 100644
26721--- a/arch/x86/kernel/signal.c
26722+++ b/arch/x86/kernel/signal.c
26723@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26724 * Align the stack pointer according to the i386 ABI,
26725 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26726 */
26727- sp = ((sp + 4) & -16ul) - 4;
26728+ sp = ((sp - 12) & -16ul) - 4;
26729 #else /* !CONFIG_X86_32 */
26730 sp = round_down(sp, 16) - 8;
26731 #endif
26732@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26733 }
26734
26735 if (current->mm->context.vdso)
26736- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26737+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26738 else
26739- restorer = &frame->retcode;
26740+ restorer = (void __user *)&frame->retcode;
26741 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26742 restorer = ksig->ka.sa.sa_restorer;
26743
26744@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26745 * reasons and because gdb uses it as a signature to notice
26746 * signal handler stack frames.
26747 */
26748- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26749+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26750
26751 if (err)
26752 return -EFAULT;
26753@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26754 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26755
26756 /* Set up to return from userspace. */
26757- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26758+ if (current->mm->context.vdso)
26759+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26760+ else
26761+ restorer = (void __user *)&frame->retcode;
26762 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26763 restorer = ksig->ka.sa.sa_restorer;
26764 put_user_ex(restorer, &frame->pretcode);
26765@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26766 * reasons and because gdb uses it as a signature to notice
26767 * signal handler stack frames.
26768 */
26769- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26770+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26771 } put_user_catch(err);
26772
26773 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26774@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26775 {
26776 int usig = signr_convert(ksig->sig);
26777 sigset_t *set = sigmask_to_save();
26778- compat_sigset_t *cset = (compat_sigset_t *) set;
26779+ sigset_t sigcopy;
26780+ compat_sigset_t *cset;
26781+
26782+ sigcopy = *set;
26783+
26784+ cset = (compat_sigset_t *) &sigcopy;
26785
26786 /* Set up the stack frame */
26787 if (is_ia32_frame()) {
26788@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26789 } else if (is_x32_frame()) {
26790 return x32_setup_rt_frame(ksig, cset, regs);
26791 } else {
26792- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26793+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26794 }
26795 }
26796
26797diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26798index 7c3a5a6..f0a8961 100644
26799--- a/arch/x86/kernel/smp.c
26800+++ b/arch/x86/kernel/smp.c
26801@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26802
26803 __setup("nonmi_ipi", nonmi_ipi_setup);
26804
26805-struct smp_ops smp_ops = {
26806+struct smp_ops smp_ops __read_only = {
26807 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26808 .smp_prepare_cpus = native_smp_prepare_cpus,
26809 .smp_cpus_done = native_smp_cpus_done,
26810diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26811index a32da80..30c97f1 100644
26812--- a/arch/x86/kernel/smpboot.c
26813+++ b/arch/x86/kernel/smpboot.c
26814@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26815
26816 enable_start_cpu0 = 0;
26817
26818-#ifdef CONFIG_X86_32
26819- /* switch away from the initial page table */
26820- load_cr3(swapper_pg_dir);
26821- __flush_tlb_all();
26822-#endif
26823-
26824 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26825 barrier();
26826+
26827+ /* switch away from the initial page table */
26828+#ifdef CONFIG_PAX_PER_CPU_PGD
26829+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26830+ __flush_tlb_all();
26831+#elif defined(CONFIG_X86_32)
26832+ load_cr3(swapper_pg_dir);
26833+ __flush_tlb_all();
26834+#endif
26835+
26836 /*
26837 * Check TSC synchronization with the BP:
26838 */
26839@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26840 alternatives_enable_smp();
26841
26842 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26843- (THREAD_SIZE + task_stack_page(idle))) - 1);
26844+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26845 per_cpu(current_task, cpu) = idle;
26846+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26847
26848 #ifdef CONFIG_X86_32
26849 /* Stack for startup_32 can be just as for start_secondary onwards */
26850@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26851 #else
26852 clear_tsk_thread_flag(idle, TIF_FORK);
26853 initial_gs = per_cpu_offset(cpu);
26854- per_cpu(kernel_stack, cpu) =
26855- (unsigned long)task_stack_page(idle) -
26856- KERNEL_STACK_OFFSET + THREAD_SIZE;
26857+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26858 #endif
26859+
26860+ pax_open_kernel();
26861 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26862+ pax_close_kernel();
26863+
26864 initial_code = (unsigned long)start_secondary;
26865 stack_start = idle->thread.sp;
26866
26867@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26868 /* the FPU context is blank, nobody can own it */
26869 __cpu_disable_lazy_restore(cpu);
26870
26871+#ifdef CONFIG_PAX_PER_CPU_PGD
26872+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26873+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26874+ KERNEL_PGD_PTRS);
26875+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26876+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26877+ KERNEL_PGD_PTRS);
26878+#endif
26879+
26880 err = do_boot_cpu(apicid, cpu, tidle);
26881 if (err) {
26882 pr_debug("do_boot_cpu failed %d\n", err);
26883diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26884index 9b4d51d..5d28b58 100644
26885--- a/arch/x86/kernel/step.c
26886+++ b/arch/x86/kernel/step.c
26887@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26888 struct desc_struct *desc;
26889 unsigned long base;
26890
26891- seg &= ~7UL;
26892+ seg >>= 3;
26893
26894 mutex_lock(&child->mm->context.lock);
26895- if (unlikely((seg >> 3) >= child->mm->context.size))
26896+ if (unlikely(seg >= child->mm->context.size))
26897 addr = -1L; /* bogus selector, access would fault */
26898 else {
26899 desc = child->mm->context.ldt + seg;
26900@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26901 addr += base;
26902 }
26903 mutex_unlock(&child->mm->context.lock);
26904- }
26905+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26906+ addr = ktla_ktva(addr);
26907
26908 return addr;
26909 }
26910@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26911 unsigned char opcode[15];
26912 unsigned long addr = convert_ip_to_linear(child, regs);
26913
26914+ if (addr == -EINVAL)
26915+ return 0;
26916+
26917 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26918 for (i = 0; i < copied; i++) {
26919 switch (opcode[i]) {
26920diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26921new file mode 100644
26922index 0000000..5877189
26923--- /dev/null
26924+++ b/arch/x86/kernel/sys_i386_32.c
26925@@ -0,0 +1,189 @@
26926+/*
26927+ * This file contains various random system calls that
26928+ * have a non-standard calling sequence on the Linux/i386
26929+ * platform.
26930+ */
26931+
26932+#include <linux/errno.h>
26933+#include <linux/sched.h>
26934+#include <linux/mm.h>
26935+#include <linux/fs.h>
26936+#include <linux/smp.h>
26937+#include <linux/sem.h>
26938+#include <linux/msg.h>
26939+#include <linux/shm.h>
26940+#include <linux/stat.h>
26941+#include <linux/syscalls.h>
26942+#include <linux/mman.h>
26943+#include <linux/file.h>
26944+#include <linux/utsname.h>
26945+#include <linux/ipc.h>
26946+#include <linux/elf.h>
26947+
26948+#include <linux/uaccess.h>
26949+#include <linux/unistd.h>
26950+
26951+#include <asm/syscalls.h>
26952+
26953+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26954+{
26955+ unsigned long pax_task_size = TASK_SIZE;
26956+
26957+#ifdef CONFIG_PAX_SEGMEXEC
26958+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26959+ pax_task_size = SEGMEXEC_TASK_SIZE;
26960+#endif
26961+
26962+ if (flags & MAP_FIXED)
26963+ if (len > pax_task_size || addr > pax_task_size - len)
26964+ return -EINVAL;
26965+
26966+ return 0;
26967+}
26968+
26969+/*
26970+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26971+ */
26972+static unsigned long get_align_mask(void)
26973+{
26974+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26975+ return 0;
26976+
26977+ if (!(current->flags & PF_RANDOMIZE))
26978+ return 0;
26979+
26980+ return va_align.mask;
26981+}
26982+
26983+unsigned long
26984+arch_get_unmapped_area(struct file *filp, unsigned long addr,
26985+ unsigned long len, unsigned long pgoff, unsigned long flags)
26986+{
26987+ struct mm_struct *mm = current->mm;
26988+ struct vm_area_struct *vma;
26989+ unsigned long pax_task_size = TASK_SIZE;
26990+ struct vm_unmapped_area_info info;
26991+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26992+
26993+#ifdef CONFIG_PAX_SEGMEXEC
26994+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26995+ pax_task_size = SEGMEXEC_TASK_SIZE;
26996+#endif
26997+
26998+ pax_task_size -= PAGE_SIZE;
26999+
27000+ if (len > pax_task_size)
27001+ return -ENOMEM;
27002+
27003+ if (flags & MAP_FIXED)
27004+ return addr;
27005+
27006+#ifdef CONFIG_PAX_RANDMMAP
27007+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27008+#endif
27009+
27010+ if (addr) {
27011+ addr = PAGE_ALIGN(addr);
27012+ if (pax_task_size - len >= addr) {
27013+ vma = find_vma(mm, addr);
27014+ if (check_heap_stack_gap(vma, addr, len, offset))
27015+ return addr;
27016+ }
27017+ }
27018+
27019+ info.flags = 0;
27020+ info.length = len;
27021+ info.align_mask = filp ? get_align_mask() : 0;
27022+ info.align_offset = pgoff << PAGE_SHIFT;
27023+ info.threadstack_offset = offset;
27024+
27025+#ifdef CONFIG_PAX_PAGEEXEC
27026+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27027+ info.low_limit = 0x00110000UL;
27028+ info.high_limit = mm->start_code;
27029+
27030+#ifdef CONFIG_PAX_RANDMMAP
27031+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27032+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27033+#endif
27034+
27035+ if (info.low_limit < info.high_limit) {
27036+ addr = vm_unmapped_area(&info);
27037+ if (!IS_ERR_VALUE(addr))
27038+ return addr;
27039+ }
27040+ } else
27041+#endif
27042+
27043+ info.low_limit = mm->mmap_base;
27044+ info.high_limit = pax_task_size;
27045+
27046+ return vm_unmapped_area(&info);
27047+}
27048+
27049+unsigned long
27050+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27051+ const unsigned long len, const unsigned long pgoff,
27052+ const unsigned long flags)
27053+{
27054+ struct vm_area_struct *vma;
27055+ struct mm_struct *mm = current->mm;
27056+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27057+ struct vm_unmapped_area_info info;
27058+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27059+
27060+#ifdef CONFIG_PAX_SEGMEXEC
27061+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27062+ pax_task_size = SEGMEXEC_TASK_SIZE;
27063+#endif
27064+
27065+ pax_task_size -= PAGE_SIZE;
27066+
27067+ /* requested length too big for entire address space */
27068+ if (len > pax_task_size)
27069+ return -ENOMEM;
27070+
27071+ if (flags & MAP_FIXED)
27072+ return addr;
27073+
27074+#ifdef CONFIG_PAX_PAGEEXEC
27075+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27076+ goto bottomup;
27077+#endif
27078+
27079+#ifdef CONFIG_PAX_RANDMMAP
27080+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27081+#endif
27082+
27083+ /* requesting a specific address */
27084+ if (addr) {
27085+ addr = PAGE_ALIGN(addr);
27086+ if (pax_task_size - len >= addr) {
27087+ vma = find_vma(mm, addr);
27088+ if (check_heap_stack_gap(vma, addr, len, offset))
27089+ return addr;
27090+ }
27091+ }
27092+
27093+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27094+ info.length = len;
27095+ info.low_limit = PAGE_SIZE;
27096+ info.high_limit = mm->mmap_base;
27097+ info.align_mask = filp ? get_align_mask() : 0;
27098+ info.align_offset = pgoff << PAGE_SHIFT;
27099+ info.threadstack_offset = offset;
27100+
27101+ addr = vm_unmapped_area(&info);
27102+ if (!(addr & ~PAGE_MASK))
27103+ return addr;
27104+ VM_BUG_ON(addr != -ENOMEM);
27105+
27106+bottomup:
27107+ /*
27108+ * A failed mmap() very likely causes application failure,
27109+ * so fall back to the bottom-up function here. This scenario
27110+ * can happen with large stack limits and large mmap()
27111+ * allocations.
27112+ */
27113+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27114+}
27115diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27116index 30277e2..5664a29 100644
27117--- a/arch/x86/kernel/sys_x86_64.c
27118+++ b/arch/x86/kernel/sys_x86_64.c
27119@@ -81,8 +81,8 @@ out:
27120 return error;
27121 }
27122
27123-static void find_start_end(unsigned long flags, unsigned long *begin,
27124- unsigned long *end)
27125+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27126+ unsigned long *begin, unsigned long *end)
27127 {
27128 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27129 unsigned long new_begin;
27130@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27131 *begin = new_begin;
27132 }
27133 } else {
27134- *begin = current->mm->mmap_legacy_base;
27135+ *begin = mm->mmap_legacy_base;
27136 *end = TASK_SIZE;
27137 }
27138 }
27139@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27140 struct vm_area_struct *vma;
27141 struct vm_unmapped_area_info info;
27142 unsigned long begin, end;
27143+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27144
27145 if (flags & MAP_FIXED)
27146 return addr;
27147
27148- find_start_end(flags, &begin, &end);
27149+ find_start_end(mm, flags, &begin, &end);
27150
27151 if (len > end)
27152 return -ENOMEM;
27153
27154+#ifdef CONFIG_PAX_RANDMMAP
27155+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27156+#endif
27157+
27158 if (addr) {
27159 addr = PAGE_ALIGN(addr);
27160 vma = find_vma(mm, addr);
27161- if (end - len >= addr &&
27162- (!vma || addr + len <= vma->vm_start))
27163+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27164 return addr;
27165 }
27166
27167@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27168 info.high_limit = end;
27169 info.align_mask = filp ? get_align_mask() : 0;
27170 info.align_offset = pgoff << PAGE_SHIFT;
27171+ info.threadstack_offset = offset;
27172 return vm_unmapped_area(&info);
27173 }
27174
27175@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27176 struct mm_struct *mm = current->mm;
27177 unsigned long addr = addr0;
27178 struct vm_unmapped_area_info info;
27179+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27180
27181 /* requested length too big for entire address space */
27182 if (len > TASK_SIZE)
27183@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27184 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27185 goto bottomup;
27186
27187+#ifdef CONFIG_PAX_RANDMMAP
27188+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27189+#endif
27190+
27191 /* requesting a specific address */
27192 if (addr) {
27193 addr = PAGE_ALIGN(addr);
27194 vma = find_vma(mm, addr);
27195- if (TASK_SIZE - len >= addr &&
27196- (!vma || addr + len <= vma->vm_start))
27197+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27198 return addr;
27199 }
27200
27201@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27202 info.high_limit = mm->mmap_base;
27203 info.align_mask = filp ? get_align_mask() : 0;
27204 info.align_offset = pgoff << PAGE_SHIFT;
27205+ info.threadstack_offset = offset;
27206 addr = vm_unmapped_area(&info);
27207 if (!(addr & ~PAGE_MASK))
27208 return addr;
27209diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27210index 91a4496..bb87552 100644
27211--- a/arch/x86/kernel/tboot.c
27212+++ b/arch/x86/kernel/tboot.c
27213@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27214
27215 void tboot_shutdown(u32 shutdown_type)
27216 {
27217- void (*shutdown)(void);
27218+ void (* __noreturn shutdown)(void);
27219
27220 if (!tboot_enabled())
27221 return;
27222@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27223
27224 switch_to_tboot_pt();
27225
27226- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27227+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27228 shutdown();
27229
27230 /* should not reach here */
27231@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27232 return -ENODEV;
27233 }
27234
27235-static atomic_t ap_wfs_count;
27236+static atomic_unchecked_t ap_wfs_count;
27237
27238 static int tboot_wait_for_aps(int num_aps)
27239 {
27240@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27241 {
27242 switch (action) {
27243 case CPU_DYING:
27244- atomic_inc(&ap_wfs_count);
27245+ atomic_inc_unchecked(&ap_wfs_count);
27246 if (num_online_cpus() == 1)
27247- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27248+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27249 return NOTIFY_BAD;
27250 break;
27251 }
27252@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27253
27254 tboot_create_trampoline();
27255
27256- atomic_set(&ap_wfs_count, 0);
27257+ atomic_set_unchecked(&ap_wfs_count, 0);
27258 register_hotcpu_notifier(&tboot_cpu_notifier);
27259
27260 #ifdef CONFIG_DEBUG_FS
27261diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27262index 24d3c91..d06b473 100644
27263--- a/arch/x86/kernel/time.c
27264+++ b/arch/x86/kernel/time.c
27265@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27266 {
27267 unsigned long pc = instruction_pointer(regs);
27268
27269- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27270+ if (!user_mode(regs) && in_lock_functions(pc)) {
27271 #ifdef CONFIG_FRAME_POINTER
27272- return *(unsigned long *)(regs->bp + sizeof(long));
27273+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27274 #else
27275 unsigned long *sp =
27276 (unsigned long *)kernel_stack_pointer(regs);
27277@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27278 * or above a saved flags. Eflags has bits 22-31 zero,
27279 * kernel addresses don't.
27280 */
27281+
27282+#ifdef CONFIG_PAX_KERNEXEC
27283+ return ktla_ktva(sp[0]);
27284+#else
27285 if (sp[0] >> 22)
27286 return sp[0];
27287 if (sp[1] >> 22)
27288 return sp[1];
27289 #endif
27290+
27291+#endif
27292 }
27293 return pc;
27294 }
27295diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27296index f7fec09..9991981 100644
27297--- a/arch/x86/kernel/tls.c
27298+++ b/arch/x86/kernel/tls.c
27299@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27300 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27301 return -EINVAL;
27302
27303+#ifdef CONFIG_PAX_SEGMEXEC
27304+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27305+ return -EINVAL;
27306+#endif
27307+
27308 set_tls_desc(p, idx, &info, 1);
27309
27310 return 0;
27311@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27312
27313 if (kbuf)
27314 info = kbuf;
27315- else if (__copy_from_user(infobuf, ubuf, count))
27316+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27317 return -EFAULT;
27318 else
27319 info = infobuf;
27320diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27321index 1c113db..287b42e 100644
27322--- a/arch/x86/kernel/tracepoint.c
27323+++ b/arch/x86/kernel/tracepoint.c
27324@@ -9,11 +9,11 @@
27325 #include <linux/atomic.h>
27326
27327 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27328-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27329+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27330 (unsigned long) trace_idt_table };
27331
27332 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27333-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27334+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27335
27336 static int trace_irq_vector_refcount;
27337 static DEFINE_MUTEX(irq_vector_mutex);
27338diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27339index 57409f6..e2c17e1 100644
27340--- a/arch/x86/kernel/traps.c
27341+++ b/arch/x86/kernel/traps.c
27342@@ -66,7 +66,7 @@
27343 #include <asm/proto.h>
27344
27345 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27346-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27347+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27348 #else
27349 #include <asm/processor-flags.h>
27350 #include <asm/setup.h>
27351@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27352 #endif
27353
27354 /* Must be page-aligned because the real IDT is used in a fixmap. */
27355-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27356+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27357
27358 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27359 EXPORT_SYMBOL_GPL(used_vectors);
27360@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27361 }
27362
27363 static int __kprobes
27364-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27365+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27366 struct pt_regs *regs, long error_code)
27367 {
27368 #ifdef CONFIG_X86_32
27369- if (regs->flags & X86_VM_MASK) {
27370+ if (v8086_mode(regs)) {
27371 /*
27372 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27373 * On nmi (interrupt 2), do_trap should not be called.
27374@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27375 return -1;
27376 }
27377 #endif
27378- if (!user_mode(regs)) {
27379+ if (!user_mode_novm(regs)) {
27380 if (!fixup_exception(regs)) {
27381 tsk->thread.error_code = error_code;
27382 tsk->thread.trap_nr = trapnr;
27383+
27384+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27385+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27386+ str = "PAX: suspicious stack segment fault";
27387+#endif
27388+
27389 die(str, regs, error_code);
27390 }
27391+
27392+#ifdef CONFIG_PAX_REFCOUNT
27393+ if (trapnr == X86_TRAP_OF)
27394+ pax_report_refcount_overflow(regs);
27395+#endif
27396+
27397 return 0;
27398 }
27399
27400@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27401 }
27402
27403 static void __kprobes
27404-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27405+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27406 long error_code, siginfo_t *info)
27407 {
27408 struct task_struct *tsk = current;
27409@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27410 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27411 printk_ratelimit()) {
27412 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27413- tsk->comm, tsk->pid, str,
27414+ tsk->comm, task_pid_nr(tsk), str,
27415 regs->ip, regs->sp, error_code);
27416 print_vma_addr(" in ", regs->ip);
27417 pr_cont("\n");
27418@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27419 conditional_sti(regs);
27420
27421 #ifdef CONFIG_X86_32
27422- if (regs->flags & X86_VM_MASK) {
27423+ if (v8086_mode(regs)) {
27424 local_irq_enable();
27425 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27426 goto exit;
27427@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27428 #endif
27429
27430 tsk = current;
27431- if (!user_mode(regs)) {
27432+ if (!user_mode_novm(regs)) {
27433 if (fixup_exception(regs))
27434 goto exit;
27435
27436 tsk->thread.error_code = error_code;
27437 tsk->thread.trap_nr = X86_TRAP_GP;
27438 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27439- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27440+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27441+
27442+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27443+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27444+ die("PAX: suspicious general protection fault", regs, error_code);
27445+ else
27446+#endif
27447+
27448 die("general protection fault", regs, error_code);
27449+ }
27450 goto exit;
27451 }
27452
27453+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27454+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27455+ struct mm_struct *mm = tsk->mm;
27456+ unsigned long limit;
27457+
27458+ down_write(&mm->mmap_sem);
27459+ limit = mm->context.user_cs_limit;
27460+ if (limit < TASK_SIZE) {
27461+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27462+ up_write(&mm->mmap_sem);
27463+ return;
27464+ }
27465+ up_write(&mm->mmap_sem);
27466+ }
27467+#endif
27468+
27469 tsk->thread.error_code = error_code;
27470 tsk->thread.trap_nr = X86_TRAP_GP;
27471
27472@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27473 /* It's safe to allow irq's after DR6 has been saved */
27474 preempt_conditional_sti(regs);
27475
27476- if (regs->flags & X86_VM_MASK) {
27477+ if (v8086_mode(regs)) {
27478 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27479 X86_TRAP_DB);
27480 preempt_conditional_cli(regs);
27481@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27482 * We already checked v86 mode above, so we can check for kernel mode
27483 * by just checking the CPL of CS.
27484 */
27485- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27486+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27487 tsk->thread.debugreg6 &= ~DR_STEP;
27488 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27489 regs->flags &= ~X86_EFLAGS_TF;
27490@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27491 return;
27492 conditional_sti(regs);
27493
27494- if (!user_mode_vm(regs))
27495+ if (!user_mode(regs))
27496 {
27497 if (!fixup_exception(regs)) {
27498 task->thread.error_code = error_code;
27499diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27500index cfbe99f..a6e8fa7 100644
27501--- a/arch/x86/kernel/tsc.c
27502+++ b/arch/x86/kernel/tsc.c
27503@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27504 */
27505 smp_wmb();
27506
27507- ACCESS_ONCE(c2n->head) = data;
27508+ ACCESS_ONCE_RW(c2n->head) = data;
27509 }
27510
27511 /*
27512diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27513index 2ed8459..7cf329f 100644
27514--- a/arch/x86/kernel/uprobes.c
27515+++ b/arch/x86/kernel/uprobes.c
27516@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27517 int ret = NOTIFY_DONE;
27518
27519 /* We are only interested in userspace traps */
27520- if (regs && !user_mode_vm(regs))
27521+ if (regs && !user_mode(regs))
27522 return NOTIFY_DONE;
27523
27524 switch (val) {
27525@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27526
27527 if (ncopied != rasize) {
27528 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27529- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27530+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27531
27532 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27533 }
27534diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27535index b9242ba..50c5edd 100644
27536--- a/arch/x86/kernel/verify_cpu.S
27537+++ b/arch/x86/kernel/verify_cpu.S
27538@@ -20,6 +20,7 @@
27539 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27540 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27541 * arch/x86/kernel/head_32.S: processor startup
27542+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27543 *
27544 * verify_cpu, returns the status of longmode and SSE in register %eax.
27545 * 0: Success 1: Failure
27546diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27547index e8edcf5..27f9344 100644
27548--- a/arch/x86/kernel/vm86_32.c
27549+++ b/arch/x86/kernel/vm86_32.c
27550@@ -44,6 +44,7 @@
27551 #include <linux/ptrace.h>
27552 #include <linux/audit.h>
27553 #include <linux/stddef.h>
27554+#include <linux/grsecurity.h>
27555
27556 #include <asm/uaccess.h>
27557 #include <asm/io.h>
27558@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27559 do_exit(SIGSEGV);
27560 }
27561
27562- tss = &per_cpu(init_tss, get_cpu());
27563+ tss = init_tss + get_cpu();
27564 current->thread.sp0 = current->thread.saved_sp0;
27565 current->thread.sysenter_cs = __KERNEL_CS;
27566 load_sp0(tss, &current->thread);
27567@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27568
27569 if (tsk->thread.saved_sp0)
27570 return -EPERM;
27571+
27572+#ifdef CONFIG_GRKERNSEC_VM86
27573+ if (!capable(CAP_SYS_RAWIO)) {
27574+ gr_handle_vm86();
27575+ return -EPERM;
27576+ }
27577+#endif
27578+
27579 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27580 offsetof(struct kernel_vm86_struct, vm86plus) -
27581 sizeof(info.regs));
27582@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27583 int tmp;
27584 struct vm86plus_struct __user *v86;
27585
27586+#ifdef CONFIG_GRKERNSEC_VM86
27587+ if (!capable(CAP_SYS_RAWIO)) {
27588+ gr_handle_vm86();
27589+ return -EPERM;
27590+ }
27591+#endif
27592+
27593 tsk = current;
27594 switch (cmd) {
27595 case VM86_REQUEST_IRQ:
27596@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27597 tsk->thread.saved_fs = info->regs32->fs;
27598 tsk->thread.saved_gs = get_user_gs(info->regs32);
27599
27600- tss = &per_cpu(init_tss, get_cpu());
27601+ tss = init_tss + get_cpu();
27602 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27603 if (cpu_has_sep)
27604 tsk->thread.sysenter_cs = 0;
27605@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27606 goto cannot_handle;
27607 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27608 goto cannot_handle;
27609- intr_ptr = (unsigned long __user *) (i << 2);
27610+ intr_ptr = (__force unsigned long __user *) (i << 2);
27611 if (get_user(segoffs, intr_ptr))
27612 goto cannot_handle;
27613 if ((segoffs >> 16) == BIOSSEG)
27614diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27615index da6b35a..977e9cf 100644
27616--- a/arch/x86/kernel/vmlinux.lds.S
27617+++ b/arch/x86/kernel/vmlinux.lds.S
27618@@ -26,6 +26,13 @@
27619 #include <asm/page_types.h>
27620 #include <asm/cache.h>
27621 #include <asm/boot.h>
27622+#include <asm/segment.h>
27623+
27624+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27625+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27626+#else
27627+#define __KERNEL_TEXT_OFFSET 0
27628+#endif
27629
27630 #undef i386 /* in case the preprocessor is a 32bit one */
27631
27632@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27633
27634 PHDRS {
27635 text PT_LOAD FLAGS(5); /* R_E */
27636+#ifdef CONFIG_X86_32
27637+ module PT_LOAD FLAGS(5); /* R_E */
27638+#endif
27639+#ifdef CONFIG_XEN
27640+ rodata PT_LOAD FLAGS(5); /* R_E */
27641+#else
27642+ rodata PT_LOAD FLAGS(4); /* R__ */
27643+#endif
27644 data PT_LOAD FLAGS(6); /* RW_ */
27645-#ifdef CONFIG_X86_64
27646+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27647 #ifdef CONFIG_SMP
27648 percpu PT_LOAD FLAGS(6); /* RW_ */
27649 #endif
27650+ text.init PT_LOAD FLAGS(5); /* R_E */
27651+ text.exit PT_LOAD FLAGS(5); /* R_E */
27652 init PT_LOAD FLAGS(7); /* RWE */
27653-#endif
27654 note PT_NOTE FLAGS(0); /* ___ */
27655 }
27656
27657 SECTIONS
27658 {
27659 #ifdef CONFIG_X86_32
27660- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27661- phys_startup_32 = startup_32 - LOAD_OFFSET;
27662+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27663 #else
27664- . = __START_KERNEL;
27665- phys_startup_64 = startup_64 - LOAD_OFFSET;
27666+ . = __START_KERNEL;
27667 #endif
27668
27669 /* Text and read-only data */
27670- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27671- _text = .;
27672+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27673 /* bootstrapping code */
27674+#ifdef CONFIG_X86_32
27675+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27676+#else
27677+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27678+#endif
27679+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27680+ _text = .;
27681 HEAD_TEXT
27682 . = ALIGN(8);
27683 _stext = .;
27684@@ -104,13 +124,47 @@ SECTIONS
27685 IRQENTRY_TEXT
27686 *(.fixup)
27687 *(.gnu.warning)
27688- /* End of text section */
27689- _etext = .;
27690 } :text = 0x9090
27691
27692- NOTES :text :note
27693+ . += __KERNEL_TEXT_OFFSET;
27694
27695- EXCEPTION_TABLE(16) :text = 0x9090
27696+#ifdef CONFIG_X86_32
27697+ . = ALIGN(PAGE_SIZE);
27698+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27699+
27700+#ifdef CONFIG_PAX_KERNEXEC
27701+ MODULES_EXEC_VADDR = .;
27702+ BYTE(0)
27703+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27704+ . = ALIGN(HPAGE_SIZE) - 1;
27705+ MODULES_EXEC_END = .;
27706+#endif
27707+
27708+ } :module
27709+#endif
27710+
27711+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27712+ /* End of text section */
27713+ BYTE(0)
27714+ _etext = . - __KERNEL_TEXT_OFFSET;
27715+ }
27716+
27717+#ifdef CONFIG_X86_32
27718+ . = ALIGN(PAGE_SIZE);
27719+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27720+ . = ALIGN(PAGE_SIZE);
27721+ *(.empty_zero_page)
27722+ *(.initial_pg_fixmap)
27723+ *(.initial_pg_pmd)
27724+ *(.initial_page_table)
27725+ *(.swapper_pg_dir)
27726+ } :rodata
27727+#endif
27728+
27729+ . = ALIGN(PAGE_SIZE);
27730+ NOTES :rodata :note
27731+
27732+ EXCEPTION_TABLE(16) :rodata
27733
27734 #if defined(CONFIG_DEBUG_RODATA)
27735 /* .text should occupy whole number of pages */
27736@@ -122,16 +176,20 @@ SECTIONS
27737
27738 /* Data */
27739 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27740+
27741+#ifdef CONFIG_PAX_KERNEXEC
27742+ . = ALIGN(HPAGE_SIZE);
27743+#else
27744+ . = ALIGN(PAGE_SIZE);
27745+#endif
27746+
27747 /* Start of data section */
27748 _sdata = .;
27749
27750 /* init_task */
27751 INIT_TASK_DATA(THREAD_SIZE)
27752
27753-#ifdef CONFIG_X86_32
27754- /* 32 bit has nosave before _edata */
27755 NOSAVE_DATA
27756-#endif
27757
27758 PAGE_ALIGNED_DATA(PAGE_SIZE)
27759
27760@@ -172,12 +230,19 @@ SECTIONS
27761 #endif /* CONFIG_X86_64 */
27762
27763 /* Init code and data - will be freed after init */
27764- . = ALIGN(PAGE_SIZE);
27765 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27766+ BYTE(0)
27767+
27768+#ifdef CONFIG_PAX_KERNEXEC
27769+ . = ALIGN(HPAGE_SIZE);
27770+#else
27771+ . = ALIGN(PAGE_SIZE);
27772+#endif
27773+
27774 __init_begin = .; /* paired with __init_end */
27775- }
27776+ } :init.begin
27777
27778-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27779+#ifdef CONFIG_SMP
27780 /*
27781 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27782 * output PHDR, so the next output section - .init.text - should
27783@@ -186,12 +251,27 @@ SECTIONS
27784 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27785 #endif
27786
27787- INIT_TEXT_SECTION(PAGE_SIZE)
27788-#ifdef CONFIG_X86_64
27789- :init
27790-#endif
27791+ . = ALIGN(PAGE_SIZE);
27792+ init_begin = .;
27793+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27794+ VMLINUX_SYMBOL(_sinittext) = .;
27795+ INIT_TEXT
27796+ VMLINUX_SYMBOL(_einittext) = .;
27797+ . = ALIGN(PAGE_SIZE);
27798+ } :text.init
27799
27800- INIT_DATA_SECTION(16)
27801+ /*
27802+ * .exit.text is discard at runtime, not link time, to deal with
27803+ * references from .altinstructions and .eh_frame
27804+ */
27805+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27806+ EXIT_TEXT
27807+ . = ALIGN(16);
27808+ } :text.exit
27809+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27810+
27811+ . = ALIGN(PAGE_SIZE);
27812+ INIT_DATA_SECTION(16) :init
27813
27814 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27815 __x86_cpu_dev_start = .;
27816@@ -262,19 +342,12 @@ SECTIONS
27817 }
27818
27819 . = ALIGN(8);
27820- /*
27821- * .exit.text is discard at runtime, not link time, to deal with
27822- * references from .altinstructions and .eh_frame
27823- */
27824- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27825- EXIT_TEXT
27826- }
27827
27828 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27829 EXIT_DATA
27830 }
27831
27832-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27833+#ifndef CONFIG_SMP
27834 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27835 #endif
27836
27837@@ -293,16 +366,10 @@ SECTIONS
27838 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27839 __smp_locks = .;
27840 *(.smp_locks)
27841- . = ALIGN(PAGE_SIZE);
27842 __smp_locks_end = .;
27843+ . = ALIGN(PAGE_SIZE);
27844 }
27845
27846-#ifdef CONFIG_X86_64
27847- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27848- NOSAVE_DATA
27849- }
27850-#endif
27851-
27852 /* BSS */
27853 . = ALIGN(PAGE_SIZE);
27854 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27855@@ -318,6 +385,7 @@ SECTIONS
27856 __brk_base = .;
27857 . += 64 * 1024; /* 64k alignment slop space */
27858 *(.brk_reservation) /* areas brk users have reserved */
27859+ . = ALIGN(HPAGE_SIZE);
27860 __brk_limit = .;
27861 }
27862
27863@@ -344,13 +412,12 @@ SECTIONS
27864 * for the boot processor.
27865 */
27866 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27867-INIT_PER_CPU(gdt_page);
27868 INIT_PER_CPU(irq_stack_union);
27869
27870 /*
27871 * Build-time check on the image size:
27872 */
27873-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27874+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27875 "kernel image bigger than KERNEL_IMAGE_SIZE");
27876
27877 #ifdef CONFIG_SMP
27878diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27879index 1f96f93..d5c8f7a 100644
27880--- a/arch/x86/kernel/vsyscall_64.c
27881+++ b/arch/x86/kernel/vsyscall_64.c
27882@@ -56,15 +56,13 @@
27883 DEFINE_VVAR(int, vgetcpu_mode);
27884 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27885
27886-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27887+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27888
27889 static int __init vsyscall_setup(char *str)
27890 {
27891 if (str) {
27892 if (!strcmp("emulate", str))
27893 vsyscall_mode = EMULATE;
27894- else if (!strcmp("native", str))
27895- vsyscall_mode = NATIVE;
27896 else if (!strcmp("none", str))
27897 vsyscall_mode = NONE;
27898 else
27899@@ -323,8 +321,7 @@ do_ret:
27900 return true;
27901
27902 sigsegv:
27903- force_sig(SIGSEGV, current);
27904- return true;
27905+ do_group_exit(SIGKILL);
27906 }
27907
27908 /*
27909@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27910 extern char __vvar_page;
27911 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27912
27913- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27914- vsyscall_mode == NATIVE
27915- ? PAGE_KERNEL_VSYSCALL
27916- : PAGE_KERNEL_VVAR);
27917+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27918 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27919 (unsigned long)VSYSCALL_START);
27920
27921diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27922index 04068192..4d75aa6 100644
27923--- a/arch/x86/kernel/x8664_ksyms_64.c
27924+++ b/arch/x86/kernel/x8664_ksyms_64.c
27925@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27926 EXPORT_SYMBOL(copy_user_generic_unrolled);
27927 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27928 EXPORT_SYMBOL(__copy_user_nocache);
27929-EXPORT_SYMBOL(_copy_from_user);
27930-EXPORT_SYMBOL(_copy_to_user);
27931
27932 EXPORT_SYMBOL(copy_page);
27933 EXPORT_SYMBOL(clear_page);
27934@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27935 EXPORT_SYMBOL(___preempt_schedule_context);
27936 #endif
27937 #endif
27938+
27939+#ifdef CONFIG_PAX_PER_CPU_PGD
27940+EXPORT_SYMBOL(cpu_pgd);
27941+#endif
27942diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27943index e48b674..a451dd9 100644
27944--- a/arch/x86/kernel/x86_init.c
27945+++ b/arch/x86/kernel/x86_init.c
27946@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27947 static void default_nmi_init(void) { };
27948 static int default_i8042_detect(void) { return 1; };
27949
27950-struct x86_platform_ops x86_platform = {
27951+struct x86_platform_ops x86_platform __read_only = {
27952 .calibrate_tsc = native_calibrate_tsc,
27953 .get_wallclock = mach_get_cmos_time,
27954 .set_wallclock = mach_set_rtc_mmss,
27955@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27956 EXPORT_SYMBOL_GPL(x86_platform);
27957
27958 #if defined(CONFIG_PCI_MSI)
27959-struct x86_msi_ops x86_msi = {
27960+struct x86_msi_ops x86_msi __read_only = {
27961 .setup_msi_irqs = native_setup_msi_irqs,
27962 .compose_msi_msg = native_compose_msi_msg,
27963 .teardown_msi_irq = native_teardown_msi_irq,
27964@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27965 }
27966 #endif
27967
27968-struct x86_io_apic_ops x86_io_apic_ops = {
27969+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27970 .init = native_io_apic_init_mappings,
27971 .read = native_io_apic_read,
27972 .write = native_io_apic_write,
27973diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27974index a4b451c..8dfe1ad 100644
27975--- a/arch/x86/kernel/xsave.c
27976+++ b/arch/x86/kernel/xsave.c
27977@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27978
27979 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27980 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27981- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27982+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27983
27984 if (!use_xsave())
27985 return err;
27986
27987- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27988+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27989
27990 /*
27991 * Read the xstate_bv which we copied (directly from the cpu or
27992 * from the state in task struct) to the user buffers.
27993 */
27994- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27995+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27996
27997 /*
27998 * For legacy compatible, we always set FP/SSE bits in the bit
27999@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28000 */
28001 xstate_bv |= XSTATE_FPSSE;
28002
28003- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28004+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28005
28006 return err;
28007 }
28008@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28009 {
28010 int err;
28011
28012+ buf = (struct xsave_struct __user *)____m(buf);
28013 if (use_xsave())
28014 err = xsave_user(buf);
28015 else if (use_fxsr())
28016@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28017 */
28018 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28019 {
28020+ buf = (void __user *)____m(buf);
28021 if (use_xsave()) {
28022 if ((unsigned long)buf % 64 || fx_only) {
28023 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28024diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28025index c697625..a032162 100644
28026--- a/arch/x86/kvm/cpuid.c
28027+++ b/arch/x86/kvm/cpuid.c
28028@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28029 struct kvm_cpuid2 *cpuid,
28030 struct kvm_cpuid_entry2 __user *entries)
28031 {
28032- int r;
28033+ int r, i;
28034
28035 r = -E2BIG;
28036 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28037 goto out;
28038 r = -EFAULT;
28039- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28040- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28041+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28042 goto out;
28043+ for (i = 0; i < cpuid->nent; ++i) {
28044+ struct kvm_cpuid_entry2 cpuid_entry;
28045+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28046+ goto out;
28047+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28048+ }
28049 vcpu->arch.cpuid_nent = cpuid->nent;
28050 kvm_apic_set_version(vcpu);
28051 kvm_x86_ops->cpuid_update(vcpu);
28052@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28053 struct kvm_cpuid2 *cpuid,
28054 struct kvm_cpuid_entry2 __user *entries)
28055 {
28056- int r;
28057+ int r, i;
28058
28059 r = -E2BIG;
28060 if (cpuid->nent < vcpu->arch.cpuid_nent)
28061 goto out;
28062 r = -EFAULT;
28063- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28064- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28065+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28066 goto out;
28067+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28068+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28069+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28070+ goto out;
28071+ }
28072 return 0;
28073
28074 out:
28075diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28076index 9736529..ab4f54c 100644
28077--- a/arch/x86/kvm/lapic.c
28078+++ b/arch/x86/kvm/lapic.c
28079@@ -55,7 +55,7 @@
28080 #define APIC_BUS_CYCLE_NS 1
28081
28082 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28083-#define apic_debug(fmt, arg...)
28084+#define apic_debug(fmt, arg...) do {} while (0)
28085
28086 #define APIC_LVT_NUM 6
28087 /* 14 is the version for Xeon and Pentium 8.4.8*/
28088diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28089index cba218a..1cc1bed 100644
28090--- a/arch/x86/kvm/paging_tmpl.h
28091+++ b/arch/x86/kvm/paging_tmpl.h
28092@@ -331,7 +331,7 @@ retry_walk:
28093 if (unlikely(kvm_is_error_hva(host_addr)))
28094 goto error;
28095
28096- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28097+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28098 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28099 goto error;
28100 walker->ptep_user[walker->level - 1] = ptep_user;
28101diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28102index 2de1bc0..22251ee 100644
28103--- a/arch/x86/kvm/svm.c
28104+++ b/arch/x86/kvm/svm.c
28105@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28106 int cpu = raw_smp_processor_id();
28107
28108 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28109+
28110+ pax_open_kernel();
28111 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28112+ pax_close_kernel();
28113+
28114 load_TR_desc();
28115 }
28116
28117@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28118 #endif
28119 #endif
28120
28121+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28122+ __set_fs(current_thread_info()->addr_limit);
28123+#endif
28124+
28125 reload_tss(vcpu);
28126
28127 local_irq_disable();
28128diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28129index 3927528..fc19971 100644
28130--- a/arch/x86/kvm/vmx.c
28131+++ b/arch/x86/kvm/vmx.c
28132@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28133 #endif
28134 }
28135
28136-static void vmcs_clear_bits(unsigned long field, u32 mask)
28137+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28138 {
28139 vmcs_writel(field, vmcs_readl(field) & ~mask);
28140 }
28141
28142-static void vmcs_set_bits(unsigned long field, u32 mask)
28143+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28144 {
28145 vmcs_writel(field, vmcs_readl(field) | mask);
28146 }
28147@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28148 struct desc_struct *descs;
28149
28150 descs = (void *)gdt->address;
28151+
28152+ pax_open_kernel();
28153 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28154+ pax_close_kernel();
28155+
28156 load_TR_desc();
28157 }
28158
28159@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28160 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28161 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28162
28163+#ifdef CONFIG_PAX_PER_CPU_PGD
28164+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28165+#endif
28166+
28167 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28168 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28169 vmx->loaded_vmcs->cpu = cpu;
28170@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28171 * reads and returns guest's timestamp counter "register"
28172 * guest_tsc = host_tsc + tsc_offset -- 21.3
28173 */
28174-static u64 guest_read_tsc(void)
28175+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28176 {
28177 u64 host_tsc, tsc_offset;
28178
28179@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28180 if (!cpu_has_vmx_flexpriority())
28181 flexpriority_enabled = 0;
28182
28183- if (!cpu_has_vmx_tpr_shadow())
28184- kvm_x86_ops->update_cr8_intercept = NULL;
28185+ if (!cpu_has_vmx_tpr_shadow()) {
28186+ pax_open_kernel();
28187+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28188+ pax_close_kernel();
28189+ }
28190
28191 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28192 kvm_disable_largepages();
28193@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28194 if (!cpu_has_vmx_apicv())
28195 enable_apicv = 0;
28196
28197+ pax_open_kernel();
28198 if (enable_apicv)
28199- kvm_x86_ops->update_cr8_intercept = NULL;
28200+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28201 else {
28202- kvm_x86_ops->hwapic_irr_update = NULL;
28203- kvm_x86_ops->deliver_posted_interrupt = NULL;
28204- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28205+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28206+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28207+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28208 }
28209+ pax_close_kernel();
28210
28211 if (nested)
28212 nested_vmx_setup_ctls_msrs();
28213@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28214
28215 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28216 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28217+
28218+#ifndef CONFIG_PAX_PER_CPU_PGD
28219 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28220+#endif
28221
28222 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28223 #ifdef CONFIG_X86_64
28224@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28225 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28226 vmx->host_idt_base = dt.address;
28227
28228- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28229+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28230
28231 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28232 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28233@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28234 "jmp 2f \n\t"
28235 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28236 "2: "
28237+
28238+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28239+ "ljmp %[cs],$3f\n\t"
28240+ "3: "
28241+#endif
28242+
28243 /* Save guest registers, load host registers, keep flags */
28244 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28245 "pop %0 \n\t"
28246@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28247 #endif
28248 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28249 [wordsize]"i"(sizeof(ulong))
28250+
28251+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28252+ ,[cs]"i"(__KERNEL_CS)
28253+#endif
28254+
28255 : "cc", "memory"
28256 #ifdef CONFIG_X86_64
28257 , "rax", "rbx", "rdi", "rsi"
28258@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28259 if (debugctlmsr)
28260 update_debugctlmsr(debugctlmsr);
28261
28262-#ifndef CONFIG_X86_64
28263+#ifdef CONFIG_X86_32
28264 /*
28265 * The sysexit path does not restore ds/es, so we must set them to
28266 * a reasonable value ourselves.
28267@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28268 * may be executed in interrupt context, which saves and restore segments
28269 * around it, nullifying its effect.
28270 */
28271- loadsegment(ds, __USER_DS);
28272- loadsegment(es, __USER_DS);
28273+ loadsegment(ds, __KERNEL_DS);
28274+ loadsegment(es, __KERNEL_DS);
28275+ loadsegment(ss, __KERNEL_DS);
28276+
28277+#ifdef CONFIG_PAX_KERNEXEC
28278+ loadsegment(fs, __KERNEL_PERCPU);
28279+#endif
28280+
28281+#ifdef CONFIG_PAX_MEMORY_UDEREF
28282+ __set_fs(current_thread_info()->addr_limit);
28283+#endif
28284+
28285 #endif
28286
28287 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28288diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28289index 2b85784..ad70e19 100644
28290--- a/arch/x86/kvm/x86.c
28291+++ b/arch/x86/kvm/x86.c
28292@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28293 {
28294 struct kvm *kvm = vcpu->kvm;
28295 int lm = is_long_mode(vcpu);
28296- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28297- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28298+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28299+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28300 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28301 : kvm->arch.xen_hvm_config.blob_size_32;
28302 u32 page_num = data & ~PAGE_MASK;
28303@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28304 if (n < msr_list.nmsrs)
28305 goto out;
28306 r = -EFAULT;
28307+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28308+ goto out;
28309 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28310 num_msrs_to_save * sizeof(u32)))
28311 goto out;
28312@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28313 };
28314 #endif
28315
28316-int kvm_arch_init(void *opaque)
28317+int kvm_arch_init(const void *opaque)
28318 {
28319 int r;
28320 struct kvm_x86_ops *ops = opaque;
28321diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28322index ad1fb5f..fe30b66 100644
28323--- a/arch/x86/lguest/boot.c
28324+++ b/arch/x86/lguest/boot.c
28325@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28326 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28327 * Launcher to reboot us.
28328 */
28329-static void lguest_restart(char *reason)
28330+static __noreturn void lguest_restart(char *reason)
28331 {
28332 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28333+ BUG();
28334 }
28335
28336 /*G:050
28337diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28338index 00933d5..3a64af9 100644
28339--- a/arch/x86/lib/atomic64_386_32.S
28340+++ b/arch/x86/lib/atomic64_386_32.S
28341@@ -48,6 +48,10 @@ BEGIN(read)
28342 movl (v), %eax
28343 movl 4(v), %edx
28344 RET_ENDP
28345+BEGIN(read_unchecked)
28346+ movl (v), %eax
28347+ movl 4(v), %edx
28348+RET_ENDP
28349 #undef v
28350
28351 #define v %esi
28352@@ -55,6 +59,10 @@ BEGIN(set)
28353 movl %ebx, (v)
28354 movl %ecx, 4(v)
28355 RET_ENDP
28356+BEGIN(set_unchecked)
28357+ movl %ebx, (v)
28358+ movl %ecx, 4(v)
28359+RET_ENDP
28360 #undef v
28361
28362 #define v %esi
28363@@ -70,6 +78,20 @@ RET_ENDP
28364 BEGIN(add)
28365 addl %eax, (v)
28366 adcl %edx, 4(v)
28367+
28368+#ifdef CONFIG_PAX_REFCOUNT
28369+ jno 0f
28370+ subl %eax, (v)
28371+ sbbl %edx, 4(v)
28372+ int $4
28373+0:
28374+ _ASM_EXTABLE(0b, 0b)
28375+#endif
28376+
28377+RET_ENDP
28378+BEGIN(add_unchecked)
28379+ addl %eax, (v)
28380+ adcl %edx, 4(v)
28381 RET_ENDP
28382 #undef v
28383
28384@@ -77,6 +99,24 @@ RET_ENDP
28385 BEGIN(add_return)
28386 addl (v), %eax
28387 adcl 4(v), %edx
28388+
28389+#ifdef CONFIG_PAX_REFCOUNT
28390+ into
28391+1234:
28392+ _ASM_EXTABLE(1234b, 2f)
28393+#endif
28394+
28395+ movl %eax, (v)
28396+ movl %edx, 4(v)
28397+
28398+#ifdef CONFIG_PAX_REFCOUNT
28399+2:
28400+#endif
28401+
28402+RET_ENDP
28403+BEGIN(add_return_unchecked)
28404+ addl (v), %eax
28405+ adcl 4(v), %edx
28406 movl %eax, (v)
28407 movl %edx, 4(v)
28408 RET_ENDP
28409@@ -86,6 +126,20 @@ RET_ENDP
28410 BEGIN(sub)
28411 subl %eax, (v)
28412 sbbl %edx, 4(v)
28413+
28414+#ifdef CONFIG_PAX_REFCOUNT
28415+ jno 0f
28416+ addl %eax, (v)
28417+ adcl %edx, 4(v)
28418+ int $4
28419+0:
28420+ _ASM_EXTABLE(0b, 0b)
28421+#endif
28422+
28423+RET_ENDP
28424+BEGIN(sub_unchecked)
28425+ subl %eax, (v)
28426+ sbbl %edx, 4(v)
28427 RET_ENDP
28428 #undef v
28429
28430@@ -96,6 +150,27 @@ BEGIN(sub_return)
28431 sbbl $0, %edx
28432 addl (v), %eax
28433 adcl 4(v), %edx
28434+
28435+#ifdef CONFIG_PAX_REFCOUNT
28436+ into
28437+1234:
28438+ _ASM_EXTABLE(1234b, 2f)
28439+#endif
28440+
28441+ movl %eax, (v)
28442+ movl %edx, 4(v)
28443+
28444+#ifdef CONFIG_PAX_REFCOUNT
28445+2:
28446+#endif
28447+
28448+RET_ENDP
28449+BEGIN(sub_return_unchecked)
28450+ negl %edx
28451+ negl %eax
28452+ sbbl $0, %edx
28453+ addl (v), %eax
28454+ adcl 4(v), %edx
28455 movl %eax, (v)
28456 movl %edx, 4(v)
28457 RET_ENDP
28458@@ -105,6 +180,20 @@ RET_ENDP
28459 BEGIN(inc)
28460 addl $1, (v)
28461 adcl $0, 4(v)
28462+
28463+#ifdef CONFIG_PAX_REFCOUNT
28464+ jno 0f
28465+ subl $1, (v)
28466+ sbbl $0, 4(v)
28467+ int $4
28468+0:
28469+ _ASM_EXTABLE(0b, 0b)
28470+#endif
28471+
28472+RET_ENDP
28473+BEGIN(inc_unchecked)
28474+ addl $1, (v)
28475+ adcl $0, 4(v)
28476 RET_ENDP
28477 #undef v
28478
28479@@ -114,6 +203,26 @@ BEGIN(inc_return)
28480 movl 4(v), %edx
28481 addl $1, %eax
28482 adcl $0, %edx
28483+
28484+#ifdef CONFIG_PAX_REFCOUNT
28485+ into
28486+1234:
28487+ _ASM_EXTABLE(1234b, 2f)
28488+#endif
28489+
28490+ movl %eax, (v)
28491+ movl %edx, 4(v)
28492+
28493+#ifdef CONFIG_PAX_REFCOUNT
28494+2:
28495+#endif
28496+
28497+RET_ENDP
28498+BEGIN(inc_return_unchecked)
28499+ movl (v), %eax
28500+ movl 4(v), %edx
28501+ addl $1, %eax
28502+ adcl $0, %edx
28503 movl %eax, (v)
28504 movl %edx, 4(v)
28505 RET_ENDP
28506@@ -123,6 +232,20 @@ RET_ENDP
28507 BEGIN(dec)
28508 subl $1, (v)
28509 sbbl $0, 4(v)
28510+
28511+#ifdef CONFIG_PAX_REFCOUNT
28512+ jno 0f
28513+ addl $1, (v)
28514+ adcl $0, 4(v)
28515+ int $4
28516+0:
28517+ _ASM_EXTABLE(0b, 0b)
28518+#endif
28519+
28520+RET_ENDP
28521+BEGIN(dec_unchecked)
28522+ subl $1, (v)
28523+ sbbl $0, 4(v)
28524 RET_ENDP
28525 #undef v
28526
28527@@ -132,6 +255,26 @@ BEGIN(dec_return)
28528 movl 4(v), %edx
28529 subl $1, %eax
28530 sbbl $0, %edx
28531+
28532+#ifdef CONFIG_PAX_REFCOUNT
28533+ into
28534+1234:
28535+ _ASM_EXTABLE(1234b, 2f)
28536+#endif
28537+
28538+ movl %eax, (v)
28539+ movl %edx, 4(v)
28540+
28541+#ifdef CONFIG_PAX_REFCOUNT
28542+2:
28543+#endif
28544+
28545+RET_ENDP
28546+BEGIN(dec_return_unchecked)
28547+ movl (v), %eax
28548+ movl 4(v), %edx
28549+ subl $1, %eax
28550+ sbbl $0, %edx
28551 movl %eax, (v)
28552 movl %edx, 4(v)
28553 RET_ENDP
28554@@ -143,6 +286,13 @@ BEGIN(add_unless)
28555 adcl %edx, %edi
28556 addl (v), %eax
28557 adcl 4(v), %edx
28558+
28559+#ifdef CONFIG_PAX_REFCOUNT
28560+ into
28561+1234:
28562+ _ASM_EXTABLE(1234b, 2f)
28563+#endif
28564+
28565 cmpl %eax, %ecx
28566 je 3f
28567 1:
28568@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28569 1:
28570 addl $1, %eax
28571 adcl $0, %edx
28572+
28573+#ifdef CONFIG_PAX_REFCOUNT
28574+ into
28575+1234:
28576+ _ASM_EXTABLE(1234b, 2f)
28577+#endif
28578+
28579 movl %eax, (v)
28580 movl %edx, 4(v)
28581 movl $1, %eax
28582@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28583 movl 4(v), %edx
28584 subl $1, %eax
28585 sbbl $0, %edx
28586+
28587+#ifdef CONFIG_PAX_REFCOUNT
28588+ into
28589+1234:
28590+ _ASM_EXTABLE(1234b, 1f)
28591+#endif
28592+
28593 js 1f
28594 movl %eax, (v)
28595 movl %edx, 4(v)
28596diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28597index f5cc9eb..51fa319 100644
28598--- a/arch/x86/lib/atomic64_cx8_32.S
28599+++ b/arch/x86/lib/atomic64_cx8_32.S
28600@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28601 CFI_STARTPROC
28602
28603 read64 %ecx
28604+ pax_force_retaddr
28605 ret
28606 CFI_ENDPROC
28607 ENDPROC(atomic64_read_cx8)
28608
28609+ENTRY(atomic64_read_unchecked_cx8)
28610+ CFI_STARTPROC
28611+
28612+ read64 %ecx
28613+ pax_force_retaddr
28614+ ret
28615+ CFI_ENDPROC
28616+ENDPROC(atomic64_read_unchecked_cx8)
28617+
28618 ENTRY(atomic64_set_cx8)
28619 CFI_STARTPROC
28620
28621@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28622 cmpxchg8b (%esi)
28623 jne 1b
28624
28625+ pax_force_retaddr
28626 ret
28627 CFI_ENDPROC
28628 ENDPROC(atomic64_set_cx8)
28629
28630+ENTRY(atomic64_set_unchecked_cx8)
28631+ CFI_STARTPROC
28632+
28633+1:
28634+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28635+ * are atomic on 586 and newer */
28636+ cmpxchg8b (%esi)
28637+ jne 1b
28638+
28639+ pax_force_retaddr
28640+ ret
28641+ CFI_ENDPROC
28642+ENDPROC(atomic64_set_unchecked_cx8)
28643+
28644 ENTRY(atomic64_xchg_cx8)
28645 CFI_STARTPROC
28646
28647@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28648 cmpxchg8b (%esi)
28649 jne 1b
28650
28651+ pax_force_retaddr
28652 ret
28653 CFI_ENDPROC
28654 ENDPROC(atomic64_xchg_cx8)
28655
28656-.macro addsub_return func ins insc
28657-ENTRY(atomic64_\func\()_return_cx8)
28658+.macro addsub_return func ins insc unchecked=""
28659+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28660 CFI_STARTPROC
28661 SAVE ebp
28662 SAVE ebx
28663@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28664 movl %edx, %ecx
28665 \ins\()l %esi, %ebx
28666 \insc\()l %edi, %ecx
28667+
28668+.ifb \unchecked
28669+#ifdef CONFIG_PAX_REFCOUNT
28670+ into
28671+2:
28672+ _ASM_EXTABLE(2b, 3f)
28673+#endif
28674+.endif
28675+
28676 LOCK_PREFIX
28677 cmpxchg8b (%ebp)
28678 jne 1b
28679-
28680-10:
28681 movl %ebx, %eax
28682 movl %ecx, %edx
28683+
28684+.ifb \unchecked
28685+#ifdef CONFIG_PAX_REFCOUNT
28686+3:
28687+#endif
28688+.endif
28689+
28690 RESTORE edi
28691 RESTORE esi
28692 RESTORE ebx
28693 RESTORE ebp
28694+ pax_force_retaddr
28695 ret
28696 CFI_ENDPROC
28697-ENDPROC(atomic64_\func\()_return_cx8)
28698+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28699 .endm
28700
28701 addsub_return add add adc
28702 addsub_return sub sub sbb
28703+addsub_return add add adc _unchecked
28704+addsub_return sub sub sbb _unchecked
28705
28706-.macro incdec_return func ins insc
28707-ENTRY(atomic64_\func\()_return_cx8)
28708+.macro incdec_return func ins insc unchecked=""
28709+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28710 CFI_STARTPROC
28711 SAVE ebx
28712
28713@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28714 movl %edx, %ecx
28715 \ins\()l $1, %ebx
28716 \insc\()l $0, %ecx
28717+
28718+.ifb \unchecked
28719+#ifdef CONFIG_PAX_REFCOUNT
28720+ into
28721+2:
28722+ _ASM_EXTABLE(2b, 3f)
28723+#endif
28724+.endif
28725+
28726 LOCK_PREFIX
28727 cmpxchg8b (%esi)
28728 jne 1b
28729
28730-10:
28731 movl %ebx, %eax
28732 movl %ecx, %edx
28733+
28734+.ifb \unchecked
28735+#ifdef CONFIG_PAX_REFCOUNT
28736+3:
28737+#endif
28738+.endif
28739+
28740 RESTORE ebx
28741+ pax_force_retaddr
28742 ret
28743 CFI_ENDPROC
28744-ENDPROC(atomic64_\func\()_return_cx8)
28745+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28746 .endm
28747
28748 incdec_return inc add adc
28749 incdec_return dec sub sbb
28750+incdec_return inc add adc _unchecked
28751+incdec_return dec sub sbb _unchecked
28752
28753 ENTRY(atomic64_dec_if_positive_cx8)
28754 CFI_STARTPROC
28755@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28756 movl %edx, %ecx
28757 subl $1, %ebx
28758 sbb $0, %ecx
28759+
28760+#ifdef CONFIG_PAX_REFCOUNT
28761+ into
28762+1234:
28763+ _ASM_EXTABLE(1234b, 2f)
28764+#endif
28765+
28766 js 2f
28767 LOCK_PREFIX
28768 cmpxchg8b (%esi)
28769@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28770 movl %ebx, %eax
28771 movl %ecx, %edx
28772 RESTORE ebx
28773+ pax_force_retaddr
28774 ret
28775 CFI_ENDPROC
28776 ENDPROC(atomic64_dec_if_positive_cx8)
28777@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28778 movl %edx, %ecx
28779 addl %ebp, %ebx
28780 adcl %edi, %ecx
28781+
28782+#ifdef CONFIG_PAX_REFCOUNT
28783+ into
28784+1234:
28785+ _ASM_EXTABLE(1234b, 3f)
28786+#endif
28787+
28788 LOCK_PREFIX
28789 cmpxchg8b (%esi)
28790 jne 1b
28791@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28792 CFI_ADJUST_CFA_OFFSET -8
28793 RESTORE ebx
28794 RESTORE ebp
28795+ pax_force_retaddr
28796 ret
28797 4:
28798 cmpl %edx, 4(%esp)
28799@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28800 xorl %ecx, %ecx
28801 addl $1, %ebx
28802 adcl %edx, %ecx
28803+
28804+#ifdef CONFIG_PAX_REFCOUNT
28805+ into
28806+1234:
28807+ _ASM_EXTABLE(1234b, 3f)
28808+#endif
28809+
28810 LOCK_PREFIX
28811 cmpxchg8b (%esi)
28812 jne 1b
28813@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28814 movl $1, %eax
28815 3:
28816 RESTORE ebx
28817+ pax_force_retaddr
28818 ret
28819 CFI_ENDPROC
28820 ENDPROC(atomic64_inc_not_zero_cx8)
28821diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28822index e78b8ee..7e173a8 100644
28823--- a/arch/x86/lib/checksum_32.S
28824+++ b/arch/x86/lib/checksum_32.S
28825@@ -29,7 +29,8 @@
28826 #include <asm/dwarf2.h>
28827 #include <asm/errno.h>
28828 #include <asm/asm.h>
28829-
28830+#include <asm/segment.h>
28831+
28832 /*
28833 * computes a partial checksum, e.g. for TCP/UDP fragments
28834 */
28835@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28836
28837 #define ARGBASE 16
28838 #define FP 12
28839-
28840-ENTRY(csum_partial_copy_generic)
28841+
28842+ENTRY(csum_partial_copy_generic_to_user)
28843 CFI_STARTPROC
28844+
28845+#ifdef CONFIG_PAX_MEMORY_UDEREF
28846+ pushl_cfi %gs
28847+ popl_cfi %es
28848+ jmp csum_partial_copy_generic
28849+#endif
28850+
28851+ENTRY(csum_partial_copy_generic_from_user)
28852+
28853+#ifdef CONFIG_PAX_MEMORY_UDEREF
28854+ pushl_cfi %gs
28855+ popl_cfi %ds
28856+#endif
28857+
28858+ENTRY(csum_partial_copy_generic)
28859 subl $4,%esp
28860 CFI_ADJUST_CFA_OFFSET 4
28861 pushl_cfi %edi
28862@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28863 jmp 4f
28864 SRC(1: movw (%esi), %bx )
28865 addl $2, %esi
28866-DST( movw %bx, (%edi) )
28867+DST( movw %bx, %es:(%edi) )
28868 addl $2, %edi
28869 addw %bx, %ax
28870 adcl $0, %eax
28871@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28872 SRC(1: movl (%esi), %ebx )
28873 SRC( movl 4(%esi), %edx )
28874 adcl %ebx, %eax
28875-DST( movl %ebx, (%edi) )
28876+DST( movl %ebx, %es:(%edi) )
28877 adcl %edx, %eax
28878-DST( movl %edx, 4(%edi) )
28879+DST( movl %edx, %es:4(%edi) )
28880
28881 SRC( movl 8(%esi), %ebx )
28882 SRC( movl 12(%esi), %edx )
28883 adcl %ebx, %eax
28884-DST( movl %ebx, 8(%edi) )
28885+DST( movl %ebx, %es:8(%edi) )
28886 adcl %edx, %eax
28887-DST( movl %edx, 12(%edi) )
28888+DST( movl %edx, %es:12(%edi) )
28889
28890 SRC( movl 16(%esi), %ebx )
28891 SRC( movl 20(%esi), %edx )
28892 adcl %ebx, %eax
28893-DST( movl %ebx, 16(%edi) )
28894+DST( movl %ebx, %es:16(%edi) )
28895 adcl %edx, %eax
28896-DST( movl %edx, 20(%edi) )
28897+DST( movl %edx, %es:20(%edi) )
28898
28899 SRC( movl 24(%esi), %ebx )
28900 SRC( movl 28(%esi), %edx )
28901 adcl %ebx, %eax
28902-DST( movl %ebx, 24(%edi) )
28903+DST( movl %ebx, %es:24(%edi) )
28904 adcl %edx, %eax
28905-DST( movl %edx, 28(%edi) )
28906+DST( movl %edx, %es:28(%edi) )
28907
28908 lea 32(%esi), %esi
28909 lea 32(%edi), %edi
28910@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28911 shrl $2, %edx # This clears CF
28912 SRC(3: movl (%esi), %ebx )
28913 adcl %ebx, %eax
28914-DST( movl %ebx, (%edi) )
28915+DST( movl %ebx, %es:(%edi) )
28916 lea 4(%esi), %esi
28917 lea 4(%edi), %edi
28918 dec %edx
28919@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28920 jb 5f
28921 SRC( movw (%esi), %cx )
28922 leal 2(%esi), %esi
28923-DST( movw %cx, (%edi) )
28924+DST( movw %cx, %es:(%edi) )
28925 leal 2(%edi), %edi
28926 je 6f
28927 shll $16,%ecx
28928 SRC(5: movb (%esi), %cl )
28929-DST( movb %cl, (%edi) )
28930+DST( movb %cl, %es:(%edi) )
28931 6: addl %ecx, %eax
28932 adcl $0, %eax
28933 7:
28934@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28935
28936 6001:
28937 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28938- movl $-EFAULT, (%ebx)
28939+ movl $-EFAULT, %ss:(%ebx)
28940
28941 # zero the complete destination - computing the rest
28942 # is too much work
28943@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28944
28945 6002:
28946 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28947- movl $-EFAULT,(%ebx)
28948+ movl $-EFAULT,%ss:(%ebx)
28949 jmp 5000b
28950
28951 .previous
28952
28953+ pushl_cfi %ss
28954+ popl_cfi %ds
28955+ pushl_cfi %ss
28956+ popl_cfi %es
28957 popl_cfi %ebx
28958 CFI_RESTORE ebx
28959 popl_cfi %esi
28960@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28961 popl_cfi %ecx # equivalent to addl $4,%esp
28962 ret
28963 CFI_ENDPROC
28964-ENDPROC(csum_partial_copy_generic)
28965+ENDPROC(csum_partial_copy_generic_to_user)
28966
28967 #else
28968
28969 /* Version for PentiumII/PPro */
28970
28971 #define ROUND1(x) \
28972+ nop; nop; nop; \
28973 SRC(movl x(%esi), %ebx ) ; \
28974 addl %ebx, %eax ; \
28975- DST(movl %ebx, x(%edi) ) ;
28976+ DST(movl %ebx, %es:x(%edi)) ;
28977
28978 #define ROUND(x) \
28979+ nop; nop; nop; \
28980 SRC(movl x(%esi), %ebx ) ; \
28981 adcl %ebx, %eax ; \
28982- DST(movl %ebx, x(%edi) ) ;
28983+ DST(movl %ebx, %es:x(%edi)) ;
28984
28985 #define ARGBASE 12
28986-
28987-ENTRY(csum_partial_copy_generic)
28988+
28989+ENTRY(csum_partial_copy_generic_to_user)
28990 CFI_STARTPROC
28991+
28992+#ifdef CONFIG_PAX_MEMORY_UDEREF
28993+ pushl_cfi %gs
28994+ popl_cfi %es
28995+ jmp csum_partial_copy_generic
28996+#endif
28997+
28998+ENTRY(csum_partial_copy_generic_from_user)
28999+
29000+#ifdef CONFIG_PAX_MEMORY_UDEREF
29001+ pushl_cfi %gs
29002+ popl_cfi %ds
29003+#endif
29004+
29005+ENTRY(csum_partial_copy_generic)
29006 pushl_cfi %ebx
29007 CFI_REL_OFFSET ebx, 0
29008 pushl_cfi %edi
29009@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29010 subl %ebx, %edi
29011 lea -1(%esi),%edx
29012 andl $-32,%edx
29013- lea 3f(%ebx,%ebx), %ebx
29014+ lea 3f(%ebx,%ebx,2), %ebx
29015 testl %esi, %esi
29016 jmp *%ebx
29017 1: addl $64,%esi
29018@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29019 jb 5f
29020 SRC( movw (%esi), %dx )
29021 leal 2(%esi), %esi
29022-DST( movw %dx, (%edi) )
29023+DST( movw %dx, %es:(%edi) )
29024 leal 2(%edi), %edi
29025 je 6f
29026 shll $16,%edx
29027 5:
29028 SRC( movb (%esi), %dl )
29029-DST( movb %dl, (%edi) )
29030+DST( movb %dl, %es:(%edi) )
29031 6: addl %edx, %eax
29032 adcl $0, %eax
29033 7:
29034 .section .fixup, "ax"
29035 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29036- movl $-EFAULT, (%ebx)
29037+ movl $-EFAULT, %ss:(%ebx)
29038 # zero the complete destination (computing the rest is too much work)
29039 movl ARGBASE+8(%esp),%edi # dst
29040 movl ARGBASE+12(%esp),%ecx # len
29041@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29042 rep; stosb
29043 jmp 7b
29044 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29045- movl $-EFAULT, (%ebx)
29046+ movl $-EFAULT, %ss:(%ebx)
29047 jmp 7b
29048 .previous
29049
29050+#ifdef CONFIG_PAX_MEMORY_UDEREF
29051+ pushl_cfi %ss
29052+ popl_cfi %ds
29053+ pushl_cfi %ss
29054+ popl_cfi %es
29055+#endif
29056+
29057 popl_cfi %esi
29058 CFI_RESTORE esi
29059 popl_cfi %edi
29060@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29061 CFI_RESTORE ebx
29062 ret
29063 CFI_ENDPROC
29064-ENDPROC(csum_partial_copy_generic)
29065+ENDPROC(csum_partial_copy_generic_to_user)
29066
29067 #undef ROUND
29068 #undef ROUND1
29069diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29070index f2145cf..cea889d 100644
29071--- a/arch/x86/lib/clear_page_64.S
29072+++ b/arch/x86/lib/clear_page_64.S
29073@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29074 movl $4096/8,%ecx
29075 xorl %eax,%eax
29076 rep stosq
29077+ pax_force_retaddr
29078 ret
29079 CFI_ENDPROC
29080 ENDPROC(clear_page_c)
29081@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29082 movl $4096,%ecx
29083 xorl %eax,%eax
29084 rep stosb
29085+ pax_force_retaddr
29086 ret
29087 CFI_ENDPROC
29088 ENDPROC(clear_page_c_e)
29089@@ -43,6 +45,7 @@ ENTRY(clear_page)
29090 leaq 64(%rdi),%rdi
29091 jnz .Lloop
29092 nop
29093+ pax_force_retaddr
29094 ret
29095 CFI_ENDPROC
29096 .Lclear_page_end:
29097@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29098
29099 #include <asm/cpufeature.h>
29100
29101- .section .altinstr_replacement,"ax"
29102+ .section .altinstr_replacement,"a"
29103 1: .byte 0xeb /* jmp <disp8> */
29104 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29105 2: .byte 0xeb /* jmp <disp8> */
29106diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29107index 1e572c5..2a162cd 100644
29108--- a/arch/x86/lib/cmpxchg16b_emu.S
29109+++ b/arch/x86/lib/cmpxchg16b_emu.S
29110@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29111
29112 popf
29113 mov $1, %al
29114+ pax_force_retaddr
29115 ret
29116
29117 not_same:
29118 popf
29119 xor %al,%al
29120+ pax_force_retaddr
29121 ret
29122
29123 CFI_ENDPROC
29124diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29125index 176cca6..e0d658e 100644
29126--- a/arch/x86/lib/copy_page_64.S
29127+++ b/arch/x86/lib/copy_page_64.S
29128@@ -9,6 +9,7 @@ copy_page_rep:
29129 CFI_STARTPROC
29130 movl $4096/8, %ecx
29131 rep movsq
29132+ pax_force_retaddr
29133 ret
29134 CFI_ENDPROC
29135 ENDPROC(copy_page_rep)
29136@@ -24,8 +25,8 @@ ENTRY(copy_page)
29137 CFI_ADJUST_CFA_OFFSET 2*8
29138 movq %rbx, (%rsp)
29139 CFI_REL_OFFSET rbx, 0
29140- movq %r12, 1*8(%rsp)
29141- CFI_REL_OFFSET r12, 1*8
29142+ movq %r13, 1*8(%rsp)
29143+ CFI_REL_OFFSET r13, 1*8
29144
29145 movl $(4096/64)-5, %ecx
29146 .p2align 4
29147@@ -38,7 +39,7 @@ ENTRY(copy_page)
29148 movq 0x8*4(%rsi), %r9
29149 movq 0x8*5(%rsi), %r10
29150 movq 0x8*6(%rsi), %r11
29151- movq 0x8*7(%rsi), %r12
29152+ movq 0x8*7(%rsi), %r13
29153
29154 prefetcht0 5*64(%rsi)
29155
29156@@ -49,7 +50,7 @@ ENTRY(copy_page)
29157 movq %r9, 0x8*4(%rdi)
29158 movq %r10, 0x8*5(%rdi)
29159 movq %r11, 0x8*6(%rdi)
29160- movq %r12, 0x8*7(%rdi)
29161+ movq %r13, 0x8*7(%rdi)
29162
29163 leaq 64 (%rsi), %rsi
29164 leaq 64 (%rdi), %rdi
29165@@ -68,7 +69,7 @@ ENTRY(copy_page)
29166 movq 0x8*4(%rsi), %r9
29167 movq 0x8*5(%rsi), %r10
29168 movq 0x8*6(%rsi), %r11
29169- movq 0x8*7(%rsi), %r12
29170+ movq 0x8*7(%rsi), %r13
29171
29172 movq %rax, 0x8*0(%rdi)
29173 movq %rbx, 0x8*1(%rdi)
29174@@ -77,7 +78,7 @@ ENTRY(copy_page)
29175 movq %r9, 0x8*4(%rdi)
29176 movq %r10, 0x8*5(%rdi)
29177 movq %r11, 0x8*6(%rdi)
29178- movq %r12, 0x8*7(%rdi)
29179+ movq %r13, 0x8*7(%rdi)
29180
29181 leaq 64(%rdi), %rdi
29182 leaq 64(%rsi), %rsi
29183@@ -85,10 +86,11 @@ ENTRY(copy_page)
29184
29185 movq (%rsp), %rbx
29186 CFI_RESTORE rbx
29187- movq 1*8(%rsp), %r12
29188- CFI_RESTORE r12
29189+ movq 1*8(%rsp), %r13
29190+ CFI_RESTORE r13
29191 addq $2*8, %rsp
29192 CFI_ADJUST_CFA_OFFSET -2*8
29193+ pax_force_retaddr
29194 ret
29195 .Lcopy_page_end:
29196 CFI_ENDPROC
29197@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29198
29199 #include <asm/cpufeature.h>
29200
29201- .section .altinstr_replacement,"ax"
29202+ .section .altinstr_replacement,"a"
29203 1: .byte 0xeb /* jmp <disp8> */
29204 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29205 2:
29206diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29207index dee945d..a84067b 100644
29208--- a/arch/x86/lib/copy_user_64.S
29209+++ b/arch/x86/lib/copy_user_64.S
29210@@ -18,31 +18,7 @@
29211 #include <asm/alternative-asm.h>
29212 #include <asm/asm.h>
29213 #include <asm/smap.h>
29214-
29215-/*
29216- * By placing feature2 after feature1 in altinstructions section, we logically
29217- * implement:
29218- * If CPU has feature2, jmp to alt2 is used
29219- * else if CPU has feature1, jmp to alt1 is used
29220- * else jmp to orig is used.
29221- */
29222- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29223-0:
29224- .byte 0xe9 /* 32bit jump */
29225- .long \orig-1f /* by default jump to orig */
29226-1:
29227- .section .altinstr_replacement,"ax"
29228-2: .byte 0xe9 /* near jump with 32bit immediate */
29229- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29230-3: .byte 0xe9 /* near jump with 32bit immediate */
29231- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29232- .previous
29233-
29234- .section .altinstructions,"a"
29235- altinstruction_entry 0b,2b,\feature1,5,5
29236- altinstruction_entry 0b,3b,\feature2,5,5
29237- .previous
29238- .endm
29239+#include <asm/pgtable.h>
29240
29241 .macro ALIGN_DESTINATION
29242 #ifdef FIX_ALIGNMENT
29243@@ -70,52 +46,6 @@
29244 #endif
29245 .endm
29246
29247-/* Standard copy_to_user with segment limit checking */
29248-ENTRY(_copy_to_user)
29249- CFI_STARTPROC
29250- GET_THREAD_INFO(%rax)
29251- movq %rdi,%rcx
29252- addq %rdx,%rcx
29253- jc bad_to_user
29254- cmpq TI_addr_limit(%rax),%rcx
29255- ja bad_to_user
29256- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29257- copy_user_generic_unrolled,copy_user_generic_string, \
29258- copy_user_enhanced_fast_string
29259- CFI_ENDPROC
29260-ENDPROC(_copy_to_user)
29261-
29262-/* Standard copy_from_user with segment limit checking */
29263-ENTRY(_copy_from_user)
29264- CFI_STARTPROC
29265- GET_THREAD_INFO(%rax)
29266- movq %rsi,%rcx
29267- addq %rdx,%rcx
29268- jc bad_from_user
29269- cmpq TI_addr_limit(%rax),%rcx
29270- ja bad_from_user
29271- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29272- copy_user_generic_unrolled,copy_user_generic_string, \
29273- copy_user_enhanced_fast_string
29274- CFI_ENDPROC
29275-ENDPROC(_copy_from_user)
29276-
29277- .section .fixup,"ax"
29278- /* must zero dest */
29279-ENTRY(bad_from_user)
29280-bad_from_user:
29281- CFI_STARTPROC
29282- movl %edx,%ecx
29283- xorl %eax,%eax
29284- rep
29285- stosb
29286-bad_to_user:
29287- movl %edx,%eax
29288- ret
29289- CFI_ENDPROC
29290-ENDPROC(bad_from_user)
29291- .previous
29292-
29293 /*
29294 * copy_user_generic_unrolled - memory copy with exception handling.
29295 * This version is for CPUs like P4 that don't have efficient micro
29296@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29297 */
29298 ENTRY(copy_user_generic_unrolled)
29299 CFI_STARTPROC
29300+ ASM_PAX_OPEN_USERLAND
29301 ASM_STAC
29302 cmpl $8,%edx
29303 jb 20f /* less then 8 bytes, go to byte copy loop */
29304@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29305 jnz 21b
29306 23: xor %eax,%eax
29307 ASM_CLAC
29308+ ASM_PAX_CLOSE_USERLAND
29309+ pax_force_retaddr
29310 ret
29311
29312 .section .fixup,"ax"
29313@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29314 */
29315 ENTRY(copy_user_generic_string)
29316 CFI_STARTPROC
29317+ ASM_PAX_OPEN_USERLAND
29318 ASM_STAC
29319 cmpl $8,%edx
29320 jb 2f /* less than 8 bytes, go to byte copy loop */
29321@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29322 movsb
29323 xorl %eax,%eax
29324 ASM_CLAC
29325+ ASM_PAX_CLOSE_USERLAND
29326+ pax_force_retaddr
29327 ret
29328
29329 .section .fixup,"ax"
29330@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29331 */
29332 ENTRY(copy_user_enhanced_fast_string)
29333 CFI_STARTPROC
29334+ ASM_PAX_OPEN_USERLAND
29335 ASM_STAC
29336 movl %edx,%ecx
29337 1: rep
29338 movsb
29339 xorl %eax,%eax
29340 ASM_CLAC
29341+ ASM_PAX_CLOSE_USERLAND
29342+ pax_force_retaddr
29343 ret
29344
29345 .section .fixup,"ax"
29346diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29347index 6a4f43c..c70fb52 100644
29348--- a/arch/x86/lib/copy_user_nocache_64.S
29349+++ b/arch/x86/lib/copy_user_nocache_64.S
29350@@ -8,6 +8,7 @@
29351
29352 #include <linux/linkage.h>
29353 #include <asm/dwarf2.h>
29354+#include <asm/alternative-asm.h>
29355
29356 #define FIX_ALIGNMENT 1
29357
29358@@ -16,6 +17,7 @@
29359 #include <asm/thread_info.h>
29360 #include <asm/asm.h>
29361 #include <asm/smap.h>
29362+#include <asm/pgtable.h>
29363
29364 .macro ALIGN_DESTINATION
29365 #ifdef FIX_ALIGNMENT
29366@@ -49,6 +51,16 @@
29367 */
29368 ENTRY(__copy_user_nocache)
29369 CFI_STARTPROC
29370+
29371+#ifdef CONFIG_PAX_MEMORY_UDEREF
29372+ mov pax_user_shadow_base,%rcx
29373+ cmp %rcx,%rsi
29374+ jae 1f
29375+ add %rcx,%rsi
29376+1:
29377+#endif
29378+
29379+ ASM_PAX_OPEN_USERLAND
29380 ASM_STAC
29381 cmpl $8,%edx
29382 jb 20f /* less then 8 bytes, go to byte copy loop */
29383@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29384 jnz 21b
29385 23: xorl %eax,%eax
29386 ASM_CLAC
29387+ ASM_PAX_CLOSE_USERLAND
29388 sfence
29389+ pax_force_retaddr
29390 ret
29391
29392 .section .fixup,"ax"
29393diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29394index 2419d5f..fe52d0e 100644
29395--- a/arch/x86/lib/csum-copy_64.S
29396+++ b/arch/x86/lib/csum-copy_64.S
29397@@ -9,6 +9,7 @@
29398 #include <asm/dwarf2.h>
29399 #include <asm/errno.h>
29400 #include <asm/asm.h>
29401+#include <asm/alternative-asm.h>
29402
29403 /*
29404 * Checksum copy with exception handling.
29405@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29406 CFI_ADJUST_CFA_OFFSET 7*8
29407 movq %rbx, 2*8(%rsp)
29408 CFI_REL_OFFSET rbx, 2*8
29409- movq %r12, 3*8(%rsp)
29410- CFI_REL_OFFSET r12, 3*8
29411+ movq %r15, 3*8(%rsp)
29412+ CFI_REL_OFFSET r15, 3*8
29413 movq %r14, 4*8(%rsp)
29414 CFI_REL_OFFSET r14, 4*8
29415 movq %r13, 5*8(%rsp)
29416@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29417 movl %edx, %ecx
29418
29419 xorl %r9d, %r9d
29420- movq %rcx, %r12
29421+ movq %rcx, %r15
29422
29423- shrq $6, %r12
29424+ shrq $6, %r15
29425 jz .Lhandle_tail /* < 64 */
29426
29427 clc
29428
29429 /* main loop. clear in 64 byte blocks */
29430 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29431- /* r11: temp3, rdx: temp4, r12 loopcnt */
29432+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29433 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29434 .p2align 4
29435 .Lloop:
29436@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29437 adcq %r14, %rax
29438 adcq %r13, %rax
29439
29440- decl %r12d
29441+ decl %r15d
29442
29443 dest
29444 movq %rbx, (%rsi)
29445@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29446 .Lende:
29447 movq 2*8(%rsp), %rbx
29448 CFI_RESTORE rbx
29449- movq 3*8(%rsp), %r12
29450- CFI_RESTORE r12
29451+ movq 3*8(%rsp), %r15
29452+ CFI_RESTORE r15
29453 movq 4*8(%rsp), %r14
29454 CFI_RESTORE r14
29455 movq 5*8(%rsp), %r13
29456@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29457 CFI_RESTORE rbp
29458 addq $7*8, %rsp
29459 CFI_ADJUST_CFA_OFFSET -7*8
29460+ pax_force_retaddr
29461 ret
29462 CFI_RESTORE_STATE
29463
29464diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29465index 7609e0e..b449b98 100644
29466--- a/arch/x86/lib/csum-wrappers_64.c
29467+++ b/arch/x86/lib/csum-wrappers_64.c
29468@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29469 len -= 2;
29470 }
29471 }
29472+ pax_open_userland();
29473 stac();
29474- isum = csum_partial_copy_generic((__force const void *)src,
29475+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29476 dst, len, isum, errp, NULL);
29477 clac();
29478+ pax_close_userland();
29479 if (unlikely(*errp))
29480 goto out_err;
29481
29482@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29483 }
29484
29485 *errp = 0;
29486+ pax_open_userland();
29487 stac();
29488- ret = csum_partial_copy_generic(src, (void __force *)dst,
29489+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29490 len, isum, NULL, errp);
29491 clac();
29492+ pax_close_userland();
29493 return ret;
29494 }
29495 EXPORT_SYMBOL(csum_partial_copy_to_user);
29496diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29497index a451235..1daa956 100644
29498--- a/arch/x86/lib/getuser.S
29499+++ b/arch/x86/lib/getuser.S
29500@@ -33,17 +33,40 @@
29501 #include <asm/thread_info.h>
29502 #include <asm/asm.h>
29503 #include <asm/smap.h>
29504+#include <asm/segment.h>
29505+#include <asm/pgtable.h>
29506+#include <asm/alternative-asm.h>
29507+
29508+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29509+#define __copyuser_seg gs;
29510+#else
29511+#define __copyuser_seg
29512+#endif
29513
29514 .text
29515 ENTRY(__get_user_1)
29516 CFI_STARTPROC
29517+
29518+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29519 GET_THREAD_INFO(%_ASM_DX)
29520 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29521 jae bad_get_user
29522 ASM_STAC
29523-1: movzbl (%_ASM_AX),%edx
29524+
29525+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29526+ mov pax_user_shadow_base,%_ASM_DX
29527+ cmp %_ASM_DX,%_ASM_AX
29528+ jae 1234f
29529+ add %_ASM_DX,%_ASM_AX
29530+1234:
29531+#endif
29532+
29533+#endif
29534+
29535+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29536 xor %eax,%eax
29537 ASM_CLAC
29538+ pax_force_retaddr
29539 ret
29540 CFI_ENDPROC
29541 ENDPROC(__get_user_1)
29542@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29543 ENTRY(__get_user_2)
29544 CFI_STARTPROC
29545 add $1,%_ASM_AX
29546+
29547+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29548 jc bad_get_user
29549 GET_THREAD_INFO(%_ASM_DX)
29550 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29551 jae bad_get_user
29552 ASM_STAC
29553-2: movzwl -1(%_ASM_AX),%edx
29554+
29555+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29556+ mov pax_user_shadow_base,%_ASM_DX
29557+ cmp %_ASM_DX,%_ASM_AX
29558+ jae 1234f
29559+ add %_ASM_DX,%_ASM_AX
29560+1234:
29561+#endif
29562+
29563+#endif
29564+
29565+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29566 xor %eax,%eax
29567 ASM_CLAC
29568+ pax_force_retaddr
29569 ret
29570 CFI_ENDPROC
29571 ENDPROC(__get_user_2)
29572@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29573 ENTRY(__get_user_4)
29574 CFI_STARTPROC
29575 add $3,%_ASM_AX
29576+
29577+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29578 jc bad_get_user
29579 GET_THREAD_INFO(%_ASM_DX)
29580 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29581 jae bad_get_user
29582 ASM_STAC
29583-3: movl -3(%_ASM_AX),%edx
29584+
29585+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29586+ mov pax_user_shadow_base,%_ASM_DX
29587+ cmp %_ASM_DX,%_ASM_AX
29588+ jae 1234f
29589+ add %_ASM_DX,%_ASM_AX
29590+1234:
29591+#endif
29592+
29593+#endif
29594+
29595+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29596 xor %eax,%eax
29597 ASM_CLAC
29598+ pax_force_retaddr
29599 ret
29600 CFI_ENDPROC
29601 ENDPROC(__get_user_4)
29602@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29603 GET_THREAD_INFO(%_ASM_DX)
29604 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29605 jae bad_get_user
29606+
29607+#ifdef CONFIG_PAX_MEMORY_UDEREF
29608+ mov pax_user_shadow_base,%_ASM_DX
29609+ cmp %_ASM_DX,%_ASM_AX
29610+ jae 1234f
29611+ add %_ASM_DX,%_ASM_AX
29612+1234:
29613+#endif
29614+
29615 ASM_STAC
29616 4: movq -7(%_ASM_AX),%rdx
29617 xor %eax,%eax
29618 ASM_CLAC
29619+ pax_force_retaddr
29620 ret
29621 #else
29622 add $7,%_ASM_AX
29623@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29624 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29625 jae bad_get_user_8
29626 ASM_STAC
29627-4: movl -7(%_ASM_AX),%edx
29628-5: movl -3(%_ASM_AX),%ecx
29629+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29630+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29631 xor %eax,%eax
29632 ASM_CLAC
29633+ pax_force_retaddr
29634 ret
29635 #endif
29636 CFI_ENDPROC
29637@@ -113,6 +175,7 @@ bad_get_user:
29638 xor %edx,%edx
29639 mov $(-EFAULT),%_ASM_AX
29640 ASM_CLAC
29641+ pax_force_retaddr
29642 ret
29643 CFI_ENDPROC
29644 END(bad_get_user)
29645@@ -124,6 +187,7 @@ bad_get_user_8:
29646 xor %ecx,%ecx
29647 mov $(-EFAULT),%_ASM_AX
29648 ASM_CLAC
29649+ pax_force_retaddr
29650 ret
29651 CFI_ENDPROC
29652 END(bad_get_user_8)
29653diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29654index 54fcffe..7be149e 100644
29655--- a/arch/x86/lib/insn.c
29656+++ b/arch/x86/lib/insn.c
29657@@ -20,8 +20,10 @@
29658
29659 #ifdef __KERNEL__
29660 #include <linux/string.h>
29661+#include <asm/pgtable_types.h>
29662 #else
29663 #include <string.h>
29664+#define ktla_ktva(addr) addr
29665 #endif
29666 #include <asm/inat.h>
29667 #include <asm/insn.h>
29668@@ -53,8 +55,8 @@
29669 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29670 {
29671 memset(insn, 0, sizeof(*insn));
29672- insn->kaddr = kaddr;
29673- insn->next_byte = kaddr;
29674+ insn->kaddr = ktla_ktva(kaddr);
29675+ insn->next_byte = ktla_ktva(kaddr);
29676 insn->x86_64 = x86_64 ? 1 : 0;
29677 insn->opnd_bytes = 4;
29678 if (x86_64)
29679diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29680index 05a95e7..326f2fa 100644
29681--- a/arch/x86/lib/iomap_copy_64.S
29682+++ b/arch/x86/lib/iomap_copy_64.S
29683@@ -17,6 +17,7 @@
29684
29685 #include <linux/linkage.h>
29686 #include <asm/dwarf2.h>
29687+#include <asm/alternative-asm.h>
29688
29689 /*
29690 * override generic version in lib/iomap_copy.c
29691@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29692 CFI_STARTPROC
29693 movl %edx,%ecx
29694 rep movsd
29695+ pax_force_retaddr
29696 ret
29697 CFI_ENDPROC
29698 ENDPROC(__iowrite32_copy)
29699diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29700index 56313a3..0db417e 100644
29701--- a/arch/x86/lib/memcpy_64.S
29702+++ b/arch/x86/lib/memcpy_64.S
29703@@ -24,7 +24,7 @@
29704 * This gets patched over the unrolled variant (below) via the
29705 * alternative instructions framework:
29706 */
29707- .section .altinstr_replacement, "ax", @progbits
29708+ .section .altinstr_replacement, "a", @progbits
29709 .Lmemcpy_c:
29710 movq %rdi, %rax
29711 movq %rdx, %rcx
29712@@ -33,6 +33,7 @@
29713 rep movsq
29714 movl %edx, %ecx
29715 rep movsb
29716+ pax_force_retaddr
29717 ret
29718 .Lmemcpy_e:
29719 .previous
29720@@ -44,11 +45,12 @@
29721 * This gets patched over the unrolled variant (below) via the
29722 * alternative instructions framework:
29723 */
29724- .section .altinstr_replacement, "ax", @progbits
29725+ .section .altinstr_replacement, "a", @progbits
29726 .Lmemcpy_c_e:
29727 movq %rdi, %rax
29728 movq %rdx, %rcx
29729 rep movsb
29730+ pax_force_retaddr
29731 ret
29732 .Lmemcpy_e_e:
29733 .previous
29734@@ -136,6 +138,7 @@ ENTRY(memcpy)
29735 movq %r9, 1*8(%rdi)
29736 movq %r10, -2*8(%rdi, %rdx)
29737 movq %r11, -1*8(%rdi, %rdx)
29738+ pax_force_retaddr
29739 retq
29740 .p2align 4
29741 .Lless_16bytes:
29742@@ -148,6 +151,7 @@ ENTRY(memcpy)
29743 movq -1*8(%rsi, %rdx), %r9
29744 movq %r8, 0*8(%rdi)
29745 movq %r9, -1*8(%rdi, %rdx)
29746+ pax_force_retaddr
29747 retq
29748 .p2align 4
29749 .Lless_8bytes:
29750@@ -161,6 +165,7 @@ ENTRY(memcpy)
29751 movl -4(%rsi, %rdx), %r8d
29752 movl %ecx, (%rdi)
29753 movl %r8d, -4(%rdi, %rdx)
29754+ pax_force_retaddr
29755 retq
29756 .p2align 4
29757 .Lless_3bytes:
29758@@ -179,6 +184,7 @@ ENTRY(memcpy)
29759 movb %cl, (%rdi)
29760
29761 .Lend:
29762+ pax_force_retaddr
29763 retq
29764 CFI_ENDPROC
29765 ENDPROC(memcpy)
29766diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29767index 65268a6..dd1de11 100644
29768--- a/arch/x86/lib/memmove_64.S
29769+++ b/arch/x86/lib/memmove_64.S
29770@@ -202,14 +202,16 @@ ENTRY(memmove)
29771 movb (%rsi), %r11b
29772 movb %r11b, (%rdi)
29773 13:
29774+ pax_force_retaddr
29775 retq
29776 CFI_ENDPROC
29777
29778- .section .altinstr_replacement,"ax"
29779+ .section .altinstr_replacement,"a"
29780 .Lmemmove_begin_forward_efs:
29781 /* Forward moving data. */
29782 movq %rdx, %rcx
29783 rep movsb
29784+ pax_force_retaddr
29785 retq
29786 .Lmemmove_end_forward_efs:
29787 .previous
29788diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29789index 2dcb380..2eb79fe 100644
29790--- a/arch/x86/lib/memset_64.S
29791+++ b/arch/x86/lib/memset_64.S
29792@@ -16,7 +16,7 @@
29793 *
29794 * rax original destination
29795 */
29796- .section .altinstr_replacement, "ax", @progbits
29797+ .section .altinstr_replacement, "a", @progbits
29798 .Lmemset_c:
29799 movq %rdi,%r9
29800 movq %rdx,%rcx
29801@@ -30,6 +30,7 @@
29802 movl %edx,%ecx
29803 rep stosb
29804 movq %r9,%rax
29805+ pax_force_retaddr
29806 ret
29807 .Lmemset_e:
29808 .previous
29809@@ -45,13 +46,14 @@
29810 *
29811 * rax original destination
29812 */
29813- .section .altinstr_replacement, "ax", @progbits
29814+ .section .altinstr_replacement, "a", @progbits
29815 .Lmemset_c_e:
29816 movq %rdi,%r9
29817 movb %sil,%al
29818 movq %rdx,%rcx
29819 rep stosb
29820 movq %r9,%rax
29821+ pax_force_retaddr
29822 ret
29823 .Lmemset_e_e:
29824 .previous
29825@@ -118,6 +120,7 @@ ENTRY(__memset)
29826
29827 .Lende:
29828 movq %r10,%rax
29829+ pax_force_retaddr
29830 ret
29831
29832 CFI_RESTORE_STATE
29833diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29834index c9f2d9b..e7fd2c0 100644
29835--- a/arch/x86/lib/mmx_32.c
29836+++ b/arch/x86/lib/mmx_32.c
29837@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29838 {
29839 void *p;
29840 int i;
29841+ unsigned long cr0;
29842
29843 if (unlikely(in_interrupt()))
29844 return __memcpy(to, from, len);
29845@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29846 kernel_fpu_begin();
29847
29848 __asm__ __volatile__ (
29849- "1: prefetch (%0)\n" /* This set is 28 bytes */
29850- " prefetch 64(%0)\n"
29851- " prefetch 128(%0)\n"
29852- " prefetch 192(%0)\n"
29853- " prefetch 256(%0)\n"
29854+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29855+ " prefetch 64(%1)\n"
29856+ " prefetch 128(%1)\n"
29857+ " prefetch 192(%1)\n"
29858+ " prefetch 256(%1)\n"
29859 "2: \n"
29860 ".section .fixup, \"ax\"\n"
29861- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29862+ "3: \n"
29863+
29864+#ifdef CONFIG_PAX_KERNEXEC
29865+ " movl %%cr0, %0\n"
29866+ " movl %0, %%eax\n"
29867+ " andl $0xFFFEFFFF, %%eax\n"
29868+ " movl %%eax, %%cr0\n"
29869+#endif
29870+
29871+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29872+
29873+#ifdef CONFIG_PAX_KERNEXEC
29874+ " movl %0, %%cr0\n"
29875+#endif
29876+
29877 " jmp 2b\n"
29878 ".previous\n"
29879 _ASM_EXTABLE(1b, 3b)
29880- : : "r" (from));
29881+ : "=&r" (cr0) : "r" (from) : "ax");
29882
29883 for ( ; i > 5; i--) {
29884 __asm__ __volatile__ (
29885- "1: prefetch 320(%0)\n"
29886- "2: movq (%0), %%mm0\n"
29887- " movq 8(%0), %%mm1\n"
29888- " movq 16(%0), %%mm2\n"
29889- " movq 24(%0), %%mm3\n"
29890- " movq %%mm0, (%1)\n"
29891- " movq %%mm1, 8(%1)\n"
29892- " movq %%mm2, 16(%1)\n"
29893- " movq %%mm3, 24(%1)\n"
29894- " movq 32(%0), %%mm0\n"
29895- " movq 40(%0), %%mm1\n"
29896- " movq 48(%0), %%mm2\n"
29897- " movq 56(%0), %%mm3\n"
29898- " movq %%mm0, 32(%1)\n"
29899- " movq %%mm1, 40(%1)\n"
29900- " movq %%mm2, 48(%1)\n"
29901- " movq %%mm3, 56(%1)\n"
29902+ "1: prefetch 320(%1)\n"
29903+ "2: movq (%1), %%mm0\n"
29904+ " movq 8(%1), %%mm1\n"
29905+ " movq 16(%1), %%mm2\n"
29906+ " movq 24(%1), %%mm3\n"
29907+ " movq %%mm0, (%2)\n"
29908+ " movq %%mm1, 8(%2)\n"
29909+ " movq %%mm2, 16(%2)\n"
29910+ " movq %%mm3, 24(%2)\n"
29911+ " movq 32(%1), %%mm0\n"
29912+ " movq 40(%1), %%mm1\n"
29913+ " movq 48(%1), %%mm2\n"
29914+ " movq 56(%1), %%mm3\n"
29915+ " movq %%mm0, 32(%2)\n"
29916+ " movq %%mm1, 40(%2)\n"
29917+ " movq %%mm2, 48(%2)\n"
29918+ " movq %%mm3, 56(%2)\n"
29919 ".section .fixup, \"ax\"\n"
29920- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29921+ "3:\n"
29922+
29923+#ifdef CONFIG_PAX_KERNEXEC
29924+ " movl %%cr0, %0\n"
29925+ " movl %0, %%eax\n"
29926+ " andl $0xFFFEFFFF, %%eax\n"
29927+ " movl %%eax, %%cr0\n"
29928+#endif
29929+
29930+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29931+
29932+#ifdef CONFIG_PAX_KERNEXEC
29933+ " movl %0, %%cr0\n"
29934+#endif
29935+
29936 " jmp 2b\n"
29937 ".previous\n"
29938 _ASM_EXTABLE(1b, 3b)
29939- : : "r" (from), "r" (to) : "memory");
29940+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29941
29942 from += 64;
29943 to += 64;
29944@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29945 static void fast_copy_page(void *to, void *from)
29946 {
29947 int i;
29948+ unsigned long cr0;
29949
29950 kernel_fpu_begin();
29951
29952@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29953 * but that is for later. -AV
29954 */
29955 __asm__ __volatile__(
29956- "1: prefetch (%0)\n"
29957- " prefetch 64(%0)\n"
29958- " prefetch 128(%0)\n"
29959- " prefetch 192(%0)\n"
29960- " prefetch 256(%0)\n"
29961+ "1: prefetch (%1)\n"
29962+ " prefetch 64(%1)\n"
29963+ " prefetch 128(%1)\n"
29964+ " prefetch 192(%1)\n"
29965+ " prefetch 256(%1)\n"
29966 "2: \n"
29967 ".section .fixup, \"ax\"\n"
29968- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29969+ "3: \n"
29970+
29971+#ifdef CONFIG_PAX_KERNEXEC
29972+ " movl %%cr0, %0\n"
29973+ " movl %0, %%eax\n"
29974+ " andl $0xFFFEFFFF, %%eax\n"
29975+ " movl %%eax, %%cr0\n"
29976+#endif
29977+
29978+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29979+
29980+#ifdef CONFIG_PAX_KERNEXEC
29981+ " movl %0, %%cr0\n"
29982+#endif
29983+
29984 " jmp 2b\n"
29985 ".previous\n"
29986- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29987+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29988
29989 for (i = 0; i < (4096-320)/64; i++) {
29990 __asm__ __volatile__ (
29991- "1: prefetch 320(%0)\n"
29992- "2: movq (%0), %%mm0\n"
29993- " movntq %%mm0, (%1)\n"
29994- " movq 8(%0), %%mm1\n"
29995- " movntq %%mm1, 8(%1)\n"
29996- " movq 16(%0), %%mm2\n"
29997- " movntq %%mm2, 16(%1)\n"
29998- " movq 24(%0), %%mm3\n"
29999- " movntq %%mm3, 24(%1)\n"
30000- " movq 32(%0), %%mm4\n"
30001- " movntq %%mm4, 32(%1)\n"
30002- " movq 40(%0), %%mm5\n"
30003- " movntq %%mm5, 40(%1)\n"
30004- " movq 48(%0), %%mm6\n"
30005- " movntq %%mm6, 48(%1)\n"
30006- " movq 56(%0), %%mm7\n"
30007- " movntq %%mm7, 56(%1)\n"
30008+ "1: prefetch 320(%1)\n"
30009+ "2: movq (%1), %%mm0\n"
30010+ " movntq %%mm0, (%2)\n"
30011+ " movq 8(%1), %%mm1\n"
30012+ " movntq %%mm1, 8(%2)\n"
30013+ " movq 16(%1), %%mm2\n"
30014+ " movntq %%mm2, 16(%2)\n"
30015+ " movq 24(%1), %%mm3\n"
30016+ " movntq %%mm3, 24(%2)\n"
30017+ " movq 32(%1), %%mm4\n"
30018+ " movntq %%mm4, 32(%2)\n"
30019+ " movq 40(%1), %%mm5\n"
30020+ " movntq %%mm5, 40(%2)\n"
30021+ " movq 48(%1), %%mm6\n"
30022+ " movntq %%mm6, 48(%2)\n"
30023+ " movq 56(%1), %%mm7\n"
30024+ " movntq %%mm7, 56(%2)\n"
30025 ".section .fixup, \"ax\"\n"
30026- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30027+ "3:\n"
30028+
30029+#ifdef CONFIG_PAX_KERNEXEC
30030+ " movl %%cr0, %0\n"
30031+ " movl %0, %%eax\n"
30032+ " andl $0xFFFEFFFF, %%eax\n"
30033+ " movl %%eax, %%cr0\n"
30034+#endif
30035+
30036+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30037+
30038+#ifdef CONFIG_PAX_KERNEXEC
30039+ " movl %0, %%cr0\n"
30040+#endif
30041+
30042 " jmp 2b\n"
30043 ".previous\n"
30044- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30045+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30046
30047 from += 64;
30048 to += 64;
30049@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30050 static void fast_copy_page(void *to, void *from)
30051 {
30052 int i;
30053+ unsigned long cr0;
30054
30055 kernel_fpu_begin();
30056
30057 __asm__ __volatile__ (
30058- "1: prefetch (%0)\n"
30059- " prefetch 64(%0)\n"
30060- " prefetch 128(%0)\n"
30061- " prefetch 192(%0)\n"
30062- " prefetch 256(%0)\n"
30063+ "1: prefetch (%1)\n"
30064+ " prefetch 64(%1)\n"
30065+ " prefetch 128(%1)\n"
30066+ " prefetch 192(%1)\n"
30067+ " prefetch 256(%1)\n"
30068 "2: \n"
30069 ".section .fixup, \"ax\"\n"
30070- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30071+ "3: \n"
30072+
30073+#ifdef CONFIG_PAX_KERNEXEC
30074+ " movl %%cr0, %0\n"
30075+ " movl %0, %%eax\n"
30076+ " andl $0xFFFEFFFF, %%eax\n"
30077+ " movl %%eax, %%cr0\n"
30078+#endif
30079+
30080+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30081+
30082+#ifdef CONFIG_PAX_KERNEXEC
30083+ " movl %0, %%cr0\n"
30084+#endif
30085+
30086 " jmp 2b\n"
30087 ".previous\n"
30088- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30089+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30090
30091 for (i = 0; i < 4096/64; i++) {
30092 __asm__ __volatile__ (
30093- "1: prefetch 320(%0)\n"
30094- "2: movq (%0), %%mm0\n"
30095- " movq 8(%0), %%mm1\n"
30096- " movq 16(%0), %%mm2\n"
30097- " movq 24(%0), %%mm3\n"
30098- " movq %%mm0, (%1)\n"
30099- " movq %%mm1, 8(%1)\n"
30100- " movq %%mm2, 16(%1)\n"
30101- " movq %%mm3, 24(%1)\n"
30102- " movq 32(%0), %%mm0\n"
30103- " movq 40(%0), %%mm1\n"
30104- " movq 48(%0), %%mm2\n"
30105- " movq 56(%0), %%mm3\n"
30106- " movq %%mm0, 32(%1)\n"
30107- " movq %%mm1, 40(%1)\n"
30108- " movq %%mm2, 48(%1)\n"
30109- " movq %%mm3, 56(%1)\n"
30110+ "1: prefetch 320(%1)\n"
30111+ "2: movq (%1), %%mm0\n"
30112+ " movq 8(%1), %%mm1\n"
30113+ " movq 16(%1), %%mm2\n"
30114+ " movq 24(%1), %%mm3\n"
30115+ " movq %%mm0, (%2)\n"
30116+ " movq %%mm1, 8(%2)\n"
30117+ " movq %%mm2, 16(%2)\n"
30118+ " movq %%mm3, 24(%2)\n"
30119+ " movq 32(%1), %%mm0\n"
30120+ " movq 40(%1), %%mm1\n"
30121+ " movq 48(%1), %%mm2\n"
30122+ " movq 56(%1), %%mm3\n"
30123+ " movq %%mm0, 32(%2)\n"
30124+ " movq %%mm1, 40(%2)\n"
30125+ " movq %%mm2, 48(%2)\n"
30126+ " movq %%mm3, 56(%2)\n"
30127 ".section .fixup, \"ax\"\n"
30128- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30129+ "3:\n"
30130+
30131+#ifdef CONFIG_PAX_KERNEXEC
30132+ " movl %%cr0, %0\n"
30133+ " movl %0, %%eax\n"
30134+ " andl $0xFFFEFFFF, %%eax\n"
30135+ " movl %%eax, %%cr0\n"
30136+#endif
30137+
30138+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30139+
30140+#ifdef CONFIG_PAX_KERNEXEC
30141+ " movl %0, %%cr0\n"
30142+#endif
30143+
30144 " jmp 2b\n"
30145 ".previous\n"
30146 _ASM_EXTABLE(1b, 3b)
30147- : : "r" (from), "r" (to) : "memory");
30148+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30149
30150 from += 64;
30151 to += 64;
30152diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30153index f6d13ee..d789440 100644
30154--- a/arch/x86/lib/msr-reg.S
30155+++ b/arch/x86/lib/msr-reg.S
30156@@ -3,6 +3,7 @@
30157 #include <asm/dwarf2.h>
30158 #include <asm/asm.h>
30159 #include <asm/msr.h>
30160+#include <asm/alternative-asm.h>
30161
30162 #ifdef CONFIG_X86_64
30163 /*
30164@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30165 movl %edi, 28(%r10)
30166 popq_cfi %rbp
30167 popq_cfi %rbx
30168+ pax_force_retaddr
30169 ret
30170 3:
30171 CFI_RESTORE_STATE
30172diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30173index fc6ba17..d4d989d 100644
30174--- a/arch/x86/lib/putuser.S
30175+++ b/arch/x86/lib/putuser.S
30176@@ -16,7 +16,9 @@
30177 #include <asm/errno.h>
30178 #include <asm/asm.h>
30179 #include <asm/smap.h>
30180-
30181+#include <asm/segment.h>
30182+#include <asm/pgtable.h>
30183+#include <asm/alternative-asm.h>
30184
30185 /*
30186 * __put_user_X
30187@@ -30,57 +32,125 @@
30188 * as they get called from within inline assembly.
30189 */
30190
30191-#define ENTER CFI_STARTPROC ; \
30192- GET_THREAD_INFO(%_ASM_BX)
30193-#define EXIT ASM_CLAC ; \
30194- ret ; \
30195+#define ENTER CFI_STARTPROC
30196+#define EXIT ASM_CLAC ; \
30197+ pax_force_retaddr ; \
30198+ ret ; \
30199 CFI_ENDPROC
30200
30201+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30202+#define _DEST %_ASM_CX,%_ASM_BX
30203+#else
30204+#define _DEST %_ASM_CX
30205+#endif
30206+
30207+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30208+#define __copyuser_seg gs;
30209+#else
30210+#define __copyuser_seg
30211+#endif
30212+
30213 .text
30214 ENTRY(__put_user_1)
30215 ENTER
30216+
30217+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30218+ GET_THREAD_INFO(%_ASM_BX)
30219 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30220 jae bad_put_user
30221 ASM_STAC
30222-1: movb %al,(%_ASM_CX)
30223+
30224+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30225+ mov pax_user_shadow_base,%_ASM_BX
30226+ cmp %_ASM_BX,%_ASM_CX
30227+ jb 1234f
30228+ xor %ebx,%ebx
30229+1234:
30230+#endif
30231+
30232+#endif
30233+
30234+1: __copyuser_seg movb %al,(_DEST)
30235 xor %eax,%eax
30236 EXIT
30237 ENDPROC(__put_user_1)
30238
30239 ENTRY(__put_user_2)
30240 ENTER
30241+
30242+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30243+ GET_THREAD_INFO(%_ASM_BX)
30244 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30245 sub $1,%_ASM_BX
30246 cmp %_ASM_BX,%_ASM_CX
30247 jae bad_put_user
30248 ASM_STAC
30249-2: movw %ax,(%_ASM_CX)
30250+
30251+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30252+ mov pax_user_shadow_base,%_ASM_BX
30253+ cmp %_ASM_BX,%_ASM_CX
30254+ jb 1234f
30255+ xor %ebx,%ebx
30256+1234:
30257+#endif
30258+
30259+#endif
30260+
30261+2: __copyuser_seg movw %ax,(_DEST)
30262 xor %eax,%eax
30263 EXIT
30264 ENDPROC(__put_user_2)
30265
30266 ENTRY(__put_user_4)
30267 ENTER
30268+
30269+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30270+ GET_THREAD_INFO(%_ASM_BX)
30271 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30272 sub $3,%_ASM_BX
30273 cmp %_ASM_BX,%_ASM_CX
30274 jae bad_put_user
30275 ASM_STAC
30276-3: movl %eax,(%_ASM_CX)
30277+
30278+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30279+ mov pax_user_shadow_base,%_ASM_BX
30280+ cmp %_ASM_BX,%_ASM_CX
30281+ jb 1234f
30282+ xor %ebx,%ebx
30283+1234:
30284+#endif
30285+
30286+#endif
30287+
30288+3: __copyuser_seg movl %eax,(_DEST)
30289 xor %eax,%eax
30290 EXIT
30291 ENDPROC(__put_user_4)
30292
30293 ENTRY(__put_user_8)
30294 ENTER
30295+
30296+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30297+ GET_THREAD_INFO(%_ASM_BX)
30298 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30299 sub $7,%_ASM_BX
30300 cmp %_ASM_BX,%_ASM_CX
30301 jae bad_put_user
30302 ASM_STAC
30303-4: mov %_ASM_AX,(%_ASM_CX)
30304+
30305+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30306+ mov pax_user_shadow_base,%_ASM_BX
30307+ cmp %_ASM_BX,%_ASM_CX
30308+ jb 1234f
30309+ xor %ebx,%ebx
30310+1234:
30311+#endif
30312+
30313+#endif
30314+
30315+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30316 #ifdef CONFIG_X86_32
30317-5: movl %edx,4(%_ASM_CX)
30318+5: __copyuser_seg movl %edx,4(_DEST)
30319 #endif
30320 xor %eax,%eax
30321 EXIT
30322diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30323index 1cad221..de671ee 100644
30324--- a/arch/x86/lib/rwlock.S
30325+++ b/arch/x86/lib/rwlock.S
30326@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30327 FRAME
30328 0: LOCK_PREFIX
30329 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30330+
30331+#ifdef CONFIG_PAX_REFCOUNT
30332+ jno 1234f
30333+ LOCK_PREFIX
30334+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30335+ int $4
30336+1234:
30337+ _ASM_EXTABLE(1234b, 1234b)
30338+#endif
30339+
30340 1: rep; nop
30341 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30342 jne 1b
30343 LOCK_PREFIX
30344 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30345+
30346+#ifdef CONFIG_PAX_REFCOUNT
30347+ jno 1234f
30348+ LOCK_PREFIX
30349+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30350+ int $4
30351+1234:
30352+ _ASM_EXTABLE(1234b, 1234b)
30353+#endif
30354+
30355 jnz 0b
30356 ENDFRAME
30357+ pax_force_retaddr
30358 ret
30359 CFI_ENDPROC
30360 END(__write_lock_failed)
30361@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30362 FRAME
30363 0: LOCK_PREFIX
30364 READ_LOCK_SIZE(inc) (%__lock_ptr)
30365+
30366+#ifdef CONFIG_PAX_REFCOUNT
30367+ jno 1234f
30368+ LOCK_PREFIX
30369+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30370+ int $4
30371+1234:
30372+ _ASM_EXTABLE(1234b, 1234b)
30373+#endif
30374+
30375 1: rep; nop
30376 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30377 js 1b
30378 LOCK_PREFIX
30379 READ_LOCK_SIZE(dec) (%__lock_ptr)
30380+
30381+#ifdef CONFIG_PAX_REFCOUNT
30382+ jno 1234f
30383+ LOCK_PREFIX
30384+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30385+ int $4
30386+1234:
30387+ _ASM_EXTABLE(1234b, 1234b)
30388+#endif
30389+
30390 js 0b
30391 ENDFRAME
30392+ pax_force_retaddr
30393 ret
30394 CFI_ENDPROC
30395 END(__read_lock_failed)
30396diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30397index 5dff5f0..cadebf4 100644
30398--- a/arch/x86/lib/rwsem.S
30399+++ b/arch/x86/lib/rwsem.S
30400@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30401 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30402 CFI_RESTORE __ASM_REG(dx)
30403 restore_common_regs
30404+ pax_force_retaddr
30405 ret
30406 CFI_ENDPROC
30407 ENDPROC(call_rwsem_down_read_failed)
30408@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30409 movq %rax,%rdi
30410 call rwsem_down_write_failed
30411 restore_common_regs
30412+ pax_force_retaddr
30413 ret
30414 CFI_ENDPROC
30415 ENDPROC(call_rwsem_down_write_failed)
30416@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30417 movq %rax,%rdi
30418 call rwsem_wake
30419 restore_common_regs
30420-1: ret
30421+1: pax_force_retaddr
30422+ ret
30423 CFI_ENDPROC
30424 ENDPROC(call_rwsem_wake)
30425
30426@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30427 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30428 CFI_RESTORE __ASM_REG(dx)
30429 restore_common_regs
30430+ pax_force_retaddr
30431 ret
30432 CFI_ENDPROC
30433 ENDPROC(call_rwsem_downgrade_wake)
30434diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30435index a63efd6..8149fbe 100644
30436--- a/arch/x86/lib/thunk_64.S
30437+++ b/arch/x86/lib/thunk_64.S
30438@@ -8,6 +8,7 @@
30439 #include <linux/linkage.h>
30440 #include <asm/dwarf2.h>
30441 #include <asm/calling.h>
30442+#include <asm/alternative-asm.h>
30443
30444 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30445 .macro THUNK name, func, put_ret_addr_in_rdi=0
30446@@ -15,11 +16,11 @@
30447 \name:
30448 CFI_STARTPROC
30449
30450- /* this one pushes 9 elems, the next one would be %rIP */
30451- SAVE_ARGS
30452+ /* this one pushes 15+1 elems, the next one would be %rIP */
30453+ SAVE_ARGS 8
30454
30455 .if \put_ret_addr_in_rdi
30456- movq_cfi_restore 9*8, rdi
30457+ movq_cfi_restore RIP, rdi
30458 .endif
30459
30460 call \func
30461@@ -38,8 +39,9 @@
30462
30463 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30464 CFI_STARTPROC
30465- SAVE_ARGS
30466+ SAVE_ARGS 8
30467 restore:
30468- RESTORE_ARGS
30469+ RESTORE_ARGS 1,8
30470+ pax_force_retaddr
30471 ret
30472 CFI_ENDPROC
30473diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30474index e2f5e21..4b22130 100644
30475--- a/arch/x86/lib/usercopy_32.c
30476+++ b/arch/x86/lib/usercopy_32.c
30477@@ -42,11 +42,13 @@ do { \
30478 int __d0; \
30479 might_fault(); \
30480 __asm__ __volatile__( \
30481+ __COPYUSER_SET_ES \
30482 ASM_STAC "\n" \
30483 "0: rep; stosl\n" \
30484 " movl %2,%0\n" \
30485 "1: rep; stosb\n" \
30486 "2: " ASM_CLAC "\n" \
30487+ __COPYUSER_RESTORE_ES \
30488 ".section .fixup,\"ax\"\n" \
30489 "3: lea 0(%2,%0,4),%0\n" \
30490 " jmp 2b\n" \
30491@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30492
30493 #ifdef CONFIG_X86_INTEL_USERCOPY
30494 static unsigned long
30495-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30496+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30497 {
30498 int d0, d1;
30499 __asm__ __volatile__(
30500@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30501 " .align 2,0x90\n"
30502 "3: movl 0(%4), %%eax\n"
30503 "4: movl 4(%4), %%edx\n"
30504- "5: movl %%eax, 0(%3)\n"
30505- "6: movl %%edx, 4(%3)\n"
30506+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30507+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30508 "7: movl 8(%4), %%eax\n"
30509 "8: movl 12(%4),%%edx\n"
30510- "9: movl %%eax, 8(%3)\n"
30511- "10: movl %%edx, 12(%3)\n"
30512+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30513+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30514 "11: movl 16(%4), %%eax\n"
30515 "12: movl 20(%4), %%edx\n"
30516- "13: movl %%eax, 16(%3)\n"
30517- "14: movl %%edx, 20(%3)\n"
30518+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30519+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30520 "15: movl 24(%4), %%eax\n"
30521 "16: movl 28(%4), %%edx\n"
30522- "17: movl %%eax, 24(%3)\n"
30523- "18: movl %%edx, 28(%3)\n"
30524+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30525+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30526 "19: movl 32(%4), %%eax\n"
30527 "20: movl 36(%4), %%edx\n"
30528- "21: movl %%eax, 32(%3)\n"
30529- "22: movl %%edx, 36(%3)\n"
30530+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30531+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30532 "23: movl 40(%4), %%eax\n"
30533 "24: movl 44(%4), %%edx\n"
30534- "25: movl %%eax, 40(%3)\n"
30535- "26: movl %%edx, 44(%3)\n"
30536+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30537+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30538 "27: movl 48(%4), %%eax\n"
30539 "28: movl 52(%4), %%edx\n"
30540- "29: movl %%eax, 48(%3)\n"
30541- "30: movl %%edx, 52(%3)\n"
30542+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30543+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30544 "31: movl 56(%4), %%eax\n"
30545 "32: movl 60(%4), %%edx\n"
30546- "33: movl %%eax, 56(%3)\n"
30547- "34: movl %%edx, 60(%3)\n"
30548+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30549+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30550 " addl $-64, %0\n"
30551 " addl $64, %4\n"
30552 " addl $64, %3\n"
30553@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30554 " shrl $2, %0\n"
30555 " andl $3, %%eax\n"
30556 " cld\n"
30557+ __COPYUSER_SET_ES
30558 "99: rep; movsl\n"
30559 "36: movl %%eax, %0\n"
30560 "37: rep; movsb\n"
30561 "100:\n"
30562+ __COPYUSER_RESTORE_ES
30563+ ".section .fixup,\"ax\"\n"
30564+ "101: lea 0(%%eax,%0,4),%0\n"
30565+ " jmp 100b\n"
30566+ ".previous\n"
30567+ _ASM_EXTABLE(1b,100b)
30568+ _ASM_EXTABLE(2b,100b)
30569+ _ASM_EXTABLE(3b,100b)
30570+ _ASM_EXTABLE(4b,100b)
30571+ _ASM_EXTABLE(5b,100b)
30572+ _ASM_EXTABLE(6b,100b)
30573+ _ASM_EXTABLE(7b,100b)
30574+ _ASM_EXTABLE(8b,100b)
30575+ _ASM_EXTABLE(9b,100b)
30576+ _ASM_EXTABLE(10b,100b)
30577+ _ASM_EXTABLE(11b,100b)
30578+ _ASM_EXTABLE(12b,100b)
30579+ _ASM_EXTABLE(13b,100b)
30580+ _ASM_EXTABLE(14b,100b)
30581+ _ASM_EXTABLE(15b,100b)
30582+ _ASM_EXTABLE(16b,100b)
30583+ _ASM_EXTABLE(17b,100b)
30584+ _ASM_EXTABLE(18b,100b)
30585+ _ASM_EXTABLE(19b,100b)
30586+ _ASM_EXTABLE(20b,100b)
30587+ _ASM_EXTABLE(21b,100b)
30588+ _ASM_EXTABLE(22b,100b)
30589+ _ASM_EXTABLE(23b,100b)
30590+ _ASM_EXTABLE(24b,100b)
30591+ _ASM_EXTABLE(25b,100b)
30592+ _ASM_EXTABLE(26b,100b)
30593+ _ASM_EXTABLE(27b,100b)
30594+ _ASM_EXTABLE(28b,100b)
30595+ _ASM_EXTABLE(29b,100b)
30596+ _ASM_EXTABLE(30b,100b)
30597+ _ASM_EXTABLE(31b,100b)
30598+ _ASM_EXTABLE(32b,100b)
30599+ _ASM_EXTABLE(33b,100b)
30600+ _ASM_EXTABLE(34b,100b)
30601+ _ASM_EXTABLE(35b,100b)
30602+ _ASM_EXTABLE(36b,100b)
30603+ _ASM_EXTABLE(37b,100b)
30604+ _ASM_EXTABLE(99b,101b)
30605+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30606+ : "1"(to), "2"(from), "0"(size)
30607+ : "eax", "edx", "memory");
30608+ return size;
30609+}
30610+
30611+static unsigned long
30612+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30613+{
30614+ int d0, d1;
30615+ __asm__ __volatile__(
30616+ " .align 2,0x90\n"
30617+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30618+ " cmpl $67, %0\n"
30619+ " jbe 3f\n"
30620+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30621+ " .align 2,0x90\n"
30622+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30623+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30624+ "5: movl %%eax, 0(%3)\n"
30625+ "6: movl %%edx, 4(%3)\n"
30626+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30627+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30628+ "9: movl %%eax, 8(%3)\n"
30629+ "10: movl %%edx, 12(%3)\n"
30630+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30631+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30632+ "13: movl %%eax, 16(%3)\n"
30633+ "14: movl %%edx, 20(%3)\n"
30634+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30635+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30636+ "17: movl %%eax, 24(%3)\n"
30637+ "18: movl %%edx, 28(%3)\n"
30638+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30639+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30640+ "21: movl %%eax, 32(%3)\n"
30641+ "22: movl %%edx, 36(%3)\n"
30642+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30643+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30644+ "25: movl %%eax, 40(%3)\n"
30645+ "26: movl %%edx, 44(%3)\n"
30646+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30647+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30648+ "29: movl %%eax, 48(%3)\n"
30649+ "30: movl %%edx, 52(%3)\n"
30650+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30651+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30652+ "33: movl %%eax, 56(%3)\n"
30653+ "34: movl %%edx, 60(%3)\n"
30654+ " addl $-64, %0\n"
30655+ " addl $64, %4\n"
30656+ " addl $64, %3\n"
30657+ " cmpl $63, %0\n"
30658+ " ja 1b\n"
30659+ "35: movl %0, %%eax\n"
30660+ " shrl $2, %0\n"
30661+ " andl $3, %%eax\n"
30662+ " cld\n"
30663+ "99: rep; "__copyuser_seg" movsl\n"
30664+ "36: movl %%eax, %0\n"
30665+ "37: rep; "__copyuser_seg" movsb\n"
30666+ "100:\n"
30667 ".section .fixup,\"ax\"\n"
30668 "101: lea 0(%%eax,%0,4),%0\n"
30669 " jmp 100b\n"
30670@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30671 int d0, d1;
30672 __asm__ __volatile__(
30673 " .align 2,0x90\n"
30674- "0: movl 32(%4), %%eax\n"
30675+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30676 " cmpl $67, %0\n"
30677 " jbe 2f\n"
30678- "1: movl 64(%4), %%eax\n"
30679+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30680 " .align 2,0x90\n"
30681- "2: movl 0(%4), %%eax\n"
30682- "21: movl 4(%4), %%edx\n"
30683+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30684+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30685 " movl %%eax, 0(%3)\n"
30686 " movl %%edx, 4(%3)\n"
30687- "3: movl 8(%4), %%eax\n"
30688- "31: movl 12(%4),%%edx\n"
30689+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30690+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30691 " movl %%eax, 8(%3)\n"
30692 " movl %%edx, 12(%3)\n"
30693- "4: movl 16(%4), %%eax\n"
30694- "41: movl 20(%4), %%edx\n"
30695+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30696+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30697 " movl %%eax, 16(%3)\n"
30698 " movl %%edx, 20(%3)\n"
30699- "10: movl 24(%4), %%eax\n"
30700- "51: movl 28(%4), %%edx\n"
30701+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30702+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30703 " movl %%eax, 24(%3)\n"
30704 " movl %%edx, 28(%3)\n"
30705- "11: movl 32(%4), %%eax\n"
30706- "61: movl 36(%4), %%edx\n"
30707+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30708+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30709 " movl %%eax, 32(%3)\n"
30710 " movl %%edx, 36(%3)\n"
30711- "12: movl 40(%4), %%eax\n"
30712- "71: movl 44(%4), %%edx\n"
30713+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30714+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30715 " movl %%eax, 40(%3)\n"
30716 " movl %%edx, 44(%3)\n"
30717- "13: movl 48(%4), %%eax\n"
30718- "81: movl 52(%4), %%edx\n"
30719+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30720+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30721 " movl %%eax, 48(%3)\n"
30722 " movl %%edx, 52(%3)\n"
30723- "14: movl 56(%4), %%eax\n"
30724- "91: movl 60(%4), %%edx\n"
30725+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30726+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30727 " movl %%eax, 56(%3)\n"
30728 " movl %%edx, 60(%3)\n"
30729 " addl $-64, %0\n"
30730@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30731 " shrl $2, %0\n"
30732 " andl $3, %%eax\n"
30733 " cld\n"
30734- "6: rep; movsl\n"
30735+ "6: rep; "__copyuser_seg" movsl\n"
30736 " movl %%eax,%0\n"
30737- "7: rep; movsb\n"
30738+ "7: rep; "__copyuser_seg" movsb\n"
30739 "8:\n"
30740 ".section .fixup,\"ax\"\n"
30741 "9: lea 0(%%eax,%0,4),%0\n"
30742@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30743
30744 __asm__ __volatile__(
30745 " .align 2,0x90\n"
30746- "0: movl 32(%4), %%eax\n"
30747+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30748 " cmpl $67, %0\n"
30749 " jbe 2f\n"
30750- "1: movl 64(%4), %%eax\n"
30751+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30752 " .align 2,0x90\n"
30753- "2: movl 0(%4), %%eax\n"
30754- "21: movl 4(%4), %%edx\n"
30755+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30756+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30757 " movnti %%eax, 0(%3)\n"
30758 " movnti %%edx, 4(%3)\n"
30759- "3: movl 8(%4), %%eax\n"
30760- "31: movl 12(%4),%%edx\n"
30761+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30762+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30763 " movnti %%eax, 8(%3)\n"
30764 " movnti %%edx, 12(%3)\n"
30765- "4: movl 16(%4), %%eax\n"
30766- "41: movl 20(%4), %%edx\n"
30767+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30768+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30769 " movnti %%eax, 16(%3)\n"
30770 " movnti %%edx, 20(%3)\n"
30771- "10: movl 24(%4), %%eax\n"
30772- "51: movl 28(%4), %%edx\n"
30773+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30774+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30775 " movnti %%eax, 24(%3)\n"
30776 " movnti %%edx, 28(%3)\n"
30777- "11: movl 32(%4), %%eax\n"
30778- "61: movl 36(%4), %%edx\n"
30779+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30780+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30781 " movnti %%eax, 32(%3)\n"
30782 " movnti %%edx, 36(%3)\n"
30783- "12: movl 40(%4), %%eax\n"
30784- "71: movl 44(%4), %%edx\n"
30785+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30786+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30787 " movnti %%eax, 40(%3)\n"
30788 " movnti %%edx, 44(%3)\n"
30789- "13: movl 48(%4), %%eax\n"
30790- "81: movl 52(%4), %%edx\n"
30791+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30792+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30793 " movnti %%eax, 48(%3)\n"
30794 " movnti %%edx, 52(%3)\n"
30795- "14: movl 56(%4), %%eax\n"
30796- "91: movl 60(%4), %%edx\n"
30797+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30798+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30799 " movnti %%eax, 56(%3)\n"
30800 " movnti %%edx, 60(%3)\n"
30801 " addl $-64, %0\n"
30802@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30803 " shrl $2, %0\n"
30804 " andl $3, %%eax\n"
30805 " cld\n"
30806- "6: rep; movsl\n"
30807+ "6: rep; "__copyuser_seg" movsl\n"
30808 " movl %%eax,%0\n"
30809- "7: rep; movsb\n"
30810+ "7: rep; "__copyuser_seg" movsb\n"
30811 "8:\n"
30812 ".section .fixup,\"ax\"\n"
30813 "9: lea 0(%%eax,%0,4),%0\n"
30814@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30815
30816 __asm__ __volatile__(
30817 " .align 2,0x90\n"
30818- "0: movl 32(%4), %%eax\n"
30819+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30820 " cmpl $67, %0\n"
30821 " jbe 2f\n"
30822- "1: movl 64(%4), %%eax\n"
30823+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30824 " .align 2,0x90\n"
30825- "2: movl 0(%4), %%eax\n"
30826- "21: movl 4(%4), %%edx\n"
30827+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30828+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30829 " movnti %%eax, 0(%3)\n"
30830 " movnti %%edx, 4(%3)\n"
30831- "3: movl 8(%4), %%eax\n"
30832- "31: movl 12(%4),%%edx\n"
30833+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30834+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30835 " movnti %%eax, 8(%3)\n"
30836 " movnti %%edx, 12(%3)\n"
30837- "4: movl 16(%4), %%eax\n"
30838- "41: movl 20(%4), %%edx\n"
30839+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30840+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30841 " movnti %%eax, 16(%3)\n"
30842 " movnti %%edx, 20(%3)\n"
30843- "10: movl 24(%4), %%eax\n"
30844- "51: movl 28(%4), %%edx\n"
30845+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30846+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30847 " movnti %%eax, 24(%3)\n"
30848 " movnti %%edx, 28(%3)\n"
30849- "11: movl 32(%4), %%eax\n"
30850- "61: movl 36(%4), %%edx\n"
30851+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30852+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30853 " movnti %%eax, 32(%3)\n"
30854 " movnti %%edx, 36(%3)\n"
30855- "12: movl 40(%4), %%eax\n"
30856- "71: movl 44(%4), %%edx\n"
30857+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30858+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30859 " movnti %%eax, 40(%3)\n"
30860 " movnti %%edx, 44(%3)\n"
30861- "13: movl 48(%4), %%eax\n"
30862- "81: movl 52(%4), %%edx\n"
30863+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30864+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30865 " movnti %%eax, 48(%3)\n"
30866 " movnti %%edx, 52(%3)\n"
30867- "14: movl 56(%4), %%eax\n"
30868- "91: movl 60(%4), %%edx\n"
30869+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30870+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30871 " movnti %%eax, 56(%3)\n"
30872 " movnti %%edx, 60(%3)\n"
30873 " addl $-64, %0\n"
30874@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30875 " shrl $2, %0\n"
30876 " andl $3, %%eax\n"
30877 " cld\n"
30878- "6: rep; movsl\n"
30879+ "6: rep; "__copyuser_seg" movsl\n"
30880 " movl %%eax,%0\n"
30881- "7: rep; movsb\n"
30882+ "7: rep; "__copyuser_seg" movsb\n"
30883 "8:\n"
30884 ".section .fixup,\"ax\"\n"
30885 "9: lea 0(%%eax,%0,4),%0\n"
30886@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30887 */
30888 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30889 unsigned long size);
30890-unsigned long __copy_user_intel(void __user *to, const void *from,
30891+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30892+ unsigned long size);
30893+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30894 unsigned long size);
30895 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30896 const void __user *from, unsigned long size);
30897 #endif /* CONFIG_X86_INTEL_USERCOPY */
30898
30899 /* Generic arbitrary sized copy. */
30900-#define __copy_user(to, from, size) \
30901+#define __copy_user(to, from, size, prefix, set, restore) \
30902 do { \
30903 int __d0, __d1, __d2; \
30904 __asm__ __volatile__( \
30905+ set \
30906 " cmp $7,%0\n" \
30907 " jbe 1f\n" \
30908 " movl %1,%0\n" \
30909 " negl %0\n" \
30910 " andl $7,%0\n" \
30911 " subl %0,%3\n" \
30912- "4: rep; movsb\n" \
30913+ "4: rep; "prefix"movsb\n" \
30914 " movl %3,%0\n" \
30915 " shrl $2,%0\n" \
30916 " andl $3,%3\n" \
30917 " .align 2,0x90\n" \
30918- "0: rep; movsl\n" \
30919+ "0: rep; "prefix"movsl\n" \
30920 " movl %3,%0\n" \
30921- "1: rep; movsb\n" \
30922+ "1: rep; "prefix"movsb\n" \
30923 "2:\n" \
30924+ restore \
30925 ".section .fixup,\"ax\"\n" \
30926 "5: addl %3,%0\n" \
30927 " jmp 2b\n" \
30928@@ -538,14 +650,14 @@ do { \
30929 " negl %0\n" \
30930 " andl $7,%0\n" \
30931 " subl %0,%3\n" \
30932- "4: rep; movsb\n" \
30933+ "4: rep; "__copyuser_seg"movsb\n" \
30934 " movl %3,%0\n" \
30935 " shrl $2,%0\n" \
30936 " andl $3,%3\n" \
30937 " .align 2,0x90\n" \
30938- "0: rep; movsl\n" \
30939+ "0: rep; "__copyuser_seg"movsl\n" \
30940 " movl %3,%0\n" \
30941- "1: rep; movsb\n" \
30942+ "1: rep; "__copyuser_seg"movsb\n" \
30943 "2:\n" \
30944 ".section .fixup,\"ax\"\n" \
30945 "5: addl %3,%0\n" \
30946@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *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_SET_ES, __COPYUSER_RESTORE_ES);
30952 else
30953- n = __copy_user_intel(to, from, n);
30954+ n = __generic_copy_to_user_intel(to, from, n);
30955 clac();
30956 return n;
30957 }
30958@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30959 {
30960 stac();
30961 if (movsl_is_ok(to, from, n))
30962- __copy_user(to, from, n);
30963+ __copy_user(to, from, n, __copyuser_seg, "", "");
30964 else
30965- n = __copy_user_intel((void __user *)to,
30966- (const void *)from, n);
30967+ n = __generic_copy_from_user_intel(to, from, n);
30968 clac();
30969 return n;
30970 }
30971@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30972 if (n > 64 && cpu_has_xmm2)
30973 n = __copy_user_intel_nocache(to, from, n);
30974 else
30975- __copy_user(to, from, n);
30976+ __copy_user(to, from, n, __copyuser_seg, "", "");
30977 #else
30978- __copy_user(to, from, n);
30979+ __copy_user(to, from, n, __copyuser_seg, "", "");
30980 #endif
30981 clac();
30982 return n;
30983 }
30984 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30985
30986-/**
30987- * copy_to_user: - Copy a block of data into user space.
30988- * @to: Destination address, in user space.
30989- * @from: Source address, in kernel space.
30990- * @n: Number of bytes to copy.
30991- *
30992- * Context: User context only. This function may sleep.
30993- *
30994- * Copy data from kernel space to user space.
30995- *
30996- * Returns number of bytes that could not be copied.
30997- * On success, this will be zero.
30998- */
30999-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31000+#ifdef CONFIG_PAX_MEMORY_UDEREF
31001+void __set_fs(mm_segment_t x)
31002 {
31003- if (access_ok(VERIFY_WRITE, to, n))
31004- n = __copy_to_user(to, from, n);
31005- return n;
31006+ switch (x.seg) {
31007+ case 0:
31008+ loadsegment(gs, 0);
31009+ break;
31010+ case TASK_SIZE_MAX:
31011+ loadsegment(gs, __USER_DS);
31012+ break;
31013+ case -1UL:
31014+ loadsegment(gs, __KERNEL_DS);
31015+ break;
31016+ default:
31017+ BUG();
31018+ }
31019 }
31020-EXPORT_SYMBOL(_copy_to_user);
31021+EXPORT_SYMBOL(__set_fs);
31022
31023-/**
31024- * copy_from_user: - Copy a block of data from user space.
31025- * @to: Destination address, in kernel space.
31026- * @from: Source address, in user space.
31027- * @n: Number of bytes to copy.
31028- *
31029- * Context: User context only. This function may sleep.
31030- *
31031- * Copy data from user space to kernel space.
31032- *
31033- * Returns number of bytes that could not be copied.
31034- * On success, this will be zero.
31035- *
31036- * If some data could not be copied, this function will pad the copied
31037- * data to the requested size using zero bytes.
31038- */
31039-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31040+void set_fs(mm_segment_t x)
31041 {
31042- if (access_ok(VERIFY_READ, from, n))
31043- n = __copy_from_user(to, from, n);
31044- else
31045- memset(to, 0, n);
31046- return n;
31047+ current_thread_info()->addr_limit = x;
31048+ __set_fs(x);
31049 }
31050-EXPORT_SYMBOL(_copy_from_user);
31051+EXPORT_SYMBOL(set_fs);
31052+#endif
31053diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31054index c905e89..01ab928 100644
31055--- a/arch/x86/lib/usercopy_64.c
31056+++ b/arch/x86/lib/usercopy_64.c
31057@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31058 might_fault();
31059 /* no memory constraint because it doesn't change any memory gcc knows
31060 about */
31061+ pax_open_userland();
31062 stac();
31063 asm volatile(
31064 " testq %[size8],%[size8]\n"
31065@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31066 _ASM_EXTABLE(0b,3b)
31067 _ASM_EXTABLE(1b,2b)
31068 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31069- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31070+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31071 [zero] "r" (0UL), [eight] "r" (8UL));
31072 clac();
31073+ pax_close_userland();
31074 return size;
31075 }
31076 EXPORT_SYMBOL(__clear_user);
31077@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31078 }
31079 EXPORT_SYMBOL(clear_user);
31080
31081-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31082+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31083 {
31084- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31085- return copy_user_generic((__force void *)to, (__force void *)from, len);
31086- }
31087- return len;
31088+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31089+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31090+ return len;
31091 }
31092 EXPORT_SYMBOL(copy_in_user);
31093
31094@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31095 * it is not necessary to optimize tail handling.
31096 */
31097 __visible unsigned long
31098-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31099+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31100 {
31101 char c;
31102 unsigned zero_len;
31103
31104+ clac();
31105+ pax_close_userland();
31106 for (; len; --len, to++) {
31107 if (__get_user_nocheck(c, from++, sizeof(char)))
31108 break;
31109@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31110 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31111 if (__put_user_nocheck(c, to++, sizeof(char)))
31112 break;
31113- clac();
31114 return len;
31115 }
31116diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31117index 6a19ad9..1c48f9a 100644
31118--- a/arch/x86/mm/Makefile
31119+++ b/arch/x86/mm/Makefile
31120@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31121 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31122
31123 obj-$(CONFIG_MEMTEST) += memtest.o
31124+
31125+quote:="
31126+obj-$(CONFIG_X86_64) += uderef_64.o
31127+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31128diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31129index 903ec1e..c4166b2 100644
31130--- a/arch/x86/mm/extable.c
31131+++ b/arch/x86/mm/extable.c
31132@@ -6,12 +6,24 @@
31133 static inline unsigned long
31134 ex_insn_addr(const struct exception_table_entry *x)
31135 {
31136- return (unsigned long)&x->insn + x->insn;
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->insn + x->insn + reloc;
31144 }
31145 static inline unsigned long
31146 ex_fixup_addr(const struct exception_table_entry *x)
31147 {
31148- return (unsigned long)&x->fixup + x->fixup;
31149+ unsigned long reloc = 0;
31150+
31151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31152+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31153+#endif
31154+
31155+ return (unsigned long)&x->fixup + x->fixup + reloc;
31156 }
31157
31158 int fixup_exception(struct pt_regs *regs)
31159@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31160 unsigned long new_ip;
31161
31162 #ifdef CONFIG_PNPBIOS
31163- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31164+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31165 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31166 extern u32 pnp_bios_is_utter_crap;
31167 pnp_bios_is_utter_crap = 1;
31168@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31169 i += 4;
31170 p->fixup -= i;
31171 i += 4;
31172+
31173+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31174+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31175+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31176+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31177+#endif
31178+
31179 }
31180 }
31181
31182diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31183index a10c8c7..35a5abb 100644
31184--- a/arch/x86/mm/fault.c
31185+++ b/arch/x86/mm/fault.c
31186@@ -14,11 +14,18 @@
31187 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31188 #include <linux/prefetch.h> /* prefetchw */
31189 #include <linux/context_tracking.h> /* exception_enter(), ... */
31190+#include <linux/unistd.h>
31191+#include <linux/compiler.h>
31192
31193 #include <asm/traps.h> /* dotraplinkage, ... */
31194 #include <asm/pgalloc.h> /* pgd_*(), ... */
31195 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31196 #include <asm/fixmap.h> /* VSYSCALL_START */
31197+#include <asm/tlbflush.h>
31198+
31199+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31200+#include <asm/stacktrace.h>
31201+#endif
31202
31203 #define CREATE_TRACE_POINTS
31204 #include <asm/trace/exceptions.h>
31205@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31206 int ret = 0;
31207
31208 /* kprobe_running() needs smp_processor_id() */
31209- if (kprobes_built_in() && !user_mode_vm(regs)) {
31210+ if (kprobes_built_in() && !user_mode(regs)) {
31211 preempt_disable();
31212 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31213 ret = 1;
31214@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31215 return !instr_lo || (instr_lo>>1) == 1;
31216 case 0x00:
31217 /* Prefetch instruction is 0x0F0D or 0x0F18 */
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+ return 0;
31222+ } else if (probe_kernel_address(instr, opcode))
31223 return 0;
31224
31225 *prefetch = (instr_lo == 0xF) &&
31226@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31227 while (instr < max_instr) {
31228 unsigned char opcode;
31229
31230- if (probe_kernel_address(instr, opcode))
31231+ if (user_mode(regs)) {
31232+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31233+ break;
31234+ } else if (probe_kernel_address(instr, opcode))
31235 break;
31236
31237 instr++;
31238@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31239 force_sig_info(si_signo, &info, tsk);
31240 }
31241
31242+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31243+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31244+#endif
31245+
31246+#ifdef CONFIG_PAX_EMUTRAMP
31247+static int pax_handle_fetch_fault(struct pt_regs *regs);
31248+#endif
31249+
31250+#ifdef CONFIG_PAX_PAGEEXEC
31251+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31252+{
31253+ pgd_t *pgd;
31254+ pud_t *pud;
31255+ pmd_t *pmd;
31256+
31257+ pgd = pgd_offset(mm, address);
31258+ if (!pgd_present(*pgd))
31259+ return NULL;
31260+ pud = pud_offset(pgd, address);
31261+ if (!pud_present(*pud))
31262+ return NULL;
31263+ pmd = pmd_offset(pud, address);
31264+ if (!pmd_present(*pmd))
31265+ return NULL;
31266+ return pmd;
31267+}
31268+#endif
31269+
31270 DEFINE_SPINLOCK(pgd_lock);
31271 LIST_HEAD(pgd_list);
31272
31273@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31274 for (address = VMALLOC_START & PMD_MASK;
31275 address >= TASK_SIZE && address < FIXADDR_TOP;
31276 address += PMD_SIZE) {
31277+
31278+#ifdef CONFIG_PAX_PER_CPU_PGD
31279+ unsigned long cpu;
31280+#else
31281 struct page *page;
31282+#endif
31283
31284 spin_lock(&pgd_lock);
31285+
31286+#ifdef CONFIG_PAX_PER_CPU_PGD
31287+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31288+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31289+ pmd_t *ret;
31290+
31291+ ret = vmalloc_sync_one(pgd, address);
31292+ if (!ret)
31293+ break;
31294+ pgd = get_cpu_pgd(cpu, kernel);
31295+#else
31296 list_for_each_entry(page, &pgd_list, lru) {
31297+ pgd_t *pgd;
31298 spinlock_t *pgt_lock;
31299 pmd_t *ret;
31300
31301@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31302 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31303
31304 spin_lock(pgt_lock);
31305- ret = vmalloc_sync_one(page_address(page), address);
31306+ pgd = page_address(page);
31307+#endif
31308+
31309+ ret = vmalloc_sync_one(pgd, address);
31310+
31311+#ifndef CONFIG_PAX_PER_CPU_PGD
31312 spin_unlock(pgt_lock);
31313+#endif
31314
31315 if (!ret)
31316 break;
31317@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31318 * an interrupt in the middle of a task switch..
31319 */
31320 pgd_paddr = read_cr3();
31321+
31322+#ifdef CONFIG_PAX_PER_CPU_PGD
31323+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31324+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31325+#endif
31326+
31327 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31328 if (!pmd_k)
31329 return -1;
31330@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31331 * happen within a race in page table update. In the later
31332 * case just flush:
31333 */
31334- pgd = pgd_offset(current->active_mm, address);
31335+
31336 pgd_ref = pgd_offset_k(address);
31337 if (pgd_none(*pgd_ref))
31338 return -1;
31339
31340+#ifdef CONFIG_PAX_PER_CPU_PGD
31341+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31342+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31343+ if (pgd_none(*pgd)) {
31344+ set_pgd(pgd, *pgd_ref);
31345+ arch_flush_lazy_mmu_mode();
31346+ } else {
31347+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31348+ }
31349+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31350+#else
31351+ pgd = pgd_offset(current->active_mm, address);
31352+#endif
31353+
31354 if (pgd_none(*pgd)) {
31355 set_pgd(pgd, *pgd_ref);
31356 arch_flush_lazy_mmu_mode();
31357@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31358 static int is_errata100(struct pt_regs *regs, unsigned long address)
31359 {
31360 #ifdef CONFIG_X86_64
31361- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31362+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31363 return 1;
31364 #endif
31365 return 0;
31366@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31367 }
31368
31369 static const char nx_warning[] = KERN_CRIT
31370-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31371+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31372
31373 static void
31374 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31375@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31376 if (!oops_may_print())
31377 return;
31378
31379- if (error_code & PF_INSTR) {
31380+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31381 unsigned int level;
31382
31383 pte_t *pte = lookup_address(address, &level);
31384
31385 if (pte && pte_present(*pte) && !pte_exec(*pte))
31386- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31387+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31388 }
31389
31390+#ifdef CONFIG_PAX_KERNEXEC
31391+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31392+ if (current->signal->curr_ip)
31393+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31394+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31395+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31396+ else
31397+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31398+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31399+ }
31400+#endif
31401+
31402 printk(KERN_ALERT "BUG: unable to handle kernel ");
31403 if (address < PAGE_SIZE)
31404 printk(KERN_CONT "NULL pointer dereference");
31405@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31406 return;
31407 }
31408 #endif
31409+
31410+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31411+ if (pax_is_fetch_fault(regs, error_code, address)) {
31412+
31413+#ifdef CONFIG_PAX_EMUTRAMP
31414+ switch (pax_handle_fetch_fault(regs)) {
31415+ case 2:
31416+ return;
31417+ }
31418+#endif
31419+
31420+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31421+ do_group_exit(SIGKILL);
31422+ }
31423+#endif
31424+
31425 /* Kernel addresses are always protection faults: */
31426 if (address >= TASK_SIZE)
31427 error_code |= PF_PROT;
31428@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31429 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31430 printk(KERN_ERR
31431 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31432- tsk->comm, tsk->pid, address);
31433+ tsk->comm, task_pid_nr(tsk), address);
31434 code = BUS_MCEERR_AR;
31435 }
31436 #endif
31437@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31438 return 1;
31439 }
31440
31441+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31442+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31443+{
31444+ pte_t *pte;
31445+ pmd_t *pmd;
31446+ spinlock_t *ptl;
31447+ unsigned char pte_mask;
31448+
31449+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31450+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31451+ return 0;
31452+
31453+ /* PaX: it's our fault, let's handle it if we can */
31454+
31455+ /* PaX: take a look at read faults before acquiring any locks */
31456+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31457+ /* instruction fetch attempt from a protected page in user mode */
31458+ up_read(&mm->mmap_sem);
31459+
31460+#ifdef CONFIG_PAX_EMUTRAMP
31461+ switch (pax_handle_fetch_fault(regs)) {
31462+ case 2:
31463+ return 1;
31464+ }
31465+#endif
31466+
31467+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31468+ do_group_exit(SIGKILL);
31469+ }
31470+
31471+ pmd = pax_get_pmd(mm, address);
31472+ if (unlikely(!pmd))
31473+ return 0;
31474+
31475+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31476+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31477+ pte_unmap_unlock(pte, ptl);
31478+ return 0;
31479+ }
31480+
31481+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31482+ /* write attempt to a protected page in user mode */
31483+ pte_unmap_unlock(pte, ptl);
31484+ return 0;
31485+ }
31486+
31487+#ifdef CONFIG_SMP
31488+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31489+#else
31490+ if (likely(address > get_limit(regs->cs)))
31491+#endif
31492+ {
31493+ set_pte(pte, pte_mkread(*pte));
31494+ __flush_tlb_one(address);
31495+ pte_unmap_unlock(pte, ptl);
31496+ up_read(&mm->mmap_sem);
31497+ return 1;
31498+ }
31499+
31500+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31501+
31502+ /*
31503+ * PaX: fill DTLB with user rights and retry
31504+ */
31505+ __asm__ __volatile__ (
31506+ "orb %2,(%1)\n"
31507+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31508+/*
31509+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31510+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31511+ * page fault when examined during a TLB load attempt. this is true not only
31512+ * for PTEs holding a non-present entry but also present entries that will
31513+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31514+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31515+ * for our target pages since their PTEs are simply not in the TLBs at all.
31516+
31517+ * the best thing in omitting it is that we gain around 15-20% speed in the
31518+ * fast path of the page fault handler and can get rid of tracing since we
31519+ * can no longer flush unintended entries.
31520+ */
31521+ "invlpg (%0)\n"
31522+#endif
31523+ __copyuser_seg"testb $0,(%0)\n"
31524+ "xorb %3,(%1)\n"
31525+ :
31526+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31527+ : "memory", "cc");
31528+ pte_unmap_unlock(pte, ptl);
31529+ up_read(&mm->mmap_sem);
31530+ return 1;
31531+}
31532+#endif
31533+
31534 /*
31535 * Handle a spurious fault caused by a stale TLB entry.
31536 *
31537@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31538 static inline int
31539 access_error(unsigned long error_code, struct vm_area_struct *vma)
31540 {
31541+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31542+ return 1;
31543+
31544 if (error_code & PF_WRITE) {
31545 /* write, present and write, not present: */
31546 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31547@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31548 if (error_code & PF_USER)
31549 return false;
31550
31551- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31552+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31553 return false;
31554
31555 return true;
31556@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31557 tsk = current;
31558 mm = tsk->mm;
31559
31560+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31561+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31562+ if (!search_exception_tables(regs->ip)) {
31563+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31564+ bad_area_nosemaphore(regs, error_code, address);
31565+ return;
31566+ }
31567+ if (address < pax_user_shadow_base) {
31568+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31569+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31570+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31571+ } else
31572+ address -= pax_user_shadow_base;
31573+ }
31574+#endif
31575+
31576 /*
31577 * Detect and handle instructions that would cause a page fault for
31578 * both a tracked kernel page and a userspace page.
31579@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31580 * User-mode registers count as a user access even for any
31581 * potential system fault or CPU buglet:
31582 */
31583- if (user_mode_vm(regs)) {
31584+ if (user_mode(regs)) {
31585 local_irq_enable();
31586 error_code |= PF_USER;
31587 flags |= FAULT_FLAG_USER;
31588@@ -1162,6 +1386,11 @@ retry:
31589 might_sleep();
31590 }
31591
31592+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31593+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31594+ return;
31595+#endif
31596+
31597 vma = find_vma(mm, address);
31598 if (unlikely(!vma)) {
31599 bad_area(regs, error_code, address);
31600@@ -1173,18 +1402,24 @@ retry:
31601 bad_area(regs, error_code, address);
31602 return;
31603 }
31604- if (error_code & PF_USER) {
31605- /*
31606- * Accessing the stack below %sp is always a bug.
31607- * The large cushion allows instructions like enter
31608- * and pusha to work. ("enter $65535, $31" pushes
31609- * 32 pointers and then decrements %sp by 65535.)
31610- */
31611- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31612- bad_area(regs, error_code, address);
31613- return;
31614- }
31615+ /*
31616+ * Accessing the stack below %sp is always a bug.
31617+ * The large cushion allows instructions like enter
31618+ * and pusha to work. ("enter $65535, $31" pushes
31619+ * 32 pointers and then decrements %sp by 65535.)
31620+ */
31621+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31622+ bad_area(regs, error_code, address);
31623+ return;
31624 }
31625+
31626+#ifdef CONFIG_PAX_SEGMEXEC
31627+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31628+ bad_area(regs, error_code, address);
31629+ return;
31630+ }
31631+#endif
31632+
31633 if (unlikely(expand_stack(vma, address))) {
31634 bad_area(regs, error_code, address);
31635 return;
31636@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31637 exception_exit(prev_state);
31638 }
31639 #endif /* CONFIG_TRACING */
31640+
31641+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31642+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31643+{
31644+ struct mm_struct *mm = current->mm;
31645+ unsigned long ip = regs->ip;
31646+
31647+ if (v8086_mode(regs))
31648+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31649+
31650+#ifdef CONFIG_PAX_PAGEEXEC
31651+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31652+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31653+ return true;
31654+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31655+ return true;
31656+ return false;
31657+ }
31658+#endif
31659+
31660+#ifdef CONFIG_PAX_SEGMEXEC
31661+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31662+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31663+ return true;
31664+ return false;
31665+ }
31666+#endif
31667+
31668+ return false;
31669+}
31670+#endif
31671+
31672+#ifdef CONFIG_PAX_EMUTRAMP
31673+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31674+{
31675+ int err;
31676+
31677+ do { /* PaX: libffi trampoline emulation */
31678+ unsigned char mov, jmp;
31679+ unsigned int addr1, addr2;
31680+
31681+#ifdef CONFIG_X86_64
31682+ if ((regs->ip + 9) >> 32)
31683+ break;
31684+#endif
31685+
31686+ err = get_user(mov, (unsigned char __user *)regs->ip);
31687+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31688+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31689+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31690+
31691+ if (err)
31692+ break;
31693+
31694+ if (mov == 0xB8 && jmp == 0xE9) {
31695+ regs->ax = addr1;
31696+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31697+ return 2;
31698+ }
31699+ } while (0);
31700+
31701+ do { /* PaX: gcc trampoline emulation #1 */
31702+ unsigned char mov1, mov2;
31703+ unsigned short jmp;
31704+ unsigned int addr1, addr2;
31705+
31706+#ifdef CONFIG_X86_64
31707+ if ((regs->ip + 11) >> 32)
31708+ break;
31709+#endif
31710+
31711+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31712+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31713+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31714+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31715+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31716+
31717+ if (err)
31718+ break;
31719+
31720+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31721+ regs->cx = addr1;
31722+ regs->ax = addr2;
31723+ regs->ip = addr2;
31724+ return 2;
31725+ }
31726+ } while (0);
31727+
31728+ do { /* PaX: gcc trampoline emulation #2 */
31729+ unsigned char mov, jmp;
31730+ unsigned int addr1, addr2;
31731+
31732+#ifdef CONFIG_X86_64
31733+ if ((regs->ip + 9) >> 32)
31734+ break;
31735+#endif
31736+
31737+ err = get_user(mov, (unsigned char __user *)regs->ip);
31738+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31739+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31740+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31741+
31742+ if (err)
31743+ break;
31744+
31745+ if (mov == 0xB9 && jmp == 0xE9) {
31746+ regs->cx = addr1;
31747+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31748+ return 2;
31749+ }
31750+ } while (0);
31751+
31752+ return 1; /* PaX in action */
31753+}
31754+
31755+#ifdef CONFIG_X86_64
31756+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31757+{
31758+ int err;
31759+
31760+ do { /* PaX: libffi trampoline emulation */
31761+ unsigned short mov1, mov2, jmp1;
31762+ unsigned char stcclc, jmp2;
31763+ unsigned long addr1, addr2;
31764+
31765+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31766+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31767+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31768+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31769+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31770+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31771+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31772+
31773+ if (err)
31774+ break;
31775+
31776+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31777+ regs->r11 = addr1;
31778+ regs->r10 = addr2;
31779+ if (stcclc == 0xF8)
31780+ regs->flags &= ~X86_EFLAGS_CF;
31781+ else
31782+ regs->flags |= X86_EFLAGS_CF;
31783+ regs->ip = addr1;
31784+ return 2;
31785+ }
31786+ } while (0);
31787+
31788+ do { /* PaX: gcc trampoline emulation #1 */
31789+ unsigned short mov1, mov2, jmp1;
31790+ unsigned char jmp2;
31791+ unsigned int addr1;
31792+ unsigned long addr2;
31793+
31794+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31795+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31796+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31797+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31798+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31799+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31800+
31801+ if (err)
31802+ break;
31803+
31804+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31805+ regs->r11 = addr1;
31806+ regs->r10 = addr2;
31807+ regs->ip = addr1;
31808+ return 2;
31809+ }
31810+ } while (0);
31811+
31812+ do { /* PaX: gcc trampoline emulation #2 */
31813+ unsigned short mov1, mov2, jmp1;
31814+ unsigned char jmp2;
31815+ unsigned long addr1, addr2;
31816+
31817+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31818+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31819+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31820+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31821+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31822+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31823+
31824+ if (err)
31825+ break;
31826+
31827+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31828+ regs->r11 = addr1;
31829+ regs->r10 = addr2;
31830+ regs->ip = addr1;
31831+ return 2;
31832+ }
31833+ } while (0);
31834+
31835+ return 1; /* PaX in action */
31836+}
31837+#endif
31838+
31839+/*
31840+ * PaX: decide what to do with offenders (regs->ip = fault address)
31841+ *
31842+ * returns 1 when task should be killed
31843+ * 2 when gcc trampoline was detected
31844+ */
31845+static int pax_handle_fetch_fault(struct pt_regs *regs)
31846+{
31847+ if (v8086_mode(regs))
31848+ return 1;
31849+
31850+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31851+ return 1;
31852+
31853+#ifdef CONFIG_X86_32
31854+ return pax_handle_fetch_fault_32(regs);
31855+#else
31856+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31857+ return pax_handle_fetch_fault_32(regs);
31858+ else
31859+ return pax_handle_fetch_fault_64(regs);
31860+#endif
31861+}
31862+#endif
31863+
31864+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31865+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31866+{
31867+ long i;
31868+
31869+ printk(KERN_ERR "PAX: bytes at PC: ");
31870+ for (i = 0; i < 20; i++) {
31871+ unsigned char c;
31872+ if (get_user(c, (unsigned char __force_user *)pc+i))
31873+ printk(KERN_CONT "?? ");
31874+ else
31875+ printk(KERN_CONT "%02x ", c);
31876+ }
31877+ printk("\n");
31878+
31879+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31880+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31881+ unsigned long c;
31882+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31883+#ifdef CONFIG_X86_32
31884+ printk(KERN_CONT "???????? ");
31885+#else
31886+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31887+ printk(KERN_CONT "???????? ???????? ");
31888+ else
31889+ printk(KERN_CONT "???????????????? ");
31890+#endif
31891+ } else {
31892+#ifdef CONFIG_X86_64
31893+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31894+ printk(KERN_CONT "%08x ", (unsigned int)c);
31895+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31896+ } else
31897+#endif
31898+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31899+ }
31900+ }
31901+ printk("\n");
31902+}
31903+#endif
31904+
31905+/**
31906+ * probe_kernel_write(): safely attempt to write to a location
31907+ * @dst: address to write to
31908+ * @src: pointer to the data that shall be written
31909+ * @size: size of the data chunk
31910+ *
31911+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31912+ * happens, handle that and return -EFAULT.
31913+ */
31914+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31915+{
31916+ long ret;
31917+ mm_segment_t old_fs = get_fs();
31918+
31919+ set_fs(KERNEL_DS);
31920+ pagefault_disable();
31921+ pax_open_kernel();
31922+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31923+ pax_close_kernel();
31924+ pagefault_enable();
31925+ set_fs(old_fs);
31926+
31927+ return ret ? -EFAULT : 0;
31928+}
31929diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31930index 207d9aef..69030980 100644
31931--- a/arch/x86/mm/gup.c
31932+++ b/arch/x86/mm/gup.c
31933@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31934 addr = start;
31935 len = (unsigned long) nr_pages << PAGE_SHIFT;
31936 end = start + len;
31937- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31938+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31939 (void __user *)start, len)))
31940 return 0;
31941
31942@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31943 goto slow_irqon;
31944 #endif
31945
31946+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31947+ (void __user *)start, len)))
31948+ return 0;
31949+
31950 /*
31951 * XXX: batch / limit 'nr', to avoid large irq off latency
31952 * needs some instrumenting to determine the common sizes used by
31953diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31954index 4500142..53a363c 100644
31955--- a/arch/x86/mm/highmem_32.c
31956+++ b/arch/x86/mm/highmem_32.c
31957@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31958 idx = type + KM_TYPE_NR*smp_processor_id();
31959 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31960 BUG_ON(!pte_none(*(kmap_pte-idx)));
31961+
31962+ pax_open_kernel();
31963 set_pte(kmap_pte-idx, mk_pte(page, prot));
31964+ pax_close_kernel();
31965+
31966 arch_flush_lazy_mmu_mode();
31967
31968 return (void *)vaddr;
31969diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31970index 8c9f647..57cb402 100644
31971--- a/arch/x86/mm/hugetlbpage.c
31972+++ b/arch/x86/mm/hugetlbpage.c
31973@@ -90,23 +90,24 @@ int pmd_huge_support(void)
31974 #ifdef CONFIG_HUGETLB_PAGE
31975 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31976 unsigned long addr, unsigned long len,
31977- unsigned long pgoff, unsigned long flags)
31978+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31979 {
31980 struct hstate *h = hstate_file(file);
31981 struct vm_unmapped_area_info info;
31982-
31983+
31984 info.flags = 0;
31985 info.length = len;
31986 info.low_limit = current->mm->mmap_legacy_base;
31987 info.high_limit = TASK_SIZE;
31988 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31989 info.align_offset = 0;
31990+ info.threadstack_offset = offset;
31991 return vm_unmapped_area(&info);
31992 }
31993
31994 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31995 unsigned long addr0, unsigned long len,
31996- unsigned long pgoff, unsigned long flags)
31997+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31998 {
31999 struct hstate *h = hstate_file(file);
32000 struct vm_unmapped_area_info info;
32001@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32002 info.high_limit = current->mm->mmap_base;
32003 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32004 info.align_offset = 0;
32005+ info.threadstack_offset = offset;
32006 addr = vm_unmapped_area(&info);
32007
32008 /*
32009@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32010 VM_BUG_ON(addr != -ENOMEM);
32011 info.flags = 0;
32012 info.low_limit = TASK_UNMAPPED_BASE;
32013+
32014+#ifdef CONFIG_PAX_RANDMMAP
32015+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32016+ info.low_limit += current->mm->delta_mmap;
32017+#endif
32018+
32019 info.high_limit = TASK_SIZE;
32020 addr = vm_unmapped_area(&info);
32021 }
32022@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32023 struct hstate *h = hstate_file(file);
32024 struct mm_struct *mm = current->mm;
32025 struct vm_area_struct *vma;
32026+ unsigned long pax_task_size = TASK_SIZE;
32027+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32028
32029 if (len & ~huge_page_mask(h))
32030 return -EINVAL;
32031- if (len > TASK_SIZE)
32032+
32033+#ifdef CONFIG_PAX_SEGMEXEC
32034+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32035+ pax_task_size = SEGMEXEC_TASK_SIZE;
32036+#endif
32037+
32038+ pax_task_size -= PAGE_SIZE;
32039+
32040+ if (len > pax_task_size)
32041 return -ENOMEM;
32042
32043 if (flags & MAP_FIXED) {
32044@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32045 return addr;
32046 }
32047
32048+#ifdef CONFIG_PAX_RANDMMAP
32049+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32050+#endif
32051+
32052 if (addr) {
32053 addr = ALIGN(addr, huge_page_size(h));
32054 vma = find_vma(mm, addr);
32055- if (TASK_SIZE - len >= addr &&
32056- (!vma || addr + len <= vma->vm_start))
32057+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32058 return addr;
32059 }
32060 if (mm->get_unmapped_area == arch_get_unmapped_area)
32061 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32062- pgoff, flags);
32063+ pgoff, flags, offset);
32064 else
32065 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32066- pgoff, flags);
32067+ pgoff, flags, offset);
32068 }
32069 #endif /* CONFIG_HUGETLB_PAGE */
32070
32071diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32072index f971306..e83e0f6 100644
32073--- a/arch/x86/mm/init.c
32074+++ b/arch/x86/mm/init.c
32075@@ -4,6 +4,7 @@
32076 #include <linux/swap.h>
32077 #include <linux/memblock.h>
32078 #include <linux/bootmem.h> /* for max_low_pfn */
32079+#include <linux/tboot.h>
32080
32081 #include <asm/cacheflush.h>
32082 #include <asm/e820.h>
32083@@ -17,6 +18,8 @@
32084 #include <asm/proto.h>
32085 #include <asm/dma.h> /* for MAX_DMA_PFN */
32086 #include <asm/microcode.h>
32087+#include <asm/desc.h>
32088+#include <asm/bios_ebda.h>
32089
32090 #include "mm_internal.h"
32091
32092@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32093 early_ioremap_page_table_range_init();
32094 #endif
32095
32096+#ifdef CONFIG_PAX_PER_CPU_PGD
32097+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32098+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32099+ KERNEL_PGD_PTRS);
32100+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32101+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32102+ KERNEL_PGD_PTRS);
32103+ load_cr3(get_cpu_pgd(0, kernel));
32104+#else
32105 load_cr3(swapper_pg_dir);
32106+#endif
32107+
32108 __flush_tlb_all();
32109
32110 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32111@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32112 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32113 * mmio resources as well as potential bios/acpi data regions.
32114 */
32115+
32116+#ifdef CONFIG_GRKERNSEC_KMEM
32117+static unsigned int ebda_start __read_only;
32118+static unsigned int ebda_end __read_only;
32119+#endif
32120+
32121 int devmem_is_allowed(unsigned long pagenr)
32122 {
32123- if (pagenr < 256)
32124+#ifdef CONFIG_GRKERNSEC_KMEM
32125+ /* allow BDA */
32126+ if (!pagenr)
32127 return 1;
32128+ /* allow EBDA */
32129+ if (pagenr >= ebda_start && pagenr < ebda_end)
32130+ return 1;
32131+ /* if tboot is in use, allow access to its hardcoded serial log range */
32132+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32133+ return 1;
32134+#else
32135+ if (!pagenr)
32136+ return 1;
32137+#ifdef CONFIG_VM86
32138+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32139+ return 1;
32140+#endif
32141+#endif
32142+
32143+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32144+ return 1;
32145+#ifdef CONFIG_GRKERNSEC_KMEM
32146+ /* throw out everything else below 1MB */
32147+ if (pagenr <= 256)
32148+ return 0;
32149+#endif
32150 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32151 return 0;
32152 if (!page_is_ram(pagenr))
32153@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32154 #endif
32155 }
32156
32157+#ifdef CONFIG_GRKERNSEC_KMEM
32158+static inline void gr_init_ebda(void)
32159+{
32160+ unsigned int ebda_addr;
32161+ unsigned int ebda_size = 0;
32162+
32163+ ebda_addr = get_bios_ebda();
32164+ if (ebda_addr) {
32165+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32166+ ebda_size <<= 10;
32167+ }
32168+ if (ebda_addr && ebda_size) {
32169+ ebda_start = ebda_addr >> PAGE_SHIFT;
32170+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32171+ } else {
32172+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32173+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32174+ }
32175+}
32176+#else
32177+static inline void gr_init_ebda(void) { }
32178+#endif
32179+
32180 void free_initmem(void)
32181 {
32182+#ifdef CONFIG_PAX_KERNEXEC
32183+#ifdef CONFIG_X86_32
32184+ /* PaX: limit KERNEL_CS to actual size */
32185+ unsigned long addr, limit;
32186+ struct desc_struct d;
32187+ int cpu;
32188+#else
32189+ pgd_t *pgd;
32190+ pud_t *pud;
32191+ pmd_t *pmd;
32192+ unsigned long addr, end;
32193+#endif
32194+#endif
32195+
32196+ gr_init_ebda();
32197+
32198+#ifdef CONFIG_PAX_KERNEXEC
32199+#ifdef CONFIG_X86_32
32200+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32201+ limit = (limit - 1UL) >> PAGE_SHIFT;
32202+
32203+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32204+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32205+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32206+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32207+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32208+ }
32209+
32210+ /* PaX: make KERNEL_CS read-only */
32211+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32212+ if (!paravirt_enabled())
32213+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32214+/*
32215+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32216+ pgd = pgd_offset_k(addr);
32217+ pud = pud_offset(pgd, addr);
32218+ pmd = pmd_offset(pud, addr);
32219+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32220+ }
32221+*/
32222+#ifdef CONFIG_X86_PAE
32223+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32224+/*
32225+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32226+ pgd = pgd_offset_k(addr);
32227+ pud = pud_offset(pgd, addr);
32228+ pmd = pmd_offset(pud, addr);
32229+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32230+ }
32231+*/
32232+#endif
32233+
32234+#ifdef CONFIG_MODULES
32235+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32236+#endif
32237+
32238+#else
32239+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32240+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32241+ pgd = pgd_offset_k(addr);
32242+ pud = pud_offset(pgd, addr);
32243+ pmd = pmd_offset(pud, addr);
32244+ if (!pmd_present(*pmd))
32245+ continue;
32246+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32247+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32248+ else
32249+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32250+ }
32251+
32252+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32253+ end = addr + KERNEL_IMAGE_SIZE;
32254+ for (; addr < end; addr += PMD_SIZE) {
32255+ pgd = pgd_offset_k(addr);
32256+ pud = pud_offset(pgd, addr);
32257+ pmd = pmd_offset(pud, addr);
32258+ if (!pmd_present(*pmd))
32259+ continue;
32260+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32261+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32262+ }
32263+#endif
32264+
32265+ flush_tlb_all();
32266+#endif
32267+
32268 free_init_pages("unused kernel",
32269 (unsigned long)(&__init_begin),
32270 (unsigned long)(&__init_end));
32271diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32272index e395048..cd38278 100644
32273--- a/arch/x86/mm/init_32.c
32274+++ b/arch/x86/mm/init_32.c
32275@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32276 bool __read_mostly __vmalloc_start_set = false;
32277
32278 /*
32279- * Creates a middle page table and puts a pointer to it in the
32280- * given global directory entry. This only returns the gd entry
32281- * in non-PAE compilation mode, since the middle layer is folded.
32282- */
32283-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32284-{
32285- pud_t *pud;
32286- pmd_t *pmd_table;
32287-
32288-#ifdef CONFIG_X86_PAE
32289- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32290- pmd_table = (pmd_t *)alloc_low_page();
32291- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32292- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32293- pud = pud_offset(pgd, 0);
32294- BUG_ON(pmd_table != pmd_offset(pud, 0));
32295-
32296- return pmd_table;
32297- }
32298-#endif
32299- pud = pud_offset(pgd, 0);
32300- pmd_table = pmd_offset(pud, 0);
32301-
32302- return pmd_table;
32303-}
32304-
32305-/*
32306 * Create a page table and place a pointer to it in a middle page
32307 * directory entry:
32308 */
32309@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32310 pte_t *page_table = (pte_t *)alloc_low_page();
32311
32312 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32313+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32314+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32315+#else
32316 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32317+#endif
32318 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32319 }
32320
32321 return pte_offset_kernel(pmd, 0);
32322 }
32323
32324+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32325+{
32326+ pud_t *pud;
32327+ pmd_t *pmd_table;
32328+
32329+ pud = pud_offset(pgd, 0);
32330+ pmd_table = pmd_offset(pud, 0);
32331+
32332+ return pmd_table;
32333+}
32334+
32335 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32336 {
32337 int pgd_idx = pgd_index(vaddr);
32338@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32339 int pgd_idx, pmd_idx;
32340 unsigned long vaddr;
32341 pgd_t *pgd;
32342+ pud_t *pud;
32343 pmd_t *pmd;
32344 pte_t *pte = NULL;
32345 unsigned long count = page_table_range_init_count(start, end);
32346@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32347 pgd = pgd_base + pgd_idx;
32348
32349 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32350- pmd = one_md_table_init(pgd);
32351- pmd = pmd + pmd_index(vaddr);
32352+ pud = pud_offset(pgd, vaddr);
32353+ pmd = pmd_offset(pud, vaddr);
32354+
32355+#ifdef CONFIG_X86_PAE
32356+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32357+#endif
32358+
32359 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32360 pmd++, pmd_idx++) {
32361 pte = page_table_kmap_check(one_page_table_init(pmd),
32362@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32363 }
32364 }
32365
32366-static inline int is_kernel_text(unsigned long addr)
32367+static inline int is_kernel_text(unsigned long start, unsigned long end)
32368 {
32369- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32370- return 1;
32371- return 0;
32372+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32373+ end <= ktla_ktva((unsigned long)_stext)) &&
32374+ (start >= ktla_ktva((unsigned long)_einittext) ||
32375+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32376+
32377+#ifdef CONFIG_ACPI_SLEEP
32378+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32379+#endif
32380+
32381+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32382+ return 0;
32383+ return 1;
32384 }
32385
32386 /*
32387@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32388 unsigned long last_map_addr = end;
32389 unsigned long start_pfn, end_pfn;
32390 pgd_t *pgd_base = swapper_pg_dir;
32391- int pgd_idx, pmd_idx, pte_ofs;
32392+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32393 unsigned long pfn;
32394 pgd_t *pgd;
32395+ pud_t *pud;
32396 pmd_t *pmd;
32397 pte_t *pte;
32398 unsigned pages_2m, pages_4k;
32399@@ -291,8 +295,13 @@ repeat:
32400 pfn = start_pfn;
32401 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32402 pgd = pgd_base + pgd_idx;
32403- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32404- pmd = one_md_table_init(pgd);
32405+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32406+ pud = pud_offset(pgd, 0);
32407+ pmd = pmd_offset(pud, 0);
32408+
32409+#ifdef CONFIG_X86_PAE
32410+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32411+#endif
32412
32413 if (pfn >= end_pfn)
32414 continue;
32415@@ -304,14 +313,13 @@ repeat:
32416 #endif
32417 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32418 pmd++, pmd_idx++) {
32419- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32420+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32421
32422 /*
32423 * Map with big pages if possible, otherwise
32424 * create normal page tables:
32425 */
32426 if (use_pse) {
32427- unsigned int addr2;
32428 pgprot_t prot = PAGE_KERNEL_LARGE;
32429 /*
32430 * first pass will use the same initial
32431@@ -322,11 +330,7 @@ repeat:
32432 _PAGE_PSE);
32433
32434 pfn &= PMD_MASK >> PAGE_SHIFT;
32435- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32436- PAGE_OFFSET + PAGE_SIZE-1;
32437-
32438- if (is_kernel_text(addr) ||
32439- is_kernel_text(addr2))
32440+ if (is_kernel_text(address, address + PMD_SIZE))
32441 prot = PAGE_KERNEL_LARGE_EXEC;
32442
32443 pages_2m++;
32444@@ -343,7 +347,7 @@ repeat:
32445 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32446 pte += pte_ofs;
32447 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32448- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32449+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32450 pgprot_t prot = PAGE_KERNEL;
32451 /*
32452 * first pass will use the same initial
32453@@ -351,7 +355,7 @@ repeat:
32454 */
32455 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32456
32457- if (is_kernel_text(addr))
32458+ if (is_kernel_text(address, address + PAGE_SIZE))
32459 prot = PAGE_KERNEL_EXEC;
32460
32461 pages_4k++;
32462@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32463
32464 pud = pud_offset(pgd, va);
32465 pmd = pmd_offset(pud, va);
32466- if (!pmd_present(*pmd))
32467+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32468 break;
32469
32470 /* should not be large page here */
32471@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32472
32473 static void __init pagetable_init(void)
32474 {
32475- pgd_t *pgd_base = swapper_pg_dir;
32476-
32477- permanent_kmaps_init(pgd_base);
32478+ permanent_kmaps_init(swapper_pg_dir);
32479 }
32480
32481-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32482+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32483 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32484
32485 /* user-defined highmem size */
32486@@ -787,10 +789,10 @@ void __init mem_init(void)
32487 ((unsigned long)&__init_end -
32488 (unsigned long)&__init_begin) >> 10,
32489
32490- (unsigned long)&_etext, (unsigned long)&_edata,
32491- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32492+ (unsigned long)&_sdata, (unsigned long)&_edata,
32493+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32494
32495- (unsigned long)&_text, (unsigned long)&_etext,
32496+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32497 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32498
32499 /*
32500@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32501 if (!kernel_set_to_readonly)
32502 return;
32503
32504+ start = ktla_ktva(start);
32505 pr_debug("Set kernel text: %lx - %lx for read write\n",
32506 start, start+size);
32507
32508@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32509 if (!kernel_set_to_readonly)
32510 return;
32511
32512+ start = ktla_ktva(start);
32513 pr_debug("Set kernel text: %lx - %lx for read only\n",
32514 start, start+size);
32515
32516@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32517 unsigned long start = PFN_ALIGN(_text);
32518 unsigned long size = PFN_ALIGN(_etext) - start;
32519
32520+ start = ktla_ktva(start);
32521 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32522 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32523 size >> 10);
32524diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32525index f35c66c..84b95ef 100644
32526--- a/arch/x86/mm/init_64.c
32527+++ b/arch/x86/mm/init_64.c
32528@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32529 * around without checking the pgd every time.
32530 */
32531
32532-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32533+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32534 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32535
32536 int force_personality32;
32537@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32538
32539 for (address = start; address <= end; address += PGDIR_SIZE) {
32540 const pgd_t *pgd_ref = pgd_offset_k(address);
32541+
32542+#ifdef CONFIG_PAX_PER_CPU_PGD
32543+ unsigned long cpu;
32544+#else
32545 struct page *page;
32546+#endif
32547
32548 if (pgd_none(*pgd_ref))
32549 continue;
32550
32551 spin_lock(&pgd_lock);
32552+
32553+#ifdef CONFIG_PAX_PER_CPU_PGD
32554+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32555+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32556+
32557+ if (pgd_none(*pgd))
32558+ set_pgd(pgd, *pgd_ref);
32559+ else
32560+ BUG_ON(pgd_page_vaddr(*pgd)
32561+ != pgd_page_vaddr(*pgd_ref));
32562+ pgd = pgd_offset_cpu(cpu, kernel, address);
32563+#else
32564 list_for_each_entry(page, &pgd_list, lru) {
32565 pgd_t *pgd;
32566 spinlock_t *pgt_lock;
32567@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32568 /* the pgt_lock only for Xen */
32569 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32570 spin_lock(pgt_lock);
32571+#endif
32572
32573 if (pgd_none(*pgd))
32574 set_pgd(pgd, *pgd_ref);
32575@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32576 BUG_ON(pgd_page_vaddr(*pgd)
32577 != pgd_page_vaddr(*pgd_ref));
32578
32579+#ifndef CONFIG_PAX_PER_CPU_PGD
32580 spin_unlock(pgt_lock);
32581+#endif
32582+
32583 }
32584 spin_unlock(&pgd_lock);
32585 }
32586@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32587 {
32588 if (pgd_none(*pgd)) {
32589 pud_t *pud = (pud_t *)spp_getpage();
32590- pgd_populate(&init_mm, pgd, pud);
32591+ pgd_populate_kernel(&init_mm, pgd, pud);
32592 if (pud != pud_offset(pgd, 0))
32593 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32594 pud, pud_offset(pgd, 0));
32595@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32596 {
32597 if (pud_none(*pud)) {
32598 pmd_t *pmd = (pmd_t *) spp_getpage();
32599- pud_populate(&init_mm, pud, pmd);
32600+ pud_populate_kernel(&init_mm, pud, pmd);
32601 if (pmd != pmd_offset(pud, 0))
32602 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32603 pmd, pmd_offset(pud, 0));
32604@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32605 pmd = fill_pmd(pud, vaddr);
32606 pte = fill_pte(pmd, vaddr);
32607
32608+ pax_open_kernel();
32609 set_pte(pte, new_pte);
32610+ pax_close_kernel();
32611
32612 /*
32613 * It's enough to flush this one mapping.
32614@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32615 pgd = pgd_offset_k((unsigned long)__va(phys));
32616 if (pgd_none(*pgd)) {
32617 pud = (pud_t *) spp_getpage();
32618- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32619- _PAGE_USER));
32620+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32621 }
32622 pud = pud_offset(pgd, (unsigned long)__va(phys));
32623 if (pud_none(*pud)) {
32624 pmd = (pmd_t *) spp_getpage();
32625- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32626- _PAGE_USER));
32627+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32628 }
32629 pmd = pmd_offset(pud, phys);
32630 BUG_ON(!pmd_none(*pmd));
32631@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32632 prot);
32633
32634 spin_lock(&init_mm.page_table_lock);
32635- pud_populate(&init_mm, pud, pmd);
32636+ pud_populate_kernel(&init_mm, pud, pmd);
32637 spin_unlock(&init_mm.page_table_lock);
32638 }
32639 __flush_tlb_all();
32640@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32641 page_size_mask);
32642
32643 spin_lock(&init_mm.page_table_lock);
32644- pgd_populate(&init_mm, pgd, pud);
32645+ pgd_populate_kernel(&init_mm, pgd, pud);
32646 spin_unlock(&init_mm.page_table_lock);
32647 pgd_changed = true;
32648 }
32649@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32650 static struct vm_area_struct gate_vma = {
32651 .vm_start = VSYSCALL_START,
32652 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32653- .vm_page_prot = PAGE_READONLY_EXEC,
32654- .vm_flags = VM_READ | VM_EXEC
32655+ .vm_page_prot = PAGE_READONLY,
32656+ .vm_flags = VM_READ
32657 };
32658
32659 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32660@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32661
32662 const char *arch_vma_name(struct vm_area_struct *vma)
32663 {
32664- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32665+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32666 return "[vdso]";
32667 if (vma == &gate_vma)
32668 return "[vsyscall]";
32669diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32670index 7b179b4..6bd17777 100644
32671--- a/arch/x86/mm/iomap_32.c
32672+++ b/arch/x86/mm/iomap_32.c
32673@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32674 type = kmap_atomic_idx_push();
32675 idx = type + KM_TYPE_NR * smp_processor_id();
32676 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32677+
32678+ pax_open_kernel();
32679 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32680+ pax_close_kernel();
32681+
32682 arch_flush_lazy_mmu_mode();
32683
32684 return (void *)vaddr;
32685diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32686index 799580c..72f9fe0 100644
32687--- a/arch/x86/mm/ioremap.c
32688+++ b/arch/x86/mm/ioremap.c
32689@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32690 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32691 int is_ram = page_is_ram(pfn);
32692
32693- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32694+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32695 return NULL;
32696 WARN_ON_ONCE(is_ram);
32697 }
32698@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32699 *
32700 * Caller must ensure there is only one unmapping for the same pointer.
32701 */
32702-void iounmap(volatile void __iomem *addr)
32703+void iounmap(const volatile void __iomem *addr)
32704 {
32705 struct vm_struct *p, *o;
32706
32707@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32708
32709 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32710 if (page_is_ram(start >> PAGE_SHIFT))
32711+#ifdef CONFIG_HIGHMEM
32712+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32713+#endif
32714 return __va(phys);
32715
32716 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32717@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32718 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32719 {
32720 if (page_is_ram(phys >> PAGE_SHIFT))
32721+#ifdef CONFIG_HIGHMEM
32722+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32723+#endif
32724 return;
32725
32726 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32727@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32728 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32729
32730 static __initdata int after_paging_init;
32731-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32732+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32733
32734 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32735 {
32736@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32737 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32738
32739 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32740- memset(bm_pte, 0, sizeof(bm_pte));
32741- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32742+ pmd_populate_user(&init_mm, pmd, bm_pte);
32743
32744 /*
32745 * The boot-ioremap range spans multiple pmds, for which
32746diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32747index d87dd6d..bf3fa66 100644
32748--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32749+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32750@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32751 * memory (e.g. tracked pages)? For now, we need this to avoid
32752 * invoking kmemcheck for PnP BIOS calls.
32753 */
32754- if (regs->flags & X86_VM_MASK)
32755+ if (v8086_mode(regs))
32756 return false;
32757- if (regs->cs != __KERNEL_CS)
32758+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32759 return false;
32760
32761 pte = kmemcheck_pte_lookup(address);
32762diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32763index 25e7e13..1964579 100644
32764--- a/arch/x86/mm/mmap.c
32765+++ b/arch/x86/mm/mmap.c
32766@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32767 * Leave an at least ~128 MB hole with possible stack randomization.
32768 */
32769 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32770-#define MAX_GAP (TASK_SIZE/6*5)
32771+#define MAX_GAP (pax_task_size/6*5)
32772
32773 static int mmap_is_legacy(void)
32774 {
32775@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32776 return rnd << PAGE_SHIFT;
32777 }
32778
32779-static unsigned long mmap_base(void)
32780+static unsigned long mmap_base(struct mm_struct *mm)
32781 {
32782 unsigned long gap = rlimit(RLIMIT_STACK);
32783+ unsigned long pax_task_size = TASK_SIZE;
32784+
32785+#ifdef CONFIG_PAX_SEGMEXEC
32786+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32787+ pax_task_size = SEGMEXEC_TASK_SIZE;
32788+#endif
32789
32790 if (gap < MIN_GAP)
32791 gap = MIN_GAP;
32792 else if (gap > MAX_GAP)
32793 gap = MAX_GAP;
32794
32795- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32796+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32797 }
32798
32799 /*
32800 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32801 * does, but not when emulating X86_32
32802 */
32803-static unsigned long mmap_legacy_base(void)
32804+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32805 {
32806- if (mmap_is_ia32())
32807+ if (mmap_is_ia32()) {
32808+
32809+#ifdef CONFIG_PAX_SEGMEXEC
32810+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32811+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32812+ else
32813+#endif
32814+
32815 return TASK_UNMAPPED_BASE;
32816- else
32817+ } else
32818 return TASK_UNMAPPED_BASE + mmap_rnd();
32819 }
32820
32821@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32822 */
32823 void arch_pick_mmap_layout(struct mm_struct *mm)
32824 {
32825- mm->mmap_legacy_base = mmap_legacy_base();
32826- mm->mmap_base = mmap_base();
32827+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32828+ mm->mmap_base = mmap_base(mm);
32829+
32830+#ifdef CONFIG_PAX_RANDMMAP
32831+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32832+ mm->mmap_legacy_base += mm->delta_mmap;
32833+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32834+ }
32835+#endif
32836
32837 if (mmap_is_legacy()) {
32838 mm->mmap_base = mm->mmap_legacy_base;
32839diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32840index 0057a7a..95c7edd 100644
32841--- a/arch/x86/mm/mmio-mod.c
32842+++ b/arch/x86/mm/mmio-mod.c
32843@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32844 break;
32845 default:
32846 {
32847- unsigned char *ip = (unsigned char *)instptr;
32848+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32849 my_trace->opcode = MMIO_UNKNOWN_OP;
32850 my_trace->width = 0;
32851 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32852@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32853 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32854 void __iomem *addr)
32855 {
32856- static atomic_t next_id;
32857+ static atomic_unchecked_t next_id;
32858 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32859 /* These are page-unaligned. */
32860 struct mmiotrace_map map = {
32861@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32862 .private = trace
32863 },
32864 .phys = offset,
32865- .id = atomic_inc_return(&next_id)
32866+ .id = atomic_inc_return_unchecked(&next_id)
32867 };
32868 map.map_id = trace->id;
32869
32870@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32871 ioremap_trace_core(offset, size, addr);
32872 }
32873
32874-static void iounmap_trace_core(volatile void __iomem *addr)
32875+static void iounmap_trace_core(const volatile void __iomem *addr)
32876 {
32877 struct mmiotrace_map map = {
32878 .phys = 0,
32879@@ -328,7 +328,7 @@ not_enabled:
32880 }
32881 }
32882
32883-void mmiotrace_iounmap(volatile void __iomem *addr)
32884+void mmiotrace_iounmap(const volatile void __iomem *addr)
32885 {
32886 might_sleep();
32887 if (is_enabled()) /* recheck and proper locking in *_core() */
32888diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32889index 27aa0455..0eb1406 100644
32890--- a/arch/x86/mm/numa.c
32891+++ b/arch/x86/mm/numa.c
32892@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32893 return true;
32894 }
32895
32896-static int __init numa_register_memblks(struct numa_meminfo *mi)
32897+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32898 {
32899 unsigned long uninitialized_var(pfn_align);
32900 int i, nid;
32901diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32902index 461bc82..4e091a3 100644
32903--- a/arch/x86/mm/pageattr-test.c
32904+++ b/arch/x86/mm/pageattr-test.c
32905@@ -35,7 +35,7 @@ enum {
32906
32907 static int pte_testbit(pte_t pte)
32908 {
32909- return pte_flags(pte) & _PAGE_UNUSED1;
32910+ return pte_flags(pte) & _PAGE_CPA_TEST;
32911 }
32912
32913 struct split_state {
32914diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32915index a348868..3c64310 100644
32916--- a/arch/x86/mm/pageattr.c
32917+++ b/arch/x86/mm/pageattr.c
32918@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32919 */
32920 #ifdef CONFIG_PCI_BIOS
32921 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32922- pgprot_val(forbidden) |= _PAGE_NX;
32923+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32924 #endif
32925
32926 /*
32927@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32928 * Does not cover __inittext since that is gone later on. On
32929 * 64bit we do not enforce !NX on the low mapping
32930 */
32931- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32932- pgprot_val(forbidden) |= _PAGE_NX;
32933+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32934+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32935
32936+#ifdef CONFIG_DEBUG_RODATA
32937 /*
32938 * The .rodata section needs to be read-only. Using the pfn
32939 * catches all aliases.
32940@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32941 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32942 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32943 pgprot_val(forbidden) |= _PAGE_RW;
32944+#endif
32945
32946 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32947 /*
32948@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32949 }
32950 #endif
32951
32952+#ifdef CONFIG_PAX_KERNEXEC
32953+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32954+ pgprot_val(forbidden) |= _PAGE_RW;
32955+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32956+ }
32957+#endif
32958+
32959 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32960
32961 return prot;
32962@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32963 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32964 {
32965 /* change init_mm */
32966+ pax_open_kernel();
32967 set_pte_atomic(kpte, pte);
32968+
32969 #ifdef CONFIG_X86_32
32970 if (!SHARED_KERNEL_PMD) {
32971+
32972+#ifdef CONFIG_PAX_PER_CPU_PGD
32973+ unsigned long cpu;
32974+#else
32975 struct page *page;
32976+#endif
32977
32978+#ifdef CONFIG_PAX_PER_CPU_PGD
32979+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32980+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32981+#else
32982 list_for_each_entry(page, &pgd_list, lru) {
32983- pgd_t *pgd;
32984+ pgd_t *pgd = (pgd_t *)page_address(page);
32985+#endif
32986+
32987 pud_t *pud;
32988 pmd_t *pmd;
32989
32990- pgd = (pgd_t *)page_address(page) + pgd_index(address);
32991+ pgd += pgd_index(address);
32992 pud = pud_offset(pgd, address);
32993 pmd = pmd_offset(pud, address);
32994 set_pte_atomic((pte_t *)pmd, pte);
32995 }
32996 }
32997 #endif
32998+ pax_close_kernel();
32999 }
33000
33001 static int
33002diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33003index 6574388..87e9bef 100644
33004--- a/arch/x86/mm/pat.c
33005+++ b/arch/x86/mm/pat.c
33006@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33007
33008 if (!entry) {
33009 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33010- current->comm, current->pid, start, end - 1);
33011+ current->comm, task_pid_nr(current), start, end - 1);
33012 return -EINVAL;
33013 }
33014
33015@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33016
33017 while (cursor < to) {
33018 if (!devmem_is_allowed(pfn)) {
33019- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33020- current->comm, from, to - 1);
33021+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33022+ current->comm, from, to - 1, cursor);
33023 return 0;
33024 }
33025 cursor += PAGE_SIZE;
33026@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33027 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33028 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33029 "for [mem %#010Lx-%#010Lx]\n",
33030- current->comm, current->pid,
33031+ current->comm, task_pid_nr(current),
33032 cattr_name(flags),
33033 base, (unsigned long long)(base + size-1));
33034 return -EINVAL;
33035@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33036 flags = lookup_memtype(paddr);
33037 if (want_flags != flags) {
33038 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33039- current->comm, current->pid,
33040+ current->comm, task_pid_nr(current),
33041 cattr_name(want_flags),
33042 (unsigned long long)paddr,
33043 (unsigned long long)(paddr + size - 1),
33044@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33045 free_memtype(paddr, paddr + size);
33046 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33047 " for [mem %#010Lx-%#010Lx], got %s\n",
33048- current->comm, current->pid,
33049+ current->comm, task_pid_nr(current),
33050 cattr_name(want_flags),
33051 (unsigned long long)paddr,
33052 (unsigned long long)(paddr + size - 1),
33053diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33054index 415f6c4..d319983 100644
33055--- a/arch/x86/mm/pat_rbtree.c
33056+++ b/arch/x86/mm/pat_rbtree.c
33057@@ -160,7 +160,7 @@ success:
33058
33059 failure:
33060 printk(KERN_INFO "%s:%d conflicting memory types "
33061- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33062+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33063 end, cattr_name(found_type), cattr_name(match->type));
33064 return -EBUSY;
33065 }
33066diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33067index 9f0614d..92ae64a 100644
33068--- a/arch/x86/mm/pf_in.c
33069+++ b/arch/x86/mm/pf_in.c
33070@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33071 int i;
33072 enum reason_type rv = OTHERS;
33073
33074- p = (unsigned char *)ins_addr;
33075+ p = (unsigned char *)ktla_ktva(ins_addr);
33076 p += skip_prefix(p, &prf);
33077 p += get_opcode(p, &opcode);
33078
33079@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33080 struct prefix_bits prf;
33081 int i;
33082
33083- p = (unsigned char *)ins_addr;
33084+ p = (unsigned char *)ktla_ktva(ins_addr);
33085 p += skip_prefix(p, &prf);
33086 p += get_opcode(p, &opcode);
33087
33088@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33089 struct prefix_bits prf;
33090 int i;
33091
33092- p = (unsigned char *)ins_addr;
33093+ p = (unsigned char *)ktla_ktva(ins_addr);
33094 p += skip_prefix(p, &prf);
33095 p += get_opcode(p, &opcode);
33096
33097@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33098 struct prefix_bits prf;
33099 int i;
33100
33101- p = (unsigned char *)ins_addr;
33102+ p = (unsigned char *)ktla_ktva(ins_addr);
33103 p += skip_prefix(p, &prf);
33104 p += get_opcode(p, &opcode);
33105 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33106@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33107 struct prefix_bits prf;
33108 int i;
33109
33110- p = (unsigned char *)ins_addr;
33111+ p = (unsigned char *)ktla_ktva(ins_addr);
33112 p += skip_prefix(p, &prf);
33113 p += get_opcode(p, &opcode);
33114 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33115diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33116index c96314a..433b127 100644
33117--- a/arch/x86/mm/pgtable.c
33118+++ b/arch/x86/mm/pgtable.c
33119@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33120 list_del(&page->lru);
33121 }
33122
33123-#define UNSHARED_PTRS_PER_PGD \
33124- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33125+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33126+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33127
33128+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33129+{
33130+ unsigned int count = USER_PGD_PTRS;
33131
33132+ if (!pax_user_shadow_base)
33133+ return;
33134+
33135+ while (count--)
33136+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33137+}
33138+#endif
33139+
33140+#ifdef CONFIG_PAX_PER_CPU_PGD
33141+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33142+{
33143+ unsigned int count = USER_PGD_PTRS;
33144+
33145+ while (count--) {
33146+ pgd_t pgd;
33147+
33148+#ifdef CONFIG_X86_64
33149+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33150+#else
33151+ pgd = *src++;
33152+#endif
33153+
33154+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33155+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33156+#endif
33157+
33158+ *dst++ = pgd;
33159+ }
33160+
33161+}
33162+#endif
33163+
33164+#ifdef CONFIG_X86_64
33165+#define pxd_t pud_t
33166+#define pyd_t pgd_t
33167+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33168+#define pgtable_pxd_page_ctor(page) true
33169+#define pgtable_pxd_page_dtor(page)
33170+#define pxd_free(mm, pud) pud_free((mm), (pud))
33171+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33172+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33173+#define PYD_SIZE PGDIR_SIZE
33174+#else
33175+#define pxd_t pmd_t
33176+#define pyd_t pud_t
33177+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33178+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33179+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33180+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33181+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33182+#define pyd_offset(mm, address) pud_offset((mm), (address))
33183+#define PYD_SIZE PUD_SIZE
33184+#endif
33185+
33186+#ifdef CONFIG_PAX_PER_CPU_PGD
33187+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33188+static inline void pgd_dtor(pgd_t *pgd) {}
33189+#else
33190 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33191 {
33192 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33193@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33194 pgd_list_del(pgd);
33195 spin_unlock(&pgd_lock);
33196 }
33197+#endif
33198
33199 /*
33200 * List of all pgd's needed for non-PAE so it can invalidate entries
33201@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33202 * -- nyc
33203 */
33204
33205-#ifdef CONFIG_X86_PAE
33206+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33207 /*
33208 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33209 * updating the top-level pagetable entries to guarantee the
33210@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33211 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33212 * and initialize the kernel pmds here.
33213 */
33214-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33215+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33216
33217 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33218 {
33219@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33220 */
33221 flush_tlb_mm(mm);
33222 }
33223+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33224+#define PREALLOCATED_PXDS USER_PGD_PTRS
33225 #else /* !CONFIG_X86_PAE */
33226
33227 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33228-#define PREALLOCATED_PMDS 0
33229+#define PREALLOCATED_PXDS 0
33230
33231 #endif /* CONFIG_X86_PAE */
33232
33233-static void free_pmds(pmd_t *pmds[])
33234+static void free_pxds(pxd_t *pxds[])
33235 {
33236 int i;
33237
33238- for(i = 0; i < PREALLOCATED_PMDS; i++)
33239- if (pmds[i]) {
33240- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33241- free_page((unsigned long)pmds[i]);
33242+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33243+ if (pxds[i]) {
33244+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33245+ free_page((unsigned long)pxds[i]);
33246 }
33247 }
33248
33249-static int preallocate_pmds(pmd_t *pmds[])
33250+static int preallocate_pxds(pxd_t *pxds[])
33251 {
33252 int i;
33253 bool failed = false;
33254
33255- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33256- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33257- if (!pmd)
33258+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33259+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33260+ if (!pxd)
33261 failed = true;
33262- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33263- free_page((unsigned long)pmd);
33264- pmd = NULL;
33265+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33266+ free_page((unsigned long)pxd);
33267+ pxd = NULL;
33268 failed = true;
33269 }
33270- pmds[i] = pmd;
33271+ pxds[i] = pxd;
33272 }
33273
33274 if (failed) {
33275- free_pmds(pmds);
33276+ free_pxds(pxds);
33277 return -ENOMEM;
33278 }
33279
33280@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33281 * preallocate which never got a corresponding vma will need to be
33282 * freed manually.
33283 */
33284-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33285+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33286 {
33287 int i;
33288
33289- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33290+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33291 pgd_t pgd = pgdp[i];
33292
33293 if (pgd_val(pgd) != 0) {
33294- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33295+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33296
33297- pgdp[i] = native_make_pgd(0);
33298+ set_pgd(pgdp + i, native_make_pgd(0));
33299
33300- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33301- pmd_free(mm, pmd);
33302+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33303+ pxd_free(mm, pxd);
33304 }
33305 }
33306 }
33307
33308-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33309+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33310 {
33311- pud_t *pud;
33312+ pyd_t *pyd;
33313 int i;
33314
33315- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33316+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33317 return;
33318
33319- pud = pud_offset(pgd, 0);
33320-
33321- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33322- pmd_t *pmd = pmds[i];
33323+#ifdef CONFIG_X86_64
33324+ pyd = pyd_offset(mm, 0L);
33325+#else
33326+ pyd = pyd_offset(pgd, 0L);
33327+#endif
33328
33329+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33330+ pxd_t *pxd = pxds[i];
33331 if (i >= KERNEL_PGD_BOUNDARY)
33332- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33333- sizeof(pmd_t) * PTRS_PER_PMD);
33334+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33335+ sizeof(pxd_t) * PTRS_PER_PMD);
33336
33337- pud_populate(mm, pud, pmd);
33338+ pyd_populate(mm, pyd, pxd);
33339 }
33340 }
33341
33342 pgd_t *pgd_alloc(struct mm_struct *mm)
33343 {
33344 pgd_t *pgd;
33345- pmd_t *pmds[PREALLOCATED_PMDS];
33346+ pxd_t *pxds[PREALLOCATED_PXDS];
33347
33348 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33349
33350@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33351
33352 mm->pgd = pgd;
33353
33354- if (preallocate_pmds(pmds) != 0)
33355+ if (preallocate_pxds(pxds) != 0)
33356 goto out_free_pgd;
33357
33358 if (paravirt_pgd_alloc(mm) != 0)
33359- goto out_free_pmds;
33360+ goto out_free_pxds;
33361
33362 /*
33363 * Make sure that pre-populating the pmds is atomic with
33364@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33365 spin_lock(&pgd_lock);
33366
33367 pgd_ctor(mm, pgd);
33368- pgd_prepopulate_pmd(mm, pgd, pmds);
33369+ pgd_prepopulate_pxd(mm, pgd, pxds);
33370
33371 spin_unlock(&pgd_lock);
33372
33373 return pgd;
33374
33375-out_free_pmds:
33376- free_pmds(pmds);
33377+out_free_pxds:
33378+ free_pxds(pxds);
33379 out_free_pgd:
33380 free_page((unsigned long)pgd);
33381 out:
33382@@ -313,7 +380,7 @@ out:
33383
33384 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33385 {
33386- pgd_mop_up_pmds(mm, pgd);
33387+ pgd_mop_up_pxds(mm, pgd);
33388 pgd_dtor(pgd);
33389 paravirt_pgd_free(mm, pgd);
33390 free_page((unsigned long)pgd);
33391diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33392index a69bcb8..19068ab 100644
33393--- a/arch/x86/mm/pgtable_32.c
33394+++ b/arch/x86/mm/pgtable_32.c
33395@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33396 return;
33397 }
33398 pte = pte_offset_kernel(pmd, vaddr);
33399+
33400+ pax_open_kernel();
33401 if (pte_val(pteval))
33402 set_pte_at(&init_mm, vaddr, pte, pteval);
33403 else
33404 pte_clear(&init_mm, vaddr, pte);
33405+ pax_close_kernel();
33406
33407 /*
33408 * It's enough to flush this one mapping.
33409diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33410index e666cbb..61788c45 100644
33411--- a/arch/x86/mm/physaddr.c
33412+++ b/arch/x86/mm/physaddr.c
33413@@ -10,7 +10,7 @@
33414 #ifdef CONFIG_X86_64
33415
33416 #ifdef CONFIG_DEBUG_VIRTUAL
33417-unsigned long __phys_addr(unsigned long x)
33418+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33419 {
33420 unsigned long y = x - __START_KERNEL_map;
33421
33422@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33423 #else
33424
33425 #ifdef CONFIG_DEBUG_VIRTUAL
33426-unsigned long __phys_addr(unsigned long x)
33427+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33428 {
33429 unsigned long phys_addr = x - PAGE_OFFSET;
33430 /* VMALLOC_* aren't constants */
33431diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33432index 90555bf..f5f1828 100644
33433--- a/arch/x86/mm/setup_nx.c
33434+++ b/arch/x86/mm/setup_nx.c
33435@@ -5,8 +5,10 @@
33436 #include <asm/pgtable.h>
33437 #include <asm/proto.h>
33438
33439+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33440 static int disable_nx;
33441
33442+#ifndef CONFIG_PAX_PAGEEXEC
33443 /*
33444 * noexec = on|off
33445 *
33446@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33447 return 0;
33448 }
33449 early_param("noexec", noexec_setup);
33450+#endif
33451+
33452+#endif
33453
33454 void x86_configure_nx(void)
33455 {
33456+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33457 if (cpu_has_nx && !disable_nx)
33458 __supported_pte_mask |= _PAGE_NX;
33459 else
33460+#endif
33461 __supported_pte_mask &= ~_PAGE_NX;
33462 }
33463
33464diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33465index dd8dda1..9e9b0f6 100644
33466--- a/arch/x86/mm/tlb.c
33467+++ b/arch/x86/mm/tlb.c
33468@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33469 BUG();
33470 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33471 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33472+
33473+#ifndef CONFIG_PAX_PER_CPU_PGD
33474 load_cr3(swapper_pg_dir);
33475+#endif
33476+
33477 }
33478 }
33479 EXPORT_SYMBOL_GPL(leave_mm);
33480diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33481new file mode 100644
33482index 0000000..dace51c
33483--- /dev/null
33484+++ b/arch/x86/mm/uderef_64.c
33485@@ -0,0 +1,37 @@
33486+#include <linux/mm.h>
33487+#include <asm/pgtable.h>
33488+#include <asm/uaccess.h>
33489+
33490+#ifdef CONFIG_PAX_MEMORY_UDEREF
33491+/* PaX: due to the special call convention these functions must
33492+ * - remain leaf functions under all configurations,
33493+ * - never be called directly, only dereferenced from the wrappers.
33494+ */
33495+void __pax_open_userland(void)
33496+{
33497+ unsigned int cpu;
33498+
33499+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33500+ return;
33501+
33502+ cpu = raw_get_cpu();
33503+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33504+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33505+ raw_put_cpu_no_resched();
33506+}
33507+EXPORT_SYMBOL(__pax_open_userland);
33508+
33509+void __pax_close_userland(void)
33510+{
33511+ unsigned int cpu;
33512+
33513+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33514+ return;
33515+
33516+ cpu = raw_get_cpu();
33517+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33518+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33519+ raw_put_cpu_no_resched();
33520+}
33521+EXPORT_SYMBOL(__pax_close_userland);
33522+#endif
33523diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33524index 0149575..f746de8 100644
33525--- a/arch/x86/net/bpf_jit.S
33526+++ b/arch/x86/net/bpf_jit.S
33527@@ -9,6 +9,7 @@
33528 */
33529 #include <linux/linkage.h>
33530 #include <asm/dwarf2.h>
33531+#include <asm/alternative-asm.h>
33532
33533 /*
33534 * Calling convention :
33535@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33536 jle bpf_slow_path_word
33537 mov (SKBDATA,%rsi),%eax
33538 bswap %eax /* ntohl() */
33539+ pax_force_retaddr
33540 ret
33541
33542 sk_load_half:
33543@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33544 jle bpf_slow_path_half
33545 movzwl (SKBDATA,%rsi),%eax
33546 rol $8,%ax # ntohs()
33547+ pax_force_retaddr
33548 ret
33549
33550 sk_load_byte:
33551@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33552 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33553 jle bpf_slow_path_byte
33554 movzbl (SKBDATA,%rsi),%eax
33555+ pax_force_retaddr
33556 ret
33557
33558 /**
33559@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33560 movzbl (SKBDATA,%rsi),%ebx
33561 and $15,%bl
33562 shl $2,%bl
33563+ pax_force_retaddr
33564 ret
33565
33566 /* rsi contains offset and can be scratched */
33567@@ -109,6 +114,7 @@ bpf_slow_path_word:
33568 js bpf_error
33569 mov -12(%rbp),%eax
33570 bswap %eax
33571+ pax_force_retaddr
33572 ret
33573
33574 bpf_slow_path_half:
33575@@ -117,12 +123,14 @@ bpf_slow_path_half:
33576 mov -12(%rbp),%ax
33577 rol $8,%ax
33578 movzwl %ax,%eax
33579+ pax_force_retaddr
33580 ret
33581
33582 bpf_slow_path_byte:
33583 bpf_slow_path_common(1)
33584 js bpf_error
33585 movzbl -12(%rbp),%eax
33586+ pax_force_retaddr
33587 ret
33588
33589 bpf_slow_path_byte_msh:
33590@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33591 and $15,%al
33592 shl $2,%al
33593 xchg %eax,%ebx
33594+ pax_force_retaddr
33595 ret
33596
33597 #define sk_negative_common(SIZE) \
33598@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33599 sk_negative_common(4)
33600 mov (%rax), %eax
33601 bswap %eax
33602+ pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_half_neg:
33606@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33607 mov (%rax),%ax
33608 rol $8,%ax
33609 movzwl %ax,%eax
33610+ pax_force_retaddr
33611 ret
33612
33613 bpf_slow_path_byte_neg:
33614@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33615 .globl sk_load_byte_negative_offset
33616 sk_negative_common(1)
33617 movzbl (%rax), %eax
33618+ pax_force_retaddr
33619 ret
33620
33621 bpf_slow_path_byte_msh_neg:
33622@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33623 and $15,%al
33624 shl $2,%al
33625 xchg %eax,%ebx
33626+ pax_force_retaddr
33627 ret
33628
33629 bpf_error:
33630@@ -197,4 +210,5 @@ bpf_error:
33631 xor %eax,%eax
33632 mov -8(%rbp),%rbx
33633 leaveq
33634+ pax_force_retaddr
33635 ret
33636diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33637index 4ed75dd..3cf24f0b 100644
33638--- a/arch/x86/net/bpf_jit_comp.c
33639+++ b/arch/x86/net/bpf_jit_comp.c
33640@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33641 return ptr + len;
33642 }
33643
33644+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33645+#define MAX_INSTR_CODE_SIZE 96
33646+#else
33647+#define MAX_INSTR_CODE_SIZE 64
33648+#endif
33649+
33650 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33651
33652 #define EMIT1(b1) EMIT(b1, 1)
33653 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33654 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33655 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33656+
33657+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33658+/* original constant will appear in ecx */
33659+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33660+do { \
33661+ /* mov ecx, randkey */ \
33662+ EMIT1(0xb9); \
33663+ EMIT(_key, 4); \
33664+ /* xor ecx, randkey ^ off */ \
33665+ EMIT2(0x81, 0xf1); \
33666+ EMIT((_key) ^ (_off), 4); \
33667+} while (0)
33668+
33669+#define EMIT1_off32(b1, _off) \
33670+do { \
33671+ switch (b1) { \
33672+ case 0x05: /* add eax, imm32 */ \
33673+ case 0x2d: /* sub eax, imm32 */ \
33674+ case 0x25: /* and eax, imm32 */ \
33675+ case 0x0d: /* or eax, imm32 */ \
33676+ case 0xb8: /* mov eax, imm32 */ \
33677+ case 0x35: /* xor eax, imm32 */ \
33678+ case 0x3d: /* cmp eax, imm32 */ \
33679+ case 0xa9: /* test eax, imm32 */ \
33680+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33681+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33682+ break; \
33683+ case 0xbb: /* mov ebx, imm32 */ \
33684+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33685+ /* mov ebx, ecx */ \
33686+ EMIT2(0x89, 0xcb); \
33687+ break; \
33688+ case 0xbe: /* mov esi, imm32 */ \
33689+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33690+ /* mov esi, ecx */ \
33691+ EMIT2(0x89, 0xce); \
33692+ break; \
33693+ case 0xe8: /* call rel imm32, always to known funcs */ \
33694+ EMIT1(b1); \
33695+ EMIT(_off, 4); \
33696+ break; \
33697+ case 0xe9: /* jmp rel imm32 */ \
33698+ EMIT1(b1); \
33699+ EMIT(_off, 4); \
33700+ /* prevent fall-through, we're not called if off = 0 */ \
33701+ EMIT(0xcccccccc, 4); \
33702+ EMIT(0xcccccccc, 4); \
33703+ break; \
33704+ default: \
33705+ BUILD_BUG(); \
33706+ } \
33707+} while (0)
33708+
33709+#define EMIT2_off32(b1, b2, _off) \
33710+do { \
33711+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33712+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33713+ EMIT(randkey, 4); \
33714+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33715+ EMIT((_off) - randkey, 4); \
33716+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33717+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33718+ /* imul eax, ecx */ \
33719+ EMIT3(0x0f, 0xaf, 0xc1); \
33720+ } else { \
33721+ BUILD_BUG(); \
33722+ } \
33723+} while (0)
33724+#else
33725 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33726+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33727+#endif
33728
33729 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33730 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33731@@ -91,6 +168,24 @@ do { \
33732 #define X86_JBE 0x76
33733 #define X86_JA 0x77
33734
33735+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33736+#define APPEND_FLOW_VERIFY() \
33737+do { \
33738+ /* mov ecx, randkey */ \
33739+ EMIT1(0xb9); \
33740+ EMIT(randkey, 4); \
33741+ /* cmp ecx, randkey */ \
33742+ EMIT2(0x81, 0xf9); \
33743+ EMIT(randkey, 4); \
33744+ /* jz after 8 int 3s */ \
33745+ EMIT2(0x74, 0x08); \
33746+ EMIT(0xcccccccc, 4); \
33747+ EMIT(0xcccccccc, 4); \
33748+} while (0)
33749+#else
33750+#define APPEND_FLOW_VERIFY() do { } while (0)
33751+#endif
33752+
33753 #define EMIT_COND_JMP(op, offset) \
33754 do { \
33755 if (is_near(offset)) \
33756@@ -98,6 +193,7 @@ do { \
33757 else { \
33758 EMIT2(0x0f, op + 0x10); \
33759 EMIT(offset, 4); /* jxx .+off32 */ \
33760+ APPEND_FLOW_VERIFY(); \
33761 } \
33762 } while (0)
33763
33764@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33765 return -1;
33766 }
33767
33768-struct bpf_binary_header {
33769- unsigned int pages;
33770- /* Note : for security reasons, bpf code will follow a randomly
33771- * sized amount of int3 instructions
33772- */
33773- u8 image[];
33774-};
33775-
33776-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33777+/* Note : for security reasons, bpf code will follow a randomly
33778+ * sized amount of int3 instructions
33779+ */
33780+static u8 *bpf_alloc_binary(unsigned int proglen,
33781 u8 **image_ptr)
33782 {
33783 unsigned int sz, hole;
33784- struct bpf_binary_header *header;
33785+ u8 *header;
33786
33787 /* Most of BPF filters are really small,
33788 * but if some of them fill a page, allow at least
33789 * 128 extra bytes to insert a random section of int3
33790 */
33791- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33792- header = module_alloc(sz);
33793+ sz = round_up(proglen + 128, PAGE_SIZE);
33794+ header = module_alloc_exec(sz);
33795 if (!header)
33796 return NULL;
33797
33798+ pax_open_kernel();
33799 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33800+ pax_close_kernel();
33801
33802- header->pages = sz / PAGE_SIZE;
33803- hole = sz - (proglen + sizeof(*header));
33804+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33805
33806 /* insert a random number of int3 instructions before BPF code */
33807- *image_ptr = &header->image[prandom_u32() % hole];
33808+ *image_ptr = &header[prandom_u32() % hole];
33809 return header;
33810 }
33811
33812 void bpf_jit_compile(struct sk_filter *fp)
33813 {
33814- u8 temp[64];
33815+ u8 temp[MAX_INSTR_CODE_SIZE];
33816 u8 *prog;
33817 unsigned int proglen, oldproglen = 0;
33818 int ilen, i;
33819 int t_offset, f_offset;
33820 u8 t_op, f_op, seen = 0, pass;
33821 u8 *image = NULL;
33822- struct bpf_binary_header *header = NULL;
33823+ u8 *header = NULL;
33824 u8 *func;
33825 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33826 unsigned int cleanup_addr; /* epilogue code offset */
33827 unsigned int *addrs;
33828 const struct sock_filter *filter = fp->insns;
33829 int flen = fp->len;
33830+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33831+ unsigned int randkey;
33832+#endif
33833
33834 if (!bpf_jit_enable)
33835 return;
33836@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33837 return;
33838
33839 /* Before first pass, make a rough estimation of addrs[]
33840- * each bpf instruction is translated to less than 64 bytes
33841+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33842 */
33843 for (proglen = 0, i = 0; i < flen; i++) {
33844- proglen += 64;
33845+ proglen += MAX_INSTR_CODE_SIZE;
33846 addrs[i] = proglen;
33847 }
33848 cleanup_addr = proglen; /* epilogue address */
33849@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33850 for (i = 0; i < flen; i++) {
33851 unsigned int K = filter[i].k;
33852
33853+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854+ randkey = prandom_u32();
33855+#endif
33856+
33857 switch (filter[i].code) {
33858 case BPF_S_ALU_ADD_X: /* A += X; */
33859 seen |= SEEN_XREG;
33860@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33861 case BPF_S_ALU_MUL_K: /* A *= K */
33862 if (is_imm8(K))
33863 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33864- else {
33865- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33866- EMIT(K, 4);
33867- }
33868+ else
33869+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33870 break;
33871 case BPF_S_ALU_DIV_X: /* A /= X; */
33872 seen |= SEEN_XREG;
33873@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33874 break;
33875 }
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 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33884 break;
33885@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33886 if (K == 1)
33887 break;
33888 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33889+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33890+ DILUTE_CONST_SEQUENCE(K, randkey);
33891+#else
33892 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33893+#endif
33894 EMIT2(0xf7, 0xf1); /* div %ecx */
33895 break;
33896 case BPF_S_ALU_AND_X:
33897@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33898 if (is_imm8(K)) {
33899 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33900 } else {
33901- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33902- EMIT(K, 4);
33903+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33904 }
33905 } else {
33906 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33907@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33908 if (unlikely(proglen + ilen > oldproglen)) {
33909 pr_err("bpb_jit_compile fatal error\n");
33910 kfree(addrs);
33911- module_free(NULL, header);
33912+ module_free_exec(NULL, image);
33913 return;
33914 }
33915+ pax_open_kernel();
33916 memcpy(image + proglen, temp, ilen);
33917+ pax_close_kernel();
33918 }
33919 proglen += ilen;
33920 addrs[i] = proglen;
33921@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33922
33923 if (image) {
33924 bpf_flush_icache(header, image + proglen);
33925- set_memory_ro((unsigned long)header, header->pages);
33926 fp->bpf_func = (void *)image;
33927 }
33928 out:
33929@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33930 {
33931 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33932 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33933- struct bpf_binary_header *header = (void *)addr;
33934
33935- set_memory_rw(addr, header->pages);
33936- module_free(NULL, header);
33937+ set_memory_rw(addr, 1);
33938+ module_free_exec(NULL, (void *)addr);
33939 kfree(fp);
33940 }
33941
33942diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33943index 5d04be5..2beeaa2 100644
33944--- a/arch/x86/oprofile/backtrace.c
33945+++ b/arch/x86/oprofile/backtrace.c
33946@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33947 struct stack_frame_ia32 *fp;
33948 unsigned long bytes;
33949
33950- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33951+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33952 if (bytes != 0)
33953 return NULL;
33954
33955- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33956+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33957
33958 oprofile_add_trace(bufhead[0].return_address);
33959
33960@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33961 struct stack_frame bufhead[2];
33962 unsigned long bytes;
33963
33964- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33965+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33966 if (bytes != 0)
33967 return NULL;
33968
33969@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33970 {
33971 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33972
33973- if (!user_mode_vm(regs)) {
33974+ if (!user_mode(regs)) {
33975 unsigned long stack = kernel_stack_pointer(regs);
33976 if (depth)
33977 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33978diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33979index 6890d84..1dad1f1 100644
33980--- a/arch/x86/oprofile/nmi_int.c
33981+++ b/arch/x86/oprofile/nmi_int.c
33982@@ -23,6 +23,7 @@
33983 #include <asm/nmi.h>
33984 #include <asm/msr.h>
33985 #include <asm/apic.h>
33986+#include <asm/pgtable.h>
33987
33988 #include "op_counter.h"
33989 #include "op_x86_model.h"
33990@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33991 if (ret)
33992 return ret;
33993
33994- if (!model->num_virt_counters)
33995- model->num_virt_counters = model->num_counters;
33996+ if (!model->num_virt_counters) {
33997+ pax_open_kernel();
33998+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
33999+ pax_close_kernel();
34000+ }
34001
34002 mux_init(ops);
34003
34004diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34005index 50d86c0..7985318 100644
34006--- a/arch/x86/oprofile/op_model_amd.c
34007+++ b/arch/x86/oprofile/op_model_amd.c
34008@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34009 num_counters = AMD64_NUM_COUNTERS;
34010 }
34011
34012- op_amd_spec.num_counters = num_counters;
34013- op_amd_spec.num_controls = num_counters;
34014- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34015+ pax_open_kernel();
34016+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34017+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34018+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34019+ pax_close_kernel();
34020
34021 return 0;
34022 }
34023diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34024index d90528e..0127e2b 100644
34025--- a/arch/x86/oprofile/op_model_ppro.c
34026+++ b/arch/x86/oprofile/op_model_ppro.c
34027@@ -19,6 +19,7 @@
34028 #include <asm/msr.h>
34029 #include <asm/apic.h>
34030 #include <asm/nmi.h>
34031+#include <asm/pgtable.h>
34032
34033 #include "op_x86_model.h"
34034 #include "op_counter.h"
34035@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34036
34037 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34038
34039- op_arch_perfmon_spec.num_counters = num_counters;
34040- op_arch_perfmon_spec.num_controls = num_counters;
34041+ pax_open_kernel();
34042+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34043+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34044+ pax_close_kernel();
34045 }
34046
34047 static int arch_perfmon_init(struct oprofile_operations *ignore)
34048diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34049index 71e8a67..6a313bb 100644
34050--- a/arch/x86/oprofile/op_x86_model.h
34051+++ b/arch/x86/oprofile/op_x86_model.h
34052@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34053 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34054 struct op_msrs const * const msrs);
34055 #endif
34056-};
34057+} __do_const;
34058
34059 struct op_counter_config;
34060
34061diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34062index 84b9d67..260e5ff 100644
34063--- a/arch/x86/pci/intel_mid_pci.c
34064+++ b/arch/x86/pci/intel_mid_pci.c
34065@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34066 pr_info("Intel MID platform detected, using MID PCI ops\n");
34067 pci_mmcfg_late_init();
34068 pcibios_enable_irq = intel_mid_pci_irq_enable;
34069- pci_root_ops = intel_mid_pci_ops;
34070+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34071 pci_soc_mode = 1;
34072 /* Continue with standard init */
34073 return 1;
34074diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34075index 372e9b8..e775a6c 100644
34076--- a/arch/x86/pci/irq.c
34077+++ b/arch/x86/pci/irq.c
34078@@ -50,7 +50,7 @@ struct irq_router {
34079 struct irq_router_handler {
34080 u16 vendor;
34081 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34082-};
34083+} __do_const;
34084
34085 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34086 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34087@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34088 return 0;
34089 }
34090
34091-static __initdata struct irq_router_handler pirq_routers[] = {
34092+static __initconst const struct irq_router_handler pirq_routers[] = {
34093 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34094 { PCI_VENDOR_ID_AL, ali_router_probe },
34095 { PCI_VENDOR_ID_ITE, ite_router_probe },
34096@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34097 static void __init pirq_find_router(struct irq_router *r)
34098 {
34099 struct irq_routing_table *rt = pirq_table;
34100- struct irq_router_handler *h;
34101+ const struct irq_router_handler *h;
34102
34103 #ifdef CONFIG_PCI_BIOS
34104 if (!rt->signature) {
34105@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34106 return 0;
34107 }
34108
34109-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34110+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34111 {
34112 .callback = fix_broken_hp_bios_irq9,
34113 .ident = "HP Pavilion N5400 Series Laptop",
34114diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34115index c77b24a..c979855 100644
34116--- a/arch/x86/pci/pcbios.c
34117+++ b/arch/x86/pci/pcbios.c
34118@@ -79,7 +79,7 @@ union bios32 {
34119 static struct {
34120 unsigned long address;
34121 unsigned short segment;
34122-} bios32_indirect = { 0, __KERNEL_CS };
34123+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34124
34125 /*
34126 * Returns the entry point for the given service, NULL on error
34127@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34128 unsigned long length; /* %ecx */
34129 unsigned long entry; /* %edx */
34130 unsigned long flags;
34131+ struct desc_struct d, *gdt;
34132
34133 local_irq_save(flags);
34134- __asm__("lcall *(%%edi); cld"
34135+
34136+ gdt = get_cpu_gdt_table(smp_processor_id());
34137+
34138+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34139+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34140+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34141+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34142+
34143+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34144 : "=a" (return_code),
34145 "=b" (address),
34146 "=c" (length),
34147 "=d" (entry)
34148 : "0" (service),
34149 "1" (0),
34150- "D" (&bios32_indirect));
34151+ "D" (&bios32_indirect),
34152+ "r"(__PCIBIOS_DS)
34153+ : "memory");
34154+
34155+ pax_open_kernel();
34156+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34157+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34158+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34159+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34160+ pax_close_kernel();
34161+
34162 local_irq_restore(flags);
34163
34164 switch (return_code) {
34165- case 0:
34166- return address + entry;
34167- case 0x80: /* Not present */
34168- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34169- return 0;
34170- default: /* Shouldn't happen */
34171- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34172- service, return_code);
34173+ case 0: {
34174+ int cpu;
34175+ unsigned char flags;
34176+
34177+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34178+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34179+ printk(KERN_WARNING "bios32_service: not valid\n");
34180 return 0;
34181+ }
34182+ address = address + PAGE_OFFSET;
34183+ length += 16UL; /* some BIOSs underreport this... */
34184+ flags = 4;
34185+ if (length >= 64*1024*1024) {
34186+ length >>= PAGE_SHIFT;
34187+ flags |= 8;
34188+ }
34189+
34190+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34191+ gdt = get_cpu_gdt_table(cpu);
34192+ pack_descriptor(&d, address, length, 0x9b, flags);
34193+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34194+ pack_descriptor(&d, address, length, 0x93, flags);
34195+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34196+ }
34197+ return entry;
34198+ }
34199+ case 0x80: /* Not present */
34200+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34201+ return 0;
34202+ default: /* Shouldn't happen */
34203+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34204+ service, return_code);
34205+ return 0;
34206 }
34207 }
34208
34209 static struct {
34210 unsigned long address;
34211 unsigned short segment;
34212-} pci_indirect = { 0, __KERNEL_CS };
34213+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34214
34215-static int pci_bios_present;
34216+static int pci_bios_present __read_only;
34217
34218 static int check_pcibios(void)
34219 {
34220@@ -131,11 +174,13 @@ static int check_pcibios(void)
34221 unsigned long flags, pcibios_entry;
34222
34223 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34224- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34225+ pci_indirect.address = pcibios_entry;
34226
34227 local_irq_save(flags);
34228- __asm__(
34229- "lcall *(%%edi); cld\n\t"
34230+ __asm__("movw %w6, %%ds\n\t"
34231+ "lcall *%%ss:(%%edi); cld\n\t"
34232+ "push %%ss\n\t"
34233+ "pop %%ds\n\t"
34234 "jc 1f\n\t"
34235 "xor %%ah, %%ah\n"
34236 "1:"
34237@@ -144,7 +189,8 @@ static int check_pcibios(void)
34238 "=b" (ebx),
34239 "=c" (ecx)
34240 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34241- "D" (&pci_indirect)
34242+ "D" (&pci_indirect),
34243+ "r" (__PCIBIOS_DS)
34244 : "memory");
34245 local_irq_restore(flags);
34246
34247@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34248
34249 switch (len) {
34250 case 1:
34251- __asm__("lcall *(%%esi); cld\n\t"
34252+ __asm__("movw %w6, %%ds\n\t"
34253+ "lcall *%%ss:(%%esi); cld\n\t"
34254+ "push %%ss\n\t"
34255+ "pop %%ds\n\t"
34256 "jc 1f\n\t"
34257 "xor %%ah, %%ah\n"
34258 "1:"
34259@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34260 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34261 "b" (bx),
34262 "D" ((long)reg),
34263- "S" (&pci_indirect));
34264+ "S" (&pci_indirect),
34265+ "r" (__PCIBIOS_DS));
34266 /*
34267 * Zero-extend the result beyond 8 bits, do not trust the
34268 * BIOS having done it:
34269@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34270 *value &= 0xff;
34271 break;
34272 case 2:
34273- __asm__("lcall *(%%esi); cld\n\t"
34274+ __asm__("movw %w6, %%ds\n\t"
34275+ "lcall *%%ss:(%%esi); cld\n\t"
34276+ "push %%ss\n\t"
34277+ "pop %%ds\n\t"
34278 "jc 1f\n\t"
34279 "xor %%ah, %%ah\n"
34280 "1:"
34281@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34282 : "1" (PCIBIOS_READ_CONFIG_WORD),
34283 "b" (bx),
34284 "D" ((long)reg),
34285- "S" (&pci_indirect));
34286+ "S" (&pci_indirect),
34287+ "r" (__PCIBIOS_DS));
34288 /*
34289 * Zero-extend the result beyond 16 bits, do not trust the
34290 * BIOS having done it:
34291@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34292 *value &= 0xffff;
34293 break;
34294 case 4:
34295- __asm__("lcall *(%%esi); cld\n\t"
34296+ __asm__("movw %w6, %%ds\n\t"
34297+ "lcall *%%ss:(%%esi); cld\n\t"
34298+ "push %%ss\n\t"
34299+ "pop %%ds\n\t"
34300 "jc 1f\n\t"
34301 "xor %%ah, %%ah\n"
34302 "1:"
34303@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34304 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34305 "b" (bx),
34306 "D" ((long)reg),
34307- "S" (&pci_indirect));
34308+ "S" (&pci_indirect),
34309+ "r" (__PCIBIOS_DS));
34310 break;
34311 }
34312
34313@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34314
34315 switch (len) {
34316 case 1:
34317- __asm__("lcall *(%%esi); cld\n\t"
34318+ __asm__("movw %w6, %%ds\n\t"
34319+ "lcall *%%ss:(%%esi); cld\n\t"
34320+ "push %%ss\n\t"
34321+ "pop %%ds\n\t"
34322 "jc 1f\n\t"
34323 "xor %%ah, %%ah\n"
34324 "1:"
34325@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34326 "c" (value),
34327 "b" (bx),
34328 "D" ((long)reg),
34329- "S" (&pci_indirect));
34330+ "S" (&pci_indirect),
34331+ "r" (__PCIBIOS_DS));
34332 break;
34333 case 2:
34334- __asm__("lcall *(%%esi); cld\n\t"
34335+ __asm__("movw %w6, %%ds\n\t"
34336+ "lcall *%%ss:(%%esi); cld\n\t"
34337+ "push %%ss\n\t"
34338+ "pop %%ds\n\t"
34339 "jc 1f\n\t"
34340 "xor %%ah, %%ah\n"
34341 "1:"
34342@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34343 "c" (value),
34344 "b" (bx),
34345 "D" ((long)reg),
34346- "S" (&pci_indirect));
34347+ "S" (&pci_indirect),
34348+ "r" (__PCIBIOS_DS));
34349 break;
34350 case 4:
34351- __asm__("lcall *(%%esi); cld\n\t"
34352+ __asm__("movw %w6, %%ds\n\t"
34353+ "lcall *%%ss:(%%esi); cld\n\t"
34354+ "push %%ss\n\t"
34355+ "pop %%ds\n\t"
34356 "jc 1f\n\t"
34357 "xor %%ah, %%ah\n"
34358 "1:"
34359@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34360 "c" (value),
34361 "b" (bx),
34362 "D" ((long)reg),
34363- "S" (&pci_indirect));
34364+ "S" (&pci_indirect),
34365+ "r" (__PCIBIOS_DS));
34366 break;
34367 }
34368
34369@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34370
34371 DBG("PCI: Fetching IRQ routing table... ");
34372 __asm__("push %%es\n\t"
34373+ "movw %w8, %%ds\n\t"
34374 "push %%ds\n\t"
34375 "pop %%es\n\t"
34376- "lcall *(%%esi); cld\n\t"
34377+ "lcall *%%ss:(%%esi); cld\n\t"
34378 "pop %%es\n\t"
34379+ "push %%ss\n\t"
34380+ "pop %%ds\n"
34381 "jc 1f\n\t"
34382 "xor %%ah, %%ah\n"
34383 "1:"
34384@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34385 "1" (0),
34386 "D" ((long) &opt),
34387 "S" (&pci_indirect),
34388- "m" (opt)
34389+ "m" (opt),
34390+ "r" (__PCIBIOS_DS)
34391 : "memory");
34392 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34393 if (ret & 0xff00)
34394@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34395 {
34396 int ret;
34397
34398- __asm__("lcall *(%%esi); cld\n\t"
34399+ __asm__("movw %w5, %%ds\n\t"
34400+ "lcall *%%ss:(%%esi); cld\n\t"
34401+ "push %%ss\n\t"
34402+ "pop %%ds\n"
34403 "jc 1f\n\t"
34404 "xor %%ah, %%ah\n"
34405 "1:"
34406@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34407 : "0" (PCIBIOS_SET_PCI_HW_INT),
34408 "b" ((dev->bus->number << 8) | dev->devfn),
34409 "c" ((irq << 8) | (pin + 10)),
34410- "S" (&pci_indirect));
34411+ "S" (&pci_indirect),
34412+ "r" (__PCIBIOS_DS));
34413 return !(ret & 0xff00);
34414 }
34415 EXPORT_SYMBOL(pcibios_set_irq_routing);
34416diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34417index 9ee3491..872192f 100644
34418--- a/arch/x86/platform/efi/efi_32.c
34419+++ b/arch/x86/platform/efi/efi_32.c
34420@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34421 {
34422 struct desc_ptr gdt_descr;
34423
34424+#ifdef CONFIG_PAX_KERNEXEC
34425+ struct desc_struct d;
34426+#endif
34427+
34428 local_irq_save(efi_rt_eflags);
34429
34430 load_cr3(initial_page_table);
34431 __flush_tlb_all();
34432
34433+#ifdef CONFIG_PAX_KERNEXEC
34434+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34435+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34436+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34437+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34438+#endif
34439+
34440 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34441 gdt_descr.size = GDT_SIZE - 1;
34442 load_gdt(&gdt_descr);
34443@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34444 {
34445 struct desc_ptr gdt_descr;
34446
34447+#ifdef CONFIG_PAX_KERNEXEC
34448+ struct desc_struct d;
34449+
34450+ memset(&d, 0, sizeof d);
34451+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34452+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34453+#endif
34454+
34455 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34456 gdt_descr.size = GDT_SIZE - 1;
34457 load_gdt(&gdt_descr);
34458
34459+#ifdef CONFIG_PAX_PER_CPU_PGD
34460+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34461+#else
34462 load_cr3(swapper_pg_dir);
34463+#endif
34464+
34465 __flush_tlb_all();
34466
34467 local_irq_restore(efi_rt_eflags);
34468diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34469index 666b74a..673d88f 100644
34470--- a/arch/x86/platform/efi/efi_64.c
34471+++ b/arch/x86/platform/efi/efi_64.c
34472@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34473 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34474 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34475 }
34476+
34477+#ifdef CONFIG_PAX_PER_CPU_PGD
34478+ load_cr3(swapper_pg_dir);
34479+#endif
34480+
34481 __flush_tlb_all();
34482 }
34483
34484@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34485 for (pgd = 0; pgd < n_pgds; pgd++)
34486 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34487 kfree(save_pgd);
34488+
34489+#ifdef CONFIG_PAX_PER_CPU_PGD
34490+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34491+#endif
34492+
34493 __flush_tlb_all();
34494 local_irq_restore(efi_flags);
34495 early_code_mapping_set_exec(0);
34496diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34497index fbe66e6..eae5e38 100644
34498--- a/arch/x86/platform/efi/efi_stub_32.S
34499+++ b/arch/x86/platform/efi/efi_stub_32.S
34500@@ -6,7 +6,9 @@
34501 */
34502
34503 #include <linux/linkage.h>
34504+#include <linux/init.h>
34505 #include <asm/page_types.h>
34506+#include <asm/segment.h>
34507
34508 /*
34509 * efi_call_phys(void *, ...) is a function with variable parameters.
34510@@ -20,7 +22,7 @@
34511 * service functions will comply with gcc calling convention, too.
34512 */
34513
34514-.text
34515+__INIT
34516 ENTRY(efi_call_phys)
34517 /*
34518 * 0. The function can only be called in Linux kernel. So CS has been
34519@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34520 * The mapping of lower virtual memory has been created in prelog and
34521 * epilog.
34522 */
34523- movl $1f, %edx
34524- subl $__PAGE_OFFSET, %edx
34525- jmp *%edx
34526+#ifdef CONFIG_PAX_KERNEXEC
34527+ movl $(__KERNEXEC_EFI_DS), %edx
34528+ mov %edx, %ds
34529+ mov %edx, %es
34530+ mov %edx, %ss
34531+ addl $2f,(1f)
34532+ ljmp *(1f)
34533+
34534+__INITDATA
34535+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34536+.previous
34537+
34538+2:
34539+ subl $2b,(1b)
34540+#else
34541+ jmp 1f-__PAGE_OFFSET
34542 1:
34543+#endif
34544
34545 /*
34546 * 2. Now on the top of stack is the return
34547@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34548 * parameter 2, ..., param n. To make things easy, we save the return
34549 * address of efi_call_phys in a global variable.
34550 */
34551- popl %edx
34552- movl %edx, saved_return_addr
34553- /* get the function pointer into ECX*/
34554- popl %ecx
34555- movl %ecx, efi_rt_function_ptr
34556- movl $2f, %edx
34557- subl $__PAGE_OFFSET, %edx
34558- pushl %edx
34559+ popl (saved_return_addr)
34560+ popl (efi_rt_function_ptr)
34561
34562 /*
34563 * 3. Clear PG bit in %CR0.
34564@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34565 /*
34566 * 5. Call the physical function.
34567 */
34568- jmp *%ecx
34569+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34570
34571-2:
34572 /*
34573 * 6. After EFI runtime service returns, control will return to
34574 * following instruction. We'd better readjust stack pointer first.
34575@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34576 movl %cr0, %edx
34577 orl $0x80000000, %edx
34578 movl %edx, %cr0
34579- jmp 1f
34580-1:
34581+
34582 /*
34583 * 8. Now restore the virtual mode from flat mode by
34584 * adding EIP with PAGE_OFFSET.
34585 */
34586- movl $1f, %edx
34587- jmp *%edx
34588+#ifdef CONFIG_PAX_KERNEXEC
34589+ movl $(__KERNEL_DS), %edx
34590+ mov %edx, %ds
34591+ mov %edx, %es
34592+ mov %edx, %ss
34593+ ljmp $(__KERNEL_CS),$1f
34594+#else
34595+ jmp 1f+__PAGE_OFFSET
34596+#endif
34597 1:
34598
34599 /*
34600 * 9. Balance the stack. And because EAX contain the return value,
34601 * we'd better not clobber it.
34602 */
34603- leal efi_rt_function_ptr, %edx
34604- movl (%edx), %ecx
34605- pushl %ecx
34606+ pushl (efi_rt_function_ptr)
34607
34608 /*
34609- * 10. Push the saved return address onto the stack and return.
34610+ * 10. Return to the saved return address.
34611 */
34612- leal saved_return_addr, %edx
34613- movl (%edx), %ecx
34614- pushl %ecx
34615- ret
34616+ jmpl *(saved_return_addr)
34617 ENDPROC(efi_call_phys)
34618 .previous
34619
34620-.data
34621+__INITDATA
34622 saved_return_addr:
34623 .long 0
34624 efi_rt_function_ptr:
34625diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34626index 88073b1..1cc2f53 100644
34627--- a/arch/x86/platform/efi/efi_stub_64.S
34628+++ b/arch/x86/platform/efi/efi_stub_64.S
34629@@ -7,6 +7,7 @@
34630 */
34631
34632 #include <linux/linkage.h>
34633+#include <asm/alternative-asm.h>
34634
34635 #define SAVE_XMM \
34636 mov %rsp, %rax; \
34637@@ -77,6 +78,7 @@ ENTRY(efi_call0)
34638 RESTORE_PGT
34639 addq $32, %rsp
34640 RESTORE_XMM
34641+ pax_force_retaddr 0, 1
34642 ret
34643 ENDPROC(efi_call0)
34644
34645@@ -89,6 +91,7 @@ ENTRY(efi_call1)
34646 RESTORE_PGT
34647 addq $32, %rsp
34648 RESTORE_XMM
34649+ pax_force_retaddr 0, 1
34650 ret
34651 ENDPROC(efi_call1)
34652
34653@@ -101,6 +104,7 @@ ENTRY(efi_call2)
34654 RESTORE_PGT
34655 addq $32, %rsp
34656 RESTORE_XMM
34657+ pax_force_retaddr 0, 1
34658 ret
34659 ENDPROC(efi_call2)
34660
34661@@ -114,6 +118,7 @@ ENTRY(efi_call3)
34662 RESTORE_PGT
34663 addq $32, %rsp
34664 RESTORE_XMM
34665+ pax_force_retaddr 0, 1
34666 ret
34667 ENDPROC(efi_call3)
34668
34669@@ -128,6 +133,7 @@ ENTRY(efi_call4)
34670 RESTORE_PGT
34671 addq $32, %rsp
34672 RESTORE_XMM
34673+ pax_force_retaddr 0, 1
34674 ret
34675 ENDPROC(efi_call4)
34676
34677@@ -143,6 +149,7 @@ ENTRY(efi_call5)
34678 RESTORE_PGT
34679 addq $48, %rsp
34680 RESTORE_XMM
34681+ pax_force_retaddr 0, 1
34682 ret
34683 ENDPROC(efi_call5)
34684
34685@@ -161,6 +168,7 @@ ENTRY(efi_call6)
34686 RESTORE_PGT
34687 addq $48, %rsp
34688 RESTORE_XMM
34689+ pax_force_retaddr 0, 1
34690 ret
34691 ENDPROC(efi_call6)
34692
34693diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34694index 1bbedc4..eb795b5 100644
34695--- a/arch/x86/platform/intel-mid/intel-mid.c
34696+++ b/arch/x86/platform/intel-mid/intel-mid.c
34697@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34698 {
34699 };
34700
34701-static void intel_mid_reboot(void)
34702+static void __noreturn intel_mid_reboot(void)
34703 {
34704 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34705+ BUG();
34706 }
34707
34708 static unsigned long __init intel_mid_calibrate_tsc(void)
34709diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34710index d6ee929..3637cb5 100644
34711--- a/arch/x86/platform/olpc/olpc_dt.c
34712+++ b/arch/x86/platform/olpc/olpc_dt.c
34713@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34714 return res;
34715 }
34716
34717-static struct of_pdt_ops prom_olpc_ops __initdata = {
34718+static struct of_pdt_ops prom_olpc_ops __initconst = {
34719 .nextprop = olpc_dt_nextprop,
34720 .getproplen = olpc_dt_getproplen,
34721 .getproperty = olpc_dt_getproperty,
34722diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34723index 424f4c9..f2a2988 100644
34724--- a/arch/x86/power/cpu.c
34725+++ b/arch/x86/power/cpu.c
34726@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34727 static void fix_processor_context(void)
34728 {
34729 int cpu = smp_processor_id();
34730- struct tss_struct *t = &per_cpu(init_tss, cpu);
34731-#ifdef CONFIG_X86_64
34732- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34733- tss_desc tss;
34734-#endif
34735+ struct tss_struct *t = init_tss + cpu;
34736+
34737 set_tss_desc(cpu, t); /*
34738 * This just modifies memory; should not be
34739 * necessary. But... This is necessary, because
34740@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34741 */
34742
34743 #ifdef CONFIG_X86_64
34744- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34745- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34746- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34747-
34748 syscall_init(); /* This sets MSR_*STAR and related */
34749 #endif
34750 load_TR_desc(); /* This does ltr */
34751diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34752index bad628a..a102610 100644
34753--- a/arch/x86/realmode/init.c
34754+++ b/arch/x86/realmode/init.c
34755@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34756 __va(real_mode_header->trampoline_header);
34757
34758 #ifdef CONFIG_X86_32
34759- trampoline_header->start = __pa_symbol(startup_32_smp);
34760+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34761+
34762+#ifdef CONFIG_PAX_KERNEXEC
34763+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34764+#endif
34765+
34766+ trampoline_header->boot_cs = __BOOT_CS;
34767 trampoline_header->gdt_limit = __BOOT_DS + 7;
34768 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34769 #else
34770@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34771 *trampoline_cr4_features = read_cr4();
34772
34773 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34774- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34775+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34776 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34777 #endif
34778 }
34779diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34780index 3497f14..cc73b92 100644
34781--- a/arch/x86/realmode/rm/Makefile
34782+++ b/arch/x86/realmode/rm/Makefile
34783@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34784
34785 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34786 -I$(srctree)/arch/x86/boot
34787+ifdef CONSTIFY_PLUGIN
34788+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34789+endif
34790 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34791 GCOV_PROFILE := n
34792diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34793index a28221d..93c40f1 100644
34794--- a/arch/x86/realmode/rm/header.S
34795+++ b/arch/x86/realmode/rm/header.S
34796@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34797 #endif
34798 /* APM/BIOS reboot */
34799 .long pa_machine_real_restart_asm
34800-#ifdef CONFIG_X86_64
34801+#ifdef CONFIG_X86_32
34802+ .long __KERNEL_CS
34803+#else
34804 .long __KERNEL32_CS
34805 #endif
34806 END(real_mode_header)
34807diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34808index 48ddd76..c26749f 100644
34809--- a/arch/x86/realmode/rm/trampoline_32.S
34810+++ b/arch/x86/realmode/rm/trampoline_32.S
34811@@ -24,6 +24,12 @@
34812 #include <asm/page_types.h>
34813 #include "realmode.h"
34814
34815+#ifdef CONFIG_PAX_KERNEXEC
34816+#define ta(X) (X)
34817+#else
34818+#define ta(X) (pa_ ## X)
34819+#endif
34820+
34821 .text
34822 .code16
34823
34824@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34825
34826 cli # We should be safe anyway
34827
34828- movl tr_start, %eax # where we need to go
34829-
34830 movl $0xA5A5A5A5, trampoline_status
34831 # write marker for master knows we're running
34832
34833@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34834 movw $1, %dx # protected mode (PE) bit
34835 lmsw %dx # into protected mode
34836
34837- ljmpl $__BOOT_CS, $pa_startup_32
34838+ ljmpl *(trampoline_header)
34839
34840 .section ".text32","ax"
34841 .code32
34842@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34843 .balign 8
34844 GLOBAL(trampoline_header)
34845 tr_start: .space 4
34846- tr_gdt_pad: .space 2
34847+ tr_boot_cs: .space 2
34848 tr_gdt: .space 6
34849 END(trampoline_header)
34850
34851diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34852index dac7b20..72dbaca 100644
34853--- a/arch/x86/realmode/rm/trampoline_64.S
34854+++ b/arch/x86/realmode/rm/trampoline_64.S
34855@@ -93,6 +93,7 @@ ENTRY(startup_32)
34856 movl %edx, %gs
34857
34858 movl pa_tr_cr4, %eax
34859+ andl $~X86_CR4_PCIDE, %eax
34860 movl %eax, %cr4 # Enable PAE mode
34861
34862 # Setup trampoline 4 level pagetables
34863@@ -106,7 +107,7 @@ ENTRY(startup_32)
34864 wrmsr
34865
34866 # Enable paging and in turn activate Long Mode
34867- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34868+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34869 movl %eax, %cr0
34870
34871 /*
34872diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34873index e812034..c747134 100644
34874--- a/arch/x86/tools/Makefile
34875+++ b/arch/x86/tools/Makefile
34876@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34877
34878 $(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
34879
34880-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34881+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34882 hostprogs-y += relocs
34883 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34884 relocs: $(obj)/relocs
34885diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34886index cfbdbdb..1aa763c 100644
34887--- a/arch/x86/tools/relocs.c
34888+++ b/arch/x86/tools/relocs.c
34889@@ -1,5 +1,7 @@
34890 /* This is included from relocs_32/64.c */
34891
34892+#include "../../../include/generated/autoconf.h"
34893+
34894 #define ElfW(type) _ElfW(ELF_BITS, type)
34895 #define _ElfW(bits, type) __ElfW(bits, type)
34896 #define __ElfW(bits, type) Elf##bits##_##type
34897@@ -11,6 +13,7 @@
34898 #define Elf_Sym ElfW(Sym)
34899
34900 static Elf_Ehdr ehdr;
34901+static Elf_Phdr *phdr;
34902
34903 struct relocs {
34904 uint32_t *offset;
34905@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34906 }
34907 }
34908
34909+static void read_phdrs(FILE *fp)
34910+{
34911+ unsigned int i;
34912+
34913+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34914+ if (!phdr) {
34915+ die("Unable to allocate %d program headers\n",
34916+ ehdr.e_phnum);
34917+ }
34918+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34919+ die("Seek to %d failed: %s\n",
34920+ ehdr.e_phoff, strerror(errno));
34921+ }
34922+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34923+ die("Cannot read ELF program headers: %s\n",
34924+ strerror(errno));
34925+ }
34926+ for(i = 0; i < ehdr.e_phnum; i++) {
34927+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34928+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34929+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34930+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34931+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34932+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34933+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34934+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34935+ }
34936+
34937+}
34938+
34939 static void read_shdrs(FILE *fp)
34940 {
34941- int i;
34942+ unsigned int i;
34943 Elf_Shdr shdr;
34944
34945 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34946@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34947
34948 static void read_strtabs(FILE *fp)
34949 {
34950- int i;
34951+ unsigned int i;
34952 for (i = 0; i < ehdr.e_shnum; i++) {
34953 struct section *sec = &secs[i];
34954 if (sec->shdr.sh_type != SHT_STRTAB) {
34955@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34956
34957 static void read_symtabs(FILE *fp)
34958 {
34959- int i,j;
34960+ unsigned int i,j;
34961 for (i = 0; i < ehdr.e_shnum; i++) {
34962 struct section *sec = &secs[i];
34963 if (sec->shdr.sh_type != SHT_SYMTAB) {
34964@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34965 }
34966
34967
34968-static void read_relocs(FILE *fp)
34969+static void read_relocs(FILE *fp, int use_real_mode)
34970 {
34971- int i,j;
34972+ unsigned int i,j;
34973+ uint32_t base;
34974+
34975 for (i = 0; i < ehdr.e_shnum; i++) {
34976 struct section *sec = &secs[i];
34977 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34978@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34979 die("Cannot read symbol table: %s\n",
34980 strerror(errno));
34981 }
34982+ base = 0;
34983+
34984+#ifdef CONFIG_X86_32
34985+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34986+ if (phdr[j].p_type != PT_LOAD )
34987+ continue;
34988+ 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)
34989+ continue;
34990+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34991+ break;
34992+ }
34993+#endif
34994+
34995 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34996 Elf_Rel *rel = &sec->reltab[j];
34997- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34998+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34999 rel->r_info = elf_xword_to_cpu(rel->r_info);
35000 #if (SHT_REL_TYPE == SHT_RELA)
35001 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35002@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35003
35004 static void print_absolute_symbols(void)
35005 {
35006- int i;
35007+ unsigned int i;
35008 const char *format;
35009
35010 if (ELF_BITS == 64)
35011@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35012 for (i = 0; i < ehdr.e_shnum; i++) {
35013 struct section *sec = &secs[i];
35014 char *sym_strtab;
35015- int j;
35016+ unsigned int j;
35017
35018 if (sec->shdr.sh_type != SHT_SYMTAB) {
35019 continue;
35020@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35021
35022 static void print_absolute_relocs(void)
35023 {
35024- int i, printed = 0;
35025+ unsigned int i, printed = 0;
35026 const char *format;
35027
35028 if (ELF_BITS == 64)
35029@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35030 struct section *sec_applies, *sec_symtab;
35031 char *sym_strtab;
35032 Elf_Sym *sh_symtab;
35033- int j;
35034+ unsigned int j;
35035 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35036 continue;
35037 }
35038@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35039 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35040 Elf_Sym *sym, const char *symname))
35041 {
35042- int i;
35043+ unsigned int i;
35044 /* Walk through the relocations */
35045 for (i = 0; i < ehdr.e_shnum; i++) {
35046 char *sym_strtab;
35047 Elf_Sym *sh_symtab;
35048 struct section *sec_applies, *sec_symtab;
35049- int j;
35050+ unsigned int j;
35051 struct section *sec = &secs[i];
35052
35053 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35054@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35055 {
35056 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35057 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35058+ char *sym_strtab = sec->link->link->strtab;
35059+
35060+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35061+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35062+ return 0;
35063+
35064+#ifdef CONFIG_PAX_KERNEXEC
35065+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35066+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35067+ return 0;
35068+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35069+ return 0;
35070+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35071+ return 0;
35072+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35073+ return 0;
35074+#endif
35075
35076 switch (r_type) {
35077 case R_386_NONE:
35078@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35079
35080 static void emit_relocs(int as_text, int use_real_mode)
35081 {
35082- int i;
35083+ unsigned int i;
35084 int (*write_reloc)(uint32_t, FILE *) = write32;
35085 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35086 const char *symname);
35087@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35088 {
35089 regex_init(use_real_mode);
35090 read_ehdr(fp);
35091+ read_phdrs(fp);
35092 read_shdrs(fp);
35093 read_strtabs(fp);
35094 read_symtabs(fp);
35095- read_relocs(fp);
35096+ read_relocs(fp, use_real_mode);
35097 if (ELF_BITS == 64)
35098 percpu_init();
35099 if (show_absolute_syms) {
35100diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35101index 80ffa5b..a33bd15 100644
35102--- a/arch/x86/um/tls_32.c
35103+++ b/arch/x86/um/tls_32.c
35104@@ -260,7 +260,7 @@ out:
35105 if (unlikely(task == current &&
35106 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35107 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35108- "without flushed TLS.", current->pid);
35109+ "without flushed TLS.", task_pid_nr(current));
35110 }
35111
35112 return 0;
35113diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35114index fd14be1..e3c79c0 100644
35115--- a/arch/x86/vdso/Makefile
35116+++ b/arch/x86/vdso/Makefile
35117@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35118 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35119 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35120
35121-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35122+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35123 GCOV_PROFILE := n
35124
35125 #
35126diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35127index d6bfb87..876ee18 100644
35128--- a/arch/x86/vdso/vdso32-setup.c
35129+++ b/arch/x86/vdso/vdso32-setup.c
35130@@ -25,6 +25,7 @@
35131 #include <asm/tlbflush.h>
35132 #include <asm/vdso.h>
35133 #include <asm/proto.h>
35134+#include <asm/mman.h>
35135
35136 enum {
35137 VDSO_DISABLED = 0,
35138@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35139 void enable_sep_cpu(void)
35140 {
35141 int cpu = get_cpu();
35142- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35143+ struct tss_struct *tss = init_tss + cpu;
35144
35145 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35146 put_cpu();
35147@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35148 gate_vma.vm_start = FIXADDR_USER_START;
35149 gate_vma.vm_end = FIXADDR_USER_END;
35150 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35151- gate_vma.vm_page_prot = __P101;
35152+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35153
35154 return 0;
35155 }
35156@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35157 if (compat)
35158 addr = VDSO_HIGH_BASE;
35159 else {
35160- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35161+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35162 if (IS_ERR_VALUE(addr)) {
35163 ret = addr;
35164 goto up_fail;
35165 }
35166 }
35167
35168- current->mm->context.vdso = (void *)addr;
35169+ current->mm->context.vdso = addr;
35170
35171 if (compat_uses_vma || !compat) {
35172 /*
35173@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35174 }
35175
35176 current_thread_info()->sysenter_return =
35177- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35178+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35179
35180 up_fail:
35181 if (ret)
35182- current->mm->context.vdso = NULL;
35183+ current->mm->context.vdso = 0;
35184
35185 up_write(&mm->mmap_sem);
35186
35187@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35188
35189 const char *arch_vma_name(struct vm_area_struct *vma)
35190 {
35191- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35192+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35193 return "[vdso]";
35194+
35195+#ifdef CONFIG_PAX_SEGMEXEC
35196+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35197+ return "[vdso]";
35198+#endif
35199+
35200 return NULL;
35201 }
35202
35203@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35204 * Check to see if the corresponding task was created in compat vdso
35205 * mode.
35206 */
35207- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35208+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35209 return &gate_vma;
35210 return NULL;
35211 }
35212diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35213index 431e875..cbb23f3 100644
35214--- a/arch/x86/vdso/vma.c
35215+++ b/arch/x86/vdso/vma.c
35216@@ -16,8 +16,6 @@
35217 #include <asm/vdso.h>
35218 #include <asm/page.h>
35219
35220-unsigned int __read_mostly vdso_enabled = 1;
35221-
35222 extern char vdso_start[], vdso_end[];
35223 extern unsigned short vdso_sync_cpuid;
35224
35225@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35226 * unaligned here as a result of stack start randomization.
35227 */
35228 addr = PAGE_ALIGN(addr);
35229- addr = align_vdso_addr(addr);
35230
35231 return addr;
35232 }
35233@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35234 unsigned size)
35235 {
35236 struct mm_struct *mm = current->mm;
35237- unsigned long addr;
35238+ unsigned long addr = 0;
35239 int ret;
35240
35241- if (!vdso_enabled)
35242- return 0;
35243-
35244 down_write(&mm->mmap_sem);
35245+
35246+#ifdef CONFIG_PAX_RANDMMAP
35247+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35248+#endif
35249+
35250 addr = vdso_addr(mm->start_stack, size);
35251+ addr = align_vdso_addr(addr);
35252 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35253 if (IS_ERR_VALUE(addr)) {
35254 ret = addr;
35255 goto up_fail;
35256 }
35257
35258- current->mm->context.vdso = (void *)addr;
35259+ mm->context.vdso = addr;
35260
35261 ret = install_special_mapping(mm, addr, size,
35262 VM_READ|VM_EXEC|
35263 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35264 pages);
35265- if (ret) {
35266- current->mm->context.vdso = NULL;
35267- goto up_fail;
35268- }
35269+ if (ret)
35270+ mm->context.vdso = 0;
35271
35272 up_fail:
35273 up_write(&mm->mmap_sem);
35274@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35275 vdsox32_size);
35276 }
35277 #endif
35278-
35279-static __init int vdso_setup(char *s)
35280-{
35281- vdso_enabled = simple_strtoul(s, NULL, 0);
35282- return 0;
35283-}
35284-__setup("vdso=", vdso_setup);
35285diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35286index 01b9026..1e476df 100644
35287--- a/arch/x86/xen/Kconfig
35288+++ b/arch/x86/xen/Kconfig
35289@@ -9,6 +9,7 @@ config XEN
35290 select XEN_HAVE_PVMMU
35291 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35292 depends on X86_TSC
35293+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35294 help
35295 This is the Linux Xen port. Enabling this will allow the
35296 kernel to boot in a paravirtualized environment under the
35297diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35298index 201d09a..e4723e5 100644
35299--- a/arch/x86/xen/enlighten.c
35300+++ b/arch/x86/xen/enlighten.c
35301@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35302
35303 struct shared_info xen_dummy_shared_info;
35304
35305-void *xen_initial_gdt;
35306-
35307 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35308 __read_mostly int xen_have_vector_callback;
35309 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35310@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35311 {
35312 unsigned long va = dtr->address;
35313 unsigned int size = dtr->size + 1;
35314- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35315- unsigned long frames[pages];
35316+ unsigned long frames[65536 / PAGE_SIZE];
35317 int f;
35318
35319 /*
35320@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35321 {
35322 unsigned long va = dtr->address;
35323 unsigned int size = dtr->size + 1;
35324- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35325- unsigned long frames[pages];
35326+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35327 int f;
35328
35329 /*
35330@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35331 * 8-byte entries, or 16 4k pages..
35332 */
35333
35334- BUG_ON(size > 65536);
35335+ BUG_ON(size > GDT_SIZE);
35336 BUG_ON(va & ~PAGE_MASK);
35337
35338 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35339@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35340 return 0;
35341 }
35342
35343-static void set_xen_basic_apic_ops(void)
35344+static void __init set_xen_basic_apic_ops(void)
35345 {
35346 apic->read = xen_apic_read;
35347 apic->write = xen_apic_write;
35348@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35349 #endif
35350 };
35351
35352-static void xen_reboot(int reason)
35353+static __noreturn void xen_reboot(int reason)
35354 {
35355 struct sched_shutdown r = { .reason = reason };
35356
35357- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35358- BUG();
35359+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35360+ BUG();
35361 }
35362
35363-static void xen_restart(char *msg)
35364+static __noreturn void xen_restart(char *msg)
35365 {
35366 xen_reboot(SHUTDOWN_reboot);
35367 }
35368
35369-static void xen_emergency_restart(void)
35370+static __noreturn void xen_emergency_restart(void)
35371 {
35372 xen_reboot(SHUTDOWN_reboot);
35373 }
35374
35375-static void xen_machine_halt(void)
35376+static __noreturn void xen_machine_halt(void)
35377 {
35378 xen_reboot(SHUTDOWN_poweroff);
35379 }
35380
35381-static void xen_machine_power_off(void)
35382+static __noreturn void xen_machine_power_off(void)
35383 {
35384 if (pm_power_off)
35385 pm_power_off();
35386@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35387 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35388
35389 /* Work out if we support NX */
35390- x86_configure_nx();
35391+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35392+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35393+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35394+ unsigned l, h;
35395+
35396+ __supported_pte_mask |= _PAGE_NX;
35397+ rdmsr(MSR_EFER, l, h);
35398+ l |= EFER_NX;
35399+ wrmsr(MSR_EFER, l, h);
35400+ }
35401+#endif
35402
35403 /* Get mfn list */
35404 xen_build_dynamic_phys_to_machine();
35405@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35406
35407 machine_ops = xen_machine_ops;
35408
35409- /*
35410- * The only reliable way to retain the initial address of the
35411- * percpu gdt_page is to remember it here, so we can go and
35412- * mark it RW later, when the initial percpu area is freed.
35413- */
35414- xen_initial_gdt = &per_cpu(gdt_page, 0);
35415-
35416 xen_smp_init();
35417
35418 #ifdef CONFIG_ACPI_NUMA
35419diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35420index 2423ef0..4f6fb5b 100644
35421--- a/arch/x86/xen/mmu.c
35422+++ b/arch/x86/xen/mmu.c
35423@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35424 return val;
35425 }
35426
35427-static pteval_t pte_pfn_to_mfn(pteval_t val)
35428+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35429 {
35430 if (val & _PAGE_PRESENT) {
35431 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35432@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35433 /* L3_k[510] -> level2_kernel_pgt
35434 * L3_i[511] -> level2_fixmap_pgt */
35435 convert_pfn_mfn(level3_kernel_pgt);
35436+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35437+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35438+ convert_pfn_mfn(level3_vmemmap_pgt);
35439 }
35440 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35441 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35442@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35443 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35444 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35445 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35446+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35447+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35448+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35449 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35450 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35451+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35452 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35453 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35454
35455@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35456 pv_mmu_ops.set_pud = xen_set_pud;
35457 #if PAGETABLE_LEVELS == 4
35458 pv_mmu_ops.set_pgd = xen_set_pgd;
35459+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35460 #endif
35461
35462 /* This will work as long as patching hasn't happened yet
35463@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35464 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35465 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35466 .set_pgd = xen_set_pgd_hyper,
35467+ .set_pgd_batched = xen_set_pgd_hyper,
35468
35469 .alloc_pud = xen_alloc_pmd_init,
35470 .release_pud = xen_release_pmd_init,
35471diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35472index a18eadd..2e2f10e 100644
35473--- a/arch/x86/xen/smp.c
35474+++ b/arch/x86/xen/smp.c
35475@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35476
35477 if (xen_pv_domain()) {
35478 if (!xen_feature(XENFEAT_writable_page_tables))
35479- /* We've switched to the "real" per-cpu gdt, so make
35480- * sure the old memory can be recycled. */
35481- make_lowmem_page_readwrite(xen_initial_gdt);
35482-
35483 #ifdef CONFIG_X86_32
35484 /*
35485 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35486 * expects __USER_DS
35487 */
35488- loadsegment(ds, __USER_DS);
35489- loadsegment(es, __USER_DS);
35490+ loadsegment(ds, __KERNEL_DS);
35491+ loadsegment(es, __KERNEL_DS);
35492 #endif
35493
35494 xen_filter_cpu_maps();
35495@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35496 #ifdef CONFIG_X86_32
35497 /* Note: PVH is not yet supported on x86_32. */
35498 ctxt->user_regs.fs = __KERNEL_PERCPU;
35499- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35500+ savesegment(gs, ctxt->user_regs.gs);
35501 #endif
35502 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35503
35504@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35505 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35506 ctxt->flags = VGCF_IN_KERNEL;
35507 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35508- ctxt->user_regs.ds = __USER_DS;
35509- ctxt->user_regs.es = __USER_DS;
35510+ ctxt->user_regs.ds = __KERNEL_DS;
35511+ ctxt->user_regs.es = __KERNEL_DS;
35512 ctxt->user_regs.ss = __KERNEL_DS;
35513
35514 xen_copy_trap_info(ctxt->trap_ctxt);
35515@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35516 int rc;
35517
35518 per_cpu(current_task, cpu) = idle;
35519+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35520 #ifdef CONFIG_X86_32
35521 irq_ctx_init(cpu);
35522 #else
35523 clear_tsk_thread_flag(idle, TIF_FORK);
35524- per_cpu(kernel_stack, cpu) =
35525- (unsigned long)task_stack_page(idle) -
35526- KERNEL_STACK_OFFSET + THREAD_SIZE;
35527+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35528 #endif
35529 xen_setup_runstate_info(cpu);
35530 xen_setup_timer(cpu);
35531@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35532
35533 void __init xen_smp_init(void)
35534 {
35535- smp_ops = xen_smp_ops;
35536+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35537 xen_fill_possible_map();
35538 }
35539
35540diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35541index 33ca6e4..0ded929 100644
35542--- a/arch/x86/xen/xen-asm_32.S
35543+++ b/arch/x86/xen/xen-asm_32.S
35544@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35545 ESP_OFFSET=4 # bytes pushed onto stack
35546
35547 /*
35548- * Store vcpu_info pointer for easy access. Do it this way to
35549- * avoid having to reload %fs
35550+ * Store vcpu_info pointer for easy access.
35551 */
35552 #ifdef CONFIG_SMP
35553- GET_THREAD_INFO(%eax)
35554- movl %ss:TI_cpu(%eax), %eax
35555- movl %ss:__per_cpu_offset(,%eax,4), %eax
35556- mov %ss:xen_vcpu(%eax), %eax
35557+ push %fs
35558+ mov $(__KERNEL_PERCPU), %eax
35559+ mov %eax, %fs
35560+ mov PER_CPU_VAR(xen_vcpu), %eax
35561+ pop %fs
35562 #else
35563 movl %ss:xen_vcpu, %eax
35564 #endif
35565diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35566index 485b695..fda3e7c 100644
35567--- a/arch/x86/xen/xen-head.S
35568+++ b/arch/x86/xen/xen-head.S
35569@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35570 #ifdef CONFIG_X86_32
35571 mov %esi,xen_start_info
35572 mov $init_thread_union+THREAD_SIZE,%esp
35573+#ifdef CONFIG_SMP
35574+ movl $cpu_gdt_table,%edi
35575+ movl $__per_cpu_load,%eax
35576+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35577+ rorl $16,%eax
35578+ movb %al,__KERNEL_PERCPU + 4(%edi)
35579+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35580+ movl $__per_cpu_end - 1,%eax
35581+ subl $__per_cpu_start,%eax
35582+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35583+#endif
35584 #else
35585 mov %rsi,xen_start_info
35586 mov $init_thread_union+THREAD_SIZE,%rsp
35587diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35588index 1cb6f4c..9981524 100644
35589--- a/arch/x86/xen/xen-ops.h
35590+++ b/arch/x86/xen/xen-ops.h
35591@@ -10,8 +10,6 @@
35592 extern const char xen_hypervisor_callback[];
35593 extern const char xen_failsafe_callback[];
35594
35595-extern void *xen_initial_gdt;
35596-
35597 struct trap_info;
35598 void xen_copy_trap_info(struct trap_info *traps);
35599
35600diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35601index 525bd3d..ef888b1 100644
35602--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35603+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35604@@ -119,9 +119,9 @@
35605 ----------------------------------------------------------------------*/
35606
35607 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35608-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35609 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35610 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35611+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35612
35613 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35614 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35615diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35616index 2f33760..835e50a 100644
35617--- a/arch/xtensa/variants/fsf/include/variant/core.h
35618+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35619@@ -11,6 +11,7 @@
35620 #ifndef _XTENSA_CORE_H
35621 #define _XTENSA_CORE_H
35622
35623+#include <linux/const.h>
35624
35625 /****************************************************************************
35626 Parameters Useful for Any Code, USER or PRIVILEGED
35627@@ -112,9 +113,9 @@
35628 ----------------------------------------------------------------------*/
35629
35630 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35631-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35632 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35633 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35634+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35635
35636 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35637 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35638diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35639index af00795..2bb8105 100644
35640--- a/arch/xtensa/variants/s6000/include/variant/core.h
35641+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35642@@ -11,6 +11,7 @@
35643 #ifndef _XTENSA_CORE_CONFIGURATION_H
35644 #define _XTENSA_CORE_CONFIGURATION_H
35645
35646+#include <linux/const.h>
35647
35648 /****************************************************************************
35649 Parameters Useful for Any Code, USER or PRIVILEGED
35650@@ -118,9 +119,9 @@
35651 ----------------------------------------------------------------------*/
35652
35653 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35654-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35655 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35656 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35657+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35658
35659 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35660 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35661diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35662index 4e491d9..c8e18e4 100644
35663--- a/block/blk-cgroup.c
35664+++ b/block/blk-cgroup.c
35665@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35666 static struct cgroup_subsys_state *
35667 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35668 {
35669- static atomic64_t id_seq = ATOMIC64_INIT(0);
35670+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35671 struct blkcg *blkcg;
35672
35673 if (!parent_css) {
35674@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35675
35676 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35677 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35678- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35679+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35680 done:
35681 spin_lock_init(&blkcg->lock);
35682 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35683diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35684index 1855bf5..af12b06 100644
35685--- a/block/blk-iopoll.c
35686+++ b/block/blk-iopoll.c
35687@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35688 }
35689 EXPORT_SYMBOL(blk_iopoll_complete);
35690
35691-static void blk_iopoll_softirq(struct softirq_action *h)
35692+static __latent_entropy void blk_iopoll_softirq(void)
35693 {
35694 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35695 int rearm = 0, budget = blk_iopoll_budget;
35696diff --git a/block/blk-map.c b/block/blk-map.c
35697index ae4ae10..c470b8d 100644
35698--- a/block/blk-map.c
35699+++ b/block/blk-map.c
35700@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35701 if (!len || !kbuf)
35702 return -EINVAL;
35703
35704- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35705+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35706 if (do_copy)
35707 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35708 else
35709diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35710index 57790c1..5e988dd 100644
35711--- a/block/blk-softirq.c
35712+++ b/block/blk-softirq.c
35713@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35714 * Softirq action handler - move entries to local list and loop over them
35715 * while passing them to the queue registered handler.
35716 */
35717-static void blk_done_softirq(struct softirq_action *h)
35718+static __latent_entropy void blk_done_softirq(void)
35719 {
35720 struct list_head *cpu_list, local_list;
35721
35722diff --git a/block/bsg.c b/block/bsg.c
35723index 420a5a9..23834aa 100644
35724--- a/block/bsg.c
35725+++ b/block/bsg.c
35726@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35727 struct sg_io_v4 *hdr, struct bsg_device *bd,
35728 fmode_t has_write_perm)
35729 {
35730+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35731+ unsigned char *cmdptr;
35732+
35733 if (hdr->request_len > BLK_MAX_CDB) {
35734 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35735 if (!rq->cmd)
35736 return -ENOMEM;
35737- }
35738+ cmdptr = rq->cmd;
35739+ } else
35740+ cmdptr = tmpcmd;
35741
35742- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35743+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35744 hdr->request_len))
35745 return -EFAULT;
35746
35747+ if (cmdptr != rq->cmd)
35748+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35749+
35750 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35751 if (blk_verify_command(rq->cmd, has_write_perm))
35752 return -EPERM;
35753diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35754index fbd5a67..f24fd95 100644
35755--- a/block/compat_ioctl.c
35756+++ b/block/compat_ioctl.c
35757@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35758 cgc = compat_alloc_user_space(sizeof(*cgc));
35759 cgc32 = compat_ptr(arg);
35760
35761- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35762+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35763 get_user(data, &cgc32->buffer) ||
35764 put_user(compat_ptr(data), &cgc->buffer) ||
35765 copy_in_user(&cgc->buflen, &cgc32->buflen,
35766@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35767 err |= __get_user(f->spec1, &uf->spec1);
35768 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35769 err |= __get_user(name, &uf->name);
35770- f->name = compat_ptr(name);
35771+ f->name = (void __force_kernel *)compat_ptr(name);
35772 if (err) {
35773 err = -EFAULT;
35774 goto out;
35775diff --git a/block/genhd.c b/block/genhd.c
35776index 791f419..89f21c4 100644
35777--- a/block/genhd.c
35778+++ b/block/genhd.c
35779@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35780
35781 /*
35782 * Register device numbers dev..(dev+range-1)
35783- * range must be nonzero
35784+ * Noop if @range is zero.
35785 * The hash chain is sorted on range, so that subranges can override.
35786 */
35787 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35788 struct kobject *(*probe)(dev_t, int *, void *),
35789 int (*lock)(dev_t, void *), void *data)
35790 {
35791- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35792+ if (range)
35793+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35794 }
35795
35796 EXPORT_SYMBOL(blk_register_region);
35797
35798+/* undo blk_register_region(), noop if @range is zero */
35799 void blk_unregister_region(dev_t devt, unsigned long range)
35800 {
35801- kobj_unmap(bdev_map, devt, range);
35802+ if (range)
35803+ kobj_unmap(bdev_map, devt, range);
35804 }
35805
35806 EXPORT_SYMBOL(blk_unregister_region);
35807diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35808index dc51f46..d5446a8 100644
35809--- a/block/partitions/efi.c
35810+++ b/block/partitions/efi.c
35811@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35812 if (!gpt)
35813 return NULL;
35814
35815+ if (!le32_to_cpu(gpt->num_partition_entries))
35816+ return NULL;
35817+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35818+ if (!pte)
35819+ return NULL;
35820+
35821 count = le32_to_cpu(gpt->num_partition_entries) *
35822 le32_to_cpu(gpt->sizeof_partition_entry);
35823- if (!count)
35824- return NULL;
35825- pte = kmalloc(count, GFP_KERNEL);
35826- if (!pte)
35827- return NULL;
35828-
35829 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35830 (u8 *) pte, count) < count) {
35831 kfree(pte);
35832diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35833index 2648797..92ed21f 100644
35834--- a/block/scsi_ioctl.c
35835+++ b/block/scsi_ioctl.c
35836@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35837 return put_user(0, p);
35838 }
35839
35840-static int sg_get_timeout(struct request_queue *q)
35841+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35842 {
35843 return jiffies_to_clock_t(q->sg_timeout);
35844 }
35845@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35846 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35847 struct sg_io_hdr *hdr, fmode_t mode)
35848 {
35849- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35850+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35851+ unsigned char *cmdptr;
35852+
35853+ if (rq->cmd != rq->__cmd)
35854+ cmdptr = rq->cmd;
35855+ else
35856+ cmdptr = tmpcmd;
35857+
35858+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35859 return -EFAULT;
35860+
35861+ if (cmdptr != rq->cmd)
35862+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35863+
35864 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35865 return -EPERM;
35866
35867@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35868 int err;
35869 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35870 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35871+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35872+ unsigned char *cmdptr;
35873
35874 if (!sic)
35875 return -EINVAL;
35876@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35877 */
35878 err = -EFAULT;
35879 rq->cmd_len = cmdlen;
35880- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35881+
35882+ if (rq->cmd != rq->__cmd)
35883+ cmdptr = rq->cmd;
35884+ else
35885+ cmdptr = tmpcmd;
35886+
35887+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35888 goto error;
35889
35890+ if (rq->cmd != cmdptr)
35891+ memcpy(rq->cmd, cmdptr, cmdlen);
35892+
35893 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35894 goto error;
35895
35896diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35897index 7bdd61b..afec999 100644
35898--- a/crypto/cryptd.c
35899+++ b/crypto/cryptd.c
35900@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35901
35902 struct cryptd_blkcipher_request_ctx {
35903 crypto_completion_t complete;
35904-};
35905+} __no_const;
35906
35907 struct cryptd_hash_ctx {
35908 struct crypto_shash *child;
35909@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35910
35911 struct cryptd_aead_request_ctx {
35912 crypto_completion_t complete;
35913-};
35914+} __no_const;
35915
35916 static void cryptd_queue_worker(struct work_struct *work);
35917
35918diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35919index 309d345..1632720 100644
35920--- a/crypto/pcrypt.c
35921+++ b/crypto/pcrypt.c
35922@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35923 int ret;
35924
35925 pinst->kobj.kset = pcrypt_kset;
35926- ret = kobject_add(&pinst->kobj, NULL, name);
35927+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35928 if (!ret)
35929 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35930
35931diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35932index 15dddc1..b61cf0c 100644
35933--- a/drivers/acpi/acpica/hwxfsleep.c
35934+++ b/drivers/acpi/acpica/hwxfsleep.c
35935@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35936 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35937
35938 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35939- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35940- acpi_hw_extended_sleep},
35941- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35942- acpi_hw_extended_wake_prep},
35943- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35944+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35945+ .extended_function = acpi_hw_extended_sleep},
35946+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35947+ .extended_function = acpi_hw_extended_wake_prep},
35948+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35949+ .extended_function = acpi_hw_extended_wake}
35950 };
35951
35952 /*
35953diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35954index e5bcd91..74f050d 100644
35955--- a/drivers/acpi/apei/apei-internal.h
35956+++ b/drivers/acpi/apei/apei-internal.h
35957@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35958 struct apei_exec_ins_type {
35959 u32 flags;
35960 apei_exec_ins_func_t run;
35961-};
35962+} __do_const;
35963
35964 struct apei_exec_context {
35965 u32 ip;
35966diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35967index dab7cb7..f0d2994 100644
35968--- a/drivers/acpi/apei/ghes.c
35969+++ b/drivers/acpi/apei/ghes.c
35970@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
35971 const struct acpi_hest_generic *generic,
35972 const struct acpi_generic_status *estatus)
35973 {
35974- static atomic_t seqno;
35975+ static atomic_unchecked_t seqno;
35976 unsigned int curr_seqno;
35977 char pfx_seq[64];
35978
35979@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
35980 else
35981 pfx = KERN_ERR;
35982 }
35983- curr_seqno = atomic_inc_return(&seqno);
35984+ curr_seqno = atomic_inc_return_unchecked(&seqno);
35985 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35986 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35987 pfx_seq, generic->header.source_id);
35988diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35989index a83e3c6..c3d617f 100644
35990--- a/drivers/acpi/bgrt.c
35991+++ b/drivers/acpi/bgrt.c
35992@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35993 if (!bgrt_image)
35994 return -ENODEV;
35995
35996- bin_attr_image.private = bgrt_image;
35997- bin_attr_image.size = bgrt_image_size;
35998+ pax_open_kernel();
35999+ *(void **)&bin_attr_image.private = bgrt_image;
36000+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36001+ pax_close_kernel();
36002
36003 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36004 if (!bgrt_kobj)
36005diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36006index afec452..c5d8b96 100644
36007--- a/drivers/acpi/blacklist.c
36008+++ b/drivers/acpi/blacklist.c
36009@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36010 u32 is_critical_error;
36011 };
36012
36013-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36014+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36015
36016 /*
36017 * POLICY: If *anything* doesn't work, put it on the blacklist.
36018@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36019 return 0;
36020 }
36021
36022-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36023+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36024 {
36025 .callback = dmi_disable_osi_vista,
36026 .ident = "Fujitsu Siemens",
36027diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36028index c68e724..e863008 100644
36029--- a/drivers/acpi/custom_method.c
36030+++ b/drivers/acpi/custom_method.c
36031@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36032 struct acpi_table_header table;
36033 acpi_status status;
36034
36035+#ifdef CONFIG_GRKERNSEC_KMEM
36036+ return -EPERM;
36037+#endif
36038+
36039 if (!(*ppos)) {
36040 /* parse the table header to get the table length */
36041 if (count <= sizeof(struct acpi_table_header))
36042diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36043index 3dca36d..abaf070 100644
36044--- a/drivers/acpi/processor_idle.c
36045+++ b/drivers/acpi/processor_idle.c
36046@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36047 {
36048 int i, count = CPUIDLE_DRIVER_STATE_START;
36049 struct acpi_processor_cx *cx;
36050- struct cpuidle_state *state;
36051+ cpuidle_state_no_const *state;
36052 struct cpuidle_driver *drv = &acpi_idle_driver;
36053
36054 if (!pr->flags.power_setup_done)
36055diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36056index 91a32ce..d77fcaf 100644
36057--- a/drivers/acpi/sysfs.c
36058+++ b/drivers/acpi/sysfs.c
36059@@ -425,11 +425,11 @@ static u32 num_counters;
36060 static struct attribute **all_attrs;
36061 static u32 acpi_gpe_count;
36062
36063-static struct attribute_group interrupt_stats_attr_group = {
36064+static attribute_group_no_const interrupt_stats_attr_group = {
36065 .name = "interrupts",
36066 };
36067
36068-static struct kobj_attribute *counter_attrs;
36069+static kobj_attribute_no_const *counter_attrs;
36070
36071 static void delete_gpe_attr_array(void)
36072 {
36073diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36074index 36605ab..6ef6d4b 100644
36075--- a/drivers/ata/libahci.c
36076+++ b/drivers/ata/libahci.c
36077@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36078 }
36079 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36080
36081-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36082+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36083 struct ata_taskfile *tf, int is_cmd, u16 flags,
36084 unsigned long timeout_msec)
36085 {
36086diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36087index 8cb2522..a815e54 100644
36088--- a/drivers/ata/libata-core.c
36089+++ b/drivers/ata/libata-core.c
36090@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36091 static void ata_dev_xfermask(struct ata_device *dev);
36092 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36093
36094-atomic_t ata_print_id = ATOMIC_INIT(0);
36095+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36096
36097 struct ata_force_param {
36098 const char *name;
36099@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36100 struct ata_port *ap;
36101 unsigned int tag;
36102
36103- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36104+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36105 ap = qc->ap;
36106
36107 qc->flags = 0;
36108@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36109 struct ata_port *ap;
36110 struct ata_link *link;
36111
36112- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36113+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36114 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36115 ap = qc->ap;
36116 link = qc->dev->link;
36117@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36118 return;
36119
36120 spin_lock(&lock);
36121+ pax_open_kernel();
36122
36123 for (cur = ops->inherits; cur; cur = cur->inherits) {
36124 void **inherit = (void **)cur;
36125@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36126 if (IS_ERR(*pp))
36127 *pp = NULL;
36128
36129- ops->inherits = NULL;
36130+ *(struct ata_port_operations **)&ops->inherits = NULL;
36131
36132+ pax_close_kernel();
36133 spin_unlock(&lock);
36134 }
36135
36136@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36137
36138 /* give ports names and add SCSI hosts */
36139 for (i = 0; i < host->n_ports; i++) {
36140- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36141+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36142 host->ports[i]->local_port_no = i + 1;
36143 }
36144
36145diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36146index ef8567d..8bdbd03 100644
36147--- a/drivers/ata/libata-scsi.c
36148+++ b/drivers/ata/libata-scsi.c
36149@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36150
36151 if (rc)
36152 return rc;
36153- ap->print_id = atomic_inc_return(&ata_print_id);
36154+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36155 return 0;
36156 }
36157 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36158diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36159index 45b5ab3..98446b8 100644
36160--- a/drivers/ata/libata.h
36161+++ b/drivers/ata/libata.h
36162@@ -53,7 +53,7 @@ enum {
36163 ATA_DNXFER_QUIET = (1 << 31),
36164 };
36165
36166-extern atomic_t ata_print_id;
36167+extern atomic_unchecked_t ata_print_id;
36168 extern int atapi_passthru16;
36169 extern int libata_fua;
36170 extern int libata_noacpi;
36171diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36172index 73492dd..ca2bff5 100644
36173--- a/drivers/ata/pata_arasan_cf.c
36174+++ b/drivers/ata/pata_arasan_cf.c
36175@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36176 /* Handle platform specific quirks */
36177 if (quirk) {
36178 if (quirk & CF_BROKEN_PIO) {
36179- ap->ops->set_piomode = NULL;
36180+ pax_open_kernel();
36181+ *(void **)&ap->ops->set_piomode = NULL;
36182+ pax_close_kernel();
36183 ap->pio_mask = 0;
36184 }
36185 if (quirk & CF_BROKEN_MWDMA)
36186diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36187index f9b983a..887b9d8 100644
36188--- a/drivers/atm/adummy.c
36189+++ b/drivers/atm/adummy.c
36190@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36191 vcc->pop(vcc, skb);
36192 else
36193 dev_kfree_skb_any(skb);
36194- atomic_inc(&vcc->stats->tx);
36195+ atomic_inc_unchecked(&vcc->stats->tx);
36196
36197 return 0;
36198 }
36199diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36200index 62a7607..cc4be104 100644
36201--- a/drivers/atm/ambassador.c
36202+++ b/drivers/atm/ambassador.c
36203@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36204 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36205
36206 // VC layer stats
36207- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36208+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36209
36210 // free the descriptor
36211 kfree (tx_descr);
36212@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36213 dump_skb ("<<<", vc, skb);
36214
36215 // VC layer stats
36216- atomic_inc(&atm_vcc->stats->rx);
36217+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36218 __net_timestamp(skb);
36219 // end of our responsibility
36220 atm_vcc->push (atm_vcc, skb);
36221@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36222 } else {
36223 PRINTK (KERN_INFO, "dropped over-size frame");
36224 // should we count this?
36225- atomic_inc(&atm_vcc->stats->rx_drop);
36226+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36227 }
36228
36229 } else {
36230@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36231 }
36232
36233 if (check_area (skb->data, skb->len)) {
36234- atomic_inc(&atm_vcc->stats->tx_err);
36235+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36236 return -ENOMEM; // ?
36237 }
36238
36239diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36240index 0e3f8f9..765a7a5 100644
36241--- a/drivers/atm/atmtcp.c
36242+++ b/drivers/atm/atmtcp.c
36243@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36244 if (vcc->pop) vcc->pop(vcc,skb);
36245 else dev_kfree_skb(skb);
36246 if (dev_data) return 0;
36247- atomic_inc(&vcc->stats->tx_err);
36248+ atomic_inc_unchecked(&vcc->stats->tx_err);
36249 return -ENOLINK;
36250 }
36251 size = skb->len+sizeof(struct atmtcp_hdr);
36252@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36253 if (!new_skb) {
36254 if (vcc->pop) vcc->pop(vcc,skb);
36255 else dev_kfree_skb(skb);
36256- atomic_inc(&vcc->stats->tx_err);
36257+ atomic_inc_unchecked(&vcc->stats->tx_err);
36258 return -ENOBUFS;
36259 }
36260 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36261@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36262 if (vcc->pop) vcc->pop(vcc,skb);
36263 else dev_kfree_skb(skb);
36264 out_vcc->push(out_vcc,new_skb);
36265- atomic_inc(&vcc->stats->tx);
36266- atomic_inc(&out_vcc->stats->rx);
36267+ atomic_inc_unchecked(&vcc->stats->tx);
36268+ atomic_inc_unchecked(&out_vcc->stats->rx);
36269 return 0;
36270 }
36271
36272@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36273 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36274 read_unlock(&vcc_sklist_lock);
36275 if (!out_vcc) {
36276- atomic_inc(&vcc->stats->tx_err);
36277+ atomic_inc_unchecked(&vcc->stats->tx_err);
36278 goto done;
36279 }
36280 skb_pull(skb,sizeof(struct atmtcp_hdr));
36281@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36282 __net_timestamp(new_skb);
36283 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36284 out_vcc->push(out_vcc,new_skb);
36285- atomic_inc(&vcc->stats->tx);
36286- atomic_inc(&out_vcc->stats->rx);
36287+ atomic_inc_unchecked(&vcc->stats->tx);
36288+ atomic_inc_unchecked(&out_vcc->stats->rx);
36289 done:
36290 if (vcc->pop) vcc->pop(vcc,skb);
36291 else dev_kfree_skb(skb);
36292diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36293index b1955ba..b179940 100644
36294--- a/drivers/atm/eni.c
36295+++ b/drivers/atm/eni.c
36296@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36297 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36298 vcc->dev->number);
36299 length = 0;
36300- atomic_inc(&vcc->stats->rx_err);
36301+ atomic_inc_unchecked(&vcc->stats->rx_err);
36302 }
36303 else {
36304 length = ATM_CELL_SIZE-1; /* no HEC */
36305@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36306 size);
36307 }
36308 eff = length = 0;
36309- atomic_inc(&vcc->stats->rx_err);
36310+ atomic_inc_unchecked(&vcc->stats->rx_err);
36311 }
36312 else {
36313 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36314@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36315 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36316 vcc->dev->number,vcc->vci,length,size << 2,descr);
36317 length = eff = 0;
36318- atomic_inc(&vcc->stats->rx_err);
36319+ atomic_inc_unchecked(&vcc->stats->rx_err);
36320 }
36321 }
36322 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36323@@ -767,7 +767,7 @@ rx_dequeued++;
36324 vcc->push(vcc,skb);
36325 pushed++;
36326 }
36327- atomic_inc(&vcc->stats->rx);
36328+ atomic_inc_unchecked(&vcc->stats->rx);
36329 }
36330 wake_up(&eni_dev->rx_wait);
36331 }
36332@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36333 PCI_DMA_TODEVICE);
36334 if (vcc->pop) vcc->pop(vcc,skb);
36335 else dev_kfree_skb_irq(skb);
36336- atomic_inc(&vcc->stats->tx);
36337+ atomic_inc_unchecked(&vcc->stats->tx);
36338 wake_up(&eni_dev->tx_wait);
36339 dma_complete++;
36340 }
36341diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36342index b41c948..a002b17 100644
36343--- a/drivers/atm/firestream.c
36344+++ b/drivers/atm/firestream.c
36345@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36346 }
36347 }
36348
36349- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36350+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36351
36352 fs_dprintk (FS_DEBUG_TXMEM, "i");
36353 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36354@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36355 #endif
36356 skb_put (skb, qe->p1 & 0xffff);
36357 ATM_SKB(skb)->vcc = atm_vcc;
36358- atomic_inc(&atm_vcc->stats->rx);
36359+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36360 __net_timestamp(skb);
36361 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36362 atm_vcc->push (atm_vcc, skb);
36363@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36364 kfree (pe);
36365 }
36366 if (atm_vcc)
36367- atomic_inc(&atm_vcc->stats->rx_drop);
36368+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36369 break;
36370 case 0x1f: /* Reassembly abort: no buffers. */
36371 /* Silently increment error counter. */
36372 if (atm_vcc)
36373- atomic_inc(&atm_vcc->stats->rx_drop);
36374+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36375 break;
36376 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36377 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36378diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36379index 204814e..cede831 100644
36380--- a/drivers/atm/fore200e.c
36381+++ b/drivers/atm/fore200e.c
36382@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36383 #endif
36384 /* check error condition */
36385 if (*entry->status & STATUS_ERROR)
36386- atomic_inc(&vcc->stats->tx_err);
36387+ atomic_inc_unchecked(&vcc->stats->tx_err);
36388 else
36389- atomic_inc(&vcc->stats->tx);
36390+ atomic_inc_unchecked(&vcc->stats->tx);
36391 }
36392 }
36393
36394@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36395 if (skb == NULL) {
36396 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36397
36398- atomic_inc(&vcc->stats->rx_drop);
36399+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36400 return -ENOMEM;
36401 }
36402
36403@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36404
36405 dev_kfree_skb_any(skb);
36406
36407- atomic_inc(&vcc->stats->rx_drop);
36408+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36409 return -ENOMEM;
36410 }
36411
36412 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36413
36414 vcc->push(vcc, skb);
36415- atomic_inc(&vcc->stats->rx);
36416+ atomic_inc_unchecked(&vcc->stats->rx);
36417
36418 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36419
36420@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36421 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36422 fore200e->atm_dev->number,
36423 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36424- atomic_inc(&vcc->stats->rx_err);
36425+ atomic_inc_unchecked(&vcc->stats->rx_err);
36426 }
36427 }
36428
36429@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36430 goto retry_here;
36431 }
36432
36433- atomic_inc(&vcc->stats->tx_err);
36434+ atomic_inc_unchecked(&vcc->stats->tx_err);
36435
36436 fore200e->tx_sat++;
36437 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36438diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36439index aa6be26..f70a785 100644
36440--- a/drivers/atm/he.c
36441+++ b/drivers/atm/he.c
36442@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36443
36444 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36445 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36446- atomic_inc(&vcc->stats->rx_drop);
36447+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36448 goto return_host_buffers;
36449 }
36450
36451@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36452 RBRQ_LEN_ERR(he_dev->rbrq_head)
36453 ? "LEN_ERR" : "",
36454 vcc->vpi, vcc->vci);
36455- atomic_inc(&vcc->stats->rx_err);
36456+ atomic_inc_unchecked(&vcc->stats->rx_err);
36457 goto return_host_buffers;
36458 }
36459
36460@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36461 vcc->push(vcc, skb);
36462 spin_lock(&he_dev->global_lock);
36463
36464- atomic_inc(&vcc->stats->rx);
36465+ atomic_inc_unchecked(&vcc->stats->rx);
36466
36467 return_host_buffers:
36468 ++pdus_assembled;
36469@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36470 tpd->vcc->pop(tpd->vcc, tpd->skb);
36471 else
36472 dev_kfree_skb_any(tpd->skb);
36473- atomic_inc(&tpd->vcc->stats->tx_err);
36474+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36475 }
36476 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36477 return;
36478@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36479 vcc->pop(vcc, skb);
36480 else
36481 dev_kfree_skb_any(skb);
36482- atomic_inc(&vcc->stats->tx_err);
36483+ atomic_inc_unchecked(&vcc->stats->tx_err);
36484 return -EINVAL;
36485 }
36486
36487@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36488 vcc->pop(vcc, skb);
36489 else
36490 dev_kfree_skb_any(skb);
36491- atomic_inc(&vcc->stats->tx_err);
36492+ atomic_inc_unchecked(&vcc->stats->tx_err);
36493 return -EINVAL;
36494 }
36495 #endif
36496@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36497 vcc->pop(vcc, skb);
36498 else
36499 dev_kfree_skb_any(skb);
36500- atomic_inc(&vcc->stats->tx_err);
36501+ atomic_inc_unchecked(&vcc->stats->tx_err);
36502 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36503 return -ENOMEM;
36504 }
36505@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36506 vcc->pop(vcc, skb);
36507 else
36508 dev_kfree_skb_any(skb);
36509- atomic_inc(&vcc->stats->tx_err);
36510+ atomic_inc_unchecked(&vcc->stats->tx_err);
36511 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36512 return -ENOMEM;
36513 }
36514@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36515 __enqueue_tpd(he_dev, tpd, cid);
36516 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36517
36518- atomic_inc(&vcc->stats->tx);
36519+ atomic_inc_unchecked(&vcc->stats->tx);
36520
36521 return 0;
36522 }
36523diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36524index 1dc0519..1aadaf7 100644
36525--- a/drivers/atm/horizon.c
36526+++ b/drivers/atm/horizon.c
36527@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36528 {
36529 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36530 // VC layer stats
36531- atomic_inc(&vcc->stats->rx);
36532+ atomic_inc_unchecked(&vcc->stats->rx);
36533 __net_timestamp(skb);
36534 // end of our responsibility
36535 vcc->push (vcc, skb);
36536@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36537 dev->tx_iovec = NULL;
36538
36539 // VC layer stats
36540- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36541+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36542
36543 // free the skb
36544 hrz_kfree_skb (skb);
36545diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36546index 1bdf104..9dc44b1 100644
36547--- a/drivers/atm/idt77252.c
36548+++ b/drivers/atm/idt77252.c
36549@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36550 else
36551 dev_kfree_skb(skb);
36552
36553- atomic_inc(&vcc->stats->tx);
36554+ atomic_inc_unchecked(&vcc->stats->tx);
36555 }
36556
36557 atomic_dec(&scq->used);
36558@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36559 if ((sb = dev_alloc_skb(64)) == NULL) {
36560 printk("%s: Can't allocate buffers for aal0.\n",
36561 card->name);
36562- atomic_add(i, &vcc->stats->rx_drop);
36563+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36564 break;
36565 }
36566 if (!atm_charge(vcc, sb->truesize)) {
36567 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36568 card->name);
36569- atomic_add(i - 1, &vcc->stats->rx_drop);
36570+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36571 dev_kfree_skb(sb);
36572 break;
36573 }
36574@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36575 ATM_SKB(sb)->vcc = vcc;
36576 __net_timestamp(sb);
36577 vcc->push(vcc, sb);
36578- atomic_inc(&vcc->stats->rx);
36579+ atomic_inc_unchecked(&vcc->stats->rx);
36580
36581 cell += ATM_CELL_PAYLOAD;
36582 }
36583@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36584 "(CDC: %08x)\n",
36585 card->name, len, rpp->len, readl(SAR_REG_CDC));
36586 recycle_rx_pool_skb(card, rpp);
36587- atomic_inc(&vcc->stats->rx_err);
36588+ atomic_inc_unchecked(&vcc->stats->rx_err);
36589 return;
36590 }
36591 if (stat & SAR_RSQE_CRC) {
36592 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36593 recycle_rx_pool_skb(card, rpp);
36594- atomic_inc(&vcc->stats->rx_err);
36595+ atomic_inc_unchecked(&vcc->stats->rx_err);
36596 return;
36597 }
36598 if (skb_queue_len(&rpp->queue) > 1) {
36599@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36600 RXPRINTK("%s: Can't alloc RX skb.\n",
36601 card->name);
36602 recycle_rx_pool_skb(card, rpp);
36603- atomic_inc(&vcc->stats->rx_err);
36604+ atomic_inc_unchecked(&vcc->stats->rx_err);
36605 return;
36606 }
36607 if (!atm_charge(vcc, skb->truesize)) {
36608@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36609 __net_timestamp(skb);
36610
36611 vcc->push(vcc, skb);
36612- atomic_inc(&vcc->stats->rx);
36613+ atomic_inc_unchecked(&vcc->stats->rx);
36614
36615 return;
36616 }
36617@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36618 __net_timestamp(skb);
36619
36620 vcc->push(vcc, skb);
36621- atomic_inc(&vcc->stats->rx);
36622+ atomic_inc_unchecked(&vcc->stats->rx);
36623
36624 if (skb->truesize > SAR_FB_SIZE_3)
36625 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36626@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36627 if (vcc->qos.aal != ATM_AAL0) {
36628 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36629 card->name, vpi, vci);
36630- atomic_inc(&vcc->stats->rx_drop);
36631+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36632 goto drop;
36633 }
36634
36635 if ((sb = dev_alloc_skb(64)) == NULL) {
36636 printk("%s: Can't allocate buffers for AAL0.\n",
36637 card->name);
36638- atomic_inc(&vcc->stats->rx_err);
36639+ atomic_inc_unchecked(&vcc->stats->rx_err);
36640 goto drop;
36641 }
36642
36643@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36644 ATM_SKB(sb)->vcc = vcc;
36645 __net_timestamp(sb);
36646 vcc->push(vcc, sb);
36647- atomic_inc(&vcc->stats->rx);
36648+ atomic_inc_unchecked(&vcc->stats->rx);
36649
36650 drop:
36651 skb_pull(queue, 64);
36652@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36653
36654 if (vc == NULL) {
36655 printk("%s: NULL connection in send().\n", card->name);
36656- atomic_inc(&vcc->stats->tx_err);
36657+ atomic_inc_unchecked(&vcc->stats->tx_err);
36658 dev_kfree_skb(skb);
36659 return -EINVAL;
36660 }
36661 if (!test_bit(VCF_TX, &vc->flags)) {
36662 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36663- atomic_inc(&vcc->stats->tx_err);
36664+ atomic_inc_unchecked(&vcc->stats->tx_err);
36665 dev_kfree_skb(skb);
36666 return -EINVAL;
36667 }
36668@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36669 break;
36670 default:
36671 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36672- atomic_inc(&vcc->stats->tx_err);
36673+ atomic_inc_unchecked(&vcc->stats->tx_err);
36674 dev_kfree_skb(skb);
36675 return -EINVAL;
36676 }
36677
36678 if (skb_shinfo(skb)->nr_frags != 0) {
36679 printk("%s: No scatter-gather yet.\n", card->name);
36680- atomic_inc(&vcc->stats->tx_err);
36681+ atomic_inc_unchecked(&vcc->stats->tx_err);
36682 dev_kfree_skb(skb);
36683 return -EINVAL;
36684 }
36685@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36686
36687 err = queue_skb(card, vc, skb, oam);
36688 if (err) {
36689- atomic_inc(&vcc->stats->tx_err);
36690+ atomic_inc_unchecked(&vcc->stats->tx_err);
36691 dev_kfree_skb(skb);
36692 return err;
36693 }
36694@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36695 skb = dev_alloc_skb(64);
36696 if (!skb) {
36697 printk("%s: Out of memory in send_oam().\n", card->name);
36698- atomic_inc(&vcc->stats->tx_err);
36699+ atomic_inc_unchecked(&vcc->stats->tx_err);
36700 return -ENOMEM;
36701 }
36702 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36703diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36704index 4217f29..88f547a 100644
36705--- a/drivers/atm/iphase.c
36706+++ b/drivers/atm/iphase.c
36707@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36708 status = (u_short) (buf_desc_ptr->desc_mode);
36709 if (status & (RX_CER | RX_PTE | RX_OFL))
36710 {
36711- atomic_inc(&vcc->stats->rx_err);
36712+ atomic_inc_unchecked(&vcc->stats->rx_err);
36713 IF_ERR(printk("IA: bad packet, dropping it");)
36714 if (status & RX_CER) {
36715 IF_ERR(printk(" cause: packet CRC error\n");)
36716@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36717 len = dma_addr - buf_addr;
36718 if (len > iadev->rx_buf_sz) {
36719 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36720- atomic_inc(&vcc->stats->rx_err);
36721+ atomic_inc_unchecked(&vcc->stats->rx_err);
36722 goto out_free_desc;
36723 }
36724
36725@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36726 ia_vcc = INPH_IA_VCC(vcc);
36727 if (ia_vcc == NULL)
36728 {
36729- atomic_inc(&vcc->stats->rx_err);
36730+ atomic_inc_unchecked(&vcc->stats->rx_err);
36731 atm_return(vcc, skb->truesize);
36732 dev_kfree_skb_any(skb);
36733 goto INCR_DLE;
36734@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36735 if ((length > iadev->rx_buf_sz) || (length >
36736 (skb->len - sizeof(struct cpcs_trailer))))
36737 {
36738- atomic_inc(&vcc->stats->rx_err);
36739+ atomic_inc_unchecked(&vcc->stats->rx_err);
36740 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36741 length, skb->len);)
36742 atm_return(vcc, skb->truesize);
36743@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36744
36745 IF_RX(printk("rx_dle_intr: skb push");)
36746 vcc->push(vcc,skb);
36747- atomic_inc(&vcc->stats->rx);
36748+ atomic_inc_unchecked(&vcc->stats->rx);
36749 iadev->rx_pkt_cnt++;
36750 }
36751 INCR_DLE:
36752@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36753 {
36754 struct k_sonet_stats *stats;
36755 stats = &PRIV(_ia_dev[board])->sonet_stats;
36756- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36757- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36758- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36759- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36760- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36761- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36762- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36763- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36764- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36765+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36766+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36767+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36768+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36769+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36770+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36771+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36772+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36773+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36774 }
36775 ia_cmds.status = 0;
36776 break;
36777@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36778 if ((desc == 0) || (desc > iadev->num_tx_desc))
36779 {
36780 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36781- atomic_inc(&vcc->stats->tx);
36782+ atomic_inc_unchecked(&vcc->stats->tx);
36783 if (vcc->pop)
36784 vcc->pop(vcc, skb);
36785 else
36786@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36787 ATM_DESC(skb) = vcc->vci;
36788 skb_queue_tail(&iadev->tx_dma_q, skb);
36789
36790- atomic_inc(&vcc->stats->tx);
36791+ atomic_inc_unchecked(&vcc->stats->tx);
36792 iadev->tx_pkt_cnt++;
36793 /* Increment transaction counter */
36794 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36795
36796 #if 0
36797 /* add flow control logic */
36798- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36799+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36800 if (iavcc->vc_desc_cnt > 10) {
36801 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36802 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36803diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36804index fa7d701..1e404c7 100644
36805--- a/drivers/atm/lanai.c
36806+++ b/drivers/atm/lanai.c
36807@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36808 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36809 lanai_endtx(lanai, lvcc);
36810 lanai_free_skb(lvcc->tx.atmvcc, skb);
36811- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36812+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36813 }
36814
36815 /* Try to fill the buffer - don't call unless there is backlog */
36816@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36817 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36818 __net_timestamp(skb);
36819 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36820- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36821+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36822 out:
36823 lvcc->rx.buf.ptr = end;
36824 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36825@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36826 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36827 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36828 lanai->stats.service_rxnotaal5++;
36829- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36830+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36831 return 0;
36832 }
36833 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36834@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36835 int bytes;
36836 read_unlock(&vcc_sklist_lock);
36837 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36838- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36839+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36840 lvcc->stats.x.aal5.service_trash++;
36841 bytes = (SERVICE_GET_END(s) * 16) -
36842 (((unsigned long) lvcc->rx.buf.ptr) -
36843@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36844 }
36845 if (s & SERVICE_STREAM) {
36846 read_unlock(&vcc_sklist_lock);
36847- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36848+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36849 lvcc->stats.x.aal5.service_stream++;
36850 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36851 "PDU on VCI %d!\n", lanai->number, vci);
36852@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36853 return 0;
36854 }
36855 DPRINTK("got rx crc error on vci %d\n", vci);
36856- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36857+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36858 lvcc->stats.x.aal5.service_rxcrc++;
36859 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36860 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36861diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36862index 9587e95..b45c5cb 100644
36863--- a/drivers/atm/nicstar.c
36864+++ b/drivers/atm/nicstar.c
36865@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36866 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36867 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36868 card->index);
36869- atomic_inc(&vcc->stats->tx_err);
36870+ atomic_inc_unchecked(&vcc->stats->tx_err);
36871 dev_kfree_skb_any(skb);
36872 return -EINVAL;
36873 }
36874@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36875 if (!vc->tx) {
36876 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36877 card->index);
36878- atomic_inc(&vcc->stats->tx_err);
36879+ atomic_inc_unchecked(&vcc->stats->tx_err);
36880 dev_kfree_skb_any(skb);
36881 return -EINVAL;
36882 }
36883@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36884 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36885 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36886 card->index);
36887- atomic_inc(&vcc->stats->tx_err);
36888+ atomic_inc_unchecked(&vcc->stats->tx_err);
36889 dev_kfree_skb_any(skb);
36890 return -EINVAL;
36891 }
36892
36893 if (skb_shinfo(skb)->nr_frags != 0) {
36894 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36895- atomic_inc(&vcc->stats->tx_err);
36896+ atomic_inc_unchecked(&vcc->stats->tx_err);
36897 dev_kfree_skb_any(skb);
36898 return -EINVAL;
36899 }
36900@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36901 }
36902
36903 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36904- atomic_inc(&vcc->stats->tx_err);
36905+ atomic_inc_unchecked(&vcc->stats->tx_err);
36906 dev_kfree_skb_any(skb);
36907 return -EIO;
36908 }
36909- atomic_inc(&vcc->stats->tx);
36910+ atomic_inc_unchecked(&vcc->stats->tx);
36911
36912 return 0;
36913 }
36914@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36915 printk
36916 ("nicstar%d: Can't allocate buffers for aal0.\n",
36917 card->index);
36918- atomic_add(i, &vcc->stats->rx_drop);
36919+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36920 break;
36921 }
36922 if (!atm_charge(vcc, sb->truesize)) {
36923 RXPRINTK
36924 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36925 card->index);
36926- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36927+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36928 dev_kfree_skb_any(sb);
36929 break;
36930 }
36931@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36932 ATM_SKB(sb)->vcc = vcc;
36933 __net_timestamp(sb);
36934 vcc->push(vcc, sb);
36935- atomic_inc(&vcc->stats->rx);
36936+ atomic_inc_unchecked(&vcc->stats->rx);
36937 cell += ATM_CELL_PAYLOAD;
36938 }
36939
36940@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36941 if (iovb == NULL) {
36942 printk("nicstar%d: Out of iovec buffers.\n",
36943 card->index);
36944- atomic_inc(&vcc->stats->rx_drop);
36945+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36946 recycle_rx_buf(card, skb);
36947 return;
36948 }
36949@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36950 small or large buffer itself. */
36951 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36952 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36953- atomic_inc(&vcc->stats->rx_err);
36954+ atomic_inc_unchecked(&vcc->stats->rx_err);
36955 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36956 NS_MAX_IOVECS);
36957 NS_PRV_IOVCNT(iovb) = 0;
36958@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36959 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36960 card->index);
36961 which_list(card, skb);
36962- atomic_inc(&vcc->stats->rx_err);
36963+ atomic_inc_unchecked(&vcc->stats->rx_err);
36964 recycle_rx_buf(card, skb);
36965 vc->rx_iov = NULL;
36966 recycle_iov_buf(card, iovb);
36967@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36968 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36969 card->index);
36970 which_list(card, skb);
36971- atomic_inc(&vcc->stats->rx_err);
36972+ atomic_inc_unchecked(&vcc->stats->rx_err);
36973 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36974 NS_PRV_IOVCNT(iovb));
36975 vc->rx_iov = NULL;
36976@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36977 printk(" - PDU size mismatch.\n");
36978 else
36979 printk(".\n");
36980- atomic_inc(&vcc->stats->rx_err);
36981+ atomic_inc_unchecked(&vcc->stats->rx_err);
36982 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36983 NS_PRV_IOVCNT(iovb));
36984 vc->rx_iov = NULL;
36985@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36986 /* skb points to a small buffer */
36987 if (!atm_charge(vcc, skb->truesize)) {
36988 push_rxbufs(card, skb);
36989- atomic_inc(&vcc->stats->rx_drop);
36990+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36991 } else {
36992 skb_put(skb, len);
36993 dequeue_sm_buf(card, skb);
36994@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36995 ATM_SKB(skb)->vcc = vcc;
36996 __net_timestamp(skb);
36997 vcc->push(vcc, skb);
36998- atomic_inc(&vcc->stats->rx);
36999+ atomic_inc_unchecked(&vcc->stats->rx);
37000 }
37001 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37002 struct sk_buff *sb;
37003@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37004 if (len <= NS_SMBUFSIZE) {
37005 if (!atm_charge(vcc, sb->truesize)) {
37006 push_rxbufs(card, sb);
37007- atomic_inc(&vcc->stats->rx_drop);
37008+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37009 } else {
37010 skb_put(sb, len);
37011 dequeue_sm_buf(card, sb);
37012@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37013 ATM_SKB(sb)->vcc = vcc;
37014 __net_timestamp(sb);
37015 vcc->push(vcc, sb);
37016- atomic_inc(&vcc->stats->rx);
37017+ atomic_inc_unchecked(&vcc->stats->rx);
37018 }
37019
37020 push_rxbufs(card, skb);
37021@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37022
37023 if (!atm_charge(vcc, skb->truesize)) {
37024 push_rxbufs(card, skb);
37025- atomic_inc(&vcc->stats->rx_drop);
37026+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37027 } else {
37028 dequeue_lg_buf(card, skb);
37029 #ifdef NS_USE_DESTRUCTORS
37030@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37031 ATM_SKB(skb)->vcc = vcc;
37032 __net_timestamp(skb);
37033 vcc->push(vcc, skb);
37034- atomic_inc(&vcc->stats->rx);
37035+ atomic_inc_unchecked(&vcc->stats->rx);
37036 }
37037
37038 push_rxbufs(card, sb);
37039@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37040 printk
37041 ("nicstar%d: Out of huge buffers.\n",
37042 card->index);
37043- atomic_inc(&vcc->stats->rx_drop);
37044+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37045 recycle_iovec_rx_bufs(card,
37046 (struct iovec *)
37047 iovb->data,
37048@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37049 card->hbpool.count++;
37050 } else
37051 dev_kfree_skb_any(hb);
37052- atomic_inc(&vcc->stats->rx_drop);
37053+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37054 } else {
37055 /* Copy the small buffer to the huge buffer */
37056 sb = (struct sk_buff *)iov->iov_base;
37057@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37058 #endif /* NS_USE_DESTRUCTORS */
37059 __net_timestamp(hb);
37060 vcc->push(vcc, hb);
37061- atomic_inc(&vcc->stats->rx);
37062+ atomic_inc_unchecked(&vcc->stats->rx);
37063 }
37064 }
37065
37066diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37067index e3fb496..d9646bf 100644
37068--- a/drivers/atm/solos-pci.c
37069+++ b/drivers/atm/solos-pci.c
37070@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37071 }
37072 atm_charge(vcc, skb->truesize);
37073 vcc->push(vcc, skb);
37074- atomic_inc(&vcc->stats->rx);
37075+ atomic_inc_unchecked(&vcc->stats->rx);
37076 break;
37077
37078 case PKT_STATUS:
37079@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37080 vcc = SKB_CB(oldskb)->vcc;
37081
37082 if (vcc) {
37083- atomic_inc(&vcc->stats->tx);
37084+ atomic_inc_unchecked(&vcc->stats->tx);
37085 solos_pop(vcc, oldskb);
37086 } else {
37087 dev_kfree_skb_irq(oldskb);
37088diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37089index 0215934..ce9f5b1 100644
37090--- a/drivers/atm/suni.c
37091+++ b/drivers/atm/suni.c
37092@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37093
37094
37095 #define ADD_LIMITED(s,v) \
37096- atomic_add((v),&stats->s); \
37097- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37098+ atomic_add_unchecked((v),&stats->s); \
37099+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37100
37101
37102 static void suni_hz(unsigned long from_timer)
37103diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37104index 5120a96..e2572bd 100644
37105--- a/drivers/atm/uPD98402.c
37106+++ b/drivers/atm/uPD98402.c
37107@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37108 struct sonet_stats tmp;
37109 int error = 0;
37110
37111- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37112+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37113 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37114 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37115 if (zero && !error) {
37116@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37117
37118
37119 #define ADD_LIMITED(s,v) \
37120- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37121- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37122- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37123+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37124+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37125+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37126
37127
37128 static void stat_event(struct atm_dev *dev)
37129@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37130 if (reason & uPD98402_INT_PFM) stat_event(dev);
37131 if (reason & uPD98402_INT_PCO) {
37132 (void) GET(PCOCR); /* clear interrupt cause */
37133- atomic_add(GET(HECCT),
37134+ atomic_add_unchecked(GET(HECCT),
37135 &PRIV(dev)->sonet_stats.uncorr_hcs);
37136 }
37137 if ((reason & uPD98402_INT_RFO) &&
37138@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37139 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37140 uPD98402_INT_LOS),PIMR); /* enable them */
37141 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37142- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37143- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37144- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37145+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37146+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37147+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37148 return 0;
37149 }
37150
37151diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37152index 969c3c2..9b72956 100644
37153--- a/drivers/atm/zatm.c
37154+++ b/drivers/atm/zatm.c
37155@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37156 }
37157 if (!size) {
37158 dev_kfree_skb_irq(skb);
37159- if (vcc) atomic_inc(&vcc->stats->rx_err);
37160+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37161 continue;
37162 }
37163 if (!atm_charge(vcc,skb->truesize)) {
37164@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37165 skb->len = size;
37166 ATM_SKB(skb)->vcc = vcc;
37167 vcc->push(vcc,skb);
37168- atomic_inc(&vcc->stats->rx);
37169+ atomic_inc_unchecked(&vcc->stats->rx);
37170 }
37171 zout(pos & 0xffff,MTA(mbx));
37172 #if 0 /* probably a stupid idea */
37173@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37174 skb_queue_head(&zatm_vcc->backlog,skb);
37175 break;
37176 }
37177- atomic_inc(&vcc->stats->tx);
37178+ atomic_inc_unchecked(&vcc->stats->tx);
37179 wake_up(&zatm_vcc->tx_wait);
37180 }
37181
37182diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37183index 59dc808..f10c74e 100644
37184--- a/drivers/base/bus.c
37185+++ b/drivers/base/bus.c
37186@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37187 return -EINVAL;
37188
37189 mutex_lock(&subsys->p->mutex);
37190- list_add_tail(&sif->node, &subsys->p->interfaces);
37191+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37192 if (sif->add_dev) {
37193 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37194 while ((dev = subsys_dev_iter_next(&iter)))
37195@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37196 subsys = sif->subsys;
37197
37198 mutex_lock(&subsys->p->mutex);
37199- list_del_init(&sif->node);
37200+ pax_list_del_init((struct list_head *)&sif->node);
37201 if (sif->remove_dev) {
37202 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37203 while ((dev = subsys_dev_iter_next(&iter)))
37204diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37205index 25798db..15f130e 100644
37206--- a/drivers/base/devtmpfs.c
37207+++ b/drivers/base/devtmpfs.c
37208@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37209 if (!thread)
37210 return 0;
37211
37212- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37213+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37214 if (err)
37215 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37216 else
37217@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37218 *err = sys_unshare(CLONE_NEWNS);
37219 if (*err)
37220 goto out;
37221- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37222+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37223 if (*err)
37224 goto out;
37225- sys_chdir("/.."); /* will traverse into overmounted root */
37226- sys_chroot(".");
37227+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37228+ sys_chroot((char __force_user *)".");
37229 complete(&setup_done);
37230 while (1) {
37231 spin_lock(&req_lock);
37232diff --git a/drivers/base/node.c b/drivers/base/node.c
37233index bc9f43b..29703b8 100644
37234--- a/drivers/base/node.c
37235+++ b/drivers/base/node.c
37236@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37237 struct node_attr {
37238 struct device_attribute attr;
37239 enum node_states state;
37240-};
37241+} __do_const;
37242
37243 static ssize_t show_node_state(struct device *dev,
37244 struct device_attribute *attr, char *buf)
37245diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37246index bfb8955..4ebff34 100644
37247--- a/drivers/base/power/domain.c
37248+++ b/drivers/base/power/domain.c
37249@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37250
37251 if (dev->power.subsys_data->domain_data) {
37252 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37253- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37254+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37255 if (clear_td)
37256- gpd_data->td = (struct gpd_timing_data){ 0 };
37257+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37258
37259 if (--gpd_data->refcount == 0) {
37260 dev->power.subsys_data->domain_data = NULL;
37261@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37262 {
37263 struct cpuidle_driver *cpuidle_drv;
37264 struct gpd_cpu_data *cpu_data;
37265- struct cpuidle_state *idle_state;
37266+ cpuidle_state_no_const *idle_state;
37267 int ret = 0;
37268
37269 if (IS_ERR_OR_NULL(genpd) || state < 0)
37270@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37271 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37272 {
37273 struct gpd_cpu_data *cpu_data;
37274- struct cpuidle_state *idle_state;
37275+ cpuidle_state_no_const *idle_state;
37276 int ret = 0;
37277
37278 if (IS_ERR_OR_NULL(genpd))
37279diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37280index 03e089a..0e9560c 100644
37281--- a/drivers/base/power/sysfs.c
37282+++ b/drivers/base/power/sysfs.c
37283@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37284 return -EIO;
37285 }
37286 }
37287- return sprintf(buf, p);
37288+ return sprintf(buf, "%s", p);
37289 }
37290
37291 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37292diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37293index 2d56f41..8830f19 100644
37294--- a/drivers/base/power/wakeup.c
37295+++ b/drivers/base/power/wakeup.c
37296@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37297 * They need to be modified together atomically, so it's better to use one
37298 * atomic variable to hold them both.
37299 */
37300-static atomic_t combined_event_count = ATOMIC_INIT(0);
37301+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37302
37303 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37304 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37305
37306 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37307 {
37308- unsigned int comb = atomic_read(&combined_event_count);
37309+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37310
37311 *cnt = (comb >> IN_PROGRESS_BITS);
37312 *inpr = comb & MAX_IN_PROGRESS;
37313@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37314 ws->start_prevent_time = ws->last_time;
37315
37316 /* Increment the counter of events in progress. */
37317- cec = atomic_inc_return(&combined_event_count);
37318+ cec = atomic_inc_return_unchecked(&combined_event_count);
37319
37320 trace_wakeup_source_activate(ws->name, cec);
37321 }
37322@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37323 * Increment the counter of registered wakeup events and decrement the
37324 * couter of wakeup events in progress simultaneously.
37325 */
37326- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37327+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37328 trace_wakeup_source_deactivate(ws->name, cec);
37329
37330 split_counters(&cnt, &inpr);
37331diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37332index e8d11b6..7b1b36f 100644
37333--- a/drivers/base/syscore.c
37334+++ b/drivers/base/syscore.c
37335@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37336 void register_syscore_ops(struct syscore_ops *ops)
37337 {
37338 mutex_lock(&syscore_ops_lock);
37339- list_add_tail(&ops->node, &syscore_ops_list);
37340+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37341 mutex_unlock(&syscore_ops_lock);
37342 }
37343 EXPORT_SYMBOL_GPL(register_syscore_ops);
37344@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37345 void unregister_syscore_ops(struct syscore_ops *ops)
37346 {
37347 mutex_lock(&syscore_ops_lock);
37348- list_del(&ops->node);
37349+ pax_list_del((struct list_head *)&ops->node);
37350 mutex_unlock(&syscore_ops_lock);
37351 }
37352 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37353diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37354index 036e8ab..6221dec 100644
37355--- a/drivers/block/cciss.c
37356+++ b/drivers/block/cciss.c
37357@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37358 while (!list_empty(&h->reqQ)) {
37359 c = list_entry(h->reqQ.next, CommandList_struct, list);
37360 /* can't do anything if fifo is full */
37361- if ((h->access.fifo_full(h))) {
37362+ if ((h->access->fifo_full(h))) {
37363 dev_warn(&h->pdev->dev, "fifo full\n");
37364 break;
37365 }
37366@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37367 h->Qdepth--;
37368
37369 /* Tell the controller execute command */
37370- h->access.submit_command(h, c);
37371+ h->access->submit_command(h, c);
37372
37373 /* Put job onto the completed Q */
37374 addQ(&h->cmpQ, c);
37375@@ -3447,17 +3447,17 @@ startio:
37376
37377 static inline unsigned long get_next_completion(ctlr_info_t *h)
37378 {
37379- return h->access.command_completed(h);
37380+ return h->access->command_completed(h);
37381 }
37382
37383 static inline int interrupt_pending(ctlr_info_t *h)
37384 {
37385- return h->access.intr_pending(h);
37386+ return h->access->intr_pending(h);
37387 }
37388
37389 static inline long interrupt_not_for_us(ctlr_info_t *h)
37390 {
37391- return ((h->access.intr_pending(h) == 0) ||
37392+ return ((h->access->intr_pending(h) == 0) ||
37393 (h->interrupts_enabled == 0));
37394 }
37395
37396@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37397 u32 a;
37398
37399 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37400- return h->access.command_completed(h);
37401+ return h->access->command_completed(h);
37402
37403 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37404 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37405@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37406 trans_support & CFGTBL_Trans_use_short_tags);
37407
37408 /* Change the access methods to the performant access methods */
37409- h->access = SA5_performant_access;
37410+ h->access = &SA5_performant_access;
37411 h->transMethod = CFGTBL_Trans_Performant;
37412
37413 return;
37414@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37415 if (prod_index < 0)
37416 return -ENODEV;
37417 h->product_name = products[prod_index].product_name;
37418- h->access = *(products[prod_index].access);
37419+ h->access = products[prod_index].access;
37420
37421 if (cciss_board_disabled(h)) {
37422 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37423@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37424 }
37425
37426 /* make sure the board interrupts are off */
37427- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37428+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37429 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37430 if (rc)
37431 goto clean2;
37432@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37433 * fake ones to scoop up any residual completions.
37434 */
37435 spin_lock_irqsave(&h->lock, flags);
37436- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37437+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37438 spin_unlock_irqrestore(&h->lock, flags);
37439 free_irq(h->intr[h->intr_mode], h);
37440 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37441@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37442 dev_info(&h->pdev->dev, "Board READY.\n");
37443 dev_info(&h->pdev->dev,
37444 "Waiting for stale completions to drain.\n");
37445- h->access.set_intr_mask(h, CCISS_INTR_ON);
37446+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37447 msleep(10000);
37448- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37449+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37450
37451 rc = controller_reset_failed(h->cfgtable);
37452 if (rc)
37453@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37454 cciss_scsi_setup(h);
37455
37456 /* Turn the interrupts on so we can service requests */
37457- h->access.set_intr_mask(h, CCISS_INTR_ON);
37458+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37459
37460 /* Get the firmware version */
37461 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37462@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37463 kfree(flush_buf);
37464 if (return_code != IO_OK)
37465 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37466- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37467+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37468 free_irq(h->intr[h->intr_mode], h);
37469 }
37470
37471diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37472index 7fda30e..2f27946 100644
37473--- a/drivers/block/cciss.h
37474+++ b/drivers/block/cciss.h
37475@@ -101,7 +101,7 @@ struct ctlr_info
37476 /* information about each logical volume */
37477 drive_info_struct *drv[CISS_MAX_LUN];
37478
37479- struct access_method access;
37480+ struct access_method *access;
37481
37482 /* queue and queue Info */
37483 struct list_head reqQ;
37484@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37485 }
37486
37487 static struct access_method SA5_access = {
37488- SA5_submit_command,
37489- SA5_intr_mask,
37490- SA5_fifo_full,
37491- SA5_intr_pending,
37492- SA5_completed,
37493+ .submit_command = SA5_submit_command,
37494+ .set_intr_mask = SA5_intr_mask,
37495+ .fifo_full = SA5_fifo_full,
37496+ .intr_pending = SA5_intr_pending,
37497+ .command_completed = SA5_completed,
37498 };
37499
37500 static struct access_method SA5B_access = {
37501- SA5_submit_command,
37502- SA5B_intr_mask,
37503- SA5_fifo_full,
37504- SA5B_intr_pending,
37505- SA5_completed,
37506+ .submit_command = SA5_submit_command,
37507+ .set_intr_mask = SA5B_intr_mask,
37508+ .fifo_full = SA5_fifo_full,
37509+ .intr_pending = SA5B_intr_pending,
37510+ .command_completed = SA5_completed,
37511 };
37512
37513 static struct access_method SA5_performant_access = {
37514- SA5_submit_command,
37515- SA5_performant_intr_mask,
37516- SA5_fifo_full,
37517- SA5_performant_intr_pending,
37518- SA5_performant_completed,
37519+ .submit_command = SA5_submit_command,
37520+ .set_intr_mask = SA5_performant_intr_mask,
37521+ .fifo_full = SA5_fifo_full,
37522+ .intr_pending = SA5_performant_intr_pending,
37523+ .command_completed = SA5_performant_completed,
37524 };
37525
37526 struct board_type {
37527diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37528index 2b94403..fd6ad1f 100644
37529--- a/drivers/block/cpqarray.c
37530+++ b/drivers/block/cpqarray.c
37531@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37532 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37533 goto Enomem4;
37534 }
37535- hba[i]->access.set_intr_mask(hba[i], 0);
37536+ hba[i]->access->set_intr_mask(hba[i], 0);
37537 if (request_irq(hba[i]->intr, do_ida_intr,
37538 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37539 {
37540@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37541 add_timer(&hba[i]->timer);
37542
37543 /* Enable IRQ now that spinlock and rate limit timer are set up */
37544- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37545+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37546
37547 for(j=0; j<NWD; j++) {
37548 struct gendisk *disk = ida_gendisk[i][j];
37549@@ -694,7 +694,7 @@ DBGINFO(
37550 for(i=0; i<NR_PRODUCTS; i++) {
37551 if (board_id == products[i].board_id) {
37552 c->product_name = products[i].product_name;
37553- c->access = *(products[i].access);
37554+ c->access = products[i].access;
37555 break;
37556 }
37557 }
37558@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37559 hba[ctlr]->intr = intr;
37560 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37561 hba[ctlr]->product_name = products[j].product_name;
37562- hba[ctlr]->access = *(products[j].access);
37563+ hba[ctlr]->access = products[j].access;
37564 hba[ctlr]->ctlr = ctlr;
37565 hba[ctlr]->board_id = board_id;
37566 hba[ctlr]->pci_dev = NULL; /* not PCI */
37567@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37568
37569 while((c = h->reqQ) != NULL) {
37570 /* Can't do anything if we're busy */
37571- if (h->access.fifo_full(h) == 0)
37572+ if (h->access->fifo_full(h) == 0)
37573 return;
37574
37575 /* Get the first entry from the request Q */
37576@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37577 h->Qdepth--;
37578
37579 /* Tell the controller to do our bidding */
37580- h->access.submit_command(h, c);
37581+ h->access->submit_command(h, c);
37582
37583 /* Get onto the completion Q */
37584 addQ(&h->cmpQ, c);
37585@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37586 unsigned long flags;
37587 __u32 a,a1;
37588
37589- istat = h->access.intr_pending(h);
37590+ istat = h->access->intr_pending(h);
37591 /* Is this interrupt for us? */
37592 if (istat == 0)
37593 return IRQ_NONE;
37594@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37595 */
37596 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37597 if (istat & FIFO_NOT_EMPTY) {
37598- while((a = h->access.command_completed(h))) {
37599+ while((a = h->access->command_completed(h))) {
37600 a1 = a; a &= ~3;
37601 if ((c = h->cmpQ) == NULL)
37602 {
37603@@ -1448,11 +1448,11 @@ static int sendcmd(
37604 /*
37605 * Disable interrupt
37606 */
37607- info_p->access.set_intr_mask(info_p, 0);
37608+ info_p->access->set_intr_mask(info_p, 0);
37609 /* Make sure there is room in the command FIFO */
37610 /* Actually it should be completely empty at this time. */
37611 for (i = 200000; i > 0; i--) {
37612- temp = info_p->access.fifo_full(info_p);
37613+ temp = info_p->access->fifo_full(info_p);
37614 if (temp != 0) {
37615 break;
37616 }
37617@@ -1465,7 +1465,7 @@ DBG(
37618 /*
37619 * Send the cmd
37620 */
37621- info_p->access.submit_command(info_p, c);
37622+ info_p->access->submit_command(info_p, c);
37623 complete = pollcomplete(ctlr);
37624
37625 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37626@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37627 * we check the new geometry. Then turn interrupts back on when
37628 * we're done.
37629 */
37630- host->access.set_intr_mask(host, 0);
37631+ host->access->set_intr_mask(host, 0);
37632 getgeometry(ctlr);
37633- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37634+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37635
37636 for(i=0; i<NWD; i++) {
37637 struct gendisk *disk = ida_gendisk[ctlr][i];
37638@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37639 /* Wait (up to 2 seconds) for a command to complete */
37640
37641 for (i = 200000; i > 0; i--) {
37642- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37643+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37644 if (done == 0) {
37645 udelay(10); /* a short fixed delay */
37646 } else
37647diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37648index be73e9d..7fbf140 100644
37649--- a/drivers/block/cpqarray.h
37650+++ b/drivers/block/cpqarray.h
37651@@ -99,7 +99,7 @@ struct ctlr_info {
37652 drv_info_t drv[NWD];
37653 struct proc_dir_entry *proc;
37654
37655- struct access_method access;
37656+ struct access_method *access;
37657
37658 cmdlist_t *reqQ;
37659 cmdlist_t *cmpQ;
37660diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37661index 0e06f0c..c47b81d 100644
37662--- a/drivers/block/drbd/drbd_int.h
37663+++ b/drivers/block/drbd/drbd_int.h
37664@@ -582,7 +582,7 @@ struct drbd_epoch {
37665 struct drbd_tconn *tconn;
37666 struct list_head list;
37667 unsigned int barrier_nr;
37668- atomic_t epoch_size; /* increased on every request added. */
37669+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37670 atomic_t active; /* increased on every req. added, and dec on every finished. */
37671 unsigned long flags;
37672 };
37673@@ -1022,7 +1022,7 @@ struct drbd_conf {
37674 unsigned int al_tr_number;
37675 int al_tr_cycle;
37676 wait_queue_head_t seq_wait;
37677- atomic_t packet_seq;
37678+ atomic_unchecked_t packet_seq;
37679 unsigned int peer_seq;
37680 spinlock_t peer_seq_lock;
37681 unsigned int minor;
37682@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37683 char __user *uoptval;
37684 int err;
37685
37686- uoptval = (char __user __force *)optval;
37687+ uoptval = (char __force_user *)optval;
37688
37689 set_fs(KERNEL_DS);
37690 if (level == SOL_SOCKET)
37691diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37692index 89c497c..9c736ae 100644
37693--- a/drivers/block/drbd/drbd_interval.c
37694+++ b/drivers/block/drbd/drbd_interval.c
37695@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37696 }
37697
37698 static const struct rb_augment_callbacks augment_callbacks = {
37699- augment_propagate,
37700- augment_copy,
37701- augment_rotate,
37702+ .propagate = augment_propagate,
37703+ .copy = augment_copy,
37704+ .rotate = augment_rotate,
37705 };
37706
37707 /**
37708diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37709index 929468e..7d934eb 100644
37710--- a/drivers/block/drbd/drbd_main.c
37711+++ b/drivers/block/drbd/drbd_main.c
37712@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37713 p->sector = sector;
37714 p->block_id = block_id;
37715 p->blksize = blksize;
37716- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37717+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37718 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37719 }
37720
37721@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37722 return -EIO;
37723 p->sector = cpu_to_be64(req->i.sector);
37724 p->block_id = (unsigned long)req;
37725- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37726+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37727 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37728 if (mdev->state.conn >= C_SYNC_SOURCE &&
37729 mdev->state.conn <= C_PAUSED_SYNC_T)
37730@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37731 {
37732 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37733
37734- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37735- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37736+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37737+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37738 kfree(tconn->current_epoch);
37739
37740 idr_destroy(&tconn->volumes);
37741diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37742index c706d50..5e1b472 100644
37743--- a/drivers/block/drbd/drbd_nl.c
37744+++ b/drivers/block/drbd/drbd_nl.c
37745@@ -3440,7 +3440,7 @@ out:
37746
37747 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37748 {
37749- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37750+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37751 struct sk_buff *msg;
37752 struct drbd_genlmsghdr *d_out;
37753 unsigned seq;
37754@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37755 return;
37756 }
37757
37758- seq = atomic_inc_return(&drbd_genl_seq);
37759+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37760 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37761 if (!msg)
37762 goto failed;
37763diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37764index d073305..4998fea 100644
37765--- a/drivers/block/drbd/drbd_receiver.c
37766+++ b/drivers/block/drbd/drbd_receiver.c
37767@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37768 {
37769 int err;
37770
37771- atomic_set(&mdev->packet_seq, 0);
37772+ atomic_set_unchecked(&mdev->packet_seq, 0);
37773 mdev->peer_seq = 0;
37774
37775 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37776@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37777 do {
37778 next_epoch = NULL;
37779
37780- epoch_size = atomic_read(&epoch->epoch_size);
37781+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37782
37783 switch (ev & ~EV_CLEANUP) {
37784 case EV_PUT:
37785@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37786 rv = FE_DESTROYED;
37787 } else {
37788 epoch->flags = 0;
37789- atomic_set(&epoch->epoch_size, 0);
37790+ atomic_set_unchecked(&epoch->epoch_size, 0);
37791 /* atomic_set(&epoch->active, 0); is already zero */
37792 if (rv == FE_STILL_LIVE)
37793 rv = FE_RECYCLED;
37794@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37795 conn_wait_active_ee_empty(tconn);
37796 drbd_flush(tconn);
37797
37798- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37799+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37800 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37801 if (epoch)
37802 break;
37803@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37804 }
37805
37806 epoch->flags = 0;
37807- atomic_set(&epoch->epoch_size, 0);
37808+ atomic_set_unchecked(&epoch->epoch_size, 0);
37809 atomic_set(&epoch->active, 0);
37810
37811 spin_lock(&tconn->epoch_lock);
37812- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37813+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37814 list_add(&epoch->list, &tconn->current_epoch->list);
37815 tconn->current_epoch = epoch;
37816 tconn->epochs++;
37817@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37818
37819 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37820 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37821- atomic_inc(&tconn->current_epoch->epoch_size);
37822+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37823 err2 = drbd_drain_block(mdev, pi->size);
37824 if (!err)
37825 err = err2;
37826@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37827
37828 spin_lock(&tconn->epoch_lock);
37829 peer_req->epoch = tconn->current_epoch;
37830- atomic_inc(&peer_req->epoch->epoch_size);
37831+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37832 atomic_inc(&peer_req->epoch->active);
37833 spin_unlock(&tconn->epoch_lock);
37834
37835@@ -4345,7 +4345,7 @@ struct data_cmd {
37836 int expect_payload;
37837 size_t pkt_size;
37838 int (*fn)(struct drbd_tconn *, struct packet_info *);
37839-};
37840+} __do_const;
37841
37842 static struct data_cmd drbd_cmd_handler[] = {
37843 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37844@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37845 if (!list_empty(&tconn->current_epoch->list))
37846 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37847 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37848- atomic_set(&tconn->current_epoch->epoch_size, 0);
37849+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37850 tconn->send.seen_any_write_yet = false;
37851
37852 conn_info(tconn, "Connection closed\n");
37853@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37854 struct asender_cmd {
37855 size_t pkt_size;
37856 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37857-};
37858+} __do_const;
37859
37860 static struct asender_cmd asender_tbl[] = {
37861 [P_PING] = { 0, got_Ping },
37862diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
37863index 2023043..dab515c 100644
37864--- a/drivers/block/floppy.c
37865+++ b/drivers/block/floppy.c
37866@@ -3053,7 +3053,10 @@ static int raw_cmd_copyout(int cmd, void __user *param,
37867 int ret;
37868
37869 while (ptr) {
37870- ret = copy_to_user(param, ptr, sizeof(*ptr));
37871+ struct floppy_raw_cmd cmd = *ptr;
37872+ cmd.next = NULL;
37873+ cmd.kernel_data = NULL;
37874+ ret = copy_to_user(param, &cmd, sizeof(cmd));
37875 if (ret)
37876 return -EFAULT;
37877 param += sizeof(struct floppy_raw_cmd);
37878@@ -3107,10 +3110,11 @@ loop:
37879 return -ENOMEM;
37880 *rcmd = ptr;
37881 ret = copy_from_user(ptr, param, sizeof(*ptr));
37882- if (ret)
37883- return -EFAULT;
37884 ptr->next = NULL;
37885 ptr->buffer_length = 0;
37886+ ptr->kernel_data = NULL;
37887+ if (ret)
37888+ return -EFAULT;
37889 param += sizeof(struct floppy_raw_cmd);
37890 if (ptr->cmd_count > 33)
37891 /* the command may now also take up the space
37892@@ -3126,7 +3130,6 @@ loop:
37893 for (i = 0; i < 16; i++)
37894 ptr->reply[i] = 0;
37895 ptr->resultcode = 0;
37896- ptr->kernel_data = NULL;
37897
37898 if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
37899 if (ptr->length <= 0)
37900diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37901index 66e8c3b..9b68dd9 100644
37902--- a/drivers/block/loop.c
37903+++ b/drivers/block/loop.c
37904@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37905
37906 file_start_write(file);
37907 set_fs(get_ds());
37908- bw = file->f_op->write(file, buf, len, &pos);
37909+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37910 set_fs(old_fs);
37911 file_end_write(file);
37912 if (likely(bw == len))
37913diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37914index 091b9ea..f5428f8 100644
37915--- a/drivers/block/null_blk.c
37916+++ b/drivers/block/null_blk.c
37917@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37918 return 0;
37919 }
37920
37921-static struct blk_mq_ops null_mq_ops = {
37922- .queue_rq = null_queue_rq,
37923- .map_queue = blk_mq_map_queue,
37924+static struct blk_mq_ops null_mq_single_ops = {
37925+ .queue_rq = null_queue_rq,
37926+ .map_queue = blk_mq_map_queue,
37927 .init_hctx = null_init_hctx,
37928 .complete = null_softirq_done_fn,
37929+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37930+ .free_hctx = blk_mq_free_single_hw_queue,
37931+};
37932+
37933+static struct blk_mq_ops null_mq_per_node_ops = {
37934+ .queue_rq = null_queue_rq,
37935+ .map_queue = blk_mq_map_queue,
37936+ .init_hctx = null_init_hctx,
37937+ .alloc_hctx = null_alloc_hctx,
37938+ .free_hctx = null_free_hctx,
37939 };
37940
37941 static struct blk_mq_reg null_mq_reg = {
37942- .ops = &null_mq_ops,
37943+ .ops = &null_mq_single_ops,
37944 .queue_depth = 64,
37945 .cmd_size = sizeof(struct nullb_cmd),
37946 .flags = BLK_MQ_F_SHOULD_MERGE,
37947@@ -521,13 +531,8 @@ static int null_add_dev(void)
37948 null_mq_reg.queue_depth = hw_queue_depth;
37949 null_mq_reg.nr_hw_queues = submit_queues;
37950
37951- if (use_per_node_hctx) {
37952- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37953- null_mq_reg.ops->free_hctx = null_free_hctx;
37954- } else {
37955- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37956- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37957- }
37958+ if (use_per_node_hctx)
37959+ null_mq_reg.ops = &null_mq_per_node_ops;
37960
37961 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37962 } else if (queue_mode == NULL_Q_BIO) {
37963diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37964index a2af73d..c0b8f61 100644
37965--- a/drivers/block/pktcdvd.c
37966+++ b/drivers/block/pktcdvd.c
37967@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37968
37969 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37970 {
37971- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37972+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37973 }
37974
37975 /*
37976@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37977 return -EROFS;
37978 }
37979 pd->settings.fp = ti.fp;
37980- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37981+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37982
37983 if (ti.nwa_v) {
37984 pd->nwa = be32_to_cpu(ti.next_writable);
37985diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37986index e5565fb..71be10b4 100644
37987--- a/drivers/block/smart1,2.h
37988+++ b/drivers/block/smart1,2.h
37989@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37990 }
37991
37992 static struct access_method smart4_access = {
37993- smart4_submit_command,
37994- smart4_intr_mask,
37995- smart4_fifo_full,
37996- smart4_intr_pending,
37997- smart4_completed,
37998+ .submit_command = smart4_submit_command,
37999+ .set_intr_mask = smart4_intr_mask,
38000+ .fifo_full = smart4_fifo_full,
38001+ .intr_pending = smart4_intr_pending,
38002+ .command_completed = smart4_completed,
38003 };
38004
38005 /*
38006@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38007 }
38008
38009 static struct access_method smart2_access = {
38010- smart2_submit_command,
38011- smart2_intr_mask,
38012- smart2_fifo_full,
38013- smart2_intr_pending,
38014- smart2_completed,
38015+ .submit_command = smart2_submit_command,
38016+ .set_intr_mask = smart2_intr_mask,
38017+ .fifo_full = smart2_fifo_full,
38018+ .intr_pending = smart2_intr_pending,
38019+ .command_completed = smart2_completed,
38020 };
38021
38022 /*
38023@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38024 }
38025
38026 static struct access_method smart2e_access = {
38027- smart2e_submit_command,
38028- smart2e_intr_mask,
38029- smart2e_fifo_full,
38030- smart2e_intr_pending,
38031- smart2e_completed,
38032+ .submit_command = smart2e_submit_command,
38033+ .set_intr_mask = smart2e_intr_mask,
38034+ .fifo_full = smart2e_fifo_full,
38035+ .intr_pending = smart2e_intr_pending,
38036+ .command_completed = smart2e_completed,
38037 };
38038
38039 /*
38040@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38041 }
38042
38043 static struct access_method smart1_access = {
38044- smart1_submit_command,
38045- smart1_intr_mask,
38046- smart1_fifo_full,
38047- smart1_intr_pending,
38048- smart1_completed,
38049+ .submit_command = smart1_submit_command,
38050+ .set_intr_mask = smart1_intr_mask,
38051+ .fifo_full = smart1_fifo_full,
38052+ .intr_pending = smart1_intr_pending,
38053+ .command_completed = smart1_completed,
38054 };
38055diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38056index f038dba..bb74c08 100644
38057--- a/drivers/bluetooth/btwilink.c
38058+++ b/drivers/bluetooth/btwilink.c
38059@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38060
38061 static int bt_ti_probe(struct platform_device *pdev)
38062 {
38063- static struct ti_st *hst;
38064+ struct ti_st *hst;
38065 struct hci_dev *hdev;
38066 int err;
38067
38068diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38069index 8a3aff7..d7538c2 100644
38070--- a/drivers/cdrom/cdrom.c
38071+++ b/drivers/cdrom/cdrom.c
38072@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38073 ENSURE(reset, CDC_RESET);
38074 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38075 cdi->mc_flags = 0;
38076- cdo->n_minors = 0;
38077 cdi->options = CDO_USE_FFLAGS;
38078
38079 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38080@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38081 else
38082 cdi->cdda_method = CDDA_OLD;
38083
38084- if (!cdo->generic_packet)
38085- cdo->generic_packet = cdrom_dummy_generic_packet;
38086+ if (!cdo->generic_packet) {
38087+ pax_open_kernel();
38088+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38089+ pax_close_kernel();
38090+ }
38091
38092 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38093 mutex_lock(&cdrom_mutex);
38094@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38095 if (cdi->exit)
38096 cdi->exit(cdi);
38097
38098- cdi->ops->n_minors--;
38099 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38100 }
38101
38102@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38103 */
38104 nr = nframes;
38105 do {
38106- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38107+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38108 if (cgc.buffer)
38109 break;
38110
38111@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38112 struct cdrom_device_info *cdi;
38113 int ret;
38114
38115- ret = scnprintf(info + *pos, max_size - *pos, header);
38116+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38117 if (!ret)
38118 return 1;
38119
38120diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38121index 51e75ad..39c4c76 100644
38122--- a/drivers/cdrom/gdrom.c
38123+++ b/drivers/cdrom/gdrom.c
38124@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38125 .audio_ioctl = gdrom_audio_ioctl,
38126 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38127 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38128- .n_minors = 1,
38129 };
38130
38131 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38132diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38133index 1386749..5430258 100644
38134--- a/drivers/char/Kconfig
38135+++ b/drivers/char/Kconfig
38136@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38137
38138 config DEVKMEM
38139 bool "/dev/kmem virtual device support"
38140- default y
38141+ default n
38142+ depends on !GRKERNSEC_KMEM
38143 help
38144 Say Y here if you want to support the /dev/kmem device. The
38145 /dev/kmem device is rarely used, but can be used for certain
38146@@ -577,6 +578,7 @@ config DEVPORT
38147 bool
38148 depends on !M68K
38149 depends on ISA || PCI
38150+ depends on !GRKERNSEC_KMEM
38151 default y
38152
38153 source "drivers/s390/char/Kconfig"
38154diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38155index a48e05b..6bac831 100644
38156--- a/drivers/char/agp/compat_ioctl.c
38157+++ b/drivers/char/agp/compat_ioctl.c
38158@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38159 return -ENOMEM;
38160 }
38161
38162- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38163+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38164 sizeof(*usegment) * ureserve.seg_count)) {
38165 kfree(usegment);
38166 kfree(ksegment);
38167diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38168index 1b19239..963967b 100644
38169--- a/drivers/char/agp/frontend.c
38170+++ b/drivers/char/agp/frontend.c
38171@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38172
38173 agp_copy_info(agp_bridge, &kerninfo);
38174
38175+ memset(&userinfo, 0, sizeof(userinfo));
38176 userinfo.version.major = kerninfo.version.major;
38177 userinfo.version.minor = kerninfo.version.minor;
38178 userinfo.bridge_id = kerninfo.device->vendor |
38179@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38180 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38181 return -EFAULT;
38182
38183- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38184+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38185 return -EFAULT;
38186
38187 client = agp_find_client_by_pid(reserve.pid);
38188@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38189 if (segment == NULL)
38190 return -ENOMEM;
38191
38192- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38193+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38194 sizeof(struct agp_segment) * reserve.seg_count)) {
38195 kfree(segment);
38196 return -EFAULT;
38197diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38198index 4f94375..413694e 100644
38199--- a/drivers/char/genrtc.c
38200+++ b/drivers/char/genrtc.c
38201@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38202 switch (cmd) {
38203
38204 case RTC_PLL_GET:
38205+ memset(&pll, 0, sizeof(pll));
38206 if (get_rtc_pll(&pll))
38207 return -EINVAL;
38208 else
38209diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38210index d5d4cd8..22d561d 100644
38211--- a/drivers/char/hpet.c
38212+++ b/drivers/char/hpet.c
38213@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38214 }
38215
38216 static int
38217-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38218+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38219 struct hpet_info *info)
38220 {
38221 struct hpet_timer __iomem *timer;
38222diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38223index 86fe45c..c0ea948 100644
38224--- a/drivers/char/hw_random/intel-rng.c
38225+++ b/drivers/char/hw_random/intel-rng.c
38226@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38227
38228 if (no_fwh_detect)
38229 return -ENODEV;
38230- printk(warning);
38231+ printk("%s", warning);
38232 return -EBUSY;
38233 }
38234
38235diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38236index ec4e10f..f2a763b 100644
38237--- a/drivers/char/ipmi/ipmi_msghandler.c
38238+++ b/drivers/char/ipmi/ipmi_msghandler.c
38239@@ -420,7 +420,7 @@ struct ipmi_smi {
38240 struct proc_dir_entry *proc_dir;
38241 char proc_dir_name[10];
38242
38243- atomic_t stats[IPMI_NUM_STATS];
38244+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38245
38246 /*
38247 * run_to_completion duplicate of smb_info, smi_info
38248@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38249
38250
38251 #define ipmi_inc_stat(intf, stat) \
38252- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38253+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38254 #define ipmi_get_stat(intf, stat) \
38255- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38256+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38257
38258 static int is_lan_addr(struct ipmi_addr *addr)
38259 {
38260@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38261 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38262 init_waitqueue_head(&intf->waitq);
38263 for (i = 0; i < IPMI_NUM_STATS; i++)
38264- atomic_set(&intf->stats[i], 0);
38265+ atomic_set_unchecked(&intf->stats[i], 0);
38266
38267 intf->proc_dir = NULL;
38268
38269diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38270index 03f4189..e79f5e0 100644
38271--- a/drivers/char/ipmi/ipmi_si_intf.c
38272+++ b/drivers/char/ipmi/ipmi_si_intf.c
38273@@ -280,7 +280,7 @@ struct smi_info {
38274 unsigned char slave_addr;
38275
38276 /* Counters and things for the proc filesystem. */
38277- atomic_t stats[SI_NUM_STATS];
38278+ atomic_unchecked_t stats[SI_NUM_STATS];
38279
38280 struct task_struct *thread;
38281
38282@@ -289,9 +289,9 @@ struct smi_info {
38283 };
38284
38285 #define smi_inc_stat(smi, stat) \
38286- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38287+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38288 #define smi_get_stat(smi, stat) \
38289- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38290+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38291
38292 #define SI_MAX_PARMS 4
38293
38294@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38295 atomic_set(&new_smi->req_events, 0);
38296 new_smi->run_to_completion = 0;
38297 for (i = 0; i < SI_NUM_STATS; i++)
38298- atomic_set(&new_smi->stats[i], 0);
38299+ atomic_set_unchecked(&new_smi->stats[i], 0);
38300
38301 new_smi->interrupt_disabled = 1;
38302 atomic_set(&new_smi->stop_operation, 0);
38303diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38304index 92c5937..1be4e4d 100644
38305--- a/drivers/char/mem.c
38306+++ b/drivers/char/mem.c
38307@@ -18,6 +18,7 @@
38308 #include <linux/raw.h>
38309 #include <linux/tty.h>
38310 #include <linux/capability.h>
38311+#include <linux/security.h>
38312 #include <linux/ptrace.h>
38313 #include <linux/device.h>
38314 #include <linux/highmem.h>
38315@@ -36,6 +37,10 @@
38316
38317 #define DEVPORT_MINOR 4
38318
38319+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38320+extern const struct file_operations grsec_fops;
38321+#endif
38322+
38323 static inline unsigned long size_inside_page(unsigned long start,
38324 unsigned long size)
38325 {
38326@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38327
38328 while (cursor < to) {
38329 if (!devmem_is_allowed(pfn)) {
38330+#ifdef CONFIG_GRKERNSEC_KMEM
38331+ gr_handle_mem_readwrite(from, to);
38332+#else
38333 printk(KERN_INFO
38334 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38335 current->comm, from, to);
38336+#endif
38337 return 0;
38338 }
38339 cursor += PAGE_SIZE;
38340@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38341 }
38342 return 1;
38343 }
38344+#elif defined(CONFIG_GRKERNSEC_KMEM)
38345+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38346+{
38347+ return 0;
38348+}
38349 #else
38350 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38351 {
38352@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38353
38354 while (count > 0) {
38355 unsigned long remaining;
38356+ char *temp;
38357
38358 sz = size_inside_page(p, count);
38359
38360@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38361 if (!ptr)
38362 return -EFAULT;
38363
38364- remaining = copy_to_user(buf, ptr, sz);
38365+#ifdef CONFIG_PAX_USERCOPY
38366+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38367+ if (!temp) {
38368+ unxlate_dev_mem_ptr(p, ptr);
38369+ return -ENOMEM;
38370+ }
38371+ memcpy(temp, ptr, sz);
38372+#else
38373+ temp = ptr;
38374+#endif
38375+
38376+ remaining = copy_to_user(buf, temp, sz);
38377+
38378+#ifdef CONFIG_PAX_USERCOPY
38379+ kfree(temp);
38380+#endif
38381+
38382 unxlate_dev_mem_ptr(p, ptr);
38383 if (remaining)
38384 return -EFAULT;
38385@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38386 size_t count, loff_t *ppos)
38387 {
38388 unsigned long p = *ppos;
38389- ssize_t low_count, read, sz;
38390+ ssize_t low_count, read, sz, err = 0;
38391 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38392- int err = 0;
38393
38394 read = 0;
38395 if (p < (unsigned long) high_memory) {
38396@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38397 }
38398 #endif
38399 while (low_count > 0) {
38400+ char *temp;
38401+
38402 sz = size_inside_page(p, low_count);
38403
38404 /*
38405@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38406 */
38407 kbuf = xlate_dev_kmem_ptr((char *)p);
38408
38409- if (copy_to_user(buf, kbuf, sz))
38410+#ifdef CONFIG_PAX_USERCOPY
38411+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38412+ if (!temp)
38413+ return -ENOMEM;
38414+ memcpy(temp, kbuf, sz);
38415+#else
38416+ temp = kbuf;
38417+#endif
38418+
38419+ err = copy_to_user(buf, temp, sz);
38420+
38421+#ifdef CONFIG_PAX_USERCOPY
38422+ kfree(temp);
38423+#endif
38424+
38425+ if (err)
38426 return -EFAULT;
38427 buf += sz;
38428 p += sz;
38429@@ -821,6 +868,9 @@ static const struct memdev {
38430 #ifdef CONFIG_PRINTK
38431 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38432 #endif
38433+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38434+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38435+#endif
38436 };
38437
38438 static int memory_open(struct inode *inode, struct file *filp)
38439@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38440 continue;
38441
38442 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38443- NULL, devlist[minor].name);
38444+ NULL, "%s", devlist[minor].name);
38445 }
38446
38447 return tty_init();
38448diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38449index 9df78e2..01ba9ae 100644
38450--- a/drivers/char/nvram.c
38451+++ b/drivers/char/nvram.c
38452@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38453
38454 spin_unlock_irq(&rtc_lock);
38455
38456- if (copy_to_user(buf, contents, tmp - contents))
38457+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38458 return -EFAULT;
38459
38460 *ppos = i;
38461diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38462index 8320abd..ec48108 100644
38463--- a/drivers/char/pcmcia/synclink_cs.c
38464+++ b/drivers/char/pcmcia/synclink_cs.c
38465@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38466
38467 if (debug_level >= DEBUG_LEVEL_INFO)
38468 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38469- __FILE__, __LINE__, info->device_name, port->count);
38470+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38471
38472- WARN_ON(!port->count);
38473+ WARN_ON(!atomic_read(&port->count));
38474
38475 if (tty_port_close_start(port, tty, filp) == 0)
38476 goto cleanup;
38477@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38478 cleanup:
38479 if (debug_level >= DEBUG_LEVEL_INFO)
38480 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38481- tty->driver->name, port->count);
38482+ tty->driver->name, atomic_read(&port->count));
38483 }
38484
38485 /* Wait until the transmitter is empty.
38486@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38487
38488 if (debug_level >= DEBUG_LEVEL_INFO)
38489 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38490- __FILE__, __LINE__, tty->driver->name, port->count);
38491+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38492
38493 /* If port is closing, signal caller to try again */
38494 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38495@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38496 goto cleanup;
38497 }
38498 spin_lock(&port->lock);
38499- port->count++;
38500+ atomic_inc(&port->count);
38501 spin_unlock(&port->lock);
38502 spin_unlock_irqrestore(&info->netlock, flags);
38503
38504- if (port->count == 1) {
38505+ if (atomic_read(&port->count) == 1) {
38506 /* 1st open on this device, init hardware */
38507 retval = startup(info, tty);
38508 if (retval < 0)
38509@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38510 unsigned short new_crctype;
38511
38512 /* return error if TTY interface open */
38513- if (info->port.count)
38514+ if (atomic_read(&info->port.count))
38515 return -EBUSY;
38516
38517 switch (encoding)
38518@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38519
38520 /* arbitrate between network and tty opens */
38521 spin_lock_irqsave(&info->netlock, flags);
38522- if (info->port.count != 0 || info->netcount != 0) {
38523+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38524 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38525 spin_unlock_irqrestore(&info->netlock, flags);
38526 return -EBUSY;
38527@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38528 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38529
38530 /* return error if TTY interface open */
38531- if (info->port.count)
38532+ if (atomic_read(&info->port.count))
38533 return -EBUSY;
38534
38535 if (cmd != SIOCWANDEV)
38536diff --git a/drivers/char/random.c b/drivers/char/random.c
38537index 429b75b..a7f4145 100644
38538--- a/drivers/char/random.c
38539+++ b/drivers/char/random.c
38540@@ -270,10 +270,17 @@
38541 /*
38542 * Configuration information
38543 */
38544+#ifdef CONFIG_GRKERNSEC_RANDNET
38545+#define INPUT_POOL_SHIFT 14
38546+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38547+#define OUTPUT_POOL_SHIFT 12
38548+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38549+#else
38550 #define INPUT_POOL_SHIFT 12
38551 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38552 #define OUTPUT_POOL_SHIFT 10
38553 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38554+#endif
38555 #define SEC_XFER_SIZE 512
38556 #define EXTRACT_SIZE 10
38557
38558@@ -284,9 +291,6 @@
38559 /*
38560 * To allow fractional bits to be tracked, the entropy_count field is
38561 * denominated in units of 1/8th bits.
38562- *
38563- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38564- * credit_entropy_bits() needs to be 64 bits wide.
38565 */
38566 #define ENTROPY_SHIFT 3
38567 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38568@@ -361,12 +365,19 @@ static struct poolinfo {
38569 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38570 int tap1, tap2, tap3, tap4, tap5;
38571 } poolinfo_table[] = {
38572+#ifdef CONFIG_GRKERNSEC_RANDNET
38573+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38574+ { S(512), 411, 308, 208, 104, 1 },
38575+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38576+ { S(128), 104, 76, 51, 25, 1 },
38577+#else
38578 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38579 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38580 { S(128), 104, 76, 51, 25, 1 },
38581 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38582 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38583 { S(32), 26, 19, 14, 7, 1 },
38584+#endif
38585 #if 0
38586 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38587 { S(2048), 1638, 1231, 819, 411, 1 },
38588@@ -433,9 +444,9 @@ struct entropy_store {
38589 };
38590
38591 static void push_to_pool(struct work_struct *work);
38592-static __u32 input_pool_data[INPUT_POOL_WORDS];
38593-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38594-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38595+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38596+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38597+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38598
38599 static struct entropy_store input_pool = {
38600 .poolinfo = &poolinfo_table[0],
38601@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38602 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38603 }
38604
38605- ACCESS_ONCE(r->input_rotate) = input_rotate;
38606- ACCESS_ONCE(r->add_ptr) = i;
38607+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38608+ ACCESS_ONCE_RW(r->add_ptr) = i;
38609 smp_wmb();
38610
38611 if (out)
38612@@ -632,7 +643,7 @@ retry:
38613 /* The +2 corresponds to the /4 in the denominator */
38614
38615 do {
38616- unsigned int anfrac = min(pnfrac, pool_size/2);
38617+ u64 anfrac = min(pnfrac, pool_size/2);
38618 unsigned int add =
38619 ((pool_size - entropy_count)*anfrac*3) >> s;
38620
38621@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38622
38623 extract_buf(r, tmp);
38624 i = min_t(int, nbytes, EXTRACT_SIZE);
38625- if (copy_to_user(buf, tmp, i)) {
38626+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38627 ret = -EFAULT;
38628 break;
38629 }
38630@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38631 #include <linux/sysctl.h>
38632
38633 static int min_read_thresh = 8, min_write_thresh;
38634-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38635+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38636 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38637 static char sysctl_bootid[16];
38638
38639@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38640 static int proc_do_uuid(struct ctl_table *table, int write,
38641 void __user *buffer, size_t *lenp, loff_t *ppos)
38642 {
38643- struct ctl_table fake_table;
38644+ ctl_table_no_const fake_table;
38645 unsigned char buf[64], tmp_uuid[16], *uuid;
38646
38647 uuid = table->data;
38648@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38649 static int proc_do_entropy(ctl_table *table, int write,
38650 void __user *buffer, size_t *lenp, loff_t *ppos)
38651 {
38652- ctl_table fake_table;
38653+ ctl_table_no_const fake_table;
38654 int entropy_count;
38655
38656 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38657diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38658index 7cc1fe22..b602d6b 100644
38659--- a/drivers/char/sonypi.c
38660+++ b/drivers/char/sonypi.c
38661@@ -54,6 +54,7 @@
38662
38663 #include <asm/uaccess.h>
38664 #include <asm/io.h>
38665+#include <asm/local.h>
38666
38667 #include <linux/sonypi.h>
38668
38669@@ -490,7 +491,7 @@ static struct sonypi_device {
38670 spinlock_t fifo_lock;
38671 wait_queue_head_t fifo_proc_list;
38672 struct fasync_struct *fifo_async;
38673- int open_count;
38674+ local_t open_count;
38675 int model;
38676 struct input_dev *input_jog_dev;
38677 struct input_dev *input_key_dev;
38678@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38679 static int sonypi_misc_release(struct inode *inode, struct file *file)
38680 {
38681 mutex_lock(&sonypi_device.lock);
38682- sonypi_device.open_count--;
38683+ local_dec(&sonypi_device.open_count);
38684 mutex_unlock(&sonypi_device.lock);
38685 return 0;
38686 }
38687@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38688 {
38689 mutex_lock(&sonypi_device.lock);
38690 /* Flush input queue on first open */
38691- if (!sonypi_device.open_count)
38692+ if (!local_read(&sonypi_device.open_count))
38693 kfifo_reset(&sonypi_device.fifo);
38694- sonypi_device.open_count++;
38695+ local_inc(&sonypi_device.open_count);
38696 mutex_unlock(&sonypi_device.lock);
38697
38698 return 0;
38699diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38700index b9a57fa..5bb9e38 100644
38701--- a/drivers/char/tpm/tpm_acpi.c
38702+++ b/drivers/char/tpm/tpm_acpi.c
38703@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38704 virt = acpi_os_map_memory(start, len);
38705 if (!virt) {
38706 kfree(log->bios_event_log);
38707+ log->bios_event_log = NULL;
38708 printk("%s: ERROR - Unable to map memory\n", __func__);
38709 return -EIO;
38710 }
38711
38712- memcpy_fromio(log->bios_event_log, virt, len);
38713+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38714
38715 acpi_os_unmap_memory(virt, len);
38716 return 0;
38717diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38718index 59f7cb2..bac8b6d 100644
38719--- a/drivers/char/tpm/tpm_eventlog.c
38720+++ b/drivers/char/tpm/tpm_eventlog.c
38721@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38722 event = addr;
38723
38724 if ((event->event_type == 0 && event->event_size == 0) ||
38725- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38726+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38727 return NULL;
38728
38729 return addr;
38730@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38731 return NULL;
38732
38733 if ((event->event_type == 0 && event->event_size == 0) ||
38734- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38735+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38736 return NULL;
38737
38738 (*pos)++;
38739@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38740 int i;
38741
38742 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38743- seq_putc(m, data[i]);
38744+ if (!seq_putc(m, data[i]))
38745+ return -EFAULT;
38746
38747 return 0;
38748 }
38749diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38750index 6928d09..ff6abe8 100644
38751--- a/drivers/char/virtio_console.c
38752+++ b/drivers/char/virtio_console.c
38753@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38754 if (to_user) {
38755 ssize_t ret;
38756
38757- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38758+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38759 if (ret)
38760 return -EFAULT;
38761 } else {
38762@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38763 if (!port_has_data(port) && !port->host_connected)
38764 return 0;
38765
38766- return fill_readbuf(port, ubuf, count, true);
38767+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38768 }
38769
38770 static int wait_port_writable(struct port *port, bool nonblock)
38771diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38772index 57a078e..c17cde8 100644
38773--- a/drivers/clk/clk-composite.c
38774+++ b/drivers/clk/clk-composite.c
38775@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38776 struct clk *clk;
38777 struct clk_init_data init;
38778 struct clk_composite *composite;
38779- struct clk_ops *clk_composite_ops;
38780+ clk_ops_no_const *clk_composite_ops;
38781
38782 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38783 if (!composite) {
38784diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38785index 5983a26..65d5f46 100644
38786--- a/drivers/clk/socfpga/clk.c
38787+++ b/drivers/clk/socfpga/clk.c
38788@@ -22,6 +22,7 @@
38789 #include <linux/clk-provider.h>
38790 #include <linux/io.h>
38791 #include <linux/of.h>
38792+#include <asm/pgtable.h>
38793
38794 /* Clock Manager offsets */
38795 #define CLKMGR_CTRL 0x0
38796@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38797 streq(clk_name, "periph_pll") ||
38798 streq(clk_name, "sdram_pll")) {
38799 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38800- clk_pll_ops.enable = clk_gate_ops.enable;
38801- clk_pll_ops.disable = clk_gate_ops.disable;
38802+ pax_open_kernel();
38803+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38804+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38805+ pax_close_kernel();
38806 }
38807
38808 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38809@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38810 return parent_rate / div;
38811 }
38812
38813-static struct clk_ops gateclk_ops = {
38814+static clk_ops_no_const gateclk_ops __read_only = {
38815 .recalc_rate = socfpga_clk_recalc_rate,
38816 .get_parent = socfpga_clk_get_parent,
38817 .set_parent = socfpga_clk_set_parent,
38818diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38819index 18448a7..d5fad43 100644
38820--- a/drivers/cpufreq/acpi-cpufreq.c
38821+++ b/drivers/cpufreq/acpi-cpufreq.c
38822@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38823 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38824 per_cpu(acfreq_data, cpu) = data;
38825
38826- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38827- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38828+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38829+ pax_open_kernel();
38830+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38831+ pax_close_kernel();
38832+ }
38833
38834 result = acpi_processor_register_performance(data->acpi_data, cpu);
38835 if (result)
38836@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38837 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38838 break;
38839 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38840- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38841+ pax_open_kernel();
38842+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38843+ pax_close_kernel();
38844 break;
38845 default:
38846 break;
38847@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38848 if (!msrs)
38849 return;
38850
38851- acpi_cpufreq_driver.boost_supported = true;
38852- acpi_cpufreq_driver.boost_enabled = boost_state(0);
38853+ pax_open_kernel();
38854+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38855+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38856+ pax_close_kernel();
38857 get_online_cpus();
38858
38859 /* Force all MSRs to the same value */
38860diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38861index 199b52b..e3503bb 100644
38862--- a/drivers/cpufreq/cpufreq.c
38863+++ b/drivers/cpufreq/cpufreq.c
38864@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38865 #endif
38866
38867 mutex_lock(&cpufreq_governor_mutex);
38868- list_del(&governor->governor_list);
38869+ pax_list_del(&governor->governor_list);
38870 mutex_unlock(&cpufreq_governor_mutex);
38871 return;
38872 }
38873@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38874 return NOTIFY_OK;
38875 }
38876
38877-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38878+static struct notifier_block cpufreq_cpu_notifier = {
38879 .notifier_call = cpufreq_cpu_callback,
38880 };
38881
38882@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38883 return 0;
38884
38885 write_lock_irqsave(&cpufreq_driver_lock, flags);
38886- cpufreq_driver->boost_enabled = state;
38887+ pax_open_kernel();
38888+ *(bool *)&cpufreq_driver->boost_enabled = state;
38889+ pax_close_kernel();
38890 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38891
38892 ret = cpufreq_driver->set_boost(state);
38893 if (ret) {
38894 write_lock_irqsave(&cpufreq_driver_lock, flags);
38895- cpufreq_driver->boost_enabled = !state;
38896+ pax_open_kernel();
38897+ *(bool *)&cpufreq_driver->boost_enabled = !state;
38898+ pax_close_kernel();
38899 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38900
38901 pr_err("%s: Cannot %s BOOST\n", __func__,
38902@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38903
38904 pr_debug("trying to register driver %s\n", driver_data->name);
38905
38906- if (driver_data->setpolicy)
38907- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38908+ if (driver_data->setpolicy) {
38909+ pax_open_kernel();
38910+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38911+ pax_close_kernel();
38912+ }
38913
38914 write_lock_irqsave(&cpufreq_driver_lock, flags);
38915 if (cpufreq_driver) {
38916@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38917 * Check if driver provides function to enable boost -
38918 * if not, use cpufreq_boost_set_sw as default
38919 */
38920- if (!cpufreq_driver->set_boost)
38921- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38922+ if (!cpufreq_driver->set_boost) {
38923+ pax_open_kernel();
38924+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38925+ pax_close_kernel();
38926+ }
38927
38928 ret = cpufreq_sysfs_create_file(&boost.attr);
38929 if (ret) {
38930diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38931index ba43991..23858ffb 100644
38932--- a/drivers/cpufreq/cpufreq_governor.c
38933+++ b/drivers/cpufreq/cpufreq_governor.c
38934@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38935 struct dbs_data *dbs_data;
38936 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38937 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38938- struct od_ops *od_ops = NULL;
38939+ const struct od_ops *od_ops = NULL;
38940 struct od_dbs_tuners *od_tuners = NULL;
38941 struct cs_dbs_tuners *cs_tuners = NULL;
38942 struct cpu_dbs_common_info *cpu_cdbs;
38943@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38944
38945 if ((cdata->governor == GOV_CONSERVATIVE) &&
38946 (!policy->governor->initialized)) {
38947- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38948+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38949
38950 cpufreq_register_notifier(cs_ops->notifier_block,
38951 CPUFREQ_TRANSITION_NOTIFIER);
38952@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38953
38954 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38955 (policy->governor->initialized == 1)) {
38956- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38957+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38958
38959 cpufreq_unregister_notifier(cs_ops->notifier_block,
38960 CPUFREQ_TRANSITION_NOTIFIER);
38961diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38962index bfb9ae1..e1d3a7e 100644
38963--- a/drivers/cpufreq/cpufreq_governor.h
38964+++ b/drivers/cpufreq/cpufreq_governor.h
38965@@ -205,7 +205,7 @@ struct common_dbs_data {
38966 void (*exit)(struct dbs_data *dbs_data);
38967
38968 /* Governor specific ops, see below */
38969- void *gov_ops;
38970+ const void *gov_ops;
38971 };
38972
38973 /* Governor Per policy data */
38974@@ -225,7 +225,7 @@ struct od_ops {
38975 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38976 unsigned int freq_next, unsigned int relation);
38977 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38978-};
38979+} __no_const;
38980
38981 struct cs_ops {
38982 struct notifier_block *notifier_block;
38983diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38984index 18d4091..434be15 100644
38985--- a/drivers/cpufreq/cpufreq_ondemand.c
38986+++ b/drivers/cpufreq/cpufreq_ondemand.c
38987@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38988
38989 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38990
38991-static struct od_ops od_ops = {
38992+static struct od_ops od_ops __read_only = {
38993 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38994 .powersave_bias_target = generic_powersave_bias_target,
38995 .freq_increase = dbs_freq_increase,
38996@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38997 (struct cpufreq_policy *, unsigned int, unsigned int),
38998 unsigned int powersave_bias)
38999 {
39000- od_ops.powersave_bias_target = f;
39001+ pax_open_kernel();
39002+ *(void **)&od_ops.powersave_bias_target = f;
39003+ pax_close_kernel();
39004 od_set_powersave_bias(powersave_bias);
39005 }
39006 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39007
39008 void od_unregister_powersave_bias_handler(void)
39009 {
39010- od_ops.powersave_bias_target = generic_powersave_bias_target;
39011+ pax_open_kernel();
39012+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39013+ pax_close_kernel();
39014 od_set_powersave_bias(0);
39015 }
39016 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39017diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39018index 2cd36b9..8f07fae 100644
39019--- a/drivers/cpufreq/intel_pstate.c
39020+++ b/drivers/cpufreq/intel_pstate.c
39021@@ -124,10 +124,10 @@ struct pstate_funcs {
39022 struct cpu_defaults {
39023 struct pstate_adjust_policy pid_policy;
39024 struct pstate_funcs funcs;
39025-};
39026+} __do_const;
39027
39028 static struct pstate_adjust_policy pid_params;
39029-static struct pstate_funcs pstate_funcs;
39030+static struct pstate_funcs *pstate_funcs;
39031
39032 struct perf_limits {
39033 int no_turbo;
39034@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39035
39036 cpu->pstate.current_pstate = pstate;
39037
39038- pstate_funcs.set(cpu, pstate);
39039+ pstate_funcs->set(cpu, pstate);
39040 }
39041
39042 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39043@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39044 {
39045 sprintf(cpu->name, "Intel 2nd generation core");
39046
39047- cpu->pstate.min_pstate = pstate_funcs.get_min();
39048- cpu->pstate.max_pstate = pstate_funcs.get_max();
39049- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39050+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39051+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39052+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39053
39054- if (pstate_funcs.get_vid)
39055- pstate_funcs.get_vid(cpu);
39056+ if (pstate_funcs->get_vid)
39057+ pstate_funcs->get_vid(cpu);
39058
39059 /*
39060 * goto max pstate so we don't slow up boot if we are built-in if we are
39061@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39062 rdmsrl(MSR_IA32_APERF, aperf);
39063 rdmsrl(MSR_IA32_MPERF, mperf);
39064
39065- if (!pstate_funcs.get_max() ||
39066- !pstate_funcs.get_min() ||
39067- !pstate_funcs.get_turbo())
39068+ if (!pstate_funcs->get_max() ||
39069+ !pstate_funcs->get_min() ||
39070+ !pstate_funcs->get_turbo())
39071 return -ENODEV;
39072
39073 rdmsrl(MSR_IA32_APERF, tmp);
39074@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39075 return 0;
39076 }
39077
39078-static void copy_pid_params(struct pstate_adjust_policy *policy)
39079+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39080 {
39081 pid_params.sample_rate_ms = policy->sample_rate_ms;
39082 pid_params.p_gain_pct = policy->p_gain_pct;
39083@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39084
39085 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39086 {
39087- pstate_funcs.get_max = funcs->get_max;
39088- pstate_funcs.get_min = funcs->get_min;
39089- pstate_funcs.get_turbo = funcs->get_turbo;
39090- pstate_funcs.set = funcs->set;
39091- pstate_funcs.get_vid = funcs->get_vid;
39092+ pstate_funcs = funcs;
39093 }
39094
39095 #if IS_ENABLED(CONFIG_ACPI)
39096diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39097index 3d1cba9..0ab21d2 100644
39098--- a/drivers/cpufreq/p4-clockmod.c
39099+++ b/drivers/cpufreq/p4-clockmod.c
39100@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39101 case 0x0F: /* Core Duo */
39102 case 0x16: /* Celeron Core */
39103 case 0x1C: /* Atom */
39104- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39105+ pax_open_kernel();
39106+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39107+ pax_close_kernel();
39108 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39109 case 0x0D: /* Pentium M (Dothan) */
39110- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39111+ pax_open_kernel();
39112+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39113+ pax_close_kernel();
39114 /* fall through */
39115 case 0x09: /* Pentium M (Banias) */
39116 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39117@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39118
39119 /* on P-4s, the TSC runs with constant frequency independent whether
39120 * throttling is active or not. */
39121- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39122+ pax_open_kernel();
39123+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39124+ pax_close_kernel();
39125
39126 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39127 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39128diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39129index 724ffbd..ad83692 100644
39130--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39131+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39132@@ -18,14 +18,12 @@
39133 #include <asm/head.h>
39134 #include <asm/timer.h>
39135
39136-static struct cpufreq_driver *cpufreq_us3_driver;
39137-
39138 struct us3_freq_percpu_info {
39139 struct cpufreq_frequency_table table[4];
39140 };
39141
39142 /* Indexed by cpu number. */
39143-static struct us3_freq_percpu_info *us3_freq_table;
39144+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39145
39146 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39147 * in the Safari config register.
39148@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39149
39150 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39151 {
39152- if (cpufreq_us3_driver) {
39153- cpufreq_frequency_table_put_attr(policy->cpu);
39154- us3_freq_target(policy, 0);
39155- }
39156+ cpufreq_frequency_table_put_attr(policy->cpu);
39157+ us3_freq_target(policy, 0);
39158
39159 return 0;
39160 }
39161
39162+static int __init us3_freq_init(void);
39163+static void __exit us3_freq_exit(void);
39164+
39165+static struct cpufreq_driver cpufreq_us3_driver = {
39166+ .init = us3_freq_cpu_init,
39167+ .verify = cpufreq_generic_frequency_table_verify,
39168+ .target_index = us3_freq_target,
39169+ .get = us3_freq_get,
39170+ .exit = us3_freq_cpu_exit,
39171+ .owner = THIS_MODULE,
39172+ .name = "UltraSPARC-III",
39173+
39174+};
39175+
39176 static int __init us3_freq_init(void)
39177 {
39178 unsigned long manuf, impl, ver;
39179@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39180 (impl == CHEETAH_IMPL ||
39181 impl == CHEETAH_PLUS_IMPL ||
39182 impl == JAGUAR_IMPL ||
39183- impl == PANTHER_IMPL)) {
39184- struct cpufreq_driver *driver;
39185-
39186- ret = -ENOMEM;
39187- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39188- if (!driver)
39189- goto err_out;
39190-
39191- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39192- GFP_KERNEL);
39193- if (!us3_freq_table)
39194- goto err_out;
39195-
39196- driver->init = us3_freq_cpu_init;
39197- driver->verify = cpufreq_generic_frequency_table_verify;
39198- driver->target_index = us3_freq_target;
39199- driver->get = us3_freq_get;
39200- driver->exit = us3_freq_cpu_exit;
39201- strcpy(driver->name, "UltraSPARC-III");
39202-
39203- cpufreq_us3_driver = driver;
39204- ret = cpufreq_register_driver(driver);
39205- if (ret)
39206- goto err_out;
39207-
39208- return 0;
39209-
39210-err_out:
39211- if (driver) {
39212- kfree(driver);
39213- cpufreq_us3_driver = NULL;
39214- }
39215- kfree(us3_freq_table);
39216- us3_freq_table = NULL;
39217- return ret;
39218- }
39219+ impl == PANTHER_IMPL))
39220+ return cpufreq_register_driver(&cpufreq_us3_driver);
39221
39222 return -ENODEV;
39223 }
39224
39225 static void __exit us3_freq_exit(void)
39226 {
39227- if (cpufreq_us3_driver) {
39228- cpufreq_unregister_driver(cpufreq_us3_driver);
39229- kfree(cpufreq_us3_driver);
39230- cpufreq_us3_driver = NULL;
39231- kfree(us3_freq_table);
39232- us3_freq_table = NULL;
39233- }
39234+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39235 }
39236
39237 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39238diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39239index 4e1daca..e707b61 100644
39240--- a/drivers/cpufreq/speedstep-centrino.c
39241+++ b/drivers/cpufreq/speedstep-centrino.c
39242@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39243 !cpu_has(cpu, X86_FEATURE_EST))
39244 return -ENODEV;
39245
39246- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39247- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39248+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39249+ pax_open_kernel();
39250+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39251+ pax_close_kernel();
39252+ }
39253
39254 if (policy->cpu != 0)
39255 return -ENODEV;
39256diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39257index 06dbe7c..c2c8671 100644
39258--- a/drivers/cpuidle/driver.c
39259+++ b/drivers/cpuidle/driver.c
39260@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39261
39262 static void poll_idle_init(struct cpuidle_driver *drv)
39263 {
39264- struct cpuidle_state *state = &drv->states[0];
39265+ cpuidle_state_no_const *state = &drv->states[0];
39266
39267 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39268 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39269diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39270index ca89412..a7b9c49 100644
39271--- a/drivers/cpuidle/governor.c
39272+++ b/drivers/cpuidle/governor.c
39273@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39274 mutex_lock(&cpuidle_lock);
39275 if (__cpuidle_find_governor(gov->name) == NULL) {
39276 ret = 0;
39277- list_add_tail(&gov->governor_list, &cpuidle_governors);
39278+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39279 if (!cpuidle_curr_governor ||
39280 cpuidle_curr_governor->rating < gov->rating)
39281 cpuidle_switch_governor(gov);
39282diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39283index e918b6d..f87ea80 100644
39284--- a/drivers/cpuidle/sysfs.c
39285+++ b/drivers/cpuidle/sysfs.c
39286@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39287 NULL
39288 };
39289
39290-static struct attribute_group cpuidle_attr_group = {
39291+static attribute_group_no_const cpuidle_attr_group = {
39292 .attrs = cpuidle_default_attrs,
39293 .name = "cpuidle",
39294 };
39295diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39296index 12fea3e..1e28f47 100644
39297--- a/drivers/crypto/hifn_795x.c
39298+++ b/drivers/crypto/hifn_795x.c
39299@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39300 MODULE_PARM_DESC(hifn_pll_ref,
39301 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39302
39303-static atomic_t hifn_dev_number;
39304+static atomic_unchecked_t hifn_dev_number;
39305
39306 #define ACRYPTO_OP_DECRYPT 0
39307 #define ACRYPTO_OP_ENCRYPT 1
39308@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39309 goto err_out_disable_pci_device;
39310
39311 snprintf(name, sizeof(name), "hifn%d",
39312- atomic_inc_return(&hifn_dev_number)-1);
39313+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39314
39315 err = pci_request_regions(pdev, name);
39316 if (err)
39317diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39318index a0b2f7e..1b6f028 100644
39319--- a/drivers/devfreq/devfreq.c
39320+++ b/drivers/devfreq/devfreq.c
39321@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39322 goto err_out;
39323 }
39324
39325- list_add(&governor->node, &devfreq_governor_list);
39326+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39327
39328 list_for_each_entry(devfreq, &devfreq_list, node) {
39329 int ret = 0;
39330@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39331 }
39332 }
39333
39334- list_del(&governor->node);
39335+ pax_list_del((struct list_head *)&governor->node);
39336 err_out:
39337 mutex_unlock(&devfreq_list_lock);
39338
39339diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39340index 2e7b394..1371a64 100644
39341--- a/drivers/dma/sh/shdma-base.c
39342+++ b/drivers/dma/sh/shdma-base.c
39343@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39344 schan->slave_id = -EINVAL;
39345 }
39346
39347- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39348- sdev->desc_size, GFP_KERNEL);
39349+ schan->desc = kcalloc(sdev->desc_size,
39350+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39351 if (!schan->desc) {
39352 ret = -ENOMEM;
39353 goto edescalloc;
39354diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39355index 0d765c0..60b7480 100644
39356--- a/drivers/dma/sh/shdmac.c
39357+++ b/drivers/dma/sh/shdmac.c
39358@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39359 return ret;
39360 }
39361
39362-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39363+static struct notifier_block sh_dmae_nmi_notifier = {
39364 .notifier_call = sh_dmae_nmi_handler,
39365
39366 /* Run before NMI debug handler and KGDB */
39367diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39368index 592af5f..bb1d583 100644
39369--- a/drivers/edac/edac_device.c
39370+++ b/drivers/edac/edac_device.c
39371@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39372 */
39373 int edac_device_alloc_index(void)
39374 {
39375- static atomic_t device_indexes = ATOMIC_INIT(0);
39376+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39377
39378- return atomic_inc_return(&device_indexes) - 1;
39379+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39380 }
39381 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39382
39383diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39384index b335c6a..db65b44 100644
39385--- a/drivers/edac/edac_mc_sysfs.c
39386+++ b/drivers/edac/edac_mc_sysfs.c
39387@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39388 struct dev_ch_attribute {
39389 struct device_attribute attr;
39390 int channel;
39391-};
39392+} __do_const;
39393
39394 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39395 struct dev_ch_attribute dev_attr_legacy_##_name = \
39396@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39397 }
39398
39399 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39400+ pax_open_kernel();
39401 if (mci->get_sdram_scrub_rate) {
39402- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39403- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39404+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39405+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39406 }
39407 if (mci->set_sdram_scrub_rate) {
39408- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39409- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39410+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39411+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39412 }
39413+ pax_close_kernel();
39414 err = device_create_file(&mci->dev,
39415 &dev_attr_sdram_scrub_rate);
39416 if (err) {
39417diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39418index 2cf44b4d..6dd2dc7 100644
39419--- a/drivers/edac/edac_pci.c
39420+++ b/drivers/edac/edac_pci.c
39421@@ -29,7 +29,7 @@
39422
39423 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39424 static LIST_HEAD(edac_pci_list);
39425-static atomic_t pci_indexes = ATOMIC_INIT(0);
39426+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39427
39428 /*
39429 * edac_pci_alloc_ctl_info
39430@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39431 */
39432 int edac_pci_alloc_index(void)
39433 {
39434- return atomic_inc_return(&pci_indexes) - 1;
39435+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39436 }
39437 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39438
39439diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39440index e8658e4..22746d6 100644
39441--- a/drivers/edac/edac_pci_sysfs.c
39442+++ b/drivers/edac/edac_pci_sysfs.c
39443@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39444 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39445 static int edac_pci_poll_msec = 1000; /* one second workq period */
39446
39447-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39448-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39449+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39450+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39451
39452 static struct kobject *edac_pci_top_main_kobj;
39453 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39454@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39455 void *value;
39456 ssize_t(*show) (void *, char *);
39457 ssize_t(*store) (void *, const char *, size_t);
39458-};
39459+} __do_const;
39460
39461 /* Set of show/store abstract level functions for PCI Parity object */
39462 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39463@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39464 edac_printk(KERN_CRIT, EDAC_PCI,
39465 "Signaled System Error on %s\n",
39466 pci_name(dev));
39467- atomic_inc(&pci_nonparity_count);
39468+ atomic_inc_unchecked(&pci_nonparity_count);
39469 }
39470
39471 if (status & (PCI_STATUS_PARITY)) {
39472@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39473 "Master Data Parity Error on %s\n",
39474 pci_name(dev));
39475
39476- atomic_inc(&pci_parity_count);
39477+ atomic_inc_unchecked(&pci_parity_count);
39478 }
39479
39480 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39481@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39482 "Detected Parity Error on %s\n",
39483 pci_name(dev));
39484
39485- atomic_inc(&pci_parity_count);
39486+ atomic_inc_unchecked(&pci_parity_count);
39487 }
39488 }
39489
39490@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39491 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39492 "Signaled System Error on %s\n",
39493 pci_name(dev));
39494- atomic_inc(&pci_nonparity_count);
39495+ atomic_inc_unchecked(&pci_nonparity_count);
39496 }
39497
39498 if (status & (PCI_STATUS_PARITY)) {
39499@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39500 "Master Data Parity Error on "
39501 "%s\n", pci_name(dev));
39502
39503- atomic_inc(&pci_parity_count);
39504+ atomic_inc_unchecked(&pci_parity_count);
39505 }
39506
39507 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39508@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39509 "Detected Parity Error on %s\n",
39510 pci_name(dev));
39511
39512- atomic_inc(&pci_parity_count);
39513+ atomic_inc_unchecked(&pci_parity_count);
39514 }
39515 }
39516 }
39517@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39518 if (!check_pci_errors)
39519 return;
39520
39521- before_count = atomic_read(&pci_parity_count);
39522+ before_count = atomic_read_unchecked(&pci_parity_count);
39523
39524 /* scan all PCI devices looking for a Parity Error on devices and
39525 * bridges.
39526@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39527 /* Only if operator has selected panic on PCI Error */
39528 if (edac_pci_get_panic_on_pe()) {
39529 /* If the count is different 'after' from 'before' */
39530- if (before_count != atomic_read(&pci_parity_count))
39531+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39532 panic("EDAC: PCI Parity Error");
39533 }
39534 }
39535diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39536index 51b7e3a..aa8a3e8 100644
39537--- a/drivers/edac/mce_amd.h
39538+++ b/drivers/edac/mce_amd.h
39539@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39540 bool (*mc0_mce)(u16, u8);
39541 bool (*mc1_mce)(u16, u8);
39542 bool (*mc2_mce)(u16, u8);
39543-};
39544+} __no_const;
39545
39546 void amd_report_gart_errors(bool);
39547 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39548diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39549index 57ea7f4..af06b76 100644
39550--- a/drivers/firewire/core-card.c
39551+++ b/drivers/firewire/core-card.c
39552@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39553 const struct fw_card_driver *driver,
39554 struct device *device)
39555 {
39556- static atomic_t index = ATOMIC_INIT(-1);
39557+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39558
39559- card->index = atomic_inc_return(&index);
39560+ card->index = atomic_inc_return_unchecked(&index);
39561 card->driver = driver;
39562 card->device = device;
39563 card->current_tlabel = 0;
39564@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39565
39566 void fw_core_remove_card(struct fw_card *card)
39567 {
39568- struct fw_card_driver dummy_driver = dummy_driver_template;
39569+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39570
39571 card->driver->update_phy_reg(card, 4,
39572 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39573diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39574index 2c6d5e1..a2cca6b 100644
39575--- a/drivers/firewire/core-device.c
39576+++ b/drivers/firewire/core-device.c
39577@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39578 struct config_rom_attribute {
39579 struct device_attribute attr;
39580 u32 key;
39581-};
39582+} __do_const;
39583
39584 static ssize_t show_immediate(struct device *dev,
39585 struct device_attribute *dattr, char *buf)
39586diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39587index eb6935c..3cc2bfa 100644
39588--- a/drivers/firewire/core-transaction.c
39589+++ b/drivers/firewire/core-transaction.c
39590@@ -38,6 +38,7 @@
39591 #include <linux/timer.h>
39592 #include <linux/types.h>
39593 #include <linux/workqueue.h>
39594+#include <linux/sched.h>
39595
39596 #include <asm/byteorder.h>
39597
39598diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39599index c98764a..551b520 100644
39600--- a/drivers/firewire/core.h
39601+++ b/drivers/firewire/core.h
39602@@ -111,6 +111,7 @@ struct fw_card_driver {
39603
39604 int (*stop_iso)(struct fw_iso_context *ctx);
39605 };
39606+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39607
39608 void fw_card_initialize(struct fw_card *card,
39609 const struct fw_card_driver *driver, struct device *device);
39610diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39611index 8db6632..9bbc8ca 100644
39612--- a/drivers/firewire/ohci.c
39613+++ b/drivers/firewire/ohci.c
39614@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39615 be32_to_cpu(ohci->next_header));
39616 }
39617
39618+#ifndef CONFIG_GRKERNSEC
39619 if (param_remote_dma) {
39620 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39621 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39622 }
39623+#endif
39624
39625 spin_unlock_irq(&ohci->lock);
39626
39627@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39628 unsigned long flags;
39629 int n, ret = 0;
39630
39631+#ifndef CONFIG_GRKERNSEC
39632 if (param_remote_dma)
39633 return 0;
39634+#endif
39635
39636 /*
39637 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39638diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39639index 94a58a0..f5eba42 100644
39640--- a/drivers/firmware/dmi-id.c
39641+++ b/drivers/firmware/dmi-id.c
39642@@ -16,7 +16,7 @@
39643 struct dmi_device_attribute{
39644 struct device_attribute dev_attr;
39645 int field;
39646-};
39647+} __do_const;
39648 #define to_dmi_dev_attr(_dev_attr) \
39649 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39650
39651diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39652index 17afc51..0ef90cd 100644
39653--- a/drivers/firmware/dmi_scan.c
39654+++ b/drivers/firmware/dmi_scan.c
39655@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39656 if (buf == NULL)
39657 return -1;
39658
39659- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39660+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39661
39662 dmi_unmap(buf);
39663 return 0;
39664diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39665index 1491dd4..aa910db 100644
39666--- a/drivers/firmware/efi/cper.c
39667+++ b/drivers/firmware/efi/cper.c
39668@@ -41,12 +41,12 @@
39669 */
39670 u64 cper_next_record_id(void)
39671 {
39672- static atomic64_t seq;
39673+ static atomic64_unchecked_t seq;
39674
39675- if (!atomic64_read(&seq))
39676- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39677+ if (!atomic64_read_unchecked(&seq))
39678+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39679
39680- return atomic64_inc_return(&seq);
39681+ return atomic64_inc_return_unchecked(&seq);
39682 }
39683 EXPORT_SYMBOL_GPL(cper_next_record_id);
39684
39685diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39686index 4753bac..02861a2 100644
39687--- a/drivers/firmware/efi/efi.c
39688+++ b/drivers/firmware/efi/efi.c
39689@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39690 };
39691
39692 static struct efivars generic_efivars;
39693-static struct efivar_operations generic_ops;
39694+static efivar_operations_no_const generic_ops __read_only;
39695
39696 static int generic_ops_register(void)
39697 {
39698- generic_ops.get_variable = efi.get_variable;
39699- generic_ops.set_variable = efi.set_variable;
39700- generic_ops.get_next_variable = efi.get_next_variable;
39701- generic_ops.query_variable_store = efi_query_variable_store;
39702+ pax_open_kernel();
39703+ *(void **)&generic_ops.get_variable = efi.get_variable;
39704+ *(void **)&generic_ops.set_variable = efi.set_variable;
39705+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39706+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39707+ pax_close_kernel();
39708
39709 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39710 }
39711diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39712index 3dc2482..7bd2f61 100644
39713--- a/drivers/firmware/efi/efivars.c
39714+++ b/drivers/firmware/efi/efivars.c
39715@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39716 static int
39717 create_efivars_bin_attributes(void)
39718 {
39719- struct bin_attribute *attr;
39720+ bin_attribute_no_const *attr;
39721 int error;
39722
39723 /* new_var */
39724diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39725index 2a90ba6..07f3733 100644
39726--- a/drivers/firmware/google/memconsole.c
39727+++ b/drivers/firmware/google/memconsole.c
39728@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39729 if (!found_memconsole())
39730 return -ENODEV;
39731
39732- memconsole_bin_attr.size = memconsole_length;
39733+ pax_open_kernel();
39734+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39735+ pax_close_kernel();
39736
39737 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39738
39739diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39740index 1e98a98..b444372 100644
39741--- a/drivers/gpio/gpio-em.c
39742+++ b/drivers/gpio/gpio-em.c
39743@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39744 struct em_gio_priv *p;
39745 struct resource *io[2], *irq[2];
39746 struct gpio_chip *gpio_chip;
39747- struct irq_chip *irq_chip;
39748+ irq_chip_no_const *irq_chip;
39749 const char *name = dev_name(&pdev->dev);
39750 int ret;
39751
39752diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39753index f5bf3c3..7baaa59 100644
39754--- a/drivers/gpio/gpio-ich.c
39755+++ b/drivers/gpio/gpio-ich.c
39756@@ -71,7 +71,7 @@ struct ichx_desc {
39757 /* Some chipsets have quirks, let these use their own request/get */
39758 int (*request)(struct gpio_chip *chip, unsigned offset);
39759 int (*get)(struct gpio_chip *chip, unsigned offset);
39760-};
39761+} __do_const;
39762
39763 static struct {
39764 spinlock_t lock;
39765diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39766index ca76ce7..68b384b 100644
39767--- a/drivers/gpio/gpio-rcar.c
39768+++ b/drivers/gpio/gpio-rcar.c
39769@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39770 struct gpio_rcar_priv *p;
39771 struct resource *io, *irq;
39772 struct gpio_chip *gpio_chip;
39773- struct irq_chip *irq_chip;
39774+ irq_chip_no_const *irq_chip;
39775 const char *name = dev_name(&pdev->dev);
39776 int ret;
39777
39778diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39779index 9902732..64b62dd 100644
39780--- a/drivers/gpio/gpio-vr41xx.c
39781+++ b/drivers/gpio/gpio-vr41xx.c
39782@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39783 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39784 maskl, pendl, maskh, pendh);
39785
39786- atomic_inc(&irq_err_count);
39787+ atomic_inc_unchecked(&irq_err_count);
39788
39789 return -EINVAL;
39790 }
39791diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39792index 3b7d32d..05c2f74 100644
39793--- a/drivers/gpu/drm/drm_crtc.c
39794+++ b/drivers/gpu/drm/drm_crtc.c
39795@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39796 goto done;
39797 }
39798
39799- if (copy_to_user(&enum_ptr[copied].name,
39800+ if (copy_to_user(enum_ptr[copied].name,
39801 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39802 ret = -EFAULT;
39803 goto done;
39804diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39805index 345be03..158368d 100644
39806--- a/drivers/gpu/drm/drm_drv.c
39807+++ b/drivers/gpu/drm/drm_drv.c
39808@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39809 /**
39810 * Copy and IOCTL return string to user space
39811 */
39812-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39813+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39814 {
39815 int len;
39816
39817@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39818 struct drm_file *file_priv = filp->private_data;
39819 struct drm_device *dev;
39820 const struct drm_ioctl_desc *ioctl = NULL;
39821- drm_ioctl_t *func;
39822+ drm_ioctl_no_const_t func;
39823 unsigned int nr = DRM_IOCTL_NR(cmd);
39824 int retcode = -EINVAL;
39825 char stack_kdata[128];
39826diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39827index 7f2af9a..1561914 100644
39828--- a/drivers/gpu/drm/drm_fops.c
39829+++ b/drivers/gpu/drm/drm_fops.c
39830@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39831 if (drm_device_is_unplugged(dev))
39832 return -ENODEV;
39833
39834- if (!dev->open_count++)
39835+ if (local_inc_return(&dev->open_count) == 1)
39836 need_setup = 1;
39837 mutex_lock(&dev->struct_mutex);
39838 old_imapping = inode->i_mapping;
39839@@ -127,7 +127,7 @@ err_undo:
39840 iput(container_of(dev->dev_mapping, struct inode, i_data));
39841 dev->dev_mapping = old_mapping;
39842 mutex_unlock(&dev->struct_mutex);
39843- dev->open_count--;
39844+ local_dec(&dev->open_count);
39845 return retcode;
39846 }
39847 EXPORT_SYMBOL(drm_open);
39848@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39849
39850 mutex_lock(&drm_global_mutex);
39851
39852- DRM_DEBUG("open_count = %d\n", dev->open_count);
39853+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39854
39855 if (dev->driver->preclose)
39856 dev->driver->preclose(dev, file_priv);
39857@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39858 * Begin inline drm_release
39859 */
39860
39861- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39862+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39863 task_pid_nr(current),
39864 (long)old_encode_dev(file_priv->minor->device),
39865- dev->open_count);
39866+ local_read(&dev->open_count));
39867
39868 /* Release any auth tokens that might point to this file_priv,
39869 (do that under the drm_global_mutex) */
39870@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39871 * End inline drm_release
39872 */
39873
39874- if (!--dev->open_count) {
39875+ if (local_dec_and_test(&dev->open_count)) {
39876 retcode = drm_lastclose(dev);
39877 if (drm_device_is_unplugged(dev))
39878 drm_put_dev(dev);
39879diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39880index 3d2e91c..d31c4c9 100644
39881--- a/drivers/gpu/drm/drm_global.c
39882+++ b/drivers/gpu/drm/drm_global.c
39883@@ -36,7 +36,7 @@
39884 struct drm_global_item {
39885 struct mutex mutex;
39886 void *object;
39887- int refcount;
39888+ atomic_t refcount;
39889 };
39890
39891 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39892@@ -49,7 +49,7 @@ void drm_global_init(void)
39893 struct drm_global_item *item = &glob[i];
39894 mutex_init(&item->mutex);
39895 item->object = NULL;
39896- item->refcount = 0;
39897+ atomic_set(&item->refcount, 0);
39898 }
39899 }
39900
39901@@ -59,7 +59,7 @@ void drm_global_release(void)
39902 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39903 struct drm_global_item *item = &glob[i];
39904 BUG_ON(item->object != NULL);
39905- BUG_ON(item->refcount != 0);
39906+ BUG_ON(atomic_read(&item->refcount) != 0);
39907 }
39908 }
39909
39910@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39911 struct drm_global_item *item = &glob[ref->global_type];
39912
39913 mutex_lock(&item->mutex);
39914- if (item->refcount == 0) {
39915+ if (atomic_read(&item->refcount) == 0) {
39916 item->object = kzalloc(ref->size, GFP_KERNEL);
39917 if (unlikely(item->object == NULL)) {
39918 ret = -ENOMEM;
39919@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39920 goto out_err;
39921
39922 }
39923- ++item->refcount;
39924+ atomic_inc(&item->refcount);
39925 ref->object = item->object;
39926 mutex_unlock(&item->mutex);
39927 return 0;
39928@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39929 struct drm_global_item *item = &glob[ref->global_type];
39930
39931 mutex_lock(&item->mutex);
39932- BUG_ON(item->refcount == 0);
39933+ BUG_ON(atomic_read(&item->refcount) == 0);
39934 BUG_ON(ref->object != item->object);
39935- if (--item->refcount == 0) {
39936+ if (atomic_dec_and_test(&item->refcount)) {
39937 ref->release(ref);
39938 item->object = NULL;
39939 }
39940diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39941index 7473035..a48b9c5 100644
39942--- a/drivers/gpu/drm/drm_info.c
39943+++ b/drivers/gpu/drm/drm_info.c
39944@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
39945 struct drm_local_map *map;
39946 struct drm_map_list *r_list;
39947
39948- /* Hardcoded from _DRM_FRAME_BUFFER,
39949- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39950- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39951- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39952+ static const char * const types[] = {
39953+ [_DRM_FRAME_BUFFER] = "FB",
39954+ [_DRM_REGISTERS] = "REG",
39955+ [_DRM_SHM] = "SHM",
39956+ [_DRM_AGP] = "AGP",
39957+ [_DRM_SCATTER_GATHER] = "SG",
39958+ [_DRM_CONSISTENT] = "PCI"};
39959 const char *type;
39960 int i;
39961
39962@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39963 map = r_list->map;
39964 if (!map)
39965 continue;
39966- if (map->type < 0 || map->type > 5)
39967+ if (map->type >= ARRAY_SIZE(types))
39968 type = "??";
39969 else
39970 type = types[map->type];
39971@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39972 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39973 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39974 vma->vm_flags & VM_IO ? 'i' : '-',
39975+#ifdef CONFIG_GRKERNSEC_HIDESYM
39976+ 0);
39977+#else
39978 vma->vm_pgoff);
39979+#endif
39980
39981 #if defined(__i386__)
39982 pgprot = pgprot_val(vma->vm_page_prot);
39983diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39984index 2f4c4343..dd12cd2 100644
39985--- a/drivers/gpu/drm/drm_ioc32.c
39986+++ b/drivers/gpu/drm/drm_ioc32.c
39987@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39988 request = compat_alloc_user_space(nbytes);
39989 if (!access_ok(VERIFY_WRITE, request, nbytes))
39990 return -EFAULT;
39991- list = (struct drm_buf_desc *) (request + 1);
39992+ list = (struct drm_buf_desc __user *) (request + 1);
39993
39994 if (__put_user(count, &request->count)
39995 || __put_user(list, &request->list))
39996@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39997 request = compat_alloc_user_space(nbytes);
39998 if (!access_ok(VERIFY_WRITE, request, nbytes))
39999 return -EFAULT;
40000- list = (struct drm_buf_pub *) (request + 1);
40001+ list = (struct drm_buf_pub __user *) (request + 1);
40002
40003 if (__put_user(count, &request->count)
40004 || __put_user(list, &request->list))
40005@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40006 return 0;
40007 }
40008
40009-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40010+drm_ioctl_compat_t drm_compat_ioctls[] = {
40011 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40012 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40013 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40014@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40015 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40016 {
40017 unsigned int nr = DRM_IOCTL_NR(cmd);
40018- drm_ioctl_compat_t *fn;
40019 int ret;
40020
40021 /* Assume that ioctls without an explicit compat routine will just
40022@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40023 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40024 return drm_ioctl(filp, cmd, arg);
40025
40026- fn = drm_compat_ioctls[nr];
40027-
40028- if (fn != NULL)
40029- ret = (*fn) (filp, cmd, arg);
40030+ if (drm_compat_ioctls[nr] != NULL)
40031+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40032 else
40033 ret = drm_ioctl(filp, cmd, arg);
40034
40035diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40036index 98a33c580..8fd1c2b 100644
40037--- a/drivers/gpu/drm/drm_stub.c
40038+++ b/drivers/gpu/drm/drm_stub.c
40039@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40040
40041 drm_device_set_unplugged(dev);
40042
40043- if (dev->open_count == 0) {
40044+ if (local_read(&dev->open_count) == 0) {
40045 drm_put_dev(dev);
40046 }
40047 mutex_unlock(&drm_global_mutex);
40048diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40049index c22c309..ae758c3 100644
40050--- a/drivers/gpu/drm/drm_sysfs.c
40051+++ b/drivers/gpu/drm/drm_sysfs.c
40052@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40053 */
40054 int drm_sysfs_device_add(struct drm_minor *minor)
40055 {
40056- char *minor_str;
40057+ const char *minor_str;
40058 int r;
40059
40060 if (minor->type == DRM_MINOR_CONTROL)
40061diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40062index d4d16ed..8fb0b51 100644
40063--- a/drivers/gpu/drm/i810/i810_drv.h
40064+++ b/drivers/gpu/drm/i810/i810_drv.h
40065@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40066 int page_flipping;
40067
40068 wait_queue_head_t irq_queue;
40069- atomic_t irq_received;
40070- atomic_t irq_emitted;
40071+ atomic_unchecked_t irq_received;
40072+ atomic_unchecked_t irq_emitted;
40073
40074 int front_offset;
40075 } drm_i810_private_t;
40076diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40077index b2b46c5..feb9fe7 100644
40078--- a/drivers/gpu/drm/i915/i915_debugfs.c
40079+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40080@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40081 I915_READ(GTIMR));
40082 }
40083 seq_printf(m, "Interrupts received: %d\n",
40084- atomic_read(&dev_priv->irq_received));
40085+ atomic_read_unchecked(&dev_priv->irq_received));
40086 for_each_ring(ring, dev_priv, i) {
40087 if (INTEL_INFO(dev)->gen >= 6) {
40088 seq_printf(m,
40089diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40090index 15a74f9..4278889 100644
40091--- a/drivers/gpu/drm/i915/i915_dma.c
40092+++ b/drivers/gpu/drm/i915/i915_dma.c
40093@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40094 bool can_switch;
40095
40096 spin_lock(&dev->count_lock);
40097- can_switch = (dev->open_count == 0);
40098+ can_switch = (local_read(&dev->open_count) == 0);
40099 spin_unlock(&dev->count_lock);
40100 return can_switch;
40101 }
40102diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40103index df77e20..d3fda9f 100644
40104--- a/drivers/gpu/drm/i915/i915_drv.h
40105+++ b/drivers/gpu/drm/i915/i915_drv.h
40106@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40107 drm_dma_handle_t *status_page_dmah;
40108 struct resource mch_res;
40109
40110- atomic_t irq_received;
40111+ atomic_unchecked_t irq_received;
40112
40113 /* protects the irq masks */
40114 spinlock_t irq_lock;
40115diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40116index d269ecf..6d857bc 100644
40117--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40118+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40119@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40120
40121 static int
40122 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40123- int count)
40124+ unsigned int count)
40125 {
40126- int i;
40127+ unsigned int i;
40128 unsigned relocs_total = 0;
40129 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40130
40131diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40132index 3c59584..500f2e9 100644
40133--- a/drivers/gpu/drm/i915/i915_ioc32.c
40134+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40135@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40136 (unsigned long)request);
40137 }
40138
40139-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40140+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40141 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40142 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40143 [DRM_I915_GETPARAM] = compat_i915_getparam,
40144@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40145 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40146 {
40147 unsigned int nr = DRM_IOCTL_NR(cmd);
40148- drm_ioctl_compat_t *fn = NULL;
40149 int ret;
40150
40151 if (nr < DRM_COMMAND_BASE)
40152 return drm_compat_ioctl(filp, cmd, arg);
40153
40154- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40155- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40156-
40157- if (fn != NULL)
40158+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40159+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40160 ret = (*fn) (filp, cmd, arg);
40161- else
40162+ } else
40163 ret = drm_ioctl(filp, cmd, arg);
40164
40165 return ret;
40166diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40167index d554169..f4426bb 100644
40168--- a/drivers/gpu/drm/i915/i915_irq.c
40169+++ b/drivers/gpu/drm/i915/i915_irq.c
40170@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40171 int pipe;
40172 u32 pipe_stats[I915_MAX_PIPES];
40173
40174- atomic_inc(&dev_priv->irq_received);
40175+ atomic_inc_unchecked(&dev_priv->irq_received);
40176
40177 while (true) {
40178 iir = I915_READ(VLV_IIR);
40179@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40180 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40181 irqreturn_t ret = IRQ_NONE;
40182
40183- atomic_inc(&dev_priv->irq_received);
40184+ atomic_inc_unchecked(&dev_priv->irq_received);
40185
40186 /* We get interrupts on unclaimed registers, so check for this before we
40187 * do any I915_{READ,WRITE}. */
40188@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40189 uint32_t tmp = 0;
40190 enum pipe pipe;
40191
40192- atomic_inc(&dev_priv->irq_received);
40193+ atomic_inc_unchecked(&dev_priv->irq_received);
40194
40195 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40196 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40197@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40198 {
40199 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40200
40201- atomic_set(&dev_priv->irq_received, 0);
40202+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40203
40204 I915_WRITE(HWSTAM, 0xeffe);
40205
40206@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40207 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40208 int pipe;
40209
40210- atomic_set(&dev_priv->irq_received, 0);
40211+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40212
40213 /* VLV magic */
40214 I915_WRITE(VLV_IMR, 0);
40215@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40216 struct drm_i915_private *dev_priv = dev->dev_private;
40217 int pipe;
40218
40219- atomic_set(&dev_priv->irq_received, 0);
40220+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40221
40222 I915_WRITE(GEN8_MASTER_IRQ, 0);
40223 POSTING_READ(GEN8_MASTER_IRQ);
40224@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40225 if (!dev_priv)
40226 return;
40227
40228- atomic_set(&dev_priv->irq_received, 0);
40229+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40230
40231 I915_WRITE(GEN8_MASTER_IRQ, 0);
40232
40233@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40234 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40235 int pipe;
40236
40237- atomic_set(&dev_priv->irq_received, 0);
40238+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40239
40240 for_each_pipe(pipe)
40241 I915_WRITE(PIPESTAT(pipe), 0);
40242@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40243 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40244 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40245
40246- atomic_inc(&dev_priv->irq_received);
40247+ atomic_inc_unchecked(&dev_priv->irq_received);
40248
40249 iir = I915_READ16(IIR);
40250 if (iir == 0)
40251@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40252 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40253 int pipe;
40254
40255- atomic_set(&dev_priv->irq_received, 0);
40256+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40257
40258 if (I915_HAS_HOTPLUG(dev)) {
40259 I915_WRITE(PORT_HOTPLUG_EN, 0);
40260@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40261 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40262 int pipe, ret = IRQ_NONE;
40263
40264- atomic_inc(&dev_priv->irq_received);
40265+ atomic_inc_unchecked(&dev_priv->irq_received);
40266
40267 iir = I915_READ(IIR);
40268 do {
40269@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40270 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40271 int pipe;
40272
40273- atomic_set(&dev_priv->irq_received, 0);
40274+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40275
40276 I915_WRITE(PORT_HOTPLUG_EN, 0);
40277 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40278@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40279 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40280 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40281
40282- atomic_inc(&dev_priv->irq_received);
40283+ atomic_inc_unchecked(&dev_priv->irq_received);
40284
40285 iir = I915_READ(IIR);
40286
40287diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40288index 9b8a7c7..60f6003 100644
40289--- a/drivers/gpu/drm/i915/intel_display.c
40290+++ b/drivers/gpu/drm/i915/intel_display.c
40291@@ -10776,13 +10776,13 @@ struct intel_quirk {
40292 int subsystem_vendor;
40293 int subsystem_device;
40294 void (*hook)(struct drm_device *dev);
40295-};
40296+} __do_const;
40297
40298 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40299 struct intel_dmi_quirk {
40300 void (*hook)(struct drm_device *dev);
40301 const struct dmi_system_id (*dmi_id_list)[];
40302-};
40303+} __do_const;
40304
40305 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40306 {
40307@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40308 return 1;
40309 }
40310
40311-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40312+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40313 {
40314- .dmi_id_list = &(const struct dmi_system_id[]) {
40315- {
40316- .callback = intel_dmi_reverse_brightness,
40317- .ident = "NCR Corporation",
40318- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40319- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40320- },
40321- },
40322- { } /* terminating entry */
40323+ .callback = intel_dmi_reverse_brightness,
40324+ .ident = "NCR Corporation",
40325+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40326+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40327 },
40328+ },
40329+ { } /* terminating entry */
40330+};
40331+
40332+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40333+ {
40334+ .dmi_id_list = &intel_dmi_quirks_table,
40335 .hook = quirk_invert_brightness,
40336 },
40337 };
40338diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40339index fe45321..836fdca 100644
40340--- a/drivers/gpu/drm/mga/mga_drv.h
40341+++ b/drivers/gpu/drm/mga/mga_drv.h
40342@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40343 u32 clear_cmd;
40344 u32 maccess;
40345
40346- atomic_t vbl_received; /**< Number of vblanks received. */
40347+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40348 wait_queue_head_t fence_queue;
40349- atomic_t last_fence_retired;
40350+ atomic_unchecked_t last_fence_retired;
40351 u32 next_fence_to_post;
40352
40353 unsigned int fb_cpp;
40354diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40355index 86b4bb8..ae237ad 100644
40356--- a/drivers/gpu/drm/mga/mga_ioc32.c
40357+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40358@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40359 return 0;
40360 }
40361
40362-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40363+drm_ioctl_compat_t mga_compat_ioctls[] = {
40364 [DRM_MGA_INIT] = compat_mga_init,
40365 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40366 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40367@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40368 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40369 {
40370 unsigned int nr = DRM_IOCTL_NR(cmd);
40371- drm_ioctl_compat_t *fn = NULL;
40372 int ret;
40373
40374 if (nr < DRM_COMMAND_BASE)
40375 return drm_compat_ioctl(filp, cmd, arg);
40376
40377- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40378- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40379-
40380- if (fn != NULL)
40381+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40382+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40383 ret = (*fn) (filp, cmd, arg);
40384- else
40385+ } else
40386 ret = drm_ioctl(filp, cmd, arg);
40387
40388 return ret;
40389diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40390index 1b071b8..de8601a 100644
40391--- a/drivers/gpu/drm/mga/mga_irq.c
40392+++ b/drivers/gpu/drm/mga/mga_irq.c
40393@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40394 if (crtc != 0)
40395 return 0;
40396
40397- return atomic_read(&dev_priv->vbl_received);
40398+ return atomic_read_unchecked(&dev_priv->vbl_received);
40399 }
40400
40401
40402@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40403 /* VBLANK interrupt */
40404 if (status & MGA_VLINEPEN) {
40405 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40406- atomic_inc(&dev_priv->vbl_received);
40407+ atomic_inc_unchecked(&dev_priv->vbl_received);
40408 drm_handle_vblank(dev, 0);
40409 handled = 1;
40410 }
40411@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40412 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40413 MGA_WRITE(MGA_PRIMEND, prim_end);
40414
40415- atomic_inc(&dev_priv->last_fence_retired);
40416+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40417 wake_up(&dev_priv->fence_queue);
40418 handled = 1;
40419 }
40420@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40421 * using fences.
40422 */
40423 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40424- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40425+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40426 - *sequence) <= (1 << 23)));
40427
40428 *sequence = cur_fence;
40429diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40430index 4c3feaa..26391ce 100644
40431--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40432+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40433@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40434 struct bit_table {
40435 const char id;
40436 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40437-};
40438+} __no_const;
40439
40440 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40441
40442diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40443index 23ca7a5..b6c955d 100644
40444--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40445+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40446@@ -97,7 +97,6 @@ struct nouveau_drm {
40447 struct drm_global_reference mem_global_ref;
40448 struct ttm_bo_global_ref bo_global_ref;
40449 struct ttm_bo_device bdev;
40450- atomic_t validate_sequence;
40451 int (*move)(struct nouveau_channel *,
40452 struct ttm_buffer_object *,
40453 struct ttm_mem_reg *, struct ttm_mem_reg *);
40454diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40455index c1a7e5a..38b8539 100644
40456--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40457+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40458@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40459 unsigned long arg)
40460 {
40461 unsigned int nr = DRM_IOCTL_NR(cmd);
40462- drm_ioctl_compat_t *fn = NULL;
40463+ drm_ioctl_compat_t fn = NULL;
40464 int ret;
40465
40466 if (nr < DRM_COMMAND_BASE)
40467diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40468index d45d50d..72a5dd2 100644
40469--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40470+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40471@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40472 }
40473
40474 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40475- nouveau_vram_manager_init,
40476- nouveau_vram_manager_fini,
40477- nouveau_vram_manager_new,
40478- nouveau_vram_manager_del,
40479- nouveau_vram_manager_debug
40480+ .init = nouveau_vram_manager_init,
40481+ .takedown = nouveau_vram_manager_fini,
40482+ .get_node = nouveau_vram_manager_new,
40483+ .put_node = nouveau_vram_manager_del,
40484+ .debug = nouveau_vram_manager_debug
40485 };
40486
40487 static int
40488@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40489 }
40490
40491 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40492- nouveau_gart_manager_init,
40493- nouveau_gart_manager_fini,
40494- nouveau_gart_manager_new,
40495- nouveau_gart_manager_del,
40496- nouveau_gart_manager_debug
40497+ .init = nouveau_gart_manager_init,
40498+ .takedown = nouveau_gart_manager_fini,
40499+ .get_node = nouveau_gart_manager_new,
40500+ .put_node = nouveau_gart_manager_del,
40501+ .debug = nouveau_gart_manager_debug
40502 };
40503
40504 #include <core/subdev/vm/nv04.h>
40505@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40506 }
40507
40508 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40509- nv04_gart_manager_init,
40510- nv04_gart_manager_fini,
40511- nv04_gart_manager_new,
40512- nv04_gart_manager_del,
40513- nv04_gart_manager_debug
40514+ .init = nv04_gart_manager_init,
40515+ .takedown = nv04_gart_manager_fini,
40516+ .get_node = nv04_gart_manager_new,
40517+ .put_node = nv04_gart_manager_del,
40518+ .debug = nv04_gart_manager_debug
40519 };
40520
40521 int
40522diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40523index 471347e..5adc6b9 100644
40524--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40525+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40526@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40527 bool can_switch;
40528
40529 spin_lock(&dev->count_lock);
40530- can_switch = (dev->open_count == 0);
40531+ can_switch = (local_read(&dev->open_count) == 0);
40532 spin_unlock(&dev->count_lock);
40533 return can_switch;
40534 }
40535diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40536index eb89653..613cf71 100644
40537--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40538+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40539@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40540 int ret;
40541
40542 mutex_lock(&qdev->async_io_mutex);
40543- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40544+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40545 if (qdev->last_sent_io_cmd > irq_num) {
40546 if (intr)
40547 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40548- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40549+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40550 else
40551 ret = wait_event_timeout(qdev->io_cmd_event,
40552- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40553+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40554 /* 0 is timeout, just bail the "hw" has gone away */
40555 if (ret <= 0)
40556 goto out;
40557- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40558+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40559 }
40560 outb(val, addr);
40561 qdev->last_sent_io_cmd = irq_num + 1;
40562 if (intr)
40563 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40564- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40565+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40566 else
40567 ret = wait_event_timeout(qdev->io_cmd_event,
40568- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40569+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40570 out:
40571 if (ret > 0)
40572 ret = 0;
40573diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40574index c3c2bbd..bc3c0fb 100644
40575--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40576+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40577@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40578 struct drm_info_node *node = (struct drm_info_node *) m->private;
40579 struct qxl_device *qdev = node->minor->dev->dev_private;
40580
40581- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40582- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40583- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40584- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40585+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40586+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40587+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40588+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40589 seq_printf(m, "%d\n", qdev->irq_received_error);
40590 return 0;
40591 }
40592diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40593index 36ed40b..0397633 100644
40594--- a/drivers/gpu/drm/qxl/qxl_drv.h
40595+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40596@@ -290,10 +290,10 @@ struct qxl_device {
40597 unsigned int last_sent_io_cmd;
40598
40599 /* interrupt handling */
40600- atomic_t irq_received;
40601- atomic_t irq_received_display;
40602- atomic_t irq_received_cursor;
40603- atomic_t irq_received_io_cmd;
40604+ atomic_unchecked_t irq_received;
40605+ atomic_unchecked_t irq_received_display;
40606+ atomic_unchecked_t irq_received_cursor;
40607+ atomic_unchecked_t irq_received_io_cmd;
40608 unsigned irq_received_error;
40609 wait_queue_head_t display_event;
40610 wait_queue_head_t cursor_event;
40611diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40612index 0bb86e6..d41416d 100644
40613--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40614+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40615@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40616
40617 /* TODO copy slow path code from i915 */
40618 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40619- 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);
40620+ 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);
40621
40622 {
40623 struct qxl_drawable *draw = fb_cmd;
40624@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40625 struct drm_qxl_reloc reloc;
40626
40627 if (copy_from_user(&reloc,
40628- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40629+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40630 sizeof(reloc))) {
40631 ret = -EFAULT;
40632 goto out_free_bos;
40633@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40634
40635 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40636
40637- struct drm_qxl_command *commands =
40638- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40639+ struct drm_qxl_command __user *commands =
40640+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40641
40642- if (copy_from_user(&user_cmd, &commands[cmd_num],
40643+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40644 sizeof(user_cmd)))
40645 return -EFAULT;
40646
40647diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40648index 28f84b4..fb3e224 100644
40649--- a/drivers/gpu/drm/qxl/qxl_irq.c
40650+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40651@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40652
40653 pending = xchg(&qdev->ram_header->int_pending, 0);
40654
40655- atomic_inc(&qdev->irq_received);
40656+ atomic_inc_unchecked(&qdev->irq_received);
40657
40658 if (pending & QXL_INTERRUPT_DISPLAY) {
40659- atomic_inc(&qdev->irq_received_display);
40660+ atomic_inc_unchecked(&qdev->irq_received_display);
40661 wake_up_all(&qdev->display_event);
40662 qxl_queue_garbage_collect(qdev, false);
40663 }
40664 if (pending & QXL_INTERRUPT_CURSOR) {
40665- atomic_inc(&qdev->irq_received_cursor);
40666+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40667 wake_up_all(&qdev->cursor_event);
40668 }
40669 if (pending & QXL_INTERRUPT_IO_CMD) {
40670- atomic_inc(&qdev->irq_received_io_cmd);
40671+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40672 wake_up_all(&qdev->io_cmd_event);
40673 }
40674 if (pending & QXL_INTERRUPT_ERROR) {
40675@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40676 init_waitqueue_head(&qdev->io_cmd_event);
40677 INIT_WORK(&qdev->client_monitors_config_work,
40678 qxl_client_monitors_config_work_func);
40679- atomic_set(&qdev->irq_received, 0);
40680- atomic_set(&qdev->irq_received_display, 0);
40681- atomic_set(&qdev->irq_received_cursor, 0);
40682- atomic_set(&qdev->irq_received_io_cmd, 0);
40683+ atomic_set_unchecked(&qdev->irq_received, 0);
40684+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40685+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40686+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40687 qdev->irq_received_error = 0;
40688 ret = drm_irq_install(qdev->ddev);
40689 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40690diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40691index c7e7e65..7dddd4d 100644
40692--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40693+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40694@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40695 }
40696 }
40697
40698-static struct vm_operations_struct qxl_ttm_vm_ops;
40699+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40700 static const struct vm_operations_struct *ttm_vm_ops;
40701
40702 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40703@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40704 return r;
40705 if (unlikely(ttm_vm_ops == NULL)) {
40706 ttm_vm_ops = vma->vm_ops;
40707+ pax_open_kernel();
40708 qxl_ttm_vm_ops = *ttm_vm_ops;
40709 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40710+ pax_close_kernel();
40711 }
40712 vma->vm_ops = &qxl_ttm_vm_ops;
40713 return 0;
40714@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40715 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40716 {
40717 #if defined(CONFIG_DEBUG_FS)
40718- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40719- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40720- unsigned i;
40721+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40722+ {
40723+ .name = "qxl_mem_mm",
40724+ .show = &qxl_mm_dump_table,
40725+ },
40726+ {
40727+ .name = "qxl_surf_mm",
40728+ .show = &qxl_mm_dump_table,
40729+ }
40730+ };
40731
40732- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40733- if (i == 0)
40734- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40735- else
40736- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40737- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40738- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40739- qxl_mem_types_list[i].driver_features = 0;
40740- if (i == 0)
40741- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40742- else
40743- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40744+ pax_open_kernel();
40745+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40746+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40747+ pax_close_kernel();
40748
40749- }
40750- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40751+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40752 #else
40753 return 0;
40754 #endif
40755diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40756index 59459fe..be26b31 100644
40757--- a/drivers/gpu/drm/r128/r128_cce.c
40758+++ b/drivers/gpu/drm/r128/r128_cce.c
40759@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40760
40761 /* GH: Simple idle check.
40762 */
40763- atomic_set(&dev_priv->idle_count, 0);
40764+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40765
40766 /* We don't support anything other than bus-mastering ring mode,
40767 * but the ring can be in either AGP or PCI space for the ring
40768diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40769index 5bf3f5f..7000661 100644
40770--- a/drivers/gpu/drm/r128/r128_drv.h
40771+++ b/drivers/gpu/drm/r128/r128_drv.h
40772@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40773 int is_pci;
40774 unsigned long cce_buffers_offset;
40775
40776- atomic_t idle_count;
40777+ atomic_unchecked_t idle_count;
40778
40779 int page_flipping;
40780 int current_page;
40781 u32 crtc_offset;
40782 u32 crtc_offset_cntl;
40783
40784- atomic_t vbl_received;
40785+ atomic_unchecked_t vbl_received;
40786
40787 u32 color_fmt;
40788 unsigned int front_offset;
40789diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40790index b0d0fd3..a6fbbe4 100644
40791--- a/drivers/gpu/drm/r128/r128_ioc32.c
40792+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40793@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40794 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40795 }
40796
40797-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40798+drm_ioctl_compat_t r128_compat_ioctls[] = {
40799 [DRM_R128_INIT] = compat_r128_init,
40800 [DRM_R128_DEPTH] = compat_r128_depth,
40801 [DRM_R128_STIPPLE] = compat_r128_stipple,
40802@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40803 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40804 {
40805 unsigned int nr = DRM_IOCTL_NR(cmd);
40806- drm_ioctl_compat_t *fn = NULL;
40807 int ret;
40808
40809 if (nr < DRM_COMMAND_BASE)
40810 return drm_compat_ioctl(filp, cmd, arg);
40811
40812- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40813- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40814-
40815- if (fn != NULL)
40816+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40817+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40818 ret = (*fn) (filp, cmd, arg);
40819- else
40820+ } else
40821 ret = drm_ioctl(filp, cmd, arg);
40822
40823 return ret;
40824diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40825index c2ae496..30b5993 100644
40826--- a/drivers/gpu/drm/r128/r128_irq.c
40827+++ b/drivers/gpu/drm/r128/r128_irq.c
40828@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40829 if (crtc != 0)
40830 return 0;
40831
40832- return atomic_read(&dev_priv->vbl_received);
40833+ return atomic_read_unchecked(&dev_priv->vbl_received);
40834 }
40835
40836 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40837@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40838 /* VBLANK interrupt */
40839 if (status & R128_CRTC_VBLANK_INT) {
40840 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40841- atomic_inc(&dev_priv->vbl_received);
40842+ atomic_inc_unchecked(&dev_priv->vbl_received);
40843 drm_handle_vblank(dev, 0);
40844 return IRQ_HANDLED;
40845 }
40846diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40847index e806dac..f81d32f 100644
40848--- a/drivers/gpu/drm/r128/r128_state.c
40849+++ b/drivers/gpu/drm/r128/r128_state.c
40850@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40851
40852 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40853 {
40854- if (atomic_read(&dev_priv->idle_count) == 0)
40855+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40856 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40857 else
40858- atomic_set(&dev_priv->idle_count, 0);
40859+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40860 }
40861
40862 #endif
40863diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40864index 4a85bb6..aaea819 100644
40865--- a/drivers/gpu/drm/radeon/mkregtable.c
40866+++ b/drivers/gpu/drm/radeon/mkregtable.c
40867@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40868 regex_t mask_rex;
40869 regmatch_t match[4];
40870 char buf[1024];
40871- size_t end;
40872+ long end;
40873 int len;
40874 int done = 0;
40875 int r;
40876 unsigned o;
40877 struct offset *offset;
40878 char last_reg_s[10];
40879- int last_reg;
40880+ unsigned long last_reg;
40881
40882 if (regcomp
40883 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40884diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40885index 044bc98..50ced9b 100644
40886--- a/drivers/gpu/drm/radeon/radeon_device.c
40887+++ b/drivers/gpu/drm/radeon/radeon_device.c
40888@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40889 bool can_switch;
40890
40891 spin_lock(&dev->count_lock);
40892- can_switch = (dev->open_count == 0);
40893+ can_switch = (local_read(&dev->open_count) == 0);
40894 spin_unlock(&dev->count_lock);
40895 return can_switch;
40896 }
40897diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40898index dafd812..1bf20c7 100644
40899--- a/drivers/gpu/drm/radeon/radeon_drv.h
40900+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40901@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40902
40903 /* SW interrupt */
40904 wait_queue_head_t swi_queue;
40905- atomic_t swi_emitted;
40906+ atomic_unchecked_t swi_emitted;
40907 int vblank_crtc;
40908 uint32_t irq_enable_reg;
40909 uint32_t r500_disp_irq_reg;
40910diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40911index bdb0f93..5ff558f 100644
40912--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40913+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40914@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40915 request = compat_alloc_user_space(sizeof(*request));
40916 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40917 || __put_user(req32.param, &request->param)
40918- || __put_user((void __user *)(unsigned long)req32.value,
40919+ || __put_user((unsigned long)req32.value,
40920 &request->value))
40921 return -EFAULT;
40922
40923@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40924 #define compat_radeon_cp_setparam NULL
40925 #endif /* X86_64 || IA64 */
40926
40927-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40928+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40929 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40930 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40931 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40932@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40933 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40934 {
40935 unsigned int nr = DRM_IOCTL_NR(cmd);
40936- drm_ioctl_compat_t *fn = NULL;
40937 int ret;
40938
40939 if (nr < DRM_COMMAND_BASE)
40940 return drm_compat_ioctl(filp, cmd, arg);
40941
40942- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40943- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40944-
40945- if (fn != NULL)
40946+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40947+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40948 ret = (*fn) (filp, cmd, arg);
40949- else
40950+ } else
40951 ret = drm_ioctl(filp, cmd, arg);
40952
40953 return ret;
40954diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40955index 244b19b..c19226d 100644
40956--- a/drivers/gpu/drm/radeon/radeon_irq.c
40957+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40958@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40959 unsigned int ret;
40960 RING_LOCALS;
40961
40962- atomic_inc(&dev_priv->swi_emitted);
40963- ret = atomic_read(&dev_priv->swi_emitted);
40964+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40965+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40966
40967 BEGIN_RING(4);
40968 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40969@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40970 drm_radeon_private_t *dev_priv =
40971 (drm_radeon_private_t *) dev->dev_private;
40972
40973- atomic_set(&dev_priv->swi_emitted, 0);
40974+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40975 init_waitqueue_head(&dev_priv->swi_queue);
40976
40977 dev->max_vblank_count = 0x001fffff;
40978diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40979index 956ab7f..fbd36d8 100644
40980--- a/drivers/gpu/drm/radeon/radeon_state.c
40981+++ b/drivers/gpu/drm/radeon/radeon_state.c
40982@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40983 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40984 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40985
40986- if (copy_from_user(&depth_boxes, clear->depth_boxes,
40987+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40988 sarea_priv->nbox * sizeof(depth_boxes[0])))
40989 return -EFAULT;
40990
40991@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40992 {
40993 drm_radeon_private_t *dev_priv = dev->dev_private;
40994 drm_radeon_getparam_t *param = data;
40995- int value;
40996+ int value = 0;
40997
40998 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40999
41000diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41001index 040a2a1..eae4e54 100644
41002--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41003+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41004@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41005 man->size = size >> PAGE_SHIFT;
41006 }
41007
41008-static struct vm_operations_struct radeon_ttm_vm_ops;
41009+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41010 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41011
41012 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41013@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41014 }
41015 if (unlikely(ttm_vm_ops == NULL)) {
41016 ttm_vm_ops = vma->vm_ops;
41017+ pax_open_kernel();
41018 radeon_ttm_vm_ops = *ttm_vm_ops;
41019 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41020+ pax_close_kernel();
41021 }
41022 vma->vm_ops = &radeon_ttm_vm_ops;
41023 return 0;
41024diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41025index 9336006..ce78aa7 100644
41026--- a/drivers/gpu/drm/tegra/dc.c
41027+++ b/drivers/gpu/drm/tegra/dc.c
41028@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41029 }
41030
41031 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41032- dc->debugfs_files[i].data = dc;
41033+ *(void **)&dc->debugfs_files[i].data = dc;
41034
41035 err = drm_debugfs_create_files(dc->debugfs_files,
41036 ARRAY_SIZE(debugfs_files),
41037diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41038index d452faab..f8cbc6a 100644
41039--- a/drivers/gpu/drm/tegra/dsi.c
41040+++ b/drivers/gpu/drm/tegra/dsi.c
41041@@ -53,7 +53,7 @@ struct tegra_dsi {
41042 struct clk *clk_lp;
41043 struct clk *clk;
41044
41045- struct drm_info_list *debugfs_files;
41046+ drm_info_list_no_const *debugfs_files;
41047 struct drm_minor *minor;
41048 struct dentry *debugfs;
41049
41050diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41051index 6928015..c9853e7 100644
41052--- a/drivers/gpu/drm/tegra/hdmi.c
41053+++ b/drivers/gpu/drm/tegra/hdmi.c
41054@@ -59,7 +59,7 @@ struct tegra_hdmi {
41055 bool stereo;
41056 bool dvi;
41057
41058- struct drm_info_list *debugfs_files;
41059+ drm_info_list_no_const *debugfs_files;
41060 struct drm_minor *minor;
41061 struct dentry *debugfs;
41062 };
41063diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41064index c58eba33..83c2728 100644
41065--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41066+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41067@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41068 }
41069
41070 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41071- ttm_bo_man_init,
41072- ttm_bo_man_takedown,
41073- ttm_bo_man_get_node,
41074- ttm_bo_man_put_node,
41075- ttm_bo_man_debug
41076+ .init = ttm_bo_man_init,
41077+ .takedown = ttm_bo_man_takedown,
41078+ .get_node = ttm_bo_man_get_node,
41079+ .put_node = ttm_bo_man_put_node,
41080+ .debug = ttm_bo_man_debug
41081 };
41082 EXPORT_SYMBOL(ttm_bo_manager_func);
41083diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41084index dbc2def..0a9f710 100644
41085--- a/drivers/gpu/drm/ttm/ttm_memory.c
41086+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41087@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41088 zone->glob = glob;
41089 glob->zone_kernel = zone;
41090 ret = kobject_init_and_add(
41091- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41092+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41093 if (unlikely(ret != 0)) {
41094 kobject_put(&zone->kobj);
41095 return ret;
41096@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41097 zone->glob = glob;
41098 glob->zone_dma32 = zone;
41099 ret = kobject_init_and_add(
41100- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41101+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41102 if (unlikely(ret != 0)) {
41103 kobject_put(&zone->kobj);
41104 return ret;
41105diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41106index 863bef9..cba15cf 100644
41107--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41108+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41109@@ -391,9 +391,9 @@ out:
41110 static unsigned long
41111 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41112 {
41113- static atomic_t start_pool = ATOMIC_INIT(0);
41114+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41115 unsigned i;
41116- unsigned pool_offset = atomic_add_return(1, &start_pool);
41117+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41118 struct ttm_page_pool *pool;
41119 int shrink_pages = sc->nr_to_scan;
41120 unsigned long freed = 0;
41121diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41122index dbadd49..1b7457b 100644
41123--- a/drivers/gpu/drm/udl/udl_fb.c
41124+++ b/drivers/gpu/drm/udl/udl_fb.c
41125@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41126 fb_deferred_io_cleanup(info);
41127 kfree(info->fbdefio);
41128 info->fbdefio = NULL;
41129- info->fbops->fb_mmap = udl_fb_mmap;
41130 }
41131
41132 pr_warn("released /dev/fb%d user=%d count=%d\n",
41133diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41134index ad02732..144f5ed 100644
41135--- a/drivers/gpu/drm/via/via_drv.h
41136+++ b/drivers/gpu/drm/via/via_drv.h
41137@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41138 typedef uint32_t maskarray_t[5];
41139
41140 typedef struct drm_via_irq {
41141- atomic_t irq_received;
41142+ atomic_unchecked_t irq_received;
41143 uint32_t pending_mask;
41144 uint32_t enable_mask;
41145 wait_queue_head_t irq_queue;
41146@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41147 struct timeval last_vblank;
41148 int last_vblank_valid;
41149 unsigned usec_per_vblank;
41150- atomic_t vbl_received;
41151+ atomic_unchecked_t vbl_received;
41152 drm_via_state_t hc_state;
41153 char pci_buf[VIA_PCI_BUF_SIZE];
41154 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41155diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41156index 1319433..a993b0c 100644
41157--- a/drivers/gpu/drm/via/via_irq.c
41158+++ b/drivers/gpu/drm/via/via_irq.c
41159@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41160 if (crtc != 0)
41161 return 0;
41162
41163- return atomic_read(&dev_priv->vbl_received);
41164+ return atomic_read_unchecked(&dev_priv->vbl_received);
41165 }
41166
41167 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41168@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41169
41170 status = VIA_READ(VIA_REG_INTERRUPT);
41171 if (status & VIA_IRQ_VBLANK_PENDING) {
41172- atomic_inc(&dev_priv->vbl_received);
41173- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41174+ atomic_inc_unchecked(&dev_priv->vbl_received);
41175+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41176 do_gettimeofday(&cur_vblank);
41177 if (dev_priv->last_vblank_valid) {
41178 dev_priv->usec_per_vblank =
41179@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41180 dev_priv->last_vblank = cur_vblank;
41181 dev_priv->last_vblank_valid = 1;
41182 }
41183- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41184+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41185 DRM_DEBUG("US per vblank is: %u\n",
41186 dev_priv->usec_per_vblank);
41187 }
41188@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41189
41190 for (i = 0; i < dev_priv->num_irqs; ++i) {
41191 if (status & cur_irq->pending_mask) {
41192- atomic_inc(&cur_irq->irq_received);
41193+ atomic_inc_unchecked(&cur_irq->irq_received);
41194 wake_up(&cur_irq->irq_queue);
41195 handled = 1;
41196 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41197@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41198 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41199 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41200 masks[irq][4]));
41201- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41202+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41203 } else {
41204 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41205 (((cur_irq_sequence =
41206- atomic_read(&cur_irq->irq_received)) -
41207+ atomic_read_unchecked(&cur_irq->irq_received)) -
41208 *sequence) <= (1 << 23)));
41209 }
41210 *sequence = cur_irq_sequence;
41211@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41212 }
41213
41214 for (i = 0; i < dev_priv->num_irqs; ++i) {
41215- atomic_set(&cur_irq->irq_received, 0);
41216+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41217 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41218 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41219 init_waitqueue_head(&cur_irq->irq_queue);
41220@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41221 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41222 case VIA_IRQ_RELATIVE:
41223 irqwait->request.sequence +=
41224- atomic_read(&cur_irq->irq_received);
41225+ atomic_read_unchecked(&cur_irq->irq_received);
41226 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41227 case VIA_IRQ_ABSOLUTE:
41228 break;
41229diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41230index 0783155..b29e18e 100644
41231--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41232+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41233@@ -437,7 +437,7 @@ struct vmw_private {
41234 * Fencing and IRQs.
41235 */
41236
41237- atomic_t marker_seq;
41238+ atomic_unchecked_t marker_seq;
41239 wait_queue_head_t fence_queue;
41240 wait_queue_head_t fifo_queue;
41241 int fence_queue_waiters; /* Protected by hw_mutex */
41242diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41243index 6ccd993..618d592 100644
41244--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41245+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41246@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41247 (unsigned int) min,
41248 (unsigned int) fifo->capabilities);
41249
41250- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41251+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41252 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41253 vmw_marker_queue_init(&fifo->marker_queue);
41254 return vmw_fifo_send_fence(dev_priv, &dummy);
41255@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41256 if (reserveable)
41257 iowrite32(bytes, fifo_mem +
41258 SVGA_FIFO_RESERVED);
41259- return fifo_mem + (next_cmd >> 2);
41260+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41261 } else {
41262 need_bounce = true;
41263 }
41264@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41265
41266 fm = vmw_fifo_reserve(dev_priv, bytes);
41267 if (unlikely(fm == NULL)) {
41268- *seqno = atomic_read(&dev_priv->marker_seq);
41269+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41270 ret = -ENOMEM;
41271 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41272 false, 3*HZ);
41273@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41274 }
41275
41276 do {
41277- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41278+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41279 } while (*seqno == 0);
41280
41281 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41282diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41283index b1273e8..9c274fd 100644
41284--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41285+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41286@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41287 }
41288
41289 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41290- vmw_gmrid_man_init,
41291- vmw_gmrid_man_takedown,
41292- vmw_gmrid_man_get_node,
41293- vmw_gmrid_man_put_node,
41294- vmw_gmrid_man_debug
41295+ .init = vmw_gmrid_man_init,
41296+ .takedown = vmw_gmrid_man_takedown,
41297+ .get_node = vmw_gmrid_man_get_node,
41298+ .put_node = vmw_gmrid_man_put_node,
41299+ .debug = vmw_gmrid_man_debug
41300 };
41301diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41302index 47b7094..698ba09 100644
41303--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41304+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41305@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41306 int ret;
41307
41308 num_clips = arg->num_clips;
41309- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41310+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41311
41312 if (unlikely(num_clips == 0))
41313 return 0;
41314@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41315 int ret;
41316
41317 num_clips = arg->num_clips;
41318- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41319+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41320
41321 if (unlikely(num_clips == 0))
41322 return 0;
41323diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41324index 0c42376..6febe77 100644
41325--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41326+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41327@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41328 * emitted. Then the fence is stale and signaled.
41329 */
41330
41331- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41332+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41333 > VMW_FENCE_WRAP);
41334
41335 return ret;
41336@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41337
41338 if (fifo_idle)
41339 down_read(&fifo_state->rwsem);
41340- signal_seq = atomic_read(&dev_priv->marker_seq);
41341+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41342 ret = 0;
41343
41344 for (;;) {
41345diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41346index 8a8725c2..afed796 100644
41347--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41348+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41349@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41350 while (!vmw_lag_lt(queue, us)) {
41351 spin_lock(&queue->lock);
41352 if (list_empty(&queue->head))
41353- seqno = atomic_read(&dev_priv->marker_seq);
41354+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41355 else {
41356 marker = list_first_entry(&queue->head,
41357 struct vmw_marker, head);
41358diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41359index ec0ae2d..dc0780b 100644
41360--- a/drivers/gpu/vga/vga_switcheroo.c
41361+++ b/drivers/gpu/vga/vga_switcheroo.c
41362@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41363
41364 /* this version is for the case where the power switch is separate
41365 to the device being powered down. */
41366-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41367+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41368 {
41369 /* copy over all the bus versions */
41370 if (dev->bus && dev->bus->pm) {
41371@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41372 return ret;
41373 }
41374
41375-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41376+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41377 {
41378 /* copy over all the bus versions */
41379 if (dev->bus && dev->bus->pm) {
41380diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41381index cc32a6f..02a4b1c 100644
41382--- a/drivers/hid/hid-core.c
41383+++ b/drivers/hid/hid-core.c
41384@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41385
41386 int hid_add_device(struct hid_device *hdev)
41387 {
41388- static atomic_t id = ATOMIC_INIT(0);
41389+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41390 int ret;
41391
41392 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41393@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41394 /* XXX hack, any other cleaner solution after the driver core
41395 * is converted to allow more than 20 bytes as the device name? */
41396 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41397- hdev->vendor, hdev->product, atomic_inc_return(&id));
41398+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41399
41400 hid_debug_register(hdev, dev_name(&hdev->dev));
41401 ret = device_add(&hdev->dev);
41402diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41403index c13fb5b..55a3802 100644
41404--- a/drivers/hid/hid-wiimote-debug.c
41405+++ b/drivers/hid/hid-wiimote-debug.c
41406@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41407 else if (size == 0)
41408 return -EIO;
41409
41410- if (copy_to_user(u, buf, size))
41411+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41412 return -EFAULT;
41413
41414 *off += size;
41415diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41416index cedc6da..2c3da2a 100644
41417--- a/drivers/hid/uhid.c
41418+++ b/drivers/hid/uhid.c
41419@@ -47,7 +47,7 @@ struct uhid_device {
41420 struct mutex report_lock;
41421 wait_queue_head_t report_wait;
41422 atomic_t report_done;
41423- atomic_t report_id;
41424+ atomic_unchecked_t report_id;
41425 struct uhid_event report_buf;
41426 };
41427
41428@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41429
41430 spin_lock_irqsave(&uhid->qlock, flags);
41431 ev->type = UHID_FEATURE;
41432- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41433+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41434 ev->u.feature.rnum = rnum;
41435 ev->u.feature.rtype = report_type;
41436
41437@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41438 spin_lock_irqsave(&uhid->qlock, flags);
41439
41440 /* id for old report; drop it silently */
41441- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41442+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41443 goto unlock;
41444 if (atomic_read(&uhid->report_done))
41445 goto unlock;
41446diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41447index 69ea36f..8dbf4bb 100644
41448--- a/drivers/hv/channel.c
41449+++ b/drivers/hv/channel.c
41450@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41451 int ret = 0;
41452 int t;
41453
41454- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41455- atomic_inc(&vmbus_connection.next_gpadl_handle);
41456+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41457+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41458
41459 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41460 if (ret)
41461diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41462index bcb4950..61dba6c 100644
41463--- a/drivers/hv/hv.c
41464+++ b/drivers/hv/hv.c
41465@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41466 u64 output_address = (output) ? virt_to_phys(output) : 0;
41467 u32 output_address_hi = output_address >> 32;
41468 u32 output_address_lo = output_address & 0xFFFFFFFF;
41469- void *hypercall_page = hv_context.hypercall_page;
41470+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41471
41472 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41473 "=a"(hv_status_lo) : "d" (control_hi),
41474@@ -154,7 +154,7 @@ int hv_init(void)
41475 /* See if the hypercall page is already set */
41476 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41477
41478- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41479+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41480
41481 if (!virtaddr)
41482 goto cleanup;
41483diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41484index 7e17a54..a50a33d 100644
41485--- a/drivers/hv/hv_balloon.c
41486+++ b/drivers/hv/hv_balloon.c
41487@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41488
41489 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41490 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41491-static atomic_t trans_id = ATOMIC_INIT(0);
41492+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41493
41494 static int dm_ring_size = (5 * PAGE_SIZE);
41495
41496@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41497 pr_info("Memory hot add failed\n");
41498
41499 dm->state = DM_INITIALIZED;
41500- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41501+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41502 vmbus_sendpacket(dm->dev->channel, &resp,
41503 sizeof(struct dm_hot_add_response),
41504 (unsigned long)NULL,
41505@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41506 memset(&status, 0, sizeof(struct dm_status));
41507 status.hdr.type = DM_STATUS_REPORT;
41508 status.hdr.size = sizeof(struct dm_status);
41509- status.hdr.trans_id = atomic_inc_return(&trans_id);
41510+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41511
41512 /*
41513 * The host expects the guest to report free memory.
41514@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41515 * send the status. This can happen if we were interrupted
41516 * after we picked our transaction ID.
41517 */
41518- if (status.hdr.trans_id != atomic_read(&trans_id))
41519+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41520 return;
41521
41522 vmbus_sendpacket(dm->dev->channel, &status,
41523@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41524 */
41525
41526 do {
41527- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41528+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41529 ret = vmbus_sendpacket(dm_device.dev->channel,
41530 bl_resp,
41531 bl_resp->hdr.size,
41532@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41533
41534 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41535 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41536- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41537+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41538 resp.hdr.size = sizeof(struct dm_unballoon_response);
41539
41540 vmbus_sendpacket(dm_device.dev->channel, &resp,
41541@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41542 memset(&version_req, 0, sizeof(struct dm_version_request));
41543 version_req.hdr.type = DM_VERSION_REQUEST;
41544 version_req.hdr.size = sizeof(struct dm_version_request);
41545- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41546+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41547 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41548 version_req.is_last_attempt = 1;
41549
41550@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41551 memset(&version_req, 0, sizeof(struct dm_version_request));
41552 version_req.hdr.type = DM_VERSION_REQUEST;
41553 version_req.hdr.size = sizeof(struct dm_version_request);
41554- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41555+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41556 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41557 version_req.is_last_attempt = 0;
41558
41559@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41560 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41561 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41562 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41563- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41564+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41565
41566 cap_msg.caps.cap_bits.balloon = 1;
41567 cap_msg.caps.cap_bits.hot_add = 1;
41568diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41569index e055176..c22ff1f 100644
41570--- a/drivers/hv/hyperv_vmbus.h
41571+++ b/drivers/hv/hyperv_vmbus.h
41572@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41573 struct vmbus_connection {
41574 enum vmbus_connect_state conn_state;
41575
41576- atomic_t next_gpadl_handle;
41577+ atomic_unchecked_t next_gpadl_handle;
41578
41579 /*
41580 * Represents channel interrupts. Each bit position represents a
41581diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41582index 077bb1b..d433d74 100644
41583--- a/drivers/hv/vmbus_drv.c
41584+++ b/drivers/hv/vmbus_drv.c
41585@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41586 {
41587 int ret = 0;
41588
41589- static atomic_t device_num = ATOMIC_INIT(0);
41590+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41591
41592 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41593- atomic_inc_return(&device_num));
41594+ atomic_inc_return_unchecked(&device_num));
41595
41596 child_device_obj->device.bus = &hv_bus;
41597 child_device_obj->device.parent = &hv_acpi_dev->dev;
41598diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41599index 579bdf9..75118b5 100644
41600--- a/drivers/hwmon/acpi_power_meter.c
41601+++ b/drivers/hwmon/acpi_power_meter.c
41602@@ -116,7 +116,7 @@ struct sensor_template {
41603 struct device_attribute *devattr,
41604 const char *buf, size_t count);
41605 int index;
41606-};
41607+} __do_const;
41608
41609 /* Averaging interval */
41610 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41611@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41612 struct sensor_template *attrs)
41613 {
41614 struct device *dev = &resource->acpi_dev->dev;
41615- struct sensor_device_attribute *sensors =
41616+ sensor_device_attribute_no_const *sensors =
41617 &resource->sensors[resource->num_sensors];
41618 int res = 0;
41619
41620diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41621index 3288f13..71cfb4e 100644
41622--- a/drivers/hwmon/applesmc.c
41623+++ b/drivers/hwmon/applesmc.c
41624@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41625 {
41626 struct applesmc_node_group *grp;
41627 struct applesmc_dev_attr *node;
41628- struct attribute *attr;
41629+ attribute_no_const *attr;
41630 int ret, i;
41631
41632 for (grp = groups; grp->format; grp++) {
41633diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41634index ae208f6..48b6c5b 100644
41635--- a/drivers/hwmon/asus_atk0110.c
41636+++ b/drivers/hwmon/asus_atk0110.c
41637@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41638 struct atk_sensor_data {
41639 struct list_head list;
41640 struct atk_data *data;
41641- struct device_attribute label_attr;
41642- struct device_attribute input_attr;
41643- struct device_attribute limit1_attr;
41644- struct device_attribute limit2_attr;
41645+ device_attribute_no_const label_attr;
41646+ device_attribute_no_const input_attr;
41647+ device_attribute_no_const limit1_attr;
41648+ device_attribute_no_const limit2_attr;
41649 char label_attr_name[ATTR_NAME_SIZE];
41650 char input_attr_name[ATTR_NAME_SIZE];
41651 char limit1_attr_name[ATTR_NAME_SIZE];
41652@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41653 static struct device_attribute atk_name_attr =
41654 __ATTR(name, 0444, atk_name_show, NULL);
41655
41656-static void atk_init_attribute(struct device_attribute *attr, char *name,
41657+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41658 sysfs_show_func show)
41659 {
41660 sysfs_attr_init(&attr->attr);
41661diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41662index bbb0b0d..9fe1332 100644
41663--- a/drivers/hwmon/coretemp.c
41664+++ b/drivers/hwmon/coretemp.c
41665@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41666 return NOTIFY_OK;
41667 }
41668
41669-static struct notifier_block coretemp_cpu_notifier __refdata = {
41670+static struct notifier_block coretemp_cpu_notifier = {
41671 .notifier_call = coretemp_cpu_callback,
41672 };
41673
41674diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41675index 632f1dc..57e6a58 100644
41676--- a/drivers/hwmon/ibmaem.c
41677+++ b/drivers/hwmon/ibmaem.c
41678@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41679 struct aem_rw_sensor_template *rw)
41680 {
41681 struct device *dev = &data->pdev->dev;
41682- struct sensor_device_attribute *sensors = data->sensors;
41683+ sensor_device_attribute_no_const *sensors = data->sensors;
41684 int err;
41685
41686 /* Set up read-only sensors */
41687diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41688index 708081b..fe2d4ab 100644
41689--- a/drivers/hwmon/iio_hwmon.c
41690+++ b/drivers/hwmon/iio_hwmon.c
41691@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41692 {
41693 struct device *dev = &pdev->dev;
41694 struct iio_hwmon_state *st;
41695- struct sensor_device_attribute *a;
41696+ sensor_device_attribute_no_const *a;
41697 int ret, i;
41698 int in_i = 1, temp_i = 1, curr_i = 1;
41699 enum iio_chan_type type;
41700diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41701index 38d5a63..cf2c2ea 100644
41702--- a/drivers/hwmon/nct6775.c
41703+++ b/drivers/hwmon/nct6775.c
41704@@ -944,10 +944,10 @@ static struct attribute_group *
41705 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41706 int repeat)
41707 {
41708- struct attribute_group *group;
41709+ attribute_group_no_const *group;
41710 struct sensor_device_attr_u *su;
41711- struct sensor_device_attribute *a;
41712- struct sensor_device_attribute_2 *a2;
41713+ sensor_device_attribute_no_const *a;
41714+ sensor_device_attribute_2_no_const *a2;
41715 struct attribute **attrs;
41716 struct sensor_device_template **t;
41717 int i, count;
41718diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41719index 291d11f..3f0dbbd 100644
41720--- a/drivers/hwmon/pmbus/pmbus_core.c
41721+++ b/drivers/hwmon/pmbus/pmbus_core.c
41722@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41723 return 0;
41724 }
41725
41726-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41727+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41728 const char *name,
41729 umode_t mode,
41730 ssize_t (*show)(struct device *dev,
41731@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41732 dev_attr->store = store;
41733 }
41734
41735-static void pmbus_attr_init(struct sensor_device_attribute *a,
41736+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41737 const char *name,
41738 umode_t mode,
41739 ssize_t (*show)(struct device *dev,
41740@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41741 u16 reg, u8 mask)
41742 {
41743 struct pmbus_boolean *boolean;
41744- struct sensor_device_attribute *a;
41745+ sensor_device_attribute_no_const *a;
41746
41747 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41748 if (!boolean)
41749@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41750 bool update, bool readonly)
41751 {
41752 struct pmbus_sensor *sensor;
41753- struct device_attribute *a;
41754+ device_attribute_no_const *a;
41755
41756 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41757 if (!sensor)
41758@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41759 const char *lstring, int index)
41760 {
41761 struct pmbus_label *label;
41762- struct device_attribute *a;
41763+ device_attribute_no_const *a;
41764
41765 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41766 if (!label)
41767diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41768index 97cd45a..ac54d8b 100644
41769--- a/drivers/hwmon/sht15.c
41770+++ b/drivers/hwmon/sht15.c
41771@@ -169,7 +169,7 @@ struct sht15_data {
41772 int supply_uv;
41773 bool supply_uv_valid;
41774 struct work_struct update_supply_work;
41775- atomic_t interrupt_handled;
41776+ atomic_unchecked_t interrupt_handled;
41777 };
41778
41779 /**
41780@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41781 ret = gpio_direction_input(data->pdata->gpio_data);
41782 if (ret)
41783 return ret;
41784- atomic_set(&data->interrupt_handled, 0);
41785+ atomic_set_unchecked(&data->interrupt_handled, 0);
41786
41787 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41788 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41789 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41790 /* Only relevant if the interrupt hasn't occurred. */
41791- if (!atomic_read(&data->interrupt_handled))
41792+ if (!atomic_read_unchecked(&data->interrupt_handled))
41793 schedule_work(&data->read_work);
41794 }
41795 ret = wait_event_timeout(data->wait_queue,
41796@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41797
41798 /* First disable the interrupt */
41799 disable_irq_nosync(irq);
41800- atomic_inc(&data->interrupt_handled);
41801+ atomic_inc_unchecked(&data->interrupt_handled);
41802 /* Then schedule a reading work struct */
41803 if (data->state != SHT15_READING_NOTHING)
41804 schedule_work(&data->read_work);
41805@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41806 * If not, then start the interrupt again - care here as could
41807 * have gone low in meantime so verify it hasn't!
41808 */
41809- atomic_set(&data->interrupt_handled, 0);
41810+ atomic_set_unchecked(&data->interrupt_handled, 0);
41811 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41812 /* If still not occurred or another handler was scheduled */
41813 if (gpio_get_value(data->pdata->gpio_data)
41814- || atomic_read(&data->interrupt_handled))
41815+ || atomic_read_unchecked(&data->interrupt_handled))
41816 return;
41817 }
41818
41819diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41820index 38944e9..ae9e5ed 100644
41821--- a/drivers/hwmon/via-cputemp.c
41822+++ b/drivers/hwmon/via-cputemp.c
41823@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41824 return NOTIFY_OK;
41825 }
41826
41827-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41828+static struct notifier_block via_cputemp_cpu_notifier = {
41829 .notifier_call = via_cputemp_cpu_callback,
41830 };
41831
41832diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41833index 41fc683..a39cfea 100644
41834--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41835+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41836@@ -43,7 +43,7 @@
41837 extern struct i2c_adapter amd756_smbus;
41838
41839 static struct i2c_adapter *s4882_adapter;
41840-static struct i2c_algorithm *s4882_algo;
41841+static i2c_algorithm_no_const *s4882_algo;
41842
41843 /* Wrapper access functions for multiplexed SMBus */
41844 static DEFINE_MUTEX(amd756_lock);
41845diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41846index 721f7eb..0fd2a09 100644
41847--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41848+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41849@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41850 /* usb layer */
41851
41852 /* Send command to device, and get response. */
41853-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41854+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41855 {
41856 int ret = 0;
41857 int actual;
41858diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41859index b170bdf..3c76427 100644
41860--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41861+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41862@@ -41,7 +41,7 @@
41863 extern struct i2c_adapter *nforce2_smbus;
41864
41865 static struct i2c_adapter *s4985_adapter;
41866-static struct i2c_algorithm *s4985_algo;
41867+static i2c_algorithm_no_const *s4985_algo;
41868
41869 /* Wrapper access functions for multiplexed SMBus */
41870 static DEFINE_MUTEX(nforce2_lock);
41871diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41872index 80b47e8..1a6040d9 100644
41873--- a/drivers/i2c/i2c-dev.c
41874+++ b/drivers/i2c/i2c-dev.c
41875@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41876 break;
41877 }
41878
41879- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41880+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41881 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41882 if (IS_ERR(rdwr_pa[i].buf)) {
41883 res = PTR_ERR(rdwr_pa[i].buf);
41884diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41885index 0b510ba..4fbb5085 100644
41886--- a/drivers/ide/ide-cd.c
41887+++ b/drivers/ide/ide-cd.c
41888@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41889 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41890 if ((unsigned long)buf & alignment
41891 || blk_rq_bytes(rq) & q->dma_pad_mask
41892- || object_is_on_stack(buf))
41893+ || object_starts_on_stack(buf))
41894 drive->dma = 0;
41895 }
41896 }
41897diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41898index acc911a..8700c3c 100644
41899--- a/drivers/iio/industrialio-core.c
41900+++ b/drivers/iio/industrialio-core.c
41901@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41902 }
41903
41904 static
41905-int __iio_device_attr_init(struct device_attribute *dev_attr,
41906+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41907 const char *postfix,
41908 struct iio_chan_spec const *chan,
41909 ssize_t (*readfunc)(struct device *dev,
41910diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41911index c323917..6ddea8b 100644
41912--- a/drivers/infiniband/core/cm.c
41913+++ b/drivers/infiniband/core/cm.c
41914@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41915
41916 struct cm_counter_group {
41917 struct kobject obj;
41918- atomic_long_t counter[CM_ATTR_COUNT];
41919+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41920 };
41921
41922 struct cm_counter_attribute {
41923@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41924 struct ib_mad_send_buf *msg = NULL;
41925 int ret;
41926
41927- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41928+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41929 counter[CM_REQ_COUNTER]);
41930
41931 /* Quick state check to discard duplicate REQs. */
41932@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41933 if (!cm_id_priv)
41934 return;
41935
41936- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41937+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41938 counter[CM_REP_COUNTER]);
41939 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41940 if (ret)
41941@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41942 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41943 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41944 spin_unlock_irq(&cm_id_priv->lock);
41945- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41946+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41947 counter[CM_RTU_COUNTER]);
41948 goto out;
41949 }
41950@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
41951 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41952 dreq_msg->local_comm_id);
41953 if (!cm_id_priv) {
41954- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41955+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41956 counter[CM_DREQ_COUNTER]);
41957 cm_issue_drep(work->port, work->mad_recv_wc);
41958 return -EINVAL;
41959@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
41960 case IB_CM_MRA_REP_RCVD:
41961 break;
41962 case IB_CM_TIMEWAIT:
41963- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41964+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41965 counter[CM_DREQ_COUNTER]);
41966 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41967 goto unlock;
41968@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
41969 cm_free_msg(msg);
41970 goto deref;
41971 case IB_CM_DREQ_RCVD:
41972- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41973+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41974 counter[CM_DREQ_COUNTER]);
41975 goto unlock;
41976 default:
41977@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41978 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41979 cm_id_priv->msg, timeout)) {
41980 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41981- atomic_long_inc(&work->port->
41982+ atomic_long_inc_unchecked(&work->port->
41983 counter_group[CM_RECV_DUPLICATES].
41984 counter[CM_MRA_COUNTER]);
41985 goto out;
41986@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
41987 break;
41988 case IB_CM_MRA_REQ_RCVD:
41989 case IB_CM_MRA_REP_RCVD:
41990- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41991+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41992 counter[CM_MRA_COUNTER]);
41993 /* fall through */
41994 default:
41995@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
41996 case IB_CM_LAP_IDLE:
41997 break;
41998 case IB_CM_MRA_LAP_SENT:
41999- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42000+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42001 counter[CM_LAP_COUNTER]);
42002 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42003 goto unlock;
42004@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42005 cm_free_msg(msg);
42006 goto deref;
42007 case IB_CM_LAP_RCVD:
42008- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42009+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42010 counter[CM_LAP_COUNTER]);
42011 goto unlock;
42012 default:
42013@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42014 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42015 if (cur_cm_id_priv) {
42016 spin_unlock_irq(&cm.lock);
42017- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42018+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42019 counter[CM_SIDR_REQ_COUNTER]);
42020 goto out; /* Duplicate message. */
42021 }
42022@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42023 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42024 msg->retries = 1;
42025
42026- atomic_long_add(1 + msg->retries,
42027+ atomic_long_add_unchecked(1 + msg->retries,
42028 &port->counter_group[CM_XMIT].counter[attr_index]);
42029 if (msg->retries)
42030- atomic_long_add(msg->retries,
42031+ atomic_long_add_unchecked(msg->retries,
42032 &port->counter_group[CM_XMIT_RETRIES].
42033 counter[attr_index]);
42034
42035@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42036 }
42037
42038 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42039- atomic_long_inc(&port->counter_group[CM_RECV].
42040+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42041 counter[attr_id - CM_ATTR_ID_OFFSET]);
42042
42043 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42044@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42045 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42046
42047 return sprintf(buf, "%ld\n",
42048- atomic_long_read(&group->counter[cm_attr->index]));
42049+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42050 }
42051
42052 static const struct sysfs_ops cm_counter_ops = {
42053diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42054index 9f5ad7c..588cd84 100644
42055--- a/drivers/infiniband/core/fmr_pool.c
42056+++ b/drivers/infiniband/core/fmr_pool.c
42057@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42058
42059 struct task_struct *thread;
42060
42061- atomic_t req_ser;
42062- atomic_t flush_ser;
42063+ atomic_unchecked_t req_ser;
42064+ atomic_unchecked_t flush_ser;
42065
42066 wait_queue_head_t force_wait;
42067 };
42068@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42069 struct ib_fmr_pool *pool = pool_ptr;
42070
42071 do {
42072- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42073+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42074 ib_fmr_batch_release(pool);
42075
42076- atomic_inc(&pool->flush_ser);
42077+ atomic_inc_unchecked(&pool->flush_ser);
42078 wake_up_interruptible(&pool->force_wait);
42079
42080 if (pool->flush_function)
42081@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42082 }
42083
42084 set_current_state(TASK_INTERRUPTIBLE);
42085- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42086+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42087 !kthread_should_stop())
42088 schedule();
42089 __set_current_state(TASK_RUNNING);
42090@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42091 pool->dirty_watermark = params->dirty_watermark;
42092 pool->dirty_len = 0;
42093 spin_lock_init(&pool->pool_lock);
42094- atomic_set(&pool->req_ser, 0);
42095- atomic_set(&pool->flush_ser, 0);
42096+ atomic_set_unchecked(&pool->req_ser, 0);
42097+ atomic_set_unchecked(&pool->flush_ser, 0);
42098 init_waitqueue_head(&pool->force_wait);
42099
42100 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42101@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42102 }
42103 spin_unlock_irq(&pool->pool_lock);
42104
42105- serial = atomic_inc_return(&pool->req_ser);
42106+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42107 wake_up_process(pool->thread);
42108
42109 if (wait_event_interruptible(pool->force_wait,
42110- atomic_read(&pool->flush_ser) - serial >= 0))
42111+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42112 return -EINTR;
42113
42114 return 0;
42115@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42116 } else {
42117 list_add_tail(&fmr->list, &pool->dirty_list);
42118 if (++pool->dirty_len >= pool->dirty_watermark) {
42119- atomic_inc(&pool->req_ser);
42120+ atomic_inc_unchecked(&pool->req_ser);
42121 wake_up_process(pool->thread);
42122 }
42123 }
42124diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42125index 41b1195..27971a0 100644
42126--- a/drivers/infiniband/hw/cxgb4/mem.c
42127+++ b/drivers/infiniband/hw/cxgb4/mem.c
42128@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42129 int err;
42130 struct fw_ri_tpte tpt;
42131 u32 stag_idx;
42132- static atomic_t key;
42133+ static atomic_unchecked_t key;
42134
42135 if (c4iw_fatal_error(rdev))
42136 return -EIO;
42137@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42138 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42139 rdev->stats.stag.max = rdev->stats.stag.cur;
42140 mutex_unlock(&rdev->stats.lock);
42141- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42142+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42143 }
42144 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42145 __func__, stag_state, type, pdid, stag_idx);
42146diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42147index 644c2c7..ecf0879 100644
42148--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42149+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42150@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42151 }
42152
42153 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42154- ipath_mapping_error,
42155- ipath_dma_map_single,
42156- ipath_dma_unmap_single,
42157- ipath_dma_map_page,
42158- ipath_dma_unmap_page,
42159- ipath_map_sg,
42160- ipath_unmap_sg,
42161- ipath_sg_dma_address,
42162- ipath_sg_dma_len,
42163- ipath_sync_single_for_cpu,
42164- ipath_sync_single_for_device,
42165- ipath_dma_alloc_coherent,
42166- ipath_dma_free_coherent
42167+ .mapping_error = ipath_mapping_error,
42168+ .map_single = ipath_dma_map_single,
42169+ .unmap_single = ipath_dma_unmap_single,
42170+ .map_page = ipath_dma_map_page,
42171+ .unmap_page = ipath_dma_unmap_page,
42172+ .map_sg = ipath_map_sg,
42173+ .unmap_sg = ipath_unmap_sg,
42174+ .dma_address = ipath_sg_dma_address,
42175+ .dma_len = ipath_sg_dma_len,
42176+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42177+ .sync_single_for_device = ipath_sync_single_for_device,
42178+ .alloc_coherent = ipath_dma_alloc_coherent,
42179+ .free_coherent = ipath_dma_free_coherent
42180 };
42181diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42182index 79b3dbc..96e5fcc 100644
42183--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42184+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42185@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42186 struct ib_atomic_eth *ateth;
42187 struct ipath_ack_entry *e;
42188 u64 vaddr;
42189- atomic64_t *maddr;
42190+ atomic64_unchecked_t *maddr;
42191 u64 sdata;
42192 u32 rkey;
42193 u8 next;
42194@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42195 IB_ACCESS_REMOTE_ATOMIC)))
42196 goto nack_acc_unlck;
42197 /* Perform atomic OP and save result. */
42198- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42199+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42200 sdata = be64_to_cpu(ateth->swap_data);
42201 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42202 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42203- (u64) atomic64_add_return(sdata, maddr) - sdata :
42204+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42205 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42206 be64_to_cpu(ateth->compare_data),
42207 sdata);
42208diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42209index 1f95bba..9530f87 100644
42210--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42211+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42212@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42213 unsigned long flags;
42214 struct ib_wc wc;
42215 u64 sdata;
42216- atomic64_t *maddr;
42217+ atomic64_unchecked_t *maddr;
42218 enum ib_wc_status send_status;
42219
42220 /*
42221@@ -382,11 +382,11 @@ again:
42222 IB_ACCESS_REMOTE_ATOMIC)))
42223 goto acc_err;
42224 /* Perform atomic OP and save result. */
42225- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42226+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42227 sdata = wqe->wr.wr.atomic.compare_add;
42228 *(u64 *) sqp->s_sge.sge.vaddr =
42229 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42230- (u64) atomic64_add_return(sdata, maddr) - sdata :
42231+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42232 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42233 sdata, wqe->wr.wr.atomic.swap);
42234 goto send_comp;
42235diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42236index f2a3f48..673ec79 100644
42237--- a/drivers/infiniband/hw/mlx4/mad.c
42238+++ b/drivers/infiniband/hw/mlx4/mad.c
42239@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42240
42241 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42242 {
42243- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42244+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42245 cpu_to_be64(0xff00000000000000LL);
42246 }
42247
42248diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42249index 25b2cdf..099ff97 100644
42250--- a/drivers/infiniband/hw/mlx4/mcg.c
42251+++ b/drivers/infiniband/hw/mlx4/mcg.c
42252@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42253 {
42254 char name[20];
42255
42256- atomic_set(&ctx->tid, 0);
42257+ atomic_set_unchecked(&ctx->tid, 0);
42258 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42259 ctx->mcg_wq = create_singlethread_workqueue(name);
42260 if (!ctx->mcg_wq)
42261diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42262index a230683..3723f2d 100644
42263--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42264+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42265@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42266 struct list_head mcg_mgid0_list;
42267 struct workqueue_struct *mcg_wq;
42268 struct mlx4_ib_demux_pv_ctx **tun;
42269- atomic_t tid;
42270+ atomic_unchecked_t tid;
42271 int flushing; /* flushing the work queue */
42272 };
42273
42274diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42275index 9d3e5c1..6f166df 100644
42276--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42277+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42278@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42279 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42280 }
42281
42282-int mthca_QUERY_FW(struct mthca_dev *dev)
42283+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42284 {
42285 struct mthca_mailbox *mailbox;
42286 u32 *outbox;
42287@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42288 CMD_TIME_CLASS_B);
42289 }
42290
42291-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42292+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42293 int num_mtt)
42294 {
42295 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42296@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42297 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42298 }
42299
42300-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42301+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42302 int eq_num)
42303 {
42304 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42305@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42306 CMD_TIME_CLASS_B);
42307 }
42308
42309-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42310+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42311 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42312 void *in_mad, void *response_mad)
42313 {
42314diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42315index 87897b9..7e79542 100644
42316--- a/drivers/infiniband/hw/mthca/mthca_main.c
42317+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42318@@ -692,7 +692,7 @@ err_close:
42319 return err;
42320 }
42321
42322-static int mthca_setup_hca(struct mthca_dev *dev)
42323+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42324 {
42325 int err;
42326
42327diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42328index ed9a989..6aa5dc2 100644
42329--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42330+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42331@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42332 * through the bitmaps)
42333 */
42334
42335-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42336+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42337 {
42338 int o;
42339 int m;
42340@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42341 return key;
42342 }
42343
42344-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42345+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42346 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42347 {
42348 struct mthca_mailbox *mailbox;
42349@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42350 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42351 }
42352
42353-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42354+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42355 u64 *buffer_list, int buffer_size_shift,
42356 int list_len, u64 iova, u64 total_size,
42357 u32 access, struct mthca_mr *mr)
42358diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42359index 42dde06..1257310 100644
42360--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42361+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42362@@ -764,7 +764,7 @@ unlock:
42363 return 0;
42364 }
42365
42366-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42367+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42368 {
42369 struct mthca_dev *dev = to_mdev(ibcq->device);
42370 struct mthca_cq *cq = to_mcq(ibcq);
42371diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42372index 353c7b0..c6ce921 100644
42373--- a/drivers/infiniband/hw/nes/nes.c
42374+++ b/drivers/infiniband/hw/nes/nes.c
42375@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42376 LIST_HEAD(nes_adapter_list);
42377 static LIST_HEAD(nes_dev_list);
42378
42379-atomic_t qps_destroyed;
42380+atomic_unchecked_t qps_destroyed;
42381
42382 static unsigned int ee_flsh_adapter;
42383 static unsigned int sysfs_nonidx_addr;
42384@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42385 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42386 struct nes_adapter *nesadapter = nesdev->nesadapter;
42387
42388- atomic_inc(&qps_destroyed);
42389+ atomic_inc_unchecked(&qps_destroyed);
42390
42391 /* Free the control structures */
42392
42393diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42394index 33cc589..3bd6538 100644
42395--- a/drivers/infiniband/hw/nes/nes.h
42396+++ b/drivers/infiniband/hw/nes/nes.h
42397@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42398 extern unsigned int wqm_quanta;
42399 extern struct list_head nes_adapter_list;
42400
42401-extern atomic_t cm_connects;
42402-extern atomic_t cm_accepts;
42403-extern atomic_t cm_disconnects;
42404-extern atomic_t cm_closes;
42405-extern atomic_t cm_connecteds;
42406-extern atomic_t cm_connect_reqs;
42407-extern atomic_t cm_rejects;
42408-extern atomic_t mod_qp_timouts;
42409-extern atomic_t qps_created;
42410-extern atomic_t qps_destroyed;
42411-extern atomic_t sw_qps_destroyed;
42412+extern atomic_unchecked_t cm_connects;
42413+extern atomic_unchecked_t cm_accepts;
42414+extern atomic_unchecked_t cm_disconnects;
42415+extern atomic_unchecked_t cm_closes;
42416+extern atomic_unchecked_t cm_connecteds;
42417+extern atomic_unchecked_t cm_connect_reqs;
42418+extern atomic_unchecked_t cm_rejects;
42419+extern atomic_unchecked_t mod_qp_timouts;
42420+extern atomic_unchecked_t qps_created;
42421+extern atomic_unchecked_t qps_destroyed;
42422+extern atomic_unchecked_t sw_qps_destroyed;
42423 extern u32 mh_detected;
42424 extern u32 mh_pauses_sent;
42425 extern u32 cm_packets_sent;
42426@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42427 extern u32 cm_packets_received;
42428 extern u32 cm_packets_dropped;
42429 extern u32 cm_packets_retrans;
42430-extern atomic_t cm_listens_created;
42431-extern atomic_t cm_listens_destroyed;
42432+extern atomic_unchecked_t cm_listens_created;
42433+extern atomic_unchecked_t cm_listens_destroyed;
42434 extern u32 cm_backlog_drops;
42435-extern atomic_t cm_loopbacks;
42436-extern atomic_t cm_nodes_created;
42437-extern atomic_t cm_nodes_destroyed;
42438-extern atomic_t cm_accel_dropped_pkts;
42439-extern atomic_t cm_resets_recvd;
42440-extern atomic_t pau_qps_created;
42441-extern atomic_t pau_qps_destroyed;
42442+extern atomic_unchecked_t cm_loopbacks;
42443+extern atomic_unchecked_t cm_nodes_created;
42444+extern atomic_unchecked_t cm_nodes_destroyed;
42445+extern atomic_unchecked_t cm_accel_dropped_pkts;
42446+extern atomic_unchecked_t cm_resets_recvd;
42447+extern atomic_unchecked_t pau_qps_created;
42448+extern atomic_unchecked_t pau_qps_destroyed;
42449
42450 extern u32 int_mod_timer_init;
42451 extern u32 int_mod_cq_depth_256;
42452diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42453index 9c9f2f5..2559190 100644
42454--- a/drivers/infiniband/hw/nes/nes_cm.c
42455+++ b/drivers/infiniband/hw/nes/nes_cm.c
42456@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42457 u32 cm_packets_retrans;
42458 u32 cm_packets_created;
42459 u32 cm_packets_received;
42460-atomic_t cm_listens_created;
42461-atomic_t cm_listens_destroyed;
42462+atomic_unchecked_t cm_listens_created;
42463+atomic_unchecked_t cm_listens_destroyed;
42464 u32 cm_backlog_drops;
42465-atomic_t cm_loopbacks;
42466-atomic_t cm_nodes_created;
42467-atomic_t cm_nodes_destroyed;
42468-atomic_t cm_accel_dropped_pkts;
42469-atomic_t cm_resets_recvd;
42470+atomic_unchecked_t cm_loopbacks;
42471+atomic_unchecked_t cm_nodes_created;
42472+atomic_unchecked_t cm_nodes_destroyed;
42473+atomic_unchecked_t cm_accel_dropped_pkts;
42474+atomic_unchecked_t cm_resets_recvd;
42475
42476 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42477 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42478@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42479 /* instance of function pointers for client API */
42480 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42481 static struct nes_cm_ops nes_cm_api = {
42482- mini_cm_accelerated,
42483- mini_cm_listen,
42484- mini_cm_del_listen,
42485- mini_cm_connect,
42486- mini_cm_close,
42487- mini_cm_accept,
42488- mini_cm_reject,
42489- mini_cm_recv_pkt,
42490- mini_cm_dealloc_core,
42491- mini_cm_get,
42492- mini_cm_set
42493+ .accelerated = mini_cm_accelerated,
42494+ .listen = mini_cm_listen,
42495+ .stop_listener = mini_cm_del_listen,
42496+ .connect = mini_cm_connect,
42497+ .close = mini_cm_close,
42498+ .accept = mini_cm_accept,
42499+ .reject = mini_cm_reject,
42500+ .recv_pkt = mini_cm_recv_pkt,
42501+ .destroy_cm_core = mini_cm_dealloc_core,
42502+ .get = mini_cm_get,
42503+ .set = mini_cm_set
42504 };
42505
42506 static struct nes_cm_core *g_cm_core;
42507
42508-atomic_t cm_connects;
42509-atomic_t cm_accepts;
42510-atomic_t cm_disconnects;
42511-atomic_t cm_closes;
42512-atomic_t cm_connecteds;
42513-atomic_t cm_connect_reqs;
42514-atomic_t cm_rejects;
42515+atomic_unchecked_t cm_connects;
42516+atomic_unchecked_t cm_accepts;
42517+atomic_unchecked_t cm_disconnects;
42518+atomic_unchecked_t cm_closes;
42519+atomic_unchecked_t cm_connecteds;
42520+atomic_unchecked_t cm_connect_reqs;
42521+atomic_unchecked_t cm_rejects;
42522
42523 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42524 {
42525@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42526 kfree(listener);
42527 listener = NULL;
42528 ret = 0;
42529- atomic_inc(&cm_listens_destroyed);
42530+ atomic_inc_unchecked(&cm_listens_destroyed);
42531 } else {
42532 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42533 }
42534@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42535 cm_node->rem_mac);
42536
42537 add_hte_node(cm_core, cm_node);
42538- atomic_inc(&cm_nodes_created);
42539+ atomic_inc_unchecked(&cm_nodes_created);
42540
42541 return cm_node;
42542 }
42543@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42544 }
42545
42546 atomic_dec(&cm_core->node_cnt);
42547- atomic_inc(&cm_nodes_destroyed);
42548+ atomic_inc_unchecked(&cm_nodes_destroyed);
42549 nesqp = cm_node->nesqp;
42550 if (nesqp) {
42551 nesqp->cm_node = NULL;
42552@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42553
42554 static void drop_packet(struct sk_buff *skb)
42555 {
42556- atomic_inc(&cm_accel_dropped_pkts);
42557+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42558 dev_kfree_skb_any(skb);
42559 }
42560
42561@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42562 {
42563
42564 int reset = 0; /* whether to send reset in case of err.. */
42565- atomic_inc(&cm_resets_recvd);
42566+ atomic_inc_unchecked(&cm_resets_recvd);
42567 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42568 " refcnt=%d\n", cm_node, cm_node->state,
42569 atomic_read(&cm_node->ref_count));
42570@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42571 rem_ref_cm_node(cm_node->cm_core, cm_node);
42572 return NULL;
42573 }
42574- atomic_inc(&cm_loopbacks);
42575+ atomic_inc_unchecked(&cm_loopbacks);
42576 loopbackremotenode->loopbackpartner = cm_node;
42577 loopbackremotenode->tcp_cntxt.rcv_wscale =
42578 NES_CM_DEFAULT_RCV_WND_SCALE;
42579@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42580 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42581 else {
42582 rem_ref_cm_node(cm_core, cm_node);
42583- atomic_inc(&cm_accel_dropped_pkts);
42584+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42585 dev_kfree_skb_any(skb);
42586 }
42587 break;
42588@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42589
42590 if ((cm_id) && (cm_id->event_handler)) {
42591 if (issue_disconn) {
42592- atomic_inc(&cm_disconnects);
42593+ atomic_inc_unchecked(&cm_disconnects);
42594 cm_event.event = IW_CM_EVENT_DISCONNECT;
42595 cm_event.status = disconn_status;
42596 cm_event.local_addr = cm_id->local_addr;
42597@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42598 }
42599
42600 if (issue_close) {
42601- atomic_inc(&cm_closes);
42602+ atomic_inc_unchecked(&cm_closes);
42603 nes_disconnect(nesqp, 1);
42604
42605 cm_id->provider_data = nesqp;
42606@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42607
42608 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42609 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42610- atomic_inc(&cm_accepts);
42611+ atomic_inc_unchecked(&cm_accepts);
42612
42613 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42614 netdev_refcnt_read(nesvnic->netdev));
42615@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42616 struct nes_cm_core *cm_core;
42617 u8 *start_buff;
42618
42619- atomic_inc(&cm_rejects);
42620+ atomic_inc_unchecked(&cm_rejects);
42621 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42622 loopback = cm_node->loopbackpartner;
42623 cm_core = cm_node->cm_core;
42624@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42625 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42626 ntohs(laddr->sin_port));
42627
42628- atomic_inc(&cm_connects);
42629+ atomic_inc_unchecked(&cm_connects);
42630 nesqp->active_conn = 1;
42631
42632 /* cache the cm_id in the qp */
42633@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42634 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42635 return err;
42636 }
42637- atomic_inc(&cm_listens_created);
42638+ atomic_inc_unchecked(&cm_listens_created);
42639 }
42640
42641 cm_id->add_ref(cm_id);
42642@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42643
42644 if (nesqp->destroyed)
42645 return;
42646- atomic_inc(&cm_connecteds);
42647+ atomic_inc_unchecked(&cm_connecteds);
42648 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42649 " local port 0x%04X. jiffies = %lu.\n",
42650 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42651@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42652
42653 cm_id->add_ref(cm_id);
42654 ret = cm_id->event_handler(cm_id, &cm_event);
42655- atomic_inc(&cm_closes);
42656+ atomic_inc_unchecked(&cm_closes);
42657 cm_event.event = IW_CM_EVENT_CLOSE;
42658 cm_event.status = 0;
42659 cm_event.provider_data = cm_id->provider_data;
42660@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42661 return;
42662 cm_id = cm_node->cm_id;
42663
42664- atomic_inc(&cm_connect_reqs);
42665+ atomic_inc_unchecked(&cm_connect_reqs);
42666 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42667 cm_node, cm_id, jiffies);
42668
42669@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42670 return;
42671 cm_id = cm_node->cm_id;
42672
42673- atomic_inc(&cm_connect_reqs);
42674+ atomic_inc_unchecked(&cm_connect_reqs);
42675 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42676 cm_node, cm_id, jiffies);
42677
42678diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42679index 4166452..fc952c3 100644
42680--- a/drivers/infiniband/hw/nes/nes_mgt.c
42681+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42682@@ -40,8 +40,8 @@
42683 #include "nes.h"
42684 #include "nes_mgt.h"
42685
42686-atomic_t pau_qps_created;
42687-atomic_t pau_qps_destroyed;
42688+atomic_unchecked_t pau_qps_created;
42689+atomic_unchecked_t pau_qps_destroyed;
42690
42691 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42692 {
42693@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42694 {
42695 struct sk_buff *skb;
42696 unsigned long flags;
42697- atomic_inc(&pau_qps_destroyed);
42698+ atomic_inc_unchecked(&pau_qps_destroyed);
42699
42700 /* Free packets that have not yet been forwarded */
42701 /* Lock is acquired by skb_dequeue when removing the skb */
42702@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42703 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42704 skb_queue_head_init(&nesqp->pau_list);
42705 spin_lock_init(&nesqp->pau_lock);
42706- atomic_inc(&pau_qps_created);
42707+ atomic_inc_unchecked(&pau_qps_created);
42708 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42709 }
42710
42711diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42712index 49eb511..a774366 100644
42713--- a/drivers/infiniband/hw/nes/nes_nic.c
42714+++ b/drivers/infiniband/hw/nes/nes_nic.c
42715@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42716 target_stat_values[++index] = mh_detected;
42717 target_stat_values[++index] = mh_pauses_sent;
42718 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42719- target_stat_values[++index] = atomic_read(&cm_connects);
42720- target_stat_values[++index] = atomic_read(&cm_accepts);
42721- target_stat_values[++index] = atomic_read(&cm_disconnects);
42722- target_stat_values[++index] = atomic_read(&cm_connecteds);
42723- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42724- target_stat_values[++index] = atomic_read(&cm_rejects);
42725- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42726- target_stat_values[++index] = atomic_read(&qps_created);
42727- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42728- target_stat_values[++index] = atomic_read(&qps_destroyed);
42729- target_stat_values[++index] = atomic_read(&cm_closes);
42730+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42731+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42732+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42733+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42734+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42735+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42736+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42737+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42738+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42739+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42740+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42741 target_stat_values[++index] = cm_packets_sent;
42742 target_stat_values[++index] = cm_packets_bounced;
42743 target_stat_values[++index] = cm_packets_created;
42744 target_stat_values[++index] = cm_packets_received;
42745 target_stat_values[++index] = cm_packets_dropped;
42746 target_stat_values[++index] = cm_packets_retrans;
42747- target_stat_values[++index] = atomic_read(&cm_listens_created);
42748- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42749+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42750+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42751 target_stat_values[++index] = cm_backlog_drops;
42752- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42753- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42754- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42755- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42756- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42757+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42758+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42759+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42760+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42761+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42762 target_stat_values[++index] = nesadapter->free_4kpbl;
42763 target_stat_values[++index] = nesadapter->free_256pbl;
42764 target_stat_values[++index] = int_mod_timer_init;
42765 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42766 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42767 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42768- target_stat_values[++index] = atomic_read(&pau_qps_created);
42769- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42770+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42771+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42772 }
42773
42774 /**
42775diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42776index eb62461..2b7fc71 100644
42777--- a/drivers/infiniband/hw/nes/nes_verbs.c
42778+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42779@@ -46,9 +46,9 @@
42780
42781 #include <rdma/ib_umem.h>
42782
42783-atomic_t mod_qp_timouts;
42784-atomic_t qps_created;
42785-atomic_t sw_qps_destroyed;
42786+atomic_unchecked_t mod_qp_timouts;
42787+atomic_unchecked_t qps_created;
42788+atomic_unchecked_t sw_qps_destroyed;
42789
42790 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42791
42792@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42793 if (init_attr->create_flags)
42794 return ERR_PTR(-EINVAL);
42795
42796- atomic_inc(&qps_created);
42797+ atomic_inc_unchecked(&qps_created);
42798 switch (init_attr->qp_type) {
42799 case IB_QPT_RC:
42800 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42801@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42802 struct iw_cm_event cm_event;
42803 int ret = 0;
42804
42805- atomic_inc(&sw_qps_destroyed);
42806+ atomic_inc_unchecked(&sw_qps_destroyed);
42807 nesqp->destroyed = 1;
42808
42809 /* Blow away the connection if it exists. */
42810diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42811index 1946101..09766d2 100644
42812--- a/drivers/infiniband/hw/qib/qib.h
42813+++ b/drivers/infiniband/hw/qib/qib.h
42814@@ -52,6 +52,7 @@
42815 #include <linux/kref.h>
42816 #include <linux/sched.h>
42817 #include <linux/kthread.h>
42818+#include <linux/slab.h>
42819
42820 #include "qib_common.h"
42821 #include "qib_verbs.h"
42822diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42823index 24c41ba..102d71f 100644
42824--- a/drivers/input/gameport/gameport.c
42825+++ b/drivers/input/gameport/gameport.c
42826@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42827 */
42828 static void gameport_init_port(struct gameport *gameport)
42829 {
42830- static atomic_t gameport_no = ATOMIC_INIT(0);
42831+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42832
42833 __module_get(THIS_MODULE);
42834
42835 mutex_init(&gameport->drv_mutex);
42836 device_initialize(&gameport->dev);
42837 dev_set_name(&gameport->dev, "gameport%lu",
42838- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42839+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42840 gameport->dev.bus = &gameport_bus;
42841 gameport->dev.release = gameport_release_port;
42842 if (gameport->parent)
42843diff --git a/drivers/input/input.c b/drivers/input/input.c
42844index 1c4c0db..6f7abe3 100644
42845--- a/drivers/input/input.c
42846+++ b/drivers/input/input.c
42847@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42848 */
42849 struct input_dev *input_allocate_device(void)
42850 {
42851- static atomic_t input_no = ATOMIC_INIT(0);
42852+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42853 struct input_dev *dev;
42854
42855 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42856@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42857 INIT_LIST_HEAD(&dev->node);
42858
42859 dev_set_name(&dev->dev, "input%ld",
42860- (unsigned long) atomic_inc_return(&input_no) - 1);
42861+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42862
42863 __module_get(THIS_MODULE);
42864 }
42865diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42866index 4a95b22..874c182 100644
42867--- a/drivers/input/joystick/sidewinder.c
42868+++ b/drivers/input/joystick/sidewinder.c
42869@@ -30,6 +30,7 @@
42870 #include <linux/kernel.h>
42871 #include <linux/module.h>
42872 #include <linux/slab.h>
42873+#include <linux/sched.h>
42874 #include <linux/input.h>
42875 #include <linux/gameport.h>
42876 #include <linux/jiffies.h>
42877diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42878index 603fe0d..f63decc 100644
42879--- a/drivers/input/joystick/xpad.c
42880+++ b/drivers/input/joystick/xpad.c
42881@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42882
42883 static int xpad_led_probe(struct usb_xpad *xpad)
42884 {
42885- static atomic_t led_seq = ATOMIC_INIT(0);
42886+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42887 long led_no;
42888 struct xpad_led *led;
42889 struct led_classdev *led_cdev;
42890@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42891 if (!led)
42892 return -ENOMEM;
42893
42894- led_no = (long)atomic_inc_return(&led_seq) - 1;
42895+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42896
42897 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42898 led->xpad = xpad;
42899diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42900index e204f26..8459f15 100644
42901--- a/drivers/input/misc/ims-pcu.c
42902+++ b/drivers/input/misc/ims-pcu.c
42903@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42904
42905 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42906 {
42907- static atomic_t device_no = ATOMIC_INIT(0);
42908+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42909
42910 const struct ims_pcu_device_info *info;
42911 u8 device_id;
42912@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42913 }
42914
42915 /* Device appears to be operable, complete initialization */
42916- pcu->device_no = atomic_inc_return(&device_no) - 1;
42917+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42918
42919 error = ims_pcu_setup_backlight(pcu);
42920 if (error)
42921diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42922index 2f0b39d..7370f13 100644
42923--- a/drivers/input/mouse/psmouse.h
42924+++ b/drivers/input/mouse/psmouse.h
42925@@ -116,7 +116,7 @@ struct psmouse_attribute {
42926 ssize_t (*set)(struct psmouse *psmouse, void *data,
42927 const char *buf, size_t count);
42928 bool protect;
42929-};
42930+} __do_const;
42931 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42932
42933 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42934diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42935index b604564..3f14ae4 100644
42936--- a/drivers/input/mousedev.c
42937+++ b/drivers/input/mousedev.c
42938@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42939
42940 spin_unlock_irq(&client->packet_lock);
42941
42942- if (copy_to_user(buffer, data, count))
42943+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42944 return -EFAULT;
42945
42946 return count;
42947diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42948index 8f4c4ab..5fc8a45 100644
42949--- a/drivers/input/serio/serio.c
42950+++ b/drivers/input/serio/serio.c
42951@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42952 */
42953 static void serio_init_port(struct serio *serio)
42954 {
42955- static atomic_t serio_no = ATOMIC_INIT(0);
42956+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42957
42958 __module_get(THIS_MODULE);
42959
42960@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42961 mutex_init(&serio->drv_mutex);
42962 device_initialize(&serio->dev);
42963 dev_set_name(&serio->dev, "serio%ld",
42964- (long)atomic_inc_return(&serio_no) - 1);
42965+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42966 serio->dev.bus = &serio_bus;
42967 serio->dev.release = serio_release_port;
42968 serio->dev.groups = serio_device_attr_groups;
42969diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42970index c9a02fe..0debc75 100644
42971--- a/drivers/input/serio/serio_raw.c
42972+++ b/drivers/input/serio/serio_raw.c
42973@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42974
42975 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42976 {
42977- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42978+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42979 struct serio_raw *serio_raw;
42980 int err;
42981
42982@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42983 }
42984
42985 snprintf(serio_raw->name, sizeof(serio_raw->name),
42986- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42987+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42988 kref_init(&serio_raw->kref);
42989 INIT_LIST_HEAD(&serio_raw->client_list);
42990 init_waitqueue_head(&serio_raw->wait);
42991diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42992index e5555fc..937986d 100644
42993--- a/drivers/iommu/iommu.c
42994+++ b/drivers/iommu/iommu.c
42995@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42996 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42997 {
42998 bus_register_notifier(bus, &iommu_bus_nb);
42999- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43000+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43001 }
43002
43003 /**
43004diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43005index 228632c9..edfe331 100644
43006--- a/drivers/iommu/irq_remapping.c
43007+++ b/drivers/iommu/irq_remapping.c
43008@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43009 void panic_if_irq_remap(const char *msg)
43010 {
43011 if (irq_remapping_enabled)
43012- panic(msg);
43013+ panic("%s", msg);
43014 }
43015
43016 static void ir_ack_apic_edge(struct irq_data *data)
43017@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43018
43019 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43020 {
43021- chip->irq_print_chip = ir_print_prefix;
43022- chip->irq_ack = ir_ack_apic_edge;
43023- chip->irq_eoi = ir_ack_apic_level;
43024- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43025+ pax_open_kernel();
43026+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43027+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43028+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43029+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43030+ pax_close_kernel();
43031 }
43032
43033 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43034diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43035index 341c601..e5f407e 100644
43036--- a/drivers/irqchip/irq-gic.c
43037+++ b/drivers/irqchip/irq-gic.c
43038@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43039 * Supported arch specific GIC irq extension.
43040 * Default make them NULL.
43041 */
43042-struct irq_chip gic_arch_extn = {
43043+irq_chip_no_const gic_arch_extn = {
43044 .irq_eoi = NULL,
43045 .irq_mask = NULL,
43046 .irq_unmask = NULL,
43047@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43048 chained_irq_exit(chip, desc);
43049 }
43050
43051-static struct irq_chip gic_chip = {
43052+static irq_chip_no_const gic_chip __read_only = {
43053 .name = "GIC",
43054 .irq_mask = gic_mask_irq,
43055 .irq_unmask = gic_unmask_irq,
43056diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43057index 8777065..a4a9967 100644
43058--- a/drivers/irqchip/irq-renesas-irqc.c
43059+++ b/drivers/irqchip/irq-renesas-irqc.c
43060@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43061 struct irqc_priv *p;
43062 struct resource *io;
43063 struct resource *irq;
43064- struct irq_chip *irq_chip;
43065+ irq_chip_no_const *irq_chip;
43066 const char *name = dev_name(&pdev->dev);
43067 int ret;
43068 int k;
43069diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43070index ac6f72b..81150f2 100644
43071--- a/drivers/isdn/capi/capi.c
43072+++ b/drivers/isdn/capi/capi.c
43073@@ -81,8 +81,8 @@ struct capiminor {
43074
43075 struct capi20_appl *ap;
43076 u32 ncci;
43077- atomic_t datahandle;
43078- atomic_t msgid;
43079+ atomic_unchecked_t datahandle;
43080+ atomic_unchecked_t msgid;
43081
43082 struct tty_port port;
43083 int ttyinstop;
43084@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43085 capimsg_setu16(s, 2, mp->ap->applid);
43086 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43087 capimsg_setu8 (s, 5, CAPI_RESP);
43088- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43089+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43090 capimsg_setu32(s, 8, mp->ncci);
43091 capimsg_setu16(s, 12, datahandle);
43092 }
43093@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43094 mp->outbytes -= len;
43095 spin_unlock_bh(&mp->outlock);
43096
43097- datahandle = atomic_inc_return(&mp->datahandle);
43098+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43099 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43100 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43101 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43102 capimsg_setu16(skb->data, 2, mp->ap->applid);
43103 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43104 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43105- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43106+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43107 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43108 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43109 capimsg_setu16(skb->data, 16, len); /* Data length */
43110diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43111index c44950d..10ac276 100644
43112--- a/drivers/isdn/gigaset/bas-gigaset.c
43113+++ b/drivers/isdn/gigaset/bas-gigaset.c
43114@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43115
43116
43117 static const struct gigaset_ops gigops = {
43118- gigaset_write_cmd,
43119- gigaset_write_room,
43120- gigaset_chars_in_buffer,
43121- gigaset_brkchars,
43122- gigaset_init_bchannel,
43123- gigaset_close_bchannel,
43124- gigaset_initbcshw,
43125- gigaset_freebcshw,
43126- gigaset_reinitbcshw,
43127- gigaset_initcshw,
43128- gigaset_freecshw,
43129- gigaset_set_modem_ctrl,
43130- gigaset_baud_rate,
43131- gigaset_set_line_ctrl,
43132- gigaset_isoc_send_skb,
43133- gigaset_isoc_input,
43134+ .write_cmd = gigaset_write_cmd,
43135+ .write_room = gigaset_write_room,
43136+ .chars_in_buffer = gigaset_chars_in_buffer,
43137+ .brkchars = gigaset_brkchars,
43138+ .init_bchannel = gigaset_init_bchannel,
43139+ .close_bchannel = gigaset_close_bchannel,
43140+ .initbcshw = gigaset_initbcshw,
43141+ .freebcshw = gigaset_freebcshw,
43142+ .reinitbcshw = gigaset_reinitbcshw,
43143+ .initcshw = gigaset_initcshw,
43144+ .freecshw = gigaset_freecshw,
43145+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43146+ .baud_rate = gigaset_baud_rate,
43147+ .set_line_ctrl = gigaset_set_line_ctrl,
43148+ .send_skb = gigaset_isoc_send_skb,
43149+ .handle_input = gigaset_isoc_input,
43150 };
43151
43152 /* bas_gigaset_init
43153diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43154index 600c79b..3752bab 100644
43155--- a/drivers/isdn/gigaset/interface.c
43156+++ b/drivers/isdn/gigaset/interface.c
43157@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43158 }
43159 tty->driver_data = cs;
43160
43161- ++cs->port.count;
43162+ atomic_inc(&cs->port.count);
43163
43164- if (cs->port.count == 1) {
43165+ if (atomic_read(&cs->port.count) == 1) {
43166 tty_port_tty_set(&cs->port, tty);
43167 cs->port.low_latency = 1;
43168 }
43169@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43170
43171 if (!cs->connected)
43172 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43173- else if (!cs->port.count)
43174+ else if (!atomic_read(&cs->port.count))
43175 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43176- else if (!--cs->port.count)
43177+ else if (!atomic_dec_return(&cs->port.count))
43178 tty_port_tty_set(&cs->port, NULL);
43179
43180 mutex_unlock(&cs->mutex);
43181diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43182index 8c91fd5..14f13ce 100644
43183--- a/drivers/isdn/gigaset/ser-gigaset.c
43184+++ b/drivers/isdn/gigaset/ser-gigaset.c
43185@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43186 }
43187
43188 static const struct gigaset_ops ops = {
43189- gigaset_write_cmd,
43190- gigaset_write_room,
43191- gigaset_chars_in_buffer,
43192- gigaset_brkchars,
43193- gigaset_init_bchannel,
43194- gigaset_close_bchannel,
43195- gigaset_initbcshw,
43196- gigaset_freebcshw,
43197- gigaset_reinitbcshw,
43198- gigaset_initcshw,
43199- gigaset_freecshw,
43200- gigaset_set_modem_ctrl,
43201- gigaset_baud_rate,
43202- gigaset_set_line_ctrl,
43203- gigaset_m10x_send_skb, /* asyncdata.c */
43204- gigaset_m10x_input, /* asyncdata.c */
43205+ .write_cmd = gigaset_write_cmd,
43206+ .write_room = gigaset_write_room,
43207+ .chars_in_buffer = gigaset_chars_in_buffer,
43208+ .brkchars = gigaset_brkchars,
43209+ .init_bchannel = gigaset_init_bchannel,
43210+ .close_bchannel = gigaset_close_bchannel,
43211+ .initbcshw = gigaset_initbcshw,
43212+ .freebcshw = gigaset_freebcshw,
43213+ .reinitbcshw = gigaset_reinitbcshw,
43214+ .initcshw = gigaset_initcshw,
43215+ .freecshw = gigaset_freecshw,
43216+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43217+ .baud_rate = gigaset_baud_rate,
43218+ .set_line_ctrl = gigaset_set_line_ctrl,
43219+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43220+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43221 };
43222
43223
43224diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43225index d0a41cb..b953e50 100644
43226--- a/drivers/isdn/gigaset/usb-gigaset.c
43227+++ b/drivers/isdn/gigaset/usb-gigaset.c
43228@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43229 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43230 memcpy(cs->hw.usb->bchars, buf, 6);
43231 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43232- 0, 0, &buf, 6, 2000);
43233+ 0, 0, buf, 6, 2000);
43234 }
43235
43236 static void gigaset_freebcshw(struct bc_state *bcs)
43237@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43238 }
43239
43240 static const struct gigaset_ops ops = {
43241- gigaset_write_cmd,
43242- gigaset_write_room,
43243- gigaset_chars_in_buffer,
43244- gigaset_brkchars,
43245- gigaset_init_bchannel,
43246- gigaset_close_bchannel,
43247- gigaset_initbcshw,
43248- gigaset_freebcshw,
43249- gigaset_reinitbcshw,
43250- gigaset_initcshw,
43251- gigaset_freecshw,
43252- gigaset_set_modem_ctrl,
43253- gigaset_baud_rate,
43254- gigaset_set_line_ctrl,
43255- gigaset_m10x_send_skb,
43256- gigaset_m10x_input,
43257+ .write_cmd = gigaset_write_cmd,
43258+ .write_room = gigaset_write_room,
43259+ .chars_in_buffer = gigaset_chars_in_buffer,
43260+ .brkchars = gigaset_brkchars,
43261+ .init_bchannel = gigaset_init_bchannel,
43262+ .close_bchannel = gigaset_close_bchannel,
43263+ .initbcshw = gigaset_initbcshw,
43264+ .freebcshw = gigaset_freebcshw,
43265+ .reinitbcshw = gigaset_reinitbcshw,
43266+ .initcshw = gigaset_initcshw,
43267+ .freecshw = gigaset_freecshw,
43268+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43269+ .baud_rate = gigaset_baud_rate,
43270+ .set_line_ctrl = gigaset_set_line_ctrl,
43271+ .send_skb = gigaset_m10x_send_skb,
43272+ .handle_input = gigaset_m10x_input,
43273 };
43274
43275 /*
43276diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43277index 4d9b195..455075c 100644
43278--- a/drivers/isdn/hardware/avm/b1.c
43279+++ b/drivers/isdn/hardware/avm/b1.c
43280@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43281 }
43282 if (left) {
43283 if (t4file->user) {
43284- if (copy_from_user(buf, dp, left))
43285+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43286 return -EFAULT;
43287 } else {
43288 memcpy(buf, dp, left);
43289@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43290 }
43291 if (left) {
43292 if (config->user) {
43293- if (copy_from_user(buf, dp, left))
43294+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43295 return -EFAULT;
43296 } else {
43297 memcpy(buf, dp, left);
43298diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43299index 9bb12ba..d4262f7 100644
43300--- a/drivers/isdn/i4l/isdn_common.c
43301+++ b/drivers/isdn/i4l/isdn_common.c
43302@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43303 } else
43304 return -EINVAL;
43305 case IIOCDBGVAR:
43306+ if (!capable(CAP_SYS_RAWIO))
43307+ return -EPERM;
43308 if (arg) {
43309 if (copy_to_user(argp, &dev, sizeof(ulong)))
43310 return -EFAULT;
43311diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43312index 91d5730..336523e 100644
43313--- a/drivers/isdn/i4l/isdn_concap.c
43314+++ b/drivers/isdn/i4l/isdn_concap.c
43315@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43316 }
43317
43318 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43319- &isdn_concap_dl_data_req,
43320- &isdn_concap_dl_connect_req,
43321- &isdn_concap_dl_disconn_req
43322+ .data_req = &isdn_concap_dl_data_req,
43323+ .connect_req = &isdn_concap_dl_connect_req,
43324+ .disconn_req = &isdn_concap_dl_disconn_req
43325 };
43326
43327 /* The following should better go into a dedicated source file such that
43328diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43329index 3c5f249..5fac4d0 100644
43330--- a/drivers/isdn/i4l/isdn_tty.c
43331+++ b/drivers/isdn/i4l/isdn_tty.c
43332@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43333
43334 #ifdef ISDN_DEBUG_MODEM_OPEN
43335 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43336- port->count);
43337+ atomic_read(&port->count));
43338 #endif
43339- port->count++;
43340+ atomic_inc(&port->count);
43341 port->tty = tty;
43342 /*
43343 * Start up serial port
43344@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43345 #endif
43346 return;
43347 }
43348- if ((tty->count == 1) && (port->count != 1)) {
43349+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43350 /*
43351 * Uh, oh. tty->count is 1, which means that the tty
43352 * structure will be freed. Info->count should always
43353@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43354 * serial port won't be shutdown.
43355 */
43356 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43357- "info->count is %d\n", port->count);
43358- port->count = 1;
43359+ "info->count is %d\n", atomic_read(&port->count));
43360+ atomic_set(&port->count, 1);
43361 }
43362- if (--port->count < 0) {
43363+ if (atomic_dec_return(&port->count) < 0) {
43364 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43365- info->line, port->count);
43366- port->count = 0;
43367+ info->line, atomic_read(&port->count));
43368+ atomic_set(&port->count, 0);
43369 }
43370- if (port->count) {
43371+ if (atomic_read(&port->count)) {
43372 #ifdef ISDN_DEBUG_MODEM_OPEN
43373 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43374 #endif
43375@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43376 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43377 return;
43378 isdn_tty_shutdown(info);
43379- port->count = 0;
43380+ atomic_set(&port->count, 0);
43381 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43382 port->tty = NULL;
43383 wake_up_interruptible(&port->open_wait);
43384@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43385 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43386 modem_info *info = &dev->mdm.info[i];
43387
43388- if (info->port.count == 0)
43389+ if (atomic_read(&info->port.count) == 0)
43390 continue;
43391 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43392 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43393diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43394index e2d4e58..40cd045 100644
43395--- a/drivers/isdn/i4l/isdn_x25iface.c
43396+++ b/drivers/isdn/i4l/isdn_x25iface.c
43397@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43398
43399
43400 static struct concap_proto_ops ix25_pops = {
43401- &isdn_x25iface_proto_new,
43402- &isdn_x25iface_proto_del,
43403- &isdn_x25iface_proto_restart,
43404- &isdn_x25iface_proto_close,
43405- &isdn_x25iface_xmit,
43406- &isdn_x25iface_receive,
43407- &isdn_x25iface_connect_ind,
43408- &isdn_x25iface_disconn_ind
43409+ .proto_new = &isdn_x25iface_proto_new,
43410+ .proto_del = &isdn_x25iface_proto_del,
43411+ .restart = &isdn_x25iface_proto_restart,
43412+ .close = &isdn_x25iface_proto_close,
43413+ .encap_and_xmit = &isdn_x25iface_xmit,
43414+ .data_ind = &isdn_x25iface_receive,
43415+ .connect_ind = &isdn_x25iface_connect_ind,
43416+ .disconn_ind = &isdn_x25iface_disconn_ind
43417 };
43418
43419 /* error message helper function */
43420diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43421index 53d487f..cae33fe 100644
43422--- a/drivers/isdn/icn/icn.c
43423+++ b/drivers/isdn/icn/icn.c
43424@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43425 if (count > len)
43426 count = len;
43427 if (user) {
43428- if (copy_from_user(msg, buf, count))
43429+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43430 return -EFAULT;
43431 } else
43432 memcpy(msg, buf, count);
43433@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43434 ulong a;
43435 ulong flags;
43436 int i;
43437- char cbuf[60];
43438+ char cbuf[80];
43439 isdn_ctrl cmd;
43440 icn_cdef cdef;
43441 char __user *arg;
43442@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43443 break;
43444 if ((c->arg & 255) < ICN_BCH) {
43445 char *p;
43446- char dial[50];
43447 char dcode[4];
43448
43449 a = c->arg;
43450@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43451 } else
43452 /* Normal Dial */
43453 strcpy(dcode, "CAL");
43454- strcpy(dial, p);
43455- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43456- dcode, dial, c->parm.setup.si1,
43457- c->parm.setup.si2, c->parm.setup.eazmsn);
43458+ snprintf(cbuf, sizeof(cbuf),
43459+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43460+ dcode, p, c->parm.setup.si1,
43461+ c->parm.setup.si2, c->parm.setup.eazmsn);
43462 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43463 }
43464 break;
43465diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43466index a4f05c5..1433bc5 100644
43467--- a/drivers/isdn/mISDN/dsp_cmx.c
43468+++ b/drivers/isdn/mISDN/dsp_cmx.c
43469@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43470 static u16 dsp_count; /* last sample count */
43471 static int dsp_count_valid; /* if we have last sample count */
43472
43473-void
43474+void __intentional_overflow(-1)
43475 dsp_cmx_send(void *arg)
43476 {
43477 struct dsp_conf *conf;
43478diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43479index d93e245..e7ece6b 100644
43480--- a/drivers/leds/leds-clevo-mail.c
43481+++ b/drivers/leds/leds-clevo-mail.c
43482@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43483 * detected as working, but in reality it is not) as low as
43484 * possible.
43485 */
43486-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43487+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43488 {
43489 .callback = clevo_mail_led_dmi_callback,
43490 .ident = "Clevo D410J",
43491diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43492index 5b8f938..b73d657 100644
43493--- a/drivers/leds/leds-ss4200.c
43494+++ b/drivers/leds/leds-ss4200.c
43495@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43496 * detected as working, but in reality it is not) as low as
43497 * possible.
43498 */
43499-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43500+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43501 {
43502 .callback = ss4200_led_dmi_callback,
43503 .ident = "Intel SS4200-E",
43504diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43505index 0bf1e4e..b4bf44e 100644
43506--- a/drivers/lguest/core.c
43507+++ b/drivers/lguest/core.c
43508@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43509 * The end address needs +1 because __get_vm_area allocates an
43510 * extra guard page, so we need space for that.
43511 */
43512+
43513+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43514+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43515+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43516+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43517+#else
43518 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43519 VM_ALLOC, switcher_addr, switcher_addr
43520 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43521+#endif
43522+
43523 if (!switcher_vma) {
43524 err = -ENOMEM;
43525 printk("lguest: could not map switcher pages high\n");
43526@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43527 * Now the Switcher is mapped at the right address, we can't fail!
43528 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43529 */
43530- memcpy(switcher_vma->addr, start_switcher_text,
43531+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43532 end_switcher_text - start_switcher_text);
43533
43534 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43535diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43536index bfb39bb..08a603b 100644
43537--- a/drivers/lguest/page_tables.c
43538+++ b/drivers/lguest/page_tables.c
43539@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43540 /*:*/
43541
43542 #ifdef CONFIG_X86_PAE
43543-static void release_pmd(pmd_t *spmd)
43544+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43545 {
43546 /* If the entry's not present, there's nothing to release. */
43547 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43548diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43549index 922a1ac..9dd0c2a 100644
43550--- a/drivers/lguest/x86/core.c
43551+++ b/drivers/lguest/x86/core.c
43552@@ -59,7 +59,7 @@ static struct {
43553 /* Offset from where switcher.S was compiled to where we've copied it */
43554 static unsigned long switcher_offset(void)
43555 {
43556- return switcher_addr - (unsigned long)start_switcher_text;
43557+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43558 }
43559
43560 /* This cpu's struct lguest_pages (after the Switcher text page) */
43561@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43562 * These copies are pretty cheap, so we do them unconditionally: */
43563 /* Save the current Host top-level page directory.
43564 */
43565+
43566+#ifdef CONFIG_PAX_PER_CPU_PGD
43567+ pages->state.host_cr3 = read_cr3();
43568+#else
43569 pages->state.host_cr3 = __pa(current->mm->pgd);
43570+#endif
43571+
43572 /*
43573 * Set up the Guest's page tables to see this CPU's pages (and no
43574 * other CPU's pages).
43575@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43576 * compiled-in switcher code and the high-mapped copy we just made.
43577 */
43578 for (i = 0; i < IDT_ENTRIES; i++)
43579- default_idt_entries[i] += switcher_offset();
43580+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43581
43582 /*
43583 * Set up the Switcher's per-cpu areas.
43584@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43585 * it will be undisturbed when we switch. To change %cs and jump we
43586 * need this structure to feed to Intel's "lcall" instruction.
43587 */
43588- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43589+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43590 lguest_entry.segment = LGUEST_CS;
43591
43592 /*
43593diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43594index 40634b0..4f5855e 100644
43595--- a/drivers/lguest/x86/switcher_32.S
43596+++ b/drivers/lguest/x86/switcher_32.S
43597@@ -87,6 +87,7 @@
43598 #include <asm/page.h>
43599 #include <asm/segment.h>
43600 #include <asm/lguest.h>
43601+#include <asm/processor-flags.h>
43602
43603 // We mark the start of the code to copy
43604 // It's placed in .text tho it's never run here
43605@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43606 // Changes type when we load it: damn Intel!
43607 // For after we switch over our page tables
43608 // That entry will be read-only: we'd crash.
43609+
43610+#ifdef CONFIG_PAX_KERNEXEC
43611+ mov %cr0, %edx
43612+ xor $X86_CR0_WP, %edx
43613+ mov %edx, %cr0
43614+#endif
43615+
43616 movl $(GDT_ENTRY_TSS*8), %edx
43617 ltr %dx
43618
43619@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43620 // Let's clear it again for our return.
43621 // The GDT descriptor of the Host
43622 // Points to the table after two "size" bytes
43623- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43624+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43625 // Clear "used" from type field (byte 5, bit 2)
43626- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43627+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43628+
43629+#ifdef CONFIG_PAX_KERNEXEC
43630+ mov %cr0, %eax
43631+ xor $X86_CR0_WP, %eax
43632+ mov %eax, %cr0
43633+#endif
43634
43635 // Once our page table's switched, the Guest is live!
43636 // The Host fades as we run this final step.
43637@@ -295,13 +309,12 @@ deliver_to_host:
43638 // I consulted gcc, and it gave
43639 // These instructions, which I gladly credit:
43640 leal (%edx,%ebx,8), %eax
43641- movzwl (%eax),%edx
43642- movl 4(%eax), %eax
43643- xorw %ax, %ax
43644- orl %eax, %edx
43645+ movl 4(%eax), %edx
43646+ movw (%eax), %dx
43647 // Now the address of the handler's in %edx
43648 // We call it now: its "iret" drops us home.
43649- jmp *%edx
43650+ ljmp $__KERNEL_CS, $1f
43651+1: jmp *%edx
43652
43653 // Every interrupt can come to us here
43654 // But we must truly tell each apart.
43655diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43656index 7ef7461..5a09dac 100644
43657--- a/drivers/md/bcache/closure.h
43658+++ b/drivers/md/bcache/closure.h
43659@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43660 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43661 struct workqueue_struct *wq)
43662 {
43663- BUG_ON(object_is_on_stack(cl));
43664+ BUG_ON(object_starts_on_stack(cl));
43665 closure_set_ip(cl);
43666 cl->fn = fn;
43667 cl->wq = wq;
43668diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43669index 4195a01..42527ac 100644
43670--- a/drivers/md/bitmap.c
43671+++ b/drivers/md/bitmap.c
43672@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43673 chunk_kb ? "KB" : "B");
43674 if (bitmap->storage.file) {
43675 seq_printf(seq, ", file: ");
43676- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43677+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43678 }
43679
43680 seq_printf(seq, "\n");
43681diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43682index 5152142..623d141 100644
43683--- a/drivers/md/dm-ioctl.c
43684+++ b/drivers/md/dm-ioctl.c
43685@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43686 cmd == DM_LIST_VERSIONS_CMD)
43687 return 0;
43688
43689- if ((cmd == DM_DEV_CREATE_CMD)) {
43690+ if (cmd == DM_DEV_CREATE_CMD) {
43691 if (!*param->name) {
43692 DMWARN("name not supplied when creating device");
43693 return -EINVAL;
43694diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43695index 7dfdb5c..4caada6 100644
43696--- a/drivers/md/dm-raid1.c
43697+++ b/drivers/md/dm-raid1.c
43698@@ -40,7 +40,7 @@ enum dm_raid1_error {
43699
43700 struct mirror {
43701 struct mirror_set *ms;
43702- atomic_t error_count;
43703+ atomic_unchecked_t error_count;
43704 unsigned long error_type;
43705 struct dm_dev *dev;
43706 sector_t offset;
43707@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43708 struct mirror *m;
43709
43710 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43711- if (!atomic_read(&m->error_count))
43712+ if (!atomic_read_unchecked(&m->error_count))
43713 return m;
43714
43715 return NULL;
43716@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43717 * simple way to tell if a device has encountered
43718 * errors.
43719 */
43720- atomic_inc(&m->error_count);
43721+ atomic_inc_unchecked(&m->error_count);
43722
43723 if (test_and_set_bit(error_type, &m->error_type))
43724 return;
43725@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43726 struct mirror *m = get_default_mirror(ms);
43727
43728 do {
43729- if (likely(!atomic_read(&m->error_count)))
43730+ if (likely(!atomic_read_unchecked(&m->error_count)))
43731 return m;
43732
43733 if (m-- == ms->mirror)
43734@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43735 {
43736 struct mirror *default_mirror = get_default_mirror(m->ms);
43737
43738- return !atomic_read(&default_mirror->error_count);
43739+ return !atomic_read_unchecked(&default_mirror->error_count);
43740 }
43741
43742 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43743@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43744 */
43745 if (likely(region_in_sync(ms, region, 1)))
43746 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43747- else if (m && atomic_read(&m->error_count))
43748+ else if (m && atomic_read_unchecked(&m->error_count))
43749 m = NULL;
43750
43751 if (likely(m))
43752@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43753 }
43754
43755 ms->mirror[mirror].ms = ms;
43756- atomic_set(&(ms->mirror[mirror].error_count), 0);
43757+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43758 ms->mirror[mirror].error_type = 0;
43759 ms->mirror[mirror].offset = offset;
43760
43761@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43762 */
43763 static char device_status_char(struct mirror *m)
43764 {
43765- if (!atomic_read(&(m->error_count)))
43766+ if (!atomic_read_unchecked(&(m->error_count)))
43767 return 'A';
43768
43769 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43770diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43771index 28a9012..9c0f6a5 100644
43772--- a/drivers/md/dm-stats.c
43773+++ b/drivers/md/dm-stats.c
43774@@ -382,7 +382,7 @@ do_sync_free:
43775 synchronize_rcu_expedited();
43776 dm_stat_free(&s->rcu_head);
43777 } else {
43778- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43779+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43780 call_rcu(&s->rcu_head, dm_stat_free);
43781 }
43782 return 0;
43783@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43784 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43785 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43786 ));
43787- ACCESS_ONCE(last->last_sector) = end_sector;
43788- ACCESS_ONCE(last->last_rw) = bi_rw;
43789+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43790+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43791 }
43792
43793 rcu_read_lock();
43794diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43795index d1600d2..4c3af3a 100644
43796--- a/drivers/md/dm-stripe.c
43797+++ b/drivers/md/dm-stripe.c
43798@@ -21,7 +21,7 @@ struct stripe {
43799 struct dm_dev *dev;
43800 sector_t physical_start;
43801
43802- atomic_t error_count;
43803+ atomic_unchecked_t error_count;
43804 };
43805
43806 struct stripe_c {
43807@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43808 kfree(sc);
43809 return r;
43810 }
43811- atomic_set(&(sc->stripe[i].error_count), 0);
43812+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43813 }
43814
43815 ti->private = sc;
43816@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43817 DMEMIT("%d ", sc->stripes);
43818 for (i = 0; i < sc->stripes; i++) {
43819 DMEMIT("%s ", sc->stripe[i].dev->name);
43820- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43821+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43822 'D' : 'A';
43823 }
43824 buffer[i] = '\0';
43825@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43826 */
43827 for (i = 0; i < sc->stripes; i++)
43828 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43829- atomic_inc(&(sc->stripe[i].error_count));
43830- if (atomic_read(&(sc->stripe[i].error_count)) <
43831+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43832+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43833 DM_IO_ERROR_THRESHOLD)
43834 schedule_work(&sc->trigger_event);
43835 }
43836diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43837index 6a7f2b8..fea0bde 100644
43838--- a/drivers/md/dm-table.c
43839+++ b/drivers/md/dm-table.c
43840@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43841 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43842 struct mapped_device *md)
43843 {
43844- static char *_claim_ptr = "I belong to device-mapper";
43845+ static char _claim_ptr[] = "I belong to device-mapper";
43846 struct block_device *bdev;
43847
43848 int r;
43849@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43850 if (!dev_size)
43851 return 0;
43852
43853- if ((start >= dev_size) || (start + len > dev_size)) {
43854+ if ((start >= dev_size) || (len > dev_size - start)) {
43855 DMWARN("%s: %s too small for target: "
43856 "start=%llu, len=%llu, dev_size=%llu",
43857 dm_device_name(ti->table->md), bdevname(bdev, b),
43858diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43859index fb9efc8..81e8986 100644
43860--- a/drivers/md/dm-thin-metadata.c
43861+++ b/drivers/md/dm-thin-metadata.c
43862@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43863 {
43864 pmd->info.tm = pmd->tm;
43865 pmd->info.levels = 2;
43866- pmd->info.value_type.context = pmd->data_sm;
43867+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43868 pmd->info.value_type.size = sizeof(__le64);
43869 pmd->info.value_type.inc = data_block_inc;
43870 pmd->info.value_type.dec = data_block_dec;
43871@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43872
43873 pmd->bl_info.tm = pmd->tm;
43874 pmd->bl_info.levels = 1;
43875- pmd->bl_info.value_type.context = pmd->data_sm;
43876+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43877 pmd->bl_info.value_type.size = sizeof(__le64);
43878 pmd->bl_info.value_type.inc = data_block_inc;
43879 pmd->bl_info.value_type.dec = data_block_dec;
43880diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43881index 8c53b09..f1fb2b0 100644
43882--- a/drivers/md/dm.c
43883+++ b/drivers/md/dm.c
43884@@ -185,9 +185,9 @@ struct mapped_device {
43885 /*
43886 * Event handling.
43887 */
43888- atomic_t event_nr;
43889+ atomic_unchecked_t event_nr;
43890 wait_queue_head_t eventq;
43891- atomic_t uevent_seq;
43892+ atomic_unchecked_t uevent_seq;
43893 struct list_head uevent_list;
43894 spinlock_t uevent_lock; /* Protect access to uevent_list */
43895
43896@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43897 spin_lock_init(&md->deferred_lock);
43898 atomic_set(&md->holders, 1);
43899 atomic_set(&md->open_count, 0);
43900- atomic_set(&md->event_nr, 0);
43901- atomic_set(&md->uevent_seq, 0);
43902+ atomic_set_unchecked(&md->event_nr, 0);
43903+ atomic_set_unchecked(&md->uevent_seq, 0);
43904 INIT_LIST_HEAD(&md->uevent_list);
43905 spin_lock_init(&md->uevent_lock);
43906
43907@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43908
43909 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43910
43911- atomic_inc(&md->event_nr);
43912+ atomic_inc_unchecked(&md->event_nr);
43913 wake_up(&md->eventq);
43914 }
43915
43916@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43917
43918 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43919 {
43920- return atomic_add_return(1, &md->uevent_seq);
43921+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43922 }
43923
43924 uint32_t dm_get_event_nr(struct mapped_device *md)
43925 {
43926- return atomic_read(&md->event_nr);
43927+ return atomic_read_unchecked(&md->event_nr);
43928 }
43929
43930 int dm_wait_event(struct mapped_device *md, int event_nr)
43931 {
43932 return wait_event_interruptible(md->eventq,
43933- (event_nr != atomic_read(&md->event_nr)));
43934+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43935 }
43936
43937 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43938diff --git a/drivers/md/md.c b/drivers/md/md.c
43939index 4ad5cc4..0f19664 100644
43940--- a/drivers/md/md.c
43941+++ b/drivers/md/md.c
43942@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43943 * start build, activate spare
43944 */
43945 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43946-static atomic_t md_event_count;
43947+static atomic_unchecked_t md_event_count;
43948 void md_new_event(struct mddev *mddev)
43949 {
43950- atomic_inc(&md_event_count);
43951+ atomic_inc_unchecked(&md_event_count);
43952 wake_up(&md_event_waiters);
43953 }
43954 EXPORT_SYMBOL_GPL(md_new_event);
43955@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43956 */
43957 static void md_new_event_inintr(struct mddev *mddev)
43958 {
43959- atomic_inc(&md_event_count);
43960+ atomic_inc_unchecked(&md_event_count);
43961 wake_up(&md_event_waiters);
43962 }
43963
43964@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43965 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43966 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43967 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43968- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43969+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43970
43971 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43972 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43973@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43974 else
43975 sb->resync_offset = cpu_to_le64(0);
43976
43977- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43978+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43979
43980 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43981 sb->size = cpu_to_le64(mddev->dev_sectors);
43982@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43983 static ssize_t
43984 errors_show(struct md_rdev *rdev, char *page)
43985 {
43986- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43987+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43988 }
43989
43990 static ssize_t
43991@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43992 char *e;
43993 unsigned long n = simple_strtoul(buf, &e, 10);
43994 if (*buf && (*e == 0 || *e == '\n')) {
43995- atomic_set(&rdev->corrected_errors, n);
43996+ atomic_set_unchecked(&rdev->corrected_errors, n);
43997 return len;
43998 }
43999 return -EINVAL;
44000@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44001 rdev->sb_loaded = 0;
44002 rdev->bb_page = NULL;
44003 atomic_set(&rdev->nr_pending, 0);
44004- atomic_set(&rdev->read_errors, 0);
44005- atomic_set(&rdev->corrected_errors, 0);
44006+ atomic_set_unchecked(&rdev->read_errors, 0);
44007+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44008
44009 INIT_LIST_HEAD(&rdev->same_set);
44010 init_waitqueue_head(&rdev->blocked_wait);
44011@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44012
44013 spin_unlock(&pers_lock);
44014 seq_printf(seq, "\n");
44015- seq->poll_event = atomic_read(&md_event_count);
44016+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44017 return 0;
44018 }
44019 if (v == (void*)2) {
44020@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44021 return error;
44022
44023 seq = file->private_data;
44024- seq->poll_event = atomic_read(&md_event_count);
44025+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44026 return error;
44027 }
44028
44029@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44030 /* always allow read */
44031 mask = POLLIN | POLLRDNORM;
44032
44033- if (seq->poll_event != atomic_read(&md_event_count))
44034+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44035 mask |= POLLERR | POLLPRI;
44036 return mask;
44037 }
44038@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44039 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44040 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44041 (int)part_stat_read(&disk->part0, sectors[1]) -
44042- atomic_read(&disk->sync_io);
44043+ atomic_read_unchecked(&disk->sync_io);
44044 /* sync IO will cause sync_io to increase before the disk_stats
44045 * as sync_io is counted when a request starts, and
44046 * disk_stats is counted when it completes.
44047diff --git a/drivers/md/md.h b/drivers/md/md.h
44048index 07bba96..2d6788c 100644
44049--- a/drivers/md/md.h
44050+++ b/drivers/md/md.h
44051@@ -94,13 +94,13 @@ struct md_rdev {
44052 * only maintained for arrays that
44053 * support hot removal
44054 */
44055- atomic_t read_errors; /* number of consecutive read errors that
44056+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44057 * we have tried to ignore.
44058 */
44059 struct timespec last_read_error; /* monotonic time since our
44060 * last read error
44061 */
44062- atomic_t corrected_errors; /* number of corrected read errors,
44063+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44064 * for reporting to userspace and storing
44065 * in superblock.
44066 */
44067@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44068
44069 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44070 {
44071- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44072+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44073 }
44074
44075 struct md_personality
44076diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44077index 786b689..ea8c956 100644
44078--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44079+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44080@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44081 * Flick into a mode where all blocks get allocated in the new area.
44082 */
44083 smm->begin = old_len;
44084- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44085+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44086
44087 /*
44088 * Extend.
44089@@ -710,7 +710,7 @@ out:
44090 /*
44091 * Switch back to normal behaviour.
44092 */
44093- memcpy(sm, &ops, sizeof(*sm));
44094+ memcpy((void *)sm, &ops, sizeof(*sm));
44095 return r;
44096 }
44097
44098diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44099index 3e6d115..ffecdeb 100644
44100--- a/drivers/md/persistent-data/dm-space-map.h
44101+++ b/drivers/md/persistent-data/dm-space-map.h
44102@@ -71,6 +71,7 @@ struct dm_space_map {
44103 dm_sm_threshold_fn fn,
44104 void *context);
44105 };
44106+typedef struct dm_space_map __no_const dm_space_map_no_const;
44107
44108 /*----------------------------------------------------------------*/
44109
44110diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44111index 4a6ca1c..e952750 100644
44112--- a/drivers/md/raid1.c
44113+++ b/drivers/md/raid1.c
44114@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44115 if (r1_sync_page_io(rdev, sect, s,
44116 bio->bi_io_vec[idx].bv_page,
44117 READ) != 0)
44118- atomic_add(s, &rdev->corrected_errors);
44119+ atomic_add_unchecked(s, &rdev->corrected_errors);
44120 }
44121 sectors -= s;
44122 sect += s;
44123@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44124 test_bit(In_sync, &rdev->flags)) {
44125 if (r1_sync_page_io(rdev, sect, s,
44126 conf->tmppage, READ)) {
44127- atomic_add(s, &rdev->corrected_errors);
44128+ atomic_add_unchecked(s, &rdev->corrected_errors);
44129 printk(KERN_INFO
44130 "md/raid1:%s: read error corrected "
44131 "(%d sectors at %llu on %s)\n",
44132diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44133index 33fc408..fc61709 100644
44134--- a/drivers/md/raid10.c
44135+++ b/drivers/md/raid10.c
44136@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44137 /* The write handler will notice the lack of
44138 * R10BIO_Uptodate and record any errors etc
44139 */
44140- atomic_add(r10_bio->sectors,
44141+ atomic_add_unchecked(r10_bio->sectors,
44142 &conf->mirrors[d].rdev->corrected_errors);
44143
44144 /* for reconstruct, we always reschedule after a read.
44145@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44146 {
44147 struct timespec cur_time_mon;
44148 unsigned long hours_since_last;
44149- unsigned int read_errors = atomic_read(&rdev->read_errors);
44150+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44151
44152 ktime_get_ts(&cur_time_mon);
44153
44154@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44155 * overflowing the shift of read_errors by hours_since_last.
44156 */
44157 if (hours_since_last >= 8 * sizeof(read_errors))
44158- atomic_set(&rdev->read_errors, 0);
44159+ atomic_set_unchecked(&rdev->read_errors, 0);
44160 else
44161- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44162+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44163 }
44164
44165 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44166@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44167 return;
44168
44169 check_decay_read_errors(mddev, rdev);
44170- atomic_inc(&rdev->read_errors);
44171- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44172+ atomic_inc_unchecked(&rdev->read_errors);
44173+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44174 char b[BDEVNAME_SIZE];
44175 bdevname(rdev->bdev, b);
44176
44177@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44178 "md/raid10:%s: %s: Raid device exceeded "
44179 "read_error threshold [cur %d:max %d]\n",
44180 mdname(mddev), b,
44181- atomic_read(&rdev->read_errors), max_read_errors);
44182+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44183 printk(KERN_NOTICE
44184 "md/raid10:%s: %s: Failing raid device\n",
44185 mdname(mddev), b);
44186@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44187 sect +
44188 choose_data_offset(r10_bio, rdev)),
44189 bdevname(rdev->bdev, b));
44190- atomic_add(s, &rdev->corrected_errors);
44191+ atomic_add_unchecked(s, &rdev->corrected_errors);
44192 }
44193
44194 rdev_dec_pending(rdev, mddev);
44195diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44196index 16f5c21..4df20dc 100644
44197--- a/drivers/md/raid5.c
44198+++ b/drivers/md/raid5.c
44199@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44200 mdname(conf->mddev), STRIPE_SECTORS,
44201 (unsigned long long)s,
44202 bdevname(rdev->bdev, b));
44203- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44204+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44205 clear_bit(R5_ReadError, &sh->dev[i].flags);
44206 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44207 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44208 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44209
44210- if (atomic_read(&rdev->read_errors))
44211- atomic_set(&rdev->read_errors, 0);
44212+ if (atomic_read_unchecked(&rdev->read_errors))
44213+ atomic_set_unchecked(&rdev->read_errors, 0);
44214 } else {
44215 const char *bdn = bdevname(rdev->bdev, b);
44216 int retry = 0;
44217 int set_bad = 0;
44218
44219 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44220- atomic_inc(&rdev->read_errors);
44221+ atomic_inc_unchecked(&rdev->read_errors);
44222 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44223 printk_ratelimited(
44224 KERN_WARNING
44225@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44226 mdname(conf->mddev),
44227 (unsigned long long)s,
44228 bdn);
44229- } else if (atomic_read(&rdev->read_errors)
44230+ } else if (atomic_read_unchecked(&rdev->read_errors)
44231 > conf->max_nr_stripes)
44232 printk(KERN_WARNING
44233 "md/raid:%s: Too many read errors, failing device %s.\n",
44234diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44235index 983db75..ef9248c 100644
44236--- a/drivers/media/dvb-core/dvbdev.c
44237+++ b/drivers/media/dvb-core/dvbdev.c
44238@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44239 const struct dvb_device *template, void *priv, int type)
44240 {
44241 struct dvb_device *dvbdev;
44242- struct file_operations *dvbdevfops;
44243+ file_operations_no_const *dvbdevfops;
44244 struct device *clsdev;
44245 int minor;
44246 int id;
44247diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44248index 9b6c3bb..baeb5c7 100644
44249--- a/drivers/media/dvb-frontends/dib3000.h
44250+++ b/drivers/media/dvb-frontends/dib3000.h
44251@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44252 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44253 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44254 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44255-};
44256+} __no_const;
44257
44258 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44259 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44260diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44261index d5a7a13..703560f 100644
44262--- a/drivers/media/media-device.c
44263+++ b/drivers/media/media-device.c
44264@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44265 struct media_entity *ent;
44266 struct media_entity_desc u_ent;
44267
44268+ memset(&u_ent, 0, sizeof(u_ent));
44269 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44270 return -EFAULT;
44271
44272diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44273index ed8cb90..5ef7f79 100644
44274--- a/drivers/media/pci/cx88/cx88-video.c
44275+++ b/drivers/media/pci/cx88/cx88-video.c
44276@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44277
44278 /* ------------------------------------------------------------------ */
44279
44280-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44281-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44282-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44283+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44284+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44285+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44286
44287 module_param_array(video_nr, int, NULL, 0444);
44288 module_param_array(vbi_nr, int, NULL, 0444);
44289diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44290index 802642d..5534900 100644
44291--- a/drivers/media/pci/ivtv/ivtv-driver.c
44292+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44293@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44294 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44295
44296 /* ivtv instance counter */
44297-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44298+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44299
44300 /* Parameter declarations */
44301 static int cardtype[IVTV_MAX_CARDS];
44302diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44303index dfd0a21..6bbb465 100644
44304--- a/drivers/media/platform/omap/omap_vout.c
44305+++ b/drivers/media/platform/omap/omap_vout.c
44306@@ -63,7 +63,6 @@ enum omap_vout_channels {
44307 OMAP_VIDEO2,
44308 };
44309
44310-static struct videobuf_queue_ops video_vbq_ops;
44311 /* Variables configurable through module params*/
44312 static u32 video1_numbuffers = 3;
44313 static u32 video2_numbuffers = 3;
44314@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44315 {
44316 struct videobuf_queue *q;
44317 struct omap_vout_device *vout = NULL;
44318+ static struct videobuf_queue_ops video_vbq_ops = {
44319+ .buf_setup = omap_vout_buffer_setup,
44320+ .buf_prepare = omap_vout_buffer_prepare,
44321+ .buf_release = omap_vout_buffer_release,
44322+ .buf_queue = omap_vout_buffer_queue,
44323+ };
44324
44325 vout = video_drvdata(file);
44326 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44327@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44328 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44329
44330 q = &vout->vbq;
44331- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44332- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44333- video_vbq_ops.buf_release = omap_vout_buffer_release;
44334- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44335 spin_lock_init(&vout->vbq_lock);
44336
44337 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44338diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44339index fb2acc5..a2fcbdc4 100644
44340--- a/drivers/media/platform/s5p-tv/mixer.h
44341+++ b/drivers/media/platform/s5p-tv/mixer.h
44342@@ -156,7 +156,7 @@ struct mxr_layer {
44343 /** layer index (unique identifier) */
44344 int idx;
44345 /** callbacks for layer methods */
44346- struct mxr_layer_ops ops;
44347+ struct mxr_layer_ops *ops;
44348 /** format array */
44349 const struct mxr_format **fmt_array;
44350 /** size of format array */
44351diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44352index 74344c7..a39e70e 100644
44353--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44354+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44355@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44356 {
44357 struct mxr_layer *layer;
44358 int ret;
44359- struct mxr_layer_ops ops = {
44360+ static struct mxr_layer_ops ops = {
44361 .release = mxr_graph_layer_release,
44362 .buffer_set = mxr_graph_buffer_set,
44363 .stream_set = mxr_graph_stream_set,
44364diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44365index b713403..53cb5ad 100644
44366--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44367+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44368@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44369 layer->update_buf = next;
44370 }
44371
44372- layer->ops.buffer_set(layer, layer->update_buf);
44373+ layer->ops->buffer_set(layer, layer->update_buf);
44374
44375 if (done && done != layer->shadow_buf)
44376 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44377diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44378index c5059ba..2649f28 100644
44379--- a/drivers/media/platform/s5p-tv/mixer_video.c
44380+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44381@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44382 layer->geo.src.height = layer->geo.src.full_height;
44383
44384 mxr_geometry_dump(mdev, &layer->geo);
44385- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44386+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44387 mxr_geometry_dump(mdev, &layer->geo);
44388 }
44389
44390@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44391 layer->geo.dst.full_width = mbus_fmt.width;
44392 layer->geo.dst.full_height = mbus_fmt.height;
44393 layer->geo.dst.field = mbus_fmt.field;
44394- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44395+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44396
44397 mxr_geometry_dump(mdev, &layer->geo);
44398 }
44399@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44400 /* set source size to highest accepted value */
44401 geo->src.full_width = max(geo->dst.full_width, pix->width);
44402 geo->src.full_height = max(geo->dst.full_height, pix->height);
44403- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44404+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44405 mxr_geometry_dump(mdev, &layer->geo);
44406 /* set cropping to total visible screen */
44407 geo->src.width = pix->width;
44408@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44409 geo->src.x_offset = 0;
44410 geo->src.y_offset = 0;
44411 /* assure consistency of geometry */
44412- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44413+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44414 mxr_geometry_dump(mdev, &layer->geo);
44415 /* set full size to lowest possible value */
44416 geo->src.full_width = 0;
44417 geo->src.full_height = 0;
44418- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44419+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44420 mxr_geometry_dump(mdev, &layer->geo);
44421
44422 /* returning results */
44423@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44424 target->width = s->r.width;
44425 target->height = s->r.height;
44426
44427- layer->ops.fix_geometry(layer, stage, s->flags);
44428+ layer->ops->fix_geometry(layer, stage, s->flags);
44429
44430 /* retrieve update selection rectangle */
44431 res.left = target->x_offset;
44432@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44433 mxr_output_get(mdev);
44434
44435 mxr_layer_update_output(layer);
44436- layer->ops.format_set(layer);
44437+ layer->ops->format_set(layer);
44438 /* enabling layer in hardware */
44439 spin_lock_irqsave(&layer->enq_slock, flags);
44440 layer->state = MXR_LAYER_STREAMING;
44441 spin_unlock_irqrestore(&layer->enq_slock, flags);
44442
44443- layer->ops.stream_set(layer, MXR_ENABLE);
44444+ layer->ops->stream_set(layer, MXR_ENABLE);
44445 mxr_streamer_get(mdev);
44446
44447 return 0;
44448@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44449 spin_unlock_irqrestore(&layer->enq_slock, flags);
44450
44451 /* disabling layer in hardware */
44452- layer->ops.stream_set(layer, MXR_DISABLE);
44453+ layer->ops->stream_set(layer, MXR_DISABLE);
44454 /* remove one streamer */
44455 mxr_streamer_put(mdev);
44456 /* allow changes in output configuration */
44457@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44458
44459 void mxr_layer_release(struct mxr_layer *layer)
44460 {
44461- if (layer->ops.release)
44462- layer->ops.release(layer);
44463+ if (layer->ops->release)
44464+ layer->ops->release(layer);
44465 }
44466
44467 void mxr_base_layer_release(struct mxr_layer *layer)
44468@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44469
44470 layer->mdev = mdev;
44471 layer->idx = idx;
44472- layer->ops = *ops;
44473+ layer->ops = ops;
44474
44475 spin_lock_init(&layer->enq_slock);
44476 INIT_LIST_HEAD(&layer->enq_list);
44477diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44478index c9388c4..ce71ece 100644
44479--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44480+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44481@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44482 {
44483 struct mxr_layer *layer;
44484 int ret;
44485- struct mxr_layer_ops ops = {
44486+ static struct mxr_layer_ops ops = {
44487 .release = mxr_vp_layer_release,
44488 .buffer_set = mxr_vp_buffer_set,
44489 .stream_set = mxr_vp_stream_set,
44490diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44491index 2d4e73b..8b4d5b6 100644
44492--- a/drivers/media/platform/vivi.c
44493+++ b/drivers/media/platform/vivi.c
44494@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44495 MODULE_LICENSE("Dual BSD/GPL");
44496 MODULE_VERSION(VIVI_VERSION);
44497
44498-static unsigned video_nr = -1;
44499-module_param(video_nr, uint, 0644);
44500+static int video_nr = -1;
44501+module_param(video_nr, int, 0644);
44502 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44503
44504 static unsigned n_devs = 1;
44505diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44506index 545c04c..a14bded 100644
44507--- a/drivers/media/radio/radio-cadet.c
44508+++ b/drivers/media/radio/radio-cadet.c
44509@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44510 unsigned char readbuf[RDS_BUFFER];
44511 int i = 0;
44512
44513+ if (count > RDS_BUFFER)
44514+ return -EFAULT;
44515 mutex_lock(&dev->lock);
44516 if (dev->rdsstat == 0)
44517 cadet_start_rds(dev);
44518@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44519 while (i < count && dev->rdsin != dev->rdsout)
44520 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44521
44522- if (i && copy_to_user(data, readbuf, i))
44523+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44524 i = -EFAULT;
44525 unlock:
44526 mutex_unlock(&dev->lock);
44527diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44528index 5236035..c622c74 100644
44529--- a/drivers/media/radio/radio-maxiradio.c
44530+++ b/drivers/media/radio/radio-maxiradio.c
44531@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44532 /* TEA5757 pin mappings */
44533 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44534
44535-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44536+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44537
44538 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44539 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44540diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44541index 050b3bb..79f62b9 100644
44542--- a/drivers/media/radio/radio-shark.c
44543+++ b/drivers/media/radio/radio-shark.c
44544@@ -79,7 +79,7 @@ struct shark_device {
44545 u32 last_val;
44546 };
44547
44548-static atomic_t shark_instance = ATOMIC_INIT(0);
44549+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44550
44551 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44552 {
44553diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44554index 8654e0d..0608a64 100644
44555--- a/drivers/media/radio/radio-shark2.c
44556+++ b/drivers/media/radio/radio-shark2.c
44557@@ -74,7 +74,7 @@ struct shark_device {
44558 u8 *transfer_buffer;
44559 };
44560
44561-static atomic_t shark_instance = ATOMIC_INIT(0);
44562+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44563
44564 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44565 {
44566diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44567index 2fd9009..278cc1e 100644
44568--- a/drivers/media/radio/radio-si476x.c
44569+++ b/drivers/media/radio/radio-si476x.c
44570@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44571 struct si476x_radio *radio;
44572 struct v4l2_ctrl *ctrl;
44573
44574- static atomic_t instance = ATOMIC_INIT(0);
44575+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44576
44577 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44578 if (!radio)
44579diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44580index a1c641e..3007da9 100644
44581--- a/drivers/media/usb/dvb-usb/cxusb.c
44582+++ b/drivers/media/usb/dvb-usb/cxusb.c
44583@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44584
44585 struct dib0700_adapter_state {
44586 int (*set_param_save) (struct dvb_frontend *);
44587-};
44588+} __no_const;
44589
44590 static int dib7070_set_param_override(struct dvb_frontend *fe)
44591 {
44592diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44593index ae0f56a..ec71784 100644
44594--- a/drivers/media/usb/dvb-usb/dw2102.c
44595+++ b/drivers/media/usb/dvb-usb/dw2102.c
44596@@ -118,7 +118,7 @@ struct su3000_state {
44597
44598 struct s6x0_state {
44599 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44600-};
44601+} __no_const;
44602
44603 /* debug */
44604 static int dvb_usb_dw2102_debug;
44605diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44606index b63a5e5..b16a062 100644
44607--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44608+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44609@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44610 __u32 reserved;
44611 };
44612
44613-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44614+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44615 enum v4l2_memory memory)
44616 {
44617 void __user *up_pln;
44618@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44619 return 0;
44620 }
44621
44622-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44623+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44624 enum v4l2_memory memory)
44625 {
44626 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44627@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44628 * by passing a very big num_planes value */
44629 uplane = compat_alloc_user_space(num_planes *
44630 sizeof(struct v4l2_plane));
44631- kp->m.planes = uplane;
44632+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44633
44634 while (--num_planes >= 0) {
44635 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44636@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44637 if (num_planes == 0)
44638 return 0;
44639
44640- uplane = kp->m.planes;
44641+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44642 if (get_user(p, &up->m.planes))
44643 return -EFAULT;
44644 uplane32 = compat_ptr(p);
44645@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44646 get_user(kp->capability, &up->capability) ||
44647 get_user(kp->flags, &up->flags))
44648 return -EFAULT;
44649- kp->base = compat_ptr(tmp);
44650+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44651 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44652 return 0;
44653 }
44654@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44655 n * sizeof(struct v4l2_ext_control32)))
44656 return -EFAULT;
44657 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44658- kp->controls = kcontrols;
44659+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44660 while (--n >= 0) {
44661 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44662 return -EFAULT;
44663@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44664 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44665 {
44666 struct v4l2_ext_control32 __user *ucontrols;
44667- struct v4l2_ext_control __user *kcontrols = kp->controls;
44668+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44669 int n = kp->count;
44670 compat_caddr_t p;
44671
44672@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44673 put_user(kp->start_block, &up->start_block) ||
44674 put_user(kp->blocks, &up->blocks) ||
44675 put_user(tmp, &up->edid) ||
44676- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44677+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44678 return -EFAULT;
44679 return 0;
44680 }
44681diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44682index 6ff002b..6b9316b 100644
44683--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44684+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44685@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44686 return 0;
44687
44688 case V4L2_CTRL_TYPE_STRING:
44689- len = strlen(c->string);
44690- if (len < ctrl->minimum)
44691+ len = strlen_user(c->string);
44692+ if (!len || len < ctrl->minimum)
44693 return -ERANGE;
44694 if ((len - ctrl->minimum) % ctrl->step)
44695 return -ERANGE;
44696diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44697index 02d1b63..5fd6b16 100644
44698--- a/drivers/media/v4l2-core/v4l2-device.c
44699+++ b/drivers/media/v4l2-core/v4l2-device.c
44700@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44701 EXPORT_SYMBOL_GPL(v4l2_device_put);
44702
44703 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44704- atomic_t *instance)
44705+ atomic_unchecked_t *instance)
44706 {
44707- int num = atomic_inc_return(instance) - 1;
44708+ int num = atomic_inc_return_unchecked(instance) - 1;
44709 int len = strlen(basename);
44710
44711 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44712diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44713index 707aef7..93b8ac0 100644
44714--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44715+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44716@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44717 struct file *file, void *fh, void *p);
44718 } u;
44719 void (*debug)(const void *arg, bool write_only);
44720-};
44721+} __do_const;
44722+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44723
44724 /* This control needs a priority check */
44725 #define INFO_FL_PRIO (1 << 0)
44726@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44727 struct video_device *vfd = video_devdata(file);
44728 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44729 bool write_only = false;
44730- struct v4l2_ioctl_info default_info;
44731+ v4l2_ioctl_info_no_const default_info;
44732 const struct v4l2_ioctl_info *info;
44733 void *fh = file->private_data;
44734 struct v4l2_fh *vfh = NULL;
44735@@ -2197,7 +2198,7 @@ done:
44736 }
44737
44738 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44739- void * __user *user_ptr, void ***kernel_ptr)
44740+ void __user **user_ptr, void ***kernel_ptr)
44741 {
44742 int ret = 0;
44743
44744@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44745 ret = -EINVAL;
44746 break;
44747 }
44748- *user_ptr = (void __user *)buf->m.planes;
44749+ *user_ptr = (void __force_user *)buf->m.planes;
44750 *kernel_ptr = (void *)&buf->m.planes;
44751 *array_size = sizeof(struct v4l2_plane) * buf->length;
44752 ret = 1;
44753@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44754 ret = -EINVAL;
44755 break;
44756 }
44757- *user_ptr = (void __user *)ctrls->controls;
44758+ *user_ptr = (void __force_user *)ctrls->controls;
44759 *kernel_ptr = (void *)&ctrls->controls;
44760 *array_size = sizeof(struct v4l2_ext_control)
44761 * ctrls->count;
44762@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44763 }
44764
44765 if (has_array_args) {
44766- *kernel_ptr = user_ptr;
44767+ *kernel_ptr = (void __force_kernel *)user_ptr;
44768 if (copy_to_user(user_ptr, mbuf, array_size))
44769 err = -EFAULT;
44770 goto out_array_args;
44771diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44772index 570b18a..f880314 100644
44773--- a/drivers/message/fusion/mptbase.c
44774+++ b/drivers/message/fusion/mptbase.c
44775@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44776 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44777 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44778
44779+#ifdef CONFIG_GRKERNSEC_HIDESYM
44780+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44781+#else
44782 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44783 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44784+#endif
44785+
44786 /*
44787 * Rounding UP to nearest 4-kB boundary here...
44788 */
44789@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44790 ioc->facts.GlobalCredits);
44791
44792 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44793+#ifdef CONFIG_GRKERNSEC_HIDESYM
44794+ NULL, NULL);
44795+#else
44796 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44797+#endif
44798 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44799 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44800 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44801diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44802index 00d339c..2ea899d 100644
44803--- a/drivers/message/fusion/mptsas.c
44804+++ b/drivers/message/fusion/mptsas.c
44805@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44806 return 0;
44807 }
44808
44809+static inline void
44810+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44811+{
44812+ if (phy_info->port_details) {
44813+ phy_info->port_details->rphy = rphy;
44814+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44815+ ioc->name, rphy));
44816+ }
44817+
44818+ if (rphy) {
44819+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44820+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44821+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44822+ ioc->name, rphy, rphy->dev.release));
44823+ }
44824+}
44825+
44826 /* no mutex */
44827 static void
44828 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44829@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44830 return NULL;
44831 }
44832
44833-static inline void
44834-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44835-{
44836- if (phy_info->port_details) {
44837- phy_info->port_details->rphy = rphy;
44838- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44839- ioc->name, rphy));
44840- }
44841-
44842- if (rphy) {
44843- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44844- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44845- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44846- ioc->name, rphy, rphy->dev.release));
44847- }
44848-}
44849-
44850 static inline struct sas_port *
44851 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44852 {
44853diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44854index 727819c..ad74694 100644
44855--- a/drivers/message/fusion/mptscsih.c
44856+++ b/drivers/message/fusion/mptscsih.c
44857@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44858
44859 h = shost_priv(SChost);
44860
44861- if (h) {
44862- if (h->info_kbuf == NULL)
44863- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44864- return h->info_kbuf;
44865- h->info_kbuf[0] = '\0';
44866+ if (!h)
44867+ return NULL;
44868
44869- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44870- h->info_kbuf[size-1] = '\0';
44871- }
44872+ if (h->info_kbuf == NULL)
44873+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44874+ return h->info_kbuf;
44875+ h->info_kbuf[0] = '\0';
44876+
44877+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44878+ h->info_kbuf[size-1] = '\0';
44879
44880 return h->info_kbuf;
44881 }
44882diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44883index b7d87cd..3fb36da 100644
44884--- a/drivers/message/i2o/i2o_proc.c
44885+++ b/drivers/message/i2o/i2o_proc.c
44886@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44887 "Array Controller Device"
44888 };
44889
44890-static char *chtostr(char *tmp, u8 *chars, int n)
44891-{
44892- tmp[0] = 0;
44893- return strncat(tmp, (char *)chars, n);
44894-}
44895-
44896 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44897 char *group)
44898 {
44899@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44900 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44901 {
44902 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44903- static u32 work32[5];
44904- static u8 *work8 = (u8 *) work32;
44905- static u16 *work16 = (u16 *) work32;
44906+ u32 work32[5];
44907+ u8 *work8 = (u8 *) work32;
44908+ u16 *work16 = (u16 *) work32;
44909 int token;
44910 u32 hwcap;
44911
44912@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44913 } *result;
44914
44915 i2o_exec_execute_ddm_table ddm_table;
44916- char tmp[28 + 1];
44917
44918 result = kmalloc(sizeof(*result), GFP_KERNEL);
44919 if (!result)
44920@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44921
44922 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44923 seq_printf(seq, "%-#8x", ddm_table.module_id);
44924- seq_printf(seq, "%-29s",
44925- chtostr(tmp, ddm_table.module_name_version, 28));
44926+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44927 seq_printf(seq, "%9d ", ddm_table.data_size);
44928 seq_printf(seq, "%8d", ddm_table.code_size);
44929
44930@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44931
44932 i2o_driver_result_table *result;
44933 i2o_driver_store_table *dst;
44934- char tmp[28 + 1];
44935
44936 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44937 if (result == NULL)
44938@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44939
44940 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44941 seq_printf(seq, "%-#8x", dst->module_id);
44942- seq_printf(seq, "%-29s",
44943- chtostr(tmp, dst->module_name_version, 28));
44944- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44945+ seq_printf(seq, "%-.28s", dst->module_name_version);
44946+ seq_printf(seq, "%-.8s", dst->date);
44947 seq_printf(seq, "%8d ", dst->module_size);
44948 seq_printf(seq, "%8d ", dst->mpb_size);
44949 seq_printf(seq, "0x%04x", dst->module_flags);
44950@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44951 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44952 {
44953 struct i2o_device *d = (struct i2o_device *)seq->private;
44954- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44955+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44956 // == (allow) 512d bytes (max)
44957- static u16 *work16 = (u16 *) work32;
44958+ u16 *work16 = (u16 *) work32;
44959 int token;
44960- char tmp[16 + 1];
44961
44962 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44963
44964@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44965 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44966 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44967 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44968- seq_printf(seq, "Vendor info : %s\n",
44969- chtostr(tmp, (u8 *) (work32 + 2), 16));
44970- seq_printf(seq, "Product info : %s\n",
44971- chtostr(tmp, (u8 *) (work32 + 6), 16));
44972- seq_printf(seq, "Description : %s\n",
44973- chtostr(tmp, (u8 *) (work32 + 10), 16));
44974- seq_printf(seq, "Product rev. : %s\n",
44975- chtostr(tmp, (u8 *) (work32 + 14), 8));
44976+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44977+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44978+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44979+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44980
44981 seq_printf(seq, "Serial number : ");
44982 print_serial_number(seq, (u8 *) (work32 + 16),
44983@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44984 u8 pad[256]; // allow up to 256 byte (max) serial number
44985 } result;
44986
44987- char tmp[24 + 1];
44988-
44989 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44990
44991 if (token < 0) {
44992@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44993 }
44994
44995 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44996- seq_printf(seq, "Module name : %s\n",
44997- chtostr(tmp, result.module_name, 24));
44998- seq_printf(seq, "Module revision : %s\n",
44999- chtostr(tmp, result.module_rev, 8));
45000+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45001+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45002
45003 seq_printf(seq, "Serial number : ");
45004 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45005@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45006 u8 instance_number[4];
45007 } result;
45008
45009- char tmp[64 + 1];
45010-
45011 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45012
45013 if (token < 0) {
45014@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45015 return 0;
45016 }
45017
45018- seq_printf(seq, "Device name : %s\n",
45019- chtostr(tmp, result.device_name, 64));
45020- seq_printf(seq, "Service name : %s\n",
45021- chtostr(tmp, result.service_name, 64));
45022- seq_printf(seq, "Physical name : %s\n",
45023- chtostr(tmp, result.physical_location, 64));
45024- seq_printf(seq, "Instance number : %s\n",
45025- chtostr(tmp, result.instance_number, 4));
45026+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45027+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45028+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45029+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45030
45031 return 0;
45032 }
45033@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45034 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45035 {
45036 struct i2o_device *d = (struct i2o_device *)seq->private;
45037- static u32 work32[12];
45038- static u16 *work16 = (u16 *) work32;
45039- static u8 *work8 = (u8 *) work32;
45040+ u32 work32[12];
45041+ u16 *work16 = (u16 *) work32;
45042+ u8 *work8 = (u8 *) work32;
45043 int token;
45044
45045 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45046diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45047index a8c08f3..155fe3d 100644
45048--- a/drivers/message/i2o/iop.c
45049+++ b/drivers/message/i2o/iop.c
45050@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45051
45052 spin_lock_irqsave(&c->context_list_lock, flags);
45053
45054- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45055- atomic_inc(&c->context_list_counter);
45056+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45057+ atomic_inc_unchecked(&c->context_list_counter);
45058
45059- entry->context = atomic_read(&c->context_list_counter);
45060+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45061
45062 list_add(&entry->list, &c->context_list);
45063
45064@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45065
45066 #if BITS_PER_LONG == 64
45067 spin_lock_init(&c->context_list_lock);
45068- atomic_set(&c->context_list_counter, 0);
45069+ atomic_set_unchecked(&c->context_list_counter, 0);
45070 INIT_LIST_HEAD(&c->context_list);
45071 #endif
45072
45073diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45074index d1a22aa..d0f7bf7 100644
45075--- a/drivers/mfd/ab8500-debugfs.c
45076+++ b/drivers/mfd/ab8500-debugfs.c
45077@@ -100,7 +100,7 @@ static int irq_last;
45078 static u32 *irq_count;
45079 static int num_irqs;
45080
45081-static struct device_attribute **dev_attr;
45082+static device_attribute_no_const **dev_attr;
45083 static char **event_name;
45084
45085 static u8 avg_sample = SAMPLE_16;
45086diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45087index 81b7d88..95ae998 100644
45088--- a/drivers/mfd/janz-cmodio.c
45089+++ b/drivers/mfd/janz-cmodio.c
45090@@ -13,6 +13,7 @@
45091
45092 #include <linux/kernel.h>
45093 #include <linux/module.h>
45094+#include <linux/slab.h>
45095 #include <linux/init.h>
45096 #include <linux/pci.h>
45097 #include <linux/interrupt.h>
45098diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45099index a83eed5..62a58a9 100644
45100--- a/drivers/mfd/max8925-i2c.c
45101+++ b/drivers/mfd/max8925-i2c.c
45102@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45103 const struct i2c_device_id *id)
45104 {
45105 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45106- static struct max8925_chip *chip;
45107+ struct max8925_chip *chip;
45108 struct device_node *node = client->dev.of_node;
45109
45110 if (node && !pdata) {
45111diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45112index d657331..0d9a80f 100644
45113--- a/drivers/mfd/tps65910.c
45114+++ b/drivers/mfd/tps65910.c
45115@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45116 struct tps65910_platform_data *pdata)
45117 {
45118 int ret = 0;
45119- static struct regmap_irq_chip *tps6591x_irqs_chip;
45120+ struct regmap_irq_chip *tps6591x_irqs_chip;
45121
45122 if (!irq) {
45123 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45124diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45125index 9aa6d1e..1631bfc 100644
45126--- a/drivers/mfd/twl4030-irq.c
45127+++ b/drivers/mfd/twl4030-irq.c
45128@@ -35,6 +35,7 @@
45129 #include <linux/of.h>
45130 #include <linux/irqdomain.h>
45131 #include <linux/i2c/twl.h>
45132+#include <asm/pgtable.h>
45133
45134 #include "twl-core.h"
45135
45136@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45137 * Install an irq handler for each of the SIH modules;
45138 * clone dummy irq_chip since PIH can't *do* anything
45139 */
45140- twl4030_irq_chip = dummy_irq_chip;
45141- twl4030_irq_chip.name = "twl4030";
45142+ pax_open_kernel();
45143+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45144+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45145
45146- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45147+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45148+ pax_close_kernel();
45149
45150 for (i = irq_base; i < irq_end; i++) {
45151 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45152diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45153index 464419b..64bae8d 100644
45154--- a/drivers/misc/c2port/core.c
45155+++ b/drivers/misc/c2port/core.c
45156@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45157 goto error_idr_alloc;
45158 c2dev->id = ret;
45159
45160- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45161+ pax_open_kernel();
45162+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45163+ pax_close_kernel();
45164
45165 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45166 "c2port%d", c2dev->id);
45167diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45168index 9c34e57..b981cda 100644
45169--- a/drivers/misc/eeprom/sunxi_sid.c
45170+++ b/drivers/misc/eeprom/sunxi_sid.c
45171@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45172
45173 platform_set_drvdata(pdev, sid_data);
45174
45175- sid_bin_attr.size = sid_data->keysize;
45176+ pax_open_kernel();
45177+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45178+ pax_close_kernel();
45179 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45180 return -ENODEV;
45181
45182diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45183index 36f5d52..32311c3 100644
45184--- a/drivers/misc/kgdbts.c
45185+++ b/drivers/misc/kgdbts.c
45186@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45187 char before[BREAK_INSTR_SIZE];
45188 char after[BREAK_INSTR_SIZE];
45189
45190- probe_kernel_read(before, (char *)kgdbts_break_test,
45191+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45192 BREAK_INSTR_SIZE);
45193 init_simple_test();
45194 ts.tst = plant_and_detach_test;
45195@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45196 /* Activate test with initial breakpoint */
45197 if (!is_early)
45198 kgdb_breakpoint();
45199- probe_kernel_read(after, (char *)kgdbts_break_test,
45200+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45201 BREAK_INSTR_SIZE);
45202 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45203 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45204diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45205index 036effe..b3a6336 100644
45206--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45207+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45208@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45209 * the lid is closed. This leads to interrupts as soon as a little move
45210 * is done.
45211 */
45212- atomic_inc(&lis3->count);
45213+ atomic_inc_unchecked(&lis3->count);
45214
45215 wake_up_interruptible(&lis3->misc_wait);
45216 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45217@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45218 if (lis3->pm_dev)
45219 pm_runtime_get_sync(lis3->pm_dev);
45220
45221- atomic_set(&lis3->count, 0);
45222+ atomic_set_unchecked(&lis3->count, 0);
45223 return 0;
45224 }
45225
45226@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45227 add_wait_queue(&lis3->misc_wait, &wait);
45228 while (true) {
45229 set_current_state(TASK_INTERRUPTIBLE);
45230- data = atomic_xchg(&lis3->count, 0);
45231+ data = atomic_xchg_unchecked(&lis3->count, 0);
45232 if (data)
45233 break;
45234
45235@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45236 struct lis3lv02d, miscdev);
45237
45238 poll_wait(file, &lis3->misc_wait, wait);
45239- if (atomic_read(&lis3->count))
45240+ if (atomic_read_unchecked(&lis3->count))
45241 return POLLIN | POLLRDNORM;
45242 return 0;
45243 }
45244diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45245index c439c82..1f20f57 100644
45246--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45247+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45248@@ -297,7 +297,7 @@ struct lis3lv02d {
45249 struct input_polled_dev *idev; /* input device */
45250 struct platform_device *pdev; /* platform device */
45251 struct regulator_bulk_data regulators[2];
45252- atomic_t count; /* interrupt count after last read */
45253+ atomic_unchecked_t count; /* interrupt count after last read */
45254 union axis_conversion ac; /* hw -> logical axis */
45255 int mapped_btns[3];
45256
45257diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45258index 2f30bad..c4c13d0 100644
45259--- a/drivers/misc/sgi-gru/gruhandles.c
45260+++ b/drivers/misc/sgi-gru/gruhandles.c
45261@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45262 unsigned long nsec;
45263
45264 nsec = CLKS2NSEC(clks);
45265- atomic_long_inc(&mcs_op_statistics[op].count);
45266- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45267+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45268+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45269 if (mcs_op_statistics[op].max < nsec)
45270 mcs_op_statistics[op].max = nsec;
45271 }
45272diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45273index 4f76359..cdfcb2e 100644
45274--- a/drivers/misc/sgi-gru/gruprocfs.c
45275+++ b/drivers/misc/sgi-gru/gruprocfs.c
45276@@ -32,9 +32,9 @@
45277
45278 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45279
45280-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45281+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45282 {
45283- unsigned long val = atomic_long_read(v);
45284+ unsigned long val = atomic_long_read_unchecked(v);
45285
45286 seq_printf(s, "%16lu %s\n", val, id);
45287 }
45288@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45289
45290 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45291 for (op = 0; op < mcsop_last; op++) {
45292- count = atomic_long_read(&mcs_op_statistics[op].count);
45293- total = atomic_long_read(&mcs_op_statistics[op].total);
45294+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45295+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45296 max = mcs_op_statistics[op].max;
45297 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45298 count ? total / count : 0, max);
45299diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45300index 5c3ce24..4915ccb 100644
45301--- a/drivers/misc/sgi-gru/grutables.h
45302+++ b/drivers/misc/sgi-gru/grutables.h
45303@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45304 * GRU statistics.
45305 */
45306 struct gru_stats_s {
45307- atomic_long_t vdata_alloc;
45308- atomic_long_t vdata_free;
45309- atomic_long_t gts_alloc;
45310- atomic_long_t gts_free;
45311- atomic_long_t gms_alloc;
45312- atomic_long_t gms_free;
45313- atomic_long_t gts_double_allocate;
45314- atomic_long_t assign_context;
45315- atomic_long_t assign_context_failed;
45316- atomic_long_t free_context;
45317- atomic_long_t load_user_context;
45318- atomic_long_t load_kernel_context;
45319- atomic_long_t lock_kernel_context;
45320- atomic_long_t unlock_kernel_context;
45321- atomic_long_t steal_user_context;
45322- atomic_long_t steal_kernel_context;
45323- atomic_long_t steal_context_failed;
45324- atomic_long_t nopfn;
45325- atomic_long_t asid_new;
45326- atomic_long_t asid_next;
45327- atomic_long_t asid_wrap;
45328- atomic_long_t asid_reuse;
45329- atomic_long_t intr;
45330- atomic_long_t intr_cbr;
45331- atomic_long_t intr_tfh;
45332- atomic_long_t intr_spurious;
45333- atomic_long_t intr_mm_lock_failed;
45334- atomic_long_t call_os;
45335- atomic_long_t call_os_wait_queue;
45336- atomic_long_t user_flush_tlb;
45337- atomic_long_t user_unload_context;
45338- atomic_long_t user_exception;
45339- atomic_long_t set_context_option;
45340- atomic_long_t check_context_retarget_intr;
45341- atomic_long_t check_context_unload;
45342- atomic_long_t tlb_dropin;
45343- atomic_long_t tlb_preload_page;
45344- atomic_long_t tlb_dropin_fail_no_asid;
45345- atomic_long_t tlb_dropin_fail_upm;
45346- atomic_long_t tlb_dropin_fail_invalid;
45347- atomic_long_t tlb_dropin_fail_range_active;
45348- atomic_long_t tlb_dropin_fail_idle;
45349- atomic_long_t tlb_dropin_fail_fmm;
45350- atomic_long_t tlb_dropin_fail_no_exception;
45351- atomic_long_t tfh_stale_on_fault;
45352- atomic_long_t mmu_invalidate_range;
45353- atomic_long_t mmu_invalidate_page;
45354- atomic_long_t flush_tlb;
45355- atomic_long_t flush_tlb_gru;
45356- atomic_long_t flush_tlb_gru_tgh;
45357- atomic_long_t flush_tlb_gru_zero_asid;
45358+ atomic_long_unchecked_t vdata_alloc;
45359+ atomic_long_unchecked_t vdata_free;
45360+ atomic_long_unchecked_t gts_alloc;
45361+ atomic_long_unchecked_t gts_free;
45362+ atomic_long_unchecked_t gms_alloc;
45363+ atomic_long_unchecked_t gms_free;
45364+ atomic_long_unchecked_t gts_double_allocate;
45365+ atomic_long_unchecked_t assign_context;
45366+ atomic_long_unchecked_t assign_context_failed;
45367+ atomic_long_unchecked_t free_context;
45368+ atomic_long_unchecked_t load_user_context;
45369+ atomic_long_unchecked_t load_kernel_context;
45370+ atomic_long_unchecked_t lock_kernel_context;
45371+ atomic_long_unchecked_t unlock_kernel_context;
45372+ atomic_long_unchecked_t steal_user_context;
45373+ atomic_long_unchecked_t steal_kernel_context;
45374+ atomic_long_unchecked_t steal_context_failed;
45375+ atomic_long_unchecked_t nopfn;
45376+ atomic_long_unchecked_t asid_new;
45377+ atomic_long_unchecked_t asid_next;
45378+ atomic_long_unchecked_t asid_wrap;
45379+ atomic_long_unchecked_t asid_reuse;
45380+ atomic_long_unchecked_t intr;
45381+ atomic_long_unchecked_t intr_cbr;
45382+ atomic_long_unchecked_t intr_tfh;
45383+ atomic_long_unchecked_t intr_spurious;
45384+ atomic_long_unchecked_t intr_mm_lock_failed;
45385+ atomic_long_unchecked_t call_os;
45386+ atomic_long_unchecked_t call_os_wait_queue;
45387+ atomic_long_unchecked_t user_flush_tlb;
45388+ atomic_long_unchecked_t user_unload_context;
45389+ atomic_long_unchecked_t user_exception;
45390+ atomic_long_unchecked_t set_context_option;
45391+ atomic_long_unchecked_t check_context_retarget_intr;
45392+ atomic_long_unchecked_t check_context_unload;
45393+ atomic_long_unchecked_t tlb_dropin;
45394+ atomic_long_unchecked_t tlb_preload_page;
45395+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45396+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45397+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45398+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45399+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45400+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45401+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45402+ atomic_long_unchecked_t tfh_stale_on_fault;
45403+ atomic_long_unchecked_t mmu_invalidate_range;
45404+ atomic_long_unchecked_t mmu_invalidate_page;
45405+ atomic_long_unchecked_t flush_tlb;
45406+ atomic_long_unchecked_t flush_tlb_gru;
45407+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45408+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45409
45410- atomic_long_t copy_gpa;
45411- atomic_long_t read_gpa;
45412+ atomic_long_unchecked_t copy_gpa;
45413+ atomic_long_unchecked_t read_gpa;
45414
45415- atomic_long_t mesq_receive;
45416- atomic_long_t mesq_receive_none;
45417- atomic_long_t mesq_send;
45418- atomic_long_t mesq_send_failed;
45419- atomic_long_t mesq_noop;
45420- atomic_long_t mesq_send_unexpected_error;
45421- atomic_long_t mesq_send_lb_overflow;
45422- atomic_long_t mesq_send_qlimit_reached;
45423- atomic_long_t mesq_send_amo_nacked;
45424- atomic_long_t mesq_send_put_nacked;
45425- atomic_long_t mesq_page_overflow;
45426- atomic_long_t mesq_qf_locked;
45427- atomic_long_t mesq_qf_noop_not_full;
45428- atomic_long_t mesq_qf_switch_head_failed;
45429- atomic_long_t mesq_qf_unexpected_error;
45430- atomic_long_t mesq_noop_unexpected_error;
45431- atomic_long_t mesq_noop_lb_overflow;
45432- atomic_long_t mesq_noop_qlimit_reached;
45433- atomic_long_t mesq_noop_amo_nacked;
45434- atomic_long_t mesq_noop_put_nacked;
45435- atomic_long_t mesq_noop_page_overflow;
45436+ atomic_long_unchecked_t mesq_receive;
45437+ atomic_long_unchecked_t mesq_receive_none;
45438+ atomic_long_unchecked_t mesq_send;
45439+ atomic_long_unchecked_t mesq_send_failed;
45440+ atomic_long_unchecked_t mesq_noop;
45441+ atomic_long_unchecked_t mesq_send_unexpected_error;
45442+ atomic_long_unchecked_t mesq_send_lb_overflow;
45443+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45444+ atomic_long_unchecked_t mesq_send_amo_nacked;
45445+ atomic_long_unchecked_t mesq_send_put_nacked;
45446+ atomic_long_unchecked_t mesq_page_overflow;
45447+ atomic_long_unchecked_t mesq_qf_locked;
45448+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45449+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45450+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45451+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45452+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45453+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45454+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45455+ atomic_long_unchecked_t mesq_noop_put_nacked;
45456+ atomic_long_unchecked_t mesq_noop_page_overflow;
45457
45458 };
45459
45460@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45461 tghop_invalidate, mcsop_last};
45462
45463 struct mcs_op_statistic {
45464- atomic_long_t count;
45465- atomic_long_t total;
45466+ atomic_long_unchecked_t count;
45467+ atomic_long_unchecked_t total;
45468 unsigned long max;
45469 };
45470
45471@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45472
45473 #define STAT(id) do { \
45474 if (gru_options & OPT_STATS) \
45475- atomic_long_inc(&gru_stats.id); \
45476+ atomic_long_inc_unchecked(&gru_stats.id); \
45477 } while (0)
45478
45479 #ifdef CONFIG_SGI_GRU_DEBUG
45480diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45481index c862cd4..0d176fe 100644
45482--- a/drivers/misc/sgi-xp/xp.h
45483+++ b/drivers/misc/sgi-xp/xp.h
45484@@ -288,7 +288,7 @@ struct xpc_interface {
45485 xpc_notify_func, void *);
45486 void (*received) (short, int, void *);
45487 enum xp_retval (*partid_to_nasids) (short, void *);
45488-};
45489+} __no_const;
45490
45491 extern struct xpc_interface xpc_interface;
45492
45493diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45494index 01be66d..e3a0c7e 100644
45495--- a/drivers/misc/sgi-xp/xp_main.c
45496+++ b/drivers/misc/sgi-xp/xp_main.c
45497@@ -78,13 +78,13 @@ xpc_notloaded(void)
45498 }
45499
45500 struct xpc_interface xpc_interface = {
45501- (void (*)(int))xpc_notloaded,
45502- (void (*)(int))xpc_notloaded,
45503- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45504- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45505+ .connect = (void (*)(int))xpc_notloaded,
45506+ .disconnect = (void (*)(int))xpc_notloaded,
45507+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45508+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45509 void *))xpc_notloaded,
45510- (void (*)(short, int, void *))xpc_notloaded,
45511- (enum xp_retval(*)(short, void *))xpc_notloaded
45512+ .received = (void (*)(short, int, void *))xpc_notloaded,
45513+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45514 };
45515 EXPORT_SYMBOL_GPL(xpc_interface);
45516
45517diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45518index b94d5f7..7f494c5 100644
45519--- a/drivers/misc/sgi-xp/xpc.h
45520+++ b/drivers/misc/sgi-xp/xpc.h
45521@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45522 void (*received_payload) (struct xpc_channel *, void *);
45523 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45524 };
45525+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45526
45527 /* struct xpc_partition act_state values (for XPC HB) */
45528
45529@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45530 /* found in xpc_main.c */
45531 extern struct device *xpc_part;
45532 extern struct device *xpc_chan;
45533-extern struct xpc_arch_operations xpc_arch_ops;
45534+extern xpc_arch_operations_no_const xpc_arch_ops;
45535 extern int xpc_disengage_timelimit;
45536 extern int xpc_disengage_timedout;
45537 extern int xpc_activate_IRQ_rcvd;
45538diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45539index 82dc574..8539ab2 100644
45540--- a/drivers/misc/sgi-xp/xpc_main.c
45541+++ b/drivers/misc/sgi-xp/xpc_main.c
45542@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45543 .notifier_call = xpc_system_die,
45544 };
45545
45546-struct xpc_arch_operations xpc_arch_ops;
45547+xpc_arch_operations_no_const xpc_arch_ops;
45548
45549 /*
45550 * Timer function to enforce the timelimit on the partition disengage.
45551@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45552
45553 if (((die_args->trapnr == X86_TRAP_MF) ||
45554 (die_args->trapnr == X86_TRAP_XF)) &&
45555- !user_mode_vm(die_args->regs))
45556+ !user_mode(die_args->regs))
45557 xpc_die_deactivate();
45558
45559 break;
45560diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45561index 7b5424f..ed1d6ac 100644
45562--- a/drivers/mmc/card/block.c
45563+++ b/drivers/mmc/card/block.c
45564@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45565 if (idata->ic.postsleep_min_us)
45566 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45567
45568- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45569+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45570 err = -EFAULT;
45571 goto cmd_rel_host;
45572 }
45573diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45574index e5b5eeb..7bf2212 100644
45575--- a/drivers/mmc/core/mmc_ops.c
45576+++ b/drivers/mmc/core/mmc_ops.c
45577@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45578 void *data_buf;
45579 int is_on_stack;
45580
45581- is_on_stack = object_is_on_stack(buf);
45582+ is_on_stack = object_starts_on_stack(buf);
45583 if (is_on_stack) {
45584 /*
45585 * dma onto stack is unsafe/nonportable, but callers to this
45586diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45587index 6bf24ab..13d0293b 100644
45588--- a/drivers/mmc/host/dw_mmc.h
45589+++ b/drivers/mmc/host/dw_mmc.h
45590@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45591 int (*parse_dt)(struct dw_mci *host);
45592 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45593 struct dw_mci_tuning_data *tuning_data);
45594-};
45595+} __do_const;
45596 #endif /* _DW_MMC_H_ */
45597diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45598index b931226..df6a085 100644
45599--- a/drivers/mmc/host/mmci.c
45600+++ b/drivers/mmc/host/mmci.c
45601@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45602 }
45603
45604 if (variant->busy_detect) {
45605- mmci_ops.card_busy = mmci_card_busy;
45606+ pax_open_kernel();
45607+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45608+ pax_close_kernel();
45609 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45610 }
45611
45612diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45613index b841bb7..d82712f5 100644
45614--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45615+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45616@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45617 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45618 }
45619
45620- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45621- sdhci_esdhc_ops.platform_execute_tuning =
45622+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45623+ pax_open_kernel();
45624+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45625 esdhc_executing_tuning;
45626+ pax_close_kernel();
45627+ }
45628
45629 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45630 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45631diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45632index 6debda9..2ba7427 100644
45633--- a/drivers/mmc/host/sdhci-s3c.c
45634+++ b/drivers/mmc/host/sdhci-s3c.c
45635@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45636 * we can use overriding functions instead of default.
45637 */
45638 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45639- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45640- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45641- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45642+ pax_open_kernel();
45643+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45644+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45645+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45646+ pax_close_kernel();
45647 }
45648
45649 /* It supports additional host capabilities if needed */
45650diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45651index 096993f..f02c23b 100644
45652--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45653+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45654@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45655 size_t totlen = 0, thislen;
45656 int ret = 0;
45657 size_t buflen = 0;
45658- static char *buffer;
45659+ char *buffer;
45660
45661 if (!ECCBUF_SIZE) {
45662 /* We should fall back to a general writev implementation.
45663diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45664index c07cd57..61c4fbd 100644
45665--- a/drivers/mtd/nand/denali.c
45666+++ b/drivers/mtd/nand/denali.c
45667@@ -24,6 +24,7 @@
45668 #include <linux/slab.h>
45669 #include <linux/mtd/mtd.h>
45670 #include <linux/module.h>
45671+#include <linux/slab.h>
45672
45673 #include "denali.h"
45674
45675diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45676index ca6369f..0ce9fed 100644
45677--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45678+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45679@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45680
45681 /* first try to map the upper buffer directly */
45682 if (virt_addr_valid(this->upper_buf) &&
45683- !object_is_on_stack(this->upper_buf)) {
45684+ !object_starts_on_stack(this->upper_buf)) {
45685 sg_init_one(sgl, this->upper_buf, this->upper_len);
45686 ret = dma_map_sg(this->dev, sgl, 1, dr);
45687 if (ret == 0)
45688diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45689index 51b9d6a..52af9a7 100644
45690--- a/drivers/mtd/nftlmount.c
45691+++ b/drivers/mtd/nftlmount.c
45692@@ -24,6 +24,7 @@
45693 #include <asm/errno.h>
45694 #include <linux/delay.h>
45695 #include <linux/slab.h>
45696+#include <linux/sched.h>
45697 #include <linux/mtd/mtd.h>
45698 #include <linux/mtd/nand.h>
45699 #include <linux/mtd/nftl.h>
45700diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45701index 4b8e895..6b3c498 100644
45702--- a/drivers/mtd/sm_ftl.c
45703+++ b/drivers/mtd/sm_ftl.c
45704@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45705 #define SM_CIS_VENDOR_OFFSET 0x59
45706 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45707 {
45708- struct attribute_group *attr_group;
45709+ attribute_group_no_const *attr_group;
45710 struct attribute **attributes;
45711 struct sm_sysfs_attribute *vendor_attribute;
45712
45713diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45714index e5628fc..ffe54d1 100644
45715--- a/drivers/net/bonding/bond_main.c
45716+++ b/drivers/net/bonding/bond_main.c
45717@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45718
45719 bond_netlink_fini();
45720 unregister_pernet_subsys(&bond_net_ops);
45721+ rtnl_link_unregister(&bond_link_ops);
45722
45723 #ifdef CONFIG_NET_POLL_CONTROLLER
45724 /*
45725diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45726index 70651f8..7eb1bdf 100644
45727--- a/drivers/net/bonding/bond_netlink.c
45728+++ b/drivers/net/bonding/bond_netlink.c
45729@@ -542,7 +542,7 @@ nla_put_failure:
45730 return -EMSGSIZE;
45731 }
45732
45733-struct rtnl_link_ops bond_link_ops __read_mostly = {
45734+struct rtnl_link_ops bond_link_ops = {
45735 .kind = "bond",
45736 .priv_size = sizeof(struct bonding),
45737 .setup = bond_setup,
45738diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45739index 9e7d95d..d447b88 100644
45740--- a/drivers/net/can/Kconfig
45741+++ b/drivers/net/can/Kconfig
45742@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45743
45744 config CAN_FLEXCAN
45745 tristate "Support for Freescale FLEXCAN based chips"
45746- depends on ARM || PPC
45747+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45748 ---help---
45749 Say Y here if you want to support for Freescale FlexCAN.
45750
45751diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45752index 455d4c3..3353ee7 100644
45753--- a/drivers/net/ethernet/8390/ax88796.c
45754+++ b/drivers/net/ethernet/8390/ax88796.c
45755@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45756 if (ax->plat->reg_offsets)
45757 ei_local->reg_offset = ax->plat->reg_offsets;
45758 else {
45759+ resource_size_t _mem_size = mem_size;
45760+ do_div(_mem_size, 0x18);
45761 ei_local->reg_offset = ax->reg_offsets;
45762 for (ret = 0; ret < 0x18; ret++)
45763- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45764+ ax->reg_offsets[ret] = _mem_size * ret;
45765 }
45766
45767 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45768diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45769index a89a40f..5a8a2ac 100644
45770--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45771+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45772@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45773 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45774 {
45775 /* RX_MODE controlling object */
45776- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45777+ bnx2x_init_rx_mode_obj(bp);
45778
45779 /* multicast configuration controlling object */
45780 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45781diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45782index 0fb6ff2..78fd55c 100644
45783--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45784+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45785@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45786 return rc;
45787 }
45788
45789-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45790- struct bnx2x_rx_mode_obj *o)
45791+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45792 {
45793 if (CHIP_IS_E1x(bp)) {
45794- o->wait_comp = bnx2x_empty_rx_mode_wait;
45795- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45796+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45797+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45798 } else {
45799- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45800- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45801+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45802+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45803 }
45804 }
45805
45806diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45807index 00d7f21..2cddec4 100644
45808--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45809+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45810@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45811
45812 /********************* RX MODE ****************/
45813
45814-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45815- struct bnx2x_rx_mode_obj *o);
45816+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45817
45818 /**
45819 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45820diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45821index 04321e5..b51cdc4 100644
45822--- a/drivers/net/ethernet/broadcom/tg3.h
45823+++ b/drivers/net/ethernet/broadcom/tg3.h
45824@@ -150,6 +150,7 @@
45825 #define CHIPREV_ID_5750_A0 0x4000
45826 #define CHIPREV_ID_5750_A1 0x4001
45827 #define CHIPREV_ID_5750_A3 0x4003
45828+#define CHIPREV_ID_5750_C1 0x4201
45829 #define CHIPREV_ID_5750_C2 0x4202
45830 #define CHIPREV_ID_5752_A0_HW 0x5000
45831 #define CHIPREV_ID_5752_A0 0x6000
45832diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45833index 13f9636..228040f 100644
45834--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45835+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45836@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45837 }
45838
45839 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45840- bna_cb_ioceth_enable,
45841- bna_cb_ioceth_disable,
45842- bna_cb_ioceth_hbfail,
45843- bna_cb_ioceth_reset
45844+ .enable_cbfn = bna_cb_ioceth_enable,
45845+ .disable_cbfn = bna_cb_ioceth_disable,
45846+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45847+ .reset_cbfn = bna_cb_ioceth_reset
45848 };
45849
45850 static void bna_attr_init(struct bna_ioceth *ioceth)
45851diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45852index 8cffcdf..aadf043 100644
45853--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45854+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45855@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45856 */
45857 struct l2t_skb_cb {
45858 arp_failure_handler_func arp_failure_handler;
45859-};
45860+} __no_const;
45861
45862 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45863
45864diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45865index 34e2488..07e2079 100644
45866--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45867+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45868@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45869
45870 int i;
45871 struct adapter *ap = netdev2adap(dev);
45872- static const unsigned int *reg_ranges;
45873+ const unsigned int *reg_ranges;
45874 int arr_size = 0, buf_size = 0;
45875
45876 if (is_t4(ap->params.chip)) {
45877diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45878index c05b66d..ed69872 100644
45879--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45880+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45881@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45882 for (i=0; i<ETH_ALEN; i++) {
45883 tmp.addr[i] = dev->dev_addr[i];
45884 }
45885- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45886+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45887 break;
45888
45889 case DE4X5_SET_HWADDR: /* Set the hardware address */
45890@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45891 spin_lock_irqsave(&lp->lock, flags);
45892 memcpy(&statbuf, &lp->pktStats, ioc->len);
45893 spin_unlock_irqrestore(&lp->lock, flags);
45894- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45895+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45896 return -EFAULT;
45897 break;
45898 }
45899diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45900index 36c8061..ca5e1e0 100644
45901--- a/drivers/net/ethernet/emulex/benet/be_main.c
45902+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45903@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45904
45905 if (wrapped)
45906 newacc += 65536;
45907- ACCESS_ONCE(*acc) = newacc;
45908+ ACCESS_ONCE_RW(*acc) = newacc;
45909 }
45910
45911 static void populate_erx_stats(struct be_adapter *adapter,
45912diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45913index c11ecbc..13bb299 100644
45914--- a/drivers/net/ethernet/faraday/ftgmac100.c
45915+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45916@@ -30,6 +30,8 @@
45917 #include <linux/netdevice.h>
45918 #include <linux/phy.h>
45919 #include <linux/platform_device.h>
45920+#include <linux/interrupt.h>
45921+#include <linux/irqreturn.h>
45922 #include <net/ip.h>
45923
45924 #include "ftgmac100.h"
45925diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45926index 8be5b40..081bc1b 100644
45927--- a/drivers/net/ethernet/faraday/ftmac100.c
45928+++ b/drivers/net/ethernet/faraday/ftmac100.c
45929@@ -31,6 +31,8 @@
45930 #include <linux/module.h>
45931 #include <linux/netdevice.h>
45932 #include <linux/platform_device.h>
45933+#include <linux/interrupt.h>
45934+#include <linux/irqreturn.h>
45935
45936 #include "ftmac100.h"
45937
45938diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45939index e33ec6c..f54cfe7 100644
45940--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45941+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45942@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45943 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45944
45945 /* Update the base adjustement value. */
45946- ACCESS_ONCE(pf->ptp_base_adj) = incval;
45947+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45948 smp_mb(); /* Force the above update. */
45949 }
45950
45951diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45952index 5184e2a..acb28c3 100644
45953--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45954+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45955@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45956 }
45957
45958 /* update the base incval used to calculate frequency adjustment */
45959- ACCESS_ONCE(adapter->base_incval) = incval;
45960+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45961 smp_mb();
45962
45963 /* need lock to prevent incorrect read while modifying cyclecounter */
45964diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45965index 089b713..28d87ae 100644
45966--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45967+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45968@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45969 struct __vxge_hw_fifo *fifo;
45970 struct vxge_hw_fifo_config *config;
45971 u32 txdl_size, txdl_per_memblock;
45972- struct vxge_hw_mempool_cbs fifo_mp_callback;
45973+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45974+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45975+ };
45976+
45977 struct __vxge_hw_virtualpath *vpath;
45978
45979 if ((vp == NULL) || (attr == NULL)) {
45980@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45981 goto exit;
45982 }
45983
45984- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45985-
45986 fifo->mempool =
45987 __vxge_hw_mempool_create(vpath->hldev,
45988 fifo->config->memblock_size,
45989diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45990index 90a2dda..47e620e 100644
45991--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45992+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45993@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45994 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45995 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45996 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45997- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45998+ pax_open_kernel();
45999+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46000+ pax_close_kernel();
46001 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46002 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46003 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46004diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46005index be7d7a6..a8983f8 100644
46006--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46007+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46008@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46009 case QLCNIC_NON_PRIV_FUNC:
46010 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46011 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46012- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46013+ pax_open_kernel();
46014+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46015+ pax_close_kernel();
46016 break;
46017 case QLCNIC_PRIV_FUNC:
46018 ahw->op_mode = QLCNIC_PRIV_FUNC;
46019 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46020- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46021+ pax_open_kernel();
46022+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46023+ pax_close_kernel();
46024 break;
46025 case QLCNIC_MGMT_FUNC:
46026 ahw->op_mode = QLCNIC_MGMT_FUNC;
46027 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46028- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46029+ pax_open_kernel();
46030+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46031+ pax_close_kernel();
46032 break;
46033 default:
46034 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46035diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46036index 7763962..c3499a7 100644
46037--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46038+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46039@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46040 struct qlcnic_dump_entry *entry;
46041 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46042 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46043- static const struct qlcnic_dump_operations *fw_dump_ops;
46044+ const struct qlcnic_dump_operations *fw_dump_ops;
46045 struct device *dev = &adapter->pdev->dev;
46046 struct qlcnic_hardware_context *ahw;
46047 void *temp_buffer;
46048diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46049index 3ff7bc3..366091b 100644
46050--- a/drivers/net/ethernet/realtek/r8169.c
46051+++ b/drivers/net/ethernet/realtek/r8169.c
46052@@ -758,22 +758,22 @@ struct rtl8169_private {
46053 struct mdio_ops {
46054 void (*write)(struct rtl8169_private *, int, int);
46055 int (*read)(struct rtl8169_private *, int);
46056- } mdio_ops;
46057+ } __no_const mdio_ops;
46058
46059 struct pll_power_ops {
46060 void (*down)(struct rtl8169_private *);
46061 void (*up)(struct rtl8169_private *);
46062- } pll_power_ops;
46063+ } __no_const pll_power_ops;
46064
46065 struct jumbo_ops {
46066 void (*enable)(struct rtl8169_private *);
46067 void (*disable)(struct rtl8169_private *);
46068- } jumbo_ops;
46069+ } __no_const jumbo_ops;
46070
46071 struct csi_ops {
46072 void (*write)(struct rtl8169_private *, int, int);
46073 u32 (*read)(struct rtl8169_private *, int);
46074- } csi_ops;
46075+ } __no_const csi_ops;
46076
46077 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46078 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46079diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46080index d7a3682..9ce272a 100644
46081--- a/drivers/net/ethernet/sfc/ptp.c
46082+++ b/drivers/net/ethernet/sfc/ptp.c
46083@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46084 ptp->start.dma_addr);
46085
46086 /* Clear flag that signals MC ready */
46087- ACCESS_ONCE(*start) = 0;
46088+ ACCESS_ONCE_RW(*start) = 0;
46089 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46090 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46091 EFX_BUG_ON_PARANOID(rc);
46092diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46093index 50617c5..b13724c 100644
46094--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46095+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46096@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46097
46098 writel(value, ioaddr + MMC_CNTRL);
46099
46100- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46101- MMC_CNTRL, value);
46102+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46103+// MMC_CNTRL, value);
46104 }
46105
46106 /* To mask all all interrupts.*/
46107diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46108index 7b594ce..1f6c5708 100644
46109--- a/drivers/net/hyperv/hyperv_net.h
46110+++ b/drivers/net/hyperv/hyperv_net.h
46111@@ -100,7 +100,7 @@ struct rndis_device {
46112
46113 enum rndis_device_state state;
46114 bool link_state;
46115- atomic_t new_req_id;
46116+ atomic_unchecked_t new_req_id;
46117
46118 spinlock_t request_lock;
46119 struct list_head req_list;
46120diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46121index b54fd25..9bd2bae 100644
46122--- a/drivers/net/hyperv/rndis_filter.c
46123+++ b/drivers/net/hyperv/rndis_filter.c
46124@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46125 * template
46126 */
46127 set = &rndis_msg->msg.set_req;
46128- set->req_id = atomic_inc_return(&dev->new_req_id);
46129+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46130
46131 /* Add to the request list */
46132 spin_lock_irqsave(&dev->request_lock, flags);
46133@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46134
46135 /* Setup the rndis set */
46136 halt = &request->request_msg.msg.halt_req;
46137- halt->req_id = atomic_inc_return(&dev->new_req_id);
46138+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46139
46140 /* Ignore return since this msg is optional. */
46141 rndis_filter_send_request(dev, request);
46142diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46143index bf0d55e..82bcfbd1 100644
46144--- a/drivers/net/ieee802154/fakehard.c
46145+++ b/drivers/net/ieee802154/fakehard.c
46146@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46147 phy->transmit_power = 0xbf;
46148
46149 dev->netdev_ops = &fake_ops;
46150- dev->ml_priv = &fake_mlme;
46151+ dev->ml_priv = (void *)&fake_mlme;
46152
46153 priv = netdev_priv(dev);
46154 priv->phy = phy;
46155diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46156index 1831fb7..9c24bca 100644
46157--- a/drivers/net/macvlan.c
46158+++ b/drivers/net/macvlan.c
46159@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46160 int macvlan_link_register(struct rtnl_link_ops *ops)
46161 {
46162 /* common fields */
46163- ops->priv_size = sizeof(struct macvlan_dev);
46164- ops->validate = macvlan_validate;
46165- ops->maxtype = IFLA_MACVLAN_MAX;
46166- ops->policy = macvlan_policy;
46167- ops->changelink = macvlan_changelink;
46168- ops->get_size = macvlan_get_size;
46169- ops->fill_info = macvlan_fill_info;
46170+ pax_open_kernel();
46171+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46172+ *(void **)&ops->validate = macvlan_validate;
46173+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46174+ *(const void **)&ops->policy = macvlan_policy;
46175+ *(void **)&ops->changelink = macvlan_changelink;
46176+ *(void **)&ops->get_size = macvlan_get_size;
46177+ *(void **)&ops->fill_info = macvlan_fill_info;
46178+ pax_close_kernel();
46179
46180 return rtnl_link_register(ops);
46181 };
46182@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46183 return NOTIFY_DONE;
46184 }
46185
46186-static struct notifier_block macvlan_notifier_block __read_mostly = {
46187+static struct notifier_block macvlan_notifier_block = {
46188 .notifier_call = macvlan_device_event,
46189 };
46190
46191diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46192index ff111a8..c4c3ac4 100644
46193--- a/drivers/net/macvtap.c
46194+++ b/drivers/net/macvtap.c
46195@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46196 }
46197
46198 ret = 0;
46199- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46200+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46201 put_user(q->flags, &ifr->ifr_flags))
46202 ret = -EFAULT;
46203 macvtap_put_vlan(vlan);
46204@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46205 return NOTIFY_DONE;
46206 }
46207
46208-static struct notifier_block macvtap_notifier_block __read_mostly = {
46209+static struct notifier_block macvtap_notifier_block = {
46210 .notifier_call = macvtap_device_event,
46211 };
46212
46213diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46214index daec9b0..6428fcb 100644
46215--- a/drivers/net/phy/mdio-bitbang.c
46216+++ b/drivers/net/phy/mdio-bitbang.c
46217@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46218 struct mdiobb_ctrl *ctrl = bus->priv;
46219
46220 module_put(ctrl->ops->owner);
46221+ mdiobus_unregister(bus);
46222 mdiobus_free(bus);
46223 }
46224 EXPORT_SYMBOL(free_mdio_bitbang);
46225diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46226index 72ff14b..11d442d 100644
46227--- a/drivers/net/ppp/ppp_generic.c
46228+++ b/drivers/net/ppp/ppp_generic.c
46229@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46230 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46231 struct ppp_stats stats;
46232 struct ppp_comp_stats cstats;
46233- char *vers;
46234
46235 switch (cmd) {
46236 case SIOCGPPPSTATS:
46237@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46238 break;
46239
46240 case SIOCGPPPVER:
46241- vers = PPP_VERSION;
46242- if (copy_to_user(addr, vers, strlen(vers) + 1))
46243+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46244 break;
46245 err = 0;
46246 break;
46247diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46248index 1252d9c..80e660b 100644
46249--- a/drivers/net/slip/slhc.c
46250+++ b/drivers/net/slip/slhc.c
46251@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46252 register struct tcphdr *thp;
46253 register struct iphdr *ip;
46254 register struct cstate *cs;
46255- int len, hdrlen;
46256+ long len, hdrlen;
46257 unsigned char *cp = icp;
46258
46259 /* We've got a compressed packet; read the change byte */
46260diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46261index c8624a8..f0a4f6a 100644
46262--- a/drivers/net/team/team.c
46263+++ b/drivers/net/team/team.c
46264@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46265 return NOTIFY_DONE;
46266 }
46267
46268-static struct notifier_block team_notifier_block __read_mostly = {
46269+static struct notifier_block team_notifier_block = {
46270 .notifier_call = team_device_event,
46271 };
46272
46273diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46274index 26f8635..c237839 100644
46275--- a/drivers/net/tun.c
46276+++ b/drivers/net/tun.c
46277@@ -1876,7 +1876,7 @@ unlock:
46278 }
46279
46280 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46281- unsigned long arg, int ifreq_len)
46282+ unsigned long arg, size_t ifreq_len)
46283 {
46284 struct tun_file *tfile = file->private_data;
46285 struct tun_struct *tun;
46286@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46287 unsigned int ifindex;
46288 int ret;
46289
46290+ if (ifreq_len > sizeof ifr)
46291+ return -EFAULT;
46292+
46293 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46294 if (copy_from_user(&ifr, argp, ifreq_len))
46295 return -EFAULT;
46296diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46297index d350d27..75d7d9d 100644
46298--- a/drivers/net/usb/cdc_ncm.c
46299+++ b/drivers/net/usb/cdc_ncm.c
46300@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46301 skb_out->len > CDC_NCM_MIN_TX_PKT)
46302 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46303 ctx->tx_max - skb_out->len);
46304- else if ((skb_out->len % dev->maxpacket) == 0)
46305+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46306 *skb_put(skb_out, 1) = 0; /* force short packet */
46307
46308 /* set final frame length */
46309diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46310index 660bd5e..ac59452 100644
46311--- a/drivers/net/usb/hso.c
46312+++ b/drivers/net/usb/hso.c
46313@@ -71,7 +71,7 @@
46314 #include <asm/byteorder.h>
46315 #include <linux/serial_core.h>
46316 #include <linux/serial.h>
46317-
46318+#include <asm/local.h>
46319
46320 #define MOD_AUTHOR "Option Wireless"
46321 #define MOD_DESCRIPTION "USB High Speed Option driver"
46322@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46323 struct urb *urb;
46324
46325 urb = serial->rx_urb[0];
46326- if (serial->port.count > 0) {
46327+ if (atomic_read(&serial->port.count) > 0) {
46328 count = put_rxbuf_data(urb, serial);
46329 if (count == -1)
46330 return;
46331@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46332 DUMP1(urb->transfer_buffer, urb->actual_length);
46333
46334 /* Anyone listening? */
46335- if (serial->port.count == 0)
46336+ if (atomic_read(&serial->port.count) == 0)
46337 return;
46338
46339 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46340@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46341 tty_port_tty_set(&serial->port, tty);
46342
46343 /* check for port already opened, if not set the termios */
46344- serial->port.count++;
46345- if (serial->port.count == 1) {
46346+ if (atomic_inc_return(&serial->port.count) == 1) {
46347 serial->rx_state = RX_IDLE;
46348 /* Force default termio settings */
46349 _hso_serial_set_termios(tty, NULL);
46350@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46351 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46352 if (result) {
46353 hso_stop_serial_device(serial->parent);
46354- serial->port.count--;
46355+ atomic_dec(&serial->port.count);
46356 kref_put(&serial->parent->ref, hso_serial_ref_free);
46357 }
46358 } else {
46359@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46360
46361 /* reset the rts and dtr */
46362 /* do the actual close */
46363- serial->port.count--;
46364+ atomic_dec(&serial->port.count);
46365
46366- if (serial->port.count <= 0) {
46367- serial->port.count = 0;
46368+ if (atomic_read(&serial->port.count) <= 0) {
46369+ atomic_set(&serial->port.count, 0);
46370 tty_port_tty_set(&serial->port, NULL);
46371 if (!usb_gone)
46372 hso_stop_serial_device(serial->parent);
46373@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46374
46375 /* the actual setup */
46376 spin_lock_irqsave(&serial->serial_lock, flags);
46377- if (serial->port.count)
46378+ if (atomic_read(&serial->port.count))
46379 _hso_serial_set_termios(tty, old);
46380 else
46381 tty->termios = *old;
46382@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46383 D1("Pending read interrupt on port %d\n", i);
46384 spin_lock(&serial->serial_lock);
46385 if (serial->rx_state == RX_IDLE &&
46386- serial->port.count > 0) {
46387+ atomic_read(&serial->port.count) > 0) {
46388 /* Setup and send a ctrl req read on
46389 * port i */
46390 if (!serial->rx_urb_filled[0]) {
46391@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46392 /* Start all serial ports */
46393 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46394 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46395- if (dev2ser(serial_table[i])->port.count) {
46396+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46397 result =
46398 hso_start_serial_device(serial_table[i], GFP_NOIO);
46399 hso_kick_transmit(dev2ser(serial_table[i]));
46400diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46401index adb12f3..48005ab 100644
46402--- a/drivers/net/usb/r8152.c
46403+++ b/drivers/net/usb/r8152.c
46404@@ -513,7 +513,7 @@ struct r8152 {
46405 void (*disable)(struct r8152 *);
46406 void (*down)(struct r8152 *);
46407 void (*unload)(struct r8152 *);
46408- } rtl_ops;
46409+ } __no_const rtl_ops;
46410
46411 int intr_interval;
46412 u32 msg_enable;
46413diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46414index a2515887..6d13233 100644
46415--- a/drivers/net/usb/sierra_net.c
46416+++ b/drivers/net/usb/sierra_net.c
46417@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46418 /* atomic counter partially included in MAC address to make sure 2 devices
46419 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46420 */
46421-static atomic_t iface_counter = ATOMIC_INIT(0);
46422+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46423
46424 /*
46425 * SYNC Timer Delay definition used to set the expiry time
46426@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46427 dev->net->netdev_ops = &sierra_net_device_ops;
46428
46429 /* change MAC addr to include, ifacenum, and to be unique */
46430- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46431+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46432 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46433
46434 /* we will have to manufacture ethernet headers, prepare template */
46435diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46436index d091e52..568bb179 100644
46437--- a/drivers/net/vxlan.c
46438+++ b/drivers/net/vxlan.c
46439@@ -2847,7 +2847,7 @@ nla_put_failure:
46440 return -EMSGSIZE;
46441 }
46442
46443-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46444+static struct rtnl_link_ops vxlan_link_ops = {
46445 .kind = "vxlan",
46446 .maxtype = IFLA_VXLAN_MAX,
46447 .policy = vxlan_policy,
46448@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46449 return NOTIFY_DONE;
46450 }
46451
46452-static struct notifier_block vxlan_notifier_block __read_mostly = {
46453+static struct notifier_block vxlan_notifier_block = {
46454 .notifier_call = vxlan_lowerdev_event,
46455 };
46456
46457diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46458index 5920c99..ff2e4a5 100644
46459--- a/drivers/net/wan/lmc/lmc_media.c
46460+++ b/drivers/net/wan/lmc/lmc_media.c
46461@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46462 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46463
46464 lmc_media_t lmc_ds3_media = {
46465- lmc_ds3_init, /* special media init stuff */
46466- lmc_ds3_default, /* reset to default state */
46467- lmc_ds3_set_status, /* reset status to state provided */
46468- lmc_dummy_set_1, /* set clock source */
46469- lmc_dummy_set2_1, /* set line speed */
46470- lmc_ds3_set_100ft, /* set cable length */
46471- lmc_ds3_set_scram, /* set scrambler */
46472- lmc_ds3_get_link_status, /* get link status */
46473- lmc_dummy_set_1, /* set link status */
46474- lmc_ds3_set_crc_length, /* set CRC length */
46475- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46476- lmc_ds3_watchdog
46477+ .init = lmc_ds3_init, /* special media init stuff */
46478+ .defaults = lmc_ds3_default, /* reset to default state */
46479+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46480+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46481+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46482+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46483+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46484+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46485+ .set_link_status = lmc_dummy_set_1, /* set link status */
46486+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46487+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46488+ .watchdog = lmc_ds3_watchdog
46489 };
46490
46491 lmc_media_t lmc_hssi_media = {
46492- lmc_hssi_init, /* special media init stuff */
46493- lmc_hssi_default, /* reset to default state */
46494- lmc_hssi_set_status, /* reset status to state provided */
46495- lmc_hssi_set_clock, /* set clock source */
46496- lmc_dummy_set2_1, /* set line speed */
46497- lmc_dummy_set_1, /* set cable length */
46498- lmc_dummy_set_1, /* set scrambler */
46499- lmc_hssi_get_link_status, /* get link status */
46500- lmc_hssi_set_link_status, /* set link status */
46501- lmc_hssi_set_crc_length, /* set CRC length */
46502- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46503- lmc_hssi_watchdog
46504+ .init = lmc_hssi_init, /* special media init stuff */
46505+ .defaults = lmc_hssi_default, /* reset to default state */
46506+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46507+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46508+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46509+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46510+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46511+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46512+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46513+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46514+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46515+ .watchdog = lmc_hssi_watchdog
46516 };
46517
46518-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46519- lmc_ssi_default, /* reset to default state */
46520- lmc_ssi_set_status, /* reset status to state provided */
46521- lmc_ssi_set_clock, /* set clock source */
46522- lmc_ssi_set_speed, /* set line speed */
46523- lmc_dummy_set_1, /* set cable length */
46524- lmc_dummy_set_1, /* set scrambler */
46525- lmc_ssi_get_link_status, /* get link status */
46526- lmc_ssi_set_link_status, /* set link status */
46527- lmc_ssi_set_crc_length, /* set CRC length */
46528- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46529- lmc_ssi_watchdog
46530+lmc_media_t lmc_ssi_media = {
46531+ .init = lmc_ssi_init, /* special media init stuff */
46532+ .defaults = lmc_ssi_default, /* reset to default state */
46533+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46534+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46535+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46536+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46537+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46538+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46539+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46540+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46541+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46542+ .watchdog = lmc_ssi_watchdog
46543 };
46544
46545 lmc_media_t lmc_t1_media = {
46546- lmc_t1_init, /* special media init stuff */
46547- lmc_t1_default, /* reset to default state */
46548- lmc_t1_set_status, /* reset status to state provided */
46549- lmc_t1_set_clock, /* set clock source */
46550- lmc_dummy_set2_1, /* set line speed */
46551- lmc_dummy_set_1, /* set cable length */
46552- lmc_dummy_set_1, /* set scrambler */
46553- lmc_t1_get_link_status, /* get link status */
46554- lmc_dummy_set_1, /* set link status */
46555- lmc_t1_set_crc_length, /* set CRC length */
46556- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46557- lmc_t1_watchdog
46558+ .init = lmc_t1_init, /* special media init stuff */
46559+ .defaults = lmc_t1_default, /* reset to default state */
46560+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46561+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46562+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46563+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46564+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46565+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46566+ .set_link_status = lmc_dummy_set_1, /* set link status */
46567+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46568+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46569+ .watchdog = lmc_t1_watchdog
46570 };
46571
46572 static void
46573diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46574index feacc3b..5bac0de 100644
46575--- a/drivers/net/wan/z85230.c
46576+++ b/drivers/net/wan/z85230.c
46577@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46578
46579 struct z8530_irqhandler z8530_sync =
46580 {
46581- z8530_rx,
46582- z8530_tx,
46583- z8530_status
46584+ .rx = z8530_rx,
46585+ .tx = z8530_tx,
46586+ .status = z8530_status
46587 };
46588
46589 EXPORT_SYMBOL(z8530_sync);
46590@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46591 }
46592
46593 static struct z8530_irqhandler z8530_dma_sync = {
46594- z8530_dma_rx,
46595- z8530_dma_tx,
46596- z8530_dma_status
46597+ .rx = z8530_dma_rx,
46598+ .tx = z8530_dma_tx,
46599+ .status = z8530_dma_status
46600 };
46601
46602 static struct z8530_irqhandler z8530_txdma_sync = {
46603- z8530_rx,
46604- z8530_dma_tx,
46605- z8530_dma_status
46606+ .rx = z8530_rx,
46607+ .tx = z8530_dma_tx,
46608+ .status = z8530_dma_status
46609 };
46610
46611 /**
46612@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46613
46614 struct z8530_irqhandler z8530_nop=
46615 {
46616- z8530_rx_clear,
46617- z8530_tx_clear,
46618- z8530_status_clear
46619+ .rx = z8530_rx_clear,
46620+ .tx = z8530_tx_clear,
46621+ .status = z8530_status_clear
46622 };
46623
46624
46625diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46626index 0b60295..b8bfa5b 100644
46627--- a/drivers/net/wimax/i2400m/rx.c
46628+++ b/drivers/net/wimax/i2400m/rx.c
46629@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46630 if (i2400m->rx_roq == NULL)
46631 goto error_roq_alloc;
46632
46633- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46634+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46635 GFP_KERNEL);
46636 if (rd == NULL) {
46637 result = -ENOMEM;
46638diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46639index edf4b57..68b51c0 100644
46640--- a/drivers/net/wireless/airo.c
46641+++ b/drivers/net/wireless/airo.c
46642@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46643 struct airo_info *ai = dev->ml_priv;
46644 int ridcode;
46645 int enabled;
46646- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46647+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46648 unsigned char *iobuf;
46649
46650 /* Only super-user can write RIDs */
46651diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46652index 99b3bfa..9559372 100644
46653--- a/drivers/net/wireless/at76c50x-usb.c
46654+++ b/drivers/net/wireless/at76c50x-usb.c
46655@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46656 }
46657
46658 /* Convert timeout from the DFU status to jiffies */
46659-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46660+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46661 {
46662 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46663 | (s->poll_timeout[1] << 8)
46664diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46665index edc57ab..ff49e0a 100644
46666--- a/drivers/net/wireless/ath/ath10k/htc.c
46667+++ b/drivers/net/wireless/ath/ath10k/htc.c
46668@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46669 /* registered target arrival callback from the HIF layer */
46670 int ath10k_htc_init(struct ath10k *ar)
46671 {
46672- struct ath10k_hif_cb htc_callbacks;
46673+ static struct ath10k_hif_cb htc_callbacks = {
46674+ .rx_completion = ath10k_htc_rx_completion_handler,
46675+ .tx_completion = ath10k_htc_tx_completion_handler,
46676+ };
46677 struct ath10k_htc_ep *ep = NULL;
46678 struct ath10k_htc *htc = &ar->htc;
46679
46680@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46681 ath10k_htc_reset_endpoint_states(htc);
46682
46683 /* setup HIF layer callbacks */
46684- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46685- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46686 htc->ar = ar;
46687
46688 /* Get HIF default pipe for HTC message exchange */
46689diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46690index 4716d33..a688310 100644
46691--- a/drivers/net/wireless/ath/ath10k/htc.h
46692+++ b/drivers/net/wireless/ath/ath10k/htc.h
46693@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46694
46695 struct ath10k_htc_ops {
46696 void (*target_send_suspend_complete)(struct ath10k *ar);
46697-};
46698+} __no_const;
46699
46700 struct ath10k_htc_ep_ops {
46701 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46702 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46703 void (*ep_tx_credits)(struct ath10k *);
46704-};
46705+} __no_const;
46706
46707 /* service connection information */
46708 struct ath10k_htc_svc_conn_req {
46709diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46710index 741b38d..b7ae41b 100644
46711--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46712+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46713@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46714 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46715 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46716
46717- ACCESS_ONCE(ads->ds_link) = i->link;
46718- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46719+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46720+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46721
46722 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46723 ctl6 = SM(i->keytype, AR_EncrType);
46724@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46725
46726 if ((i->is_first || i->is_last) &&
46727 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46728- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46729+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46730 | set11nTries(i->rates, 1)
46731 | set11nTries(i->rates, 2)
46732 | set11nTries(i->rates, 3)
46733 | (i->dur_update ? AR_DurUpdateEna : 0)
46734 | SM(0, AR_BurstDur);
46735
46736- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46737+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46738 | set11nRate(i->rates, 1)
46739 | set11nRate(i->rates, 2)
46740 | set11nRate(i->rates, 3);
46741 } else {
46742- ACCESS_ONCE(ads->ds_ctl2) = 0;
46743- ACCESS_ONCE(ads->ds_ctl3) = 0;
46744+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46745+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46746 }
46747
46748 if (!i->is_first) {
46749- ACCESS_ONCE(ads->ds_ctl0) = 0;
46750- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46751- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46752+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46753+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46754+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46755 return;
46756 }
46757
46758@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46759 break;
46760 }
46761
46762- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46763+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46764 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46765 | SM(i->txpower, AR_XmitPower)
46766 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46767@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46768 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46769 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46770
46771- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46772- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46773+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46774+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46775
46776 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46777 return;
46778
46779- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46780+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46781 | set11nPktDurRTSCTS(i->rates, 1);
46782
46783- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46784+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46785 | set11nPktDurRTSCTS(i->rates, 3);
46786
46787- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46788+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46789 | set11nRateFlags(i->rates, 1)
46790 | set11nRateFlags(i->rates, 2)
46791 | set11nRateFlags(i->rates, 3)
46792diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46793index 729ffbf..49f50e3 100644
46794--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46795+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46796@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46797 (i->qcu << AR_TxQcuNum_S) | desc_len;
46798
46799 checksum += val;
46800- ACCESS_ONCE(ads->info) = val;
46801+ ACCESS_ONCE_RW(ads->info) = val;
46802
46803 checksum += i->link;
46804- ACCESS_ONCE(ads->link) = i->link;
46805+ ACCESS_ONCE_RW(ads->link) = i->link;
46806
46807 checksum += i->buf_addr[0];
46808- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46809+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46810 checksum += i->buf_addr[1];
46811- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46812+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46813 checksum += i->buf_addr[2];
46814- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46815+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46816 checksum += i->buf_addr[3];
46817- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46818+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46819
46820 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46821- ACCESS_ONCE(ads->ctl3) = val;
46822+ ACCESS_ONCE_RW(ads->ctl3) = val;
46823 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46824- ACCESS_ONCE(ads->ctl5) = val;
46825+ ACCESS_ONCE_RW(ads->ctl5) = val;
46826 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46827- ACCESS_ONCE(ads->ctl7) = val;
46828+ ACCESS_ONCE_RW(ads->ctl7) = val;
46829 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46830- ACCESS_ONCE(ads->ctl9) = val;
46831+ ACCESS_ONCE_RW(ads->ctl9) = val;
46832
46833 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46834- ACCESS_ONCE(ads->ctl10) = checksum;
46835+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46836
46837 if (i->is_first || i->is_last) {
46838- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46839+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46840 | set11nTries(i->rates, 1)
46841 | set11nTries(i->rates, 2)
46842 | set11nTries(i->rates, 3)
46843 | (i->dur_update ? AR_DurUpdateEna : 0)
46844 | SM(0, AR_BurstDur);
46845
46846- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46847+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46848 | set11nRate(i->rates, 1)
46849 | set11nRate(i->rates, 2)
46850 | set11nRate(i->rates, 3);
46851 } else {
46852- ACCESS_ONCE(ads->ctl13) = 0;
46853- ACCESS_ONCE(ads->ctl14) = 0;
46854+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46855+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46856 }
46857
46858 ads->ctl20 = 0;
46859@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46860
46861 ctl17 = SM(i->keytype, AR_EncrType);
46862 if (!i->is_first) {
46863- ACCESS_ONCE(ads->ctl11) = 0;
46864- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46865- ACCESS_ONCE(ads->ctl15) = 0;
46866- ACCESS_ONCE(ads->ctl16) = 0;
46867- ACCESS_ONCE(ads->ctl17) = ctl17;
46868- ACCESS_ONCE(ads->ctl18) = 0;
46869- ACCESS_ONCE(ads->ctl19) = 0;
46870+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46871+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46872+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46873+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46874+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46875+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46876+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46877 return;
46878 }
46879
46880- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46881+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46882 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46883 | SM(i->txpower, AR_XmitPower)
46884 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46885@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46886 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46887 ctl12 |= SM(val, AR_PAPRDChainMask);
46888
46889- ACCESS_ONCE(ads->ctl12) = ctl12;
46890- ACCESS_ONCE(ads->ctl17) = ctl17;
46891+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46892+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46893
46894- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46895+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46896 | set11nPktDurRTSCTS(i->rates, 1);
46897
46898- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46899+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46900 | set11nPktDurRTSCTS(i->rates, 3);
46901
46902- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46903+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46904 | set11nRateFlags(i->rates, 1)
46905 | set11nRateFlags(i->rates, 2)
46906 | set11nRateFlags(i->rates, 3)
46907 | SM(i->rtscts_rate, AR_RTSCTSRate);
46908
46909- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46910+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46911 }
46912
46913 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46914diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46915index 0acd4b5..0591c91 100644
46916--- a/drivers/net/wireless/ath/ath9k/hw.h
46917+++ b/drivers/net/wireless/ath/ath9k/hw.h
46918@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46919
46920 /* ANI */
46921 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46922-};
46923+} __no_const;
46924
46925 /**
46926 * struct ath_spec_scan - parameters for Atheros spectral scan
46927@@ -706,7 +706,7 @@ struct ath_hw_ops {
46928 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46929 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46930 #endif
46931-};
46932+} __no_const;
46933
46934 struct ath_nf_limits {
46935 s16 max;
46936diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46937index 92190da..f3a4c4c 100644
46938--- a/drivers/net/wireless/b43/phy_lp.c
46939+++ b/drivers/net/wireless/b43/phy_lp.c
46940@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46941 {
46942 struct ssb_bus *bus = dev->dev->sdev->bus;
46943
46944- static const struct b206x_channel *chandata = NULL;
46945+ const struct b206x_channel *chandata = NULL;
46946 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46947 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46948 u16 old_comm15, scale;
46949diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46950index 0487461..fd9e84a 100644
46951--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46952+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46953@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46954 */
46955 if (il3945_mod_params.disable_hw_scan) {
46956 D_INFO("Disabling hw_scan\n");
46957- il3945_mac_ops.hw_scan = NULL;
46958+ pax_open_kernel();
46959+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46960+ pax_close_kernel();
46961 }
46962
46963 D_INFO("*** LOAD DRIVER ***\n");
46964diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46965index d2fe259..0c4c682 100644
46966--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46967+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46968@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46969 {
46970 struct iwl_priv *priv = file->private_data;
46971 char buf[64];
46972- int buf_size;
46973+ size_t buf_size;
46974 u32 offset, len;
46975
46976 memset(buf, 0, sizeof(buf));
46977@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46978 struct iwl_priv *priv = file->private_data;
46979
46980 char buf[8];
46981- int buf_size;
46982+ size_t buf_size;
46983 u32 reset_flag;
46984
46985 memset(buf, 0, sizeof(buf));
46986@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46987 {
46988 struct iwl_priv *priv = file->private_data;
46989 char buf[8];
46990- int buf_size;
46991+ size_t buf_size;
46992 int ht40;
46993
46994 memset(buf, 0, sizeof(buf));
46995@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46996 {
46997 struct iwl_priv *priv = file->private_data;
46998 char buf[8];
46999- int buf_size;
47000+ size_t buf_size;
47001 int value;
47002
47003 memset(buf, 0, sizeof(buf));
47004@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47005 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47006 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47007
47008-static const char *fmt_value = " %-30s %10u\n";
47009-static const char *fmt_hex = " %-30s 0x%02X\n";
47010-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47011-static const char *fmt_header =
47012+static const char fmt_value[] = " %-30s %10u\n";
47013+static const char fmt_hex[] = " %-30s 0x%02X\n";
47014+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47015+static const char fmt_header[] =
47016 "%-32s current cumulative delta max\n";
47017
47018 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47019@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47020 {
47021 struct iwl_priv *priv = file->private_data;
47022 char buf[8];
47023- int buf_size;
47024+ size_t buf_size;
47025 int clear;
47026
47027 memset(buf, 0, sizeof(buf));
47028@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47029 {
47030 struct iwl_priv *priv = file->private_data;
47031 char buf[8];
47032- int buf_size;
47033+ size_t buf_size;
47034 int trace;
47035
47036 memset(buf, 0, sizeof(buf));
47037@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47038 {
47039 struct iwl_priv *priv = file->private_data;
47040 char buf[8];
47041- int buf_size;
47042+ size_t buf_size;
47043 int missed;
47044
47045 memset(buf, 0, sizeof(buf));
47046@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47047
47048 struct iwl_priv *priv = file->private_data;
47049 char buf[8];
47050- int buf_size;
47051+ size_t buf_size;
47052 int plcp;
47053
47054 memset(buf, 0, sizeof(buf));
47055@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47056
47057 struct iwl_priv *priv = file->private_data;
47058 char buf[8];
47059- int buf_size;
47060+ size_t buf_size;
47061 int flush;
47062
47063 memset(buf, 0, sizeof(buf));
47064@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47065
47066 struct iwl_priv *priv = file->private_data;
47067 char buf[8];
47068- int buf_size;
47069+ size_t buf_size;
47070 int rts;
47071
47072 if (!priv->cfg->ht_params)
47073@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47074 {
47075 struct iwl_priv *priv = file->private_data;
47076 char buf[8];
47077- int buf_size;
47078+ size_t buf_size;
47079
47080 memset(buf, 0, sizeof(buf));
47081 buf_size = min(count, sizeof(buf) - 1);
47082@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47083 struct iwl_priv *priv = file->private_data;
47084 u32 event_log_flag;
47085 char buf[8];
47086- int buf_size;
47087+ size_t buf_size;
47088
47089 /* check that the interface is up */
47090 if (!iwl_is_ready(priv))
47091@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47092 struct iwl_priv *priv = file->private_data;
47093 char buf[8];
47094 u32 calib_disabled;
47095- int buf_size;
47096+ size_t buf_size;
47097
47098 memset(buf, 0, sizeof(buf));
47099 buf_size = min(count, sizeof(buf) - 1);
47100diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47101index ba1b1ea..0ff7e98 100644
47102--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47103+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47104@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47105 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47106 {
47107 struct iwl_nvm_data *data = priv->nvm_data;
47108- char *debug_msg;
47109+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47110
47111 if (data->sku_cap_11n_enable &&
47112 !priv->cfg->ht_params) {
47113@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47114 return -EINVAL;
47115 }
47116
47117- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47118 IWL_DEBUG_INFO(priv, debug_msg,
47119 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47120 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47121diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47122index f950780..be9df93 100644
47123--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47124+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47125@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47126 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47127
47128 char buf[8];
47129- int buf_size;
47130+ size_t buf_size;
47131 u32 reset_flag;
47132
47133 memset(buf, 0, sizeof(buf));
47134@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47135 {
47136 struct iwl_trans *trans = file->private_data;
47137 char buf[8];
47138- int buf_size;
47139+ size_t buf_size;
47140 int csr;
47141
47142 memset(buf, 0, sizeof(buf));
47143diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47144index 69d4c31..bd0b316 100644
47145--- a/drivers/net/wireless/mac80211_hwsim.c
47146+++ b/drivers/net/wireless/mac80211_hwsim.c
47147@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47148 if (channels < 1)
47149 return -EINVAL;
47150
47151- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47152- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47153- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47154- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47155- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47156- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47157- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47158- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47159- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47160- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47161- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47162- mac80211_hwsim_assign_vif_chanctx;
47163- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47164- mac80211_hwsim_unassign_vif_chanctx;
47165+ pax_open_kernel();
47166+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47167+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47168+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47169+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47170+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47171+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47172+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47173+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47174+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47175+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47176+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47177+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47178+ pax_close_kernel();
47179
47180 spin_lock_init(&hwsim_radio_lock);
47181 INIT_LIST_HEAD(&hwsim_radios);
47182diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47183index 5028557..91cf394 100644
47184--- a/drivers/net/wireless/rndis_wlan.c
47185+++ b/drivers/net/wireless/rndis_wlan.c
47186@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47187
47188 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47189
47190- if (rts_threshold < 0 || rts_threshold > 2347)
47191+ if (rts_threshold > 2347)
47192 rts_threshold = 2347;
47193
47194 tmp = cpu_to_le32(rts_threshold);
47195diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47196index e3b885d..7a7de2f 100644
47197--- a/drivers/net/wireless/rt2x00/rt2x00.h
47198+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47199@@ -375,7 +375,7 @@ struct rt2x00_intf {
47200 * for hardware which doesn't support hardware
47201 * sequence counting.
47202 */
47203- atomic_t seqno;
47204+ atomic_unchecked_t seqno;
47205 };
47206
47207 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47208diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47209index 5642ccc..01f03eb 100644
47210--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47211+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47212@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47213 * sequence counter given by mac80211.
47214 */
47215 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47216- seqno = atomic_add_return(0x10, &intf->seqno);
47217+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47218 else
47219- seqno = atomic_read(&intf->seqno);
47220+ seqno = atomic_read_unchecked(&intf->seqno);
47221
47222 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47223 hdr->seq_ctrl |= cpu_to_le16(seqno);
47224diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47225index e2b3d9c..67a5184 100644
47226--- a/drivers/net/wireless/ti/wl1251/sdio.c
47227+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47228@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47229
47230 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47231
47232- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47233- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47234+ pax_open_kernel();
47235+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47236+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47237+ pax_close_kernel();
47238
47239 wl1251_info("using dedicated interrupt line");
47240 } else {
47241- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47242- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47243+ pax_open_kernel();
47244+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47245+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47246+ pax_close_kernel();
47247
47248 wl1251_info("using SDIO interrupt");
47249 }
47250diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47251index be7129b..4161356 100644
47252--- a/drivers/net/wireless/ti/wl12xx/main.c
47253+++ b/drivers/net/wireless/ti/wl12xx/main.c
47254@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47255 sizeof(wl->conf.mem));
47256
47257 /* read data preparation is only needed by wl127x */
47258- wl->ops->prepare_read = wl127x_prepare_read;
47259+ pax_open_kernel();
47260+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47261+ pax_close_kernel();
47262
47263 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47264 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47265@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47266 sizeof(wl->conf.mem));
47267
47268 /* read data preparation is only needed by wl127x */
47269- wl->ops->prepare_read = wl127x_prepare_read;
47270+ pax_open_kernel();
47271+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47272+ pax_close_kernel();
47273
47274 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47275 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47276diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47277index ec37b16..7e34d66 100644
47278--- a/drivers/net/wireless/ti/wl18xx/main.c
47279+++ b/drivers/net/wireless/ti/wl18xx/main.c
47280@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47281 }
47282
47283 if (!checksum_param) {
47284- wl18xx_ops.set_rx_csum = NULL;
47285- wl18xx_ops.init_vif = NULL;
47286+ pax_open_kernel();
47287+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47288+ *(void **)&wl18xx_ops.init_vif = NULL;
47289+ pax_close_kernel();
47290 }
47291
47292 /* Enable 11a Band only if we have 5G antennas */
47293diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47294index a912dc0..a8225ba 100644
47295--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47296+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47297@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47298 {
47299 struct zd_usb *usb = urb->context;
47300 struct zd_usb_interrupt *intr = &usb->intr;
47301- int len;
47302+ unsigned int len;
47303 u16 int_num;
47304
47305 ZD_ASSERT(in_interrupt());
47306diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47307index 683671a..4519fc2 100644
47308--- a/drivers/nfc/nfcwilink.c
47309+++ b/drivers/nfc/nfcwilink.c
47310@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47311
47312 static int nfcwilink_probe(struct platform_device *pdev)
47313 {
47314- static struct nfcwilink *drv;
47315+ struct nfcwilink *drv;
47316 int rc;
47317 __u32 protocols;
47318
47319diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47320index d93b2b6..ae50401 100644
47321--- a/drivers/oprofile/buffer_sync.c
47322+++ b/drivers/oprofile/buffer_sync.c
47323@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47324 if (cookie == NO_COOKIE)
47325 offset = pc;
47326 if (cookie == INVALID_COOKIE) {
47327- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47328+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47329 offset = pc;
47330 }
47331 if (cookie != last_cookie) {
47332@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47333 /* add userspace sample */
47334
47335 if (!mm) {
47336- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47337+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47338 return 0;
47339 }
47340
47341 cookie = lookup_dcookie(mm, s->eip, &offset);
47342
47343 if (cookie == INVALID_COOKIE) {
47344- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47345+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47346 return 0;
47347 }
47348
47349@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47350 /* ignore backtraces if failed to add a sample */
47351 if (state == sb_bt_start) {
47352 state = sb_bt_ignore;
47353- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47354+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47355 }
47356 }
47357 release_mm(mm);
47358diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47359index c0cc4e7..44d4e54 100644
47360--- a/drivers/oprofile/event_buffer.c
47361+++ b/drivers/oprofile/event_buffer.c
47362@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47363 }
47364
47365 if (buffer_pos == buffer_size) {
47366- atomic_inc(&oprofile_stats.event_lost_overflow);
47367+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47368 return;
47369 }
47370
47371diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47372index ed2c3ec..deda85a 100644
47373--- a/drivers/oprofile/oprof.c
47374+++ b/drivers/oprofile/oprof.c
47375@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47376 if (oprofile_ops.switch_events())
47377 return;
47378
47379- atomic_inc(&oprofile_stats.multiplex_counter);
47380+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47381 start_switch_worker();
47382 }
47383
47384diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47385index ee2cfce..7f8f699 100644
47386--- a/drivers/oprofile/oprofile_files.c
47387+++ b/drivers/oprofile/oprofile_files.c
47388@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47389
47390 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47391
47392-static ssize_t timeout_read(struct file *file, char __user *buf,
47393+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47394 size_t count, loff_t *offset)
47395 {
47396 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47397diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47398index 59659ce..6c860a0 100644
47399--- a/drivers/oprofile/oprofile_stats.c
47400+++ b/drivers/oprofile/oprofile_stats.c
47401@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47402 cpu_buf->sample_invalid_eip = 0;
47403 }
47404
47405- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47406- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47407- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47408- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47409- atomic_set(&oprofile_stats.multiplex_counter, 0);
47410+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47411+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47412+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47413+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47414+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47415 }
47416
47417
47418diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47419index 1fc622b..8c48fc3 100644
47420--- a/drivers/oprofile/oprofile_stats.h
47421+++ b/drivers/oprofile/oprofile_stats.h
47422@@ -13,11 +13,11 @@
47423 #include <linux/atomic.h>
47424
47425 struct oprofile_stat_struct {
47426- atomic_t sample_lost_no_mm;
47427- atomic_t sample_lost_no_mapping;
47428- atomic_t bt_lost_no_mapping;
47429- atomic_t event_lost_overflow;
47430- atomic_t multiplex_counter;
47431+ atomic_unchecked_t sample_lost_no_mm;
47432+ atomic_unchecked_t sample_lost_no_mapping;
47433+ atomic_unchecked_t bt_lost_no_mapping;
47434+ atomic_unchecked_t event_lost_overflow;
47435+ atomic_unchecked_t multiplex_counter;
47436 };
47437
47438 extern struct oprofile_stat_struct oprofile_stats;
47439diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47440index 3f49345..c750d0b 100644
47441--- a/drivers/oprofile/oprofilefs.c
47442+++ b/drivers/oprofile/oprofilefs.c
47443@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47444
47445 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47446 {
47447- atomic_t *val = file->private_data;
47448- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47449+ atomic_unchecked_t *val = file->private_data;
47450+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47451 }
47452
47453
47454@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47455
47456
47457 int oprofilefs_create_ro_atomic(struct dentry *root,
47458- char const *name, atomic_t *val)
47459+ char const *name, atomic_unchecked_t *val)
47460 {
47461 return __oprofilefs_create_file(root, name,
47462 &atomic_ro_fops, 0444, val);
47463diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47464index 61be1d9..dec05d7 100644
47465--- a/drivers/oprofile/timer_int.c
47466+++ b/drivers/oprofile/timer_int.c
47467@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47468 return NOTIFY_OK;
47469 }
47470
47471-static struct notifier_block __refdata oprofile_cpu_notifier = {
47472+static struct notifier_block oprofile_cpu_notifier = {
47473 .notifier_call = oprofile_cpu_notify,
47474 };
47475
47476diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47477index 92ed045..62d39bd7 100644
47478--- a/drivers/parport/procfs.c
47479+++ b/drivers/parport/procfs.c
47480@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47481
47482 *ppos += len;
47483
47484- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47485+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47486 }
47487
47488 #ifdef CONFIG_PARPORT_1284
47489@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47490
47491 *ppos += len;
47492
47493- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47494+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47495 }
47496 #endif /* IEEE1284.3 support. */
47497
47498diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47499index 8dcccff..35d701d 100644
47500--- a/drivers/pci/hotplug/acpiphp_ibm.c
47501+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47502@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47503 goto init_cleanup;
47504 }
47505
47506- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47507+ pax_open_kernel();
47508+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47509+ pax_close_kernel();
47510 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47511
47512 return retval;
47513diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47514index 7536eef..52dc8fa 100644
47515--- a/drivers/pci/hotplug/cpcihp_generic.c
47516+++ b/drivers/pci/hotplug/cpcihp_generic.c
47517@@ -73,7 +73,6 @@ static u16 port;
47518 static unsigned int enum_bit;
47519 static u8 enum_mask;
47520
47521-static struct cpci_hp_controller_ops generic_hpc_ops;
47522 static struct cpci_hp_controller generic_hpc;
47523
47524 static int __init validate_parameters(void)
47525@@ -139,6 +138,10 @@ static int query_enum(void)
47526 return ((value & enum_mask) == enum_mask);
47527 }
47528
47529+static struct cpci_hp_controller_ops generic_hpc_ops = {
47530+ .query_enum = query_enum,
47531+};
47532+
47533 static int __init cpcihp_generic_init(void)
47534 {
47535 int status;
47536@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47537 pci_dev_put(dev);
47538
47539 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47540- generic_hpc_ops.query_enum = query_enum;
47541 generic_hpc.ops = &generic_hpc_ops;
47542
47543 status = cpci_hp_register_controller(&generic_hpc);
47544diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47545index e8c4a7c..7046f5c 100644
47546--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47547+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47548@@ -59,7 +59,6 @@
47549 /* local variables */
47550 static bool debug;
47551 static bool poll;
47552-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47553 static struct cpci_hp_controller zt5550_hpc;
47554
47555 /* Primary cPCI bus bridge device */
47556@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47557 return 0;
47558 }
47559
47560+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47561+ .query_enum = zt5550_hc_query_enum,
47562+};
47563+
47564 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47565 {
47566 int status;
47567@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47568 dbg("returned from zt5550_hc_config");
47569
47570 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47571- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47572 zt5550_hpc.ops = &zt5550_hpc_ops;
47573 if(!poll) {
47574 zt5550_hpc.irq = hc_dev->irq;
47575 zt5550_hpc.irq_flags = IRQF_SHARED;
47576 zt5550_hpc.dev_id = hc_dev;
47577
47578- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47579- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47580- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47581+ pax_open_kernel();
47582+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47583+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47584+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47585+ pax_open_kernel();
47586 } else {
47587 info("using ENUM# polling mode");
47588 }
47589diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47590index 76ba8a1..20ca857 100644
47591--- a/drivers/pci/hotplug/cpqphp_nvram.c
47592+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47593@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47594
47595 void compaq_nvram_init (void __iomem *rom_start)
47596 {
47597+
47598+#ifndef CONFIG_PAX_KERNEXEC
47599 if (rom_start) {
47600 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47601 }
47602+#endif
47603+
47604 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47605
47606 /* initialize our int15 lock */
47607diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47608index cfa92a9..29539c5 100644
47609--- a/drivers/pci/hotplug/pci_hotplug_core.c
47610+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47611@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47612 return -EINVAL;
47613 }
47614
47615- slot->ops->owner = owner;
47616- slot->ops->mod_name = mod_name;
47617+ pax_open_kernel();
47618+ *(struct module **)&slot->ops->owner = owner;
47619+ *(const char **)&slot->ops->mod_name = mod_name;
47620+ pax_close_kernel();
47621
47622 mutex_lock(&pci_hp_mutex);
47623 /*
47624diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47625index 53b58de..4479896 100644
47626--- a/drivers/pci/hotplug/pciehp_core.c
47627+++ b/drivers/pci/hotplug/pciehp_core.c
47628@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47629 struct slot *slot = ctrl->slot;
47630 struct hotplug_slot *hotplug = NULL;
47631 struct hotplug_slot_info *info = NULL;
47632- struct hotplug_slot_ops *ops = NULL;
47633+ hotplug_slot_ops_no_const *ops = NULL;
47634 char name[SLOT_NAME_SIZE];
47635 int retval = -ENOMEM;
47636
47637diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47638index 955ab79..d1df9c7 100644
47639--- a/drivers/pci/msi.c
47640+++ b/drivers/pci/msi.c
47641@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47642 {
47643 struct attribute **msi_attrs;
47644 struct attribute *msi_attr;
47645- struct device_attribute *msi_dev_attr;
47646- struct attribute_group *msi_irq_group;
47647+ device_attribute_no_const *msi_dev_attr;
47648+ attribute_group_no_const *msi_irq_group;
47649 const struct attribute_group **msi_irq_groups;
47650 struct msi_desc *entry;
47651 int ret = -ENOMEM;
47652@@ -589,7 +589,7 @@ error_attrs:
47653 count = 0;
47654 msi_attr = msi_attrs[count];
47655 while (msi_attr) {
47656- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47657+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47658 kfree(msi_attr->name);
47659 kfree(msi_dev_attr);
47660 ++count;
47661diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47662index 276ef9c..1d33a36 100644
47663--- a/drivers/pci/pci-sysfs.c
47664+++ b/drivers/pci/pci-sysfs.c
47665@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47666 {
47667 /* allocate attribute structure, piggyback attribute name */
47668 int name_len = write_combine ? 13 : 10;
47669- struct bin_attribute *res_attr;
47670+ bin_attribute_no_const *res_attr;
47671 int retval;
47672
47673 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47674@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47675 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47676 {
47677 int retval;
47678- struct bin_attribute *attr;
47679+ bin_attribute_no_const *attr;
47680
47681 /* If the device has VPD, try to expose it in sysfs. */
47682 if (dev->vpd) {
47683@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47684 {
47685 int retval;
47686 int rom_size = 0;
47687- struct bin_attribute *attr;
47688+ bin_attribute_no_const *attr;
47689
47690 if (!sysfs_initialized)
47691 return -EACCES;
47692diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47693index 4df38df..b6bb7fe 100644
47694--- a/drivers/pci/pci.h
47695+++ b/drivers/pci/pci.h
47696@@ -93,7 +93,7 @@ struct pci_vpd_ops {
47697 struct pci_vpd {
47698 unsigned int len;
47699 const struct pci_vpd_ops *ops;
47700- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47701+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47702 };
47703
47704 int pci_vpd_pci22_init(struct pci_dev *dev);
47705diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47706index e1e7026..d28dd33 100644
47707--- a/drivers/pci/pcie/aspm.c
47708+++ b/drivers/pci/pcie/aspm.c
47709@@ -27,9 +27,9 @@
47710 #define MODULE_PARAM_PREFIX "pcie_aspm."
47711
47712 /* Note: those are not register definitions */
47713-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47714-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47715-#define ASPM_STATE_L1 (4) /* L1 state */
47716+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47717+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47718+#define ASPM_STATE_L1 (4U) /* L1 state */
47719 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47720 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47721
47722diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47723index 6e34498..9911975 100644
47724--- a/drivers/pci/probe.c
47725+++ b/drivers/pci/probe.c
47726@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47727 struct pci_bus_region region, inverted_region;
47728 bool bar_too_big = false, bar_disabled = false;
47729
47730- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47731+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47732
47733 /* No printks while decoding is disabled! */
47734 if (!dev->mmio_always_on) {
47735diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47736index 46d1378..30e452b 100644
47737--- a/drivers/pci/proc.c
47738+++ b/drivers/pci/proc.c
47739@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47740 static int __init pci_proc_init(void)
47741 {
47742 struct pci_dev *dev = NULL;
47743+
47744+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47745+#ifdef CONFIG_GRKERNSEC_PROC_USER
47746+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47747+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47748+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47749+#endif
47750+#else
47751 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47752+#endif
47753 proc_create("devices", 0, proc_bus_pci_dir,
47754 &proc_bus_pci_dev_operations);
47755 proc_initialized = 1;
47756diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47757index 7f3aad0..7d604bb 100644
47758--- a/drivers/platform/chrome/chromeos_laptop.c
47759+++ b/drivers/platform/chrome/chromeos_laptop.c
47760@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47761 .callback = chromeos_laptop_dmi_matched, \
47762 .driver_data = (void *)&board_
47763
47764-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47765+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47766 {
47767 .ident = "Samsung Series 5 550",
47768 .matches = {
47769diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47770index c5e082f..d6307a0 100644
47771--- a/drivers/platform/x86/asus-wmi.c
47772+++ b/drivers/platform/x86/asus-wmi.c
47773@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47774 int err;
47775 u32 retval = -1;
47776
47777+#ifdef CONFIG_GRKERNSEC_KMEM
47778+ return -EPERM;
47779+#endif
47780+
47781 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47782
47783 if (err < 0)
47784@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47785 int err;
47786 u32 retval = -1;
47787
47788+#ifdef CONFIG_GRKERNSEC_KMEM
47789+ return -EPERM;
47790+#endif
47791+
47792 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47793 &retval);
47794
47795@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47796 union acpi_object *obj;
47797 acpi_status status;
47798
47799+#ifdef CONFIG_GRKERNSEC_KMEM
47800+ return -EPERM;
47801+#endif
47802+
47803 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47804 1, asus->debug.method_id,
47805 &input, &output);
47806diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47807index 62f8030..c7f2a45 100644
47808--- a/drivers/platform/x86/msi-laptop.c
47809+++ b/drivers/platform/x86/msi-laptop.c
47810@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47811
47812 if (!quirks->ec_read_only) {
47813 /* allow userland write sysfs file */
47814- dev_attr_bluetooth.store = store_bluetooth;
47815- dev_attr_wlan.store = store_wlan;
47816- dev_attr_threeg.store = store_threeg;
47817- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47818- dev_attr_wlan.attr.mode |= S_IWUSR;
47819- dev_attr_threeg.attr.mode |= S_IWUSR;
47820+ pax_open_kernel();
47821+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47822+ *(void **)&dev_attr_wlan.store = store_wlan;
47823+ *(void **)&dev_attr_threeg.store = store_threeg;
47824+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47825+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47826+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47827+ pax_close_kernel();
47828 }
47829
47830 /* disable hardware control by fn key */
47831diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47832index 70222f2..8c8ce66 100644
47833--- a/drivers/platform/x86/msi-wmi.c
47834+++ b/drivers/platform/x86/msi-wmi.c
47835@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47836 static void msi_wmi_notify(u32 value, void *context)
47837 {
47838 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47839- static struct key_entry *key;
47840+ struct key_entry *key;
47841 union acpi_object *obj;
47842 acpi_status status;
47843
47844diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47845index 8f8551a..3ace3ca 100644
47846--- a/drivers/platform/x86/sony-laptop.c
47847+++ b/drivers/platform/x86/sony-laptop.c
47848@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47849 }
47850
47851 /* High speed charging function */
47852-static struct device_attribute *hsc_handle;
47853+static device_attribute_no_const *hsc_handle;
47854
47855 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47856 struct device_attribute *attr,
47857diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47858index defb6af..7a5d3d1 100644
47859--- a/drivers/platform/x86/thinkpad_acpi.c
47860+++ b/drivers/platform/x86/thinkpad_acpi.c
47861@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47862 return 0;
47863 }
47864
47865-void static hotkey_mask_warn_incomplete_mask(void)
47866+static void hotkey_mask_warn_incomplete_mask(void)
47867 {
47868 /* log only what the user can fix... */
47869 const u32 wantedmask = hotkey_driver_mask &
47870@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47871 }
47872 }
47873
47874-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47875- struct tp_nvram_state *newn,
47876- const u32 event_mask)
47877-{
47878-
47879 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47880 do { \
47881 if ((event_mask & (1 << __scancode)) && \
47882@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47883 tpacpi_hotkey_send_key(__scancode); \
47884 } while (0)
47885
47886- void issue_volchange(const unsigned int oldvol,
47887- const unsigned int newvol)
47888- {
47889- unsigned int i = oldvol;
47890+static void issue_volchange(const unsigned int oldvol,
47891+ const unsigned int newvol,
47892+ const u32 event_mask)
47893+{
47894+ unsigned int i = oldvol;
47895
47896- while (i > newvol) {
47897- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47898- i--;
47899- }
47900- while (i < newvol) {
47901- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47902- i++;
47903- }
47904+ while (i > newvol) {
47905+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47906+ i--;
47907 }
47908+ while (i < newvol) {
47909+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47910+ i++;
47911+ }
47912+}
47913
47914- void issue_brightnesschange(const unsigned int oldbrt,
47915- const unsigned int newbrt)
47916- {
47917- unsigned int i = oldbrt;
47918+static void issue_brightnesschange(const unsigned int oldbrt,
47919+ const unsigned int newbrt,
47920+ const u32 event_mask)
47921+{
47922+ unsigned int i = oldbrt;
47923
47924- while (i > newbrt) {
47925- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47926- i--;
47927- }
47928- while (i < newbrt) {
47929- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47930- i++;
47931- }
47932+ while (i > newbrt) {
47933+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47934+ i--;
47935+ }
47936+ while (i < newbrt) {
47937+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47938+ i++;
47939 }
47940+}
47941
47942+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47943+ struct tp_nvram_state *newn,
47944+ const u32 event_mask)
47945+{
47946 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47947 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47948 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47949@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47950 oldn->volume_level != newn->volume_level) {
47951 /* recently muted, or repeated mute keypress, or
47952 * multiple presses ending in mute */
47953- issue_volchange(oldn->volume_level, newn->volume_level);
47954+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47955 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47956 }
47957 } else {
47958@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47959 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47960 }
47961 if (oldn->volume_level != newn->volume_level) {
47962- issue_volchange(oldn->volume_level, newn->volume_level);
47963+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47964 } else if (oldn->volume_toggle != newn->volume_toggle) {
47965 /* repeated vol up/down keypress at end of scale ? */
47966 if (newn->volume_level == 0)
47967@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47968 /* handle brightness */
47969 if (oldn->brightness_level != newn->brightness_level) {
47970 issue_brightnesschange(oldn->brightness_level,
47971- newn->brightness_level);
47972+ newn->brightness_level,
47973+ event_mask);
47974 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47975 /* repeated key presses that didn't change state */
47976 if (newn->brightness_level == 0)
47977@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47978 && !tp_features.bright_unkfw)
47979 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47980 }
47981+}
47982
47983 #undef TPACPI_COMPARE_KEY
47984 #undef TPACPI_MAY_SEND_KEY
47985-}
47986
47987 /*
47988 * Polling driver
47989diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47990index 769d265..a3a05ca 100644
47991--- a/drivers/pnp/pnpbios/bioscalls.c
47992+++ b/drivers/pnp/pnpbios/bioscalls.c
47993@@ -58,7 +58,7 @@ do { \
47994 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47995 } while(0)
47996
47997-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47998+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47999 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48000
48001 /*
48002@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48003
48004 cpu = get_cpu();
48005 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48006+
48007+ pax_open_kernel();
48008 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48009+ pax_close_kernel();
48010
48011 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48012 spin_lock_irqsave(&pnp_bios_lock, flags);
48013@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48014 :"memory");
48015 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48016
48017+ pax_open_kernel();
48018 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48019+ pax_close_kernel();
48020+
48021 put_cpu();
48022
48023 /* If we get here and this is set then the PnP BIOS faulted on us. */
48024@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48025 return status;
48026 }
48027
48028-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48029+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48030 {
48031 int i;
48032
48033@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48034 pnp_bios_callpoint.offset = header->fields.pm16offset;
48035 pnp_bios_callpoint.segment = PNP_CS16;
48036
48037+ pax_open_kernel();
48038+
48039 for_each_possible_cpu(i) {
48040 struct desc_struct *gdt = get_cpu_gdt_table(i);
48041 if (!gdt)
48042@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48043 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48044 (unsigned long)__va(header->fields.pm16dseg));
48045 }
48046+
48047+ pax_close_kernel();
48048 }
48049diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48050index bacddd1..65ea100 100644
48051--- a/drivers/pnp/resource.c
48052+++ b/drivers/pnp/resource.c
48053@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48054 return 1;
48055
48056 /* check if the resource is valid */
48057- if (*irq < 0 || *irq > 15)
48058+ if (*irq > 15)
48059 return 0;
48060
48061 /* check if the resource is reserved */
48062@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48063 return 1;
48064
48065 /* check if the resource is valid */
48066- if (*dma < 0 || *dma == 4 || *dma > 7)
48067+ if (*dma == 4 || *dma > 7)
48068 return 0;
48069
48070 /* check if the resource is reserved */
48071diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48072index 0c52e2a..3421ab7 100644
48073--- a/drivers/power/pda_power.c
48074+++ b/drivers/power/pda_power.c
48075@@ -37,7 +37,11 @@ static int polling;
48076
48077 #if IS_ENABLED(CONFIG_USB_PHY)
48078 static struct usb_phy *transceiver;
48079-static struct notifier_block otg_nb;
48080+static int otg_handle_notification(struct notifier_block *nb,
48081+ unsigned long event, void *unused);
48082+static struct notifier_block otg_nb = {
48083+ .notifier_call = otg_handle_notification
48084+};
48085 #endif
48086
48087 static struct regulator *ac_draw;
48088@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48089
48090 #if IS_ENABLED(CONFIG_USB_PHY)
48091 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48092- otg_nb.notifier_call = otg_handle_notification;
48093 ret = usb_register_notifier(transceiver, &otg_nb);
48094 if (ret) {
48095 dev_err(dev, "failure to register otg notifier\n");
48096diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48097index cc439fd..8fa30df 100644
48098--- a/drivers/power/power_supply.h
48099+++ b/drivers/power/power_supply.h
48100@@ -16,12 +16,12 @@ struct power_supply;
48101
48102 #ifdef CONFIG_SYSFS
48103
48104-extern void power_supply_init_attrs(struct device_type *dev_type);
48105+extern void power_supply_init_attrs(void);
48106 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48107
48108 #else
48109
48110-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48111+static inline void power_supply_init_attrs(void) {}
48112 #define power_supply_uevent NULL
48113
48114 #endif /* CONFIG_SYSFS */
48115diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48116index 2660664..75fcb04 100644
48117--- a/drivers/power/power_supply_core.c
48118+++ b/drivers/power/power_supply_core.c
48119@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48120 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48121 EXPORT_SYMBOL_GPL(power_supply_notifier);
48122
48123-static struct device_type power_supply_dev_type;
48124+extern const struct attribute_group *power_supply_attr_groups[];
48125+static struct device_type power_supply_dev_type = {
48126+ .groups = power_supply_attr_groups,
48127+};
48128
48129 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48130 struct power_supply *supply)
48131@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48132 return PTR_ERR(power_supply_class);
48133
48134 power_supply_class->dev_uevent = power_supply_uevent;
48135- power_supply_init_attrs(&power_supply_dev_type);
48136+ power_supply_init_attrs();
48137
48138 return 0;
48139 }
48140diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48141index 44420d1..967126e 100644
48142--- a/drivers/power/power_supply_sysfs.c
48143+++ b/drivers/power/power_supply_sysfs.c
48144@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48145 .is_visible = power_supply_attr_is_visible,
48146 };
48147
48148-static const struct attribute_group *power_supply_attr_groups[] = {
48149+const struct attribute_group *power_supply_attr_groups[] = {
48150 &power_supply_attr_group,
48151 NULL,
48152 };
48153
48154-void power_supply_init_attrs(struct device_type *dev_type)
48155+void power_supply_init_attrs(void)
48156 {
48157 int i;
48158
48159- dev_type->groups = power_supply_attr_groups;
48160-
48161 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48162 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48163 }
48164diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48165index 84419af..268ede8 100644
48166--- a/drivers/powercap/powercap_sys.c
48167+++ b/drivers/powercap/powercap_sys.c
48168@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48169 struct device_attribute name_attr;
48170 };
48171
48172+static ssize_t show_constraint_name(struct device *dev,
48173+ struct device_attribute *dev_attr,
48174+ char *buf);
48175+
48176 static struct powercap_constraint_attr
48177- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48178+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48179+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48180+ .power_limit_attr = {
48181+ .attr = {
48182+ .name = NULL,
48183+ .mode = S_IWUSR | S_IRUGO
48184+ },
48185+ .show = show_constraint_power_limit_uw,
48186+ .store = store_constraint_power_limit_uw
48187+ },
48188+
48189+ .time_window_attr = {
48190+ .attr = {
48191+ .name = NULL,
48192+ .mode = S_IWUSR | S_IRUGO
48193+ },
48194+ .show = show_constraint_time_window_us,
48195+ .store = store_constraint_time_window_us
48196+ },
48197+
48198+ .max_power_attr = {
48199+ .attr = {
48200+ .name = NULL,
48201+ .mode = S_IRUGO
48202+ },
48203+ .show = show_constraint_max_power_uw,
48204+ .store = NULL
48205+ },
48206+
48207+ .min_power_attr = {
48208+ .attr = {
48209+ .name = NULL,
48210+ .mode = S_IRUGO
48211+ },
48212+ .show = show_constraint_min_power_uw,
48213+ .store = NULL
48214+ },
48215+
48216+ .max_time_window_attr = {
48217+ .attr = {
48218+ .name = NULL,
48219+ .mode = S_IRUGO
48220+ },
48221+ .show = show_constraint_max_time_window_us,
48222+ .store = NULL
48223+ },
48224+
48225+ .min_time_window_attr = {
48226+ .attr = {
48227+ .name = NULL,
48228+ .mode = S_IRUGO
48229+ },
48230+ .show = show_constraint_min_time_window_us,
48231+ .store = NULL
48232+ },
48233+
48234+ .name_attr = {
48235+ .attr = {
48236+ .name = NULL,
48237+ .mode = S_IRUGO
48238+ },
48239+ .show = show_constraint_name,
48240+ .store = NULL
48241+ }
48242+ }
48243+};
48244
48245 /* A list of powercap control_types */
48246 static LIST_HEAD(powercap_cntrl_list);
48247@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48248 }
48249
48250 static int create_constraint_attribute(int id, const char *name,
48251- int mode,
48252- struct device_attribute *dev_attr,
48253- ssize_t (*show)(struct device *,
48254- struct device_attribute *, char *),
48255- ssize_t (*store)(struct device *,
48256- struct device_attribute *,
48257- const char *, size_t)
48258- )
48259+ struct device_attribute *dev_attr)
48260 {
48261+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48262
48263- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48264- id, name);
48265- if (!dev_attr->attr.name)
48266+ if (!name)
48267 return -ENOMEM;
48268- dev_attr->attr.mode = mode;
48269- dev_attr->show = show;
48270- dev_attr->store = store;
48271+
48272+ pax_open_kernel();
48273+ *(const char **)&dev_attr->attr.name = name;
48274+ pax_close_kernel();
48275
48276 return 0;
48277 }
48278@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48279
48280 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48281 ret = create_constraint_attribute(i, "power_limit_uw",
48282- S_IWUSR | S_IRUGO,
48283- &constraint_attrs[i].power_limit_attr,
48284- show_constraint_power_limit_uw,
48285- store_constraint_power_limit_uw);
48286+ &constraint_attrs[i].power_limit_attr);
48287 if (ret)
48288 goto err_alloc;
48289 ret = create_constraint_attribute(i, "time_window_us",
48290- S_IWUSR | S_IRUGO,
48291- &constraint_attrs[i].time_window_attr,
48292- show_constraint_time_window_us,
48293- store_constraint_time_window_us);
48294+ &constraint_attrs[i].time_window_attr);
48295 if (ret)
48296 goto err_alloc;
48297- ret = create_constraint_attribute(i, "name", S_IRUGO,
48298- &constraint_attrs[i].name_attr,
48299- show_constraint_name,
48300- NULL);
48301+ ret = create_constraint_attribute(i, "name",
48302+ &constraint_attrs[i].name_attr);
48303 if (ret)
48304 goto err_alloc;
48305- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48306- &constraint_attrs[i].max_power_attr,
48307- show_constraint_max_power_uw,
48308- NULL);
48309+ ret = create_constraint_attribute(i, "max_power_uw",
48310+ &constraint_attrs[i].max_power_attr);
48311 if (ret)
48312 goto err_alloc;
48313- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48314- &constraint_attrs[i].min_power_attr,
48315- show_constraint_min_power_uw,
48316- NULL);
48317+ ret = create_constraint_attribute(i, "min_power_uw",
48318+ &constraint_attrs[i].min_power_attr);
48319 if (ret)
48320 goto err_alloc;
48321 ret = create_constraint_attribute(i, "max_time_window_us",
48322- S_IRUGO,
48323- &constraint_attrs[i].max_time_window_attr,
48324- show_constraint_max_time_window_us,
48325- NULL);
48326+ &constraint_attrs[i].max_time_window_attr);
48327 if (ret)
48328 goto err_alloc;
48329 ret = create_constraint_attribute(i, "min_time_window_us",
48330- S_IRUGO,
48331- &constraint_attrs[i].min_time_window_attr,
48332- show_constraint_min_time_window_us,
48333- NULL);
48334+ &constraint_attrs[i].min_time_window_attr);
48335 if (ret)
48336 goto err_alloc;
48337
48338@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48339 power_zone->zone_dev_attrs[count++] =
48340 &dev_attr_max_energy_range_uj.attr;
48341 if (power_zone->ops->get_energy_uj) {
48342+ pax_open_kernel();
48343 if (power_zone->ops->reset_energy_uj)
48344- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48345+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48346 else
48347- dev_attr_energy_uj.attr.mode = S_IRUGO;
48348+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48349+ pax_close_kernel();
48350 power_zone->zone_dev_attrs[count++] =
48351 &dev_attr_energy_uj.attr;
48352 }
48353diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48354index afca1bc..86840b8 100644
48355--- a/drivers/regulator/core.c
48356+++ b/drivers/regulator/core.c
48357@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48358 {
48359 const struct regulation_constraints *constraints = NULL;
48360 const struct regulator_init_data *init_data;
48361- static atomic_t regulator_no = ATOMIC_INIT(0);
48362+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48363 struct regulator_dev *rdev;
48364 struct device *dev;
48365 int ret, i;
48366@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48367 rdev->dev.of_node = config->of_node;
48368 rdev->dev.parent = dev;
48369 dev_set_name(&rdev->dev, "regulator.%d",
48370- atomic_inc_return(&regulator_no) - 1);
48371+ atomic_inc_return_unchecked(&regulator_no) - 1);
48372 ret = device_register(&rdev->dev);
48373 if (ret != 0) {
48374 put_device(&rdev->dev);
48375diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48376index 8d94d3d..653b623 100644
48377--- a/drivers/regulator/max8660.c
48378+++ b/drivers/regulator/max8660.c
48379@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48380 max8660->shadow_regs[MAX8660_OVER1] = 5;
48381 } else {
48382 /* Otherwise devices can be toggled via software */
48383- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48384- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48385+ pax_open_kernel();
48386+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48387+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48388+ pax_close_kernel();
48389 }
48390
48391 /*
48392diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48393index 892aa1e..ebd1b9c 100644
48394--- a/drivers/regulator/max8973-regulator.c
48395+++ b/drivers/regulator/max8973-regulator.c
48396@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48397 if (!pdata || !pdata->enable_ext_control) {
48398 max->desc.enable_reg = MAX8973_VOUT;
48399 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48400- max->ops.enable = regulator_enable_regmap;
48401- max->ops.disable = regulator_disable_regmap;
48402- max->ops.is_enabled = regulator_is_enabled_regmap;
48403+ pax_open_kernel();
48404+ *(void **)&max->ops.enable = regulator_enable_regmap;
48405+ *(void **)&max->ops.disable = regulator_disable_regmap;
48406+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48407+ pax_close_kernel();
48408 }
48409
48410 if (pdata) {
48411diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48412index f374fa5..26f0683 100644
48413--- a/drivers/regulator/mc13892-regulator.c
48414+++ b/drivers/regulator/mc13892-regulator.c
48415@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48416 }
48417 mc13xxx_unlock(mc13892);
48418
48419- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48420+ pax_open_kernel();
48421+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48422 = mc13892_vcam_set_mode;
48423- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48424+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48425 = mc13892_vcam_get_mode;
48426+ pax_close_kernel();
48427
48428 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48429 ARRAY_SIZE(mc13892_regulators));
48430diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48431index cae212f..58a3980 100644
48432--- a/drivers/rtc/rtc-cmos.c
48433+++ b/drivers/rtc/rtc-cmos.c
48434@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48435 hpet_rtc_timer_init();
48436
48437 /* export at least the first block of NVRAM */
48438- nvram.size = address_space - NVRAM_OFFSET;
48439+ pax_open_kernel();
48440+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48441+ pax_close_kernel();
48442 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48443 if (retval < 0) {
48444 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48445diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48446index d049393..bb20be0 100644
48447--- a/drivers/rtc/rtc-dev.c
48448+++ b/drivers/rtc/rtc-dev.c
48449@@ -16,6 +16,7 @@
48450 #include <linux/module.h>
48451 #include <linux/rtc.h>
48452 #include <linux/sched.h>
48453+#include <linux/grsecurity.h>
48454 #include "rtc-core.h"
48455
48456 static dev_t rtc_devt;
48457@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48458 if (copy_from_user(&tm, uarg, sizeof(tm)))
48459 return -EFAULT;
48460
48461+ gr_log_timechange();
48462+
48463 return rtc_set_time(rtc, &tm);
48464
48465 case RTC_PIE_ON:
48466diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48467index 4e75345..09f8663 100644
48468--- a/drivers/rtc/rtc-ds1307.c
48469+++ b/drivers/rtc/rtc-ds1307.c
48470@@ -107,7 +107,7 @@ struct ds1307 {
48471 u8 offset; /* register's offset */
48472 u8 regs[11];
48473 u16 nvram_offset;
48474- struct bin_attribute *nvram;
48475+ bin_attribute_no_const *nvram;
48476 enum ds_type type;
48477 unsigned long flags;
48478 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48479diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48480index 11880c1..b823aa4 100644
48481--- a/drivers/rtc/rtc-m48t59.c
48482+++ b/drivers/rtc/rtc-m48t59.c
48483@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48484 if (IS_ERR(m48t59->rtc))
48485 return PTR_ERR(m48t59->rtc);
48486
48487- m48t59_nvram_attr.size = pdata->offset;
48488+ pax_open_kernel();
48489+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48490+ pax_close_kernel();
48491
48492 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48493 if (ret)
48494diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48495index 14b5f8d..cc9bd26 100644
48496--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48497+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48498@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48499 for (bit = 0; bit < 8; bit++) {
48500
48501 if ((pci_status[i] & (0x1 << bit)) != 0) {
48502- static const char *s;
48503+ const char *s;
48504
48505 s = pci_status_strings[bit];
48506 if (i == 7/*TARG*/ && bit == 3)
48507@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48508
48509 for (bit = 0; bit < 8; bit++) {
48510
48511- if ((split_status[i] & (0x1 << bit)) != 0) {
48512- static const char *s;
48513-
48514- s = split_status_strings[bit];
48515- printk(s, ahd_name(ahd),
48516+ if ((split_status[i] & (0x1 << bit)) != 0)
48517+ printk(split_status_strings[bit], ahd_name(ahd),
48518 split_status_source[i]);
48519- }
48520
48521 if (i > 1)
48522 continue;
48523
48524- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48525- static const char *s;
48526-
48527- s = split_status_strings[bit];
48528- printk(s, ahd_name(ahd), "SG");
48529- }
48530+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48531+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48532 }
48533 }
48534 /*
48535diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48536index e693af6..2e525b6 100644
48537--- a/drivers/scsi/bfa/bfa_fcpim.h
48538+++ b/drivers/scsi/bfa/bfa_fcpim.h
48539@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48540
48541 struct bfa_itn_s {
48542 bfa_isr_func_t isr;
48543-};
48544+} __no_const;
48545
48546 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48547 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48548diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48549index a3ab5cc..8143622 100644
48550--- a/drivers/scsi/bfa/bfa_fcs.c
48551+++ b/drivers/scsi/bfa/bfa_fcs.c
48552@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48553 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48554
48555 static struct bfa_fcs_mod_s fcs_modules[] = {
48556- { bfa_fcs_port_attach, NULL, NULL },
48557- { bfa_fcs_uf_attach, NULL, NULL },
48558- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48559- bfa_fcs_fabric_modexit },
48560+ {
48561+ .attach = bfa_fcs_port_attach,
48562+ .modinit = NULL,
48563+ .modexit = NULL
48564+ },
48565+ {
48566+ .attach = bfa_fcs_uf_attach,
48567+ .modinit = NULL,
48568+ .modexit = NULL
48569+ },
48570+ {
48571+ .attach = bfa_fcs_fabric_attach,
48572+ .modinit = bfa_fcs_fabric_modinit,
48573+ .modexit = bfa_fcs_fabric_modexit
48574+ },
48575 };
48576
48577 /*
48578diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48579index ff75ef8..2dfe00a 100644
48580--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48581+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48582@@ -89,15 +89,26 @@ static struct {
48583 void (*offline) (struct bfa_fcs_lport_s *port);
48584 } __port_action[] = {
48585 {
48586- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48587- bfa_fcs_lport_unknown_offline}, {
48588- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48589- bfa_fcs_lport_fab_offline}, {
48590- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48591- bfa_fcs_lport_n2n_offline}, {
48592- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48593- bfa_fcs_lport_loop_offline},
48594- };
48595+ .init = bfa_fcs_lport_unknown_init,
48596+ .online = bfa_fcs_lport_unknown_online,
48597+ .offline = bfa_fcs_lport_unknown_offline
48598+ },
48599+ {
48600+ .init = bfa_fcs_lport_fab_init,
48601+ .online = bfa_fcs_lport_fab_online,
48602+ .offline = bfa_fcs_lport_fab_offline
48603+ },
48604+ {
48605+ .init = bfa_fcs_lport_n2n_init,
48606+ .online = bfa_fcs_lport_n2n_online,
48607+ .offline = bfa_fcs_lport_n2n_offline
48608+ },
48609+ {
48610+ .init = bfa_fcs_lport_loop_init,
48611+ .online = bfa_fcs_lport_loop_online,
48612+ .offline = bfa_fcs_lport_loop_offline
48613+ },
48614+};
48615
48616 /*
48617 * fcs_port_sm FCS logical port state machine
48618diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48619index 2e28392..9d865b6 100644
48620--- a/drivers/scsi/bfa/bfa_ioc.h
48621+++ b/drivers/scsi/bfa/bfa_ioc.h
48622@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48623 bfa_ioc_disable_cbfn_t disable_cbfn;
48624 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48625 bfa_ioc_reset_cbfn_t reset_cbfn;
48626-};
48627+} __no_const;
48628
48629 /*
48630 * IOC event notification mechanism.
48631@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48632 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48633 enum bfi_ioc_state fwstate);
48634 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48635-};
48636+} __no_const;
48637
48638 /*
48639 * Queue element to wait for room in request queue. FIFO order is
48640diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48641index a14c784..6de6790 100644
48642--- a/drivers/scsi/bfa/bfa_modules.h
48643+++ b/drivers/scsi/bfa/bfa_modules.h
48644@@ -78,12 +78,12 @@ enum {
48645 \
48646 extern struct bfa_module_s hal_mod_ ## __mod; \
48647 struct bfa_module_s hal_mod_ ## __mod = { \
48648- bfa_ ## __mod ## _meminfo, \
48649- bfa_ ## __mod ## _attach, \
48650- bfa_ ## __mod ## _detach, \
48651- bfa_ ## __mod ## _start, \
48652- bfa_ ## __mod ## _stop, \
48653- bfa_ ## __mod ## _iocdisable, \
48654+ .meminfo = bfa_ ## __mod ## _meminfo, \
48655+ .attach = bfa_ ## __mod ## _attach, \
48656+ .detach = bfa_ ## __mod ## _detach, \
48657+ .start = bfa_ ## __mod ## _start, \
48658+ .stop = bfa_ ## __mod ## _stop, \
48659+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48660 }
48661
48662 #define BFA_CACHELINE_SZ (256)
48663diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48664index 045c4e1..13de803 100644
48665--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48666+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48667@@ -33,8 +33,8 @@
48668 */
48669 #include "libfcoe.h"
48670
48671-static atomic_t ctlr_num;
48672-static atomic_t fcf_num;
48673+static atomic_unchecked_t ctlr_num;
48674+static atomic_unchecked_t fcf_num;
48675
48676 /*
48677 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48678@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48679 if (!ctlr)
48680 goto out;
48681
48682- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48683+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48684 ctlr->f = f;
48685 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48686 INIT_LIST_HEAD(&ctlr->fcfs);
48687@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48688 fcf->dev.parent = &ctlr->dev;
48689 fcf->dev.bus = &fcoe_bus_type;
48690 fcf->dev.type = &fcoe_fcf_device_type;
48691- fcf->id = atomic_inc_return(&fcf_num) - 1;
48692+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48693 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48694
48695 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48696@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48697 {
48698 int error;
48699
48700- atomic_set(&ctlr_num, 0);
48701- atomic_set(&fcf_num, 0);
48702+ atomic_set_unchecked(&ctlr_num, 0);
48703+ atomic_set_unchecked(&fcf_num, 0);
48704
48705 error = bus_register(&fcoe_bus_type);
48706 if (error)
48707diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48708index f28ea07..34b16d3 100644
48709--- a/drivers/scsi/hosts.c
48710+++ b/drivers/scsi/hosts.c
48711@@ -42,7 +42,7 @@
48712 #include "scsi_logging.h"
48713
48714
48715-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48716+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48717
48718
48719 static void scsi_host_cls_release(struct device *dev)
48720@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48721 * subtract one because we increment first then return, but we need to
48722 * know what the next host number was before increment
48723 */
48724- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48725+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48726 shost->dma_channel = 0xff;
48727
48728 /* These three are default values which can be overridden */
48729diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48730index 868318a..e07ef3b 100644
48731--- a/drivers/scsi/hpsa.c
48732+++ b/drivers/scsi/hpsa.c
48733@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48734 unsigned long flags;
48735
48736 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48737- return h->access.command_completed(h, q);
48738+ return h->access->command_completed(h, q);
48739
48740 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48741 a = rq->head[rq->current_entry];
48742@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48743 while (!list_empty(&h->reqQ)) {
48744 c = list_entry(h->reqQ.next, struct CommandList, list);
48745 /* can't do anything if fifo is full */
48746- if ((h->access.fifo_full(h))) {
48747+ if ((h->access->fifo_full(h))) {
48748 h->fifo_recently_full = 1;
48749 dev_warn(&h->pdev->dev, "fifo full\n");
48750 break;
48751@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48752
48753 /* Tell the controller execute command */
48754 spin_unlock_irqrestore(&h->lock, flags);
48755- h->access.submit_command(h, c);
48756+ h->access->submit_command(h, c);
48757 spin_lock_irqsave(&h->lock, flags);
48758 }
48759 spin_unlock_irqrestore(&h->lock, flags);
48760@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48761
48762 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48763 {
48764- return h->access.command_completed(h, q);
48765+ return h->access->command_completed(h, q);
48766 }
48767
48768 static inline bool interrupt_pending(struct ctlr_info *h)
48769 {
48770- return h->access.intr_pending(h);
48771+ return h->access->intr_pending(h);
48772 }
48773
48774 static inline long interrupt_not_for_us(struct ctlr_info *h)
48775 {
48776- return (h->access.intr_pending(h) == 0) ||
48777+ return (h->access->intr_pending(h) == 0) ||
48778 (h->interrupts_enabled == 0);
48779 }
48780
48781@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48782 if (prod_index < 0)
48783 return -ENODEV;
48784 h->product_name = products[prod_index].product_name;
48785- h->access = *(products[prod_index].access);
48786+ h->access = products[prod_index].access;
48787
48788 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48789 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48790@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48791 {
48792 unsigned long flags;
48793
48794- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48795+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48796 spin_lock_irqsave(&h->lock, flags);
48797 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48798 spin_unlock_irqrestore(&h->lock, flags);
48799@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48800 }
48801
48802 /* make sure the board interrupts are off */
48803- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48804+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48805
48806 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48807 goto clean2;
48808@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48809 * fake ones to scoop up any residual completions.
48810 */
48811 spin_lock_irqsave(&h->lock, flags);
48812- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48813+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48814 spin_unlock_irqrestore(&h->lock, flags);
48815 free_irqs(h);
48816 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48817@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48818 dev_info(&h->pdev->dev, "Board READY.\n");
48819 dev_info(&h->pdev->dev,
48820 "Waiting for stale completions to drain.\n");
48821- h->access.set_intr_mask(h, HPSA_INTR_ON);
48822+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48823 msleep(10000);
48824- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48825+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48826
48827 rc = controller_reset_failed(h->cfgtable);
48828 if (rc)
48829@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48830 }
48831
48832 /* Turn the interrupts on so we can service requests */
48833- h->access.set_intr_mask(h, HPSA_INTR_ON);
48834+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48835
48836 hpsa_hba_inquiry(h);
48837 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48838@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48839 * To write all data in the battery backed cache to disks
48840 */
48841 hpsa_flush_cache(h);
48842- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48843+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48844 hpsa_free_irqs_and_disable_msix(h);
48845 }
48846
48847@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48848 return;
48849 }
48850 /* Change the access methods to the performant access methods */
48851- h->access = SA5_performant_access;
48852+ h->access = &SA5_performant_access;
48853 h->transMethod = CFGTBL_Trans_Performant;
48854 }
48855
48856diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48857index 01c3283..4655219 100644
48858--- a/drivers/scsi/hpsa.h
48859+++ b/drivers/scsi/hpsa.h
48860@@ -79,7 +79,7 @@ struct ctlr_info {
48861 unsigned int msix_vector;
48862 unsigned int msi_vector;
48863 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48864- struct access_method access;
48865+ struct access_method *access;
48866
48867 /* queue and queue Info */
48868 struct list_head reqQ;
48869@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48870 }
48871
48872 static struct access_method SA5_access = {
48873- SA5_submit_command,
48874- SA5_intr_mask,
48875- SA5_fifo_full,
48876- SA5_intr_pending,
48877- SA5_completed,
48878+ .submit_command = SA5_submit_command,
48879+ .set_intr_mask = SA5_intr_mask,
48880+ .fifo_full = SA5_fifo_full,
48881+ .intr_pending = SA5_intr_pending,
48882+ .command_completed = SA5_completed,
48883 };
48884
48885 static struct access_method SA5_performant_access = {
48886- SA5_submit_command,
48887- SA5_performant_intr_mask,
48888- SA5_fifo_full,
48889- SA5_performant_intr_pending,
48890- SA5_performant_completed,
48891+ .submit_command = SA5_submit_command,
48892+ .set_intr_mask = SA5_performant_intr_mask,
48893+ .fifo_full = SA5_fifo_full,
48894+ .intr_pending = SA5_performant_intr_pending,
48895+ .command_completed = SA5_performant_completed,
48896 };
48897
48898 struct board_type {
48899diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48900index 1b3a094..068e683 100644
48901--- a/drivers/scsi/libfc/fc_exch.c
48902+++ b/drivers/scsi/libfc/fc_exch.c
48903@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48904 u16 pool_max_index;
48905
48906 struct {
48907- atomic_t no_free_exch;
48908- atomic_t no_free_exch_xid;
48909- atomic_t xid_not_found;
48910- atomic_t xid_busy;
48911- atomic_t seq_not_found;
48912- atomic_t non_bls_resp;
48913+ atomic_unchecked_t no_free_exch;
48914+ atomic_unchecked_t no_free_exch_xid;
48915+ atomic_unchecked_t xid_not_found;
48916+ atomic_unchecked_t xid_busy;
48917+ atomic_unchecked_t seq_not_found;
48918+ atomic_unchecked_t non_bls_resp;
48919 } stats;
48920 };
48921
48922@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48923 /* allocate memory for exchange */
48924 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48925 if (!ep) {
48926- atomic_inc(&mp->stats.no_free_exch);
48927+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48928 goto out;
48929 }
48930 memset(ep, 0, sizeof(*ep));
48931@@ -874,7 +874,7 @@ out:
48932 return ep;
48933 err:
48934 spin_unlock_bh(&pool->lock);
48935- atomic_inc(&mp->stats.no_free_exch_xid);
48936+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48937 mempool_free(ep, mp->ep_pool);
48938 return NULL;
48939 }
48940@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48941 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48942 ep = fc_exch_find(mp, xid);
48943 if (!ep) {
48944- atomic_inc(&mp->stats.xid_not_found);
48945+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48946 reject = FC_RJT_OX_ID;
48947 goto out;
48948 }
48949@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48950 ep = fc_exch_find(mp, xid);
48951 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48952 if (ep) {
48953- atomic_inc(&mp->stats.xid_busy);
48954+ atomic_inc_unchecked(&mp->stats.xid_busy);
48955 reject = FC_RJT_RX_ID;
48956 goto rel;
48957 }
48958@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48959 }
48960 xid = ep->xid; /* get our XID */
48961 } else if (!ep) {
48962- atomic_inc(&mp->stats.xid_not_found);
48963+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48964 reject = FC_RJT_RX_ID; /* XID not found */
48965 goto out;
48966 }
48967@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48968 } else {
48969 sp = &ep->seq;
48970 if (sp->id != fh->fh_seq_id) {
48971- atomic_inc(&mp->stats.seq_not_found);
48972+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48973 if (f_ctl & FC_FC_END_SEQ) {
48974 /*
48975 * Update sequence_id based on incoming last
48976@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48977
48978 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48979 if (!ep) {
48980- atomic_inc(&mp->stats.xid_not_found);
48981+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48982 goto out;
48983 }
48984 if (ep->esb_stat & ESB_ST_COMPLETE) {
48985- atomic_inc(&mp->stats.xid_not_found);
48986+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48987 goto rel;
48988 }
48989 if (ep->rxid == FC_XID_UNKNOWN)
48990 ep->rxid = ntohs(fh->fh_rx_id);
48991 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48992- atomic_inc(&mp->stats.xid_not_found);
48993+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48994 goto rel;
48995 }
48996 if (ep->did != ntoh24(fh->fh_s_id) &&
48997 ep->did != FC_FID_FLOGI) {
48998- atomic_inc(&mp->stats.xid_not_found);
48999+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49000 goto rel;
49001 }
49002 sof = fr_sof(fp);
49003@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49004 sp->ssb_stat |= SSB_ST_RESP;
49005 sp->id = fh->fh_seq_id;
49006 } else if (sp->id != fh->fh_seq_id) {
49007- atomic_inc(&mp->stats.seq_not_found);
49008+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49009 goto rel;
49010 }
49011
49012@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49013 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49014
49015 if (!sp)
49016- atomic_inc(&mp->stats.xid_not_found);
49017+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49018 else
49019- atomic_inc(&mp->stats.non_bls_resp);
49020+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49021
49022 fc_frame_free(fp);
49023 }
49024@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49025
49026 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49027 mp = ema->mp;
49028- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49029+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49030 st->fc_no_free_exch_xid +=
49031- atomic_read(&mp->stats.no_free_exch_xid);
49032- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49033- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49034- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49035- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49036+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49037+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49038+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49039+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49040+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49041 }
49042 }
49043 EXPORT_SYMBOL(fc_exch_update_stats);
49044diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49045index d289583..b745eec 100644
49046--- a/drivers/scsi/libsas/sas_ata.c
49047+++ b/drivers/scsi/libsas/sas_ata.c
49048@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49049 .postreset = ata_std_postreset,
49050 .error_handler = ata_std_error_handler,
49051 .post_internal_cmd = sas_ata_post_internal,
49052- .qc_defer = ata_std_qc_defer,
49053+ .qc_defer = ata_std_qc_defer,
49054 .qc_prep = ata_noop_qc_prep,
49055 .qc_issue = sas_ata_qc_issue,
49056 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49057diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49058index 4e1b75c..0bbdfa9 100644
49059--- a/drivers/scsi/lpfc/lpfc.h
49060+++ b/drivers/scsi/lpfc/lpfc.h
49061@@ -432,7 +432,7 @@ struct lpfc_vport {
49062 struct dentry *debug_nodelist;
49063 struct dentry *vport_debugfs_root;
49064 struct lpfc_debugfs_trc *disc_trc;
49065- atomic_t disc_trc_cnt;
49066+ atomic_unchecked_t disc_trc_cnt;
49067 #endif
49068 uint8_t stat_data_enabled;
49069 uint8_t stat_data_blocked;
49070@@ -865,8 +865,8 @@ struct lpfc_hba {
49071 struct timer_list fabric_block_timer;
49072 unsigned long bit_flags;
49073 #define FABRIC_COMANDS_BLOCKED 0
49074- atomic_t num_rsrc_err;
49075- atomic_t num_cmd_success;
49076+ atomic_unchecked_t num_rsrc_err;
49077+ atomic_unchecked_t num_cmd_success;
49078 unsigned long last_rsrc_error_time;
49079 unsigned long last_ramp_down_time;
49080 unsigned long last_ramp_up_time;
49081@@ -902,7 +902,7 @@ struct lpfc_hba {
49082
49083 struct dentry *debug_slow_ring_trc;
49084 struct lpfc_debugfs_trc *slow_ring_trc;
49085- atomic_t slow_ring_trc_cnt;
49086+ atomic_unchecked_t slow_ring_trc_cnt;
49087 /* iDiag debugfs sub-directory */
49088 struct dentry *idiag_root;
49089 struct dentry *idiag_pci_cfg;
49090diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49091index b800cc9..16b6a91 100644
49092--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49093+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49094@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49095
49096 #include <linux/debugfs.h>
49097
49098-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49099+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49100 static unsigned long lpfc_debugfs_start_time = 0L;
49101
49102 /* iDiag */
49103@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49104 lpfc_debugfs_enable = 0;
49105
49106 len = 0;
49107- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49108+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49109 (lpfc_debugfs_max_disc_trc - 1);
49110 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49111 dtp = vport->disc_trc + i;
49112@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49113 lpfc_debugfs_enable = 0;
49114
49115 len = 0;
49116- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49117+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49118 (lpfc_debugfs_max_slow_ring_trc - 1);
49119 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49120 dtp = phba->slow_ring_trc + i;
49121@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49122 !vport || !vport->disc_trc)
49123 return;
49124
49125- index = atomic_inc_return(&vport->disc_trc_cnt) &
49126+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49127 (lpfc_debugfs_max_disc_trc - 1);
49128 dtp = vport->disc_trc + index;
49129 dtp->fmt = fmt;
49130 dtp->data1 = data1;
49131 dtp->data2 = data2;
49132 dtp->data3 = data3;
49133- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49134+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49135 dtp->jif = jiffies;
49136 #endif
49137 return;
49138@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49139 !phba || !phba->slow_ring_trc)
49140 return;
49141
49142- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49143+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49144 (lpfc_debugfs_max_slow_ring_trc - 1);
49145 dtp = phba->slow_ring_trc + index;
49146 dtp->fmt = fmt;
49147 dtp->data1 = data1;
49148 dtp->data2 = data2;
49149 dtp->data3 = data3;
49150- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49151+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49152 dtp->jif = jiffies;
49153 #endif
49154 return;
49155@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49156 "slow_ring buffer\n");
49157 goto debug_failed;
49158 }
49159- atomic_set(&phba->slow_ring_trc_cnt, 0);
49160+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49161 memset(phba->slow_ring_trc, 0,
49162 (sizeof(struct lpfc_debugfs_trc) *
49163 lpfc_debugfs_max_slow_ring_trc));
49164@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49165 "buffer\n");
49166 goto debug_failed;
49167 }
49168- atomic_set(&vport->disc_trc_cnt, 0);
49169+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49170
49171 snprintf(name, sizeof(name), "discovery_trace");
49172 vport->debug_disc_trc =
49173diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49174index 68c94cc..8c27be5 100644
49175--- a/drivers/scsi/lpfc/lpfc_init.c
49176+++ b/drivers/scsi/lpfc/lpfc_init.c
49177@@ -10949,8 +10949,10 @@ lpfc_init(void)
49178 "misc_register returned with status %d", error);
49179
49180 if (lpfc_enable_npiv) {
49181- lpfc_transport_functions.vport_create = lpfc_vport_create;
49182- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49183+ pax_open_kernel();
49184+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49185+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49186+ pax_close_kernel();
49187 }
49188 lpfc_transport_template =
49189 fc_attach_transport(&lpfc_transport_functions);
49190diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49191index b2ede05..aaf482ca 100644
49192--- a/drivers/scsi/lpfc/lpfc_scsi.c
49193+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49194@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49195 uint32_t evt_posted;
49196
49197 spin_lock_irqsave(&phba->hbalock, flags);
49198- atomic_inc(&phba->num_rsrc_err);
49199+ atomic_inc_unchecked(&phba->num_rsrc_err);
49200 phba->last_rsrc_error_time = jiffies;
49201
49202 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49203@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49204 unsigned long flags;
49205 struct lpfc_hba *phba = vport->phba;
49206 uint32_t evt_posted;
49207- atomic_inc(&phba->num_cmd_success);
49208+ atomic_inc_unchecked(&phba->num_cmd_success);
49209
49210 if (vport->cfg_lun_queue_depth <= queue_depth)
49211 return;
49212@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49213 unsigned long num_rsrc_err, num_cmd_success;
49214 int i;
49215
49216- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49217- num_cmd_success = atomic_read(&phba->num_cmd_success);
49218+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49219+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49220
49221 /*
49222 * The error and success command counters are global per
49223@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49224 }
49225 }
49226 lpfc_destroy_vport_work_array(phba, vports);
49227- atomic_set(&phba->num_rsrc_err, 0);
49228- atomic_set(&phba->num_cmd_success, 0);
49229+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49230+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49231 }
49232
49233 /**
49234@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49235 }
49236 }
49237 lpfc_destroy_vport_work_array(phba, vports);
49238- atomic_set(&phba->num_rsrc_err, 0);
49239- atomic_set(&phba->num_cmd_success, 0);
49240+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49241+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49242 }
49243
49244 /**
49245diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49246index 7f0af4f..193ac3e 100644
49247--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49248+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49249@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49250 {
49251 struct scsi_device *sdev = to_scsi_device(dev);
49252 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49253- static struct _raid_device *raid_device;
49254+ struct _raid_device *raid_device;
49255 unsigned long flags;
49256 Mpi2RaidVolPage0_t vol_pg0;
49257 Mpi2ConfigReply_t mpi_reply;
49258@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49259 {
49260 struct scsi_device *sdev = to_scsi_device(dev);
49261 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49262- static struct _raid_device *raid_device;
49263+ struct _raid_device *raid_device;
49264 unsigned long flags;
49265 Mpi2RaidVolPage0_t vol_pg0;
49266 Mpi2ConfigReply_t mpi_reply;
49267@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49268 struct fw_event_work *fw_event)
49269 {
49270 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49271- static struct _raid_device *raid_device;
49272+ struct _raid_device *raid_device;
49273 unsigned long flags;
49274 u16 handle;
49275
49276@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49277 u64 sas_address;
49278 struct _sas_device *sas_device;
49279 struct _sas_node *expander_device;
49280- static struct _raid_device *raid_device;
49281+ struct _raid_device *raid_device;
49282 u8 retry_count;
49283 unsigned long flags;
49284
49285diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49286index be8ce54..94ed33a 100644
49287--- a/drivers/scsi/pmcraid.c
49288+++ b/drivers/scsi/pmcraid.c
49289@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49290 res->scsi_dev = scsi_dev;
49291 scsi_dev->hostdata = res;
49292 res->change_detected = 0;
49293- atomic_set(&res->read_failures, 0);
49294- atomic_set(&res->write_failures, 0);
49295+ atomic_set_unchecked(&res->read_failures, 0);
49296+ atomic_set_unchecked(&res->write_failures, 0);
49297 rc = 0;
49298 }
49299 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49300@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49301
49302 /* If this was a SCSI read/write command keep count of errors */
49303 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49304- atomic_inc(&res->read_failures);
49305+ atomic_inc_unchecked(&res->read_failures);
49306 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49307- atomic_inc(&res->write_failures);
49308+ atomic_inc_unchecked(&res->write_failures);
49309
49310 if (!RES_IS_GSCSI(res->cfg_entry) &&
49311 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49312@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49313 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49314 * hrrq_id assigned here in queuecommand
49315 */
49316- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49317+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49318 pinstance->num_hrrq;
49319 cmd->cmd_done = pmcraid_io_done;
49320
49321@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49322 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49323 * hrrq_id assigned here in queuecommand
49324 */
49325- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49326+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49327 pinstance->num_hrrq;
49328
49329 if (request_size) {
49330@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49331
49332 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49333 /* add resources only after host is added into system */
49334- if (!atomic_read(&pinstance->expose_resources))
49335+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49336 return;
49337
49338 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49339@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49340 init_waitqueue_head(&pinstance->reset_wait_q);
49341
49342 atomic_set(&pinstance->outstanding_cmds, 0);
49343- atomic_set(&pinstance->last_message_id, 0);
49344- atomic_set(&pinstance->expose_resources, 0);
49345+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49346+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49347
49348 INIT_LIST_HEAD(&pinstance->free_res_q);
49349 INIT_LIST_HEAD(&pinstance->used_res_q);
49350@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49351 /* Schedule worker thread to handle CCN and take care of adding and
49352 * removing devices to OS
49353 */
49354- atomic_set(&pinstance->expose_resources, 1);
49355+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49356 schedule_work(&pinstance->worker_q);
49357 return rc;
49358
49359diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49360index e1d150f..6c6df44 100644
49361--- a/drivers/scsi/pmcraid.h
49362+++ b/drivers/scsi/pmcraid.h
49363@@ -748,7 +748,7 @@ struct pmcraid_instance {
49364 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49365
49366 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49367- atomic_t last_message_id;
49368+ atomic_unchecked_t last_message_id;
49369
49370 /* configuration table */
49371 struct pmcraid_config_table *cfg_table;
49372@@ -777,7 +777,7 @@ struct pmcraid_instance {
49373 atomic_t outstanding_cmds;
49374
49375 /* should add/delete resources to mid-layer now ?*/
49376- atomic_t expose_resources;
49377+ atomic_unchecked_t expose_resources;
49378
49379
49380
49381@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49382 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49383 };
49384 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49385- atomic_t read_failures; /* count of failed READ commands */
49386- atomic_t write_failures; /* count of failed WRITE commands */
49387+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49388+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49389
49390 /* To indicate add/delete/modify during CCN */
49391 u8 change_detected;
49392diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49393index 4a0d7c9..3d658d7 100644
49394--- a/drivers/scsi/qla2xxx/qla_attr.c
49395+++ b/drivers/scsi/qla2xxx/qla_attr.c
49396@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49397 return 0;
49398 }
49399
49400-struct fc_function_template qla2xxx_transport_functions = {
49401+fc_function_template_no_const qla2xxx_transport_functions = {
49402
49403 .show_host_node_name = 1,
49404 .show_host_port_name = 1,
49405@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49406 .bsg_timeout = qla24xx_bsg_timeout,
49407 };
49408
49409-struct fc_function_template qla2xxx_transport_vport_functions = {
49410+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49411
49412 .show_host_node_name = 1,
49413 .show_host_port_name = 1,
49414diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49415index 1f42662..bf9836c 100644
49416--- a/drivers/scsi/qla2xxx/qla_gbl.h
49417+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49418@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49419 struct device_attribute;
49420 extern struct device_attribute *qla2x00_host_attrs[];
49421 struct fc_function_template;
49422-extern struct fc_function_template qla2xxx_transport_functions;
49423-extern struct fc_function_template qla2xxx_transport_vport_functions;
49424+extern fc_function_template_no_const qla2xxx_transport_functions;
49425+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49426 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49427 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49428 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49429diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49430index 83cb612..9b7b08c 100644
49431--- a/drivers/scsi/qla2xxx/qla_os.c
49432+++ b/drivers/scsi/qla2xxx/qla_os.c
49433@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49434 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49435 /* Ok, a 64bit DMA mask is applicable. */
49436 ha->flags.enable_64bit_addressing = 1;
49437- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49438- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49439+ pax_open_kernel();
49440+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49441+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49442+ pax_close_kernel();
49443 return;
49444 }
49445 }
49446diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49447index aa67bb9..06d0e2a 100644
49448--- a/drivers/scsi/qla4xxx/ql4_def.h
49449+++ b/drivers/scsi/qla4xxx/ql4_def.h
49450@@ -303,7 +303,7 @@ struct ddb_entry {
49451 * (4000 only) */
49452 atomic_t relogin_timer; /* Max Time to wait for
49453 * relogin to complete */
49454- atomic_t relogin_retry_count; /* Num of times relogin has been
49455+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49456 * retried */
49457 uint32_t default_time2wait; /* Default Min time between
49458 * relogins (+aens) */
49459diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49460index c21adc3..1b4155f 100644
49461--- a/drivers/scsi/qla4xxx/ql4_os.c
49462+++ b/drivers/scsi/qla4xxx/ql4_os.c
49463@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49464 */
49465 if (!iscsi_is_session_online(cls_sess)) {
49466 /* Reset retry relogin timer */
49467- atomic_inc(&ddb_entry->relogin_retry_count);
49468+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49469 DEBUG2(ql4_printk(KERN_INFO, ha,
49470 "%s: index[%d] relogin timed out-retrying"
49471 " relogin (%d), retry (%d)\n", __func__,
49472 ddb_entry->fw_ddb_index,
49473- atomic_read(&ddb_entry->relogin_retry_count),
49474+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49475 ddb_entry->default_time2wait + 4));
49476 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49477 atomic_set(&ddb_entry->retry_relogin_timer,
49478@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49479
49480 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49481 atomic_set(&ddb_entry->relogin_timer, 0);
49482- atomic_set(&ddb_entry->relogin_retry_count, 0);
49483+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49484 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49485 ddb_entry->default_relogin_timeout =
49486 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49487diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49488index d8afec8..3ec7152 100644
49489--- a/drivers/scsi/scsi.c
49490+++ b/drivers/scsi/scsi.c
49491@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49492 struct Scsi_Host *host = cmd->device->host;
49493 int rtn = 0;
49494
49495- atomic_inc(&cmd->device->iorequest_cnt);
49496+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49497
49498 /* check if the device is still usable */
49499 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49500diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49501index 62ec84b..93159d8 100644
49502--- a/drivers/scsi/scsi_lib.c
49503+++ b/drivers/scsi/scsi_lib.c
49504@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49505 shost = sdev->host;
49506 scsi_init_cmd_errh(cmd);
49507 cmd->result = DID_NO_CONNECT << 16;
49508- atomic_inc(&cmd->device->iorequest_cnt);
49509+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49510
49511 /*
49512 * SCSI request completion path will do scsi_device_unbusy(),
49513@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49514
49515 INIT_LIST_HEAD(&cmd->eh_entry);
49516
49517- atomic_inc(&cmd->device->iodone_cnt);
49518+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49519 if (cmd->result)
49520- atomic_inc(&cmd->device->ioerr_cnt);
49521+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49522
49523 disposition = scsi_decide_disposition(cmd);
49524 if (disposition != SUCCESS &&
49525diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49526index 9117d0b..d289a7a 100644
49527--- a/drivers/scsi/scsi_sysfs.c
49528+++ b/drivers/scsi/scsi_sysfs.c
49529@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49530 char *buf) \
49531 { \
49532 struct scsi_device *sdev = to_scsi_device(dev); \
49533- unsigned long long count = atomic_read(&sdev->field); \
49534+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49535 return snprintf(buf, 20, "0x%llx\n", count); \
49536 } \
49537 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49538diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49539index 84a1fdf..693b0d6 100644
49540--- a/drivers/scsi/scsi_tgt_lib.c
49541+++ b/drivers/scsi/scsi_tgt_lib.c
49542@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49543 int err;
49544
49545 dprintk("%lx %u\n", uaddr, len);
49546- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49547+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49548 if (err) {
49549 /*
49550 * TODO: need to fixup sg_tablesize, max_segment_size,
49551diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49552index 4628fd5..a94a1c2 100644
49553--- a/drivers/scsi/scsi_transport_fc.c
49554+++ b/drivers/scsi/scsi_transport_fc.c
49555@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49556 * Netlink Infrastructure
49557 */
49558
49559-static atomic_t fc_event_seq;
49560+static atomic_unchecked_t fc_event_seq;
49561
49562 /**
49563 * fc_get_event_number - Obtain the next sequential FC event number
49564@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49565 u32
49566 fc_get_event_number(void)
49567 {
49568- return atomic_add_return(1, &fc_event_seq);
49569+ return atomic_add_return_unchecked(1, &fc_event_seq);
49570 }
49571 EXPORT_SYMBOL(fc_get_event_number);
49572
49573@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49574 {
49575 int error;
49576
49577- atomic_set(&fc_event_seq, 0);
49578+ atomic_set_unchecked(&fc_event_seq, 0);
49579
49580 error = transport_class_register(&fc_host_class);
49581 if (error)
49582@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49583 char *cp;
49584
49585 *val = simple_strtoul(buf, &cp, 0);
49586- if ((*cp && (*cp != '\n')) || (*val < 0))
49587+ if (*cp && (*cp != '\n'))
49588 return -EINVAL;
49589 /*
49590 * Check for overflow; dev_loss_tmo is u32
49591diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49592index fd8ffe6..fd0bebf 100644
49593--- a/drivers/scsi/scsi_transport_iscsi.c
49594+++ b/drivers/scsi/scsi_transport_iscsi.c
49595@@ -79,7 +79,7 @@ struct iscsi_internal {
49596 struct transport_container session_cont;
49597 };
49598
49599-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49600+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49601 static struct workqueue_struct *iscsi_eh_timer_workq;
49602
49603 static DEFINE_IDA(iscsi_sess_ida);
49604@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49605 int err;
49606
49607 ihost = shost->shost_data;
49608- session->sid = atomic_add_return(1, &iscsi_session_nr);
49609+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49610
49611 if (target_id == ISCSI_MAX_TARGET) {
49612 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49613@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49614 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49615 ISCSI_TRANSPORT_VERSION);
49616
49617- atomic_set(&iscsi_session_nr, 0);
49618+ atomic_set_unchecked(&iscsi_session_nr, 0);
49619
49620 err = class_register(&iscsi_transport_class);
49621 if (err)
49622diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49623index d47ffc8..30f46a9 100644
49624--- a/drivers/scsi/scsi_transport_srp.c
49625+++ b/drivers/scsi/scsi_transport_srp.c
49626@@ -36,7 +36,7 @@
49627 #include "scsi_transport_srp_internal.h"
49628
49629 struct srp_host_attrs {
49630- atomic_t next_port_id;
49631+ atomic_unchecked_t next_port_id;
49632 };
49633 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49634
49635@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49636 struct Scsi_Host *shost = dev_to_shost(dev);
49637 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49638
49639- atomic_set(&srp_host->next_port_id, 0);
49640+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49641 return 0;
49642 }
49643
49644@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49645 rport_fast_io_fail_timedout);
49646 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49647
49648- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49649+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49650 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49651
49652 transport_setup_device(&rport->dev);
49653diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49654index 36d1a23..3f33303 100644
49655--- a/drivers/scsi/sd.c
49656+++ b/drivers/scsi/sd.c
49657@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49658 sdkp->disk = gd;
49659 sdkp->index = index;
49660 atomic_set(&sdkp->openers, 0);
49661- atomic_set(&sdkp->device->ioerr_cnt, 0);
49662+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49663
49664 if (!sdp->request_queue->rq_timeout) {
49665 if (sdp->type != TYPE_MOD)
49666diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49667index df5e961..df6b97f 100644
49668--- a/drivers/scsi/sg.c
49669+++ b/drivers/scsi/sg.c
49670@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49671 sdp->disk->disk_name,
49672 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49673 NULL,
49674- (char *)arg);
49675+ (char __user *)arg);
49676 case BLKTRACESTART:
49677 return blk_trace_startstop(sdp->device->request_queue, 1);
49678 case BLKTRACESTOP:
49679diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49680index d0b28bb..a263613 100644
49681--- a/drivers/spi/spi.c
49682+++ b/drivers/spi/spi.c
49683@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49684 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49685
49686 /* portable code must never pass more than 32 bytes */
49687-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49688+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49689
49690 static u8 *buf;
49691
49692diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49693index 2c61783..4d49e4e 100644
49694--- a/drivers/staging/android/timed_output.c
49695+++ b/drivers/staging/android/timed_output.c
49696@@ -25,7 +25,7 @@
49697 #include "timed_output.h"
49698
49699 static struct class *timed_output_class;
49700-static atomic_t device_count;
49701+static atomic_unchecked_t device_count;
49702
49703 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49704 char *buf)
49705@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49706 timed_output_class = class_create(THIS_MODULE, "timed_output");
49707 if (IS_ERR(timed_output_class))
49708 return PTR_ERR(timed_output_class);
49709- atomic_set(&device_count, 0);
49710+ atomic_set_unchecked(&device_count, 0);
49711 timed_output_class->dev_groups = timed_output_groups;
49712 }
49713
49714@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49715 if (ret < 0)
49716 return ret;
49717
49718- tdev->index = atomic_inc_return(&device_count);
49719+ tdev->index = atomic_inc_return_unchecked(&device_count);
49720 tdev->dev = device_create(timed_output_class, NULL,
49721 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49722 if (IS_ERR(tdev->dev))
49723diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49724index fe47cd3..19a1bd1 100644
49725--- a/drivers/staging/gdm724x/gdm_tty.c
49726+++ b/drivers/staging/gdm724x/gdm_tty.c
49727@@ -44,7 +44,7 @@
49728 #define gdm_tty_send_control(n, r, v, d, l) (\
49729 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49730
49731-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49732+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49733
49734 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49735 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49736diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49737index 236ed66..dd9cd74 100644
49738--- a/drivers/staging/imx-drm/imx-drm-core.c
49739+++ b/drivers/staging/imx-drm/imx-drm-core.c
49740@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49741 goto err_busy;
49742 }
49743
49744- if (imxdrm->drm->open_count) {
49745+ if (local_read(&imxdrm->drm->open_count)) {
49746 ret = -EBUSY;
49747 goto err_busy;
49748 }
49749@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49750
49751 mutex_lock(&imxdrm->mutex);
49752
49753- if (imxdrm->drm->open_count) {
49754+ if (local_read(&imxdrm->drm->open_count)) {
49755 ret = -EBUSY;
49756 goto err_busy;
49757 }
49758@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49759
49760 mutex_lock(&imxdrm->mutex);
49761
49762- if (imxdrm->drm->open_count) {
49763+ if (local_read(&imxdrm->drm->open_count)) {
49764 ret = -EBUSY;
49765 goto err_busy;
49766 }
49767diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49768index 3f8020c..649fded 100644
49769--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49770+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49771@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49772 return 0;
49773 }
49774
49775-sfw_test_client_ops_t brw_test_client;
49776-void brw_init_test_client(void)
49777-{
49778- brw_test_client.tso_init = brw_client_init;
49779- brw_test_client.tso_fini = brw_client_fini;
49780- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49781- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49782+sfw_test_client_ops_t brw_test_client = {
49783+ .tso_init = brw_client_init,
49784+ .tso_fini = brw_client_fini,
49785+ .tso_prep_rpc = brw_client_prep_rpc,
49786+ .tso_done_rpc = brw_client_done_rpc,
49787 };
49788
49789 srpc_service_t brw_test_service;
49790diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49791index 050723a..fa6fdf1 100644
49792--- a/drivers/staging/lustre/lnet/selftest/framework.c
49793+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49794@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49795
49796 extern sfw_test_client_ops_t ping_test_client;
49797 extern srpc_service_t ping_test_service;
49798-extern void ping_init_test_client(void);
49799 extern void ping_init_test_service(void);
49800
49801 extern sfw_test_client_ops_t brw_test_client;
49802 extern srpc_service_t brw_test_service;
49803-extern void brw_init_test_client(void);
49804 extern void brw_init_test_service(void);
49805
49806
49807@@ -1684,12 +1682,10 @@ sfw_startup (void)
49808 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49809 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49810
49811- brw_init_test_client();
49812 brw_init_test_service();
49813 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49814 LASSERT (rc == 0);
49815
49816- ping_init_test_client();
49817 ping_init_test_service();
49818 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49819 LASSERT (rc == 0);
49820diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49821index 750cac4..e4d751f 100644
49822--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49823+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49824@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49825 return 0;
49826 }
49827
49828-sfw_test_client_ops_t ping_test_client;
49829-void ping_init_test_client(void)
49830-{
49831- ping_test_client.tso_init = ping_client_init;
49832- ping_test_client.tso_fini = ping_client_fini;
49833- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49834- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49835-}
49836+sfw_test_client_ops_t ping_test_client = {
49837+ .tso_init = ping_client_init,
49838+ .tso_fini = ping_client_fini,
49839+ .tso_prep_rpc = ping_client_prep_rpc,
49840+ .tso_done_rpc = ping_client_done_rpc,
49841+};
49842
49843 srpc_service_t ping_test_service;
49844 void ping_init_test_service(void)
49845diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49846index ec4bb5e..740c6dd 100644
49847--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49848+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49849@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49850 ldlm_completion_callback lcs_completion;
49851 ldlm_blocking_callback lcs_blocking;
49852 ldlm_glimpse_callback lcs_glimpse;
49853-};
49854+} __no_const;
49855
49856 /* ldlm_lockd.c */
49857 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49858diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49859index c3470ce..2bef527 100644
49860--- a/drivers/staging/lustre/lustre/include/obd.h
49861+++ b/drivers/staging/lustre/lustre/include/obd.h
49862@@ -1426,7 +1426,7 @@ struct md_ops {
49863 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49864 * wrapper function in include/linux/obd_class.h.
49865 */
49866-};
49867+} __no_const;
49868
49869 struct lsm_operations {
49870 void (*lsm_free)(struct lov_stripe_md *);
49871diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49872index c9aae13..60ea292 100644
49873--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49874+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49875@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49876 int added = (mode == LCK_NL);
49877 int overlaps = 0;
49878 int splitted = 0;
49879- const struct ldlm_callback_suite null_cbs = { NULL };
49880+ const struct ldlm_callback_suite null_cbs = { };
49881
49882 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49883 LPU64" end "LPU64"\n", *flags,
49884diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49885index e947b91..f408990 100644
49886--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49887+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49888@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49889 int LL_PROC_PROTO(proc_console_max_delay_cs)
49890 {
49891 int rc, max_delay_cs;
49892- ctl_table_t dummy = *table;
49893+ ctl_table_no_const dummy = *table;
49894 cfs_duration_t d;
49895
49896 dummy.data = &max_delay_cs;
49897@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49898 int LL_PROC_PROTO(proc_console_min_delay_cs)
49899 {
49900 int rc, min_delay_cs;
49901- ctl_table_t dummy = *table;
49902+ ctl_table_no_const dummy = *table;
49903 cfs_duration_t d;
49904
49905 dummy.data = &min_delay_cs;
49906@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49907 int LL_PROC_PROTO(proc_console_backoff)
49908 {
49909 int rc, backoff;
49910- ctl_table_t dummy = *table;
49911+ ctl_table_no_const dummy = *table;
49912
49913 dummy.data = &backoff;
49914 dummy.proc_handler = &proc_dointvec;
49915diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49916index 24ae26d..9d09cab 100644
49917--- a/drivers/staging/lustre/lustre/libcfs/module.c
49918+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49919@@ -313,11 +313,11 @@ out:
49920
49921
49922 struct cfs_psdev_ops libcfs_psdev_ops = {
49923- libcfs_psdev_open,
49924- libcfs_psdev_release,
49925- NULL,
49926- NULL,
49927- libcfs_ioctl
49928+ .p_open = libcfs_psdev_open,
49929+ .p_close = libcfs_psdev_release,
49930+ .p_read = NULL,
49931+ .p_write = NULL,
49932+ .p_ioctl = libcfs_ioctl
49933 };
49934
49935 extern int insert_proc(void);
49936diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49937index 52b7731..d604da0 100644
49938--- a/drivers/staging/lustre/lustre/llite/dir.c
49939+++ b/drivers/staging/lustre/lustre/llite/dir.c
49940@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49941 int mode;
49942 int err;
49943
49944- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49945+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49946 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49947 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49948 lump);
49949diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49950index 480b7c4..6846324 100644
49951--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49952+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49953@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49954
49955 static int solo_sysfs_init(struct solo_dev *solo_dev)
49956 {
49957- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49958+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49959 struct device *dev = &solo_dev->dev;
49960 const char *driver;
49961 int i;
49962diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49963index 1db18c7..35e6afc 100644
49964--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49965+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49966@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49967
49968 int solo_g723_init(struct solo_dev *solo_dev)
49969 {
49970- static struct snd_device_ops ops = { NULL };
49971+ static struct snd_device_ops ops = { };
49972 struct snd_card *card;
49973 struct snd_kcontrol_new kctl;
49974 char name[32];
49975diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49976index 7f2f247..d999137 100644
49977--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49978+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49979@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49980
49981 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49982 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49983- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49984+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49985 if (p2m_id < 0)
49986 p2m_id = -p2m_id;
49987 }
49988diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49989index 8964f8b..36eb087 100644
49990--- a/drivers/staging/media/solo6x10/solo6x10.h
49991+++ b/drivers/staging/media/solo6x10/solo6x10.h
49992@@ -237,7 +237,7 @@ struct solo_dev {
49993
49994 /* P2M DMA Engine */
49995 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49996- atomic_t p2m_count;
49997+ atomic_unchecked_t p2m_count;
49998 int p2m_jiffies;
49999 unsigned int p2m_timeouts;
50000
50001diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50002index a0f4868..139f1fb 100644
50003--- a/drivers/staging/octeon/ethernet-rx.c
50004+++ b/drivers/staging/octeon/ethernet-rx.c
50005@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50006 /* Increment RX stats for virtual ports */
50007 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50008 #ifdef CONFIG_64BIT
50009- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50010- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50011+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50012+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50013 #else
50014- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50015- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50016+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50017+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50018 #endif
50019 }
50020 netif_receive_skb(skb);
50021@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50022 dev->name);
50023 */
50024 #ifdef CONFIG_64BIT
50025- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50026+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50027 #else
50028- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50029+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50030 #endif
50031 dev_kfree_skb_irq(skb);
50032 }
50033diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50034index 089dc4b..c9a687e 100644
50035--- a/drivers/staging/octeon/ethernet.c
50036+++ b/drivers/staging/octeon/ethernet.c
50037@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50038 * since the RX tasklet also increments it.
50039 */
50040 #ifdef CONFIG_64BIT
50041- atomic64_add(rx_status.dropped_packets,
50042- (atomic64_t *)&priv->stats.rx_dropped);
50043+ atomic64_add_unchecked(rx_status.dropped_packets,
50044+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50045 #else
50046- atomic_add(rx_status.dropped_packets,
50047- (atomic_t *)&priv->stats.rx_dropped);
50048+ atomic_add_unchecked(rx_status.dropped_packets,
50049+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50050 #endif
50051 }
50052
50053diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50054index c274b34..f84de76 100644
50055--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50056+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50057@@ -271,7 +271,7 @@ struct hal_ops {
50058 s32 (*c2h_handler)(struct adapter *padapter,
50059 struct c2h_evt_hdr *c2h_evt);
50060 c2h_id_filter c2h_id_filter_ccx;
50061-};
50062+} __no_const;
50063
50064 enum rt_eeprom_type {
50065 EEPROM_93C46,
50066diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50067index 3d1dfcc..ff5620a 100644
50068--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50069+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50070@@ -126,7 +126,7 @@ struct _io_ops {
50071 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50072 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50073 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50074-};
50075+} __no_const;
50076
50077 struct io_req {
50078 struct list_head list;
50079diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50080index dc23395..cf7e9b1 100644
50081--- a/drivers/staging/rtl8712/rtl871x_io.h
50082+++ b/drivers/staging/rtl8712/rtl871x_io.h
50083@@ -108,7 +108,7 @@ struct _io_ops {
50084 u8 *pmem);
50085 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50086 u8 *pmem);
50087-};
50088+} __no_const;
50089
50090 struct io_req {
50091 struct list_head list;
50092diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50093index 1f5088b..0e59820 100644
50094--- a/drivers/staging/sbe-2t3e3/netdev.c
50095+++ b/drivers/staging/sbe-2t3e3/netdev.c
50096@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50097 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50098
50099 if (rlen)
50100- if (copy_to_user(data, &resp, rlen))
50101+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50102 return -EFAULT;
50103
50104 return 0;
50105diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50106index a863a98..d272795 100644
50107--- a/drivers/staging/usbip/vhci.h
50108+++ b/drivers/staging/usbip/vhci.h
50109@@ -83,7 +83,7 @@ struct vhci_hcd {
50110 unsigned resuming:1;
50111 unsigned long re_timeout;
50112
50113- atomic_t seqnum;
50114+ atomic_unchecked_t seqnum;
50115
50116 /*
50117 * NOTE:
50118diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50119index 72391ef..7c6717a 100644
50120--- a/drivers/staging/usbip/vhci_hcd.c
50121+++ b/drivers/staging/usbip/vhci_hcd.c
50122@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50123
50124 spin_lock(&vdev->priv_lock);
50125
50126- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50127+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50128 if (priv->seqnum == 0xffff)
50129 dev_info(&urb->dev->dev, "seqnum max\n");
50130
50131@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50132 return -ENOMEM;
50133 }
50134
50135- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50136+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50137 if (unlink->seqnum == 0xffff)
50138 pr_info("seqnum max\n");
50139
50140@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50141 vdev->rhport = rhport;
50142 }
50143
50144- atomic_set(&vhci->seqnum, 0);
50145+ atomic_set_unchecked(&vhci->seqnum, 0);
50146 spin_lock_init(&vhci->lock);
50147
50148 hcd->power_budget = 0; /* no limit */
50149diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50150index d07fcb5..358e1e1 100644
50151--- a/drivers/staging/usbip/vhci_rx.c
50152+++ b/drivers/staging/usbip/vhci_rx.c
50153@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50154 if (!urb) {
50155 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50156 pr_info("max seqnum %d\n",
50157- atomic_read(&the_controller->seqnum));
50158+ atomic_read_unchecked(&the_controller->seqnum));
50159 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50160 return;
50161 }
50162diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50163index 6eecd53..29317c6 100644
50164--- a/drivers/staging/vt6655/hostap.c
50165+++ b/drivers/staging/vt6655/hostap.c
50166@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50167 *
50168 */
50169
50170+static net_device_ops_no_const apdev_netdev_ops;
50171+
50172 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50173 {
50174 PSDevice apdev_priv;
50175 struct net_device *dev = pDevice->dev;
50176 int ret;
50177- const struct net_device_ops apdev_netdev_ops = {
50178- .ndo_start_xmit = pDevice->tx_80211,
50179- };
50180
50181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50182
50183@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50184 *apdev_priv = *pDevice;
50185 eth_hw_addr_inherit(pDevice->apdev, dev);
50186
50187+ /* only half broken now */
50188+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50189 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50190
50191 pDevice->apdev->type = ARPHRD_IEEE80211;
50192diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50193index 67ba48b..24e602f 100644
50194--- a/drivers/staging/vt6656/hostap.c
50195+++ b/drivers/staging/vt6656/hostap.c
50196@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50197 *
50198 */
50199
50200+static net_device_ops_no_const apdev_netdev_ops;
50201+
50202 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50203 {
50204 struct vnt_private *apdev_priv;
50205 struct net_device *dev = pDevice->dev;
50206 int ret;
50207- const struct net_device_ops apdev_netdev_ops = {
50208- .ndo_start_xmit = pDevice->tx_80211,
50209- };
50210
50211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50212
50213@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50214 *apdev_priv = *pDevice;
50215 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50216
50217+ /* only half broken now */
50218+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50219 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50220
50221 pDevice->apdev->type = ARPHRD_IEEE80211;
50222diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50223index 24884ca..26c8220 100644
50224--- a/drivers/target/sbp/sbp_target.c
50225+++ b/drivers/target/sbp/sbp_target.c
50226@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50227
50228 #define SESSION_MAINTENANCE_INTERVAL HZ
50229
50230-static atomic_t login_id = ATOMIC_INIT(0);
50231+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50232
50233 static void session_maintenance_work(struct work_struct *);
50234 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50235@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50236 login->lun = se_lun;
50237 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50238 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50239- login->login_id = atomic_inc_return(&login_id);
50240+ login->login_id = atomic_inc_return_unchecked(&login_id);
50241
50242 login->tgt_agt = sbp_target_agent_register(login);
50243 if (IS_ERR(login->tgt_agt)) {
50244diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50245index 65001e1..2ebfbb9 100644
50246--- a/drivers/target/target_core_device.c
50247+++ b/drivers/target/target_core_device.c
50248@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50249 spin_lock_init(&dev->se_tmr_lock);
50250 spin_lock_init(&dev->qf_cmd_lock);
50251 sema_init(&dev->caw_sem, 1);
50252- atomic_set(&dev->dev_ordered_id, 0);
50253+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50254 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50255 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50256 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50257diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50258index 2956250..b10f722 100644
50259--- a/drivers/target/target_core_transport.c
50260+++ b/drivers/target/target_core_transport.c
50261@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50262 * Used to determine when ORDERED commands should go from
50263 * Dormant to Active status.
50264 */
50265- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50266+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50267 smp_mb__after_atomic_inc();
50268 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50269 cmd->se_ordered_id, cmd->sam_task_attr,
50270diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50271index 04b1be7..5eff86d 100644
50272--- a/drivers/thermal/of-thermal.c
50273+++ b/drivers/thermal/of-thermal.c
50274@@ -30,6 +30,7 @@
50275 #include <linux/err.h>
50276 #include <linux/export.h>
50277 #include <linux/string.h>
50278+#include <linux/mm.h>
50279
50280 #include "thermal_core.h"
50281
50282@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50283 tz->get_trend = get_trend;
50284 tz->sensor_data = data;
50285
50286- tzd->ops->get_temp = of_thermal_get_temp;
50287- tzd->ops->get_trend = of_thermal_get_trend;
50288+ pax_open_kernel();
50289+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50290+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50291+ pax_close_kernel();
50292 mutex_unlock(&tzd->lock);
50293
50294 return tzd;
50295@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50296 return;
50297
50298 mutex_lock(&tzd->lock);
50299- tzd->ops->get_temp = NULL;
50300- tzd->ops->get_trend = NULL;
50301+ pax_open_kernel();
50302+ *(void **)&tzd->ops->get_temp = NULL;
50303+ *(void **)&tzd->ops->get_trend = NULL;
50304+ pax_close_kernel();
50305
50306 tz->get_temp = NULL;
50307 tz->get_trend = NULL;
50308diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50309index a57bb5a..1f727d33 100644
50310--- a/drivers/tty/cyclades.c
50311+++ b/drivers/tty/cyclades.c
50312@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50313 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50314 info->port.count);
50315 #endif
50316- info->port.count++;
50317+ atomic_inc(&info->port.count);
50318 #ifdef CY_DEBUG_COUNT
50319 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50320- current->pid, info->port.count);
50321+ current->pid, atomic_read(&info->port.count));
50322 #endif
50323
50324 /*
50325@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50326 for (j = 0; j < cy_card[i].nports; j++) {
50327 info = &cy_card[i].ports[j];
50328
50329- if (info->port.count) {
50330+ if (atomic_read(&info->port.count)) {
50331 /* XXX is the ldisc num worth this? */
50332 struct tty_struct *tty;
50333 struct tty_ldisc *ld;
50334diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50335index 94f9e3a..4c8afa8 100644
50336--- a/drivers/tty/hvc/hvc_console.c
50337+++ b/drivers/tty/hvc/hvc_console.c
50338@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50339
50340 spin_lock_irqsave(&hp->port.lock, flags);
50341 /* Check and then increment for fast path open. */
50342- if (hp->port.count++ > 0) {
50343+ if (atomic_inc_return(&hp->port.count) > 1) {
50344 spin_unlock_irqrestore(&hp->port.lock, flags);
50345 hvc_kick();
50346 return 0;
50347@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50348
50349 spin_lock_irqsave(&hp->port.lock, flags);
50350
50351- if (--hp->port.count == 0) {
50352+ if (atomic_dec_return(&hp->port.count) == 0) {
50353 spin_unlock_irqrestore(&hp->port.lock, flags);
50354 /* We are done with the tty pointer now. */
50355 tty_port_tty_set(&hp->port, NULL);
50356@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50357 */
50358 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50359 } else {
50360- if (hp->port.count < 0)
50361+ if (atomic_read(&hp->port.count) < 0)
50362 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50363- hp->vtermno, hp->port.count);
50364+ hp->vtermno, atomic_read(&hp->port.count));
50365 spin_unlock_irqrestore(&hp->port.lock, flags);
50366 }
50367 }
50368@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50369 * open->hangup case this can be called after the final close so prevent
50370 * that from happening for now.
50371 */
50372- if (hp->port.count <= 0) {
50373+ if (atomic_read(&hp->port.count) <= 0) {
50374 spin_unlock_irqrestore(&hp->port.lock, flags);
50375 return;
50376 }
50377
50378- hp->port.count = 0;
50379+ atomic_set(&hp->port.count, 0);
50380 spin_unlock_irqrestore(&hp->port.lock, flags);
50381 tty_port_tty_set(&hp->port, NULL);
50382
50383@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50384 return -EPIPE;
50385
50386 /* FIXME what's this (unprotected) check for? */
50387- if (hp->port.count <= 0)
50388+ if (atomic_read(&hp->port.count) <= 0)
50389 return -EIO;
50390
50391 spin_lock_irqsave(&hp->lock, flags);
50392diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50393index 81e939e..95ead10 100644
50394--- a/drivers/tty/hvc/hvcs.c
50395+++ b/drivers/tty/hvc/hvcs.c
50396@@ -83,6 +83,7 @@
50397 #include <asm/hvcserver.h>
50398 #include <asm/uaccess.h>
50399 #include <asm/vio.h>
50400+#include <asm/local.h>
50401
50402 /*
50403 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50404@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50405
50406 spin_lock_irqsave(&hvcsd->lock, flags);
50407
50408- if (hvcsd->port.count > 0) {
50409+ if (atomic_read(&hvcsd->port.count) > 0) {
50410 spin_unlock_irqrestore(&hvcsd->lock, flags);
50411 printk(KERN_INFO "HVCS: vterm state unchanged. "
50412 "The hvcs device node is still in use.\n");
50413@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50414 }
50415 }
50416
50417- hvcsd->port.count = 0;
50418+ atomic_set(&hvcsd->port.count, 0);
50419 hvcsd->port.tty = tty;
50420 tty->driver_data = hvcsd;
50421
50422@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50423 unsigned long flags;
50424
50425 spin_lock_irqsave(&hvcsd->lock, flags);
50426- hvcsd->port.count++;
50427+ atomic_inc(&hvcsd->port.count);
50428 hvcsd->todo_mask |= HVCS_SCHED_READ;
50429 spin_unlock_irqrestore(&hvcsd->lock, flags);
50430
50431@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50432 hvcsd = tty->driver_data;
50433
50434 spin_lock_irqsave(&hvcsd->lock, flags);
50435- if (--hvcsd->port.count == 0) {
50436+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50437
50438 vio_disable_interrupts(hvcsd->vdev);
50439
50440@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50441
50442 free_irq(irq, hvcsd);
50443 return;
50444- } else if (hvcsd->port.count < 0) {
50445+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50446 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50447 " is missmanaged.\n",
50448- hvcsd->vdev->unit_address, hvcsd->port.count);
50449+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50450 }
50451
50452 spin_unlock_irqrestore(&hvcsd->lock, flags);
50453@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50454
50455 spin_lock_irqsave(&hvcsd->lock, flags);
50456 /* Preserve this so that we know how many kref refs to put */
50457- temp_open_count = hvcsd->port.count;
50458+ temp_open_count = atomic_read(&hvcsd->port.count);
50459
50460 /*
50461 * Don't kref put inside the spinlock because the destruction
50462@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50463 tty->driver_data = NULL;
50464 hvcsd->port.tty = NULL;
50465
50466- hvcsd->port.count = 0;
50467+ atomic_set(&hvcsd->port.count, 0);
50468
50469 /* This will drop any buffered data on the floor which is OK in a hangup
50470 * scenario. */
50471@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50472 * the middle of a write operation? This is a crummy place to do this
50473 * but we want to keep it all in the spinlock.
50474 */
50475- if (hvcsd->port.count <= 0) {
50476+ if (atomic_read(&hvcsd->port.count) <= 0) {
50477 spin_unlock_irqrestore(&hvcsd->lock, flags);
50478 return -ENODEV;
50479 }
50480@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50481 {
50482 struct hvcs_struct *hvcsd = tty->driver_data;
50483
50484- if (!hvcsd || hvcsd->port.count <= 0)
50485+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50486 return 0;
50487
50488 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50489diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50490index 4190199..06d5bfa 100644
50491--- a/drivers/tty/hvc/hvsi.c
50492+++ b/drivers/tty/hvc/hvsi.c
50493@@ -85,7 +85,7 @@ struct hvsi_struct {
50494 int n_outbuf;
50495 uint32_t vtermno;
50496 uint32_t virq;
50497- atomic_t seqno; /* HVSI packet sequence number */
50498+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50499 uint16_t mctrl;
50500 uint8_t state; /* HVSI protocol state */
50501 uint8_t flags;
50502@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50503
50504 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50505 packet.hdr.len = sizeof(struct hvsi_query_response);
50506- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50507+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50508 packet.verb = VSV_SEND_VERSION_NUMBER;
50509 packet.u.version = HVSI_VERSION;
50510 packet.query_seqno = query_seqno+1;
50511@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50512
50513 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50514 packet.hdr.len = sizeof(struct hvsi_query);
50515- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50516+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50517 packet.verb = verb;
50518
50519 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50520@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50521 int wrote;
50522
50523 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50524- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50525+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50526 packet.hdr.len = sizeof(struct hvsi_control);
50527 packet.verb = VSV_SET_MODEM_CTL;
50528 packet.mask = HVSI_TSDTR;
50529@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50530 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50531
50532 packet.hdr.type = VS_DATA_PACKET_HEADER;
50533- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50534+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50535 packet.hdr.len = count + sizeof(struct hvsi_header);
50536 memcpy(&packet.data, buf, count);
50537
50538@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50539 struct hvsi_control packet __ALIGNED__;
50540
50541 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50542- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50543+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50544 packet.hdr.len = 6;
50545 packet.verb = VSV_CLOSE_PROTOCOL;
50546
50547@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50548
50549 tty_port_tty_set(&hp->port, tty);
50550 spin_lock_irqsave(&hp->lock, flags);
50551- hp->port.count++;
50552+ atomic_inc(&hp->port.count);
50553 atomic_set(&hp->seqno, 0);
50554 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50555 spin_unlock_irqrestore(&hp->lock, flags);
50556@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50557
50558 spin_lock_irqsave(&hp->lock, flags);
50559
50560- if (--hp->port.count == 0) {
50561+ if (atomic_dec_return(&hp->port.count) == 0) {
50562 tty_port_tty_set(&hp->port, NULL);
50563 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50564
50565@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50566
50567 spin_lock_irqsave(&hp->lock, flags);
50568 }
50569- } else if (hp->port.count < 0)
50570+ } else if (atomic_read(&hp->port.count) < 0)
50571 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50572- hp - hvsi_ports, hp->port.count);
50573+ hp - hvsi_ports, atomic_read(&hp->port.count));
50574
50575 spin_unlock_irqrestore(&hp->lock, flags);
50576 }
50577@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50578 tty_port_tty_set(&hp->port, NULL);
50579
50580 spin_lock_irqsave(&hp->lock, flags);
50581- hp->port.count = 0;
50582+ atomic_set(&hp->port.count, 0);
50583 hp->n_outbuf = 0;
50584 spin_unlock_irqrestore(&hp->lock, flags);
50585 }
50586diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50587index 7ae6c29..05c6dba 100644
50588--- a/drivers/tty/hvc/hvsi_lib.c
50589+++ b/drivers/tty/hvc/hvsi_lib.c
50590@@ -8,7 +8,7 @@
50591
50592 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50593 {
50594- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50595+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50596
50597 /* Assumes that always succeeds, works in practice */
50598 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50599@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50600
50601 /* Reset state */
50602 pv->established = 0;
50603- atomic_set(&pv->seqno, 0);
50604+ atomic_set_unchecked(&pv->seqno, 0);
50605
50606 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50607
50608diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50609index 17ee3bf..8d2520d 100644
50610--- a/drivers/tty/ipwireless/tty.c
50611+++ b/drivers/tty/ipwireless/tty.c
50612@@ -28,6 +28,7 @@
50613 #include <linux/tty_driver.h>
50614 #include <linux/tty_flip.h>
50615 #include <linux/uaccess.h>
50616+#include <asm/local.h>
50617
50618 #include "tty.h"
50619 #include "network.h"
50620@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50621 mutex_unlock(&tty->ipw_tty_mutex);
50622 return -ENODEV;
50623 }
50624- if (tty->port.count == 0)
50625+ if (atomic_read(&tty->port.count) == 0)
50626 tty->tx_bytes_queued = 0;
50627
50628- tty->port.count++;
50629+ atomic_inc(&tty->port.count);
50630
50631 tty->port.tty = linux_tty;
50632 linux_tty->driver_data = tty;
50633@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50634
50635 static void do_ipw_close(struct ipw_tty *tty)
50636 {
50637- tty->port.count--;
50638-
50639- if (tty->port.count == 0) {
50640+ if (atomic_dec_return(&tty->port.count) == 0) {
50641 struct tty_struct *linux_tty = tty->port.tty;
50642
50643 if (linux_tty != NULL) {
50644@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50645 return;
50646
50647 mutex_lock(&tty->ipw_tty_mutex);
50648- if (tty->port.count == 0) {
50649+ if (atomic_read(&tty->port.count) == 0) {
50650 mutex_unlock(&tty->ipw_tty_mutex);
50651 return;
50652 }
50653@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50654
50655 mutex_lock(&tty->ipw_tty_mutex);
50656
50657- if (!tty->port.count) {
50658+ if (!atomic_read(&tty->port.count)) {
50659 mutex_unlock(&tty->ipw_tty_mutex);
50660 return;
50661 }
50662@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50663 return -ENODEV;
50664
50665 mutex_lock(&tty->ipw_tty_mutex);
50666- if (!tty->port.count) {
50667+ if (!atomic_read(&tty->port.count)) {
50668 mutex_unlock(&tty->ipw_tty_mutex);
50669 return -EINVAL;
50670 }
50671@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50672 if (!tty)
50673 return -ENODEV;
50674
50675- if (!tty->port.count)
50676+ if (!atomic_read(&tty->port.count))
50677 return -EINVAL;
50678
50679 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50680@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50681 if (!tty)
50682 return 0;
50683
50684- if (!tty->port.count)
50685+ if (!atomic_read(&tty->port.count))
50686 return 0;
50687
50688 return tty->tx_bytes_queued;
50689@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50690 if (!tty)
50691 return -ENODEV;
50692
50693- if (!tty->port.count)
50694+ if (!atomic_read(&tty->port.count))
50695 return -EINVAL;
50696
50697 return get_control_lines(tty);
50698@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50699 if (!tty)
50700 return -ENODEV;
50701
50702- if (!tty->port.count)
50703+ if (!atomic_read(&tty->port.count))
50704 return -EINVAL;
50705
50706 return set_control_lines(tty, set, clear);
50707@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50708 if (!tty)
50709 return -ENODEV;
50710
50711- if (!tty->port.count)
50712+ if (!atomic_read(&tty->port.count))
50713 return -EINVAL;
50714
50715 /* FIXME: Exactly how is the tty object locked here .. */
50716@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50717 * are gone */
50718 mutex_lock(&ttyj->ipw_tty_mutex);
50719 }
50720- while (ttyj->port.count)
50721+ while (atomic_read(&ttyj->port.count))
50722 do_ipw_close(ttyj);
50723 ipwireless_disassociate_network_ttys(network,
50724 ttyj->channel_idx);
50725diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50726index 1deaca4..c8582d4 100644
50727--- a/drivers/tty/moxa.c
50728+++ b/drivers/tty/moxa.c
50729@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50730 }
50731
50732 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50733- ch->port.count++;
50734+ atomic_inc(&ch->port.count);
50735 tty->driver_data = ch;
50736 tty_port_tty_set(&ch->port, tty);
50737 mutex_lock(&ch->port.mutex);
50738diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50739index 2ebe47b..3205833 100644
50740--- a/drivers/tty/n_gsm.c
50741+++ b/drivers/tty/n_gsm.c
50742@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50743 spin_lock_init(&dlci->lock);
50744 mutex_init(&dlci->mutex);
50745 dlci->fifo = &dlci->_fifo;
50746- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50747+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50748 kfree(dlci);
50749 return NULL;
50750 }
50751@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50752 struct gsm_dlci *dlci = tty->driver_data;
50753 struct tty_port *port = &dlci->port;
50754
50755- port->count++;
50756+ atomic_inc(&port->count);
50757 tty_port_tty_set(port, tty);
50758
50759 dlci->modem_rx = 0;
50760diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50761index d15624c..bd628c6 100644
50762--- a/drivers/tty/n_tty.c
50763+++ b/drivers/tty/n_tty.c
50764@@ -115,7 +115,7 @@ struct n_tty_data {
50765 int minimum_to_wake;
50766
50767 /* consumer-published */
50768- size_t read_tail;
50769+ size_t read_tail __intentional_overflow(-1);
50770 size_t line_start;
50771
50772 /* protected by output lock */
50773@@ -2356,10 +2356,18 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50774 if (tty->ops->flush_chars)
50775 tty->ops->flush_chars(tty);
50776 } else {
50777+ struct n_tty_data *ldata = tty->disc_data;
50778+ bool lock;
50779+
50780+ lock = L_ECHO(tty) || (ldata->icanon & L_ECHONL(tty));
50781+ if (lock)
50782+ mutex_lock(&ldata->output_lock);
50783 while (nr > 0) {
50784 c = tty->ops->write(tty, b, nr);
50785 if (c < 0) {
50786 retval = c;
50787+ if (lock)
50788+ mutex_unlock(&ldata->output_lock);
50789 goto break_out;
50790 }
50791 if (!c)
50792@@ -2367,6 +2375,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
50793 b += c;
50794 nr -= c;
50795 }
50796+ if (lock)
50797+ mutex_unlock(&ldata->output_lock);
50798 }
50799 if (!nr)
50800 break;
50801@@ -2515,6 +2525,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50802 {
50803 *ops = tty_ldisc_N_TTY;
50804 ops->owner = NULL;
50805- ops->refcount = ops->flags = 0;
50806+ atomic_set(&ops->refcount, 0);
50807+ ops->flags = 0;
50808 }
50809 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50810diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50811index 25c9bc7..24077b7 100644
50812--- a/drivers/tty/pty.c
50813+++ b/drivers/tty/pty.c
50814@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50815 panic("Couldn't register Unix98 pts driver");
50816
50817 /* Now create the /dev/ptmx special device */
50818+ pax_open_kernel();
50819 tty_default_fops(&ptmx_fops);
50820- ptmx_fops.open = ptmx_open;
50821+ *(void **)&ptmx_fops.open = ptmx_open;
50822+ pax_close_kernel();
50823
50824 cdev_init(&ptmx_cdev, &ptmx_fops);
50825 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50826diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50827index 383c4c7..d408e21 100644
50828--- a/drivers/tty/rocket.c
50829+++ b/drivers/tty/rocket.c
50830@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50831 tty->driver_data = info;
50832 tty_port_tty_set(port, tty);
50833
50834- if (port->count++ == 0) {
50835+ if (atomic_inc_return(&port->count) == 1) {
50836 atomic_inc(&rp_num_ports_open);
50837
50838 #ifdef ROCKET_DEBUG_OPEN
50839@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50840 #endif
50841 }
50842 #ifdef ROCKET_DEBUG_OPEN
50843- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50844+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50845 #endif
50846
50847 /*
50848@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50849 spin_unlock_irqrestore(&info->port.lock, flags);
50850 return;
50851 }
50852- if (info->port.count)
50853+ if (atomic_read(&info->port.count))
50854 atomic_dec(&rp_num_ports_open);
50855 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50856 spin_unlock_irqrestore(&info->port.lock, flags);
50857diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50858index 1274499..f541382 100644
50859--- a/drivers/tty/serial/ioc4_serial.c
50860+++ b/drivers/tty/serial/ioc4_serial.c
50861@@ -437,7 +437,7 @@ struct ioc4_soft {
50862 } is_intr_info[MAX_IOC4_INTR_ENTS];
50863
50864 /* Number of entries active in the above array */
50865- atomic_t is_num_intrs;
50866+ atomic_unchecked_t is_num_intrs;
50867 } is_intr_type[IOC4_NUM_INTR_TYPES];
50868
50869 /* is_ir_lock must be held while
50870@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50871 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50872 || (type == IOC4_OTHER_INTR_TYPE)));
50873
50874- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50875+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50876 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50877
50878 /* Save off the lower level interrupt handler */
50879@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50880
50881 soft = arg;
50882 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50883- num_intrs = (int)atomic_read(
50884+ num_intrs = (int)atomic_read_unchecked(
50885 &soft->is_intr_type[intr_type].is_num_intrs);
50886
50887 this_mir = this_ir = pending_intrs(soft, intr_type);
50888diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50889index a260cde..6b2b5ce 100644
50890--- a/drivers/tty/serial/kgdboc.c
50891+++ b/drivers/tty/serial/kgdboc.c
50892@@ -24,8 +24,9 @@
50893 #define MAX_CONFIG_LEN 40
50894
50895 static struct kgdb_io kgdboc_io_ops;
50896+static struct kgdb_io kgdboc_io_ops_console;
50897
50898-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50899+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50900 static int configured = -1;
50901
50902 static char config[MAX_CONFIG_LEN];
50903@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50904 kgdboc_unregister_kbd();
50905 if (configured == 1)
50906 kgdb_unregister_io_module(&kgdboc_io_ops);
50907+ else if (configured == 2)
50908+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50909 }
50910
50911 static int configure_kgdboc(void)
50912@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50913 int err;
50914 char *cptr = config;
50915 struct console *cons;
50916+ int is_console = 0;
50917
50918 err = kgdboc_option_setup(config);
50919 if (err || !strlen(config) || isspace(config[0]))
50920 goto noconfig;
50921
50922 err = -ENODEV;
50923- kgdboc_io_ops.is_console = 0;
50924 kgdb_tty_driver = NULL;
50925
50926 kgdboc_use_kms = 0;
50927@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50928 int idx;
50929 if (cons->device && cons->device(cons, &idx) == p &&
50930 idx == tty_line) {
50931- kgdboc_io_ops.is_console = 1;
50932+ is_console = 1;
50933 break;
50934 }
50935 cons = cons->next;
50936@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50937 kgdb_tty_line = tty_line;
50938
50939 do_register:
50940- err = kgdb_register_io_module(&kgdboc_io_ops);
50941+ if (is_console) {
50942+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50943+ configured = 2;
50944+ } else {
50945+ err = kgdb_register_io_module(&kgdboc_io_ops);
50946+ configured = 1;
50947+ }
50948 if (err)
50949 goto noconfig;
50950
50951@@ -205,8 +214,6 @@ do_register:
50952 if (err)
50953 goto nmi_con_failed;
50954
50955- configured = 1;
50956-
50957 return 0;
50958
50959 nmi_con_failed:
50960@@ -223,7 +230,7 @@ noconfig:
50961 static int __init init_kgdboc(void)
50962 {
50963 /* Already configured? */
50964- if (configured == 1)
50965+ if (configured >= 1)
50966 return 0;
50967
50968 return configure_kgdboc();
50969@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50970 if (config[len - 1] == '\n')
50971 config[len - 1] = '\0';
50972
50973- if (configured == 1)
50974+ if (configured >= 1)
50975 cleanup_kgdboc();
50976
50977 /* Go and configure with the new params. */
50978@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50979 .post_exception = kgdboc_post_exp_handler,
50980 };
50981
50982+static struct kgdb_io kgdboc_io_ops_console = {
50983+ .name = "kgdboc",
50984+ .read_char = kgdboc_get_char,
50985+ .write_char = kgdboc_put_char,
50986+ .pre_exception = kgdboc_pre_exp_handler,
50987+ .post_exception = kgdboc_post_exp_handler,
50988+ .is_console = 1
50989+};
50990+
50991 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50992 /* This is only available if kgdboc is a built in for early debugging */
50993 static int __init kgdboc_early_init(char *opt)
50994diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50995index b5d779c..3622cfe 100644
50996--- a/drivers/tty/serial/msm_serial.c
50997+++ b/drivers/tty/serial/msm_serial.c
50998@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50999 .cons = MSM_CONSOLE,
51000 };
51001
51002-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51003+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51004
51005 static const struct of_device_id msm_uartdm_table[] = {
51006 { .compatible = "qcom,msm-uartdm" },
51007@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51008 int irq;
51009
51010 if (pdev->id == -1)
51011- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51012+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51013
51014 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51015 return -ENXIO;
51016diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51017index 9cd706d..6ff2de7 100644
51018--- a/drivers/tty/serial/samsung.c
51019+++ b/drivers/tty/serial/samsung.c
51020@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51021 }
51022 }
51023
51024+static int s3c64xx_serial_startup(struct uart_port *port);
51025 static int s3c24xx_serial_startup(struct uart_port *port)
51026 {
51027 struct s3c24xx_uart_port *ourport = to_ourport(port);
51028 int ret;
51029
51030+ /* Startup sequence is different for s3c64xx and higher SoC's */
51031+ if (s3c24xx_serial_has_interrupt_mask(port))
51032+ return s3c64xx_serial_startup(port);
51033+
51034 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51035 port->mapbase, port->membase);
51036
51037@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51038 /* setup info for port */
51039 port->dev = &platdev->dev;
51040
51041- /* Startup sequence is different for s3c64xx and higher SoC's */
51042- if (s3c24xx_serial_has_interrupt_mask(port))
51043- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51044-
51045 port->uartclk = 1;
51046
51047 if (cfg->uart_flags & UPF_CONS_FLOW) {
51048diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51049index ece2049..fba2524 100644
51050--- a/drivers/tty/serial/serial_core.c
51051+++ b/drivers/tty/serial/serial_core.c
51052@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51053 uart_flush_buffer(tty);
51054 uart_shutdown(tty, state);
51055 spin_lock_irqsave(&port->lock, flags);
51056- port->count = 0;
51057+ atomic_set(&port->count, 0);
51058 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51059 spin_unlock_irqrestore(&port->lock, flags);
51060 tty_port_tty_set(port, NULL);
51061@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51062 goto end;
51063 }
51064
51065- port->count++;
51066+ atomic_inc(&port->count);
51067 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51068 retval = -ENXIO;
51069 goto err_dec_count;
51070@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51071 /*
51072 * Make sure the device is in D0 state.
51073 */
51074- if (port->count == 1)
51075+ if (atomic_read(&port->count) == 1)
51076 uart_change_pm(state, UART_PM_STATE_ON);
51077
51078 /*
51079@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51080 end:
51081 return retval;
51082 err_dec_count:
51083- port->count--;
51084+ atomic_inc(&port->count);
51085 mutex_unlock(&port->mutex);
51086 goto end;
51087 }
51088diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51089index 5ae14b4..2c1288f 100644
51090--- a/drivers/tty/synclink.c
51091+++ b/drivers/tty/synclink.c
51092@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51093
51094 if (debug_level >= DEBUG_LEVEL_INFO)
51095 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51096- __FILE__,__LINE__, info->device_name, info->port.count);
51097+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51098
51099 if (tty_port_close_start(&info->port, tty, filp) == 0)
51100 goto cleanup;
51101@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51102 cleanup:
51103 if (debug_level >= DEBUG_LEVEL_INFO)
51104 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51105- tty->driver->name, info->port.count);
51106+ tty->driver->name, atomic_read(&info->port.count));
51107
51108 } /* end of mgsl_close() */
51109
51110@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51111
51112 mgsl_flush_buffer(tty);
51113 shutdown(info);
51114-
51115- info->port.count = 0;
51116+
51117+ atomic_set(&info->port.count, 0);
51118 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51119 info->port.tty = NULL;
51120
51121@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51122
51123 if (debug_level >= DEBUG_LEVEL_INFO)
51124 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51125- __FILE__,__LINE__, tty->driver->name, port->count );
51126+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51127
51128 spin_lock_irqsave(&info->irq_spinlock, flags);
51129 if (!tty_hung_up_p(filp)) {
51130 extra_count = true;
51131- port->count--;
51132+ atomic_dec(&port->count);
51133 }
51134 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51135 port->blocked_open++;
51136@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51137
51138 if (debug_level >= DEBUG_LEVEL_INFO)
51139 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51140- __FILE__,__LINE__, tty->driver->name, port->count );
51141+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51142
51143 tty_unlock(tty);
51144 schedule();
51145@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51146
51147 /* FIXME: Racy on hangup during close wait */
51148 if (extra_count)
51149- port->count++;
51150+ atomic_inc(&port->count);
51151 port->blocked_open--;
51152
51153 if (debug_level >= DEBUG_LEVEL_INFO)
51154 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51155- __FILE__,__LINE__, tty->driver->name, port->count );
51156+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51157
51158 if (!retval)
51159 port->flags |= ASYNC_NORMAL_ACTIVE;
51160@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51161
51162 if (debug_level >= DEBUG_LEVEL_INFO)
51163 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51164- __FILE__,__LINE__,tty->driver->name, info->port.count);
51165+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51166
51167 /* If port is closing, signal caller to try again */
51168 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51169@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51170 spin_unlock_irqrestore(&info->netlock, flags);
51171 goto cleanup;
51172 }
51173- info->port.count++;
51174+ atomic_inc(&info->port.count);
51175 spin_unlock_irqrestore(&info->netlock, flags);
51176
51177- if (info->port.count == 1) {
51178+ if (atomic_read(&info->port.count) == 1) {
51179 /* 1st open on this device, init hardware */
51180 retval = startup(info);
51181 if (retval < 0)
51182@@ -3446,8 +3446,8 @@ cleanup:
51183 if (retval) {
51184 if (tty->count == 1)
51185 info->port.tty = NULL; /* tty layer will release tty struct */
51186- if(info->port.count)
51187- info->port.count--;
51188+ if (atomic_read(&info->port.count))
51189+ atomic_dec(&info->port.count);
51190 }
51191
51192 return retval;
51193@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51194 unsigned short new_crctype;
51195
51196 /* return error if TTY interface open */
51197- if (info->port.count)
51198+ if (atomic_read(&info->port.count))
51199 return -EBUSY;
51200
51201 switch (encoding)
51202@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51203
51204 /* arbitrate between network and tty opens */
51205 spin_lock_irqsave(&info->netlock, flags);
51206- if (info->port.count != 0 || info->netcount != 0) {
51207+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51208 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51209 spin_unlock_irqrestore(&info->netlock, flags);
51210 return -EBUSY;
51211@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51212 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51213
51214 /* return error if TTY interface open */
51215- if (info->port.count)
51216+ if (atomic_read(&info->port.count))
51217 return -EBUSY;
51218
51219 if (cmd != SIOCWANDEV)
51220diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51221index c359a91..959fc26 100644
51222--- a/drivers/tty/synclink_gt.c
51223+++ b/drivers/tty/synclink_gt.c
51224@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51225 tty->driver_data = info;
51226 info->port.tty = tty;
51227
51228- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51229+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51230
51231 /* If port is closing, signal caller to try again */
51232 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51233@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51234 mutex_unlock(&info->port.mutex);
51235 goto cleanup;
51236 }
51237- info->port.count++;
51238+ atomic_inc(&info->port.count);
51239 spin_unlock_irqrestore(&info->netlock, flags);
51240
51241- if (info->port.count == 1) {
51242+ if (atomic_read(&info->port.count) == 1) {
51243 /* 1st open on this device, init hardware */
51244 retval = startup(info);
51245 if (retval < 0) {
51246@@ -715,8 +715,8 @@ cleanup:
51247 if (retval) {
51248 if (tty->count == 1)
51249 info->port.tty = NULL; /* tty layer will release tty struct */
51250- if(info->port.count)
51251- info->port.count--;
51252+ if(atomic_read(&info->port.count))
51253+ atomic_dec(&info->port.count);
51254 }
51255
51256 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51257@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51258
51259 if (sanity_check(info, tty->name, "close"))
51260 return;
51261- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51262+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51263
51264 if (tty_port_close_start(&info->port, tty, filp) == 0)
51265 goto cleanup;
51266@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51267 tty_port_close_end(&info->port, tty);
51268 info->port.tty = NULL;
51269 cleanup:
51270- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51271+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51272 }
51273
51274 static void hangup(struct tty_struct *tty)
51275@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51276 shutdown(info);
51277
51278 spin_lock_irqsave(&info->port.lock, flags);
51279- info->port.count = 0;
51280+ atomic_set(&info->port.count, 0);
51281 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51282 info->port.tty = NULL;
51283 spin_unlock_irqrestore(&info->port.lock, flags);
51284@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51285 unsigned short new_crctype;
51286
51287 /* return error if TTY interface open */
51288- if (info->port.count)
51289+ if (atomic_read(&info->port.count))
51290 return -EBUSY;
51291
51292 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51293@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51294
51295 /* arbitrate between network and tty opens */
51296 spin_lock_irqsave(&info->netlock, flags);
51297- if (info->port.count != 0 || info->netcount != 0) {
51298+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51299 DBGINFO(("%s hdlc_open busy\n", dev->name));
51300 spin_unlock_irqrestore(&info->netlock, flags);
51301 return -EBUSY;
51302@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51303 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51304
51305 /* return error if TTY interface open */
51306- if (info->port.count)
51307+ if (atomic_read(&info->port.count))
51308 return -EBUSY;
51309
51310 if (cmd != SIOCWANDEV)
51311@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51312 if (port == NULL)
51313 continue;
51314 spin_lock(&port->lock);
51315- if ((port->port.count || port->netcount) &&
51316+ if ((atomic_read(&port->port.count) || port->netcount) &&
51317 port->pending_bh && !port->bh_running &&
51318 !port->bh_requested) {
51319 DBGISR(("%s bh queued\n", port->device_name));
51320@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51321 spin_lock_irqsave(&info->lock, flags);
51322 if (!tty_hung_up_p(filp)) {
51323 extra_count = true;
51324- port->count--;
51325+ atomic_dec(&port->count);
51326 }
51327 spin_unlock_irqrestore(&info->lock, flags);
51328 port->blocked_open++;
51329@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51330 remove_wait_queue(&port->open_wait, &wait);
51331
51332 if (extra_count)
51333- port->count++;
51334+ atomic_inc(&port->count);
51335 port->blocked_open--;
51336
51337 if (!retval)
51338diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51339index 144202e..4ccb07d 100644
51340--- a/drivers/tty/synclinkmp.c
51341+++ b/drivers/tty/synclinkmp.c
51342@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51343
51344 if (debug_level >= DEBUG_LEVEL_INFO)
51345 printk("%s(%d):%s open(), old ref count = %d\n",
51346- __FILE__,__LINE__,tty->driver->name, info->port.count);
51347+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51348
51349 /* If port is closing, signal caller to try again */
51350 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51351@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51352 spin_unlock_irqrestore(&info->netlock, flags);
51353 goto cleanup;
51354 }
51355- info->port.count++;
51356+ atomic_inc(&info->port.count);
51357 spin_unlock_irqrestore(&info->netlock, flags);
51358
51359- if (info->port.count == 1) {
51360+ if (atomic_read(&info->port.count) == 1) {
51361 /* 1st open on this device, init hardware */
51362 retval = startup(info);
51363 if (retval < 0)
51364@@ -796,8 +796,8 @@ cleanup:
51365 if (retval) {
51366 if (tty->count == 1)
51367 info->port.tty = NULL; /* tty layer will release tty struct */
51368- if(info->port.count)
51369- info->port.count--;
51370+ if(atomic_read(&info->port.count))
51371+ atomic_dec(&info->port.count);
51372 }
51373
51374 return retval;
51375@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51376
51377 if (debug_level >= DEBUG_LEVEL_INFO)
51378 printk("%s(%d):%s close() entry, count=%d\n",
51379- __FILE__,__LINE__, info->device_name, info->port.count);
51380+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51381
51382 if (tty_port_close_start(&info->port, tty, filp) == 0)
51383 goto cleanup;
51384@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51385 cleanup:
51386 if (debug_level >= DEBUG_LEVEL_INFO)
51387 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51388- tty->driver->name, info->port.count);
51389+ tty->driver->name, atomic_read(&info->port.count));
51390 }
51391
51392 /* Called by tty_hangup() when a hangup is signaled.
51393@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51394 shutdown(info);
51395
51396 spin_lock_irqsave(&info->port.lock, flags);
51397- info->port.count = 0;
51398+ atomic_set(&info->port.count, 0);
51399 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51400 info->port.tty = NULL;
51401 spin_unlock_irqrestore(&info->port.lock, flags);
51402@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51403 unsigned short new_crctype;
51404
51405 /* return error if TTY interface open */
51406- if (info->port.count)
51407+ if (atomic_read(&info->port.count))
51408 return -EBUSY;
51409
51410 switch (encoding)
51411@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51412
51413 /* arbitrate between network and tty opens */
51414 spin_lock_irqsave(&info->netlock, flags);
51415- if (info->port.count != 0 || info->netcount != 0) {
51416+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51417 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51418 spin_unlock_irqrestore(&info->netlock, flags);
51419 return -EBUSY;
51420@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51421 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51422
51423 /* return error if TTY interface open */
51424- if (info->port.count)
51425+ if (atomic_read(&info->port.count))
51426 return -EBUSY;
51427
51428 if (cmd != SIOCWANDEV)
51429@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51430 * do not request bottom half processing if the
51431 * device is not open in a normal mode.
51432 */
51433- if ( port && (port->port.count || port->netcount) &&
51434+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51435 port->pending_bh && !port->bh_running &&
51436 !port->bh_requested ) {
51437 if ( debug_level >= DEBUG_LEVEL_ISR )
51438@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51439
51440 if (debug_level >= DEBUG_LEVEL_INFO)
51441 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51442- __FILE__,__LINE__, tty->driver->name, port->count );
51443+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51444
51445 spin_lock_irqsave(&info->lock, flags);
51446 if (!tty_hung_up_p(filp)) {
51447 extra_count = true;
51448- port->count--;
51449+ atomic_dec(&port->count);
51450 }
51451 spin_unlock_irqrestore(&info->lock, flags);
51452 port->blocked_open++;
51453@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51454
51455 if (debug_level >= DEBUG_LEVEL_INFO)
51456 printk("%s(%d):%s block_til_ready() count=%d\n",
51457- __FILE__,__LINE__, tty->driver->name, port->count );
51458+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51459
51460 tty_unlock(tty);
51461 schedule();
51462@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51463 remove_wait_queue(&port->open_wait, &wait);
51464
51465 if (extra_count)
51466- port->count++;
51467+ atomic_inc(&port->count);
51468 port->blocked_open--;
51469
51470 if (debug_level >= DEBUG_LEVEL_INFO)
51471 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51472- __FILE__,__LINE__, tty->driver->name, port->count );
51473+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51474
51475 if (!retval)
51476 port->flags |= ASYNC_NORMAL_ACTIVE;
51477diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51478index ce396ec..04a37be 100644
51479--- a/drivers/tty/sysrq.c
51480+++ b/drivers/tty/sysrq.c
51481@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51482 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51483 size_t count, loff_t *ppos)
51484 {
51485- if (count) {
51486+ if (count && capable(CAP_SYS_ADMIN)) {
51487 char c;
51488
51489 if (get_user(c, buf))
51490diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51491index d3448a9..28e8db0 100644
51492--- a/drivers/tty/tty_io.c
51493+++ b/drivers/tty/tty_io.c
51494@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51495
51496 void tty_default_fops(struct file_operations *fops)
51497 {
51498- *fops = tty_fops;
51499+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51500 }
51501
51502 /*
51503diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51504index 2d822aa..a566234 100644
51505--- a/drivers/tty/tty_ldisc.c
51506+++ b/drivers/tty/tty_ldisc.c
51507@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51508 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51509 tty_ldiscs[disc] = new_ldisc;
51510 new_ldisc->num = disc;
51511- new_ldisc->refcount = 0;
51512+ atomic_set(&new_ldisc->refcount, 0);
51513 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51514
51515 return ret;
51516@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51517 return -EINVAL;
51518
51519 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51520- if (tty_ldiscs[disc]->refcount)
51521+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51522 ret = -EBUSY;
51523 else
51524 tty_ldiscs[disc] = NULL;
51525@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51526 if (ldops) {
51527 ret = ERR_PTR(-EAGAIN);
51528 if (try_module_get(ldops->owner)) {
51529- ldops->refcount++;
51530+ atomic_inc(&ldops->refcount);
51531 ret = ldops;
51532 }
51533 }
51534@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51535 unsigned long flags;
51536
51537 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51538- ldops->refcount--;
51539+ atomic_dec(&ldops->refcount);
51540 module_put(ldops->owner);
51541 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51542 }
51543diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51544index 3f746c8..2f2fcaa 100644
51545--- a/drivers/tty/tty_port.c
51546+++ b/drivers/tty/tty_port.c
51547@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51548 unsigned long flags;
51549
51550 spin_lock_irqsave(&port->lock, flags);
51551- port->count = 0;
51552+ atomic_set(&port->count, 0);
51553 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51554 tty = port->tty;
51555 if (tty)
51556@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51557 /* The port lock protects the port counts */
51558 spin_lock_irqsave(&port->lock, flags);
51559 if (!tty_hung_up_p(filp))
51560- port->count--;
51561+ atomic_dec(&port->count);
51562 port->blocked_open++;
51563 spin_unlock_irqrestore(&port->lock, flags);
51564
51565@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51566 we must not mess that up further */
51567 spin_lock_irqsave(&port->lock, flags);
51568 if (!tty_hung_up_p(filp))
51569- port->count++;
51570+ atomic_inc(&port->count);
51571 port->blocked_open--;
51572 if (retval == 0)
51573 port->flags |= ASYNC_NORMAL_ACTIVE;
51574@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51575 return 0;
51576 }
51577
51578- if (tty->count == 1 && port->count != 1) {
51579+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51580 printk(KERN_WARNING
51581 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51582- port->count);
51583- port->count = 1;
51584+ atomic_read(&port->count));
51585+ atomic_set(&port->count, 1);
51586 }
51587- if (--port->count < 0) {
51588+ if (atomic_dec_return(&port->count) < 0) {
51589 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51590- port->count);
51591- port->count = 0;
51592+ atomic_read(&port->count));
51593+ atomic_set(&port->count, 0);
51594 }
51595
51596- if (port->count) {
51597+ if (atomic_read(&port->count)) {
51598 spin_unlock_irqrestore(&port->lock, flags);
51599 return 0;
51600 }
51601@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51602 {
51603 spin_lock_irq(&port->lock);
51604 if (!tty_hung_up_p(filp))
51605- ++port->count;
51606+ atomic_inc(&port->count);
51607 spin_unlock_irq(&port->lock);
51608 tty_port_tty_set(port, tty);
51609
51610diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51611index d0e3a44..5f8b754 100644
51612--- a/drivers/tty/vt/keyboard.c
51613+++ b/drivers/tty/vt/keyboard.c
51614@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51615 kbd->kbdmode == VC_OFF) &&
51616 value != KVAL(K_SAK))
51617 return; /* SAK is allowed even in raw mode */
51618+
51619+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51620+ {
51621+ void *func = fn_handler[value];
51622+ if (func == fn_show_state || func == fn_show_ptregs ||
51623+ func == fn_show_mem)
51624+ return;
51625+ }
51626+#endif
51627+
51628 fn_handler[value](vc);
51629 }
51630
51631@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51632 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51633 return -EFAULT;
51634
51635- if (!capable(CAP_SYS_TTY_CONFIG))
51636- perm = 0;
51637-
51638 switch (cmd) {
51639 case KDGKBENT:
51640 /* Ensure another thread doesn't free it under us */
51641@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51642 spin_unlock_irqrestore(&kbd_event_lock, flags);
51643 return put_user(val, &user_kbe->kb_value);
51644 case KDSKBENT:
51645+ if (!capable(CAP_SYS_TTY_CONFIG))
51646+ perm = 0;
51647+
51648 if (!perm)
51649 return -EPERM;
51650 if (!i && v == K_NOSUCHMAP) {
51651@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51652 int i, j, k;
51653 int ret;
51654
51655- if (!capable(CAP_SYS_TTY_CONFIG))
51656- perm = 0;
51657-
51658 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51659 if (!kbs) {
51660 ret = -ENOMEM;
51661@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51662 kfree(kbs);
51663 return ((p && *p) ? -EOVERFLOW : 0);
51664 case KDSKBSENT:
51665+ if (!capable(CAP_SYS_TTY_CONFIG))
51666+ perm = 0;
51667+
51668 if (!perm) {
51669 ret = -EPERM;
51670 goto reterr;
51671diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51672index a673e5b..36e5d32 100644
51673--- a/drivers/uio/uio.c
51674+++ b/drivers/uio/uio.c
51675@@ -25,6 +25,7 @@
51676 #include <linux/kobject.h>
51677 #include <linux/cdev.h>
51678 #include <linux/uio_driver.h>
51679+#include <asm/local.h>
51680
51681 #define UIO_MAX_DEVICES (1U << MINORBITS)
51682
51683@@ -32,7 +33,7 @@ struct uio_device {
51684 struct module *owner;
51685 struct device *dev;
51686 int minor;
51687- atomic_t event;
51688+ atomic_unchecked_t event;
51689 struct fasync_struct *async_queue;
51690 wait_queue_head_t wait;
51691 struct uio_info *info;
51692@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51693 struct device_attribute *attr, char *buf)
51694 {
51695 struct uio_device *idev = dev_get_drvdata(dev);
51696- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51697+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51698 }
51699 static DEVICE_ATTR_RO(event);
51700
51701@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51702 {
51703 struct uio_device *idev = info->uio_dev;
51704
51705- atomic_inc(&idev->event);
51706+ atomic_inc_unchecked(&idev->event);
51707 wake_up_interruptible(&idev->wait);
51708 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51709 }
51710@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51711 }
51712
51713 listener->dev = idev;
51714- listener->event_count = atomic_read(&idev->event);
51715+ listener->event_count = atomic_read_unchecked(&idev->event);
51716 filep->private_data = listener;
51717
51718 if (idev->info->open) {
51719@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51720 return -EIO;
51721
51722 poll_wait(filep, &idev->wait, wait);
51723- if (listener->event_count != atomic_read(&idev->event))
51724+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51725 return POLLIN | POLLRDNORM;
51726 return 0;
51727 }
51728@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51729 do {
51730 set_current_state(TASK_INTERRUPTIBLE);
51731
51732- event_count = atomic_read(&idev->event);
51733+ event_count = atomic_read_unchecked(&idev->event);
51734 if (event_count != listener->event_count) {
51735 if (copy_to_user(buf, &event_count, count))
51736 retval = -EFAULT;
51737@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51738 static int uio_find_mem_index(struct vm_area_struct *vma)
51739 {
51740 struct uio_device *idev = vma->vm_private_data;
51741+ unsigned long size;
51742
51743 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51744- if (idev->info->mem[vma->vm_pgoff].size == 0)
51745+ size = idev->info->mem[vma->vm_pgoff].size;
51746+ if (size == 0)
51747+ return -1;
51748+ if (vma->vm_end - vma->vm_start > size)
51749 return -1;
51750 return (int)vma->vm_pgoff;
51751 }
51752@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51753 idev->owner = owner;
51754 idev->info = info;
51755 init_waitqueue_head(&idev->wait);
51756- atomic_set(&idev->event, 0);
51757+ atomic_set_unchecked(&idev->event, 0);
51758
51759 ret = uio_get_minor(idev);
51760 if (ret)
51761diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51762index 813d4d3..a71934f 100644
51763--- a/drivers/usb/atm/cxacru.c
51764+++ b/drivers/usb/atm/cxacru.c
51765@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51766 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51767 if (ret < 2)
51768 return -EINVAL;
51769- if (index < 0 || index > 0x7f)
51770+ if (index > 0x7f)
51771 return -EINVAL;
51772 pos += tmp;
51773
51774diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51775index dada014..1d0d517 100644
51776--- a/drivers/usb/atm/usbatm.c
51777+++ b/drivers/usb/atm/usbatm.c
51778@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51779 if (printk_ratelimit())
51780 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51781 __func__, vpi, vci);
51782- atomic_inc(&vcc->stats->rx_err);
51783+ atomic_inc_unchecked(&vcc->stats->rx_err);
51784 return;
51785 }
51786
51787@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51788 if (length > ATM_MAX_AAL5_PDU) {
51789 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51790 __func__, length, vcc);
51791- atomic_inc(&vcc->stats->rx_err);
51792+ atomic_inc_unchecked(&vcc->stats->rx_err);
51793 goto out;
51794 }
51795
51796@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51797 if (sarb->len < pdu_length) {
51798 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51799 __func__, pdu_length, sarb->len, vcc);
51800- atomic_inc(&vcc->stats->rx_err);
51801+ atomic_inc_unchecked(&vcc->stats->rx_err);
51802 goto out;
51803 }
51804
51805 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51806 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51807 __func__, vcc);
51808- atomic_inc(&vcc->stats->rx_err);
51809+ atomic_inc_unchecked(&vcc->stats->rx_err);
51810 goto out;
51811 }
51812
51813@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51814 if (printk_ratelimit())
51815 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51816 __func__, length);
51817- atomic_inc(&vcc->stats->rx_drop);
51818+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51819 goto out;
51820 }
51821
51822@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51823
51824 vcc->push(vcc, skb);
51825
51826- atomic_inc(&vcc->stats->rx);
51827+ atomic_inc_unchecked(&vcc->stats->rx);
51828 out:
51829 skb_trim(sarb, 0);
51830 }
51831@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51832 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51833
51834 usbatm_pop(vcc, skb);
51835- atomic_inc(&vcc->stats->tx);
51836+ atomic_inc_unchecked(&vcc->stats->tx);
51837
51838 skb = skb_dequeue(&instance->sndqueue);
51839 }
51840@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51841 if (!left--)
51842 return sprintf(page,
51843 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51844- atomic_read(&atm_dev->stats.aal5.tx),
51845- atomic_read(&atm_dev->stats.aal5.tx_err),
51846- atomic_read(&atm_dev->stats.aal5.rx),
51847- atomic_read(&atm_dev->stats.aal5.rx_err),
51848- atomic_read(&atm_dev->stats.aal5.rx_drop));
51849+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51850+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51851+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51852+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51853+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51854
51855 if (!left--) {
51856 if (instance->disconnected)
51857diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51858index 2a3bbdf..91d72cf 100644
51859--- a/drivers/usb/core/devices.c
51860+++ b/drivers/usb/core/devices.c
51861@@ -126,7 +126,7 @@ static const char format_endpt[] =
51862 * time it gets called.
51863 */
51864 static struct device_connect_event {
51865- atomic_t count;
51866+ atomic_unchecked_t count;
51867 wait_queue_head_t wait;
51868 } device_event = {
51869 .count = ATOMIC_INIT(1),
51870@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51871
51872 void usbfs_conn_disc_event(void)
51873 {
51874- atomic_add(2, &device_event.count);
51875+ atomic_add_unchecked(2, &device_event.count);
51876 wake_up(&device_event.wait);
51877 }
51878
51879@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51880
51881 poll_wait(file, &device_event.wait, wait);
51882
51883- event_count = atomic_read(&device_event.count);
51884+ event_count = atomic_read_unchecked(&device_event.count);
51885 if (file->f_version != event_count) {
51886 file->f_version = event_count;
51887 return POLLIN | POLLRDNORM;
51888diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51889index 90e18f6..5eeda46 100644
51890--- a/drivers/usb/core/devio.c
51891+++ b/drivers/usb/core/devio.c
51892@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51893 struct dev_state *ps = file->private_data;
51894 struct usb_device *dev = ps->dev;
51895 ssize_t ret = 0;
51896- unsigned len;
51897+ size_t len;
51898 loff_t pos;
51899 int i;
51900
51901@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51902 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51903 struct usb_config_descriptor *config =
51904 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51905- unsigned int length = le16_to_cpu(config->wTotalLength);
51906+ size_t length = le16_to_cpu(config->wTotalLength);
51907
51908 if (*ppos < pos + length) {
51909
51910 /* The descriptor may claim to be longer than it
51911 * really is. Here is the actual allocated length. */
51912- unsigned alloclen =
51913+ size_t alloclen =
51914 le16_to_cpu(dev->config[i].desc.wTotalLength);
51915
51916- len = length - (*ppos - pos);
51917+ len = length + pos - *ppos;
51918 if (len > nbytes)
51919 len = nbytes;
51920
51921 /* Simply don't write (skip over) unallocated parts */
51922 if (alloclen > (*ppos - pos)) {
51923- alloclen -= (*ppos - pos);
51924+ alloclen = alloclen + pos - *ppos;
51925 if (copy_to_user(buf,
51926 dev->rawdescriptors[i] + (*ppos - pos),
51927 min(len, alloclen))) {
51928diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51929index 2518c32..1c201bb 100644
51930--- a/drivers/usb/core/hcd.c
51931+++ b/drivers/usb/core/hcd.c
51932@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51933 */
51934 usb_get_urb(urb);
51935 atomic_inc(&urb->use_count);
51936- atomic_inc(&urb->dev->urbnum);
51937+ atomic_inc_unchecked(&urb->dev->urbnum);
51938 usbmon_urb_submit(&hcd->self, urb);
51939
51940 /* NOTE requirements on root-hub callers (usbfs and the hub
51941@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51942 urb->hcpriv = NULL;
51943 INIT_LIST_HEAD(&urb->urb_list);
51944 atomic_dec(&urb->use_count);
51945- atomic_dec(&urb->dev->urbnum);
51946+ atomic_dec_unchecked(&urb->dev->urbnum);
51947 if (atomic_read(&urb->reject))
51948 wake_up(&usb_kill_urb_queue);
51949 usb_put_urb(urb);
51950diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51951index d498d03..e26f959 100644
51952--- a/drivers/usb/core/hub.c
51953+++ b/drivers/usb/core/hub.c
51954@@ -27,6 +27,7 @@
51955 #include <linux/freezer.h>
51956 #include <linux/random.h>
51957 #include <linux/pm_qos.h>
51958+#include <linux/grsecurity.h>
51959
51960 #include <asm/uaccess.h>
51961 #include <asm/byteorder.h>
51962@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51963 goto done;
51964 return;
51965 }
51966+
51967+ if (gr_handle_new_usb())
51968+ goto done;
51969+
51970 if (hub_is_superspeed(hub->hdev))
51971 unit_load = 150;
51972 else
51973diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51974index f829a1a..e6c334a 100644
51975--- a/drivers/usb/core/message.c
51976+++ b/drivers/usb/core/message.c
51977@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51978 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51979 * error number.
51980 */
51981-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51982+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51983 __u8 requesttype, __u16 value, __u16 index, void *data,
51984 __u16 size, int timeout)
51985 {
51986@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51987 * If successful, 0. Otherwise a negative error number. The number of actual
51988 * bytes transferred will be stored in the @actual_length paramater.
51989 */
51990-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51991+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51992 void *data, int len, int *actual_length, int timeout)
51993 {
51994 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51995@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51996 * bytes transferred will be stored in the @actual_length parameter.
51997 *
51998 */
51999-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52000+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52001 void *data, int len, int *actual_length, int timeout)
52002 {
52003 struct urb *urb;
52004diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52005index 1236c60..d47a51c 100644
52006--- a/drivers/usb/core/sysfs.c
52007+++ b/drivers/usb/core/sysfs.c
52008@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52009 struct usb_device *udev;
52010
52011 udev = to_usb_device(dev);
52012- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52013+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52014 }
52015 static DEVICE_ATTR_RO(urbnum);
52016
52017diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52018index 4d11449..f4ccabf 100644
52019--- a/drivers/usb/core/usb.c
52020+++ b/drivers/usb/core/usb.c
52021@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52022 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52023 dev->state = USB_STATE_ATTACHED;
52024 dev->lpm_disable_count = 1;
52025- atomic_set(&dev->urbnum, 0);
52026+ atomic_set_unchecked(&dev->urbnum, 0);
52027
52028 INIT_LIST_HEAD(&dev->ep0.urb_list);
52029 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52030diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52031index 2da0a5a..4870e09 100644
52032--- a/drivers/usb/dwc3/gadget.c
52033+++ b/drivers/usb/dwc3/gadget.c
52034@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52035 if (!usb_endpoint_xfer_isoc(desc))
52036 return 0;
52037
52038- memset(&trb_link, 0, sizeof(trb_link));
52039-
52040 /* Link TRB for ISOC. The HWO bit is never reset */
52041 trb_st_hw = &dep->trb_pool[0];
52042
52043diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52044index 8cfc319..4868255 100644
52045--- a/drivers/usb/early/ehci-dbgp.c
52046+++ b/drivers/usb/early/ehci-dbgp.c
52047@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52048
52049 #ifdef CONFIG_KGDB
52050 static struct kgdb_io kgdbdbgp_io_ops;
52051-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52052+static struct kgdb_io kgdbdbgp_io_ops_console;
52053+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52054 #else
52055 #define dbgp_kgdb_mode (0)
52056 #endif
52057@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52058 .write_char = kgdbdbgp_write_char,
52059 };
52060
52061+static struct kgdb_io kgdbdbgp_io_ops_console = {
52062+ .name = "kgdbdbgp",
52063+ .read_char = kgdbdbgp_read_char,
52064+ .write_char = kgdbdbgp_write_char,
52065+ .is_console = 1
52066+};
52067+
52068 static int kgdbdbgp_wait_time;
52069
52070 static int __init kgdbdbgp_parse_config(char *str)
52071@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52072 ptr++;
52073 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52074 }
52075- kgdb_register_io_module(&kgdbdbgp_io_ops);
52076- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52077+ if (early_dbgp_console.index != -1)
52078+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52079+ else
52080+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52081
52082 return 0;
52083 }
52084diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52085index 2b4c82d..06a8ee6 100644
52086--- a/drivers/usb/gadget/f_uac1.c
52087+++ b/drivers/usb/gadget/f_uac1.c
52088@@ -13,6 +13,7 @@
52089 #include <linux/kernel.h>
52090 #include <linux/device.h>
52091 #include <linux/atomic.h>
52092+#include <linux/module.h>
52093
52094 #include "u_uac1.h"
52095
52096diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52097index ad0aca8..8ff84865 100644
52098--- a/drivers/usb/gadget/u_serial.c
52099+++ b/drivers/usb/gadget/u_serial.c
52100@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52101 spin_lock_irq(&port->port_lock);
52102
52103 /* already open? Great. */
52104- if (port->port.count) {
52105+ if (atomic_read(&port->port.count)) {
52106 status = 0;
52107- port->port.count++;
52108+ atomic_inc(&port->port.count);
52109
52110 /* currently opening/closing? wait ... */
52111 } else if (port->openclose) {
52112@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52113 tty->driver_data = port;
52114 port->port.tty = tty;
52115
52116- port->port.count = 1;
52117+ atomic_set(&port->port.count, 1);
52118 port->openclose = false;
52119
52120 /* if connected, start the I/O stream */
52121@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52122
52123 spin_lock_irq(&port->port_lock);
52124
52125- if (port->port.count != 1) {
52126- if (port->port.count == 0)
52127+ if (atomic_read(&port->port.count) != 1) {
52128+ if (atomic_read(&port->port.count) == 0)
52129 WARN_ON(1);
52130 else
52131- --port->port.count;
52132+ atomic_dec(&port->port.count);
52133 goto exit;
52134 }
52135
52136@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52137 * and sleep if necessary
52138 */
52139 port->openclose = true;
52140- port->port.count = 0;
52141+ atomic_set(&port->port.count, 0);
52142
52143 gser = port->port_usb;
52144 if (gser && gser->disconnect)
52145@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52146 int cond;
52147
52148 spin_lock_irq(&port->port_lock);
52149- cond = (port->port.count == 0) && !port->openclose;
52150+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52151 spin_unlock_irq(&port->port_lock);
52152 return cond;
52153 }
52154@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52155 /* if it's already open, start I/O ... and notify the serial
52156 * protocol about open/close status (connect/disconnect).
52157 */
52158- if (port->port.count) {
52159+ if (atomic_read(&port->port.count)) {
52160 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52161 gs_start_io(port);
52162 if (gser->connect)
52163@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52164
52165 port->port_usb = NULL;
52166 gser->ioport = NULL;
52167- if (port->port.count > 0 || port->openclose) {
52168+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52169 wake_up_interruptible(&port->drain_wait);
52170 if (port->port.tty)
52171 tty_hangup(port->port.tty);
52172@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52173
52174 /* finally, free any unused/unusable I/O buffers */
52175 spin_lock_irqsave(&port->port_lock, flags);
52176- if (port->port.count == 0 && !port->openclose)
52177+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52178 gs_buf_free(&port->port_write_buf);
52179 gs_free_requests(gser->out, &port->read_pool, NULL);
52180 gs_free_requests(gser->out, &port->read_queue, NULL);
52181diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52182index 7a55fea..cc0ed4f 100644
52183--- a/drivers/usb/gadget/u_uac1.c
52184+++ b/drivers/usb/gadget/u_uac1.c
52185@@ -16,6 +16,7 @@
52186 #include <linux/ctype.h>
52187 #include <linux/random.h>
52188 #include <linux/syscalls.h>
52189+#include <linux/module.h>
52190
52191 #include "u_uac1.h"
52192
52193diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52194index 7ae0c4d..35521b7 100644
52195--- a/drivers/usb/host/ehci-hub.c
52196+++ b/drivers/usb/host/ehci-hub.c
52197@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52198 urb->transfer_flags = URB_DIR_IN;
52199 usb_get_urb(urb);
52200 atomic_inc(&urb->use_count);
52201- atomic_inc(&urb->dev->urbnum);
52202+ atomic_inc_unchecked(&urb->dev->urbnum);
52203 urb->setup_dma = dma_map_single(
52204 hcd->self.controller,
52205 urb->setup_packet,
52206@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52207 urb->status = -EINPROGRESS;
52208 usb_get_urb(urb);
52209 atomic_inc(&urb->use_count);
52210- atomic_inc(&urb->dev->urbnum);
52211+ atomic_inc_unchecked(&urb->dev->urbnum);
52212 retval = submit_single_step_set_feature(hcd, urb, 0);
52213 if (!retval && !wait_for_completion_timeout(&done,
52214 msecs_to_jiffies(2000))) {
52215diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52216index ba6a5d6..f88f7f3 100644
52217--- a/drivers/usb/misc/appledisplay.c
52218+++ b/drivers/usb/misc/appledisplay.c
52219@@ -83,7 +83,7 @@ struct appledisplay {
52220 spinlock_t lock;
52221 };
52222
52223-static atomic_t count_displays = ATOMIC_INIT(0);
52224+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52225 static struct workqueue_struct *wq;
52226
52227 static void appledisplay_complete(struct urb *urb)
52228@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52229
52230 /* Register backlight device */
52231 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52232- atomic_inc_return(&count_displays) - 1);
52233+ atomic_inc_return_unchecked(&count_displays) - 1);
52234 memset(&props, 0, sizeof(struct backlight_properties));
52235 props.type = BACKLIGHT_RAW;
52236 props.max_brightness = 0xff;
52237diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52238index 8d7fc48..01c4986 100644
52239--- a/drivers/usb/serial/console.c
52240+++ b/drivers/usb/serial/console.c
52241@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52242
52243 info->port = port;
52244
52245- ++port->port.count;
52246+ atomic_inc(&port->port.count);
52247 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52248 if (serial->type->set_termios) {
52249 /*
52250@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52251 }
52252 /* Now that any required fake tty operations are completed restore
52253 * the tty port count */
52254- --port->port.count;
52255+ atomic_dec(&port->port.count);
52256 /* The console is special in terms of closing the device so
52257 * indicate this port is now acting as a system console. */
52258 port->port.console = 1;
52259@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52260 free_tty:
52261 kfree(tty);
52262 reset_open_count:
52263- port->port.count = 0;
52264+ atomic_set(&port->port.count, 0);
52265 usb_autopm_put_interface(serial->interface);
52266 error_get_interface:
52267 usb_serial_put(serial);
52268@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52269 static void usb_console_write(struct console *co,
52270 const char *buf, unsigned count)
52271 {
52272- static struct usbcons_info *info = &usbcons_info;
52273+ struct usbcons_info *info = &usbcons_info;
52274 struct usb_serial_port *port = info->port;
52275 struct usb_serial *serial;
52276 int retval = -ENODEV;
52277diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52278index 75f70f0..d467e1a 100644
52279--- a/drivers/usb/storage/usb.h
52280+++ b/drivers/usb/storage/usb.h
52281@@ -63,7 +63,7 @@ struct us_unusual_dev {
52282 __u8 useProtocol;
52283 __u8 useTransport;
52284 int (*initFunction)(struct us_data *);
52285-};
52286+} __do_const;
52287
52288
52289 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52290diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52291index a2ef84b..aa7c2b8 100644
52292--- a/drivers/usb/wusbcore/wa-hc.h
52293+++ b/drivers/usb/wusbcore/wa-hc.h
52294@@ -225,7 +225,7 @@ struct wahc {
52295 spinlock_t xfer_list_lock;
52296 struct work_struct xfer_enqueue_work;
52297 struct work_struct xfer_error_work;
52298- atomic_t xfer_id_count;
52299+ atomic_unchecked_t xfer_id_count;
52300
52301 kernel_ulong_t quirks;
52302 };
52303@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52304 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52305 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52306 wa->dto_in_use = 0;
52307- atomic_set(&wa->xfer_id_count, 1);
52308+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52309 }
52310
52311 /**
52312diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52313index 3cd96e9..bd7c58d 100644
52314--- a/drivers/usb/wusbcore/wa-xfer.c
52315+++ b/drivers/usb/wusbcore/wa-xfer.c
52316@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52317 */
52318 static void wa_xfer_id_init(struct wa_xfer *xfer)
52319 {
52320- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52321+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52322 }
52323
52324 /* Return the xfer's ID. */
52325diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52326index 21271d8..45b55a0 100644
52327--- a/drivers/vfio/vfio.c
52328+++ b/drivers/vfio/vfio.c
52329@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52330 return 0;
52331
52332 /* TODO Prevent device auto probing */
52333- WARN("Device %s added to live group %d!\n", dev_name(dev),
52334+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52335 iommu_group_id(group->iommu_group));
52336
52337 return 0;
52338diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52339index 5174eba..451e6bc 100644
52340--- a/drivers/vhost/vringh.c
52341+++ b/drivers/vhost/vringh.c
52342@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52343 /* Userspace access helpers: in this case, addresses are really userspace. */
52344 static inline int getu16_user(u16 *val, const u16 *p)
52345 {
52346- return get_user(*val, (__force u16 __user *)p);
52347+ return get_user(*val, (u16 __force_user *)p);
52348 }
52349
52350 static inline int putu16_user(u16 *p, u16 val)
52351 {
52352- return put_user(val, (__force u16 __user *)p);
52353+ return put_user(val, (u16 __force_user *)p);
52354 }
52355
52356 static inline int copydesc_user(void *dst, const void *src, size_t len)
52357 {
52358- return copy_from_user(dst, (__force void __user *)src, len) ?
52359+ return copy_from_user(dst, (void __force_user *)src, len) ?
52360 -EFAULT : 0;
52361 }
52362
52363@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52364 const struct vring_used_elem *src,
52365 unsigned int num)
52366 {
52367- return copy_to_user((__force void __user *)dst, src,
52368+ return copy_to_user((void __force_user *)dst, src,
52369 sizeof(*dst) * num) ? -EFAULT : 0;
52370 }
52371
52372 static inline int xfer_from_user(void *src, void *dst, size_t len)
52373 {
52374- return copy_from_user(dst, (__force void __user *)src, len) ?
52375+ return copy_from_user(dst, (void __force_user *)src, len) ?
52376 -EFAULT : 0;
52377 }
52378
52379 static inline int xfer_to_user(void *dst, void *src, size_t len)
52380 {
52381- return copy_to_user((__force void __user *)dst, src, len) ?
52382+ return copy_to_user((void __force_user *)dst, src, len) ?
52383 -EFAULT : 0;
52384 }
52385
52386@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52387 vrh->last_used_idx = 0;
52388 vrh->vring.num = num;
52389 /* vring expects kernel addresses, but only used via accessors. */
52390- vrh->vring.desc = (__force struct vring_desc *)desc;
52391- vrh->vring.avail = (__force struct vring_avail *)avail;
52392- vrh->vring.used = (__force struct vring_used *)used;
52393+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52394+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52395+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52396 return 0;
52397 }
52398 EXPORT_SYMBOL(vringh_init_user);
52399@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52400
52401 static inline int putu16_kern(u16 *p, u16 val)
52402 {
52403- ACCESS_ONCE(*p) = val;
52404+ ACCESS_ONCE_RW(*p) = val;
52405 return 0;
52406 }
52407
52408diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52409index 1b0b233..6f34c2c 100644
52410--- a/drivers/video/arcfb.c
52411+++ b/drivers/video/arcfb.c
52412@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52413 return -ENOSPC;
52414
52415 err = 0;
52416- if ((count + p) > fbmemlength) {
52417+ if (count > (fbmemlength - p)) {
52418 count = fbmemlength - p;
52419 err = -ENOSPC;
52420 }
52421diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52422index 52108be..c7c110d 100644
52423--- a/drivers/video/aty/aty128fb.c
52424+++ b/drivers/video/aty/aty128fb.c
52425@@ -149,7 +149,7 @@ enum {
52426 };
52427
52428 /* Must match above enum */
52429-static char * const r128_family[] = {
52430+static const char * const r128_family[] = {
52431 "AGP",
52432 "PCI",
52433 "PRO AGP",
52434diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52435index 28fafbf..ae91651 100644
52436--- a/drivers/video/aty/atyfb_base.c
52437+++ b/drivers/video/aty/atyfb_base.c
52438@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52439 par->accel_flags = var->accel_flags; /* hack */
52440
52441 if (var->accel_flags) {
52442- info->fbops->fb_sync = atyfb_sync;
52443+ pax_open_kernel();
52444+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52445+ pax_close_kernel();
52446 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52447 } else {
52448- info->fbops->fb_sync = NULL;
52449+ pax_open_kernel();
52450+ *(void **)&info->fbops->fb_sync = NULL;
52451+ pax_close_kernel();
52452 info->flags |= FBINFO_HWACCEL_DISABLED;
52453 }
52454
52455diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52456index 95ec042..e6affdd 100644
52457--- a/drivers/video/aty/mach64_cursor.c
52458+++ b/drivers/video/aty/mach64_cursor.c
52459@@ -7,6 +7,7 @@
52460 #include <linux/string.h>
52461
52462 #include <asm/io.h>
52463+#include <asm/pgtable.h>
52464
52465 #ifdef __sparc__
52466 #include <asm/fbio.h>
52467@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52468 info->sprite.buf_align = 16; /* and 64 lines tall. */
52469 info->sprite.flags = FB_PIXMAP_IO;
52470
52471- info->fbops->fb_cursor = atyfb_cursor;
52472+ pax_open_kernel();
52473+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52474+ pax_close_kernel();
52475
52476 return 0;
52477 }
52478diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52479index 84a110a..96312c3 100644
52480--- a/drivers/video/backlight/kb3886_bl.c
52481+++ b/drivers/video/backlight/kb3886_bl.c
52482@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52483 static unsigned long kb3886bl_flags;
52484 #define KB3886BL_SUSPENDED 0x01
52485
52486-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52487+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52488 {
52489 .ident = "Sahara Touch-iT",
52490 .matches = {
52491diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52492index 900aa4e..6d49418 100644
52493--- a/drivers/video/fb_defio.c
52494+++ b/drivers/video/fb_defio.c
52495@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52496
52497 BUG_ON(!fbdefio);
52498 mutex_init(&fbdefio->lock);
52499- info->fbops->fb_mmap = fb_deferred_io_mmap;
52500+ pax_open_kernel();
52501+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52502+ pax_close_kernel();
52503 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52504 INIT_LIST_HEAD(&fbdefio->pagelist);
52505 if (fbdefio->delay == 0) /* set a default of 1 s */
52506@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52507 page->mapping = NULL;
52508 }
52509
52510- info->fbops->fb_mmap = NULL;
52511+ *(void **)&info->fbops->fb_mmap = NULL;
52512 mutex_destroy(&fbdefio->lock);
52513 }
52514 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52515diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52516index 7309ac7..be3c49c 100644
52517--- a/drivers/video/fbmem.c
52518+++ b/drivers/video/fbmem.c
52519@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52520 image->dx += image->width + 8;
52521 }
52522 } else if (rotate == FB_ROTATE_UD) {
52523- for (x = 0; x < num && image->dx >= 0; x++) {
52524+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52525 info->fbops->fb_imageblit(info, image);
52526 image->dx -= image->width + 8;
52527 }
52528@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52529 image->dy += image->height + 8;
52530 }
52531 } else if (rotate == FB_ROTATE_CCW) {
52532- for (x = 0; x < num && image->dy >= 0; x++) {
52533+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52534 info->fbops->fb_imageblit(info, image);
52535 image->dy -= image->height + 8;
52536 }
52537@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52538 return -EFAULT;
52539 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52540 return -EINVAL;
52541- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52542+ if (con2fb.framebuffer >= FB_MAX)
52543 return -EINVAL;
52544 if (!registered_fb[con2fb.framebuffer])
52545 request_module("fb%d", con2fb.framebuffer);
52546@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52547 __u32 data;
52548 int err;
52549
52550- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52551+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52552
52553 data = (__u32) (unsigned long) fix->smem_start;
52554 err |= put_user(data, &fix32->smem_start);
52555diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52556index 130708f..cdac1a9 100644
52557--- a/drivers/video/hyperv_fb.c
52558+++ b/drivers/video/hyperv_fb.c
52559@@ -233,7 +233,7 @@ static uint screen_fb_size;
52560 static inline int synthvid_send(struct hv_device *hdev,
52561 struct synthvid_msg *msg)
52562 {
52563- static atomic64_t request_id = ATOMIC64_INIT(0);
52564+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52565 int ret;
52566
52567 msg->pipe_hdr.type = PIPE_MSG_DATA;
52568@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52569
52570 ret = vmbus_sendpacket(hdev->channel, msg,
52571 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52572- atomic64_inc_return(&request_id),
52573+ atomic64_inc_return_unchecked(&request_id),
52574 VM_PKT_DATA_INBAND, 0);
52575
52576 if (ret)
52577diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52578index 7672d2e..b56437f 100644
52579--- a/drivers/video/i810/i810_accel.c
52580+++ b/drivers/video/i810/i810_accel.c
52581@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52582 }
52583 }
52584 printk("ringbuffer lockup!!!\n");
52585+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52586 i810_report_error(mmio);
52587 par->dev_flags |= LOCKUP;
52588 info->pixmap.scan_align = 1;
52589diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52590index 3c14e43..2630570 100644
52591--- a/drivers/video/logo/logo_linux_clut224.ppm
52592+++ b/drivers/video/logo/logo_linux_clut224.ppm
52593@@ -2,1603 +2,1123 @@ P3
52594 # Standard 224-color Linux logo
52595 80 80
52596 255
52597- 0 0 0 0 0 0 0 0 0 0 0 0
52598- 0 0 0 0 0 0 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- 6 6 6 6 6 6 10 10 10 10 10 10
52607- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0
52614- 0 0 0 0 0 0 0 0 0 0 0 0
52615- 0 0 0 0 0 0 0 0 0 0 0 0
52616- 0 0 0 0 0 0 0 0 0 0 0 0
52617- 0 0 0 0 0 0 0 0 0 0 0 0
52618- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
52626- 22 22 22 26 26 26 30 30 30 34 34 34
52627- 30 30 30 30 30 30 26 26 26 18 18 18
52628- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
52634- 0 0 0 0 0 0 0 0 0 0 0 0
52635- 0 0 0 0 0 0 0 0 0 0 0 0
52636- 0 0 0 0 0 0 0 0 0 0 0 0
52637- 0 0 0 0 0 0 0 0 0 0 0 0
52638- 0 0 0 0 0 1 0 0 1 0 0 0
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- 6 6 6 14 14 14 26 26 26 42 42 42
52646- 54 54 54 66 66 66 78 78 78 78 78 78
52647- 78 78 78 74 74 74 66 66 66 54 54 54
52648- 42 42 42 26 26 26 18 18 18 10 10 10
52649- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
52654- 0 0 0 0 0 0 0 0 0 0 0 0
52655- 0 0 0 0 0 0 0 0 0 0 0 0
52656- 0 0 0 0 0 0 0 0 0 0 0 0
52657- 0 0 0 0 0 0 0 0 0 0 0 0
52658- 0 0 1 0 0 0 0 0 0 0 0 0
52659- 0 0 0 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 10 10 10
52665- 22 22 22 42 42 42 66 66 66 86 86 86
52666- 66 66 66 38 38 38 38 38 38 22 22 22
52667- 26 26 26 34 34 34 54 54 54 66 66 66
52668- 86 86 86 70 70 70 46 46 46 26 26 26
52669- 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
52674- 0 0 0 0 0 0 0 0 0 0 0 0
52675- 0 0 0 0 0 0 0 0 0 0 0 0
52676- 0 0 0 0 0 0 0 0 0 0 0 0
52677- 0 0 0 0 0 0 0 0 0 0 0 0
52678- 0 0 1 0 0 1 0 0 1 0 0 0
52679- 0 0 0 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 10 10 10 26 26 26
52685- 50 50 50 82 82 82 58 58 58 6 6 6
52686- 2 2 6 2 2 6 2 2 6 2 2 6
52687- 2 2 6 2 2 6 2 2 6 2 2 6
52688- 6 6 6 54 54 54 86 86 86 66 66 66
52689- 38 38 38 18 18 18 6 6 6 0 0 0
52690- 0 0 0 0 0 0 0 0 0 0 0 0
52691- 0 0 0 0 0 0 0 0 0 0 0 0
52692- 0 0 0 0 0 0 0 0 0 0 0 0
52693- 0 0 0 0 0 0 0 0 0 0 0 0
52694- 0 0 0 0 0 0 0 0 0 0 0 0
52695- 0 0 0 0 0 0 0 0 0 0 0 0
52696- 0 0 0 0 0 0 0 0 0 0 0 0
52697- 0 0 0 0 0 0 0 0 0 0 0 0
52698- 0 0 0 0 0 0 0 0 0 0 0 0
52699- 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
52705- 78 78 78 34 34 34 2 2 6 2 2 6
52706- 2 2 6 2 2 6 2 2 6 2 2 6
52707- 2 2 6 2 2 6 2 2 6 2 2 6
52708- 2 2 6 2 2 6 6 6 6 70 70 70
52709- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
52713- 0 0 0 0 0 0 0 0 0 0 0 0
52714- 0 0 0 0 0 0 0 0 0 0 0 0
52715- 0 0 0 0 0 0 0 0 0 0 0 0
52716- 0 0 0 0 0 0 0 0 0 0 0 0
52717- 0 0 0 0 0 0 0 0 0 0 0 0
52718- 0 0 1 0 0 1 0 0 1 0 0 0
52719- 0 0 0 0 0 0 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- 6 6 6 18 18 18 42 42 42 82 82 82
52725- 26 26 26 2 2 6 2 2 6 2 2 6
52726- 2 2 6 2 2 6 2 2 6 2 2 6
52727- 2 2 6 2 2 6 2 2 6 14 14 14
52728- 46 46 46 34 34 34 6 6 6 2 2 6
52729- 42 42 42 78 78 78 42 42 42 18 18 18
52730- 6 6 6 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 0 0 0
52733- 0 0 0 0 0 0 0 0 0 0 0 0
52734- 0 0 0 0 0 0 0 0 0 0 0 0
52735- 0 0 0 0 0 0 0 0 0 0 0 0
52736- 0 0 0 0 0 0 0 0 0 0 0 0
52737- 0 0 0 0 0 0 0 0 0 0 0 0
52738- 0 0 1 0 0 0 0 0 1 0 0 0
52739- 0 0 0 0 0 0 0 0 0 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- 10 10 10 30 30 30 66 66 66 58 58 58
52745- 2 2 6 2 2 6 2 2 6 2 2 6
52746- 2 2 6 2 2 6 2 2 6 2 2 6
52747- 2 2 6 2 2 6 2 2 6 26 26 26
52748- 86 86 86 101 101 101 46 46 46 10 10 10
52749- 2 2 6 58 58 58 70 70 70 34 34 34
52750- 10 10 10 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 0 0 0
52753- 0 0 0 0 0 0 0 0 0 0 0 0
52754- 0 0 0 0 0 0 0 0 0 0 0 0
52755- 0 0 0 0 0 0 0 0 0 0 0 0
52756- 0 0 0 0 0 0 0 0 0 0 0 0
52757- 0 0 0 0 0 0 0 0 0 0 0 0
52758- 0 0 1 0 0 1 0 0 1 0 0 0
52759- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
52765- 2 2 6 2 2 6 2 2 6 2 2 6
52766- 2 2 6 2 2 6 2 2 6 2 2 6
52767- 2 2 6 2 2 6 2 2 6 30 30 30
52768- 94 94 94 94 94 94 58 58 58 26 26 26
52769- 2 2 6 6 6 6 78 78 78 54 54 54
52770- 22 22 22 6 6 6 0 0 0 0 0 0
52771- 0 0 0 0 0 0 0 0 0 0 0 0
52772- 0 0 0 0 0 0 0 0 0 0 0 0
52773- 0 0 0 0 0 0 0 0 0 0 0 0
52774- 0 0 0 0 0 0 0 0 0 0 0 0
52775- 0 0 0 0 0 0 0 0 0 0 0 0
52776- 0 0 0 0 0 0 0 0 0 0 0 0
52777- 0 0 0 0 0 0 0 0 0 0 0 0
52778- 0 0 0 0 0 0 0 0 0 0 0 0
52779- 0 0 0 0 0 0 0 0 0 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 6 6 6
52784- 22 22 22 62 62 62 62 62 62 2 2 6
52785- 2 2 6 2 2 6 2 2 6 2 2 6
52786- 2 2 6 2 2 6 2 2 6 2 2 6
52787- 2 2 6 2 2 6 2 2 6 26 26 26
52788- 54 54 54 38 38 38 18 18 18 10 10 10
52789- 2 2 6 2 2 6 34 34 34 82 82 82
52790- 38 38 38 14 14 14 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 0 0 0
52793- 0 0 0 0 0 0 0 0 0 0 0 0
52794- 0 0 0 0 0 0 0 0 0 0 0 0
52795- 0 0 0 0 0 0 0 0 0 0 0 0
52796- 0 0 0 0 0 0 0 0 0 0 0 0
52797- 0 0 0 0 0 0 0 0 0 0 0 0
52798- 0 0 0 0 0 1 0 0 1 0 0 0
52799- 0 0 0 0 0 0 0 0 0 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 6 6 6
52804- 30 30 30 78 78 78 30 30 30 2 2 6
52805- 2 2 6 2 2 6 2 2 6 2 2 6
52806- 2 2 6 2 2 6 2 2 6 2 2 6
52807- 2 2 6 2 2 6 2 2 6 10 10 10
52808- 10 10 10 2 2 6 2 2 6 2 2 6
52809- 2 2 6 2 2 6 2 2 6 78 78 78
52810- 50 50 50 18 18 18 6 6 6 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 0 0 0
52813- 0 0 0 0 0 0 0 0 0 0 0 0
52814- 0 0 0 0 0 0 0 0 0 0 0 0
52815- 0 0 0 0 0 0 0 0 0 0 0 0
52816- 0 0 0 0 0 0 0 0 0 0 0 0
52817- 0 0 0 0 0 0 0 0 0 0 0 0
52818- 0 0 1 0 0 0 0 0 0 0 0 0
52819- 0 0 0 0 0 0 0 0 0 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 10 10 10
52824- 38 38 38 86 86 86 14 14 14 2 2 6
52825- 2 2 6 2 2 6 2 2 6 2 2 6
52826- 2 2 6 2 2 6 2 2 6 2 2 6
52827- 2 2 6 2 2 6 2 2 6 2 2 6
52828- 2 2 6 2 2 6 2 2 6 2 2 6
52829- 2 2 6 2 2 6 2 2 6 54 54 54
52830- 66 66 66 26 26 26 6 6 6 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 0 0 0
52833- 0 0 0 0 0 0 0 0 0 0 0 0
52834- 0 0 0 0 0 0 0 0 0 0 0 0
52835- 0 0 0 0 0 0 0 0 0 0 0 0
52836- 0 0 0 0 0 0 0 0 0 0 0 0
52837- 0 0 0 0 0 0 0 0 0 0 0 0
52838- 0 0 0 0 0 1 0 0 1 0 0 0
52839- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52844- 42 42 42 82 82 82 2 2 6 2 2 6
52845- 2 2 6 6 6 6 10 10 10 2 2 6
52846- 2 2 6 2 2 6 2 2 6 2 2 6
52847- 2 2 6 2 2 6 2 2 6 6 6 6
52848- 14 14 14 10 10 10 2 2 6 2 2 6
52849- 2 2 6 2 2 6 2 2 6 18 18 18
52850- 82 82 82 34 34 34 10 10 10 0 0 0
52851- 0 0 0 0 0 0 0 0 0 0 0 0
52852- 0 0 0 0 0 0 0 0 0 0 0 0
52853- 0 0 0 0 0 0 0 0 0 0 0 0
52854- 0 0 0 0 0 0 0 0 0 0 0 0
52855- 0 0 0 0 0 0 0 0 0 0 0 0
52856- 0 0 0 0 0 0 0 0 0 0 0 0
52857- 0 0 0 0 0 0 0 0 0 0 0 0
52858- 0 0 1 0 0 0 0 0 0 0 0 0
52859- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52864- 46 46 46 86 86 86 2 2 6 2 2 6
52865- 6 6 6 6 6 6 22 22 22 34 34 34
52866- 6 6 6 2 2 6 2 2 6 2 2 6
52867- 2 2 6 2 2 6 18 18 18 34 34 34
52868- 10 10 10 50 50 50 22 22 22 2 2 6
52869- 2 2 6 2 2 6 2 2 6 10 10 10
52870- 86 86 86 42 42 42 14 14 14 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 0 0 0
52873- 0 0 0 0 0 0 0 0 0 0 0 0
52874- 0 0 0 0 0 0 0 0 0 0 0 0
52875- 0 0 0 0 0 0 0 0 0 0 0 0
52876- 0 0 0 0 0 0 0 0 0 0 0 0
52877- 0 0 0 0 0 0 0 0 0 0 0 0
52878- 0 0 1 0 0 1 0 0 1 0 0 0
52879- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52884- 46 46 46 86 86 86 2 2 6 2 2 6
52885- 38 38 38 116 116 116 94 94 94 22 22 22
52886- 22 22 22 2 2 6 2 2 6 2 2 6
52887- 14 14 14 86 86 86 138 138 138 162 162 162
52888-154 154 154 38 38 38 26 26 26 6 6 6
52889- 2 2 6 2 2 6 2 2 6 2 2 6
52890- 86 86 86 46 46 46 14 14 14 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 0 0 0
52893- 0 0 0 0 0 0 0 0 0 0 0 0
52894- 0 0 0 0 0 0 0 0 0 0 0 0
52895- 0 0 0 0 0 0 0 0 0 0 0 0
52896- 0 0 0 0 0 0 0 0 0 0 0 0
52897- 0 0 0 0 0 0 0 0 0 0 0 0
52898- 0 0 0 0 0 0 0 0 0 0 0 0
52899- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52904- 46 46 46 86 86 86 2 2 6 14 14 14
52905-134 134 134 198 198 198 195 195 195 116 116 116
52906- 10 10 10 2 2 6 2 2 6 6 6 6
52907-101 98 89 187 187 187 210 210 210 218 218 218
52908-214 214 214 134 134 134 14 14 14 6 6 6
52909- 2 2 6 2 2 6 2 2 6 2 2 6
52910- 86 86 86 50 50 50 18 18 18 6 6 6
52911- 0 0 0 0 0 0 0 0 0 0 0 0
52912- 0 0 0 0 0 0 0 0 0 0 0 0
52913- 0 0 0 0 0 0 0 0 0 0 0 0
52914- 0 0 0 0 0 0 0 0 0 0 0 0
52915- 0 0 0 0 0 0 0 0 0 0 0 0
52916- 0 0 0 0 0 0 0 0 0 0 0 0
52917- 0 0 0 0 0 0 0 0 1 0 0 0
52918- 0 0 1 0 0 1 0 0 1 0 0 0
52919- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52924- 46 46 46 86 86 86 2 2 6 54 54 54
52925-218 218 218 195 195 195 226 226 226 246 246 246
52926- 58 58 58 2 2 6 2 2 6 30 30 30
52927-210 210 210 253 253 253 174 174 174 123 123 123
52928-221 221 221 234 234 234 74 74 74 2 2 6
52929- 2 2 6 2 2 6 2 2 6 2 2 6
52930- 70 70 70 58 58 58 22 22 22 6 6 6
52931- 0 0 0 0 0 0 0 0 0 0 0 0
52932- 0 0 0 0 0 0 0 0 0 0 0 0
52933- 0 0 0 0 0 0 0 0 0 0 0 0
52934- 0 0 0 0 0 0 0 0 0 0 0 0
52935- 0 0 0 0 0 0 0 0 0 0 0 0
52936- 0 0 0 0 0 0 0 0 0 0 0 0
52937- 0 0 0 0 0 0 0 0 0 0 0 0
52938- 0 0 0 0 0 0 0 0 0 0 0 0
52939- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52944- 46 46 46 82 82 82 2 2 6 106 106 106
52945-170 170 170 26 26 26 86 86 86 226 226 226
52946-123 123 123 10 10 10 14 14 14 46 46 46
52947-231 231 231 190 190 190 6 6 6 70 70 70
52948- 90 90 90 238 238 238 158 158 158 2 2 6
52949- 2 2 6 2 2 6 2 2 6 2 2 6
52950- 70 70 70 58 58 58 22 22 22 6 6 6
52951- 0 0 0 0 0 0 0 0 0 0 0 0
52952- 0 0 0 0 0 0 0 0 0 0 0 0
52953- 0 0 0 0 0 0 0 0 0 0 0 0
52954- 0 0 0 0 0 0 0 0 0 0 0 0
52955- 0 0 0 0 0 0 0 0 0 0 0 0
52956- 0 0 0 0 0 0 0 0 0 0 0 0
52957- 0 0 0 0 0 0 0 0 1 0 0 0
52958- 0 0 1 0 0 1 0 0 1 0 0 0
52959- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52964- 42 42 42 86 86 86 6 6 6 116 116 116
52965-106 106 106 6 6 6 70 70 70 149 149 149
52966-128 128 128 18 18 18 38 38 38 54 54 54
52967-221 221 221 106 106 106 2 2 6 14 14 14
52968- 46 46 46 190 190 190 198 198 198 2 2 6
52969- 2 2 6 2 2 6 2 2 6 2 2 6
52970- 74 74 74 62 62 62 22 22 22 6 6 6
52971- 0 0 0 0 0 0 0 0 0 0 0 0
52972- 0 0 0 0 0 0 0 0 0 0 0 0
52973- 0 0 0 0 0 0 0 0 0 0 0 0
52974- 0 0 0 0 0 0 0 0 0 0 0 0
52975- 0 0 0 0 0 0 0 0 0 0 0 0
52976- 0 0 0 0 0 0 0 0 0 0 0 0
52977- 0 0 0 0 0 0 0 0 1 0 0 0
52978- 0 0 1 0 0 0 0 0 1 0 0 0
52979- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52984- 42 42 42 94 94 94 14 14 14 101 101 101
52985-128 128 128 2 2 6 18 18 18 116 116 116
52986-118 98 46 121 92 8 121 92 8 98 78 10
52987-162 162 162 106 106 106 2 2 6 2 2 6
52988- 2 2 6 195 195 195 195 195 195 6 6 6
52989- 2 2 6 2 2 6 2 2 6 2 2 6
52990- 74 74 74 62 62 62 22 22 22 6 6 6
52991- 0 0 0 0 0 0 0 0 0 0 0 0
52992- 0 0 0 0 0 0 0 0 0 0 0 0
52993- 0 0 0 0 0 0 0 0 0 0 0 0
52994- 0 0 0 0 0 0 0 0 0 0 0 0
52995- 0 0 0 0 0 0 0 0 0 0 0 0
52996- 0 0 0 0 0 0 0 0 0 0 0 0
52997- 0 0 0 0 0 0 0 0 1 0 0 1
52998- 0 0 1 0 0 0 0 0 1 0 0 0
52999- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
53004- 38 38 38 90 90 90 14 14 14 58 58 58
53005-210 210 210 26 26 26 54 38 6 154 114 10
53006-226 170 11 236 186 11 225 175 15 184 144 12
53007-215 174 15 175 146 61 37 26 9 2 2 6
53008- 70 70 70 246 246 246 138 138 138 2 2 6
53009- 2 2 6 2 2 6 2 2 6 2 2 6
53010- 70 70 70 66 66 66 26 26 26 6 6 6
53011- 0 0 0 0 0 0 0 0 0 0 0 0
53012- 0 0 0 0 0 0 0 0 0 0 0 0
53013- 0 0 0 0 0 0 0 0 0 0 0 0
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 0 0 0
53017- 0 0 0 0 0 0 0 0 0 0 0 0
53018- 0 0 0 0 0 0 0 0 0 0 0 0
53019- 0 0 0 0 0 0 0 0 0 0 0 0
53020- 0 0 0 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 10 10 10
53024- 38 38 38 86 86 86 14 14 14 10 10 10
53025-195 195 195 188 164 115 192 133 9 225 175 15
53026-239 182 13 234 190 10 232 195 16 232 200 30
53027-245 207 45 241 208 19 232 195 16 184 144 12
53028-218 194 134 211 206 186 42 42 42 2 2 6
53029- 2 2 6 2 2 6 2 2 6 2 2 6
53030- 50 50 50 74 74 74 30 30 30 6 6 6
53031- 0 0 0 0 0 0 0 0 0 0 0 0
53032- 0 0 0 0 0 0 0 0 0 0 0 0
53033- 0 0 0 0 0 0 0 0 0 0 0 0
53034- 0 0 0 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 0 0 0 0 0 0 0 0 0
53037- 0 0 0 0 0 0 0 0 0 0 0 0
53038- 0 0 0 0 0 0 0 0 0 0 0 0
53039- 0 0 0 0 0 0 0 0 0 0 0 0
53040- 0 0 0 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 10 10 10
53044- 34 34 34 86 86 86 14 14 14 2 2 6
53045-121 87 25 192 133 9 219 162 10 239 182 13
53046-236 186 11 232 195 16 241 208 19 244 214 54
53047-246 218 60 246 218 38 246 215 20 241 208 19
53048-241 208 19 226 184 13 121 87 25 2 2 6
53049- 2 2 6 2 2 6 2 2 6 2 2 6
53050- 50 50 50 82 82 82 34 34 34 10 10 10
53051- 0 0 0 0 0 0 0 0 0 0 0 0
53052- 0 0 0 0 0 0 0 0 0 0 0 0
53053- 0 0 0 0 0 0 0 0 0 0 0 0
53054- 0 0 0 0 0 0 0 0 0 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 0 0 0 0 0 0 0 0 0 0 0 0
53057- 0 0 0 0 0 0 0 0 0 0 0 0
53058- 0 0 0 0 0 0 0 0 0 0 0 0
53059- 0 0 0 0 0 0 0 0 0 0 0 0
53060- 0 0 0 0 0 0 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 10 10 10
53064- 34 34 34 82 82 82 30 30 30 61 42 6
53065-180 123 7 206 145 10 230 174 11 239 182 13
53066-234 190 10 238 202 15 241 208 19 246 218 74
53067-246 218 38 246 215 20 246 215 20 246 215 20
53068-226 184 13 215 174 15 184 144 12 6 6 6
53069- 2 2 6 2 2 6 2 2 6 2 2 6
53070- 26 26 26 94 94 94 42 42 42 14 14 14
53071- 0 0 0 0 0 0 0 0 0 0 0 0
53072- 0 0 0 0 0 0 0 0 0 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 0 0 0
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 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 10 10 10
53084- 30 30 30 78 78 78 50 50 50 104 69 6
53085-192 133 9 216 158 10 236 178 12 236 186 11
53086-232 195 16 241 208 19 244 214 54 245 215 43
53087-246 215 20 246 215 20 241 208 19 198 155 10
53088-200 144 11 216 158 10 156 118 10 2 2 6
53089- 2 2 6 2 2 6 2 2 6 2 2 6
53090- 6 6 6 90 90 90 54 54 54 18 18 18
53091- 6 6 6 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 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 10 10 10
53104- 30 30 30 78 78 78 46 46 46 22 22 22
53105-137 92 6 210 162 10 239 182 13 238 190 10
53106-238 202 15 241 208 19 246 215 20 246 215 20
53107-241 208 19 203 166 17 185 133 11 210 150 10
53108-216 158 10 210 150 10 102 78 10 2 2 6
53109- 6 6 6 54 54 54 14 14 14 2 2 6
53110- 2 2 6 62 62 62 74 74 74 30 30 30
53111- 10 10 10 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 0 0 0
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 0 0 0 0 0 0 0 0 0 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 10 10 10
53124- 34 34 34 78 78 78 50 50 50 6 6 6
53125- 94 70 30 139 102 15 190 146 13 226 184 13
53126-232 200 30 232 195 16 215 174 15 190 146 13
53127-168 122 10 192 133 9 210 150 10 213 154 11
53128-202 150 34 182 157 106 101 98 89 2 2 6
53129- 2 2 6 78 78 78 116 116 116 58 58 58
53130- 2 2 6 22 22 22 90 90 90 46 46 46
53131- 18 18 18 6 6 6 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 0 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 0 0 0
53140- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
53144- 38 38 38 86 86 86 50 50 50 6 6 6
53145-128 128 128 174 154 114 156 107 11 168 122 10
53146-198 155 10 184 144 12 197 138 11 200 144 11
53147-206 145 10 206 145 10 197 138 11 188 164 115
53148-195 195 195 198 198 198 174 174 174 14 14 14
53149- 2 2 6 22 22 22 116 116 116 116 116 116
53150- 22 22 22 2 2 6 74 74 74 70 70 70
53151- 30 30 30 10 10 10 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 0 0 0 0 0 0 0 0 0 0 0 0
53161- 0 0 0 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 6 6 6 18 18 18
53164- 50 50 50 101 101 101 26 26 26 10 10 10
53165-138 138 138 190 190 190 174 154 114 156 107 11
53166-197 138 11 200 144 11 197 138 11 192 133 9
53167-180 123 7 190 142 34 190 178 144 187 187 187
53168-202 202 202 221 221 221 214 214 214 66 66 66
53169- 2 2 6 2 2 6 50 50 50 62 62 62
53170- 6 6 6 2 2 6 10 10 10 90 90 90
53171- 50 50 50 18 18 18 6 6 6 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 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 10 10 10 34 34 34
53184- 74 74 74 74 74 74 2 2 6 6 6 6
53185-144 144 144 198 198 198 190 190 190 178 166 146
53186-154 121 60 156 107 11 156 107 11 168 124 44
53187-174 154 114 187 187 187 190 190 190 210 210 210
53188-246 246 246 253 253 253 253 253 253 182 182 182
53189- 6 6 6 2 2 6 2 2 6 2 2 6
53190- 2 2 6 2 2 6 2 2 6 62 62 62
53191- 74 74 74 34 34 34 14 14 14 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 0 0 0 0 0 0 0
53200- 0 0 0 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 10 10 10 22 22 22 54 54 54
53204- 94 94 94 18 18 18 2 2 6 46 46 46
53205-234 234 234 221 221 221 190 190 190 190 190 190
53206-190 190 190 187 187 187 187 187 187 190 190 190
53207-190 190 190 195 195 195 214 214 214 242 242 242
53208-253 253 253 253 253 253 253 253 253 253 253 253
53209- 82 82 82 2 2 6 2 2 6 2 2 6
53210- 2 2 6 2 2 6 2 2 6 14 14 14
53211- 86 86 86 54 54 54 22 22 22 6 6 6
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 0 0 0 0 0 0 0 0 0 0
53220- 0 0 0 0 0 0 0 0 0 0 0 0
53221- 0 0 0 0 0 0 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 6 6 6 18 18 18 46 46 46 90 90 90
53224- 46 46 46 18 18 18 6 6 6 182 182 182
53225-253 253 253 246 246 246 206 206 206 190 190 190
53226-190 190 190 190 190 190 190 190 190 190 190 190
53227-206 206 206 231 231 231 250 250 250 253 253 253
53228-253 253 253 253 253 253 253 253 253 253 253 253
53229-202 202 202 14 14 14 2 2 6 2 2 6
53230- 2 2 6 2 2 6 2 2 6 2 2 6
53231- 42 42 42 86 86 86 42 42 42 18 18 18
53232- 6 6 6 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 0 0 0 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 0 0 0 0 0 0 0 0 0 0 0 0
53240- 0 0 0 0 0 0 0 0 0 0 0 0
53241- 0 0 0 0 0 0 0 0 0 0 0 0
53242- 0 0 0 0 0 0 0 0 0 6 6 6
53243- 14 14 14 38 38 38 74 74 74 66 66 66
53244- 2 2 6 6 6 6 90 90 90 250 250 250
53245-253 253 253 253 253 253 238 238 238 198 198 198
53246-190 190 190 190 190 190 195 195 195 221 221 221
53247-246 246 246 253 253 253 253 253 253 253 253 253
53248-253 253 253 253 253 253 253 253 253 253 253 253
53249-253 253 253 82 82 82 2 2 6 2 2 6
53250- 2 2 6 2 2 6 2 2 6 2 2 6
53251- 2 2 6 78 78 78 70 70 70 34 34 34
53252- 14 14 14 6 6 6 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 0 0 0
53260- 0 0 0 0 0 0 0 0 0 0 0 0
53261- 0 0 0 0 0 0 0 0 0 0 0 0
53262- 0 0 0 0 0 0 0 0 0 14 14 14
53263- 34 34 34 66 66 66 78 78 78 6 6 6
53264- 2 2 6 18 18 18 218 218 218 253 253 253
53265-253 253 253 253 253 253 253 253 253 246 246 246
53266-226 226 226 231 231 231 246 246 246 253 253 253
53267-253 253 253 253 253 253 253 253 253 253 253 253
53268-253 253 253 253 253 253 253 253 253 253 253 253
53269-253 253 253 178 178 178 2 2 6 2 2 6
53270- 2 2 6 2 2 6 2 2 6 2 2 6
53271- 2 2 6 18 18 18 90 90 90 62 62 62
53272- 30 30 30 10 10 10 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 0 0 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 0 0 0
53279- 0 0 0 0 0 0 0 0 0 0 0 0
53280- 0 0 0 0 0 0 0 0 0 0 0 0
53281- 0 0 0 0 0 0 0 0 0 0 0 0
53282- 0 0 0 0 0 0 10 10 10 26 26 26
53283- 58 58 58 90 90 90 18 18 18 2 2 6
53284- 2 2 6 110 110 110 253 253 253 253 253 253
53285-253 253 253 253 253 253 253 253 253 253 253 253
53286-250 250 250 253 253 253 253 253 253 253 253 253
53287-253 253 253 253 253 253 253 253 253 253 253 253
53288-253 253 253 253 253 253 253 253 253 253 253 253
53289-253 253 253 231 231 231 18 18 18 2 2 6
53290- 2 2 6 2 2 6 2 2 6 2 2 6
53291- 2 2 6 2 2 6 18 18 18 94 94 94
53292- 54 54 54 26 26 26 10 10 10 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 0 0 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 0 0 0
53299- 0 0 0 0 0 0 0 0 0 0 0 0
53300- 0 0 0 0 0 0 0 0 0 0 0 0
53301- 0 0 0 0 0 0 0 0 0 0 0 0
53302- 0 0 0 6 6 6 22 22 22 50 50 50
53303- 90 90 90 26 26 26 2 2 6 2 2 6
53304- 14 14 14 195 195 195 250 250 250 253 253 253
53305-253 253 253 253 253 253 253 253 253 253 253 253
53306-253 253 253 253 253 253 253 253 253 253 253 253
53307-253 253 253 253 253 253 253 253 253 253 253 253
53308-253 253 253 253 253 253 253 253 253 253 253 253
53309-250 250 250 242 242 242 54 54 54 2 2 6
53310- 2 2 6 2 2 6 2 2 6 2 2 6
53311- 2 2 6 2 2 6 2 2 6 38 38 38
53312- 86 86 86 50 50 50 22 22 22 6 6 6
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 0 0 0 0 0 0 0 0 0 0 0 0
53316- 0 0 0 0 0 0 0 0 0 0 0 0
53317- 0 0 0 0 0 0 0 0 0 0 0 0
53318- 0 0 0 0 0 0 0 0 0 0 0 0
53319- 0 0 0 0 0 0 0 0 0 0 0 0
53320- 0 0 0 0 0 0 0 0 0 0 0 0
53321- 0 0 0 0 0 0 0 0 0 0 0 0
53322- 6 6 6 14 14 14 38 38 38 82 82 82
53323- 34 34 34 2 2 6 2 2 6 2 2 6
53324- 42 42 42 195 195 195 246 246 246 253 253 253
53325-253 253 253 253 253 253 253 253 253 250 250 250
53326-242 242 242 242 242 242 250 250 250 253 253 253
53327-253 253 253 253 253 253 253 253 253 253 253 253
53328-253 253 253 250 250 250 246 246 246 238 238 238
53329-226 226 226 231 231 231 101 101 101 6 6 6
53330- 2 2 6 2 2 6 2 2 6 2 2 6
53331- 2 2 6 2 2 6 2 2 6 2 2 6
53332- 38 38 38 82 82 82 42 42 42 14 14 14
53333- 6 6 6 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 0 0 0
53335- 0 0 0 0 0 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 0 0 0
53339- 0 0 0 0 0 0 0 0 0 0 0 0
53340- 0 0 0 0 0 0 0 0 0 0 0 0
53341- 0 0 0 0 0 0 0 0 0 0 0 0
53342- 10 10 10 26 26 26 62 62 62 66 66 66
53343- 2 2 6 2 2 6 2 2 6 6 6 6
53344- 70 70 70 170 170 170 206 206 206 234 234 234
53345-246 246 246 250 250 250 250 250 250 238 238 238
53346-226 226 226 231 231 231 238 238 238 250 250 250
53347-250 250 250 250 250 250 246 246 246 231 231 231
53348-214 214 214 206 206 206 202 202 202 202 202 202
53349-198 198 198 202 202 202 182 182 182 18 18 18
53350- 2 2 6 2 2 6 2 2 6 2 2 6
53351- 2 2 6 2 2 6 2 2 6 2 2 6
53352- 2 2 6 62 62 62 66 66 66 30 30 30
53353- 10 10 10 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 0 0 0
53355- 0 0 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 0 0 0
53359- 0 0 0 0 0 0 0 0 0 0 0 0
53360- 0 0 0 0 0 0 0 0 0 0 0 0
53361- 0 0 0 0 0 0 0 0 0 0 0 0
53362- 14 14 14 42 42 42 82 82 82 18 18 18
53363- 2 2 6 2 2 6 2 2 6 10 10 10
53364- 94 94 94 182 182 182 218 218 218 242 242 242
53365-250 250 250 253 253 253 253 253 253 250 250 250
53366-234 234 234 253 253 253 253 253 253 253 253 253
53367-253 253 253 253 253 253 253 253 253 246 246 246
53368-238 238 238 226 226 226 210 210 210 202 202 202
53369-195 195 195 195 195 195 210 210 210 158 158 158
53370- 6 6 6 14 14 14 50 50 50 14 14 14
53371- 2 2 6 2 2 6 2 2 6 2 2 6
53372- 2 2 6 6 6 6 86 86 86 46 46 46
53373- 18 18 18 6 6 6 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 0 0 0 0 0 0 0 0 0 0
53380- 0 0 0 0 0 0 0 0 0 0 0 0
53381- 0 0 0 0 0 0 0 0 0 6 6 6
53382- 22 22 22 54 54 54 70 70 70 2 2 6
53383- 2 2 6 10 10 10 2 2 6 22 22 22
53384-166 166 166 231 231 231 250 250 250 253 253 253
53385-253 253 253 253 253 253 253 253 253 250 250 250
53386-242 242 242 253 253 253 253 253 253 253 253 253
53387-253 253 253 253 253 253 253 253 253 253 253 253
53388-253 253 253 253 253 253 253 253 253 246 246 246
53389-231 231 231 206 206 206 198 198 198 226 226 226
53390- 94 94 94 2 2 6 6 6 6 38 38 38
53391- 30 30 30 2 2 6 2 2 6 2 2 6
53392- 2 2 6 2 2 6 62 62 62 66 66 66
53393- 26 26 26 10 10 10 0 0 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 0 0 0
53395- 0 0 0 0 0 0 0 0 0 0 0 0
53396- 0 0 0 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 0 0 0
53399- 0 0 0 0 0 0 0 0 0 0 0 0
53400- 0 0 0 0 0 0 0 0 0 0 0 0
53401- 0 0 0 0 0 0 0 0 0 10 10 10
53402- 30 30 30 74 74 74 50 50 50 2 2 6
53403- 26 26 26 26 26 26 2 2 6 106 106 106
53404-238 238 238 253 253 253 253 253 253 253 253 253
53405-253 253 253 253 253 253 253 253 253 253 253 253
53406-253 253 253 253 253 253 253 253 253 253 253 253
53407-253 253 253 253 253 253 253 253 253 253 253 253
53408-253 253 253 253 253 253 253 253 253 253 253 253
53409-253 253 253 246 246 246 218 218 218 202 202 202
53410-210 210 210 14 14 14 2 2 6 2 2 6
53411- 30 30 30 22 22 22 2 2 6 2 2 6
53412- 2 2 6 2 2 6 18 18 18 86 86 86
53413- 42 42 42 14 14 14 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 0 0 0 0 0 0 0 0 0 0
53420- 0 0 0 0 0 0 0 0 0 0 0 0
53421- 0 0 0 0 0 0 0 0 0 14 14 14
53422- 42 42 42 90 90 90 22 22 22 2 2 6
53423- 42 42 42 2 2 6 18 18 18 218 218 218
53424-253 253 253 253 253 253 253 253 253 253 253 253
53425-253 253 253 253 253 253 253 253 253 253 253 253
53426-253 253 253 253 253 253 253 253 253 253 253 253
53427-253 253 253 253 253 253 253 253 253 253 253 253
53428-253 253 253 253 253 253 253 253 253 253 253 253
53429-253 253 253 253 253 253 250 250 250 221 221 221
53430-218 218 218 101 101 101 2 2 6 14 14 14
53431- 18 18 18 38 38 38 10 10 10 2 2 6
53432- 2 2 6 2 2 6 2 2 6 78 78 78
53433- 58 58 58 22 22 22 6 6 6 0 0 0
53434- 0 0 0 0 0 0 0 0 0 0 0 0
53435- 0 0 0 0 0 0 0 0 0 0 0 0
53436- 0 0 0 0 0 0 0 0 0 0 0 0
53437- 0 0 0 0 0 0 0 0 0 0 0 0
53438- 0 0 0 0 0 0 0 0 0 0 0 0
53439- 0 0 0 0 0 0 0 0 0 0 0 0
53440- 0 0 0 0 0 0 0 0 0 0 0 0
53441- 0 0 0 0 0 0 6 6 6 18 18 18
53442- 54 54 54 82 82 82 2 2 6 26 26 26
53443- 22 22 22 2 2 6 123 123 123 253 253 253
53444-253 253 253 253 253 253 253 253 253 253 253 253
53445-253 253 253 253 253 253 253 253 253 253 253 253
53446-253 253 253 253 253 253 253 253 253 253 253 253
53447-253 253 253 253 253 253 253 253 253 253 253 253
53448-253 253 253 253 253 253 253 253 253 253 253 253
53449-253 253 253 253 253 253 253 253 253 250 250 250
53450-238 238 238 198 198 198 6 6 6 38 38 38
53451- 58 58 58 26 26 26 38 38 38 2 2 6
53452- 2 2 6 2 2 6 2 2 6 46 46 46
53453- 78 78 78 30 30 30 10 10 10 0 0 0
53454- 0 0 0 0 0 0 0 0 0 0 0 0
53455- 0 0 0 0 0 0 0 0 0 0 0 0
53456- 0 0 0 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 0 0 0
53459- 0 0 0 0 0 0 0 0 0 0 0 0
53460- 0 0 0 0 0 0 0 0 0 0 0 0
53461- 0 0 0 0 0 0 10 10 10 30 30 30
53462- 74 74 74 58 58 58 2 2 6 42 42 42
53463- 2 2 6 22 22 22 231 231 231 253 253 253
53464-253 253 253 253 253 253 253 253 253 253 253 253
53465-253 253 253 253 253 253 253 253 253 250 250 250
53466-253 253 253 253 253 253 253 253 253 253 253 253
53467-253 253 253 253 253 253 253 253 253 253 253 253
53468-253 253 253 253 253 253 253 253 253 253 253 253
53469-253 253 253 253 253 253 253 253 253 253 253 253
53470-253 253 253 246 246 246 46 46 46 38 38 38
53471- 42 42 42 14 14 14 38 38 38 14 14 14
53472- 2 2 6 2 2 6 2 2 6 6 6 6
53473- 86 86 86 46 46 46 14 14 14 0 0 0
53474- 0 0 0 0 0 0 0 0 0 0 0 0
53475- 0 0 0 0 0 0 0 0 0 0 0 0
53476- 0 0 0 0 0 0 0 0 0 0 0 0
53477- 0 0 0 0 0 0 0 0 0 0 0 0
53478- 0 0 0 0 0 0 0 0 0 0 0 0
53479- 0 0 0 0 0 0 0 0 0 0 0 0
53480- 0 0 0 0 0 0 0 0 0 0 0 0
53481- 0 0 0 6 6 6 14 14 14 42 42 42
53482- 90 90 90 18 18 18 18 18 18 26 26 26
53483- 2 2 6 116 116 116 253 253 253 253 253 253
53484-253 253 253 253 253 253 253 253 253 253 253 253
53485-253 253 253 253 253 253 250 250 250 238 238 238
53486-253 253 253 253 253 253 253 253 253 253 253 253
53487-253 253 253 253 253 253 253 253 253 253 253 253
53488-253 253 253 253 253 253 253 253 253 253 253 253
53489-253 253 253 253 253 253 253 253 253 253 253 253
53490-253 253 253 253 253 253 94 94 94 6 6 6
53491- 2 2 6 2 2 6 10 10 10 34 34 34
53492- 2 2 6 2 2 6 2 2 6 2 2 6
53493- 74 74 74 58 58 58 22 22 22 6 6 6
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 0 0 0
53496- 0 0 0 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 0 0 0
53499- 0 0 0 0 0 0 0 0 0 0 0 0
53500- 0 0 0 0 0 0 0 0 0 0 0 0
53501- 0 0 0 10 10 10 26 26 26 66 66 66
53502- 82 82 82 2 2 6 38 38 38 6 6 6
53503- 14 14 14 210 210 210 253 253 253 253 253 253
53504-253 253 253 253 253 253 253 253 253 253 253 253
53505-253 253 253 253 253 253 246 246 246 242 242 242
53506-253 253 253 253 253 253 253 253 253 253 253 253
53507-253 253 253 253 253 253 253 253 253 253 253 253
53508-253 253 253 253 253 253 253 253 253 253 253 253
53509-253 253 253 253 253 253 253 253 253 253 253 253
53510-253 253 253 253 253 253 144 144 144 2 2 6
53511- 2 2 6 2 2 6 2 2 6 46 46 46
53512- 2 2 6 2 2 6 2 2 6 2 2 6
53513- 42 42 42 74 74 74 30 30 30 10 10 10
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 0 0 0 0 0 0
53516- 0 0 0 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 0 0 0 0
53519- 0 0 0 0 0 0 0 0 0 0 0 0
53520- 0 0 0 0 0 0 0 0 0 0 0 0
53521- 6 6 6 14 14 14 42 42 42 90 90 90
53522- 26 26 26 6 6 6 42 42 42 2 2 6
53523- 74 74 74 250 250 250 253 253 253 253 253 253
53524-253 253 253 253 253 253 253 253 253 253 253 253
53525-253 253 253 253 253 253 242 242 242 242 242 242
53526-253 253 253 253 253 253 253 253 253 253 253 253
53527-253 253 253 253 253 253 253 253 253 253 253 253
53528-253 253 253 253 253 253 253 253 253 253 253 253
53529-253 253 253 253 253 253 253 253 253 253 253 253
53530-253 253 253 253 253 253 182 182 182 2 2 6
53531- 2 2 6 2 2 6 2 2 6 46 46 46
53532- 2 2 6 2 2 6 2 2 6 2 2 6
53533- 10 10 10 86 86 86 38 38 38 10 10 10
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 0 0 0 0 0 0
53536- 0 0 0 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 0 0 0 0
53539- 0 0 0 0 0 0 0 0 0 0 0 0
53540- 0 0 0 0 0 0 0 0 0 0 0 0
53541- 10 10 10 26 26 26 66 66 66 82 82 82
53542- 2 2 6 22 22 22 18 18 18 2 2 6
53543-149 149 149 253 253 253 253 253 253 253 253 253
53544-253 253 253 253 253 253 253 253 253 253 253 253
53545-253 253 253 253 253 253 234 234 234 242 242 242
53546-253 253 253 253 253 253 253 253 253 253 253 253
53547-253 253 253 253 253 253 253 253 253 253 253 253
53548-253 253 253 253 253 253 253 253 253 253 253 253
53549-253 253 253 253 253 253 253 253 253 253 253 253
53550-253 253 253 253 253 253 206 206 206 2 2 6
53551- 2 2 6 2 2 6 2 2 6 38 38 38
53552- 2 2 6 2 2 6 2 2 6 2 2 6
53553- 6 6 6 86 86 86 46 46 46 14 14 14
53554- 0 0 0 0 0 0 0 0 0 0 0 0
53555- 0 0 0 0 0 0 0 0 0 0 0 0
53556- 0 0 0 0 0 0 0 0 0 0 0 0
53557- 0 0 0 0 0 0 0 0 0 0 0 0
53558- 0 0 0 0 0 0 0 0 0 0 0 0
53559- 0 0 0 0 0 0 0 0 0 0 0 0
53560- 0 0 0 0 0 0 0 0 0 6 6 6
53561- 18 18 18 46 46 46 86 86 86 18 18 18
53562- 2 2 6 34 34 34 10 10 10 6 6 6
53563-210 210 210 253 253 253 253 253 253 253 253 253
53564-253 253 253 253 253 253 253 253 253 253 253 253
53565-253 253 253 253 253 253 234 234 234 242 242 242
53566-253 253 253 253 253 253 253 253 253 253 253 253
53567-253 253 253 253 253 253 253 253 253 253 253 253
53568-253 253 253 253 253 253 253 253 253 253 253 253
53569-253 253 253 253 253 253 253 253 253 253 253 253
53570-253 253 253 253 253 253 221 221 221 6 6 6
53571- 2 2 6 2 2 6 6 6 6 30 30 30
53572- 2 2 6 2 2 6 2 2 6 2 2 6
53573- 2 2 6 82 82 82 54 54 54 18 18 18
53574- 6 6 6 0 0 0 0 0 0 0 0 0
53575- 0 0 0 0 0 0 0 0 0 0 0 0
53576- 0 0 0 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 0 0 0 0 0 0 0 0 0 0 0 0
53579- 0 0 0 0 0 0 0 0 0 0 0 0
53580- 0 0 0 0 0 0 0 0 0 10 10 10
53581- 26 26 26 66 66 66 62 62 62 2 2 6
53582- 2 2 6 38 38 38 10 10 10 26 26 26
53583-238 238 238 253 253 253 253 253 253 253 253 253
53584-253 253 253 253 253 253 253 253 253 253 253 253
53585-253 253 253 253 253 253 231 231 231 238 238 238
53586-253 253 253 253 253 253 253 253 253 253 253 253
53587-253 253 253 253 253 253 253 253 253 253 253 253
53588-253 253 253 253 253 253 253 253 253 253 253 253
53589-253 253 253 253 253 253 253 253 253 253 253 253
53590-253 253 253 253 253 253 231 231 231 6 6 6
53591- 2 2 6 2 2 6 10 10 10 30 30 30
53592- 2 2 6 2 2 6 2 2 6 2 2 6
53593- 2 2 6 66 66 66 58 58 58 22 22 22
53594- 6 6 6 0 0 0 0 0 0 0 0 0
53595- 0 0 0 0 0 0 0 0 0 0 0 0
53596- 0 0 0 0 0 0 0 0 0 0 0 0
53597- 0 0 0 0 0 0 0 0 0 0 0 0
53598- 0 0 0 0 0 0 0 0 0 0 0 0
53599- 0 0 0 0 0 0 0 0 0 0 0 0
53600- 0 0 0 0 0 0 0 0 0 10 10 10
53601- 38 38 38 78 78 78 6 6 6 2 2 6
53602- 2 2 6 46 46 46 14 14 14 42 42 42
53603-246 246 246 253 253 253 253 253 253 253 253 253
53604-253 253 253 253 253 253 253 253 253 253 253 253
53605-253 253 253 253 253 253 231 231 231 242 242 242
53606-253 253 253 253 253 253 253 253 253 253 253 253
53607-253 253 253 253 253 253 253 253 253 253 253 253
53608-253 253 253 253 253 253 253 253 253 253 253 253
53609-253 253 253 253 253 253 253 253 253 253 253 253
53610-253 253 253 253 253 253 234 234 234 10 10 10
53611- 2 2 6 2 2 6 22 22 22 14 14 14
53612- 2 2 6 2 2 6 2 2 6 2 2 6
53613- 2 2 6 66 66 66 62 62 62 22 22 22
53614- 6 6 6 0 0 0 0 0 0 0 0 0
53615- 0 0 0 0 0 0 0 0 0 0 0 0
53616- 0 0 0 0 0 0 0 0 0 0 0 0
53617- 0 0 0 0 0 0 0 0 0 0 0 0
53618- 0 0 0 0 0 0 0 0 0 0 0 0
53619- 0 0 0 0 0 0 0 0 0 0 0 0
53620- 0 0 0 0 0 0 6 6 6 18 18 18
53621- 50 50 50 74 74 74 2 2 6 2 2 6
53622- 14 14 14 70 70 70 34 34 34 62 62 62
53623-250 250 250 253 253 253 253 253 253 253 253 253
53624-253 253 253 253 253 253 253 253 253 253 253 253
53625-253 253 253 253 253 253 231 231 231 246 246 246
53626-253 253 253 253 253 253 253 253 253 253 253 253
53627-253 253 253 253 253 253 253 253 253 253 253 253
53628-253 253 253 253 253 253 253 253 253 253 253 253
53629-253 253 253 253 253 253 253 253 253 253 253 253
53630-253 253 253 253 253 253 234 234 234 14 14 14
53631- 2 2 6 2 2 6 30 30 30 2 2 6
53632- 2 2 6 2 2 6 2 2 6 2 2 6
53633- 2 2 6 66 66 66 62 62 62 22 22 22
53634- 6 6 6 0 0 0 0 0 0 0 0 0
53635- 0 0 0 0 0 0 0 0 0 0 0 0
53636- 0 0 0 0 0 0 0 0 0 0 0 0
53637- 0 0 0 0 0 0 0 0 0 0 0 0
53638- 0 0 0 0 0 0 0 0 0 0 0 0
53639- 0 0 0 0 0 0 0 0 0 0 0 0
53640- 0 0 0 0 0 0 6 6 6 18 18 18
53641- 54 54 54 62 62 62 2 2 6 2 2 6
53642- 2 2 6 30 30 30 46 46 46 70 70 70
53643-250 250 250 253 253 253 253 253 253 253 253 253
53644-253 253 253 253 253 253 253 253 253 253 253 253
53645-253 253 253 253 253 253 231 231 231 246 246 246
53646-253 253 253 253 253 253 253 253 253 253 253 253
53647-253 253 253 253 253 253 253 253 253 253 253 253
53648-253 253 253 253 253 253 253 253 253 253 253 253
53649-253 253 253 253 253 253 253 253 253 253 253 253
53650-253 253 253 253 253 253 226 226 226 10 10 10
53651- 2 2 6 6 6 6 30 30 30 2 2 6
53652- 2 2 6 2 2 6 2 2 6 2 2 6
53653- 2 2 6 66 66 66 58 58 58 22 22 22
53654- 6 6 6 0 0 0 0 0 0 0 0 0
53655- 0 0 0 0 0 0 0 0 0 0 0 0
53656- 0 0 0 0 0 0 0 0 0 0 0 0
53657- 0 0 0 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 0 0 0 0 0 0
53659- 0 0 0 0 0 0 0 0 0 0 0 0
53660- 0 0 0 0 0 0 6 6 6 22 22 22
53661- 58 58 58 62 62 62 2 2 6 2 2 6
53662- 2 2 6 2 2 6 30 30 30 78 78 78
53663-250 250 250 253 253 253 253 253 253 253 253 253
53664-253 253 253 253 253 253 253 253 253 253 253 253
53665-253 253 253 253 253 253 231 231 231 246 246 246
53666-253 253 253 253 253 253 253 253 253 253 253 253
53667-253 253 253 253 253 253 253 253 253 253 253 253
53668-253 253 253 253 253 253 253 253 253 253 253 253
53669-253 253 253 253 253 253 253 253 253 253 253 253
53670-253 253 253 253 253 253 206 206 206 2 2 6
53671- 22 22 22 34 34 34 18 14 6 22 22 22
53672- 26 26 26 18 18 18 6 6 6 2 2 6
53673- 2 2 6 82 82 82 54 54 54 18 18 18
53674- 6 6 6 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 0 0 0 0 0 0 0 0 0
53677- 0 0 0 0 0 0 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 0 0 0
53679- 0 0 0 0 0 0 0 0 0 0 0 0
53680- 0 0 0 0 0 0 6 6 6 26 26 26
53681- 62 62 62 106 106 106 74 54 14 185 133 11
53682-210 162 10 121 92 8 6 6 6 62 62 62
53683-238 238 238 253 253 253 253 253 253 253 253 253
53684-253 253 253 253 253 253 253 253 253 253 253 253
53685-253 253 253 253 253 253 231 231 231 246 246 246
53686-253 253 253 253 253 253 253 253 253 253 253 253
53687-253 253 253 253 253 253 253 253 253 253 253 253
53688-253 253 253 253 253 253 253 253 253 253 253 253
53689-253 253 253 253 253 253 253 253 253 253 253 253
53690-253 253 253 253 253 253 158 158 158 18 18 18
53691- 14 14 14 2 2 6 2 2 6 2 2 6
53692- 6 6 6 18 18 18 66 66 66 38 38 38
53693- 6 6 6 94 94 94 50 50 50 18 18 18
53694- 6 6 6 0 0 0 0 0 0 0 0 0
53695- 0 0 0 0 0 0 0 0 0 0 0 0
53696- 0 0 0 0 0 0 0 0 0 0 0 0
53697- 0 0 0 0 0 0 0 0 0 0 0 0
53698- 0 0 0 0 0 0 0 0 0 0 0 0
53699- 0 0 0 0 0 0 0 0 0 6 6 6
53700- 10 10 10 10 10 10 18 18 18 38 38 38
53701- 78 78 78 142 134 106 216 158 10 242 186 14
53702-246 190 14 246 190 14 156 118 10 10 10 10
53703- 90 90 90 238 238 238 253 253 253 253 253 253
53704-253 253 253 253 253 253 253 253 253 253 253 253
53705-253 253 253 253 253 253 231 231 231 250 250 250
53706-253 253 253 253 253 253 253 253 253 253 253 253
53707-253 253 253 253 253 253 253 253 253 253 253 253
53708-253 253 253 253 253 253 253 253 253 253 253 253
53709-253 253 253 253 253 253 253 253 253 246 230 190
53710-238 204 91 238 204 91 181 142 44 37 26 9
53711- 2 2 6 2 2 6 2 2 6 2 2 6
53712- 2 2 6 2 2 6 38 38 38 46 46 46
53713- 26 26 26 106 106 106 54 54 54 18 18 18
53714- 6 6 6 0 0 0 0 0 0 0 0 0
53715- 0 0 0 0 0 0 0 0 0 0 0 0
53716- 0 0 0 0 0 0 0 0 0 0 0 0
53717- 0 0 0 0 0 0 0 0 0 0 0 0
53718- 0 0 0 0 0 0 0 0 0 0 0 0
53719- 0 0 0 6 6 6 14 14 14 22 22 22
53720- 30 30 30 38 38 38 50 50 50 70 70 70
53721-106 106 106 190 142 34 226 170 11 242 186 14
53722-246 190 14 246 190 14 246 190 14 154 114 10
53723- 6 6 6 74 74 74 226 226 226 253 253 253
53724-253 253 253 253 253 253 253 253 253 253 253 253
53725-253 253 253 253 253 253 231 231 231 250 250 250
53726-253 253 253 253 253 253 253 253 253 253 253 253
53727-253 253 253 253 253 253 253 253 253 253 253 253
53728-253 253 253 253 253 253 253 253 253 253 253 253
53729-253 253 253 253 253 253 253 253 253 228 184 62
53730-241 196 14 241 208 19 232 195 16 38 30 10
53731- 2 2 6 2 2 6 2 2 6 2 2 6
53732- 2 2 6 6 6 6 30 30 30 26 26 26
53733-203 166 17 154 142 90 66 66 66 26 26 26
53734- 6 6 6 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 0 0 0 0 0 0 0 0 0 0 0 0
53737- 0 0 0 0 0 0 0 0 0 0 0 0
53738- 0 0 0 0 0 0 0 0 0 0 0 0
53739- 6 6 6 18 18 18 38 38 38 58 58 58
53740- 78 78 78 86 86 86 101 101 101 123 123 123
53741-175 146 61 210 150 10 234 174 13 246 186 14
53742-246 190 14 246 190 14 246 190 14 238 190 10
53743-102 78 10 2 2 6 46 46 46 198 198 198
53744-253 253 253 253 253 253 253 253 253 253 253 253
53745-253 253 253 253 253 253 234 234 234 242 242 242
53746-253 253 253 253 253 253 253 253 253 253 253 253
53747-253 253 253 253 253 253 253 253 253 253 253 253
53748-253 253 253 253 253 253 253 253 253 253 253 253
53749-253 253 253 253 253 253 253 253 253 224 178 62
53750-242 186 14 241 196 14 210 166 10 22 18 6
53751- 2 2 6 2 2 6 2 2 6 2 2 6
53752- 2 2 6 2 2 6 6 6 6 121 92 8
53753-238 202 15 232 195 16 82 82 82 34 34 34
53754- 10 10 10 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 0 0 0 0 0 0
53758- 0 0 0 0 0 0 0 0 0 0 0 0
53759- 14 14 14 38 38 38 70 70 70 154 122 46
53760-190 142 34 200 144 11 197 138 11 197 138 11
53761-213 154 11 226 170 11 242 186 14 246 190 14
53762-246 190 14 246 190 14 246 190 14 246 190 14
53763-225 175 15 46 32 6 2 2 6 22 22 22
53764-158 158 158 250 250 250 253 253 253 253 253 253
53765-253 253 253 253 253 253 253 253 253 253 253 253
53766-253 253 253 253 253 253 253 253 253 253 253 253
53767-253 253 253 253 253 253 253 253 253 253 253 253
53768-253 253 253 253 253 253 253 253 253 253 253 253
53769-253 253 253 250 250 250 242 242 242 224 178 62
53770-239 182 13 236 186 11 213 154 11 46 32 6
53771- 2 2 6 2 2 6 2 2 6 2 2 6
53772- 2 2 6 2 2 6 61 42 6 225 175 15
53773-238 190 10 236 186 11 112 100 78 42 42 42
53774- 14 14 14 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 0 0 0
53776- 0 0 0 0 0 0 0 0 0 0 0 0
53777- 0 0 0 0 0 0 0 0 0 0 0 0
53778- 0 0 0 0 0 0 0 0 0 6 6 6
53779- 22 22 22 54 54 54 154 122 46 213 154 11
53780-226 170 11 230 174 11 226 170 11 226 170 11
53781-236 178 12 242 186 14 246 190 14 246 190 14
53782-246 190 14 246 190 14 246 190 14 246 190 14
53783-241 196 14 184 144 12 10 10 10 2 2 6
53784- 6 6 6 116 116 116 242 242 242 253 253 253
53785-253 253 253 253 253 253 253 253 253 253 253 253
53786-253 253 253 253 253 253 253 253 253 253 253 253
53787-253 253 253 253 253 253 253 253 253 253 253 253
53788-253 253 253 253 253 253 253 253 253 253 253 253
53789-253 253 253 231 231 231 198 198 198 214 170 54
53790-236 178 12 236 178 12 210 150 10 137 92 6
53791- 18 14 6 2 2 6 2 2 6 2 2 6
53792- 6 6 6 70 47 6 200 144 11 236 178 12
53793-239 182 13 239 182 13 124 112 88 58 58 58
53794- 22 22 22 6 6 6 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 0 0 0 0 0 0 0 0 0 0 0 0
53798- 0 0 0 0 0 0 0 0 0 10 10 10
53799- 30 30 30 70 70 70 180 133 36 226 170 11
53800-239 182 13 242 186 14 242 186 14 246 186 14
53801-246 190 14 246 190 14 246 190 14 246 190 14
53802-246 190 14 246 190 14 246 190 14 246 190 14
53803-246 190 14 232 195 16 98 70 6 2 2 6
53804- 2 2 6 2 2 6 66 66 66 221 221 221
53805-253 253 253 253 253 253 253 253 253 253 253 253
53806-253 253 253 253 253 253 253 253 253 253 253 253
53807-253 253 253 253 253 253 253 253 253 253 253 253
53808-253 253 253 253 253 253 253 253 253 253 253 253
53809-253 253 253 206 206 206 198 198 198 214 166 58
53810-230 174 11 230 174 11 216 158 10 192 133 9
53811-163 110 8 116 81 8 102 78 10 116 81 8
53812-167 114 7 197 138 11 226 170 11 239 182 13
53813-242 186 14 242 186 14 162 146 94 78 78 78
53814- 34 34 34 14 14 14 6 6 6 0 0 0
53815- 0 0 0 0 0 0 0 0 0 0 0 0
53816- 0 0 0 0 0 0 0 0 0 0 0 0
53817- 0 0 0 0 0 0 0 0 0 0 0 0
53818- 0 0 0 0 0 0 0 0 0 6 6 6
53819- 30 30 30 78 78 78 190 142 34 226 170 11
53820-239 182 13 246 190 14 246 190 14 246 190 14
53821-246 190 14 246 190 14 246 190 14 246 190 14
53822-246 190 14 246 190 14 246 190 14 246 190 14
53823-246 190 14 241 196 14 203 166 17 22 18 6
53824- 2 2 6 2 2 6 2 2 6 38 38 38
53825-218 218 218 253 253 253 253 253 253 253 253 253
53826-253 253 253 253 253 253 253 253 253 253 253 253
53827-253 253 253 253 253 253 253 253 253 253 253 253
53828-253 253 253 253 253 253 253 253 253 253 253 253
53829-250 250 250 206 206 206 198 198 198 202 162 69
53830-226 170 11 236 178 12 224 166 10 210 150 10
53831-200 144 11 197 138 11 192 133 9 197 138 11
53832-210 150 10 226 170 11 242 186 14 246 190 14
53833-246 190 14 246 186 14 225 175 15 124 112 88
53834- 62 62 62 30 30 30 14 14 14 6 6 6
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 0 0 0 0 0 0 0 0 0 0 0 0
53838- 0 0 0 0 0 0 0 0 0 10 10 10
53839- 30 30 30 78 78 78 174 135 50 224 166 10
53840-239 182 13 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 241 196 14 139 102 15
53844- 2 2 6 2 2 6 2 2 6 2 2 6
53845- 78 78 78 250 250 250 253 253 253 253 253 253
53846-253 253 253 253 253 253 253 253 253 253 253 253
53847-253 253 253 253 253 253 253 253 253 253 253 253
53848-253 253 253 253 253 253 253 253 253 253 253 253
53849-250 250 250 214 214 214 198 198 198 190 150 46
53850-219 162 10 236 178 12 234 174 13 224 166 10
53851-216 158 10 213 154 11 213 154 11 216 158 10
53852-226 170 11 239 182 13 246 190 14 246 190 14
53853-246 190 14 246 190 14 242 186 14 206 162 42
53854-101 101 101 58 58 58 30 30 30 14 14 14
53855- 6 6 6 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 0 0 0
53857- 0 0 0 0 0 0 0 0 0 0 0 0
53858- 0 0 0 0 0 0 0 0 0 10 10 10
53859- 30 30 30 74 74 74 174 135 50 216 158 10
53860-236 178 12 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 190 14 241 196 14 226 184 13
53864- 61 42 6 2 2 6 2 2 6 2 2 6
53865- 22 22 22 238 238 238 253 253 253 253 253 253
53866-253 253 253 253 253 253 253 253 253 253 253 253
53867-253 253 253 253 253 253 253 253 253 253 253 253
53868-253 253 253 253 253 253 253 253 253 253 253 253
53869-253 253 253 226 226 226 187 187 187 180 133 36
53870-216 158 10 236 178 12 239 182 13 236 178 12
53871-230 174 11 226 170 11 226 170 11 230 174 11
53872-236 178 12 242 186 14 246 190 14 246 190 14
53873-246 190 14 246 190 14 246 186 14 239 182 13
53874-206 162 42 106 106 106 66 66 66 34 34 34
53875- 14 14 14 6 6 6 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 0 0 0 0 0 0
53878- 0 0 0 0 0 0 0 0 0 6 6 6
53879- 26 26 26 70 70 70 163 133 67 213 154 11
53880-236 178 12 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 190 14 246 190 14 246 190 14 241 196 14
53884-190 146 13 18 14 6 2 2 6 2 2 6
53885- 46 46 46 246 246 246 253 253 253 253 253 253
53886-253 253 253 253 253 253 253 253 253 253 253 253
53887-253 253 253 253 253 253 253 253 253 253 253 253
53888-253 253 253 253 253 253 253 253 253 253 253 253
53889-253 253 253 221 221 221 86 86 86 156 107 11
53890-216 158 10 236 178 12 242 186 14 246 186 14
53891-242 186 14 239 182 13 239 182 13 242 186 14
53892-242 186 14 246 186 14 246 190 14 246 190 14
53893-246 190 14 246 190 14 246 190 14 246 190 14
53894-242 186 14 225 175 15 142 122 72 66 66 66
53895- 30 30 30 10 10 10 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 0 0 0 0 0 0 0 0 0
53898- 0 0 0 0 0 0 0 0 0 6 6 6
53899- 26 26 26 70 70 70 163 133 67 210 150 10
53900-236 178 12 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 246 190 14
53903-246 190 14 246 190 14 246 190 14 246 190 14
53904-232 195 16 121 92 8 34 34 34 106 106 106
53905-221 221 221 253 253 253 253 253 253 253 253 253
53906-253 253 253 253 253 253 253 253 253 253 253 253
53907-253 253 253 253 253 253 253 253 253 253 253 253
53908-253 253 253 253 253 253 253 253 253 253 253 253
53909-242 242 242 82 82 82 18 14 6 163 110 8
53910-216 158 10 236 178 12 242 186 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 190 14 246 190 14 246 190 14 246 190 14
53914-246 190 14 246 190 14 242 186 14 163 133 67
53915- 46 46 46 18 18 18 6 6 6 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 0 0 0 0 0 0 0 0 0
53918- 0 0 0 0 0 0 0 0 0 10 10 10
53919- 30 30 30 78 78 78 163 133 67 210 150 10
53920-236 178 12 246 186 14 246 190 14 246 190 14
53921-246 190 14 246 190 14 246 190 14 246 190 14
53922-246 190 14 246 190 14 246 190 14 246 190 14
53923-246 190 14 246 190 14 246 190 14 246 190 14
53924-241 196 14 215 174 15 190 178 144 253 253 253
53925-253 253 253 253 253 253 253 253 253 253 253 253
53926-253 253 253 253 253 253 253 253 253 253 253 253
53927-253 253 253 253 253 253 253 253 253 253 253 253
53928-253 253 253 253 253 253 253 253 253 218 218 218
53929- 58 58 58 2 2 6 22 18 6 167 114 7
53930-216 158 10 236 178 12 246 186 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 246 190 14 246 190 14 246 190 14
53934-246 190 14 246 186 14 242 186 14 190 150 46
53935- 54 54 54 22 22 22 6 6 6 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 0 0 0 0 0 0 0 0 0 0 0 0
53938- 0 0 0 0 0 0 0 0 0 14 14 14
53939- 38 38 38 86 86 86 180 133 36 213 154 11
53940-236 178 12 246 186 14 246 190 14 246 190 14
53941-246 190 14 246 190 14 246 190 14 246 190 14
53942-246 190 14 246 190 14 246 190 14 246 190 14
53943-246 190 14 246 190 14 246 190 14 246 190 14
53944-246 190 14 232 195 16 190 146 13 214 214 214
53945-253 253 253 253 253 253 253 253 253 253 253 253
53946-253 253 253 253 253 253 253 253 253 253 253 253
53947-253 253 253 253 253 253 253 253 253 253 253 253
53948-253 253 253 250 250 250 170 170 170 26 26 26
53949- 2 2 6 2 2 6 37 26 9 163 110 8
53950-219 162 10 239 182 13 246 186 14 246 190 14
53951-246 190 14 246 190 14 246 190 14 246 190 14
53952-246 190 14 246 190 14 246 190 14 246 190 14
53953-246 190 14 246 190 14 246 190 14 246 190 14
53954-246 186 14 236 178 12 224 166 10 142 122 72
53955- 46 46 46 18 18 18 6 6 6 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 0 0 0 0 0 0 0 0 0 0 0 0
53958- 0 0 0 0 0 0 6 6 6 18 18 18
53959- 50 50 50 109 106 95 192 133 9 224 166 10
53960-242 186 14 246 190 14 246 190 14 246 190 14
53961-246 190 14 246 190 14 246 190 14 246 190 14
53962-246 190 14 246 190 14 246 190 14 246 190 14
53963-246 190 14 246 190 14 246 190 14 246 190 14
53964-242 186 14 226 184 13 210 162 10 142 110 46
53965-226 226 226 253 253 253 253 253 253 253 253 253
53966-253 253 253 253 253 253 253 253 253 253 253 253
53967-253 253 253 253 253 253 253 253 253 253 253 253
53968-198 198 198 66 66 66 2 2 6 2 2 6
53969- 2 2 6 2 2 6 50 34 6 156 107 11
53970-219 162 10 239 182 13 246 186 14 246 190 14
53971-246 190 14 246 190 14 246 190 14 246 190 14
53972-246 190 14 246 190 14 246 190 14 246 190 14
53973-246 190 14 246 190 14 246 190 14 242 186 14
53974-234 174 13 213 154 11 154 122 46 66 66 66
53975- 30 30 30 10 10 10 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 0 0 0
53977- 0 0 0 0 0 0 0 0 0 0 0 0
53978- 0 0 0 0 0 0 6 6 6 22 22 22
53979- 58 58 58 154 121 60 206 145 10 234 174 13
53980-242 186 14 246 186 14 246 190 14 246 190 14
53981-246 190 14 246 190 14 246 190 14 246 190 14
53982-246 190 14 246 190 14 246 190 14 246 190 14
53983-246 190 14 246 190 14 246 190 14 246 190 14
53984-246 186 14 236 178 12 210 162 10 163 110 8
53985- 61 42 6 138 138 138 218 218 218 250 250 250
53986-253 253 253 253 253 253 253 253 253 250 250 250
53987-242 242 242 210 210 210 144 144 144 66 66 66
53988- 6 6 6 2 2 6 2 2 6 2 2 6
53989- 2 2 6 2 2 6 61 42 6 163 110 8
53990-216 158 10 236 178 12 246 190 14 246 190 14
53991-246 190 14 246 190 14 246 190 14 246 190 14
53992-246 190 14 246 190 14 246 190 14 246 190 14
53993-246 190 14 239 182 13 230 174 11 216 158 10
53994-190 142 34 124 112 88 70 70 70 38 38 38
53995- 18 18 18 6 6 6 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 0 0 0
53997- 0 0 0 0 0 0 0 0 0 0 0 0
53998- 0 0 0 0 0 0 6 6 6 22 22 22
53999- 62 62 62 168 124 44 206 145 10 224 166 10
54000-236 178 12 239 182 13 242 186 14 242 186 14
54001-246 186 14 246 190 14 246 190 14 246 190 14
54002-246 190 14 246 190 14 246 190 14 246 190 14
54003-246 190 14 246 190 14 246 190 14 246 190 14
54004-246 190 14 236 178 12 216 158 10 175 118 6
54005- 80 54 7 2 2 6 6 6 6 30 30 30
54006- 54 54 54 62 62 62 50 50 50 38 38 38
54007- 14 14 14 2 2 6 2 2 6 2 2 6
54008- 2 2 6 2 2 6 2 2 6 2 2 6
54009- 2 2 6 6 6 6 80 54 7 167 114 7
54010-213 154 11 236 178 12 246 190 14 246 190 14
54011-246 190 14 246 190 14 246 190 14 246 190 14
54012-246 190 14 242 186 14 239 182 13 239 182 13
54013-230 174 11 210 150 10 174 135 50 124 112 88
54014- 82 82 82 54 54 54 34 34 34 18 18 18
54015- 6 6 6 0 0 0 0 0 0 0 0 0
54016- 0 0 0 0 0 0 0 0 0 0 0 0
54017- 0 0 0 0 0 0 0 0 0 0 0 0
54018- 0 0 0 0 0 0 6 6 6 18 18 18
54019- 50 50 50 158 118 36 192 133 9 200 144 11
54020-216 158 10 219 162 10 224 166 10 226 170 11
54021-230 174 11 236 178 12 239 182 13 239 182 13
54022-242 186 14 246 186 14 246 190 14 246 190 14
54023-246 190 14 246 190 14 246 190 14 246 190 14
54024-246 186 14 230 174 11 210 150 10 163 110 8
54025-104 69 6 10 10 10 2 2 6 2 2 6
54026- 2 2 6 2 2 6 2 2 6 2 2 6
54027- 2 2 6 2 2 6 2 2 6 2 2 6
54028- 2 2 6 2 2 6 2 2 6 2 2 6
54029- 2 2 6 6 6 6 91 60 6 167 114 7
54030-206 145 10 230 174 11 242 186 14 246 190 14
54031-246 190 14 246 190 14 246 186 14 242 186 14
54032-239 182 13 230 174 11 224 166 10 213 154 11
54033-180 133 36 124 112 88 86 86 86 58 58 58
54034- 38 38 38 22 22 22 10 10 10 6 6 6
54035- 0 0 0 0 0 0 0 0 0 0 0 0
54036- 0 0 0 0 0 0 0 0 0 0 0 0
54037- 0 0 0 0 0 0 0 0 0 0 0 0
54038- 0 0 0 0 0 0 0 0 0 14 14 14
54039- 34 34 34 70 70 70 138 110 50 158 118 36
54040-167 114 7 180 123 7 192 133 9 197 138 11
54041-200 144 11 206 145 10 213 154 11 219 162 10
54042-224 166 10 230 174 11 239 182 13 242 186 14
54043-246 186 14 246 186 14 246 186 14 246 186 14
54044-239 182 13 216 158 10 185 133 11 152 99 6
54045-104 69 6 18 14 6 2 2 6 2 2 6
54046- 2 2 6 2 2 6 2 2 6 2 2 6
54047- 2 2 6 2 2 6 2 2 6 2 2 6
54048- 2 2 6 2 2 6 2 2 6 2 2 6
54049- 2 2 6 6 6 6 80 54 7 152 99 6
54050-192 133 9 219 162 10 236 178 12 239 182 13
54051-246 186 14 242 186 14 239 182 13 236 178 12
54052-224 166 10 206 145 10 192 133 9 154 121 60
54053- 94 94 94 62 62 62 42 42 42 22 22 22
54054- 14 14 14 6 6 6 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 0 0 0
54056- 0 0 0 0 0 0 0 0 0 0 0 0
54057- 0 0 0 0 0 0 0 0 0 0 0 0
54058- 0 0 0 0 0 0 0 0 0 6 6 6
54059- 18 18 18 34 34 34 58 58 58 78 78 78
54060-101 98 89 124 112 88 142 110 46 156 107 11
54061-163 110 8 167 114 7 175 118 6 180 123 7
54062-185 133 11 197 138 11 210 150 10 219 162 10
54063-226 170 11 236 178 12 236 178 12 234 174 13
54064-219 162 10 197 138 11 163 110 8 130 83 6
54065- 91 60 6 10 10 10 2 2 6 2 2 6
54066- 18 18 18 38 38 38 38 38 38 38 38 38
54067- 38 38 38 38 38 38 38 38 38 38 38 38
54068- 38 38 38 38 38 38 26 26 26 2 2 6
54069- 2 2 6 6 6 6 70 47 6 137 92 6
54070-175 118 6 200 144 11 219 162 10 230 174 11
54071-234 174 13 230 174 11 219 162 10 210 150 10
54072-192 133 9 163 110 8 124 112 88 82 82 82
54073- 50 50 50 30 30 30 14 14 14 6 6 6
54074- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
54079- 6 6 6 14 14 14 22 22 22 34 34 34
54080- 42 42 42 58 58 58 74 74 74 86 86 86
54081-101 98 89 122 102 70 130 98 46 121 87 25
54082-137 92 6 152 99 6 163 110 8 180 123 7
54083-185 133 11 197 138 11 206 145 10 200 144 11
54084-180 123 7 156 107 11 130 83 6 104 69 6
54085- 50 34 6 54 54 54 110 110 110 101 98 89
54086- 86 86 86 82 82 82 78 78 78 78 78 78
54087- 78 78 78 78 78 78 78 78 78 78 78 78
54088- 78 78 78 82 82 82 86 86 86 94 94 94
54089-106 106 106 101 101 101 86 66 34 124 80 6
54090-156 107 11 180 123 7 192 133 9 200 144 11
54091-206 145 10 200 144 11 192 133 9 175 118 6
54092-139 102 15 109 106 95 70 70 70 42 42 42
54093- 22 22 22 10 10 10 0 0 0 0 0 0
54094- 0 0 0 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 0 0 0 0 0 0 0 0 0
54099- 0 0 0 0 0 0 6 6 6 10 10 10
54100- 14 14 14 22 22 22 30 30 30 38 38 38
54101- 50 50 50 62 62 62 74 74 74 90 90 90
54102-101 98 89 112 100 78 121 87 25 124 80 6
54103-137 92 6 152 99 6 152 99 6 152 99 6
54104-138 86 6 124 80 6 98 70 6 86 66 30
54105-101 98 89 82 82 82 58 58 58 46 46 46
54106- 38 38 38 34 34 34 34 34 34 34 34 34
54107- 34 34 34 34 34 34 34 34 34 34 34 34
54108- 34 34 34 34 34 34 38 38 38 42 42 42
54109- 54 54 54 82 82 82 94 86 76 91 60 6
54110-134 86 6 156 107 11 167 114 7 175 118 6
54111-175 118 6 167 114 7 152 99 6 121 87 25
54112-101 98 89 62 62 62 34 34 34 18 18 18
54113- 6 6 6 0 0 0 0 0 0 0 0 0
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 0 0 0
54119- 0 0 0 0 0 0 0 0 0 0 0 0
54120- 0 0 0 6 6 6 6 6 6 10 10 10
54121- 18 18 18 22 22 22 30 30 30 42 42 42
54122- 50 50 50 66 66 66 86 86 86 101 98 89
54123-106 86 58 98 70 6 104 69 6 104 69 6
54124-104 69 6 91 60 6 82 62 34 90 90 90
54125- 62 62 62 38 38 38 22 22 22 14 14 14
54126- 10 10 10 10 10 10 10 10 10 10 10 10
54127- 10 10 10 10 10 10 6 6 6 10 10 10
54128- 10 10 10 10 10 10 10 10 10 14 14 14
54129- 22 22 22 42 42 42 70 70 70 89 81 66
54130- 80 54 7 104 69 6 124 80 6 137 92 6
54131-134 86 6 116 81 8 100 82 52 86 86 86
54132- 58 58 58 30 30 30 14 14 14 6 6 6
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 0 0 0 0 0 0 0 0 0
54136- 0 0 0 0 0 0 0 0 0 0 0 0
54137- 0 0 0 0 0 0 0 0 0 0 0 0
54138- 0 0 0 0 0 0 0 0 0 0 0 0
54139- 0 0 0 0 0 0 0 0 0 0 0 0
54140- 0 0 0 0 0 0 0 0 0 0 0 0
54141- 0 0 0 6 6 6 10 10 10 14 14 14
54142- 18 18 18 26 26 26 38 38 38 54 54 54
54143- 70 70 70 86 86 86 94 86 76 89 81 66
54144- 89 81 66 86 86 86 74 74 74 50 50 50
54145- 30 30 30 14 14 14 6 6 6 0 0 0
54146- 0 0 0 0 0 0 0 0 0 0 0 0
54147- 0 0 0 0 0 0 0 0 0 0 0 0
54148- 0 0 0 0 0 0 0 0 0 0 0 0
54149- 6 6 6 18 18 18 34 34 34 58 58 58
54150- 82 82 82 89 81 66 89 81 66 89 81 66
54151- 94 86 66 94 86 76 74 74 74 50 50 50
54152- 26 26 26 14 14 14 6 6 6 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 0 0 0 0 0 0 0 0 0 0 0 0
54156- 0 0 0 0 0 0 0 0 0 0 0 0
54157- 0 0 0 0 0 0 0 0 0 0 0 0
54158- 0 0 0 0 0 0 0 0 0 0 0 0
54159- 0 0 0 0 0 0 0 0 0 0 0 0
54160- 0 0 0 0 0 0 0 0 0 0 0 0
54161- 0 0 0 0 0 0 0 0 0 0 0 0
54162- 6 6 6 6 6 6 14 14 14 18 18 18
54163- 30 30 30 38 38 38 46 46 46 54 54 54
54164- 50 50 50 42 42 42 30 30 30 18 18 18
54165- 10 10 10 0 0 0 0 0 0 0 0 0
54166- 0 0 0 0 0 0 0 0 0 0 0 0
54167- 0 0 0 0 0 0 0 0 0 0 0 0
54168- 0 0 0 0 0 0 0 0 0 0 0 0
54169- 0 0 0 6 6 6 14 14 14 26 26 26
54170- 38 38 38 50 50 50 58 58 58 58 58 58
54171- 54 54 54 42 42 42 30 30 30 18 18 18
54172- 10 10 10 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 0 0 0
54175- 0 0 0 0 0 0 0 0 0 0 0 0
54176- 0 0 0 0 0 0 0 0 0 0 0 0
54177- 0 0 0 0 0 0 0 0 0 0 0 0
54178- 0 0 0 0 0 0 0 0 0 0 0 0
54179- 0 0 0 0 0 0 0 0 0 0 0 0
54180- 0 0 0 0 0 0 0 0 0 0 0 0
54181- 0 0 0 0 0 0 0 0 0 0 0 0
54182- 0 0 0 0 0 0 0 0 0 6 6 6
54183- 6 6 6 10 10 10 14 14 14 18 18 18
54184- 18 18 18 14 14 14 10 10 10 6 6 6
54185- 0 0 0 0 0 0 0 0 0 0 0 0
54186- 0 0 0 0 0 0 0 0 0 0 0 0
54187- 0 0 0 0 0 0 0 0 0 0 0 0
54188- 0 0 0 0 0 0 0 0 0 0 0 0
54189- 0 0 0 0 0 0 0 0 0 6 6 6
54190- 14 14 14 18 18 18 22 22 22 22 22 22
54191- 18 18 18 14 14 14 10 10 10 6 6 6
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 0 0 0 0 0 0 0 0 0
54195- 0 0 0 0 0 0 0 0 0 0 0 0
54196- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
54210+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 4 4 4 4 4 4 4 4 4
54215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
54224+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 4 4 4 4 4 4 4 4 4 4 4 4
54229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54230+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54238+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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54244+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54252+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 4 4 4 4 4 4 4 4 4 4 4 4
54256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54266+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54280+4 4 4 4 4 4
54281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54285+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54286+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54290+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54291+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54292+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54294+4 4 4 4 4 4
54295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54299+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54300+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54301+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54304+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54305+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54306+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54307+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54308+4 4 4 4 4 4
54309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54313+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54314+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54315+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54318+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54319+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54320+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54321+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54322+4 4 4 4 4 4
54323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54326+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54327+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54328+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54329+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54331+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54332+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54333+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54334+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54335+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54336+4 4 4 4 4 4
54337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54340+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54341+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54342+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54343+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54344+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54345+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54346+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54347+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54348+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54349+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54350+4 4 4 4 4 4
54351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54354+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54355+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54356+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54357+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54358+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54359+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54360+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54361+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54362+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54363+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54364+4 4 4 4 4 4
54365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54367+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54368+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54369+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54370+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54371+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54372+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54373+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54374+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54375+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54376+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54377+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54378+4 4 4 4 4 4
54379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54381+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54382+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54383+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54384+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54385+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54386+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54387+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54388+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54389+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54390+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54391+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54392+4 4 4 4 4 4
54393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54395+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54396+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54397+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54398+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54399+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54400+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54401+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54402+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54403+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54404+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54405+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54406+4 4 4 4 4 4
54407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54409+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54410+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54411+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54412+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54413+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54414+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54415+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54416+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54417+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54418+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54419+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54420+4 4 4 4 4 4
54421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54422+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54423+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54424+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54425+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54426+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54427+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54428+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54429+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54430+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54431+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54432+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54433+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54434+4 4 4 4 4 4
54435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54436+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54437+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54438+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54439+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54440+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54441+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54442+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54443+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54444+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54445+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54446+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54447+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54448+0 0 0 4 4 4
54449+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54450+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54451+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54452+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54453+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54454+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54455+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54456+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54457+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54458+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54459+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54460+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54461+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54462+2 0 0 0 0 0
54463+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54464+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54465+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54466+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54467+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54468+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54469+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54470+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54471+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54472+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54473+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54474+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54475+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54476+37 38 37 0 0 0
54477+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54478+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54479+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54480+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54481+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54482+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54483+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54484+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54485+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54486+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54487+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54488+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54489+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54490+85 115 134 4 0 0
54491+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54492+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54493+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54494+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54495+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54496+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54497+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54498+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54499+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54500+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54501+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54502+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54503+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54504+60 73 81 4 0 0
54505+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54506+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54507+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54508+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54509+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54510+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54511+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54512+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54513+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54514+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54515+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54516+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54517+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54518+16 19 21 4 0 0
54519+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54520+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54521+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54522+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54523+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54524+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54525+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54526+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54527+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54528+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54529+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54530+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54531+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54532+4 0 0 4 3 3
54533+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54534+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54535+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54537+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54538+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54539+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54540+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54541+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54542+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54543+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54544+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54545+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54546+3 2 2 4 4 4
54547+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54548+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54549+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54550+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54551+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54552+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54553+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54554+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54555+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54556+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54557+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54558+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54559+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54560+4 4 4 4 4 4
54561+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54562+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54563+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54564+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54565+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54566+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54567+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54568+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54569+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54570+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54571+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54572+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54573+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54574+4 4 4 4 4 4
54575+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54576+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54577+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54578+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54579+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54580+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54581+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54582+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54583+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54584+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54585+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54586+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54587+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54588+5 5 5 5 5 5
54589+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54590+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54591+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54592+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54593+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54594+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54595+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54596+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54597+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54598+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54599+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54600+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54601+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54602+5 5 5 4 4 4
54603+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54604+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54605+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54606+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54607+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54608+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54609+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54610+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54611+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54612+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54613+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54614+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54616+4 4 4 4 4 4
54617+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54618+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54619+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54620+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54621+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54622+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54623+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54624+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54625+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54626+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54627+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54628+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54630+4 4 4 4 4 4
54631+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54632+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54633+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54634+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54635+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54636+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54637+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54638+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54639+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54640+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54641+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
54644+4 4 4 4 4 4
54645+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54646+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54647+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54648+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54649+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54650+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54651+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54652+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54653+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54654+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54655+6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
54658+4 4 4 4 4 4
54659+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54660+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54661+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54662+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54663+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54664+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54665+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54666+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54667+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54668+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54669+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54672+4 4 4 4 4 4
54673+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54674+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54675+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54676+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54677+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54678+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54679+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54680+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54681+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54682+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54683+6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
54686+4 4 4 4 4 4
54687+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54688+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54689+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54690+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54691+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54692+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54693+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54694+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54695+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54696+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54697+4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54700+4 4 4 4 4 4
54701+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54702+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54703+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54704+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54705+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54706+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54707+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54708+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54709+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54710+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54711+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54714+4 4 4 4 4 4
54715+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54716+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54717+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54718+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54719+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54720+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54721+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54722+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54723+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54724+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54725+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54728+4 4 4 4 4 4
54729+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54730+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54731+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54732+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54733+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54734+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54735+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54736+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54737+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54738+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54739+4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54742+4 4 4 4 4 4
54743+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54744+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54745+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54746+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54747+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54748+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54749+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54750+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54751+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54752+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54753+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 4 4 4
54757+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54758+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54759+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54760+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54761+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54762+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54763+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54764+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54765+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54766+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54767+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54770+4 4 4 4 4 4
54771+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54772+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54773+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54774+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54775+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54776+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54777+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54778+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54779+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54780+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54781+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54784+4 4 4 4 4 4
54785+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54786+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54787+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54788+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54789+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54790+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54791+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54792+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54793+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54794+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54795+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54798+4 4 4 4 4 4
54799+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54800+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54801+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54802+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54803+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54804+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54805+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54806+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54807+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54808+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54809+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54812+4 4 4 4 4 4
54813+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54814+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54815+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54816+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54817+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54818+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54819+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54820+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54821+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54822+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54823+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54826+4 4 4 4 4 4
54827+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54828+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54829+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54830+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54831+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54832+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54833+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54834+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54835+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54836+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54837+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54840+4 4 4 4 4 4
54841+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54842+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54843+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54844+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54845+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54846+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54847+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54848+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54849+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54850+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54851+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54854+4 4 4 4 4 4
54855+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54856+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54857+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54858+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54859+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54860+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54861+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54862+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54863+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54864+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54865+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54868+4 4 4 4 4 4
54869+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54870+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54871+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54872+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54873+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54874+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54875+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54876+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54877+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54878+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54879+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54882+4 4 4 4 4 4
54883+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54884+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54885+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54886+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54887+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54888+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54889+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54890+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54891+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54892+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54893+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54896+4 4 4 4 4 4
54897+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54898+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54899+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54900+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54901+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54902+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54903+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54904+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54905+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54906+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54907+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54910+4 4 4 4 4 4
54911+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54912+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54913+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54914+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54915+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54916+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54917+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54918+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54919+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54920+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54921+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54924+4 4 4 4 4 4
54925+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54926+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54927+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54928+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54929+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54930+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54931+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54932+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54933+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54934+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54935+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54938+4 4 4 4 4 4
54939+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54940+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54941+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54942+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54943+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54944+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54945+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54946+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54947+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54948+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54949+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54952+4 4 4 4 4 4
54953+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54954+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54955+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54956+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54957+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54958+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54959+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54960+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54961+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54962+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54963+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54966+4 4 4 4 4 4
54967+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54968+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54969+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54970+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54971+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54972+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54973+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54974+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54975+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54976+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54977+0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
54980+4 4 4 4 4 4
54981+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54982+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54983+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54984+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54985+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54986+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54987+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54989+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54990+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54991+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54994+4 4 4 4 4 4
54995+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54996+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54997+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54998+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54999+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55000+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55001+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55002+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55003+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55004+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55005+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55008+4 4 4 4 4 4
55009+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55010+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55011+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55012+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55013+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55014+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55015+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55016+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55017+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55018+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55022+4 4 4 4 4 4
55023+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55024+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55025+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55026+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55027+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55028+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55029+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55030+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55031+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55032+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
55036+4 4 4 4 4 4
55037+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55038+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55039+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55040+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55041+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55042+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55043+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55044+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55045+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55046+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55050+4 4 4 4 4 4
55051+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55052+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55053+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55054+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55055+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55056+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55057+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55058+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55059+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55060+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55064+4 4 4 4 4 4
55065+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55066+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55067+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55068+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55069+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55070+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55071+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55072+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55073+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
55078+4 4 4 4 4 4
55079+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55080+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55081+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55082+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55083+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55084+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55085+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55086+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55087+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
55092+4 4 4 4 4 4
55093+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55094+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55095+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55096+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55097+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55098+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55099+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55100+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55101+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
55106+4 4 4 4 4 4
55107+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55108+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55109+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55110+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55111+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55112+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55113+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55114+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
55120+4 4 4 4 4 4
55121+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55122+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55123+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55124+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55125+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55126+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55127+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55128+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
55134+4 4 4 4 4 4
55135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55136+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55137+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55138+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55139+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55140+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55141+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55142+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
55148+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55151+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55152+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55153+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55154+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55155+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55156+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55162+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 5 5 5 5 5 5 5 5 5
55165+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55166+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55167+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55168+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55169+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55170+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55176+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55180+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55181+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55182+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55183+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55184+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55190+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 5 5 5
55194+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55195+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55196+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55197+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55204+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 5 5 5 4 3 3 5 5 5 4 3 3
55209+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55210+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55211+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
55218+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 5 5 5 4 3 3 5 5 5 6 6 6
55223+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55224+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55225+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55232+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 5 5 5 4 3 3 5 5 5
55237+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55238+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55239+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55246+4 4 4 4 4 4
55247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55251+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55252+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55253+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260+4 4 4 4 4 4
55261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55265+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55266+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55267+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274+4 4 4 4 4 4
55275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55280+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55281+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288+4 4 4 4 4 4
55289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55294+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302+4 4 4 4 4 4
55303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55308+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316+4 4 4 4 4 4
55317diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55318index a01147f..5d896f8 100644
55319--- a/drivers/video/matrox/matroxfb_DAC1064.c
55320+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55321@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55322
55323 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55324 struct matrox_switch matrox_mystique = {
55325- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55326+ .preinit = MGA1064_preinit,
55327+ .reset = MGA1064_reset,
55328+ .init = MGA1064_init,
55329+ .restore = MGA1064_restore,
55330 };
55331 EXPORT_SYMBOL(matrox_mystique);
55332 #endif
55333
55334 #ifdef CONFIG_FB_MATROX_G
55335 struct matrox_switch matrox_G100 = {
55336- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55337+ .preinit = MGAG100_preinit,
55338+ .reset = MGAG100_reset,
55339+ .init = MGAG100_init,
55340+ .restore = MGAG100_restore,
55341 };
55342 EXPORT_SYMBOL(matrox_G100);
55343 #endif
55344diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55345index 195ad7c..09743fc 100644
55346--- a/drivers/video/matrox/matroxfb_Ti3026.c
55347+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55348@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55349 }
55350
55351 struct matrox_switch matrox_millennium = {
55352- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55353+ .preinit = Ti3026_preinit,
55354+ .reset = Ti3026_reset,
55355+ .init = Ti3026_init,
55356+ .restore = Ti3026_restore
55357 };
55358 EXPORT_SYMBOL(matrox_millennium);
55359 #endif
55360diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55361index fe92eed..106e085 100644
55362--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55363+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55364@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55365 struct mb862xxfb_par *par = info->par;
55366
55367 if (info->var.bits_per_pixel == 32) {
55368- info->fbops->fb_fillrect = cfb_fillrect;
55369- info->fbops->fb_copyarea = cfb_copyarea;
55370- info->fbops->fb_imageblit = cfb_imageblit;
55371+ pax_open_kernel();
55372+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55373+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55374+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55375+ pax_close_kernel();
55376 } else {
55377 outreg(disp, GC_L0EM, 3);
55378- info->fbops->fb_fillrect = mb86290fb_fillrect;
55379- info->fbops->fb_copyarea = mb86290fb_copyarea;
55380- info->fbops->fb_imageblit = mb86290fb_imageblit;
55381+ pax_open_kernel();
55382+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55383+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55384+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55385+ pax_close_kernel();
55386 }
55387 outreg(draw, GDC_REG_DRAW_BASE, 0);
55388 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55389diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55390index def0412..fed6529 100644
55391--- a/drivers/video/nvidia/nvidia.c
55392+++ b/drivers/video/nvidia/nvidia.c
55393@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55394 info->fix.line_length = (info->var.xres_virtual *
55395 info->var.bits_per_pixel) >> 3;
55396 if (info->var.accel_flags) {
55397- info->fbops->fb_imageblit = nvidiafb_imageblit;
55398- info->fbops->fb_fillrect = nvidiafb_fillrect;
55399- info->fbops->fb_copyarea = nvidiafb_copyarea;
55400- info->fbops->fb_sync = nvidiafb_sync;
55401+ pax_open_kernel();
55402+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55403+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55404+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55405+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55406+ pax_close_kernel();
55407 info->pixmap.scan_align = 4;
55408 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55409 info->flags |= FBINFO_READS_FAST;
55410 NVResetGraphics(info);
55411 } else {
55412- info->fbops->fb_imageblit = cfb_imageblit;
55413- info->fbops->fb_fillrect = cfb_fillrect;
55414- info->fbops->fb_copyarea = cfb_copyarea;
55415- info->fbops->fb_sync = NULL;
55416+ pax_open_kernel();
55417+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55418+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55419+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55420+ *(void **)&info->fbops->fb_sync = NULL;
55421+ pax_close_kernel();
55422 info->pixmap.scan_align = 1;
55423 info->flags |= FBINFO_HWACCEL_DISABLED;
55424 info->flags &= ~FBINFO_READS_FAST;
55425@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55426 info->pixmap.size = 8 * 1024;
55427 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55428
55429- if (!hwcur)
55430- info->fbops->fb_cursor = NULL;
55431+ if (!hwcur) {
55432+ pax_open_kernel();
55433+ *(void **)&info->fbops->fb_cursor = NULL;
55434+ pax_close_kernel();
55435+ }
55436
55437 info->var.accel_flags = (!noaccel);
55438
55439diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55440index 669a81f..e216d76 100644
55441--- a/drivers/video/omap2/dss/display.c
55442+++ b/drivers/video/omap2/dss/display.c
55443@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55444 snprintf(dssdev->alias, sizeof(dssdev->alias),
55445 "display%d", disp_num_counter++);
55446
55447+ pax_open_kernel();
55448 if (drv && drv->get_resolution == NULL)
55449- drv->get_resolution = omapdss_default_get_resolution;
55450+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55451 if (drv && drv->get_recommended_bpp == NULL)
55452- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55453+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55454 if (drv && drv->get_timings == NULL)
55455- drv->get_timings = omapdss_default_get_timings;
55456+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55457+ pax_close_kernel();
55458
55459 mutex_lock(&panel_list_mutex);
55460 list_add_tail(&dssdev->panel_list, &panel_list);
55461diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55462index 83433cb..71e9b98 100644
55463--- a/drivers/video/s1d13xxxfb.c
55464+++ b/drivers/video/s1d13xxxfb.c
55465@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55466
55467 switch(prod_id) {
55468 case S1D13506_PROD_ID: /* activate acceleration */
55469- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55470- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55471+ pax_open_kernel();
55472+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55473+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55474+ pax_close_kernel();
55475 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55476 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55477 break;
55478diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55479index 2bcc84a..29dd1ea 100644
55480--- a/drivers/video/sh_mobile_lcdcfb.c
55481+++ b/drivers/video/sh_mobile_lcdcfb.c
55482@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55483 }
55484
55485 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55486- lcdc_sys_write_index,
55487- lcdc_sys_write_data,
55488- lcdc_sys_read_data,
55489+ .write_index = lcdc_sys_write_index,
55490+ .write_data = lcdc_sys_write_data,
55491+ .read_data = lcdc_sys_read_data,
55492 };
55493
55494 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55495diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55496index d513ed6..90b0de9 100644
55497--- a/drivers/video/smscufx.c
55498+++ b/drivers/video/smscufx.c
55499@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55500 fb_deferred_io_cleanup(info);
55501 kfree(info->fbdefio);
55502 info->fbdefio = NULL;
55503- info->fbops->fb_mmap = ufx_ops_mmap;
55504+ pax_open_kernel();
55505+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55506+ pax_close_kernel();
55507 }
55508
55509 pr_debug("released /dev/fb%d user=%d count=%d",
55510diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55511index 77b890e..458e666 100644
55512--- a/drivers/video/udlfb.c
55513+++ b/drivers/video/udlfb.c
55514@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55515 dlfb_urb_completion(urb);
55516
55517 error:
55518- atomic_add(bytes_sent, &dev->bytes_sent);
55519- atomic_add(bytes_identical, &dev->bytes_identical);
55520- atomic_add(width*height*2, &dev->bytes_rendered);
55521+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55522+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55523+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55524 end_cycles = get_cycles();
55525- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55526+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55527 >> 10)), /* Kcycles */
55528 &dev->cpu_kcycles_used);
55529
55530@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55531 dlfb_urb_completion(urb);
55532
55533 error:
55534- atomic_add(bytes_sent, &dev->bytes_sent);
55535- atomic_add(bytes_identical, &dev->bytes_identical);
55536- atomic_add(bytes_rendered, &dev->bytes_rendered);
55537+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55538+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55539+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55540 end_cycles = get_cycles();
55541- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55542+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55543 >> 10)), /* Kcycles */
55544 &dev->cpu_kcycles_used);
55545 }
55546@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55547 fb_deferred_io_cleanup(info);
55548 kfree(info->fbdefio);
55549 info->fbdefio = NULL;
55550- info->fbops->fb_mmap = dlfb_ops_mmap;
55551+ pax_open_kernel();
55552+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55553+ pax_close_kernel();
55554 }
55555
55556 pr_warn("released /dev/fb%d user=%d count=%d\n",
55557@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55558 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55559 struct dlfb_data *dev = fb_info->par;
55560 return snprintf(buf, PAGE_SIZE, "%u\n",
55561- atomic_read(&dev->bytes_rendered));
55562+ atomic_read_unchecked(&dev->bytes_rendered));
55563 }
55564
55565 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55566@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55567 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55568 struct dlfb_data *dev = fb_info->par;
55569 return snprintf(buf, PAGE_SIZE, "%u\n",
55570- atomic_read(&dev->bytes_identical));
55571+ atomic_read_unchecked(&dev->bytes_identical));
55572 }
55573
55574 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55575@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55576 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55577 struct dlfb_data *dev = fb_info->par;
55578 return snprintf(buf, PAGE_SIZE, "%u\n",
55579- atomic_read(&dev->bytes_sent));
55580+ atomic_read_unchecked(&dev->bytes_sent));
55581 }
55582
55583 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55584@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55585 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55586 struct dlfb_data *dev = fb_info->par;
55587 return snprintf(buf, PAGE_SIZE, "%u\n",
55588- atomic_read(&dev->cpu_kcycles_used));
55589+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55590 }
55591
55592 static ssize_t edid_show(
55593@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55594 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55595 struct dlfb_data *dev = fb_info->par;
55596
55597- atomic_set(&dev->bytes_rendered, 0);
55598- atomic_set(&dev->bytes_identical, 0);
55599- atomic_set(&dev->bytes_sent, 0);
55600- atomic_set(&dev->cpu_kcycles_used, 0);
55601+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55602+ atomic_set_unchecked(&dev->bytes_identical, 0);
55603+ atomic_set_unchecked(&dev->bytes_sent, 0);
55604+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55605
55606 return count;
55607 }
55608diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55609index 256fba7..6e75516 100644
55610--- a/drivers/video/uvesafb.c
55611+++ b/drivers/video/uvesafb.c
55612@@ -19,6 +19,7 @@
55613 #include <linux/io.h>
55614 #include <linux/mutex.h>
55615 #include <linux/slab.h>
55616+#include <linux/moduleloader.h>
55617 #include <video/edid.h>
55618 #include <video/uvesafb.h>
55619 #ifdef CONFIG_X86
55620@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55621 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55622 par->pmi_setpal = par->ypan = 0;
55623 } else {
55624+
55625+#ifdef CONFIG_PAX_KERNEXEC
55626+#ifdef CONFIG_MODULES
55627+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55628+#endif
55629+ if (!par->pmi_code) {
55630+ par->pmi_setpal = par->ypan = 0;
55631+ return 0;
55632+ }
55633+#endif
55634+
55635 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55636 + task->t.regs.edi);
55637+
55638+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55639+ pax_open_kernel();
55640+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55641+ pax_close_kernel();
55642+
55643+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55644+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55645+#else
55646 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55647 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55648+#endif
55649+
55650 printk(KERN_INFO "uvesafb: protected mode interface info at "
55651 "%04x:%04x\n",
55652 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55653@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55654 par->ypan = ypan;
55655
55656 if (par->pmi_setpal || par->ypan) {
55657+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55658 if (__supported_pte_mask & _PAGE_NX) {
55659 par->pmi_setpal = par->ypan = 0;
55660 printk(KERN_WARNING "uvesafb: NX protection is active, "
55661 "better not use the PMI.\n");
55662- } else {
55663+ } else
55664+#endif
55665 uvesafb_vbe_getpmi(task, par);
55666- }
55667 }
55668 #else
55669 /* The protected mode interface is not available on non-x86. */
55670@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55671 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55672
55673 /* Disable blanking if the user requested so. */
55674- if (!blank)
55675- info->fbops->fb_blank = NULL;
55676+ if (!blank) {
55677+ pax_open_kernel();
55678+ *(void **)&info->fbops->fb_blank = NULL;
55679+ pax_close_kernel();
55680+ }
55681
55682 /*
55683 * Find out how much IO memory is required for the mode with
55684@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55685 info->flags = FBINFO_FLAG_DEFAULT |
55686 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55687
55688- if (!par->ypan)
55689- info->fbops->fb_pan_display = NULL;
55690+ if (!par->ypan) {
55691+ pax_open_kernel();
55692+ *(void **)&info->fbops->fb_pan_display = NULL;
55693+ pax_close_kernel();
55694+ }
55695 }
55696
55697 static void uvesafb_init_mtrr(struct fb_info *info)
55698@@ -1792,6 +1822,11 @@ out_mode:
55699 out:
55700 kfree(par->vbe_modes);
55701
55702+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55703+ if (par->pmi_code)
55704+ module_free_exec(NULL, par->pmi_code);
55705+#endif
55706+
55707 framebuffer_release(info);
55708 return err;
55709 }
55710@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55711 kfree(par->vbe_modes);
55712 kfree(par->vbe_state_orig);
55713 kfree(par->vbe_state_saved);
55714+
55715+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55716+ if (par->pmi_code)
55717+ module_free_exec(NULL, par->pmi_code);
55718+#endif
55719+
55720 }
55721
55722 framebuffer_release(info);
55723diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55724index 1c7da3b..56ea0bd 100644
55725--- a/drivers/video/vesafb.c
55726+++ b/drivers/video/vesafb.c
55727@@ -9,6 +9,7 @@
55728 */
55729
55730 #include <linux/module.h>
55731+#include <linux/moduleloader.h>
55732 #include <linux/kernel.h>
55733 #include <linux/errno.h>
55734 #include <linux/string.h>
55735@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55736 static int vram_total; /* Set total amount of memory */
55737 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55738 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55739-static void (*pmi_start)(void) __read_mostly;
55740-static void (*pmi_pal) (void) __read_mostly;
55741+static void (*pmi_start)(void) __read_only;
55742+static void (*pmi_pal) (void) __read_only;
55743 static int depth __read_mostly;
55744 static int vga_compat __read_mostly;
55745 /* --------------------------------------------------------------------- */
55746@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55747 unsigned int size_remap;
55748 unsigned int size_total;
55749 char *option = NULL;
55750+ void *pmi_code = NULL;
55751
55752 /* ignore error return of fb_get_options */
55753 fb_get_options("vesafb", &option);
55754@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55755 size_remap = size_total;
55756 vesafb_fix.smem_len = size_remap;
55757
55758-#ifndef __i386__
55759- screen_info.vesapm_seg = 0;
55760-#endif
55761-
55762 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55763 printk(KERN_WARNING
55764 "vesafb: cannot reserve video memory at 0x%lx\n",
55765@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55766 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55767 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55768
55769+#ifdef __i386__
55770+
55771+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55772+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55773+ if (!pmi_code)
55774+#elif !defined(CONFIG_PAX_KERNEXEC)
55775+ if (0)
55776+#endif
55777+
55778+#endif
55779+ screen_info.vesapm_seg = 0;
55780+
55781 if (screen_info.vesapm_seg) {
55782- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55783- screen_info.vesapm_seg,screen_info.vesapm_off);
55784+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55785+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55786 }
55787
55788 if (screen_info.vesapm_seg < 0xc000)
55789@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55790
55791 if (ypan || pmi_setpal) {
55792 unsigned short *pmi_base;
55793+
55794 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55795- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55796- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55797+
55798+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55799+ pax_open_kernel();
55800+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55801+#else
55802+ pmi_code = pmi_base;
55803+#endif
55804+
55805+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55806+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55807+
55808+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55809+ pmi_start = ktva_ktla(pmi_start);
55810+ pmi_pal = ktva_ktla(pmi_pal);
55811+ pax_close_kernel();
55812+#endif
55813+
55814 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55815 if (pmi_base[3]) {
55816 printk(KERN_INFO "vesafb: pmi: ports = ");
55817@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55818 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55819 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55820
55821- if (!ypan)
55822- info->fbops->fb_pan_display = NULL;
55823+ if (!ypan) {
55824+ pax_open_kernel();
55825+ *(void **)&info->fbops->fb_pan_display = NULL;
55826+ pax_close_kernel();
55827+ }
55828
55829 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55830 err = -ENOMEM;
55831@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55832 fb_info(info, "%s frame buffer device\n", info->fix.id);
55833 return 0;
55834 err:
55835+
55836+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55837+ module_free_exec(NULL, pmi_code);
55838+#endif
55839+
55840 if (info->screen_base)
55841 iounmap(info->screen_base);
55842 framebuffer_release(info);
55843diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55844index 88714ae..16c2e11 100644
55845--- a/drivers/video/via/via_clock.h
55846+++ b/drivers/video/via/via_clock.h
55847@@ -56,7 +56,7 @@ struct via_clock {
55848
55849 void (*set_engine_pll_state)(u8 state);
55850 void (*set_engine_pll)(struct via_pll_config config);
55851-};
55852+} __no_const;
55853
55854
55855 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55856diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55857index fef20db..d28b1ab 100644
55858--- a/drivers/xen/xenfs/xenstored.c
55859+++ b/drivers/xen/xenfs/xenstored.c
55860@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55861 static int xsd_kva_open(struct inode *inode, struct file *file)
55862 {
55863 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55864+#ifdef CONFIG_GRKERNSEC_HIDESYM
55865+ NULL);
55866+#else
55867 xen_store_interface);
55868+#endif
55869+
55870 if (!file->private_data)
55871 return -ENOMEM;
55872 return 0;
55873diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55874index c71e886..61d3d44b 100644
55875--- a/fs/9p/vfs_addr.c
55876+++ b/fs/9p/vfs_addr.c
55877@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55878
55879 retval = v9fs_file_write_internal(inode,
55880 v9inode->writeback_fid,
55881- (__force const char __user *)buffer,
55882+ (const char __force_user *)buffer,
55883 len, &offset, 0);
55884 if (retval > 0)
55885 retval = 0;
55886diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55887index bb7991c..481e21a 100644
55888--- a/fs/9p/vfs_inode.c
55889+++ b/fs/9p/vfs_inode.c
55890@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55891 void
55892 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55893 {
55894- char *s = nd_get_link(nd);
55895+ const char *s = nd_get_link(nd);
55896
55897 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55898 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55899diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55900index 370b24c..ff0be7b 100644
55901--- a/fs/Kconfig.binfmt
55902+++ b/fs/Kconfig.binfmt
55903@@ -103,7 +103,7 @@ config HAVE_AOUT
55904
55905 config BINFMT_AOUT
55906 tristate "Kernel support for a.out and ECOFF binaries"
55907- depends on HAVE_AOUT
55908+ depends on HAVE_AOUT && BROKEN
55909 ---help---
55910 A.out (Assembler.OUTput) is a set of formats for libraries and
55911 executables used in the earliest versions of UNIX. Linux used
55912diff --git a/fs/affs/super.c b/fs/affs/super.c
55913index d098731..9a5b19d 100644
55914--- a/fs/affs/super.c
55915+++ b/fs/affs/super.c
55916@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
55917 &blocksize,&sbi->s_prefix,
55918 sbi->s_volume, &mount_flags)) {
55919 printk(KERN_ERR "AFFS: Error parsing options\n");
55920- kfree(sbi->s_prefix);
55921- kfree(sbi);
55922 return -EINVAL;
55923 }
55924 /* N.B. after this point s_prefix must be released */
55925diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55926index ce25d75..dc09eeb 100644
55927--- a/fs/afs/inode.c
55928+++ b/fs/afs/inode.c
55929@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55930 struct afs_vnode *vnode;
55931 struct super_block *sb;
55932 struct inode *inode;
55933- static atomic_t afs_autocell_ino;
55934+ static atomic_unchecked_t afs_autocell_ino;
55935
55936 _enter("{%x:%u},%*.*s,",
55937 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55938@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55939 data.fid.unique = 0;
55940 data.fid.vnode = 0;
55941
55942- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55943+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55944 afs_iget5_autocell_test, afs_iget5_set,
55945 &data);
55946 if (!inode) {
55947diff --git a/fs/aio.c b/fs/aio.c
55948index 062a5f6..6ecefa2 100644
55949--- a/fs/aio.c
55950+++ b/fs/aio.c
55951@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55952 size += sizeof(struct io_event) * nr_events;
55953
55954 nr_pages = PFN_UP(size);
55955- if (nr_pages < 0)
55956+ if (nr_pages <= 0)
55957 return -EINVAL;
55958
55959 file = aio_private_file(ctx, nr_pages);
55960@@ -1285,10 +1285,8 @@ rw_common:
55961 &iovec, compat)
55962 : aio_setup_single_vector(req, rw, buf, &nr_segs,
55963 iovec);
55964- if (ret)
55965- return ret;
55966-
55967- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
55968+ if (!ret)
55969+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
55970 if (ret < 0) {
55971 if (iovec != &inline_vec)
55972 kfree(iovec);
55973diff --git a/fs/attr.c b/fs/attr.c
55974index 5d4e59d..fd02418 100644
55975--- a/fs/attr.c
55976+++ b/fs/attr.c
55977@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55978 unsigned long limit;
55979
55980 limit = rlimit(RLIMIT_FSIZE);
55981+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55982 if (limit != RLIM_INFINITY && offset > limit)
55983 goto out_sig;
55984 if (offset > inode->i_sb->s_maxbytes)
55985diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55986index 116fd38..c04182da 100644
55987--- a/fs/autofs4/waitq.c
55988+++ b/fs/autofs4/waitq.c
55989@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55990 {
55991 unsigned long sigpipe, flags;
55992 mm_segment_t fs;
55993- const char *data = (const char *)addr;
55994+ const char __user *data = (const char __force_user *)addr;
55995 ssize_t wr = 0;
55996
55997 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55998@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55999 return 1;
56000 }
56001
56002+#ifdef CONFIG_GRKERNSEC_HIDESYM
56003+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56004+#endif
56005+
56006 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56007 enum autofs_notify notify)
56008 {
56009@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56010
56011 /* If this is a direct mount request create a dummy name */
56012 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56013+#ifdef CONFIG_GRKERNSEC_HIDESYM
56014+ /* this name does get written to userland via autofs4_write() */
56015+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56016+#else
56017 qstr.len = sprintf(name, "%p", dentry);
56018+#endif
56019 else {
56020 qstr.len = autofs4_getpath(sbi, dentry, &name);
56021 if (!qstr.len) {
56022diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56023index 2722387..56059b5 100644
56024--- a/fs/befs/endian.h
56025+++ b/fs/befs/endian.h
56026@@ -11,7 +11,7 @@
56027
56028 #include <asm/byteorder.h>
56029
56030-static inline u64
56031+static inline u64 __intentional_overflow(-1)
56032 fs64_to_cpu(const struct super_block *sb, fs64 n)
56033 {
56034 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56035@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56036 return (__force fs64)cpu_to_be64(n);
56037 }
56038
56039-static inline u32
56040+static inline u32 __intentional_overflow(-1)
56041 fs32_to_cpu(const struct super_block *sb, fs32 n)
56042 {
56043 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56044@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56045 return (__force fs32)cpu_to_be32(n);
56046 }
56047
56048-static inline u16
56049+static inline u16 __intentional_overflow(-1)
56050 fs16_to_cpu(const struct super_block *sb, fs16 n)
56051 {
56052 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56053diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56054index ca0ba15..0fa3257 100644
56055--- a/fs/binfmt_aout.c
56056+++ b/fs/binfmt_aout.c
56057@@ -16,6 +16,7 @@
56058 #include <linux/string.h>
56059 #include <linux/fs.h>
56060 #include <linux/file.h>
56061+#include <linux/security.h>
56062 #include <linux/stat.h>
56063 #include <linux/fcntl.h>
56064 #include <linux/ptrace.h>
56065@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56066 #endif
56067 # define START_STACK(u) ((void __user *)u.start_stack)
56068
56069+ memset(&dump, 0, sizeof(dump));
56070+
56071 fs = get_fs();
56072 set_fs(KERNEL_DS);
56073 has_dumped = 1;
56074@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56075
56076 /* If the size of the dump file exceeds the rlimit, then see what would happen
56077 if we wrote the stack, but not the data area. */
56078+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56079 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56080 dump.u_dsize = 0;
56081
56082 /* Make sure we have enough room to write the stack and data areas. */
56083+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56084 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56085 dump.u_ssize = 0;
56086
56087@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56088 rlim = rlimit(RLIMIT_DATA);
56089 if (rlim >= RLIM_INFINITY)
56090 rlim = ~0;
56091+
56092+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56093 if (ex.a_data + ex.a_bss > rlim)
56094 return -ENOMEM;
56095
56096@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56097
56098 install_exec_creds(bprm);
56099
56100+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56101+ current->mm->pax_flags = 0UL;
56102+#endif
56103+
56104+#ifdef CONFIG_PAX_PAGEEXEC
56105+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56106+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56107+
56108+#ifdef CONFIG_PAX_EMUTRAMP
56109+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56110+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56111+#endif
56112+
56113+#ifdef CONFIG_PAX_MPROTECT
56114+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56115+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56116+#endif
56117+
56118+ }
56119+#endif
56120+
56121 if (N_MAGIC(ex) == OMAGIC) {
56122 unsigned long text_addr, map_size;
56123 loff_t pos;
56124@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56125 }
56126
56127 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56128- PROT_READ | PROT_WRITE | PROT_EXEC,
56129+ PROT_READ | PROT_WRITE,
56130 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56131 fd_offset + ex.a_text);
56132 if (error != N_DATADDR(ex)) {
56133diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56134index 67be295..83e2f86 100644
56135--- a/fs/binfmt_elf.c
56136+++ b/fs/binfmt_elf.c
56137@@ -34,6 +34,7 @@
56138 #include <linux/utsname.h>
56139 #include <linux/coredump.h>
56140 #include <linux/sched.h>
56141+#include <linux/xattr.h>
56142 #include <asm/uaccess.h>
56143 #include <asm/param.h>
56144 #include <asm/page.h>
56145@@ -48,7 +49,7 @@
56146 static int load_elf_binary(struct linux_binprm *bprm);
56147 static int load_elf_library(struct file *);
56148 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56149- int, int, unsigned long);
56150+ int, int, unsigned long) __intentional_overflow(-1);
56151
56152 /*
56153 * If we don't support core dumping, then supply a NULL so we
56154@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56155 #define elf_core_dump NULL
56156 #endif
56157
56158+#ifdef CONFIG_PAX_MPROTECT
56159+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56160+#endif
56161+
56162+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56163+static void elf_handle_mmap(struct file *file);
56164+#endif
56165+
56166 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56167 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56168 #else
56169@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56170 .load_binary = load_elf_binary,
56171 .load_shlib = load_elf_library,
56172 .core_dump = elf_core_dump,
56173+
56174+#ifdef CONFIG_PAX_MPROTECT
56175+ .handle_mprotect= elf_handle_mprotect,
56176+#endif
56177+
56178+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56179+ .handle_mmap = elf_handle_mmap,
56180+#endif
56181+
56182 .min_coredump = ELF_EXEC_PAGESIZE,
56183 };
56184
56185@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56186
56187 static int set_brk(unsigned long start, unsigned long end)
56188 {
56189+ unsigned long e = end;
56190+
56191 start = ELF_PAGEALIGN(start);
56192 end = ELF_PAGEALIGN(end);
56193 if (end > start) {
56194@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56195 if (BAD_ADDR(addr))
56196 return addr;
56197 }
56198- current->mm->start_brk = current->mm->brk = end;
56199+ current->mm->start_brk = current->mm->brk = e;
56200 return 0;
56201 }
56202
56203@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56204 elf_addr_t __user *u_rand_bytes;
56205 const char *k_platform = ELF_PLATFORM;
56206 const char *k_base_platform = ELF_BASE_PLATFORM;
56207- unsigned char k_rand_bytes[16];
56208+ u32 k_rand_bytes[4];
56209 int items;
56210 elf_addr_t *elf_info;
56211 int ei_index = 0;
56212 const struct cred *cred = current_cred();
56213 struct vm_area_struct *vma;
56214+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56215
56216 /*
56217 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56218@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56219 * Generate 16 random bytes for userspace PRNG seeding.
56220 */
56221 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56222- u_rand_bytes = (elf_addr_t __user *)
56223- STACK_ALLOC(p, sizeof(k_rand_bytes));
56224+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56225+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56226+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56227+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56228+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56229+ u_rand_bytes = (elf_addr_t __user *) p;
56230 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56231 return -EFAULT;
56232
56233@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56234 return -EFAULT;
56235 current->mm->env_end = p;
56236
56237+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56238+
56239 /* Put the elf_info on the stack in the right place. */
56240 sp = (elf_addr_t __user *)envp + 1;
56241- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56242+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56243 return -EFAULT;
56244 return 0;
56245 }
56246@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56247 an ELF header */
56248
56249 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56250- struct file *interpreter, unsigned long *interp_map_addr,
56251- unsigned long no_base)
56252+ struct file *interpreter, unsigned long no_base)
56253 {
56254 struct elf_phdr *elf_phdata;
56255 struct elf_phdr *eppnt;
56256- unsigned long load_addr = 0;
56257+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56258 int load_addr_set = 0;
56259 unsigned long last_bss = 0, elf_bss = 0;
56260- unsigned long error = ~0UL;
56261+ unsigned long error = -EINVAL;
56262 unsigned long total_size;
56263 int retval, i, size;
56264
56265@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56266 goto out_close;
56267 }
56268
56269+#ifdef CONFIG_PAX_SEGMEXEC
56270+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56271+ pax_task_size = SEGMEXEC_TASK_SIZE;
56272+#endif
56273+
56274 eppnt = elf_phdata;
56275 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56276 if (eppnt->p_type == PT_LOAD) {
56277@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56278 map_addr = elf_map(interpreter, load_addr + vaddr,
56279 eppnt, elf_prot, elf_type, total_size);
56280 total_size = 0;
56281- if (!*interp_map_addr)
56282- *interp_map_addr = map_addr;
56283 error = map_addr;
56284 if (BAD_ADDR(map_addr))
56285 goto out_close;
56286@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56287 k = load_addr + eppnt->p_vaddr;
56288 if (BAD_ADDR(k) ||
56289 eppnt->p_filesz > eppnt->p_memsz ||
56290- eppnt->p_memsz > TASK_SIZE ||
56291- TASK_SIZE - eppnt->p_memsz < k) {
56292+ eppnt->p_memsz > pax_task_size ||
56293+ pax_task_size - eppnt->p_memsz < k) {
56294 error = -ENOMEM;
56295 goto out_close;
56296 }
56297@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56298 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56299
56300 /* Map the last of the bss segment */
56301- error = vm_brk(elf_bss, last_bss - elf_bss);
56302- if (BAD_ADDR(error))
56303- goto out_close;
56304+ if (last_bss > elf_bss) {
56305+ error = vm_brk(elf_bss, last_bss - elf_bss);
56306+ if (BAD_ADDR(error))
56307+ goto out_close;
56308+ }
56309 }
56310
56311 error = load_addr;
56312@@ -538,6 +569,336 @@ out:
56313 return error;
56314 }
56315
56316+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56317+#ifdef CONFIG_PAX_SOFTMODE
56318+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56319+{
56320+ unsigned long pax_flags = 0UL;
56321+
56322+#ifdef CONFIG_PAX_PAGEEXEC
56323+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56324+ pax_flags |= MF_PAX_PAGEEXEC;
56325+#endif
56326+
56327+#ifdef CONFIG_PAX_SEGMEXEC
56328+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56329+ pax_flags |= MF_PAX_SEGMEXEC;
56330+#endif
56331+
56332+#ifdef CONFIG_PAX_EMUTRAMP
56333+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56334+ pax_flags |= MF_PAX_EMUTRAMP;
56335+#endif
56336+
56337+#ifdef CONFIG_PAX_MPROTECT
56338+ if (elf_phdata->p_flags & PF_MPROTECT)
56339+ pax_flags |= MF_PAX_MPROTECT;
56340+#endif
56341+
56342+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56343+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56344+ pax_flags |= MF_PAX_RANDMMAP;
56345+#endif
56346+
56347+ return pax_flags;
56348+}
56349+#endif
56350+
56351+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56352+{
56353+ unsigned long pax_flags = 0UL;
56354+
56355+#ifdef CONFIG_PAX_PAGEEXEC
56356+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56357+ pax_flags |= MF_PAX_PAGEEXEC;
56358+#endif
56359+
56360+#ifdef CONFIG_PAX_SEGMEXEC
56361+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56362+ pax_flags |= MF_PAX_SEGMEXEC;
56363+#endif
56364+
56365+#ifdef CONFIG_PAX_EMUTRAMP
56366+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56367+ pax_flags |= MF_PAX_EMUTRAMP;
56368+#endif
56369+
56370+#ifdef CONFIG_PAX_MPROTECT
56371+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56372+ pax_flags |= MF_PAX_MPROTECT;
56373+#endif
56374+
56375+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56376+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56377+ pax_flags |= MF_PAX_RANDMMAP;
56378+#endif
56379+
56380+ return pax_flags;
56381+}
56382+#endif
56383+
56384+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56385+#ifdef CONFIG_PAX_SOFTMODE
56386+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56387+{
56388+ unsigned long pax_flags = 0UL;
56389+
56390+#ifdef CONFIG_PAX_PAGEEXEC
56391+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56392+ pax_flags |= MF_PAX_PAGEEXEC;
56393+#endif
56394+
56395+#ifdef CONFIG_PAX_SEGMEXEC
56396+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56397+ pax_flags |= MF_PAX_SEGMEXEC;
56398+#endif
56399+
56400+#ifdef CONFIG_PAX_EMUTRAMP
56401+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56402+ pax_flags |= MF_PAX_EMUTRAMP;
56403+#endif
56404+
56405+#ifdef CONFIG_PAX_MPROTECT
56406+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56407+ pax_flags |= MF_PAX_MPROTECT;
56408+#endif
56409+
56410+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56411+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56412+ pax_flags |= MF_PAX_RANDMMAP;
56413+#endif
56414+
56415+ return pax_flags;
56416+}
56417+#endif
56418+
56419+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56420+{
56421+ unsigned long pax_flags = 0UL;
56422+
56423+#ifdef CONFIG_PAX_PAGEEXEC
56424+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56425+ pax_flags |= MF_PAX_PAGEEXEC;
56426+#endif
56427+
56428+#ifdef CONFIG_PAX_SEGMEXEC
56429+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56430+ pax_flags |= MF_PAX_SEGMEXEC;
56431+#endif
56432+
56433+#ifdef CONFIG_PAX_EMUTRAMP
56434+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56435+ pax_flags |= MF_PAX_EMUTRAMP;
56436+#endif
56437+
56438+#ifdef CONFIG_PAX_MPROTECT
56439+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56440+ pax_flags |= MF_PAX_MPROTECT;
56441+#endif
56442+
56443+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56444+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56445+ pax_flags |= MF_PAX_RANDMMAP;
56446+#endif
56447+
56448+ return pax_flags;
56449+}
56450+#endif
56451+
56452+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56453+static unsigned long pax_parse_defaults(void)
56454+{
56455+ unsigned long pax_flags = 0UL;
56456+
56457+#ifdef CONFIG_PAX_SOFTMODE
56458+ if (pax_softmode)
56459+ return pax_flags;
56460+#endif
56461+
56462+#ifdef CONFIG_PAX_PAGEEXEC
56463+ pax_flags |= MF_PAX_PAGEEXEC;
56464+#endif
56465+
56466+#ifdef CONFIG_PAX_SEGMEXEC
56467+ pax_flags |= MF_PAX_SEGMEXEC;
56468+#endif
56469+
56470+#ifdef CONFIG_PAX_MPROTECT
56471+ pax_flags |= MF_PAX_MPROTECT;
56472+#endif
56473+
56474+#ifdef CONFIG_PAX_RANDMMAP
56475+ if (randomize_va_space)
56476+ pax_flags |= MF_PAX_RANDMMAP;
56477+#endif
56478+
56479+ return pax_flags;
56480+}
56481+
56482+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56483+{
56484+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56485+
56486+#ifdef CONFIG_PAX_EI_PAX
56487+
56488+#ifdef CONFIG_PAX_SOFTMODE
56489+ if (pax_softmode)
56490+ return pax_flags;
56491+#endif
56492+
56493+ pax_flags = 0UL;
56494+
56495+#ifdef CONFIG_PAX_PAGEEXEC
56496+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56497+ pax_flags |= MF_PAX_PAGEEXEC;
56498+#endif
56499+
56500+#ifdef CONFIG_PAX_SEGMEXEC
56501+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56502+ pax_flags |= MF_PAX_SEGMEXEC;
56503+#endif
56504+
56505+#ifdef CONFIG_PAX_EMUTRAMP
56506+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56507+ pax_flags |= MF_PAX_EMUTRAMP;
56508+#endif
56509+
56510+#ifdef CONFIG_PAX_MPROTECT
56511+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56512+ pax_flags |= MF_PAX_MPROTECT;
56513+#endif
56514+
56515+#ifdef CONFIG_PAX_ASLR
56516+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56517+ pax_flags |= MF_PAX_RANDMMAP;
56518+#endif
56519+
56520+#endif
56521+
56522+ return pax_flags;
56523+
56524+}
56525+
56526+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56527+{
56528+
56529+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56530+ unsigned long i;
56531+
56532+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56533+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56534+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56535+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56536+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56537+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56538+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56539+ return PAX_PARSE_FLAGS_FALLBACK;
56540+
56541+#ifdef CONFIG_PAX_SOFTMODE
56542+ if (pax_softmode)
56543+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56544+ else
56545+#endif
56546+
56547+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56548+ break;
56549+ }
56550+#endif
56551+
56552+ return PAX_PARSE_FLAGS_FALLBACK;
56553+}
56554+
56555+static unsigned long pax_parse_xattr_pax(struct file * const file)
56556+{
56557+
56558+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56559+ ssize_t xattr_size, i;
56560+ unsigned char xattr_value[sizeof("pemrs") - 1];
56561+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56562+
56563+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56564+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56565+ return PAX_PARSE_FLAGS_FALLBACK;
56566+
56567+ for (i = 0; i < xattr_size; i++)
56568+ switch (xattr_value[i]) {
56569+ default:
56570+ return PAX_PARSE_FLAGS_FALLBACK;
56571+
56572+#define parse_flag(option1, option2, flag) \
56573+ case option1: \
56574+ if (pax_flags_hardmode & MF_PAX_##flag) \
56575+ return PAX_PARSE_FLAGS_FALLBACK;\
56576+ pax_flags_hardmode |= MF_PAX_##flag; \
56577+ break; \
56578+ case option2: \
56579+ if (pax_flags_softmode & MF_PAX_##flag) \
56580+ return PAX_PARSE_FLAGS_FALLBACK;\
56581+ pax_flags_softmode |= MF_PAX_##flag; \
56582+ break;
56583+
56584+ parse_flag('p', 'P', PAGEEXEC);
56585+ parse_flag('e', 'E', EMUTRAMP);
56586+ parse_flag('m', 'M', MPROTECT);
56587+ parse_flag('r', 'R', RANDMMAP);
56588+ parse_flag('s', 'S', SEGMEXEC);
56589+
56590+#undef parse_flag
56591+ }
56592+
56593+ if (pax_flags_hardmode & pax_flags_softmode)
56594+ return PAX_PARSE_FLAGS_FALLBACK;
56595+
56596+#ifdef CONFIG_PAX_SOFTMODE
56597+ if (pax_softmode)
56598+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56599+ else
56600+#endif
56601+
56602+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56603+#else
56604+ return PAX_PARSE_FLAGS_FALLBACK;
56605+#endif
56606+
56607+}
56608+
56609+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56610+{
56611+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56612+
56613+ pax_flags = pax_parse_defaults();
56614+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56615+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56616+ xattr_pax_flags = pax_parse_xattr_pax(file);
56617+
56618+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56619+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56620+ pt_pax_flags != xattr_pax_flags)
56621+ return -EINVAL;
56622+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56623+ pax_flags = xattr_pax_flags;
56624+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56625+ pax_flags = pt_pax_flags;
56626+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56627+ pax_flags = ei_pax_flags;
56628+
56629+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56630+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56631+ if ((__supported_pte_mask & _PAGE_NX))
56632+ pax_flags &= ~MF_PAX_SEGMEXEC;
56633+ else
56634+ pax_flags &= ~MF_PAX_PAGEEXEC;
56635+ }
56636+#endif
56637+
56638+ if (0 > pax_check_flags(&pax_flags))
56639+ return -EINVAL;
56640+
56641+ current->mm->pax_flags = pax_flags;
56642+ return 0;
56643+}
56644+#endif
56645+
56646 /*
56647 * These are the functions used to load ELF style executables and shared
56648 * libraries. There is no binary dependent code anywhere else.
56649@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56650 {
56651 unsigned int random_variable = 0;
56652
56653+#ifdef CONFIG_PAX_RANDUSTACK
56654+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56655+ return stack_top - current->mm->delta_stack;
56656+#endif
56657+
56658 if ((current->flags & PF_RANDOMIZE) &&
56659 !(current->personality & ADDR_NO_RANDOMIZE)) {
56660 random_variable = get_random_int() & STACK_RND_MASK;
56661@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56662 unsigned long load_addr = 0, load_bias = 0;
56663 int load_addr_set = 0;
56664 char * elf_interpreter = NULL;
56665- unsigned long error;
56666+ unsigned long error = 0;
56667 struct elf_phdr *elf_ppnt, *elf_phdata;
56668 unsigned long elf_bss, elf_brk;
56669 int retval, i;
56670@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56671 unsigned long start_code, end_code, start_data, end_data;
56672 unsigned long reloc_func_desc __maybe_unused = 0;
56673 int executable_stack = EXSTACK_DEFAULT;
56674- unsigned long def_flags = 0;
56675 struct pt_regs *regs = current_pt_regs();
56676 struct {
56677 struct elfhdr elf_ex;
56678 struct elfhdr interp_elf_ex;
56679 } *loc;
56680+ unsigned long pax_task_size;
56681
56682 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56683 if (!loc) {
56684@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56685 goto out_free_dentry;
56686
56687 /* OK, This is the point of no return */
56688- current->mm->def_flags = def_flags;
56689+ current->mm->def_flags = 0;
56690
56691 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56692 may depend on the personality. */
56693 SET_PERSONALITY(loc->elf_ex);
56694+
56695+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56696+ current->mm->pax_flags = 0UL;
56697+#endif
56698+
56699+#ifdef CONFIG_PAX_DLRESOLVE
56700+ current->mm->call_dl_resolve = 0UL;
56701+#endif
56702+
56703+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56704+ current->mm->call_syscall = 0UL;
56705+#endif
56706+
56707+#ifdef CONFIG_PAX_ASLR
56708+ current->mm->delta_mmap = 0UL;
56709+ current->mm->delta_stack = 0UL;
56710+#endif
56711+
56712+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56713+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56714+ send_sig(SIGKILL, current, 0);
56715+ goto out_free_dentry;
56716+ }
56717+#endif
56718+
56719+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56720+ pax_set_initial_flags(bprm);
56721+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56722+ if (pax_set_initial_flags_func)
56723+ (pax_set_initial_flags_func)(bprm);
56724+#endif
56725+
56726+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56727+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56728+ current->mm->context.user_cs_limit = PAGE_SIZE;
56729+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56730+ }
56731+#endif
56732+
56733+#ifdef CONFIG_PAX_SEGMEXEC
56734+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56735+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56736+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56737+ pax_task_size = SEGMEXEC_TASK_SIZE;
56738+ current->mm->def_flags |= VM_NOHUGEPAGE;
56739+ } else
56740+#endif
56741+
56742+ pax_task_size = TASK_SIZE;
56743+
56744+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56745+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56746+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56747+ put_cpu();
56748+ }
56749+#endif
56750+
56751+#ifdef CONFIG_PAX_ASLR
56752+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56753+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56754+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56755+ }
56756+#endif
56757+
56758+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56759+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56760+ executable_stack = EXSTACK_DISABLE_X;
56761+ current->personality &= ~READ_IMPLIES_EXEC;
56762+ } else
56763+#endif
56764+
56765 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56766 current->personality |= READ_IMPLIES_EXEC;
56767
56768@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56769 #else
56770 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56771 #endif
56772+
56773+#ifdef CONFIG_PAX_RANDMMAP
56774+ /* PaX: randomize base address at the default exe base if requested */
56775+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56776+#ifdef CONFIG_SPARC64
56777+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56778+#else
56779+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56780+#endif
56781+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56782+ elf_flags |= MAP_FIXED;
56783+ }
56784+#endif
56785+
56786 }
56787
56788 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56789@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56790 * allowed task size. Note that p_filesz must always be
56791 * <= p_memsz so it is only necessary to check p_memsz.
56792 */
56793- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56794- elf_ppnt->p_memsz > TASK_SIZE ||
56795- TASK_SIZE - elf_ppnt->p_memsz < k) {
56796+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56797+ elf_ppnt->p_memsz > pax_task_size ||
56798+ pax_task_size - elf_ppnt->p_memsz < k) {
56799 /* set_brk can never work. Avoid overflows. */
56800 send_sig(SIGKILL, current, 0);
56801 retval = -EINVAL;
56802@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56803 goto out_free_dentry;
56804 }
56805 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56806- send_sig(SIGSEGV, current, 0);
56807- retval = -EFAULT; /* Nobody gets to see this, but.. */
56808- goto out_free_dentry;
56809+ /*
56810+ * This bss-zeroing can fail if the ELF
56811+ * file specifies odd protections. So
56812+ * we don't check the return value
56813+ */
56814 }
56815
56816+#ifdef CONFIG_PAX_RANDMMAP
56817+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56818+ unsigned long start, size, flags;
56819+ vm_flags_t vm_flags;
56820+
56821+ start = ELF_PAGEALIGN(elf_brk);
56822+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56823+ flags = MAP_FIXED | MAP_PRIVATE;
56824+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56825+
56826+ down_write(&current->mm->mmap_sem);
56827+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56828+ retval = -ENOMEM;
56829+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56830+// if (current->personality & ADDR_NO_RANDOMIZE)
56831+// vm_flags |= VM_READ | VM_MAYREAD;
56832+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56833+ retval = IS_ERR_VALUE(start) ? start : 0;
56834+ }
56835+ up_write(&current->mm->mmap_sem);
56836+ if (retval == 0)
56837+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56838+ if (retval < 0) {
56839+ send_sig(SIGKILL, current, 0);
56840+ goto out_free_dentry;
56841+ }
56842+ }
56843+#endif
56844+
56845 if (elf_interpreter) {
56846- unsigned long interp_map_addr = 0;
56847-
56848 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56849 interpreter,
56850- &interp_map_addr,
56851 load_bias);
56852 if (!IS_ERR((void *)elf_entry)) {
56853 /*
56854@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56855 * Decide what to dump of a segment, part, all or none.
56856 */
56857 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56858- unsigned long mm_flags)
56859+ unsigned long mm_flags, long signr)
56860 {
56861 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56862
56863@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56864 if (vma->vm_file == NULL)
56865 return 0;
56866
56867- if (FILTER(MAPPED_PRIVATE))
56868+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56869 goto whole;
56870
56871 /*
56872@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56873 {
56874 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56875 int i = 0;
56876- do
56877+ do {
56878 i += 2;
56879- while (auxv[i - 2] != AT_NULL);
56880+ } while (auxv[i - 2] != AT_NULL);
56881 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56882 }
56883
56884@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56885 {
56886 mm_segment_t old_fs = get_fs();
56887 set_fs(KERNEL_DS);
56888- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56889+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56890 set_fs(old_fs);
56891 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56892 }
56893@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56894 }
56895
56896 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56897- unsigned long mm_flags)
56898+ struct coredump_params *cprm)
56899 {
56900 struct vm_area_struct *vma;
56901 size_t size = 0;
56902
56903 for (vma = first_vma(current, gate_vma); vma != NULL;
56904 vma = next_vma(vma, gate_vma))
56905- size += vma_dump_size(vma, mm_flags);
56906+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56907 return size;
56908 }
56909
56910@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56911
56912 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56913
56914- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56915+ offset += elf_core_vma_data_size(gate_vma, cprm);
56916 offset += elf_core_extra_data_size();
56917 e_shoff = offset;
56918
56919@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56920 phdr.p_offset = offset;
56921 phdr.p_vaddr = vma->vm_start;
56922 phdr.p_paddr = 0;
56923- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56924+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56925 phdr.p_memsz = vma->vm_end - vma->vm_start;
56926 offset += phdr.p_filesz;
56927 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56928@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56929 unsigned long addr;
56930 unsigned long end;
56931
56932- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56933+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56934
56935 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56936 struct page *page;
56937@@ -2199,6 +2678,167 @@ out:
56938
56939 #endif /* CONFIG_ELF_CORE */
56940
56941+#ifdef CONFIG_PAX_MPROTECT
56942+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56943+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56944+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56945+ *
56946+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56947+ * basis because we want to allow the common case and not the special ones.
56948+ */
56949+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56950+{
56951+ struct elfhdr elf_h;
56952+ struct elf_phdr elf_p;
56953+ unsigned long i;
56954+ unsigned long oldflags;
56955+ bool is_textrel_rw, is_textrel_rx, is_relro;
56956+
56957+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56958+ return;
56959+
56960+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56961+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56962+
56963+#ifdef CONFIG_PAX_ELFRELOCS
56964+ /* possible TEXTREL */
56965+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56966+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56967+#else
56968+ is_textrel_rw = false;
56969+ is_textrel_rx = false;
56970+#endif
56971+
56972+ /* possible RELRO */
56973+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56974+
56975+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56976+ return;
56977+
56978+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56979+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56980+
56981+#ifdef CONFIG_PAX_ETEXECRELOCS
56982+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56983+#else
56984+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56985+#endif
56986+
56987+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56988+ !elf_check_arch(&elf_h) ||
56989+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56990+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56991+ return;
56992+
56993+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56994+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56995+ return;
56996+ switch (elf_p.p_type) {
56997+ case PT_DYNAMIC:
56998+ if (!is_textrel_rw && !is_textrel_rx)
56999+ continue;
57000+ i = 0UL;
57001+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57002+ elf_dyn dyn;
57003+
57004+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57005+ break;
57006+ if (dyn.d_tag == DT_NULL)
57007+ break;
57008+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57009+ gr_log_textrel(vma);
57010+ if (is_textrel_rw)
57011+ vma->vm_flags |= VM_MAYWRITE;
57012+ else
57013+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57014+ vma->vm_flags &= ~VM_MAYWRITE;
57015+ break;
57016+ }
57017+ i++;
57018+ }
57019+ is_textrel_rw = false;
57020+ is_textrel_rx = false;
57021+ continue;
57022+
57023+ case PT_GNU_RELRO:
57024+ if (!is_relro)
57025+ continue;
57026+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57027+ vma->vm_flags &= ~VM_MAYWRITE;
57028+ is_relro = false;
57029+ continue;
57030+
57031+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57032+ case PT_PAX_FLAGS: {
57033+ const char *msg_mprotect = "", *msg_emutramp = "";
57034+ char *buffer_lib, *buffer_exe;
57035+
57036+ if (elf_p.p_flags & PF_NOMPROTECT)
57037+ msg_mprotect = "MPROTECT disabled";
57038+
57039+#ifdef CONFIG_PAX_EMUTRAMP
57040+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57041+ msg_emutramp = "EMUTRAMP enabled";
57042+#endif
57043+
57044+ if (!msg_mprotect[0] && !msg_emutramp[0])
57045+ continue;
57046+
57047+ if (!printk_ratelimit())
57048+ continue;
57049+
57050+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57051+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57052+ if (buffer_lib && buffer_exe) {
57053+ char *path_lib, *path_exe;
57054+
57055+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57056+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57057+
57058+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57059+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57060+
57061+ }
57062+ free_page((unsigned long)buffer_exe);
57063+ free_page((unsigned long)buffer_lib);
57064+ continue;
57065+ }
57066+#endif
57067+
57068+ }
57069+ }
57070+}
57071+#endif
57072+
57073+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57074+
57075+extern int grsec_enable_log_rwxmaps;
57076+
57077+static void elf_handle_mmap(struct file *file)
57078+{
57079+ struct elfhdr elf_h;
57080+ struct elf_phdr elf_p;
57081+ unsigned long i;
57082+
57083+ if (!grsec_enable_log_rwxmaps)
57084+ return;
57085+
57086+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57087+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57088+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57089+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57090+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57091+ return;
57092+
57093+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57094+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57095+ return;
57096+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57097+ gr_log_ptgnustack(file);
57098+ }
57099+}
57100+#endif
57101+
57102 static int __init init_elf_binfmt(void)
57103 {
57104 register_binfmt(&elf_format);
57105diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
57106index d50bbe5..af3b649 100644
57107--- a/fs/binfmt_flat.c
57108+++ b/fs/binfmt_flat.c
57109@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
57110 realdatastart = (unsigned long) -ENOMEM;
57111 printk("Unable to allocate RAM for process data, errno %d\n",
57112 (int)-realdatastart);
57113+ down_write(&current->mm->mmap_sem);
57114 vm_munmap(textpos, text_len);
57115+ up_write(&current->mm->mmap_sem);
57116 ret = realdatastart;
57117 goto err;
57118 }
57119@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57120 }
57121 if (IS_ERR_VALUE(result)) {
57122 printk("Unable to read data+bss, errno %d\n", (int)-result);
57123+ down_write(&current->mm->mmap_sem);
57124 vm_munmap(textpos, text_len);
57125 vm_munmap(realdatastart, len);
57126+ up_write(&current->mm->mmap_sem);
57127 ret = result;
57128 goto err;
57129 }
57130@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57131 }
57132 if (IS_ERR_VALUE(result)) {
57133 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57134+ down_write(&current->mm->mmap_sem);
57135 vm_munmap(textpos, text_len + data_len + extra +
57136 MAX_SHARED_LIBS * sizeof(unsigned long));
57137+ up_write(&current->mm->mmap_sem);
57138 ret = result;
57139 goto err;
57140 }
57141diff --git a/fs/bio.c b/fs/bio.c
57142index 8754e7b..0669094 100644
57143--- a/fs/bio.c
57144+++ b/fs/bio.c
57145@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57146 /*
57147 * Overflow, abort
57148 */
57149- if (end < start)
57150+ if (end < start || end - start > INT_MAX - nr_pages)
57151 return ERR_PTR(-EINVAL);
57152
57153 nr_pages += end - start;
57154@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57155 /*
57156 * Overflow, abort
57157 */
57158- if (end < start)
57159+ if (end < start || end - start > INT_MAX - nr_pages)
57160 return ERR_PTR(-EINVAL);
57161
57162 nr_pages += end - start;
57163@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57164 const int read = bio_data_dir(bio) == READ;
57165 struct bio_map_data *bmd = bio->bi_private;
57166 int i;
57167- char *p = bmd->sgvecs[0].iov_base;
57168+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57169
57170 bio_for_each_segment_all(bvec, bio, i) {
57171 char *addr = page_address(bvec->bv_page);
57172diff --git a/fs/block_dev.c b/fs/block_dev.c
57173index 1e86823..8e34695 100644
57174--- a/fs/block_dev.c
57175+++ b/fs/block_dev.c
57176@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57177 else if (bdev->bd_contains == bdev)
57178 return true; /* is a whole device which isn't held */
57179
57180- else if (whole->bd_holder == bd_may_claim)
57181+ else if (whole->bd_holder == (void *)bd_may_claim)
57182 return true; /* is a partition of a device that is being partitioned */
57183 else if (whole->bd_holder != NULL)
57184 return false; /* is a partition of a held device */
57185diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57186index cbd3a7d..c6a2881 100644
57187--- a/fs/btrfs/ctree.c
57188+++ b/fs/btrfs/ctree.c
57189@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57190 free_extent_buffer(buf);
57191 add_root_to_dirty_list(root);
57192 } else {
57193- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57194- parent_start = parent->start;
57195- else
57196+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57197+ if (parent)
57198+ parent_start = parent->start;
57199+ else
57200+ parent_start = 0;
57201+ } else
57202 parent_start = 0;
57203
57204 WARN_ON(trans->transid != btrfs_header_generation(parent));
57205diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57206index 451b00c..a2cccee 100644
57207--- a/fs/btrfs/delayed-inode.c
57208+++ b/fs/btrfs/delayed-inode.c
57209@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57210
57211 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57212 {
57213- int seq = atomic_inc_return(&delayed_root->items_seq);
57214+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57215 if ((atomic_dec_return(&delayed_root->items) <
57216 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57217 waitqueue_active(&delayed_root->wait))
57218@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57219
57220 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57221 {
57222- int val = atomic_read(&delayed_root->items_seq);
57223+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57224
57225 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57226 return 1;
57227@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57228 int seq;
57229 int ret;
57230
57231- seq = atomic_read(&delayed_root->items_seq);
57232+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57233
57234 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57235 if (ret)
57236diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57237index f70119f..ab5894d 100644
57238--- a/fs/btrfs/delayed-inode.h
57239+++ b/fs/btrfs/delayed-inode.h
57240@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57241 */
57242 struct list_head prepare_list;
57243 atomic_t items; /* for delayed items */
57244- atomic_t items_seq; /* for delayed items */
57245+ atomic_unchecked_t items_seq; /* for delayed items */
57246 int nodes; /* for delayed nodes */
57247 wait_queue_head_t wait;
57248 };
57249@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57250 struct btrfs_delayed_root *delayed_root)
57251 {
57252 atomic_set(&delayed_root->items, 0);
57253- atomic_set(&delayed_root->items_seq, 0);
57254+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57255 delayed_root->nodes = 0;
57256 spin_lock_init(&delayed_root->lock);
57257 init_waitqueue_head(&delayed_root->wait);
57258diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57259index a6d8efa..2f062cf 100644
57260--- a/fs/btrfs/ioctl.c
57261+++ b/fs/btrfs/ioctl.c
57262@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57263 for (i = 0; i < num_types; i++) {
57264 struct btrfs_space_info *tmp;
57265
57266+ /* Don't copy in more than we allocated */
57267 if (!slot_count)
57268 break;
57269
57270+ slot_count--;
57271+
57272 info = NULL;
57273 rcu_read_lock();
57274 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57275@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57276 memcpy(dest, &space, sizeof(space));
57277 dest++;
57278 space_args.total_spaces++;
57279- slot_count--;
57280 }
57281- if (!slot_count)
57282- break;
57283 }
57284 up_read(&info->groups_sem);
57285 }
57286diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57287index d04db81..96e54f1 100644
57288--- a/fs/btrfs/super.c
57289+++ b/fs/btrfs/super.c
57290@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57291 function, line, errstr);
57292 return;
57293 }
57294- ACCESS_ONCE(trans->transaction->aborted) = errno;
57295+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57296 /* Wake up anybody who may be waiting on this transaction */
57297 wake_up(&root->fs_info->transaction_wait);
57298 wake_up(&root->fs_info->transaction_blocked_wait);
57299diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57300index 865f4cf..f321e86 100644
57301--- a/fs/btrfs/sysfs.c
57302+++ b/fs/btrfs/sysfs.c
57303@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57304 for (set = 0; set < FEAT_MAX; set++) {
57305 int i;
57306 struct attribute *attrs[2];
57307- struct attribute_group agroup = {
57308+ attribute_group_no_const agroup = {
57309 .name = "features",
57310 .attrs = attrs,
57311 };
57312diff --git a/fs/buffer.c b/fs/buffer.c
57313index 27265a8..289f488 100644
57314--- a/fs/buffer.c
57315+++ b/fs/buffer.c
57316@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57317 bh_cachep = kmem_cache_create("buffer_head",
57318 sizeof(struct buffer_head), 0,
57319 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57320- SLAB_MEM_SPREAD),
57321+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57322 NULL);
57323
57324 /*
57325diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57326index 622f469..e8d2d55 100644
57327--- a/fs/cachefiles/bind.c
57328+++ b/fs/cachefiles/bind.c
57329@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57330 args);
57331
57332 /* start by checking things over */
57333- ASSERT(cache->fstop_percent >= 0 &&
57334- cache->fstop_percent < cache->fcull_percent &&
57335+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57336 cache->fcull_percent < cache->frun_percent &&
57337 cache->frun_percent < 100);
57338
57339- ASSERT(cache->bstop_percent >= 0 &&
57340- cache->bstop_percent < cache->bcull_percent &&
57341+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57342 cache->bcull_percent < cache->brun_percent &&
57343 cache->brun_percent < 100);
57344
57345diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57346index 0a1467b..6a53245 100644
57347--- a/fs/cachefiles/daemon.c
57348+++ b/fs/cachefiles/daemon.c
57349@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57350 if (n > buflen)
57351 return -EMSGSIZE;
57352
57353- if (copy_to_user(_buffer, buffer, n) != 0)
57354+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57355 return -EFAULT;
57356
57357 return n;
57358@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57359 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57360 return -EIO;
57361
57362- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57363+ if (datalen > PAGE_SIZE - 1)
57364 return -EOPNOTSUPP;
57365
57366 /* drag the command string into the kernel so we can parse it */
57367@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57368 if (args[0] != '%' || args[1] != '\0')
57369 return -EINVAL;
57370
57371- if (fstop < 0 || fstop >= cache->fcull_percent)
57372+ if (fstop >= cache->fcull_percent)
57373 return cachefiles_daemon_range_error(cache, args);
57374
57375 cache->fstop_percent = fstop;
57376@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57377 if (args[0] != '%' || args[1] != '\0')
57378 return -EINVAL;
57379
57380- if (bstop < 0 || bstop >= cache->bcull_percent)
57381+ if (bstop >= cache->bcull_percent)
57382 return cachefiles_daemon_range_error(cache, args);
57383
57384 cache->bstop_percent = bstop;
57385diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57386index 5349473..d6c0b93 100644
57387--- a/fs/cachefiles/internal.h
57388+++ b/fs/cachefiles/internal.h
57389@@ -59,7 +59,7 @@ struct cachefiles_cache {
57390 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57391 struct rb_root active_nodes; /* active nodes (can't be culled) */
57392 rwlock_t active_lock; /* lock for active_nodes */
57393- atomic_t gravecounter; /* graveyard uniquifier */
57394+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57395 unsigned frun_percent; /* when to stop culling (% files) */
57396 unsigned fcull_percent; /* when to start culling (% files) */
57397 unsigned fstop_percent; /* when to stop allocating (% files) */
57398@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57399 * proc.c
57400 */
57401 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57402-extern atomic_t cachefiles_lookup_histogram[HZ];
57403-extern atomic_t cachefiles_mkdir_histogram[HZ];
57404-extern atomic_t cachefiles_create_histogram[HZ];
57405+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57406+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57407+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57408
57409 extern int __init cachefiles_proc_init(void);
57410 extern void cachefiles_proc_cleanup(void);
57411 static inline
57412-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57413+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57414 {
57415 unsigned long jif = jiffies - start_jif;
57416 if (jif >= HZ)
57417 jif = HZ - 1;
57418- atomic_inc(&histogram[jif]);
57419+ atomic_inc_unchecked(&histogram[jif]);
57420 }
57421
57422 #else
57423diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57424index ca65f39..48921e3 100644
57425--- a/fs/cachefiles/namei.c
57426+++ b/fs/cachefiles/namei.c
57427@@ -317,7 +317,7 @@ try_again:
57428 /* first step is to make up a grave dentry in the graveyard */
57429 sprintf(nbuffer, "%08x%08x",
57430 (uint32_t) get_seconds(),
57431- (uint32_t) atomic_inc_return(&cache->gravecounter));
57432+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57433
57434 /* do the multiway lock magic */
57435 trap = lock_rename(cache->graveyard, dir);
57436diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57437index eccd339..4c1d995 100644
57438--- a/fs/cachefiles/proc.c
57439+++ b/fs/cachefiles/proc.c
57440@@ -14,9 +14,9 @@
57441 #include <linux/seq_file.h>
57442 #include "internal.h"
57443
57444-atomic_t cachefiles_lookup_histogram[HZ];
57445-atomic_t cachefiles_mkdir_histogram[HZ];
57446-atomic_t cachefiles_create_histogram[HZ];
57447+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57448+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57449+atomic_unchecked_t cachefiles_create_histogram[HZ];
57450
57451 /*
57452 * display the latency histogram
57453@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57454 return 0;
57455 default:
57456 index = (unsigned long) v - 3;
57457- x = atomic_read(&cachefiles_lookup_histogram[index]);
57458- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57459- z = atomic_read(&cachefiles_create_histogram[index]);
57460+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57461+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57462+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57463 if (x == 0 && y == 0 && z == 0)
57464 return 0;
57465
57466diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57467index ebaff36..7e3ea26 100644
57468--- a/fs/cachefiles/rdwr.c
57469+++ b/fs/cachefiles/rdwr.c
57470@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57471 old_fs = get_fs();
57472 set_fs(KERNEL_DS);
57473 ret = file->f_op->write(
57474- file, (const void __user *) data, len, &pos);
57475+ file, (const void __force_user *) data, len, &pos);
57476 set_fs(old_fs);
57477 kunmap(page);
57478 file_end_write(file);
57479diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57480index 45eda6d..9126f7f 100644
57481--- a/fs/ceph/dir.c
57482+++ b/fs/ceph/dir.c
57483@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57484 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57485 struct ceph_mds_client *mdsc = fsc->mdsc;
57486 unsigned frag = fpos_frag(ctx->pos);
57487- int off = fpos_off(ctx->pos);
57488+ unsigned int off = fpos_off(ctx->pos);
57489 int err;
57490 u32 ftype;
57491 struct ceph_mds_reply_info_parsed *rinfo;
57492diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57493index 10a4ccb..92dbc5e 100644
57494--- a/fs/ceph/super.c
57495+++ b/fs/ceph/super.c
57496@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57497 /*
57498 * construct our own bdi so we can control readahead, etc.
57499 */
57500-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57501+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57502
57503 static int ceph_register_bdi(struct super_block *sb,
57504 struct ceph_fs_client *fsc)
57505@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57506 default_backing_dev_info.ra_pages;
57507
57508 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57509- atomic_long_inc_return(&bdi_seq));
57510+ atomic_long_inc_return_unchecked(&bdi_seq));
57511 if (!err)
57512 sb->s_bdi = &fsc->backing_dev_info;
57513 return err;
57514diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57515index f3ac415..3d2420c 100644
57516--- a/fs/cifs/cifs_debug.c
57517+++ b/fs/cifs/cifs_debug.c
57518@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57519
57520 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57521 #ifdef CONFIG_CIFS_STATS2
57522- atomic_set(&totBufAllocCount, 0);
57523- atomic_set(&totSmBufAllocCount, 0);
57524+ atomic_set_unchecked(&totBufAllocCount, 0);
57525+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57526 #endif /* CONFIG_CIFS_STATS2 */
57527 spin_lock(&cifs_tcp_ses_lock);
57528 list_for_each(tmp1, &cifs_tcp_ses_list) {
57529@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57530 tcon = list_entry(tmp3,
57531 struct cifs_tcon,
57532 tcon_list);
57533- atomic_set(&tcon->num_smbs_sent, 0);
57534+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57535 if (server->ops->clear_stats)
57536 server->ops->clear_stats(tcon);
57537 }
57538@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57539 smBufAllocCount.counter, cifs_min_small);
57540 #ifdef CONFIG_CIFS_STATS2
57541 seq_printf(m, "Total Large %d Small %d Allocations\n",
57542- atomic_read(&totBufAllocCount),
57543- atomic_read(&totSmBufAllocCount));
57544+ atomic_read_unchecked(&totBufAllocCount),
57545+ atomic_read_unchecked(&totSmBufAllocCount));
57546 #endif /* CONFIG_CIFS_STATS2 */
57547
57548 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57549@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57550 if (tcon->need_reconnect)
57551 seq_puts(m, "\tDISCONNECTED ");
57552 seq_printf(m, "\nSMBs: %d",
57553- atomic_read(&tcon->num_smbs_sent));
57554+ atomic_read_unchecked(&tcon->num_smbs_sent));
57555 if (server->ops->print_stats)
57556 server->ops->print_stats(m, tcon);
57557 }
57558diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57559index 849f613..eae6dec 100644
57560--- a/fs/cifs/cifsfs.c
57561+++ b/fs/cifs/cifsfs.c
57562@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57563 */
57564 cifs_req_cachep = kmem_cache_create("cifs_request",
57565 CIFSMaxBufSize + max_hdr_size, 0,
57566- SLAB_HWCACHE_ALIGN, NULL);
57567+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57568 if (cifs_req_cachep == NULL)
57569 return -ENOMEM;
57570
57571@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57572 efficient to alloc 1 per page off the slab compared to 17K (5page)
57573 alloc of large cifs buffers even when page debugging is on */
57574 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57575- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57576+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57577 NULL);
57578 if (cifs_sm_req_cachep == NULL) {
57579 mempool_destroy(cifs_req_poolp);
57580@@ -1168,8 +1168,8 @@ init_cifs(void)
57581 atomic_set(&bufAllocCount, 0);
57582 atomic_set(&smBufAllocCount, 0);
57583 #ifdef CONFIG_CIFS_STATS2
57584- atomic_set(&totBufAllocCount, 0);
57585- atomic_set(&totSmBufAllocCount, 0);
57586+ atomic_set_unchecked(&totBufAllocCount, 0);
57587+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57588 #endif /* CONFIG_CIFS_STATS2 */
57589
57590 atomic_set(&midCount, 0);
57591diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57592index c0f3718..6afed7d 100644
57593--- a/fs/cifs/cifsglob.h
57594+++ b/fs/cifs/cifsglob.h
57595@@ -804,35 +804,35 @@ struct cifs_tcon {
57596 __u16 Flags; /* optional support bits */
57597 enum statusEnum tidStatus;
57598 #ifdef CONFIG_CIFS_STATS
57599- atomic_t num_smbs_sent;
57600+ atomic_unchecked_t num_smbs_sent;
57601 union {
57602 struct {
57603- atomic_t num_writes;
57604- atomic_t num_reads;
57605- atomic_t num_flushes;
57606- atomic_t num_oplock_brks;
57607- atomic_t num_opens;
57608- atomic_t num_closes;
57609- atomic_t num_deletes;
57610- atomic_t num_mkdirs;
57611- atomic_t num_posixopens;
57612- atomic_t num_posixmkdirs;
57613- atomic_t num_rmdirs;
57614- atomic_t num_renames;
57615- atomic_t num_t2renames;
57616- atomic_t num_ffirst;
57617- atomic_t num_fnext;
57618- atomic_t num_fclose;
57619- atomic_t num_hardlinks;
57620- atomic_t num_symlinks;
57621- atomic_t num_locks;
57622- atomic_t num_acl_get;
57623- atomic_t num_acl_set;
57624+ atomic_unchecked_t num_writes;
57625+ atomic_unchecked_t num_reads;
57626+ atomic_unchecked_t num_flushes;
57627+ atomic_unchecked_t num_oplock_brks;
57628+ atomic_unchecked_t num_opens;
57629+ atomic_unchecked_t num_closes;
57630+ atomic_unchecked_t num_deletes;
57631+ atomic_unchecked_t num_mkdirs;
57632+ atomic_unchecked_t num_posixopens;
57633+ atomic_unchecked_t num_posixmkdirs;
57634+ atomic_unchecked_t num_rmdirs;
57635+ atomic_unchecked_t num_renames;
57636+ atomic_unchecked_t num_t2renames;
57637+ atomic_unchecked_t num_ffirst;
57638+ atomic_unchecked_t num_fnext;
57639+ atomic_unchecked_t num_fclose;
57640+ atomic_unchecked_t num_hardlinks;
57641+ atomic_unchecked_t num_symlinks;
57642+ atomic_unchecked_t num_locks;
57643+ atomic_unchecked_t num_acl_get;
57644+ atomic_unchecked_t num_acl_set;
57645 } cifs_stats;
57646 #ifdef CONFIG_CIFS_SMB2
57647 struct {
57648- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57649- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57650+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57651+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57652 } smb2_stats;
57653 #endif /* CONFIG_CIFS_SMB2 */
57654 } stats;
57655@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57656 }
57657
57658 #ifdef CONFIG_CIFS_STATS
57659-#define cifs_stats_inc atomic_inc
57660+#define cifs_stats_inc atomic_inc_unchecked
57661
57662 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57663 unsigned int bytes)
57664@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57665 /* Various Debug counters */
57666 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57667 #ifdef CONFIG_CIFS_STATS2
57668-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57669-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57670+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57671+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57672 #endif
57673 GLOBAL_EXTERN atomic_t smBufAllocCount;
57674 GLOBAL_EXTERN atomic_t midCount;
57675diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57676index 834fce7..8a314b5 100644
57677--- a/fs/cifs/file.c
57678+++ b/fs/cifs/file.c
57679@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57680 index = mapping->writeback_index; /* Start from prev offset */
57681 end = -1;
57682 } else {
57683- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57684- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57685- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57686+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57687 range_whole = true;
57688+ index = 0;
57689+ end = ULONG_MAX;
57690+ } else {
57691+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57692+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57693+ }
57694 scanned = true;
57695 }
57696 retry:
57697diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57698index 2f9f379..43f8025 100644
57699--- a/fs/cifs/misc.c
57700+++ b/fs/cifs/misc.c
57701@@ -170,7 +170,7 @@ cifs_buf_get(void)
57702 memset(ret_buf, 0, buf_size + 3);
57703 atomic_inc(&bufAllocCount);
57704 #ifdef CONFIG_CIFS_STATS2
57705- atomic_inc(&totBufAllocCount);
57706+ atomic_inc_unchecked(&totBufAllocCount);
57707 #endif /* CONFIG_CIFS_STATS2 */
57708 }
57709
57710@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57711 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57712 atomic_inc(&smBufAllocCount);
57713 #ifdef CONFIG_CIFS_STATS2
57714- atomic_inc(&totSmBufAllocCount);
57715+ atomic_inc_unchecked(&totSmBufAllocCount);
57716 #endif /* CONFIG_CIFS_STATS2 */
57717
57718 }
57719diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57720index 526fb89..ecdbf5a 100644
57721--- a/fs/cifs/smb1ops.c
57722+++ b/fs/cifs/smb1ops.c
57723@@ -616,27 +616,27 @@ static void
57724 cifs_clear_stats(struct cifs_tcon *tcon)
57725 {
57726 #ifdef CONFIG_CIFS_STATS
57727- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57728- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57729- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57730- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57731- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57732- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57733- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57734- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57735- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57736- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57737- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57738- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57739- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57740- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57741- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57742- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57743- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57744- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57745- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57746- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57747- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57748+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57749+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57750+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57751+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57752+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57753+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57754+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57755+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57756+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57757+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57758+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57759+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57760+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57761+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57762+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57763+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57764+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57765+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57766+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57767+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57768+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57769 #endif
57770 }
57771
57772@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57773 {
57774 #ifdef CONFIG_CIFS_STATS
57775 seq_printf(m, " Oplocks breaks: %d",
57776- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57777+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57778 seq_printf(m, "\nReads: %d Bytes: %llu",
57779- atomic_read(&tcon->stats.cifs_stats.num_reads),
57780+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57781 (long long)(tcon->bytes_read));
57782 seq_printf(m, "\nWrites: %d Bytes: %llu",
57783- atomic_read(&tcon->stats.cifs_stats.num_writes),
57784+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57785 (long long)(tcon->bytes_written));
57786 seq_printf(m, "\nFlushes: %d",
57787- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57788+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57789 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57790- atomic_read(&tcon->stats.cifs_stats.num_locks),
57791- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57792- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57793+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57794+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57795+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57796 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57797- atomic_read(&tcon->stats.cifs_stats.num_opens),
57798- atomic_read(&tcon->stats.cifs_stats.num_closes),
57799- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57800+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57801+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57802+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57803 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57804- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57805- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57806+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57807+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57808 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57809- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57810- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57811+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57812+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57813 seq_printf(m, "\nRenames: %d T2 Renames %d",
57814- atomic_read(&tcon->stats.cifs_stats.num_renames),
57815- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57816+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57817+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57818 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57819- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57820- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57821- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57822+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57823+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57824+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57825 #endif
57826 }
57827
57828diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57829index 192f51a..539307e 100644
57830--- a/fs/cifs/smb2ops.c
57831+++ b/fs/cifs/smb2ops.c
57832@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57833 #ifdef CONFIG_CIFS_STATS
57834 int i;
57835 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57836- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57837- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57838+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57839+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57840 }
57841 #endif
57842 }
57843@@ -405,65 +405,65 @@ static void
57844 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57845 {
57846 #ifdef CONFIG_CIFS_STATS
57847- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57848- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57849+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57850+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57851 seq_printf(m, "\nNegotiates: %d sent %d failed",
57852- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57853- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57854+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57855+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57856 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57857- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57858- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57859+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57860+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57861 seq_printf(m, "\nLogoffs: %d sent %d failed",
57862- atomic_read(&sent[SMB2_LOGOFF_HE]),
57863- atomic_read(&failed[SMB2_LOGOFF_HE]));
57864+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57865+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57866 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57867- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57868- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57869+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57870+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57871 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57872- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57873- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57874+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57875+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57876 seq_printf(m, "\nCreates: %d sent %d failed",
57877- atomic_read(&sent[SMB2_CREATE_HE]),
57878- atomic_read(&failed[SMB2_CREATE_HE]));
57879+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57880+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57881 seq_printf(m, "\nCloses: %d sent %d failed",
57882- atomic_read(&sent[SMB2_CLOSE_HE]),
57883- atomic_read(&failed[SMB2_CLOSE_HE]));
57884+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57885+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57886 seq_printf(m, "\nFlushes: %d sent %d failed",
57887- atomic_read(&sent[SMB2_FLUSH_HE]),
57888- atomic_read(&failed[SMB2_FLUSH_HE]));
57889+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57890+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57891 seq_printf(m, "\nReads: %d sent %d failed",
57892- atomic_read(&sent[SMB2_READ_HE]),
57893- atomic_read(&failed[SMB2_READ_HE]));
57894+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57895+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57896 seq_printf(m, "\nWrites: %d sent %d failed",
57897- atomic_read(&sent[SMB2_WRITE_HE]),
57898- atomic_read(&failed[SMB2_WRITE_HE]));
57899+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57900+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57901 seq_printf(m, "\nLocks: %d sent %d failed",
57902- atomic_read(&sent[SMB2_LOCK_HE]),
57903- atomic_read(&failed[SMB2_LOCK_HE]));
57904+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57905+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57906 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57907- atomic_read(&sent[SMB2_IOCTL_HE]),
57908- atomic_read(&failed[SMB2_IOCTL_HE]));
57909+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57910+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57911 seq_printf(m, "\nCancels: %d sent %d failed",
57912- atomic_read(&sent[SMB2_CANCEL_HE]),
57913- atomic_read(&failed[SMB2_CANCEL_HE]));
57914+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57915+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57916 seq_printf(m, "\nEchos: %d sent %d failed",
57917- atomic_read(&sent[SMB2_ECHO_HE]),
57918- atomic_read(&failed[SMB2_ECHO_HE]));
57919+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57920+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57921 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57922- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57923- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57924+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57925+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57926 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57927- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57928- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57929+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57930+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57931 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57932- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57933- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57934+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57935+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57936 seq_printf(m, "\nSetInfos: %d sent %d failed",
57937- atomic_read(&sent[SMB2_SET_INFO_HE]),
57938- atomic_read(&failed[SMB2_SET_INFO_HE]));
57939+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57940+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57941 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57942- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57943- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57944+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57945+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57946 #endif
57947 }
57948
57949diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57950index 8603447..f9caeee 100644
57951--- a/fs/cifs/smb2pdu.c
57952+++ b/fs/cifs/smb2pdu.c
57953@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57954 default:
57955 cifs_dbg(VFS, "info level %u isn't supported\n",
57956 srch_inf->info_level);
57957- rc = -EINVAL;
57958- goto qdir_exit;
57959+ return -EINVAL;
57960 }
57961
57962 req->FileIndex = cpu_to_le32(index);
57963diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57964index 1da168c..8bc7ff6 100644
57965--- a/fs/coda/cache.c
57966+++ b/fs/coda/cache.c
57967@@ -24,7 +24,7 @@
57968 #include "coda_linux.h"
57969 #include "coda_cache.h"
57970
57971-static atomic_t permission_epoch = ATOMIC_INIT(0);
57972+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57973
57974 /* replace or extend an acl cache hit */
57975 void coda_cache_enter(struct inode *inode, int mask)
57976@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57977 struct coda_inode_info *cii = ITOC(inode);
57978
57979 spin_lock(&cii->c_lock);
57980- cii->c_cached_epoch = atomic_read(&permission_epoch);
57981+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57982 if (!uid_eq(cii->c_uid, current_fsuid())) {
57983 cii->c_uid = current_fsuid();
57984 cii->c_cached_perm = mask;
57985@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57986 {
57987 struct coda_inode_info *cii = ITOC(inode);
57988 spin_lock(&cii->c_lock);
57989- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57990+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57991 spin_unlock(&cii->c_lock);
57992 }
57993
57994 /* remove all acl caches */
57995 void coda_cache_clear_all(struct super_block *sb)
57996 {
57997- atomic_inc(&permission_epoch);
57998+ atomic_inc_unchecked(&permission_epoch);
57999 }
58000
58001
58002@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58003 spin_lock(&cii->c_lock);
58004 hit = (mask & cii->c_cached_perm) == mask &&
58005 uid_eq(cii->c_uid, current_fsuid()) &&
58006- cii->c_cached_epoch == atomic_read(&permission_epoch);
58007+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58008 spin_unlock(&cii->c_lock);
58009
58010 return hit;
58011diff --git a/fs/compat.c b/fs/compat.c
58012index 6af20de..fec3fbb 100644
58013--- a/fs/compat.c
58014+++ b/fs/compat.c
58015@@ -54,7 +54,7 @@
58016 #include <asm/ioctls.h>
58017 #include "internal.h"
58018
58019-int compat_log = 1;
58020+int compat_log = 0;
58021
58022 int compat_printk(const char *fmt, ...)
58023 {
58024@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58025
58026 set_fs(KERNEL_DS);
58027 /* The __user pointer cast is valid because of the set_fs() */
58028- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58029+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58030 set_fs(oldfs);
58031 /* truncating is ok because it's a user address */
58032 if (!ret)
58033@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58034 goto out;
58035
58036 ret = -EINVAL;
58037- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58038+ if (nr_segs > UIO_MAXIOV)
58039 goto out;
58040 if (nr_segs > fast_segs) {
58041 ret = -ENOMEM;
58042@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58043 struct compat_readdir_callback {
58044 struct dir_context ctx;
58045 struct compat_old_linux_dirent __user *dirent;
58046+ struct file * file;
58047 int result;
58048 };
58049
58050@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58051 buf->result = -EOVERFLOW;
58052 return -EOVERFLOW;
58053 }
58054+
58055+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58056+ return 0;
58057+
58058 buf->result++;
58059 dirent = buf->dirent;
58060 if (!access_ok(VERIFY_WRITE, dirent,
58061@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58062 if (!f.file)
58063 return -EBADF;
58064
58065+ buf.file = f.file;
58066 error = iterate_dir(f.file, &buf.ctx);
58067 if (buf.result)
58068 error = buf.result;
58069@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58070 struct dir_context ctx;
58071 struct compat_linux_dirent __user *current_dir;
58072 struct compat_linux_dirent __user *previous;
58073+ struct file * file;
58074 int count;
58075 int error;
58076 };
58077@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58078 buf->error = -EOVERFLOW;
58079 return -EOVERFLOW;
58080 }
58081+
58082+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58083+ return 0;
58084+
58085 dirent = buf->previous;
58086 if (dirent) {
58087 if (__put_user(offset, &dirent->d_off))
58088@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58089 if (!f.file)
58090 return -EBADF;
58091
58092+ buf.file = f.file;
58093 error = iterate_dir(f.file, &buf.ctx);
58094 if (error >= 0)
58095 error = buf.error;
58096@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58097 struct dir_context ctx;
58098 struct linux_dirent64 __user *current_dir;
58099 struct linux_dirent64 __user *previous;
58100+ struct file * file;
58101 int count;
58102 int error;
58103 };
58104@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58105 buf->error = -EINVAL; /* only used if we fail.. */
58106 if (reclen > buf->count)
58107 return -EINVAL;
58108+
58109+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58110+ return 0;
58111+
58112 dirent = buf->previous;
58113
58114 if (dirent) {
58115@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58116 if (!f.file)
58117 return -EBADF;
58118
58119+ buf.file = f.file;
58120 error = iterate_dir(f.file, &buf.ctx);
58121 if (error >= 0)
58122 error = buf.error;
58123diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58124index a81147e..20bf2b5 100644
58125--- a/fs/compat_binfmt_elf.c
58126+++ b/fs/compat_binfmt_elf.c
58127@@ -30,11 +30,13 @@
58128 #undef elf_phdr
58129 #undef elf_shdr
58130 #undef elf_note
58131+#undef elf_dyn
58132 #undef elf_addr_t
58133 #define elfhdr elf32_hdr
58134 #define elf_phdr elf32_phdr
58135 #define elf_shdr elf32_shdr
58136 #define elf_note elf32_note
58137+#define elf_dyn Elf32_Dyn
58138 #define elf_addr_t Elf32_Addr
58139
58140 /*
58141diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58142index 3881610..ab3df0b 100644
58143--- a/fs/compat_ioctl.c
58144+++ b/fs/compat_ioctl.c
58145@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58146 return -EFAULT;
58147 if (__get_user(udata, &ss32->iomem_base))
58148 return -EFAULT;
58149- ss.iomem_base = compat_ptr(udata);
58150+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58151 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58152 __get_user(ss.port_high, &ss32->port_high))
58153 return -EFAULT;
58154@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58155 for (i = 0; i < nmsgs; i++) {
58156 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58157 return -EFAULT;
58158- if (get_user(datap, &umsgs[i].buf) ||
58159- put_user(compat_ptr(datap), &tmsgs[i].buf))
58160+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58161+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58162 return -EFAULT;
58163 }
58164 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58165@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58166 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58167 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58168 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58169- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58170+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58171 return -EFAULT;
58172
58173 return ioctl_preallocate(file, p);
58174@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58175 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58176 {
58177 unsigned int a, b;
58178- a = *(unsigned int *)p;
58179- b = *(unsigned int *)q;
58180+ a = *(const unsigned int *)p;
58181+ b = *(const unsigned int *)q;
58182 if (a > b)
58183 return 1;
58184 if (a < b)
58185diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58186index e081acb..911df21 100644
58187--- a/fs/configfs/dir.c
58188+++ b/fs/configfs/dir.c
58189@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58190 }
58191 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58192 struct configfs_dirent *next;
58193- const char *name;
58194+ const unsigned char * name;
58195+ char d_name[sizeof(next->s_dentry->d_iname)];
58196 int len;
58197 struct inode *inode = NULL;
58198
58199@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58200 continue;
58201
58202 name = configfs_get_name(next);
58203- len = strlen(name);
58204+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58205+ len = next->s_dentry->d_name.len;
58206+ memcpy(d_name, name, len);
58207+ name = d_name;
58208+ } else
58209+ len = strlen(name);
58210
58211 /*
58212 * We'll have a dentry and an inode for
58213diff --git a/fs/coredump.c b/fs/coredump.c
58214index e3ad709..836c55f 100644
58215--- a/fs/coredump.c
58216+++ b/fs/coredump.c
58217@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58218 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58219 {
58220 int free, need;
58221+ va_list arg_copy;
58222
58223 again:
58224 free = cn->size - cn->used;
58225- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58226+
58227+ va_copy(arg_copy, arg);
58228+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58229+ va_end(arg_copy);
58230+
58231 if (need < free) {
58232 cn->used += need;
58233 return 0;
58234@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58235 struct pipe_inode_info *pipe = file->private_data;
58236
58237 pipe_lock(pipe);
58238- pipe->readers++;
58239- pipe->writers--;
58240+ atomic_inc(&pipe->readers);
58241+ atomic_dec(&pipe->writers);
58242 wake_up_interruptible_sync(&pipe->wait);
58243 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58244 pipe_unlock(pipe);
58245@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58246 * We actually want wait_event_freezable() but then we need
58247 * to clear TIF_SIGPENDING and improve dump_interrupted().
58248 */
58249- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58250+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58251
58252 pipe_lock(pipe);
58253- pipe->readers--;
58254- pipe->writers++;
58255+ atomic_dec(&pipe->readers);
58256+ atomic_inc(&pipe->writers);
58257 pipe_unlock(pipe);
58258 }
58259
58260@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58261 struct files_struct *displaced;
58262 bool need_nonrelative = false;
58263 bool core_dumped = false;
58264- static atomic_t core_dump_count = ATOMIC_INIT(0);
58265+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58266+ long signr = siginfo->si_signo;
58267+ int dumpable;
58268 struct coredump_params cprm = {
58269 .siginfo = siginfo,
58270 .regs = signal_pt_regs(),
58271@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58272 .mm_flags = mm->flags,
58273 };
58274
58275- audit_core_dumps(siginfo->si_signo);
58276+ audit_core_dumps(signr);
58277+
58278+ dumpable = __get_dumpable(cprm.mm_flags);
58279+
58280+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58281+ gr_handle_brute_attach(dumpable);
58282
58283 binfmt = mm->binfmt;
58284 if (!binfmt || !binfmt->core_dump)
58285 goto fail;
58286- if (!__get_dumpable(cprm.mm_flags))
58287+ if (!dumpable)
58288 goto fail;
58289
58290 cred = prepare_creds();
58291@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58292 need_nonrelative = true;
58293 }
58294
58295- retval = coredump_wait(siginfo->si_signo, &core_state);
58296+ retval = coredump_wait(signr, &core_state);
58297 if (retval < 0)
58298 goto fail_creds;
58299
58300@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58301 }
58302 cprm.limit = RLIM_INFINITY;
58303
58304- dump_count = atomic_inc_return(&core_dump_count);
58305+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58306 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58307 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58308 task_tgid_vnr(current), current->comm);
58309@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58310 } else {
58311 struct inode *inode;
58312
58313+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58314+
58315 if (cprm.limit < binfmt->min_coredump)
58316 goto fail_unlock;
58317
58318@@ -668,7 +682,7 @@ close_fail:
58319 filp_close(cprm.file, NULL);
58320 fail_dropcount:
58321 if (ispipe)
58322- atomic_dec(&core_dump_count);
58323+ atomic_dec_unchecked(&core_dump_count);
58324 fail_unlock:
58325 kfree(cn.corename);
58326 coredump_finish(mm, core_dumped);
58327@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58328 struct file *file = cprm->file;
58329 loff_t pos = file->f_pos;
58330 ssize_t n;
58331+
58332+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58333 if (cprm->written + nr > cprm->limit)
58334 return 0;
58335 while (nr) {
58336diff --git a/fs/dcache.c b/fs/dcache.c
58337index ca02c13..7e2b581 100644
58338--- a/fs/dcache.c
58339+++ b/fs/dcache.c
58340@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58341 */
58342 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58343 if (name->len > DNAME_INLINE_LEN-1) {
58344- dname = kmalloc(name->len + 1, GFP_KERNEL);
58345+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58346 if (!dname) {
58347 kmem_cache_free(dentry_cache, dentry);
58348 return NULL;
58349@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58350 mempages -= reserve;
58351
58352 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58353- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58354+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58355+ SLAB_NO_SANITIZE, NULL);
58356
58357 dcache_init();
58358 inode_init();
58359diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58360index 9c0444c..628490c 100644
58361--- a/fs/debugfs/inode.c
58362+++ b/fs/debugfs/inode.c
58363@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58364 */
58365 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58366 {
58367+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58368+ return __create_file(name, S_IFDIR | S_IRWXU,
58369+#else
58370 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58371+#endif
58372 parent, NULL, NULL);
58373 }
58374 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58375diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58376index b167ca4..a224e19 100644
58377--- a/fs/ecryptfs/inode.c
58378+++ b/fs/ecryptfs/inode.c
58379@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58380 old_fs = get_fs();
58381 set_fs(get_ds());
58382 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58383- (char __user *)lower_buf,
58384+ (char __force_user *)lower_buf,
58385 PATH_MAX);
58386 set_fs(old_fs);
58387 if (rc < 0)
58388diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58389index e4141f2..d8263e8 100644
58390--- a/fs/ecryptfs/miscdev.c
58391+++ b/fs/ecryptfs/miscdev.c
58392@@ -304,7 +304,7 @@ check_list:
58393 goto out_unlock_msg_ctx;
58394 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58395 if (msg_ctx->msg) {
58396- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58397+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58398 goto out_unlock_msg_ctx;
58399 i += packet_length_size;
58400 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58401diff --git a/fs/exec.c b/fs/exec.c
58402index 3d78fcc..5a38b6b 100644
58403--- a/fs/exec.c
58404+++ b/fs/exec.c
58405@@ -55,8 +55,20 @@
58406 #include <linux/pipe_fs_i.h>
58407 #include <linux/oom.h>
58408 #include <linux/compat.h>
58409+#include <linux/random.h>
58410+#include <linux/seq_file.h>
58411+#include <linux/coredump.h>
58412+#include <linux/mman.h>
58413+
58414+#ifdef CONFIG_PAX_REFCOUNT
58415+#include <linux/kallsyms.h>
58416+#include <linux/kdebug.h>
58417+#endif
58418+
58419+#include <trace/events/fs.h>
58420
58421 #include <asm/uaccess.h>
58422+#include <asm/sections.h>
58423 #include <asm/mmu_context.h>
58424 #include <asm/tlb.h>
58425
58426@@ -65,19 +77,34 @@
58427
58428 #include <trace/events/sched.h>
58429
58430+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58431+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58432+{
58433+ 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");
58434+}
58435+#endif
58436+
58437+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58438+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58439+EXPORT_SYMBOL(pax_set_initial_flags_func);
58440+#endif
58441+
58442 int suid_dumpable = 0;
58443
58444 static LIST_HEAD(formats);
58445 static DEFINE_RWLOCK(binfmt_lock);
58446
58447+extern int gr_process_kernel_exec_ban(void);
58448+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58449+
58450 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58451 {
58452 BUG_ON(!fmt);
58453 if (WARN_ON(!fmt->load_binary))
58454 return;
58455 write_lock(&binfmt_lock);
58456- insert ? list_add(&fmt->lh, &formats) :
58457- list_add_tail(&fmt->lh, &formats);
58458+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58459+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58460 write_unlock(&binfmt_lock);
58461 }
58462
58463@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58464 void unregister_binfmt(struct linux_binfmt * fmt)
58465 {
58466 write_lock(&binfmt_lock);
58467- list_del(&fmt->lh);
58468+ pax_list_del((struct list_head *)&fmt->lh);
58469 write_unlock(&binfmt_lock);
58470 }
58471
58472@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58473 int write)
58474 {
58475 struct page *page;
58476- int ret;
58477
58478-#ifdef CONFIG_STACK_GROWSUP
58479- if (write) {
58480- ret = expand_downwards(bprm->vma, pos);
58481- if (ret < 0)
58482- return NULL;
58483- }
58484-#endif
58485- ret = get_user_pages(current, bprm->mm, pos,
58486- 1, write, 1, &page, NULL);
58487- if (ret <= 0)
58488+ if (0 > expand_downwards(bprm->vma, pos))
58489+ return NULL;
58490+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58491 return NULL;
58492
58493 if (write) {
58494@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58495 if (size <= ARG_MAX)
58496 return page;
58497
58498+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58499+ // only allow 512KB for argv+env on suid/sgid binaries
58500+ // to prevent easy ASLR exhaustion
58501+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58502+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58503+ (size > (512 * 1024))) {
58504+ put_page(page);
58505+ return NULL;
58506+ }
58507+#endif
58508+
58509 /*
58510 * Limit to 1/4-th the stack size for the argv+env strings.
58511 * This ensures that:
58512@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58513 vma->vm_end = STACK_TOP_MAX;
58514 vma->vm_start = vma->vm_end - PAGE_SIZE;
58515 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58516+
58517+#ifdef CONFIG_PAX_SEGMEXEC
58518+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58519+#endif
58520+
58521 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58522 INIT_LIST_HEAD(&vma->anon_vma_chain);
58523
58524@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58525 mm->stack_vm = mm->total_vm = 1;
58526 up_write(&mm->mmap_sem);
58527 bprm->p = vma->vm_end - sizeof(void *);
58528+
58529+#ifdef CONFIG_PAX_RANDUSTACK
58530+ if (randomize_va_space)
58531+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58532+#endif
58533+
58534 return 0;
58535 err:
58536 up_write(&mm->mmap_sem);
58537@@ -396,7 +437,7 @@ struct user_arg_ptr {
58538 } ptr;
58539 };
58540
58541-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58542+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58543 {
58544 const char __user *native;
58545
58546@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58547 compat_uptr_t compat;
58548
58549 if (get_user(compat, argv.ptr.compat + nr))
58550- return ERR_PTR(-EFAULT);
58551+ return (const char __force_user *)ERR_PTR(-EFAULT);
58552
58553 return compat_ptr(compat);
58554 }
58555 #endif
58556
58557 if (get_user(native, argv.ptr.native + nr))
58558- return ERR_PTR(-EFAULT);
58559+ return (const char __force_user *)ERR_PTR(-EFAULT);
58560
58561 return native;
58562 }
58563@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58564 if (!p)
58565 break;
58566
58567- if (IS_ERR(p))
58568+ if (IS_ERR((const char __force_kernel *)p))
58569 return -EFAULT;
58570
58571 if (i >= max)
58572@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58573
58574 ret = -EFAULT;
58575 str = get_user_arg_ptr(argv, argc);
58576- if (IS_ERR(str))
58577+ if (IS_ERR((const char __force_kernel *)str))
58578 goto out;
58579
58580 len = strnlen_user(str, MAX_ARG_STRLEN);
58581@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58582 int r;
58583 mm_segment_t oldfs = get_fs();
58584 struct user_arg_ptr argv = {
58585- .ptr.native = (const char __user *const __user *)__argv,
58586+ .ptr.native = (const char __user * const __force_user *)__argv,
58587 };
58588
58589 set_fs(KERNEL_DS);
58590@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58591 unsigned long new_end = old_end - shift;
58592 struct mmu_gather tlb;
58593
58594- BUG_ON(new_start > new_end);
58595+ if (new_start >= new_end || new_start < mmap_min_addr)
58596+ return -ENOMEM;
58597
58598 /*
58599 * ensure there are no vmas between where we want to go
58600@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58601 if (vma != find_vma(mm, new_start))
58602 return -EFAULT;
58603
58604+#ifdef CONFIG_PAX_SEGMEXEC
58605+ BUG_ON(pax_find_mirror_vma(vma));
58606+#endif
58607+
58608 /*
58609 * cover the whole range: [new_start, old_end)
58610 */
58611@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58612 stack_top = arch_align_stack(stack_top);
58613 stack_top = PAGE_ALIGN(stack_top);
58614
58615- if (unlikely(stack_top < mmap_min_addr) ||
58616- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58617- return -ENOMEM;
58618-
58619 stack_shift = vma->vm_end - stack_top;
58620
58621 bprm->p -= stack_shift;
58622@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58623 bprm->exec -= stack_shift;
58624
58625 down_write(&mm->mmap_sem);
58626+
58627+ /* Move stack pages down in memory. */
58628+ if (stack_shift) {
58629+ ret = shift_arg_pages(vma, stack_shift);
58630+ if (ret)
58631+ goto out_unlock;
58632+ }
58633+
58634 vm_flags = VM_STACK_FLAGS;
58635
58636+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58637+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58638+ vm_flags &= ~VM_EXEC;
58639+
58640+#ifdef CONFIG_PAX_MPROTECT
58641+ if (mm->pax_flags & MF_PAX_MPROTECT)
58642+ vm_flags &= ~VM_MAYEXEC;
58643+#endif
58644+
58645+ }
58646+#endif
58647+
58648 /*
58649 * Adjust stack execute permissions; explicitly enable for
58650 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58651@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58652 goto out_unlock;
58653 BUG_ON(prev != vma);
58654
58655- /* Move stack pages down in memory. */
58656- if (stack_shift) {
58657- ret = shift_arg_pages(vma, stack_shift);
58658- if (ret)
58659- goto out_unlock;
58660- }
58661-
58662 /* mprotect_fixup is overkill to remove the temporary stack flags */
58663 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58664
58665@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58666 #endif
58667 current->mm->start_stack = bprm->p;
58668 ret = expand_stack(vma, stack_base);
58669+
58670+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58671+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58672+ unsigned long size;
58673+ vm_flags_t vm_flags;
58674+
58675+ size = STACK_TOP - vma->vm_end;
58676+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58677+
58678+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58679+
58680+#ifdef CONFIG_X86
58681+ if (!ret) {
58682+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58683+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58684+ }
58685+#endif
58686+
58687+ }
58688+#endif
58689+
58690 if (ret)
58691 ret = -EFAULT;
58692
58693@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58694
58695 fsnotify_open(file);
58696
58697+ trace_open_exec(name->name);
58698+
58699 err = deny_write_access(file);
58700 if (err)
58701 goto exit;
58702@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58703 old_fs = get_fs();
58704 set_fs(get_ds());
58705 /* The cast to a user pointer is valid due to the set_fs() */
58706- result = vfs_read(file, (void __user *)addr, count, &pos);
58707+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58708 set_fs(old_fs);
58709 return result;
58710 }
58711@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58712 }
58713 rcu_read_unlock();
58714
58715- if (p->fs->users > n_fs)
58716+ if (atomic_read(&p->fs->users) > n_fs)
58717 bprm->unsafe |= LSM_UNSAFE_SHARE;
58718 else
58719 p->fs->in_exec = 1;
58720@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58721 return ret;
58722 }
58723
58724+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58725+static DEFINE_PER_CPU(u64, exec_counter);
58726+static int __init init_exec_counters(void)
58727+{
58728+ unsigned int cpu;
58729+
58730+ for_each_possible_cpu(cpu) {
58731+ per_cpu(exec_counter, cpu) = (u64)cpu;
58732+ }
58733+
58734+ return 0;
58735+}
58736+early_initcall(init_exec_counters);
58737+static inline void increment_exec_counter(void)
58738+{
58739+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58740+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58741+}
58742+#else
58743+static inline void increment_exec_counter(void) {}
58744+#endif
58745+
58746+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58747+ struct user_arg_ptr argv);
58748+
58749 /*
58750 * sys_execve() executes a new program.
58751 */
58752@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58753 struct user_arg_ptr argv,
58754 struct user_arg_ptr envp)
58755 {
58756+#ifdef CONFIG_GRKERNSEC
58757+ struct file *old_exec_file;
58758+ struct acl_subject_label *old_acl;
58759+ struct rlimit old_rlim[RLIM_NLIMITS];
58760+#endif
58761 struct linux_binprm *bprm;
58762 struct file *file;
58763 struct files_struct *displaced;
58764@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58765 if (IS_ERR(filename))
58766 return PTR_ERR(filename);
58767
58768+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58769+
58770 /*
58771 * We move the actual failure in case of RLIMIT_NPROC excess from
58772 * set*uid() to execve() because too many poorly written programs
58773@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58774 if (IS_ERR(file))
58775 goto out_unmark;
58776
58777+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58778+ retval = -EPERM;
58779+ goto out_unmark;
58780+ }
58781+
58782 sched_exec();
58783
58784 bprm->file = file;
58785 bprm->filename = bprm->interp = filename->name;
58786
58787+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58788+ retval = -EACCES;
58789+ goto out_unmark;
58790+ }
58791+
58792 retval = bprm_mm_init(bprm);
58793 if (retval)
58794 goto out_unmark;
58795@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58796 if (retval < 0)
58797 goto out;
58798
58799+#ifdef CONFIG_GRKERNSEC
58800+ old_acl = current->acl;
58801+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58802+ old_exec_file = current->exec_file;
58803+ get_file(file);
58804+ current->exec_file = file;
58805+#endif
58806+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58807+ /* limit suid stack to 8MB
58808+ * we saved the old limits above and will restore them if this exec fails
58809+ */
58810+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58811+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58812+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58813+#endif
58814+
58815+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58816+ retval = -EPERM;
58817+ goto out_fail;
58818+ }
58819+
58820+ if (!gr_tpe_allow(file)) {
58821+ retval = -EACCES;
58822+ goto out_fail;
58823+ }
58824+
58825+ if (gr_check_crash_exec(file)) {
58826+ retval = -EACCES;
58827+ goto out_fail;
58828+ }
58829+
58830+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58831+ bprm->unsafe);
58832+ if (retval < 0)
58833+ goto out_fail;
58834+
58835 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58836 if (retval < 0)
58837- goto out;
58838+ goto out_fail;
58839
58840 bprm->exec = bprm->p;
58841 retval = copy_strings(bprm->envc, envp, bprm);
58842 if (retval < 0)
58843- goto out;
58844+ goto out_fail;
58845
58846 retval = copy_strings(bprm->argc, argv, bprm);
58847 if (retval < 0)
58848- goto out;
58849+ goto out_fail;
58850+
58851+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58852+
58853+ gr_handle_exec_args(bprm, argv);
58854
58855 retval = exec_binprm(bprm);
58856 if (retval < 0)
58857- goto out;
58858+ goto out_fail;
58859+#ifdef CONFIG_GRKERNSEC
58860+ if (old_exec_file)
58861+ fput(old_exec_file);
58862+#endif
58863
58864 /* execve succeeded */
58865+
58866+ increment_exec_counter();
58867 current->fs->in_exec = 0;
58868 current->in_execve = 0;
58869 acct_update_integrals(current);
58870@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58871 put_files_struct(displaced);
58872 return retval;
58873
58874+out_fail:
58875+#ifdef CONFIG_GRKERNSEC
58876+ current->acl = old_acl;
58877+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58878+ fput(current->exec_file);
58879+ current->exec_file = old_exec_file;
58880+#endif
58881+
58882 out:
58883 if (bprm->mm) {
58884 acct_arg_size(bprm, 0);
58885@@ -1626,3 +1800,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58886 return compat_do_execve(getname(filename), argv, envp);
58887 }
58888 #endif
58889+
58890+int pax_check_flags(unsigned long *flags)
58891+{
58892+ int retval = 0;
58893+
58894+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58895+ if (*flags & MF_PAX_SEGMEXEC)
58896+ {
58897+ *flags &= ~MF_PAX_SEGMEXEC;
58898+ retval = -EINVAL;
58899+ }
58900+#endif
58901+
58902+ if ((*flags & MF_PAX_PAGEEXEC)
58903+
58904+#ifdef CONFIG_PAX_PAGEEXEC
58905+ && (*flags & MF_PAX_SEGMEXEC)
58906+#endif
58907+
58908+ )
58909+ {
58910+ *flags &= ~MF_PAX_PAGEEXEC;
58911+ retval = -EINVAL;
58912+ }
58913+
58914+ if ((*flags & MF_PAX_MPROTECT)
58915+
58916+#ifdef CONFIG_PAX_MPROTECT
58917+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58918+#endif
58919+
58920+ )
58921+ {
58922+ *flags &= ~MF_PAX_MPROTECT;
58923+ retval = -EINVAL;
58924+ }
58925+
58926+ if ((*flags & MF_PAX_EMUTRAMP)
58927+
58928+#ifdef CONFIG_PAX_EMUTRAMP
58929+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58930+#endif
58931+
58932+ )
58933+ {
58934+ *flags &= ~MF_PAX_EMUTRAMP;
58935+ retval = -EINVAL;
58936+ }
58937+
58938+ return retval;
58939+}
58940+
58941+EXPORT_SYMBOL(pax_check_flags);
58942+
58943+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58944+char *pax_get_path(const struct path *path, char *buf, int buflen)
58945+{
58946+ char *pathname = d_path(path, buf, buflen);
58947+
58948+ if (IS_ERR(pathname))
58949+ goto toolong;
58950+
58951+ pathname = mangle_path(buf, pathname, "\t\n\\");
58952+ if (!pathname)
58953+ goto toolong;
58954+
58955+ *pathname = 0;
58956+ return buf;
58957+
58958+toolong:
58959+ return "<path too long>";
58960+}
58961+EXPORT_SYMBOL(pax_get_path);
58962+
58963+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58964+{
58965+ struct task_struct *tsk = current;
58966+ struct mm_struct *mm = current->mm;
58967+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58968+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58969+ char *path_exec = NULL;
58970+ char *path_fault = NULL;
58971+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58972+ siginfo_t info = { };
58973+
58974+ if (buffer_exec && buffer_fault) {
58975+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58976+
58977+ down_read(&mm->mmap_sem);
58978+ vma = mm->mmap;
58979+ while (vma && (!vma_exec || !vma_fault)) {
58980+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58981+ vma_exec = vma;
58982+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58983+ vma_fault = vma;
58984+ vma = vma->vm_next;
58985+ }
58986+ if (vma_exec)
58987+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58988+ if (vma_fault) {
58989+ start = vma_fault->vm_start;
58990+ end = vma_fault->vm_end;
58991+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58992+ if (vma_fault->vm_file)
58993+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58994+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58995+ path_fault = "<heap>";
58996+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58997+ path_fault = "<stack>";
58998+ else
58999+ path_fault = "<anonymous mapping>";
59000+ }
59001+ up_read(&mm->mmap_sem);
59002+ }
59003+ if (tsk->signal->curr_ip)
59004+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59005+ else
59006+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59007+ 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),
59008+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59009+ free_page((unsigned long)buffer_exec);
59010+ free_page((unsigned long)buffer_fault);
59011+ pax_report_insns(regs, pc, sp);
59012+ info.si_signo = SIGKILL;
59013+ info.si_errno = 0;
59014+ info.si_code = SI_KERNEL;
59015+ info.si_pid = 0;
59016+ info.si_uid = 0;
59017+ do_coredump(&info);
59018+}
59019+#endif
59020+
59021+#ifdef CONFIG_PAX_REFCOUNT
59022+void pax_report_refcount_overflow(struct pt_regs *regs)
59023+{
59024+ if (current->signal->curr_ip)
59025+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59026+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59027+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59028+ else
59029+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59030+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59031+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59032+ preempt_disable();
59033+ show_regs(regs);
59034+ preempt_enable();
59035+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59036+}
59037+#endif
59038+
59039+#ifdef CONFIG_PAX_USERCOPY
59040+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59041+static noinline int check_stack_object(const void *obj, unsigned long len)
59042+{
59043+ const void * const stack = task_stack_page(current);
59044+ const void * const stackend = stack + THREAD_SIZE;
59045+
59046+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59047+ const void *frame = NULL;
59048+ const void *oldframe;
59049+#endif
59050+
59051+ if (obj + len < obj)
59052+ return -1;
59053+
59054+ if (obj + len <= stack || stackend <= obj)
59055+ return 0;
59056+
59057+ if (obj < stack || stackend < obj + len)
59058+ return -1;
59059+
59060+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59061+ oldframe = __builtin_frame_address(1);
59062+ if (oldframe)
59063+ frame = __builtin_frame_address(2);
59064+ /*
59065+ low ----------------------------------------------> high
59066+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59067+ ^----------------^
59068+ allow copies only within here
59069+ */
59070+ while (stack <= frame && frame < stackend) {
59071+ /* if obj + len extends past the last frame, this
59072+ check won't pass and the next frame will be 0,
59073+ causing us to bail out and correctly report
59074+ the copy as invalid
59075+ */
59076+ if (obj + len <= frame)
59077+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59078+ oldframe = frame;
59079+ frame = *(const void * const *)frame;
59080+ }
59081+ return -1;
59082+#else
59083+ return 1;
59084+#endif
59085+}
59086+
59087+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59088+{
59089+ if (current->signal->curr_ip)
59090+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59091+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59092+ else
59093+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59094+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59095+ dump_stack();
59096+ gr_handle_kernel_exploit();
59097+ do_group_exit(SIGKILL);
59098+}
59099+#endif
59100+
59101+#ifdef CONFIG_PAX_USERCOPY
59102+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59103+{
59104+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59105+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59106+#ifdef CONFIG_MODULES
59107+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59108+#else
59109+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59110+#endif
59111+
59112+#else
59113+ unsigned long textlow = (unsigned long)_stext;
59114+ unsigned long texthigh = (unsigned long)_etext;
59115+
59116+#ifdef CONFIG_X86_64
59117+ /* check against linear mapping as well */
59118+ if (high > (unsigned long)__va(__pa(textlow)) &&
59119+ low < (unsigned long)__va(__pa(texthigh)))
59120+ return true;
59121+#endif
59122+
59123+#endif
59124+
59125+ if (high <= textlow || low >= texthigh)
59126+ return false;
59127+ else
59128+ return true;
59129+}
59130+#endif
59131+
59132+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59133+{
59134+
59135+#ifdef CONFIG_PAX_USERCOPY
59136+ const char *type;
59137+
59138+ if (!n)
59139+ return;
59140+
59141+ type = check_heap_object(ptr, n);
59142+ if (!type) {
59143+ int ret = check_stack_object(ptr, n);
59144+ if (ret == 1 || ret == 2)
59145+ return;
59146+ if (ret == 0) {
59147+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59148+ type = "<kernel text>";
59149+ else
59150+ return;
59151+ } else
59152+ type = "<process stack>";
59153+ }
59154+
59155+ pax_report_usercopy(ptr, n, to_user, type);
59156+#endif
59157+
59158+}
59159+EXPORT_SYMBOL(__check_object_size);
59160+
59161+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59162+void pax_track_stack(void)
59163+{
59164+ unsigned long sp = (unsigned long)&sp;
59165+ if (sp < current_thread_info()->lowest_stack &&
59166+ sp > (unsigned long)task_stack_page(current))
59167+ current_thread_info()->lowest_stack = sp;
59168+}
59169+EXPORT_SYMBOL(pax_track_stack);
59170+#endif
59171+
59172+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59173+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59174+{
59175+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59176+ dump_stack();
59177+ do_group_exit(SIGKILL);
59178+}
59179+EXPORT_SYMBOL(report_size_overflow);
59180+#endif
59181diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59182index 9f9992b..8b59411 100644
59183--- a/fs/ext2/balloc.c
59184+++ b/fs/ext2/balloc.c
59185@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59186
59187 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59188 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59189- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59190+ if (free_blocks < root_blocks + 1 &&
59191 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59192 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59193- !in_group_p (sbi->s_resgid))) {
59194+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59195 return 0;
59196 }
59197 return 1;
59198diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59199index 9142614..97484fa 100644
59200--- a/fs/ext2/xattr.c
59201+++ b/fs/ext2/xattr.c
59202@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59203 struct buffer_head *bh = NULL;
59204 struct ext2_xattr_entry *entry;
59205 char *end;
59206- size_t rest = buffer_size;
59207+ size_t rest = buffer_size, total_size = 0;
59208 int error;
59209
59210 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59211@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59212 buffer += size;
59213 }
59214 rest -= size;
59215+ total_size += size;
59216 }
59217 }
59218- error = buffer_size - rest; /* total size */
59219+ error = total_size;
59220
59221 cleanup:
59222 brelse(bh);
59223diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59224index 22548f5..41521d8 100644
59225--- a/fs/ext3/balloc.c
59226+++ b/fs/ext3/balloc.c
59227@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59228
59229 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59230 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59231- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59232+ if (free_blocks < root_blocks + 1 &&
59233 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59234 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59235- !in_group_p (sbi->s_resgid))) {
59236+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59237 return 0;
59238 }
59239 return 1;
59240diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59241index c6874be..f8a6ae8 100644
59242--- a/fs/ext3/xattr.c
59243+++ b/fs/ext3/xattr.c
59244@@ -330,7 +330,7 @@ static int
59245 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59246 char *buffer, size_t buffer_size)
59247 {
59248- size_t rest = buffer_size;
59249+ size_t rest = buffer_size, total_size = 0;
59250
59251 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59252 const struct xattr_handler *handler =
59253@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59254 buffer += size;
59255 }
59256 rest -= size;
59257+ total_size += size;
59258 }
59259 }
59260- return buffer_size - rest;
59261+ return total_size;
59262 }
59263
59264 static int
59265diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59266index 6ea7b14..8fa16d9 100644
59267--- a/fs/ext4/balloc.c
59268+++ b/fs/ext4/balloc.c
59269@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59270 /* Hm, nope. Are (enough) root reserved clusters available? */
59271 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59272 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59273- capable(CAP_SYS_RESOURCE) ||
59274- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59275+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59276+ capable_nolog(CAP_SYS_RESOURCE)) {
59277
59278 if (free_clusters >= (nclusters + dirty_clusters +
59279 resv_clusters))
59280diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59281index 3a603a8..9b868ba 100644
59282--- a/fs/ext4/ext4.h
59283+++ b/fs/ext4/ext4.h
59284@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59285 unsigned long s_mb_last_start;
59286
59287 /* stats for buddy allocator */
59288- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59289- atomic_t s_bal_success; /* we found long enough chunks */
59290- atomic_t s_bal_allocated; /* in blocks */
59291- atomic_t s_bal_ex_scanned; /* total extents scanned */
59292- atomic_t s_bal_goals; /* goal hits */
59293- atomic_t s_bal_breaks; /* too long searches */
59294- atomic_t s_bal_2orders; /* 2^order hits */
59295+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59296+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59297+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59298+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59299+ atomic_unchecked_t s_bal_goals; /* goal hits */
59300+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59301+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59302 spinlock_t s_bal_lock;
59303 unsigned long s_mb_buddies_generated;
59304 unsigned long long s_mb_generation_time;
59305- atomic_t s_mb_lost_chunks;
59306- atomic_t s_mb_preallocated;
59307- atomic_t s_mb_discarded;
59308+ atomic_unchecked_t s_mb_lost_chunks;
59309+ atomic_unchecked_t s_mb_preallocated;
59310+ atomic_unchecked_t s_mb_discarded;
59311 atomic_t s_lock_busy;
59312
59313 /* locality groups */
59314diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59315index 04a5c75..09894fa 100644
59316--- a/fs/ext4/mballoc.c
59317+++ b/fs/ext4/mballoc.c
59318@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59319 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59320
59321 if (EXT4_SB(sb)->s_mb_stats)
59322- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59323+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59324
59325 break;
59326 }
59327@@ -2189,7 +2189,7 @@ repeat:
59328 ac->ac_status = AC_STATUS_CONTINUE;
59329 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59330 cr = 3;
59331- atomic_inc(&sbi->s_mb_lost_chunks);
59332+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59333 goto repeat;
59334 }
59335 }
59336@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59337 if (sbi->s_mb_stats) {
59338 ext4_msg(sb, KERN_INFO,
59339 "mballoc: %u blocks %u reqs (%u success)",
59340- atomic_read(&sbi->s_bal_allocated),
59341- atomic_read(&sbi->s_bal_reqs),
59342- atomic_read(&sbi->s_bal_success));
59343+ atomic_read_unchecked(&sbi->s_bal_allocated),
59344+ atomic_read_unchecked(&sbi->s_bal_reqs),
59345+ atomic_read_unchecked(&sbi->s_bal_success));
59346 ext4_msg(sb, KERN_INFO,
59347 "mballoc: %u extents scanned, %u goal hits, "
59348 "%u 2^N hits, %u breaks, %u lost",
59349- atomic_read(&sbi->s_bal_ex_scanned),
59350- atomic_read(&sbi->s_bal_goals),
59351- atomic_read(&sbi->s_bal_2orders),
59352- atomic_read(&sbi->s_bal_breaks),
59353- atomic_read(&sbi->s_mb_lost_chunks));
59354+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59355+ atomic_read_unchecked(&sbi->s_bal_goals),
59356+ atomic_read_unchecked(&sbi->s_bal_2orders),
59357+ atomic_read_unchecked(&sbi->s_bal_breaks),
59358+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59359 ext4_msg(sb, KERN_INFO,
59360 "mballoc: %lu generated and it took %Lu",
59361 sbi->s_mb_buddies_generated,
59362 sbi->s_mb_generation_time);
59363 ext4_msg(sb, KERN_INFO,
59364 "mballoc: %u preallocated, %u discarded",
59365- atomic_read(&sbi->s_mb_preallocated),
59366- atomic_read(&sbi->s_mb_discarded));
59367+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59368+ atomic_read_unchecked(&sbi->s_mb_discarded));
59369 }
59370
59371 free_percpu(sbi->s_locality_groups);
59372@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59373 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59374
59375 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59376- atomic_inc(&sbi->s_bal_reqs);
59377- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59378+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59379+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59380 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59381- atomic_inc(&sbi->s_bal_success);
59382- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59383+ atomic_inc_unchecked(&sbi->s_bal_success);
59384+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59385 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59386 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59387- atomic_inc(&sbi->s_bal_goals);
59388+ atomic_inc_unchecked(&sbi->s_bal_goals);
59389 if (ac->ac_found > sbi->s_mb_max_to_scan)
59390- atomic_inc(&sbi->s_bal_breaks);
59391+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59392 }
59393
59394 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59395@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59396 trace_ext4_mb_new_inode_pa(ac, pa);
59397
59398 ext4_mb_use_inode_pa(ac, pa);
59399- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59400+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59401
59402 ei = EXT4_I(ac->ac_inode);
59403 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59404@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59405 trace_ext4_mb_new_group_pa(ac, pa);
59406
59407 ext4_mb_use_group_pa(ac, pa);
59408- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59409+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59410
59411 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59412 lg = ac->ac_lg;
59413@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59414 * from the bitmap and continue.
59415 */
59416 }
59417- atomic_add(free, &sbi->s_mb_discarded);
59418+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59419
59420 return err;
59421 }
59422@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59423 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59424 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59425 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59426- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59427+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59428 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59429
59430 return 0;
59431diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59432index 04434ad..6404663 100644
59433--- a/fs/ext4/mmp.c
59434+++ b/fs/ext4/mmp.c
59435@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59436 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59437 const char *function, unsigned int line, const char *msg)
59438 {
59439- __ext4_warning(sb, function, line, msg);
59440+ __ext4_warning(sb, function, line, "%s", msg);
59441 __ext4_warning(sb, function, line,
59442 "MMP failure info: last update time: %llu, last update "
59443 "node: %s, last update device: %s\n",
59444diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59445index 710fed2..a82e4e8 100644
59446--- a/fs/ext4/super.c
59447+++ b/fs/ext4/super.c
59448@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59449 }
59450
59451 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59452-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59453+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59454 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59455
59456 #ifdef CONFIG_QUOTA
59457@@ -2450,7 +2450,7 @@ struct ext4_attr {
59458 int offset;
59459 int deprecated_val;
59460 } u;
59461-};
59462+} __do_const;
59463
59464 static int parse_strtoull(const char *buf,
59465 unsigned long long max, unsigned long long *value)
59466diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59467index 55e611c..cfad16d 100644
59468--- a/fs/ext4/xattr.c
59469+++ b/fs/ext4/xattr.c
59470@@ -381,7 +381,7 @@ static int
59471 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59472 char *buffer, size_t buffer_size)
59473 {
59474- size_t rest = buffer_size;
59475+ size_t rest = buffer_size, total_size = 0;
59476
59477 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59478 const struct xattr_handler *handler =
59479@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59480 buffer += size;
59481 }
59482 rest -= size;
59483+ total_size += size;
59484 }
59485 }
59486- return buffer_size - rest;
59487+ return total_size;
59488 }
59489
59490 static int
59491diff --git a/fs/fcntl.c b/fs/fcntl.c
59492index ef68665..5deacdc 100644
59493--- a/fs/fcntl.c
59494+++ b/fs/fcntl.c
59495@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59496 if (err)
59497 return err;
59498
59499+ if (gr_handle_chroot_fowner(pid, type))
59500+ return -ENOENT;
59501+ if (gr_check_protected_task_fowner(pid, type))
59502+ return -EACCES;
59503+
59504 f_modown(filp, pid, type, force);
59505 return 0;
59506 }
59507diff --git a/fs/fhandle.c b/fs/fhandle.c
59508index 999ff5c..41f4109 100644
59509--- a/fs/fhandle.c
59510+++ b/fs/fhandle.c
59511@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59512 } else
59513 retval = 0;
59514 /* copy the mount id */
59515- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59516- sizeof(*mnt_id)) ||
59517+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59518 copy_to_user(ufh, handle,
59519 sizeof(struct file_handle) + handle_bytes))
59520 retval = -EFAULT;
59521diff --git a/fs/file.c b/fs/file.c
59522index eb56a13..ccee850 100644
59523--- a/fs/file.c
59524+++ b/fs/file.c
59525@@ -16,6 +16,7 @@
59526 #include <linux/slab.h>
59527 #include <linux/vmalloc.h>
59528 #include <linux/file.h>
59529+#include <linux/security.h>
59530 #include <linux/fdtable.h>
59531 #include <linux/bitops.h>
59532 #include <linux/interrupt.h>
59533@@ -141,7 +142,7 @@ out:
59534 * Return <0 error code on error; 1 on successful completion.
59535 * The files->file_lock should be held on entry, and will be held on exit.
59536 */
59537-static int expand_fdtable(struct files_struct *files, int nr)
59538+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59539 __releases(files->file_lock)
59540 __acquires(files->file_lock)
59541 {
59542@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59543 * expanded and execution may have blocked.
59544 * The files->file_lock should be held on entry, and will be held on exit.
59545 */
59546-static int expand_files(struct files_struct *files, int nr)
59547+static int expand_files(struct files_struct *files, unsigned int nr)
59548 {
59549 struct fdtable *fdt;
59550
59551@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59552 if (!file)
59553 return __close_fd(files, fd);
59554
59555+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59556 if (fd >= rlimit(RLIMIT_NOFILE))
59557 return -EBADF;
59558
59559@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59560 if (unlikely(oldfd == newfd))
59561 return -EINVAL;
59562
59563+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59564 if (newfd >= rlimit(RLIMIT_NOFILE))
59565 return -EBADF;
59566
59567@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59568 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59569 {
59570 int err;
59571+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59572 if (from >= rlimit(RLIMIT_NOFILE))
59573 return -EINVAL;
59574 err = alloc_fd(from, flags);
59575diff --git a/fs/filesystems.c b/fs/filesystems.c
59576index 92567d9..fcd8cbf 100644
59577--- a/fs/filesystems.c
59578+++ b/fs/filesystems.c
59579@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59580 int len = dot ? dot - name : strlen(name);
59581
59582 fs = __get_fs_type(name, len);
59583+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59584+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59585+#else
59586 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59587+#endif
59588 fs = __get_fs_type(name, len);
59589
59590 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59591diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59592index 7dca743..543d620 100644
59593--- a/fs/fs_struct.c
59594+++ b/fs/fs_struct.c
59595@@ -4,6 +4,7 @@
59596 #include <linux/path.h>
59597 #include <linux/slab.h>
59598 #include <linux/fs_struct.h>
59599+#include <linux/grsecurity.h>
59600 #include "internal.h"
59601
59602 /*
59603@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59604 write_seqcount_begin(&fs->seq);
59605 old_root = fs->root;
59606 fs->root = *path;
59607+ gr_set_chroot_entries(current, path);
59608 write_seqcount_end(&fs->seq);
59609 spin_unlock(&fs->lock);
59610 if (old_root.dentry)
59611@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59612 int hits = 0;
59613 spin_lock(&fs->lock);
59614 write_seqcount_begin(&fs->seq);
59615+ /* this root replacement is only done by pivot_root,
59616+ leave grsec's chroot tagging alone for this task
59617+ so that a pivoted root isn't treated as a chroot
59618+ */
59619 hits += replace_path(&fs->root, old_root, new_root);
59620 hits += replace_path(&fs->pwd, old_root, new_root);
59621 write_seqcount_end(&fs->seq);
59622@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59623 task_lock(tsk);
59624 spin_lock(&fs->lock);
59625 tsk->fs = NULL;
59626- kill = !--fs->users;
59627+ gr_clear_chroot_entries(tsk);
59628+ kill = !atomic_dec_return(&fs->users);
59629 spin_unlock(&fs->lock);
59630 task_unlock(tsk);
59631 if (kill)
59632@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59633 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59634 /* We don't need to lock fs - think why ;-) */
59635 if (fs) {
59636- fs->users = 1;
59637+ atomic_set(&fs->users, 1);
59638 fs->in_exec = 0;
59639 spin_lock_init(&fs->lock);
59640 seqcount_init(&fs->seq);
59641@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59642 spin_lock(&old->lock);
59643 fs->root = old->root;
59644 path_get(&fs->root);
59645+ /* instead of calling gr_set_chroot_entries here,
59646+ we call it from every caller of this function
59647+ */
59648 fs->pwd = old->pwd;
59649 path_get(&fs->pwd);
59650 spin_unlock(&old->lock);
59651@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59652
59653 task_lock(current);
59654 spin_lock(&fs->lock);
59655- kill = !--fs->users;
59656+ kill = !atomic_dec_return(&fs->users);
59657 current->fs = new_fs;
59658+ gr_set_chroot_entries(current, &new_fs->root);
59659 spin_unlock(&fs->lock);
59660 task_unlock(current);
59661
59662@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59663
59664 int current_umask(void)
59665 {
59666- return current->fs->umask;
59667+ return current->fs->umask | gr_acl_umask();
59668 }
59669 EXPORT_SYMBOL(current_umask);
59670
59671 /* to be mentioned only in INIT_TASK */
59672 struct fs_struct init_fs = {
59673- .users = 1,
59674+ .users = ATOMIC_INIT(1),
59675 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59676 .seq = SEQCNT_ZERO(init_fs.seq),
59677 .umask = 0022,
59678diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59679index 29d7feb..303644d 100644
59680--- a/fs/fscache/cookie.c
59681+++ b/fs/fscache/cookie.c
59682@@ -19,7 +19,7 @@
59683
59684 struct kmem_cache *fscache_cookie_jar;
59685
59686-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59687+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59688
59689 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59690 static int fscache_alloc_object(struct fscache_cache *cache,
59691@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59692 parent ? (char *) parent->def->name : "<no-parent>",
59693 def->name, netfs_data, enable);
59694
59695- fscache_stat(&fscache_n_acquires);
59696+ fscache_stat_unchecked(&fscache_n_acquires);
59697
59698 /* if there's no parent cookie, then we don't create one here either */
59699 if (!parent) {
59700- fscache_stat(&fscache_n_acquires_null);
59701+ fscache_stat_unchecked(&fscache_n_acquires_null);
59702 _leave(" [no parent]");
59703 return NULL;
59704 }
59705@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59706 /* allocate and initialise a cookie */
59707 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59708 if (!cookie) {
59709- fscache_stat(&fscache_n_acquires_oom);
59710+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59711 _leave(" [ENOMEM]");
59712 return NULL;
59713 }
59714@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59715
59716 switch (cookie->def->type) {
59717 case FSCACHE_COOKIE_TYPE_INDEX:
59718- fscache_stat(&fscache_n_cookie_index);
59719+ fscache_stat_unchecked(&fscache_n_cookie_index);
59720 break;
59721 case FSCACHE_COOKIE_TYPE_DATAFILE:
59722- fscache_stat(&fscache_n_cookie_data);
59723+ fscache_stat_unchecked(&fscache_n_cookie_data);
59724 break;
59725 default:
59726- fscache_stat(&fscache_n_cookie_special);
59727+ fscache_stat_unchecked(&fscache_n_cookie_special);
59728 break;
59729 }
59730
59731@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59732 } else {
59733 atomic_dec(&parent->n_children);
59734 __fscache_cookie_put(cookie);
59735- fscache_stat(&fscache_n_acquires_nobufs);
59736+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59737 _leave(" = NULL");
59738 return NULL;
59739 }
59740@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59741 }
59742 }
59743
59744- fscache_stat(&fscache_n_acquires_ok);
59745+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59746 _leave(" = %p", cookie);
59747 return cookie;
59748 }
59749@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59750 cache = fscache_select_cache_for_object(cookie->parent);
59751 if (!cache) {
59752 up_read(&fscache_addremove_sem);
59753- fscache_stat(&fscache_n_acquires_no_cache);
59754+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59755 _leave(" = -ENOMEDIUM [no cache]");
59756 return -ENOMEDIUM;
59757 }
59758@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59759 object = cache->ops->alloc_object(cache, cookie);
59760 fscache_stat_d(&fscache_n_cop_alloc_object);
59761 if (IS_ERR(object)) {
59762- fscache_stat(&fscache_n_object_no_alloc);
59763+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59764 ret = PTR_ERR(object);
59765 goto error;
59766 }
59767
59768- fscache_stat(&fscache_n_object_alloc);
59769+ fscache_stat_unchecked(&fscache_n_object_alloc);
59770
59771- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59772+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59773
59774 _debug("ALLOC OBJ%x: %s {%lx}",
59775 object->debug_id, cookie->def->name, object->events);
59776@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59777
59778 _enter("{%s}", cookie->def->name);
59779
59780- fscache_stat(&fscache_n_invalidates);
59781+ fscache_stat_unchecked(&fscache_n_invalidates);
59782
59783 /* Only permit invalidation of data files. Invalidating an index will
59784 * require the caller to release all its attachments to the tree rooted
59785@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59786 {
59787 struct fscache_object *object;
59788
59789- fscache_stat(&fscache_n_updates);
59790+ fscache_stat_unchecked(&fscache_n_updates);
59791
59792 if (!cookie) {
59793- fscache_stat(&fscache_n_updates_null);
59794+ fscache_stat_unchecked(&fscache_n_updates_null);
59795 _leave(" [no cookie]");
59796 return;
59797 }
59798@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59799 */
59800 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59801 {
59802- fscache_stat(&fscache_n_relinquishes);
59803+ fscache_stat_unchecked(&fscache_n_relinquishes);
59804 if (retire)
59805- fscache_stat(&fscache_n_relinquishes_retire);
59806+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59807
59808 if (!cookie) {
59809- fscache_stat(&fscache_n_relinquishes_null);
59810+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59811 _leave(" [no cookie]");
59812 return;
59813 }
59814@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59815 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59816 goto inconsistent;
59817
59818- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59819+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59820
59821 __fscache_use_cookie(cookie);
59822 if (fscache_submit_op(object, op) < 0)
59823diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59824index 4226f66..0fb3f45 100644
59825--- a/fs/fscache/internal.h
59826+++ b/fs/fscache/internal.h
59827@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59828 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59829 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59830 struct fscache_operation *,
59831- atomic_t *,
59832- atomic_t *,
59833+ atomic_unchecked_t *,
59834+ atomic_unchecked_t *,
59835 void (*)(struct fscache_operation *));
59836 extern void fscache_invalidate_writes(struct fscache_cookie *);
59837
59838@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59839 * stats.c
59840 */
59841 #ifdef CONFIG_FSCACHE_STATS
59842-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59843-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59844+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59845+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59846
59847-extern atomic_t fscache_n_op_pend;
59848-extern atomic_t fscache_n_op_run;
59849-extern atomic_t fscache_n_op_enqueue;
59850-extern atomic_t fscache_n_op_deferred_release;
59851-extern atomic_t fscache_n_op_release;
59852-extern atomic_t fscache_n_op_gc;
59853-extern atomic_t fscache_n_op_cancelled;
59854-extern atomic_t fscache_n_op_rejected;
59855+extern atomic_unchecked_t fscache_n_op_pend;
59856+extern atomic_unchecked_t fscache_n_op_run;
59857+extern atomic_unchecked_t fscache_n_op_enqueue;
59858+extern atomic_unchecked_t fscache_n_op_deferred_release;
59859+extern atomic_unchecked_t fscache_n_op_release;
59860+extern atomic_unchecked_t fscache_n_op_gc;
59861+extern atomic_unchecked_t fscache_n_op_cancelled;
59862+extern atomic_unchecked_t fscache_n_op_rejected;
59863
59864-extern atomic_t fscache_n_attr_changed;
59865-extern atomic_t fscache_n_attr_changed_ok;
59866-extern atomic_t fscache_n_attr_changed_nobufs;
59867-extern atomic_t fscache_n_attr_changed_nomem;
59868-extern atomic_t fscache_n_attr_changed_calls;
59869+extern atomic_unchecked_t fscache_n_attr_changed;
59870+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59871+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59872+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59873+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59874
59875-extern atomic_t fscache_n_allocs;
59876-extern atomic_t fscache_n_allocs_ok;
59877-extern atomic_t fscache_n_allocs_wait;
59878-extern atomic_t fscache_n_allocs_nobufs;
59879-extern atomic_t fscache_n_allocs_intr;
59880-extern atomic_t fscache_n_allocs_object_dead;
59881-extern atomic_t fscache_n_alloc_ops;
59882-extern atomic_t fscache_n_alloc_op_waits;
59883+extern atomic_unchecked_t fscache_n_allocs;
59884+extern atomic_unchecked_t fscache_n_allocs_ok;
59885+extern atomic_unchecked_t fscache_n_allocs_wait;
59886+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59887+extern atomic_unchecked_t fscache_n_allocs_intr;
59888+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59889+extern atomic_unchecked_t fscache_n_alloc_ops;
59890+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59891
59892-extern atomic_t fscache_n_retrievals;
59893-extern atomic_t fscache_n_retrievals_ok;
59894-extern atomic_t fscache_n_retrievals_wait;
59895-extern atomic_t fscache_n_retrievals_nodata;
59896-extern atomic_t fscache_n_retrievals_nobufs;
59897-extern atomic_t fscache_n_retrievals_intr;
59898-extern atomic_t fscache_n_retrievals_nomem;
59899-extern atomic_t fscache_n_retrievals_object_dead;
59900-extern atomic_t fscache_n_retrieval_ops;
59901-extern atomic_t fscache_n_retrieval_op_waits;
59902+extern atomic_unchecked_t fscache_n_retrievals;
59903+extern atomic_unchecked_t fscache_n_retrievals_ok;
59904+extern atomic_unchecked_t fscache_n_retrievals_wait;
59905+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59906+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59907+extern atomic_unchecked_t fscache_n_retrievals_intr;
59908+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59909+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59910+extern atomic_unchecked_t fscache_n_retrieval_ops;
59911+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59912
59913-extern atomic_t fscache_n_stores;
59914-extern atomic_t fscache_n_stores_ok;
59915-extern atomic_t fscache_n_stores_again;
59916-extern atomic_t fscache_n_stores_nobufs;
59917-extern atomic_t fscache_n_stores_oom;
59918-extern atomic_t fscache_n_store_ops;
59919-extern atomic_t fscache_n_store_calls;
59920-extern atomic_t fscache_n_store_pages;
59921-extern atomic_t fscache_n_store_radix_deletes;
59922-extern atomic_t fscache_n_store_pages_over_limit;
59923+extern atomic_unchecked_t fscache_n_stores;
59924+extern atomic_unchecked_t fscache_n_stores_ok;
59925+extern atomic_unchecked_t fscache_n_stores_again;
59926+extern atomic_unchecked_t fscache_n_stores_nobufs;
59927+extern atomic_unchecked_t fscache_n_stores_oom;
59928+extern atomic_unchecked_t fscache_n_store_ops;
59929+extern atomic_unchecked_t fscache_n_store_calls;
59930+extern atomic_unchecked_t fscache_n_store_pages;
59931+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59932+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59933
59934-extern atomic_t fscache_n_store_vmscan_not_storing;
59935-extern atomic_t fscache_n_store_vmscan_gone;
59936-extern atomic_t fscache_n_store_vmscan_busy;
59937-extern atomic_t fscache_n_store_vmscan_cancelled;
59938-extern atomic_t fscache_n_store_vmscan_wait;
59939+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59940+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59941+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59942+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59943+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59944
59945-extern atomic_t fscache_n_marks;
59946-extern atomic_t fscache_n_uncaches;
59947+extern atomic_unchecked_t fscache_n_marks;
59948+extern atomic_unchecked_t fscache_n_uncaches;
59949
59950-extern atomic_t fscache_n_acquires;
59951-extern atomic_t fscache_n_acquires_null;
59952-extern atomic_t fscache_n_acquires_no_cache;
59953-extern atomic_t fscache_n_acquires_ok;
59954-extern atomic_t fscache_n_acquires_nobufs;
59955-extern atomic_t fscache_n_acquires_oom;
59956+extern atomic_unchecked_t fscache_n_acquires;
59957+extern atomic_unchecked_t fscache_n_acquires_null;
59958+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59959+extern atomic_unchecked_t fscache_n_acquires_ok;
59960+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59961+extern atomic_unchecked_t fscache_n_acquires_oom;
59962
59963-extern atomic_t fscache_n_invalidates;
59964-extern atomic_t fscache_n_invalidates_run;
59965+extern atomic_unchecked_t fscache_n_invalidates;
59966+extern atomic_unchecked_t fscache_n_invalidates_run;
59967
59968-extern atomic_t fscache_n_updates;
59969-extern atomic_t fscache_n_updates_null;
59970-extern atomic_t fscache_n_updates_run;
59971+extern atomic_unchecked_t fscache_n_updates;
59972+extern atomic_unchecked_t fscache_n_updates_null;
59973+extern atomic_unchecked_t fscache_n_updates_run;
59974
59975-extern atomic_t fscache_n_relinquishes;
59976-extern atomic_t fscache_n_relinquishes_null;
59977-extern atomic_t fscache_n_relinquishes_waitcrt;
59978-extern atomic_t fscache_n_relinquishes_retire;
59979+extern atomic_unchecked_t fscache_n_relinquishes;
59980+extern atomic_unchecked_t fscache_n_relinquishes_null;
59981+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59982+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59983
59984-extern atomic_t fscache_n_cookie_index;
59985-extern atomic_t fscache_n_cookie_data;
59986-extern atomic_t fscache_n_cookie_special;
59987+extern atomic_unchecked_t fscache_n_cookie_index;
59988+extern atomic_unchecked_t fscache_n_cookie_data;
59989+extern atomic_unchecked_t fscache_n_cookie_special;
59990
59991-extern atomic_t fscache_n_object_alloc;
59992-extern atomic_t fscache_n_object_no_alloc;
59993-extern atomic_t fscache_n_object_lookups;
59994-extern atomic_t fscache_n_object_lookups_negative;
59995-extern atomic_t fscache_n_object_lookups_positive;
59996-extern atomic_t fscache_n_object_lookups_timed_out;
59997-extern atomic_t fscache_n_object_created;
59998-extern atomic_t fscache_n_object_avail;
59999-extern atomic_t fscache_n_object_dead;
60000+extern atomic_unchecked_t fscache_n_object_alloc;
60001+extern atomic_unchecked_t fscache_n_object_no_alloc;
60002+extern atomic_unchecked_t fscache_n_object_lookups;
60003+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60004+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60005+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60006+extern atomic_unchecked_t fscache_n_object_created;
60007+extern atomic_unchecked_t fscache_n_object_avail;
60008+extern atomic_unchecked_t fscache_n_object_dead;
60009
60010-extern atomic_t fscache_n_checkaux_none;
60011-extern atomic_t fscache_n_checkaux_okay;
60012-extern atomic_t fscache_n_checkaux_update;
60013-extern atomic_t fscache_n_checkaux_obsolete;
60014+extern atomic_unchecked_t fscache_n_checkaux_none;
60015+extern atomic_unchecked_t fscache_n_checkaux_okay;
60016+extern atomic_unchecked_t fscache_n_checkaux_update;
60017+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60018
60019 extern atomic_t fscache_n_cop_alloc_object;
60020 extern atomic_t fscache_n_cop_lookup_object;
60021@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60022 atomic_inc(stat);
60023 }
60024
60025+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60026+{
60027+ atomic_inc_unchecked(stat);
60028+}
60029+
60030 static inline void fscache_stat_d(atomic_t *stat)
60031 {
60032 atomic_dec(stat);
60033@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60034
60035 #define __fscache_stat(stat) (NULL)
60036 #define fscache_stat(stat) do {} while (0)
60037+#define fscache_stat_unchecked(stat) do {} while (0)
60038 #define fscache_stat_d(stat) do {} while (0)
60039 #endif
60040
60041diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60042index d3b4539..ed0c659 100644
60043--- a/fs/fscache/object.c
60044+++ b/fs/fscache/object.c
60045@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60046 _debug("LOOKUP \"%s\" in \"%s\"",
60047 cookie->def->name, object->cache->tag->name);
60048
60049- fscache_stat(&fscache_n_object_lookups);
60050+ fscache_stat_unchecked(&fscache_n_object_lookups);
60051 fscache_stat(&fscache_n_cop_lookup_object);
60052 ret = object->cache->ops->lookup_object(object);
60053 fscache_stat_d(&fscache_n_cop_lookup_object);
60054@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60055 if (ret == -ETIMEDOUT) {
60056 /* probably stuck behind another object, so move this one to
60057 * the back of the queue */
60058- fscache_stat(&fscache_n_object_lookups_timed_out);
60059+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60060 _leave(" [timeout]");
60061 return NO_TRANSIT;
60062 }
60063@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60064 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60065
60066 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60067- fscache_stat(&fscache_n_object_lookups_negative);
60068+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60069
60070 /* Allow write requests to begin stacking up and read requests to begin
60071 * returning ENODATA.
60072@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60073 /* if we were still looking up, then we must have a positive lookup
60074 * result, in which case there may be data available */
60075 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60076- fscache_stat(&fscache_n_object_lookups_positive);
60077+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60078
60079 /* We do (presumably) have data */
60080 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60081@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60082 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60083 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60084 } else {
60085- fscache_stat(&fscache_n_object_created);
60086+ fscache_stat_unchecked(&fscache_n_object_created);
60087 }
60088
60089 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60090@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60091 fscache_stat_d(&fscache_n_cop_lookup_complete);
60092
60093 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60094- fscache_stat(&fscache_n_object_avail);
60095+ fscache_stat_unchecked(&fscache_n_object_avail);
60096
60097 _leave("");
60098 return transit_to(JUMPSTART_DEPS);
60099@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60100
60101 /* this just shifts the object release to the work processor */
60102 fscache_put_object(object);
60103- fscache_stat(&fscache_n_object_dead);
60104+ fscache_stat_unchecked(&fscache_n_object_dead);
60105
60106 _leave("");
60107 return transit_to(OBJECT_DEAD);
60108@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60109 enum fscache_checkaux result;
60110
60111 if (!object->cookie->def->check_aux) {
60112- fscache_stat(&fscache_n_checkaux_none);
60113+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60114 return FSCACHE_CHECKAUX_OKAY;
60115 }
60116
60117@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60118 switch (result) {
60119 /* entry okay as is */
60120 case FSCACHE_CHECKAUX_OKAY:
60121- fscache_stat(&fscache_n_checkaux_okay);
60122+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60123 break;
60124
60125 /* entry requires update */
60126 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60127- fscache_stat(&fscache_n_checkaux_update);
60128+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60129 break;
60130
60131 /* entry requires deletion */
60132 case FSCACHE_CHECKAUX_OBSOLETE:
60133- fscache_stat(&fscache_n_checkaux_obsolete);
60134+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60135 break;
60136
60137 default:
60138@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60139 {
60140 const struct fscache_state *s;
60141
60142- fscache_stat(&fscache_n_invalidates_run);
60143+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60144 fscache_stat(&fscache_n_cop_invalidate_object);
60145 s = _fscache_invalidate_object(object, event);
60146 fscache_stat_d(&fscache_n_cop_invalidate_object);
60147@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60148 {
60149 _enter("{OBJ%x},%d", object->debug_id, event);
60150
60151- fscache_stat(&fscache_n_updates_run);
60152+ fscache_stat_unchecked(&fscache_n_updates_run);
60153 fscache_stat(&fscache_n_cop_update_object);
60154 object->cache->ops->update_object(object);
60155 fscache_stat_d(&fscache_n_cop_update_object);
60156diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60157index 318071a..379938b 100644
60158--- a/fs/fscache/operation.c
60159+++ b/fs/fscache/operation.c
60160@@ -17,7 +17,7 @@
60161 #include <linux/slab.h>
60162 #include "internal.h"
60163
60164-atomic_t fscache_op_debug_id;
60165+atomic_unchecked_t fscache_op_debug_id;
60166 EXPORT_SYMBOL(fscache_op_debug_id);
60167
60168 /**
60169@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60170 ASSERTCMP(atomic_read(&op->usage), >, 0);
60171 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60172
60173- fscache_stat(&fscache_n_op_enqueue);
60174+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60175 switch (op->flags & FSCACHE_OP_TYPE) {
60176 case FSCACHE_OP_ASYNC:
60177 _debug("queue async");
60178@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60179 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60180 if (op->processor)
60181 fscache_enqueue_operation(op);
60182- fscache_stat(&fscache_n_op_run);
60183+ fscache_stat_unchecked(&fscache_n_op_run);
60184 }
60185
60186 /*
60187@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60188 if (object->n_in_progress > 0) {
60189 atomic_inc(&op->usage);
60190 list_add_tail(&op->pend_link, &object->pending_ops);
60191- fscache_stat(&fscache_n_op_pend);
60192+ fscache_stat_unchecked(&fscache_n_op_pend);
60193 } else if (!list_empty(&object->pending_ops)) {
60194 atomic_inc(&op->usage);
60195 list_add_tail(&op->pend_link, &object->pending_ops);
60196- fscache_stat(&fscache_n_op_pend);
60197+ fscache_stat_unchecked(&fscache_n_op_pend);
60198 fscache_start_operations(object);
60199 } else {
60200 ASSERTCMP(object->n_in_progress, ==, 0);
60201@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60202 object->n_exclusive++; /* reads and writes must wait */
60203 atomic_inc(&op->usage);
60204 list_add_tail(&op->pend_link, &object->pending_ops);
60205- fscache_stat(&fscache_n_op_pend);
60206+ fscache_stat_unchecked(&fscache_n_op_pend);
60207 ret = 0;
60208 } else {
60209 /* If we're in any other state, there must have been an I/O
60210@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60211 if (object->n_exclusive > 0) {
60212 atomic_inc(&op->usage);
60213 list_add_tail(&op->pend_link, &object->pending_ops);
60214- fscache_stat(&fscache_n_op_pend);
60215+ fscache_stat_unchecked(&fscache_n_op_pend);
60216 } else if (!list_empty(&object->pending_ops)) {
60217 atomic_inc(&op->usage);
60218 list_add_tail(&op->pend_link, &object->pending_ops);
60219- fscache_stat(&fscache_n_op_pend);
60220+ fscache_stat_unchecked(&fscache_n_op_pend);
60221 fscache_start_operations(object);
60222 } else {
60223 ASSERTCMP(object->n_exclusive, ==, 0);
60224@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60225 object->n_ops++;
60226 atomic_inc(&op->usage);
60227 list_add_tail(&op->pend_link, &object->pending_ops);
60228- fscache_stat(&fscache_n_op_pend);
60229+ fscache_stat_unchecked(&fscache_n_op_pend);
60230 ret = 0;
60231 } else if (fscache_object_is_dying(object)) {
60232- fscache_stat(&fscache_n_op_rejected);
60233+ fscache_stat_unchecked(&fscache_n_op_rejected);
60234 op->state = FSCACHE_OP_ST_CANCELLED;
60235 ret = -ENOBUFS;
60236 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60237@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60238 ret = -EBUSY;
60239 if (op->state == FSCACHE_OP_ST_PENDING) {
60240 ASSERT(!list_empty(&op->pend_link));
60241- fscache_stat(&fscache_n_op_cancelled);
60242+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60243 list_del_init(&op->pend_link);
60244 if (do_cancel)
60245 do_cancel(op);
60246@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60247 while (!list_empty(&object->pending_ops)) {
60248 op = list_entry(object->pending_ops.next,
60249 struct fscache_operation, pend_link);
60250- fscache_stat(&fscache_n_op_cancelled);
60251+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60252 list_del_init(&op->pend_link);
60253
60254 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60255@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60256 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60257 op->state = FSCACHE_OP_ST_DEAD;
60258
60259- fscache_stat(&fscache_n_op_release);
60260+ fscache_stat_unchecked(&fscache_n_op_release);
60261
60262 if (op->release) {
60263 op->release(op);
60264@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60265 * lock, and defer it otherwise */
60266 if (!spin_trylock(&object->lock)) {
60267 _debug("defer put");
60268- fscache_stat(&fscache_n_op_deferred_release);
60269+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60270
60271 cache = object->cache;
60272 spin_lock(&cache->op_gc_list_lock);
60273@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60274
60275 _debug("GC DEFERRED REL OBJ%x OP%x",
60276 object->debug_id, op->debug_id);
60277- fscache_stat(&fscache_n_op_gc);
60278+ fscache_stat_unchecked(&fscache_n_op_gc);
60279
60280 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60281 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60282diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60283index 7f5c658..6c1e164 100644
60284--- a/fs/fscache/page.c
60285+++ b/fs/fscache/page.c
60286@@ -61,7 +61,7 @@ try_again:
60287 val = radix_tree_lookup(&cookie->stores, page->index);
60288 if (!val) {
60289 rcu_read_unlock();
60290- fscache_stat(&fscache_n_store_vmscan_not_storing);
60291+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60292 __fscache_uncache_page(cookie, page);
60293 return true;
60294 }
60295@@ -91,11 +91,11 @@ try_again:
60296 spin_unlock(&cookie->stores_lock);
60297
60298 if (xpage) {
60299- fscache_stat(&fscache_n_store_vmscan_cancelled);
60300- fscache_stat(&fscache_n_store_radix_deletes);
60301+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60302+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60303 ASSERTCMP(xpage, ==, page);
60304 } else {
60305- fscache_stat(&fscache_n_store_vmscan_gone);
60306+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60307 }
60308
60309 wake_up_bit(&cookie->flags, 0);
60310@@ -110,11 +110,11 @@ page_busy:
60311 * sleeping on memory allocation, so we may need to impose a timeout
60312 * too. */
60313 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60314- fscache_stat(&fscache_n_store_vmscan_busy);
60315+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60316 return false;
60317 }
60318
60319- fscache_stat(&fscache_n_store_vmscan_wait);
60320+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60321 __fscache_wait_on_page_write(cookie, page);
60322 gfp &= ~__GFP_WAIT;
60323 goto try_again;
60324@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60325 FSCACHE_COOKIE_STORING_TAG);
60326 if (!radix_tree_tag_get(&cookie->stores, page->index,
60327 FSCACHE_COOKIE_PENDING_TAG)) {
60328- fscache_stat(&fscache_n_store_radix_deletes);
60329+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60330 xpage = radix_tree_delete(&cookie->stores, page->index);
60331 }
60332 spin_unlock(&cookie->stores_lock);
60333@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60334
60335 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60336
60337- fscache_stat(&fscache_n_attr_changed_calls);
60338+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60339
60340 if (fscache_object_is_active(object)) {
60341 fscache_stat(&fscache_n_cop_attr_changed);
60342@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60343
60344 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60345
60346- fscache_stat(&fscache_n_attr_changed);
60347+ fscache_stat_unchecked(&fscache_n_attr_changed);
60348
60349 op = kzalloc(sizeof(*op), GFP_KERNEL);
60350 if (!op) {
60351- fscache_stat(&fscache_n_attr_changed_nomem);
60352+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60353 _leave(" = -ENOMEM");
60354 return -ENOMEM;
60355 }
60356@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60357 if (fscache_submit_exclusive_op(object, op) < 0)
60358 goto nobufs;
60359 spin_unlock(&cookie->lock);
60360- fscache_stat(&fscache_n_attr_changed_ok);
60361+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60362 fscache_put_operation(op);
60363 _leave(" = 0");
60364 return 0;
60365@@ -225,7 +225,7 @@ nobufs:
60366 kfree(op);
60367 if (wake_cookie)
60368 __fscache_wake_unused_cookie(cookie);
60369- fscache_stat(&fscache_n_attr_changed_nobufs);
60370+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60371 _leave(" = %d", -ENOBUFS);
60372 return -ENOBUFS;
60373 }
60374@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60375 /* allocate a retrieval operation and attempt to submit it */
60376 op = kzalloc(sizeof(*op), GFP_NOIO);
60377 if (!op) {
60378- fscache_stat(&fscache_n_retrievals_nomem);
60379+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60380 return NULL;
60381 }
60382
60383@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60384 return 0;
60385 }
60386
60387- fscache_stat(&fscache_n_retrievals_wait);
60388+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60389
60390 jif = jiffies;
60391 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60392 fscache_wait_bit_interruptible,
60393 TASK_INTERRUPTIBLE) != 0) {
60394- fscache_stat(&fscache_n_retrievals_intr);
60395+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60396 _leave(" = -ERESTARTSYS");
60397 return -ERESTARTSYS;
60398 }
60399@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60400 */
60401 int fscache_wait_for_operation_activation(struct fscache_object *object,
60402 struct fscache_operation *op,
60403- atomic_t *stat_op_waits,
60404- atomic_t *stat_object_dead,
60405+ atomic_unchecked_t *stat_op_waits,
60406+ atomic_unchecked_t *stat_object_dead,
60407 void (*do_cancel)(struct fscache_operation *))
60408 {
60409 int ret;
60410@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60411
60412 _debug(">>> WT");
60413 if (stat_op_waits)
60414- fscache_stat(stat_op_waits);
60415+ fscache_stat_unchecked(stat_op_waits);
60416 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60417 fscache_wait_bit_interruptible,
60418 TASK_INTERRUPTIBLE) != 0) {
60419@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60420 check_if_dead:
60421 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60422 if (stat_object_dead)
60423- fscache_stat(stat_object_dead);
60424+ fscache_stat_unchecked(stat_object_dead);
60425 _leave(" = -ENOBUFS [cancelled]");
60426 return -ENOBUFS;
60427 }
60428@@ -366,7 +366,7 @@ check_if_dead:
60429 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60430 fscache_cancel_op(op, do_cancel);
60431 if (stat_object_dead)
60432- fscache_stat(stat_object_dead);
60433+ fscache_stat_unchecked(stat_object_dead);
60434 return -ENOBUFS;
60435 }
60436 return 0;
60437@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60438
60439 _enter("%p,%p,,,", cookie, page);
60440
60441- fscache_stat(&fscache_n_retrievals);
60442+ fscache_stat_unchecked(&fscache_n_retrievals);
60443
60444 if (hlist_empty(&cookie->backing_objects))
60445 goto nobufs;
60446@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60447 goto nobufs_unlock_dec;
60448 spin_unlock(&cookie->lock);
60449
60450- fscache_stat(&fscache_n_retrieval_ops);
60451+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60452
60453 /* pin the netfs read context in case we need to do the actual netfs
60454 * read because we've encountered a cache read failure */
60455@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60456
60457 error:
60458 if (ret == -ENOMEM)
60459- fscache_stat(&fscache_n_retrievals_nomem);
60460+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60461 else if (ret == -ERESTARTSYS)
60462- fscache_stat(&fscache_n_retrievals_intr);
60463+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60464 else if (ret == -ENODATA)
60465- fscache_stat(&fscache_n_retrievals_nodata);
60466+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60467 else if (ret < 0)
60468- fscache_stat(&fscache_n_retrievals_nobufs);
60469+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60470 else
60471- fscache_stat(&fscache_n_retrievals_ok);
60472+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60473
60474 fscache_put_retrieval(op);
60475 _leave(" = %d", ret);
60476@@ -490,7 +490,7 @@ nobufs_unlock:
60477 __fscache_wake_unused_cookie(cookie);
60478 kfree(op);
60479 nobufs:
60480- fscache_stat(&fscache_n_retrievals_nobufs);
60481+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60482 _leave(" = -ENOBUFS");
60483 return -ENOBUFS;
60484 }
60485@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60486
60487 _enter("%p,,%d,,,", cookie, *nr_pages);
60488
60489- fscache_stat(&fscache_n_retrievals);
60490+ fscache_stat_unchecked(&fscache_n_retrievals);
60491
60492 if (hlist_empty(&cookie->backing_objects))
60493 goto nobufs;
60494@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60495 goto nobufs_unlock_dec;
60496 spin_unlock(&cookie->lock);
60497
60498- fscache_stat(&fscache_n_retrieval_ops);
60499+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60500
60501 /* pin the netfs read context in case we need to do the actual netfs
60502 * read because we've encountered a cache read failure */
60503@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60504
60505 error:
60506 if (ret == -ENOMEM)
60507- fscache_stat(&fscache_n_retrievals_nomem);
60508+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60509 else if (ret == -ERESTARTSYS)
60510- fscache_stat(&fscache_n_retrievals_intr);
60511+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60512 else if (ret == -ENODATA)
60513- fscache_stat(&fscache_n_retrievals_nodata);
60514+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60515 else if (ret < 0)
60516- fscache_stat(&fscache_n_retrievals_nobufs);
60517+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60518 else
60519- fscache_stat(&fscache_n_retrievals_ok);
60520+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60521
60522 fscache_put_retrieval(op);
60523 _leave(" = %d", ret);
60524@@ -621,7 +621,7 @@ nobufs_unlock:
60525 if (wake_cookie)
60526 __fscache_wake_unused_cookie(cookie);
60527 nobufs:
60528- fscache_stat(&fscache_n_retrievals_nobufs);
60529+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60530 _leave(" = -ENOBUFS");
60531 return -ENOBUFS;
60532 }
60533@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60534
60535 _enter("%p,%p,,,", cookie, page);
60536
60537- fscache_stat(&fscache_n_allocs);
60538+ fscache_stat_unchecked(&fscache_n_allocs);
60539
60540 if (hlist_empty(&cookie->backing_objects))
60541 goto nobufs;
60542@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60543 goto nobufs_unlock_dec;
60544 spin_unlock(&cookie->lock);
60545
60546- fscache_stat(&fscache_n_alloc_ops);
60547+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60548
60549 ret = fscache_wait_for_operation_activation(
60550 object, &op->op,
60551@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60552
60553 error:
60554 if (ret == -ERESTARTSYS)
60555- fscache_stat(&fscache_n_allocs_intr);
60556+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60557 else if (ret < 0)
60558- fscache_stat(&fscache_n_allocs_nobufs);
60559+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60560 else
60561- fscache_stat(&fscache_n_allocs_ok);
60562+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60563
60564 fscache_put_retrieval(op);
60565 _leave(" = %d", ret);
60566@@ -715,7 +715,7 @@ nobufs_unlock:
60567 if (wake_cookie)
60568 __fscache_wake_unused_cookie(cookie);
60569 nobufs:
60570- fscache_stat(&fscache_n_allocs_nobufs);
60571+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60572 _leave(" = -ENOBUFS");
60573 return -ENOBUFS;
60574 }
60575@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60576
60577 spin_lock(&cookie->stores_lock);
60578
60579- fscache_stat(&fscache_n_store_calls);
60580+ fscache_stat_unchecked(&fscache_n_store_calls);
60581
60582 /* find a page to store */
60583 page = NULL;
60584@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60585 page = results[0];
60586 _debug("gang %d [%lx]", n, page->index);
60587 if (page->index > op->store_limit) {
60588- fscache_stat(&fscache_n_store_pages_over_limit);
60589+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60590 goto superseded;
60591 }
60592
60593@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60594 spin_unlock(&cookie->stores_lock);
60595 spin_unlock(&object->lock);
60596
60597- fscache_stat(&fscache_n_store_pages);
60598+ fscache_stat_unchecked(&fscache_n_store_pages);
60599 fscache_stat(&fscache_n_cop_write_page);
60600 ret = object->cache->ops->write_page(op, page);
60601 fscache_stat_d(&fscache_n_cop_write_page);
60602@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60603 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60604 ASSERT(PageFsCache(page));
60605
60606- fscache_stat(&fscache_n_stores);
60607+ fscache_stat_unchecked(&fscache_n_stores);
60608
60609 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60610 _leave(" = -ENOBUFS [invalidating]");
60611@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60612 spin_unlock(&cookie->stores_lock);
60613 spin_unlock(&object->lock);
60614
60615- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60616+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60617 op->store_limit = object->store_limit;
60618
60619 __fscache_use_cookie(cookie);
60620@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60621
60622 spin_unlock(&cookie->lock);
60623 radix_tree_preload_end();
60624- fscache_stat(&fscache_n_store_ops);
60625- fscache_stat(&fscache_n_stores_ok);
60626+ fscache_stat_unchecked(&fscache_n_store_ops);
60627+ fscache_stat_unchecked(&fscache_n_stores_ok);
60628
60629 /* the work queue now carries its own ref on the object */
60630 fscache_put_operation(&op->op);
60631@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60632 return 0;
60633
60634 already_queued:
60635- fscache_stat(&fscache_n_stores_again);
60636+ fscache_stat_unchecked(&fscache_n_stores_again);
60637 already_pending:
60638 spin_unlock(&cookie->stores_lock);
60639 spin_unlock(&object->lock);
60640 spin_unlock(&cookie->lock);
60641 radix_tree_preload_end();
60642 kfree(op);
60643- fscache_stat(&fscache_n_stores_ok);
60644+ fscache_stat_unchecked(&fscache_n_stores_ok);
60645 _leave(" = 0");
60646 return 0;
60647
60648@@ -1024,14 +1024,14 @@ nobufs:
60649 kfree(op);
60650 if (wake_cookie)
60651 __fscache_wake_unused_cookie(cookie);
60652- fscache_stat(&fscache_n_stores_nobufs);
60653+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60654 _leave(" = -ENOBUFS");
60655 return -ENOBUFS;
60656
60657 nomem_free:
60658 kfree(op);
60659 nomem:
60660- fscache_stat(&fscache_n_stores_oom);
60661+ fscache_stat_unchecked(&fscache_n_stores_oom);
60662 _leave(" = -ENOMEM");
60663 return -ENOMEM;
60664 }
60665@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60666 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60667 ASSERTCMP(page, !=, NULL);
60668
60669- fscache_stat(&fscache_n_uncaches);
60670+ fscache_stat_unchecked(&fscache_n_uncaches);
60671
60672 /* cache withdrawal may beat us to it */
60673 if (!PageFsCache(page))
60674@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60675 struct fscache_cookie *cookie = op->op.object->cookie;
60676
60677 #ifdef CONFIG_FSCACHE_STATS
60678- atomic_inc(&fscache_n_marks);
60679+ atomic_inc_unchecked(&fscache_n_marks);
60680 #endif
60681
60682 _debug("- mark %p{%lx}", page, page->index);
60683diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60684index 40d13c7..ddf52b9 100644
60685--- a/fs/fscache/stats.c
60686+++ b/fs/fscache/stats.c
60687@@ -18,99 +18,99 @@
60688 /*
60689 * operation counters
60690 */
60691-atomic_t fscache_n_op_pend;
60692-atomic_t fscache_n_op_run;
60693-atomic_t fscache_n_op_enqueue;
60694-atomic_t fscache_n_op_requeue;
60695-atomic_t fscache_n_op_deferred_release;
60696-atomic_t fscache_n_op_release;
60697-atomic_t fscache_n_op_gc;
60698-atomic_t fscache_n_op_cancelled;
60699-atomic_t fscache_n_op_rejected;
60700+atomic_unchecked_t fscache_n_op_pend;
60701+atomic_unchecked_t fscache_n_op_run;
60702+atomic_unchecked_t fscache_n_op_enqueue;
60703+atomic_unchecked_t fscache_n_op_requeue;
60704+atomic_unchecked_t fscache_n_op_deferred_release;
60705+atomic_unchecked_t fscache_n_op_release;
60706+atomic_unchecked_t fscache_n_op_gc;
60707+atomic_unchecked_t fscache_n_op_cancelled;
60708+atomic_unchecked_t fscache_n_op_rejected;
60709
60710-atomic_t fscache_n_attr_changed;
60711-atomic_t fscache_n_attr_changed_ok;
60712-atomic_t fscache_n_attr_changed_nobufs;
60713-atomic_t fscache_n_attr_changed_nomem;
60714-atomic_t fscache_n_attr_changed_calls;
60715+atomic_unchecked_t fscache_n_attr_changed;
60716+atomic_unchecked_t fscache_n_attr_changed_ok;
60717+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60718+atomic_unchecked_t fscache_n_attr_changed_nomem;
60719+atomic_unchecked_t fscache_n_attr_changed_calls;
60720
60721-atomic_t fscache_n_allocs;
60722-atomic_t fscache_n_allocs_ok;
60723-atomic_t fscache_n_allocs_wait;
60724-atomic_t fscache_n_allocs_nobufs;
60725-atomic_t fscache_n_allocs_intr;
60726-atomic_t fscache_n_allocs_object_dead;
60727-atomic_t fscache_n_alloc_ops;
60728-atomic_t fscache_n_alloc_op_waits;
60729+atomic_unchecked_t fscache_n_allocs;
60730+atomic_unchecked_t fscache_n_allocs_ok;
60731+atomic_unchecked_t fscache_n_allocs_wait;
60732+atomic_unchecked_t fscache_n_allocs_nobufs;
60733+atomic_unchecked_t fscache_n_allocs_intr;
60734+atomic_unchecked_t fscache_n_allocs_object_dead;
60735+atomic_unchecked_t fscache_n_alloc_ops;
60736+atomic_unchecked_t fscache_n_alloc_op_waits;
60737
60738-atomic_t fscache_n_retrievals;
60739-atomic_t fscache_n_retrievals_ok;
60740-atomic_t fscache_n_retrievals_wait;
60741-atomic_t fscache_n_retrievals_nodata;
60742-atomic_t fscache_n_retrievals_nobufs;
60743-atomic_t fscache_n_retrievals_intr;
60744-atomic_t fscache_n_retrievals_nomem;
60745-atomic_t fscache_n_retrievals_object_dead;
60746-atomic_t fscache_n_retrieval_ops;
60747-atomic_t fscache_n_retrieval_op_waits;
60748+atomic_unchecked_t fscache_n_retrievals;
60749+atomic_unchecked_t fscache_n_retrievals_ok;
60750+atomic_unchecked_t fscache_n_retrievals_wait;
60751+atomic_unchecked_t fscache_n_retrievals_nodata;
60752+atomic_unchecked_t fscache_n_retrievals_nobufs;
60753+atomic_unchecked_t fscache_n_retrievals_intr;
60754+atomic_unchecked_t fscache_n_retrievals_nomem;
60755+atomic_unchecked_t fscache_n_retrievals_object_dead;
60756+atomic_unchecked_t fscache_n_retrieval_ops;
60757+atomic_unchecked_t fscache_n_retrieval_op_waits;
60758
60759-atomic_t fscache_n_stores;
60760-atomic_t fscache_n_stores_ok;
60761-atomic_t fscache_n_stores_again;
60762-atomic_t fscache_n_stores_nobufs;
60763-atomic_t fscache_n_stores_oom;
60764-atomic_t fscache_n_store_ops;
60765-atomic_t fscache_n_store_calls;
60766-atomic_t fscache_n_store_pages;
60767-atomic_t fscache_n_store_radix_deletes;
60768-atomic_t fscache_n_store_pages_over_limit;
60769+atomic_unchecked_t fscache_n_stores;
60770+atomic_unchecked_t fscache_n_stores_ok;
60771+atomic_unchecked_t fscache_n_stores_again;
60772+atomic_unchecked_t fscache_n_stores_nobufs;
60773+atomic_unchecked_t fscache_n_stores_oom;
60774+atomic_unchecked_t fscache_n_store_ops;
60775+atomic_unchecked_t fscache_n_store_calls;
60776+atomic_unchecked_t fscache_n_store_pages;
60777+atomic_unchecked_t fscache_n_store_radix_deletes;
60778+atomic_unchecked_t fscache_n_store_pages_over_limit;
60779
60780-atomic_t fscache_n_store_vmscan_not_storing;
60781-atomic_t fscache_n_store_vmscan_gone;
60782-atomic_t fscache_n_store_vmscan_busy;
60783-atomic_t fscache_n_store_vmscan_cancelled;
60784-atomic_t fscache_n_store_vmscan_wait;
60785+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60786+atomic_unchecked_t fscache_n_store_vmscan_gone;
60787+atomic_unchecked_t fscache_n_store_vmscan_busy;
60788+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60789+atomic_unchecked_t fscache_n_store_vmscan_wait;
60790
60791-atomic_t fscache_n_marks;
60792-atomic_t fscache_n_uncaches;
60793+atomic_unchecked_t fscache_n_marks;
60794+atomic_unchecked_t fscache_n_uncaches;
60795
60796-atomic_t fscache_n_acquires;
60797-atomic_t fscache_n_acquires_null;
60798-atomic_t fscache_n_acquires_no_cache;
60799-atomic_t fscache_n_acquires_ok;
60800-atomic_t fscache_n_acquires_nobufs;
60801-atomic_t fscache_n_acquires_oom;
60802+atomic_unchecked_t fscache_n_acquires;
60803+atomic_unchecked_t fscache_n_acquires_null;
60804+atomic_unchecked_t fscache_n_acquires_no_cache;
60805+atomic_unchecked_t fscache_n_acquires_ok;
60806+atomic_unchecked_t fscache_n_acquires_nobufs;
60807+atomic_unchecked_t fscache_n_acquires_oom;
60808
60809-atomic_t fscache_n_invalidates;
60810-atomic_t fscache_n_invalidates_run;
60811+atomic_unchecked_t fscache_n_invalidates;
60812+atomic_unchecked_t fscache_n_invalidates_run;
60813
60814-atomic_t fscache_n_updates;
60815-atomic_t fscache_n_updates_null;
60816-atomic_t fscache_n_updates_run;
60817+atomic_unchecked_t fscache_n_updates;
60818+atomic_unchecked_t fscache_n_updates_null;
60819+atomic_unchecked_t fscache_n_updates_run;
60820
60821-atomic_t fscache_n_relinquishes;
60822-atomic_t fscache_n_relinquishes_null;
60823-atomic_t fscache_n_relinquishes_waitcrt;
60824-atomic_t fscache_n_relinquishes_retire;
60825+atomic_unchecked_t fscache_n_relinquishes;
60826+atomic_unchecked_t fscache_n_relinquishes_null;
60827+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60828+atomic_unchecked_t fscache_n_relinquishes_retire;
60829
60830-atomic_t fscache_n_cookie_index;
60831-atomic_t fscache_n_cookie_data;
60832-atomic_t fscache_n_cookie_special;
60833+atomic_unchecked_t fscache_n_cookie_index;
60834+atomic_unchecked_t fscache_n_cookie_data;
60835+atomic_unchecked_t fscache_n_cookie_special;
60836
60837-atomic_t fscache_n_object_alloc;
60838-atomic_t fscache_n_object_no_alloc;
60839-atomic_t fscache_n_object_lookups;
60840-atomic_t fscache_n_object_lookups_negative;
60841-atomic_t fscache_n_object_lookups_positive;
60842-atomic_t fscache_n_object_lookups_timed_out;
60843-atomic_t fscache_n_object_created;
60844-atomic_t fscache_n_object_avail;
60845-atomic_t fscache_n_object_dead;
60846+atomic_unchecked_t fscache_n_object_alloc;
60847+atomic_unchecked_t fscache_n_object_no_alloc;
60848+atomic_unchecked_t fscache_n_object_lookups;
60849+atomic_unchecked_t fscache_n_object_lookups_negative;
60850+atomic_unchecked_t fscache_n_object_lookups_positive;
60851+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60852+atomic_unchecked_t fscache_n_object_created;
60853+atomic_unchecked_t fscache_n_object_avail;
60854+atomic_unchecked_t fscache_n_object_dead;
60855
60856-atomic_t fscache_n_checkaux_none;
60857-atomic_t fscache_n_checkaux_okay;
60858-atomic_t fscache_n_checkaux_update;
60859-atomic_t fscache_n_checkaux_obsolete;
60860+atomic_unchecked_t fscache_n_checkaux_none;
60861+atomic_unchecked_t fscache_n_checkaux_okay;
60862+atomic_unchecked_t fscache_n_checkaux_update;
60863+atomic_unchecked_t fscache_n_checkaux_obsolete;
60864
60865 atomic_t fscache_n_cop_alloc_object;
60866 atomic_t fscache_n_cop_lookup_object;
60867@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60868 seq_puts(m, "FS-Cache statistics\n");
60869
60870 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60871- atomic_read(&fscache_n_cookie_index),
60872- atomic_read(&fscache_n_cookie_data),
60873- atomic_read(&fscache_n_cookie_special));
60874+ atomic_read_unchecked(&fscache_n_cookie_index),
60875+ atomic_read_unchecked(&fscache_n_cookie_data),
60876+ atomic_read_unchecked(&fscache_n_cookie_special));
60877
60878 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60879- atomic_read(&fscache_n_object_alloc),
60880- atomic_read(&fscache_n_object_no_alloc),
60881- atomic_read(&fscache_n_object_avail),
60882- atomic_read(&fscache_n_object_dead));
60883+ atomic_read_unchecked(&fscache_n_object_alloc),
60884+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60885+ atomic_read_unchecked(&fscache_n_object_avail),
60886+ atomic_read_unchecked(&fscache_n_object_dead));
60887 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60888- atomic_read(&fscache_n_checkaux_none),
60889- atomic_read(&fscache_n_checkaux_okay),
60890- atomic_read(&fscache_n_checkaux_update),
60891- atomic_read(&fscache_n_checkaux_obsolete));
60892+ atomic_read_unchecked(&fscache_n_checkaux_none),
60893+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60894+ atomic_read_unchecked(&fscache_n_checkaux_update),
60895+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60896
60897 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60898- atomic_read(&fscache_n_marks),
60899- atomic_read(&fscache_n_uncaches));
60900+ atomic_read_unchecked(&fscache_n_marks),
60901+ atomic_read_unchecked(&fscache_n_uncaches));
60902
60903 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60904 " oom=%u\n",
60905- atomic_read(&fscache_n_acquires),
60906- atomic_read(&fscache_n_acquires_null),
60907- atomic_read(&fscache_n_acquires_no_cache),
60908- atomic_read(&fscache_n_acquires_ok),
60909- atomic_read(&fscache_n_acquires_nobufs),
60910- atomic_read(&fscache_n_acquires_oom));
60911+ atomic_read_unchecked(&fscache_n_acquires),
60912+ atomic_read_unchecked(&fscache_n_acquires_null),
60913+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60914+ atomic_read_unchecked(&fscache_n_acquires_ok),
60915+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60916+ atomic_read_unchecked(&fscache_n_acquires_oom));
60917
60918 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60919- atomic_read(&fscache_n_object_lookups),
60920- atomic_read(&fscache_n_object_lookups_negative),
60921- atomic_read(&fscache_n_object_lookups_positive),
60922- atomic_read(&fscache_n_object_created),
60923- atomic_read(&fscache_n_object_lookups_timed_out));
60924+ atomic_read_unchecked(&fscache_n_object_lookups),
60925+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60926+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60927+ atomic_read_unchecked(&fscache_n_object_created),
60928+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60929
60930 seq_printf(m, "Invals : n=%u run=%u\n",
60931- atomic_read(&fscache_n_invalidates),
60932- atomic_read(&fscache_n_invalidates_run));
60933+ atomic_read_unchecked(&fscache_n_invalidates),
60934+ atomic_read_unchecked(&fscache_n_invalidates_run));
60935
60936 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60937- atomic_read(&fscache_n_updates),
60938- atomic_read(&fscache_n_updates_null),
60939- atomic_read(&fscache_n_updates_run));
60940+ atomic_read_unchecked(&fscache_n_updates),
60941+ atomic_read_unchecked(&fscache_n_updates_null),
60942+ atomic_read_unchecked(&fscache_n_updates_run));
60943
60944 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60945- atomic_read(&fscache_n_relinquishes),
60946- atomic_read(&fscache_n_relinquishes_null),
60947- atomic_read(&fscache_n_relinquishes_waitcrt),
60948- atomic_read(&fscache_n_relinquishes_retire));
60949+ atomic_read_unchecked(&fscache_n_relinquishes),
60950+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60951+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60952+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60953
60954 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60955- atomic_read(&fscache_n_attr_changed),
60956- atomic_read(&fscache_n_attr_changed_ok),
60957- atomic_read(&fscache_n_attr_changed_nobufs),
60958- atomic_read(&fscache_n_attr_changed_nomem),
60959- atomic_read(&fscache_n_attr_changed_calls));
60960+ atomic_read_unchecked(&fscache_n_attr_changed),
60961+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60962+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60963+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60964+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60965
60966 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60967- atomic_read(&fscache_n_allocs),
60968- atomic_read(&fscache_n_allocs_ok),
60969- atomic_read(&fscache_n_allocs_wait),
60970- atomic_read(&fscache_n_allocs_nobufs),
60971- atomic_read(&fscache_n_allocs_intr));
60972+ atomic_read_unchecked(&fscache_n_allocs),
60973+ atomic_read_unchecked(&fscache_n_allocs_ok),
60974+ atomic_read_unchecked(&fscache_n_allocs_wait),
60975+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60976+ atomic_read_unchecked(&fscache_n_allocs_intr));
60977 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60978- atomic_read(&fscache_n_alloc_ops),
60979- atomic_read(&fscache_n_alloc_op_waits),
60980- atomic_read(&fscache_n_allocs_object_dead));
60981+ atomic_read_unchecked(&fscache_n_alloc_ops),
60982+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60983+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60984
60985 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60986 " int=%u oom=%u\n",
60987- atomic_read(&fscache_n_retrievals),
60988- atomic_read(&fscache_n_retrievals_ok),
60989- atomic_read(&fscache_n_retrievals_wait),
60990- atomic_read(&fscache_n_retrievals_nodata),
60991- atomic_read(&fscache_n_retrievals_nobufs),
60992- atomic_read(&fscache_n_retrievals_intr),
60993- atomic_read(&fscache_n_retrievals_nomem));
60994+ atomic_read_unchecked(&fscache_n_retrievals),
60995+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60996+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60997+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60998+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60999+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61000+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61001 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61002- atomic_read(&fscache_n_retrieval_ops),
61003- atomic_read(&fscache_n_retrieval_op_waits),
61004- atomic_read(&fscache_n_retrievals_object_dead));
61005+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61006+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61007+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61008
61009 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61010- atomic_read(&fscache_n_stores),
61011- atomic_read(&fscache_n_stores_ok),
61012- atomic_read(&fscache_n_stores_again),
61013- atomic_read(&fscache_n_stores_nobufs),
61014- atomic_read(&fscache_n_stores_oom));
61015+ atomic_read_unchecked(&fscache_n_stores),
61016+ atomic_read_unchecked(&fscache_n_stores_ok),
61017+ atomic_read_unchecked(&fscache_n_stores_again),
61018+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61019+ atomic_read_unchecked(&fscache_n_stores_oom));
61020 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61021- atomic_read(&fscache_n_store_ops),
61022- atomic_read(&fscache_n_store_calls),
61023- atomic_read(&fscache_n_store_pages),
61024- atomic_read(&fscache_n_store_radix_deletes),
61025- atomic_read(&fscache_n_store_pages_over_limit));
61026+ atomic_read_unchecked(&fscache_n_store_ops),
61027+ atomic_read_unchecked(&fscache_n_store_calls),
61028+ atomic_read_unchecked(&fscache_n_store_pages),
61029+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61030+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61031
61032 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61033- atomic_read(&fscache_n_store_vmscan_not_storing),
61034- atomic_read(&fscache_n_store_vmscan_gone),
61035- atomic_read(&fscache_n_store_vmscan_busy),
61036- atomic_read(&fscache_n_store_vmscan_cancelled),
61037- atomic_read(&fscache_n_store_vmscan_wait));
61038+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61039+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61040+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61041+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61042+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61043
61044 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61045- atomic_read(&fscache_n_op_pend),
61046- atomic_read(&fscache_n_op_run),
61047- atomic_read(&fscache_n_op_enqueue),
61048- atomic_read(&fscache_n_op_cancelled),
61049- atomic_read(&fscache_n_op_rejected));
61050+ atomic_read_unchecked(&fscache_n_op_pend),
61051+ atomic_read_unchecked(&fscache_n_op_run),
61052+ atomic_read_unchecked(&fscache_n_op_enqueue),
61053+ atomic_read_unchecked(&fscache_n_op_cancelled),
61054+ atomic_read_unchecked(&fscache_n_op_rejected));
61055 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61056- atomic_read(&fscache_n_op_deferred_release),
61057- atomic_read(&fscache_n_op_release),
61058- atomic_read(&fscache_n_op_gc));
61059+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61060+ atomic_read_unchecked(&fscache_n_op_release),
61061+ atomic_read_unchecked(&fscache_n_op_gc));
61062
61063 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61064 atomic_read(&fscache_n_cop_alloc_object),
61065diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61066index b96a49b..9bfdc47 100644
61067--- a/fs/fuse/cuse.c
61068+++ b/fs/fuse/cuse.c
61069@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61070 INIT_LIST_HEAD(&cuse_conntbl[i]);
61071
61072 /* inherit and extend fuse_dev_operations */
61073- cuse_channel_fops = fuse_dev_operations;
61074- cuse_channel_fops.owner = THIS_MODULE;
61075- cuse_channel_fops.open = cuse_channel_open;
61076- cuse_channel_fops.release = cuse_channel_release;
61077+ pax_open_kernel();
61078+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61079+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61080+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61081+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61082+ pax_close_kernel();
61083
61084 cuse_class = class_create(THIS_MODULE, "cuse");
61085 if (IS_ERR(cuse_class))
61086diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61087index 0a648bb..8d463f1 100644
61088--- a/fs/fuse/dev.c
61089+++ b/fs/fuse/dev.c
61090@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61091 ret = 0;
61092 pipe_lock(pipe);
61093
61094- if (!pipe->readers) {
61095+ if (!atomic_read(&pipe->readers)) {
61096 send_sig(SIGPIPE, current, 0);
61097 if (!ret)
61098 ret = -EPIPE;
61099@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61100 page_nr++;
61101 ret += buf->len;
61102
61103- if (pipe->files)
61104+ if (atomic_read(&pipe->files))
61105 do_wakeup = 1;
61106 }
61107
61108diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61109index 1d1292c..bba17ea 100644
61110--- a/fs/fuse/dir.c
61111+++ b/fs/fuse/dir.c
61112@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61113 return link;
61114 }
61115
61116-static void free_link(char *link)
61117+static void free_link(const char *link)
61118 {
61119 if (!IS_ERR(link))
61120 free_page((unsigned long) link);
61121diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61122index fe649d3..c679164 100644
61123--- a/fs/hostfs/hostfs_kern.c
61124+++ b/fs/hostfs/hostfs_kern.c
61125@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61126
61127 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61128 {
61129- char *s = nd_get_link(nd);
61130+ const char *s = nd_get_link(nd);
61131 if (!IS_ERR(s))
61132 __putname(s);
61133 }
61134diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61135index d19b30a..ef89c36 100644
61136--- a/fs/hugetlbfs/inode.c
61137+++ b/fs/hugetlbfs/inode.c
61138@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61139 struct mm_struct *mm = current->mm;
61140 struct vm_area_struct *vma;
61141 struct hstate *h = hstate_file(file);
61142+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61143 struct vm_unmapped_area_info info;
61144
61145 if (len & ~huge_page_mask(h))
61146@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61147 return addr;
61148 }
61149
61150+#ifdef CONFIG_PAX_RANDMMAP
61151+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61152+#endif
61153+
61154 if (addr) {
61155 addr = ALIGN(addr, huge_page_size(h));
61156 vma = find_vma(mm, addr);
61157- if (TASK_SIZE - len >= addr &&
61158- (!vma || addr + len <= vma->vm_start))
61159+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61160 return addr;
61161 }
61162
61163 info.flags = 0;
61164 info.length = len;
61165 info.low_limit = TASK_UNMAPPED_BASE;
61166+
61167+#ifdef CONFIG_PAX_RANDMMAP
61168+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61169+ info.low_limit += mm->delta_mmap;
61170+#endif
61171+
61172 info.high_limit = TASK_SIZE;
61173 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61174 info.align_offset = 0;
61175@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61176 };
61177 MODULE_ALIAS_FS("hugetlbfs");
61178
61179-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61180+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61181
61182 static int can_do_hugetlb_shm(void)
61183 {
61184diff --git a/fs/inode.c b/fs/inode.c
61185index 4bcdad3..1883822 100644
61186--- a/fs/inode.c
61187+++ b/fs/inode.c
61188@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61189
61190 #ifdef CONFIG_SMP
61191 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61192- static atomic_t shared_last_ino;
61193- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61194+ static atomic_unchecked_t shared_last_ino;
61195+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61196
61197 res = next - LAST_INO_BATCH;
61198 }
61199diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61200index 4a6cf28..d3a29d3 100644
61201--- a/fs/jffs2/erase.c
61202+++ b/fs/jffs2/erase.c
61203@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61204 struct jffs2_unknown_node marker = {
61205 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61206 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61207- .totlen = cpu_to_je32(c->cleanmarker_size)
61208+ .totlen = cpu_to_je32(c->cleanmarker_size),
61209+ .hdr_crc = cpu_to_je32(0)
61210 };
61211
61212 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61213diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61214index a6597d6..41b30ec 100644
61215--- a/fs/jffs2/wbuf.c
61216+++ b/fs/jffs2/wbuf.c
61217@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61218 {
61219 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61220 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61221- .totlen = constant_cpu_to_je32(8)
61222+ .totlen = constant_cpu_to_je32(8),
61223+ .hdr_crc = constant_cpu_to_je32(0)
61224 };
61225
61226 /*
61227diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61228index e2b7483..855bca3 100644
61229--- a/fs/jfs/super.c
61230+++ b/fs/jfs/super.c
61231@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61232
61233 jfs_inode_cachep =
61234 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61235- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61236+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61237 init_once);
61238 if (jfs_inode_cachep == NULL)
61239 return -ENOMEM;
61240diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61241index 39c0143..d54fad4 100644
61242--- a/fs/kernfs/dir.c
61243+++ b/fs/kernfs/dir.c
61244@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61245 *
61246 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61247 */
61248-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61249+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61250 {
61251 unsigned long hash = init_name_hash();
61252 unsigned int len = strlen(name);
61253diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61254index dbf397b..d624b48 100644
61255--- a/fs/kernfs/file.c
61256+++ b/fs/kernfs/file.c
61257@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61258
61259 struct kernfs_open_node {
61260 atomic_t refcnt;
61261- atomic_t event;
61262+ atomic_unchecked_t event;
61263 wait_queue_head_t poll;
61264 struct list_head files; /* goes through kernfs_open_file.list */
61265 };
61266@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61267 {
61268 struct kernfs_open_file *of = sf->private;
61269
61270- of->event = atomic_read(&of->kn->attr.open->event);
61271+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61272
61273 return of->kn->attr.ops->seq_show(sf, v);
61274 }
61275@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61276 return ret;
61277 }
61278
61279-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61280- void *buf, int len, int write)
61281+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61282+ void *buf, size_t len, int write)
61283 {
61284 struct file *file = vma->vm_file;
61285 struct kernfs_open_file *of = kernfs_of(file);
61286- int ret;
61287+ ssize_t ret;
61288
61289 if (!of->vm_ops)
61290 return -EINVAL;
61291@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61292 return -ENOMEM;
61293
61294 atomic_set(&new_on->refcnt, 0);
61295- atomic_set(&new_on->event, 1);
61296+ atomic_set_unchecked(&new_on->event, 1);
61297 init_waitqueue_head(&new_on->poll);
61298 INIT_LIST_HEAD(&new_on->files);
61299 goto retry;
61300@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61301
61302 kernfs_put_active(kn);
61303
61304- if (of->event != atomic_read(&on->event))
61305+ if (of->event != atomic_read_unchecked(&on->event))
61306 goto trigger;
61307
61308 return DEFAULT_POLLMASK;
61309@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61310 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61311 on = kn->attr.open;
61312 if (on) {
61313- atomic_inc(&on->event);
61314+ atomic_inc_unchecked(&on->event);
61315 wake_up_interruptible(&on->poll);
61316 }
61317 }
61318diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61319index 4d45705..b35e0bd 100644
61320--- a/fs/kernfs/symlink.c
61321+++ b/fs/kernfs/symlink.c
61322@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61323 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61324 void *cookie)
61325 {
61326- char *page = nd_get_link(nd);
61327+ const char *page = nd_get_link(nd);
61328 if (!IS_ERR(page))
61329 free_page((unsigned long)page);
61330 }
61331diff --git a/fs/libfs.c b/fs/libfs.c
61332index a184424..944ddce 100644
61333--- a/fs/libfs.c
61334+++ b/fs/libfs.c
61335@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61336
61337 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61338 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61339+ char d_name[sizeof(next->d_iname)];
61340+ const unsigned char *name;
61341+
61342 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61343 if (!simple_positive(next)) {
61344 spin_unlock(&next->d_lock);
61345@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61346
61347 spin_unlock(&next->d_lock);
61348 spin_unlock(&dentry->d_lock);
61349- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61350+ name = next->d_name.name;
61351+ if (name == next->d_iname) {
61352+ memcpy(d_name, name, next->d_name.len);
61353+ name = d_name;
61354+ }
61355+ if (!dir_emit(ctx, name, next->d_name.len,
61356 next->d_inode->i_ino, dt_type(next->d_inode)))
61357 return 0;
61358 spin_lock(&dentry->d_lock);
61359@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61360 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61361 void *cookie)
61362 {
61363- char *s = nd_get_link(nd);
61364+ const char *s = nd_get_link(nd);
61365 if (!IS_ERR(s))
61366 kfree(s);
61367 }
61368diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61369index acd3947..1f896e2 100644
61370--- a/fs/lockd/clntproc.c
61371+++ b/fs/lockd/clntproc.c
61372@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61373 /*
61374 * Cookie counter for NLM requests
61375 */
61376-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61377+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61378
61379 void nlmclnt_next_cookie(struct nlm_cookie *c)
61380 {
61381- u32 cookie = atomic_inc_return(&nlm_cookie);
61382+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61383
61384 memcpy(c->data, &cookie, 4);
61385 c->len=4;
61386diff --git a/fs/locks.c b/fs/locks.c
61387index 92a0f0a..45a48f0 100644
61388--- a/fs/locks.c
61389+++ b/fs/locks.c
61390@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61391 return;
61392
61393 if (filp->f_op->flock) {
61394- struct file_lock fl = {
61395+ struct file_lock flock = {
61396 .fl_pid = current->tgid,
61397 .fl_file = filp,
61398 .fl_flags = FL_FLOCK,
61399 .fl_type = F_UNLCK,
61400 .fl_end = OFFSET_MAX,
61401 };
61402- filp->f_op->flock(filp, F_SETLKW, &fl);
61403- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61404- fl.fl_ops->fl_release_private(&fl);
61405+ filp->f_op->flock(filp, F_SETLKW, &flock);
61406+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61407+ flock.fl_ops->fl_release_private(&flock);
61408 }
61409
61410 spin_lock(&inode->i_lock);
61411diff --git a/fs/mount.h b/fs/mount.h
61412index b29e42f..5ea7fdf 100644
61413--- a/fs/mount.h
61414+++ b/fs/mount.h
61415@@ -11,7 +11,7 @@ struct mnt_namespace {
61416 u64 seq; /* Sequence number to prevent loops */
61417 wait_queue_head_t poll;
61418 int event;
61419-};
61420+} __randomize_layout;
61421
61422 struct mnt_pcp {
61423 int mnt_count;
61424@@ -57,7 +57,7 @@ struct mount {
61425 int mnt_expiry_mark; /* true if marked for expiry */
61426 int mnt_pinned;
61427 struct path mnt_ex_mountpoint;
61428-};
61429+} __randomize_layout;
61430
61431 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61432
61433diff --git a/fs/namei.c b/fs/namei.c
61434index 4b491b4..a0166f9 100644
61435--- a/fs/namei.c
61436+++ b/fs/namei.c
61437@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61438 if (ret != -EACCES)
61439 return ret;
61440
61441+#ifdef CONFIG_GRKERNSEC
61442+ /* we'll block if we have to log due to a denied capability use */
61443+ if (mask & MAY_NOT_BLOCK)
61444+ return -ECHILD;
61445+#endif
61446+
61447 if (S_ISDIR(inode->i_mode)) {
61448 /* DACs are overridable for directories */
61449- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61450- return 0;
61451 if (!(mask & MAY_WRITE))
61452- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61453+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61454+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61455 return 0;
61456+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61457+ return 0;
61458 return -EACCES;
61459 }
61460 /*
61461+ * Searching includes executable on directories, else just read.
61462+ */
61463+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61464+ if (mask == MAY_READ)
61465+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61466+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61467+ return 0;
61468+
61469+ /*
61470 * Read/write DACs are always overridable.
61471 * Executable DACs are overridable when there is
61472 * at least one exec bit set.
61473@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61474 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61475 return 0;
61476
61477- /*
61478- * Searching includes executable on directories, else just read.
61479- */
61480- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61481- if (mask == MAY_READ)
61482- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61483- return 0;
61484-
61485 return -EACCES;
61486 }
61487
61488@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61489 {
61490 struct dentry *dentry = link->dentry;
61491 int error;
61492- char *s;
61493+ const char *s;
61494
61495 BUG_ON(nd->flags & LOOKUP_RCU);
61496
61497@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61498 if (error)
61499 goto out_put_nd_path;
61500
61501+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61502+ dentry->d_inode, dentry, nd->path.mnt)) {
61503+ error = -EACCES;
61504+ goto out_put_nd_path;
61505+ }
61506+
61507 nd->last_type = LAST_BIND;
61508 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61509 error = PTR_ERR(*p);
61510@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61511 if (res)
61512 break;
61513 res = walk_component(nd, path, LOOKUP_FOLLOW);
61514+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61515+ res = -EACCES;
61516 put_link(nd, &link, cookie);
61517 } while (res > 0);
61518
61519@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61520 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61521 {
61522 unsigned long a, b, adata, bdata, mask, hash, len;
61523- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61524+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61525
61526 hash = a = 0;
61527 len = -sizeof(unsigned long);
61528@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61529 if (err)
61530 break;
61531 err = lookup_last(nd, &path);
61532+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61533+ err = -EACCES;
61534 put_link(nd, &link, cookie);
61535 }
61536 }
61537@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61538 if (!err)
61539 err = complete_walk(nd);
61540
61541+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61542+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61543+ path_put(&nd->path);
61544+ err = -ENOENT;
61545+ }
61546+ }
61547+
61548 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61549 if (!d_is_directory(nd->path.dentry)) {
61550 path_put(&nd->path);
61551@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61552 retval = path_lookupat(dfd, name->name,
61553 flags | LOOKUP_REVAL, nd);
61554
61555- if (likely(!retval))
61556+ if (likely(!retval)) {
61557 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61558+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61559+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61560+ path_put(&nd->path);
61561+ return -ENOENT;
61562+ }
61563+ }
61564+ }
61565 return retval;
61566 }
61567
61568@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61569 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61570 return -EPERM;
61571
61572+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61573+ return -EPERM;
61574+ if (gr_handle_rawio(inode))
61575+ return -EPERM;
61576+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61577+ return -EACCES;
61578+
61579 return 0;
61580 }
61581
61582@@ -2787,7 +2826,7 @@ looked_up:
61583 * cleared otherwise prior to returning.
61584 */
61585 static int lookup_open(struct nameidata *nd, struct path *path,
61586- struct file *file,
61587+ struct path *link, struct file *file,
61588 const struct open_flags *op,
61589 bool got_write, int *opened)
61590 {
61591@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61592 /* Negative dentry, just create the file */
61593 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61594 umode_t mode = op->mode;
61595+
61596+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61597+ error = -EACCES;
61598+ goto out_dput;
61599+ }
61600+
61601+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61602+ error = -EACCES;
61603+ goto out_dput;
61604+ }
61605+
61606 if (!IS_POSIXACL(dir->d_inode))
61607 mode &= ~current_umask();
61608 /*
61609@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61610 nd->flags & LOOKUP_EXCL);
61611 if (error)
61612 goto out_dput;
61613+ else
61614+ gr_handle_create(dentry, nd->path.mnt);
61615 }
61616 out_no_open:
61617 path->dentry = dentry;
61618@@ -2857,7 +2909,7 @@ out_dput:
61619 /*
61620 * Handle the last step of open()
61621 */
61622-static int do_last(struct nameidata *nd, struct path *path,
61623+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61624 struct file *file, const struct open_flags *op,
61625 int *opened, struct filename *name)
61626 {
61627@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61628 if (error)
61629 return error;
61630
61631+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61632+ error = -ENOENT;
61633+ goto out;
61634+ }
61635+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61636+ error = -EACCES;
61637+ goto out;
61638+ }
61639+
61640 audit_inode(name, dir, LOOKUP_PARENT);
61641 error = -EISDIR;
61642 /* trailing slashes? */
61643@@ -2926,7 +2987,7 @@ retry_lookup:
61644 */
61645 }
61646 mutex_lock(&dir->d_inode->i_mutex);
61647- error = lookup_open(nd, path, file, op, got_write, opened);
61648+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61649 mutex_unlock(&dir->d_inode->i_mutex);
61650
61651 if (error <= 0) {
61652@@ -2950,11 +3011,28 @@ retry_lookup:
61653 goto finish_open_created;
61654 }
61655
61656+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61657+ error = -ENOENT;
61658+ goto exit_dput;
61659+ }
61660+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61661+ error = -EACCES;
61662+ goto exit_dput;
61663+ }
61664+
61665 /*
61666 * create/update audit record if it already exists.
61667 */
61668- if (d_is_positive(path->dentry))
61669+ if (d_is_positive(path->dentry)) {
61670+ /* only check if O_CREAT is specified, all other checks need to go
61671+ into may_open */
61672+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61673+ error = -EACCES;
61674+ goto exit_dput;
61675+ }
61676+
61677 audit_inode(name, path->dentry, 0);
61678+ }
61679
61680 /*
61681 * If atomic_open() acquired write access it is dropped now due to
61682@@ -2995,6 +3073,11 @@ finish_lookup:
61683 }
61684 }
61685 BUG_ON(inode != path->dentry->d_inode);
61686+ /* if we're resolving a symlink to another symlink */
61687+ if (link && gr_handle_symlink_owner(link, inode)) {
61688+ error = -EACCES;
61689+ goto out;
61690+ }
61691 return 1;
61692 }
61693
61694@@ -3004,7 +3087,6 @@ finish_lookup:
61695 save_parent.dentry = nd->path.dentry;
61696 save_parent.mnt = mntget(path->mnt);
61697 nd->path.dentry = path->dentry;
61698-
61699 }
61700 nd->inode = inode;
61701 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61702@@ -3014,7 +3096,18 @@ finish_open:
61703 path_put(&save_parent);
61704 return error;
61705 }
61706+
61707+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61708+ error = -ENOENT;
61709+ goto out;
61710+ }
61711+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61712+ error = -EACCES;
61713+ goto out;
61714+ }
61715+
61716 audit_inode(name, nd->path.dentry, 0);
61717+
61718 error = -EISDIR;
61719 if ((open_flag & O_CREAT) &&
61720 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61721@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61722 if (unlikely(error))
61723 goto out;
61724
61725- error = do_last(nd, &path, file, op, &opened, pathname);
61726+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61727 while (unlikely(error > 0)) { /* trailing symlink */
61728 struct path link = path;
61729 void *cookie;
61730@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61731 error = follow_link(&link, nd, &cookie);
61732 if (unlikely(error))
61733 break;
61734- error = do_last(nd, &path, file, op, &opened, pathname);
61735+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61736 put_link(nd, &link, cookie);
61737 }
61738 out:
61739@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61740 goto unlock;
61741
61742 error = -EEXIST;
61743- if (d_is_positive(dentry))
61744+ if (d_is_positive(dentry)) {
61745+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61746+ error = -ENOENT;
61747 goto fail;
61748-
61749+ }
61750 /*
61751 * Special case - lookup gave negative, but... we had foo/bar/
61752 * From the vfs_mknod() POV we just have a negative dentry -
61753@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61754 }
61755 EXPORT_SYMBOL(user_path_create);
61756
61757+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61758+{
61759+ struct filename *tmp = getname(pathname);
61760+ struct dentry *res;
61761+ if (IS_ERR(tmp))
61762+ return ERR_CAST(tmp);
61763+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61764+ if (IS_ERR(res))
61765+ putname(tmp);
61766+ else
61767+ *to = tmp;
61768+ return res;
61769+}
61770+
61771 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61772 {
61773 int error = may_create(dir, dentry);
61774@@ -3412,6 +3521,17 @@ retry:
61775
61776 if (!IS_POSIXACL(path.dentry->d_inode))
61777 mode &= ~current_umask();
61778+
61779+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61780+ error = -EPERM;
61781+ goto out;
61782+ }
61783+
61784+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61785+ error = -EACCES;
61786+ goto out;
61787+ }
61788+
61789 error = security_path_mknod(&path, dentry, mode, dev);
61790 if (error)
61791 goto out;
61792@@ -3428,6 +3548,8 @@ retry:
61793 break;
61794 }
61795 out:
61796+ if (!error)
61797+ gr_handle_create(dentry, path.mnt);
61798 done_path_create(&path, dentry);
61799 if (retry_estale(error, lookup_flags)) {
61800 lookup_flags |= LOOKUP_REVAL;
61801@@ -3480,9 +3602,16 @@ retry:
61802
61803 if (!IS_POSIXACL(path.dentry->d_inode))
61804 mode &= ~current_umask();
61805+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61806+ error = -EACCES;
61807+ goto out;
61808+ }
61809 error = security_path_mkdir(&path, dentry, mode);
61810 if (!error)
61811 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61812+ if (!error)
61813+ gr_handle_create(dentry, path.mnt);
61814+out:
61815 done_path_create(&path, dentry);
61816 if (retry_estale(error, lookup_flags)) {
61817 lookup_flags |= LOOKUP_REVAL;
61818@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61819 struct filename *name;
61820 struct dentry *dentry;
61821 struct nameidata nd;
61822+ ino_t saved_ino = 0;
61823+ dev_t saved_dev = 0;
61824 unsigned int lookup_flags = 0;
61825 retry:
61826 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61827@@ -3595,10 +3726,21 @@ retry:
61828 error = -ENOENT;
61829 goto exit3;
61830 }
61831+
61832+ saved_ino = dentry->d_inode->i_ino;
61833+ saved_dev = gr_get_dev_from_dentry(dentry);
61834+
61835+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61836+ error = -EACCES;
61837+ goto exit3;
61838+ }
61839+
61840 error = security_path_rmdir(&nd.path, dentry);
61841 if (error)
61842 goto exit3;
61843 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61844+ if (!error && (saved_dev || saved_ino))
61845+ gr_handle_delete(saved_ino, saved_dev);
61846 exit3:
61847 dput(dentry);
61848 exit2:
61849@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61850 struct nameidata nd;
61851 struct inode *inode = NULL;
61852 struct inode *delegated_inode = NULL;
61853+ ino_t saved_ino = 0;
61854+ dev_t saved_dev = 0;
61855 unsigned int lookup_flags = 0;
61856 retry:
61857 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61858@@ -3714,10 +3858,22 @@ retry_deleg:
61859 if (d_is_negative(dentry))
61860 goto slashes;
61861 ihold(inode);
61862+
61863+ if (inode->i_nlink <= 1) {
61864+ saved_ino = inode->i_ino;
61865+ saved_dev = gr_get_dev_from_dentry(dentry);
61866+ }
61867+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61868+ error = -EACCES;
61869+ goto exit2;
61870+ }
61871+
61872 error = security_path_unlink(&nd.path, dentry);
61873 if (error)
61874 goto exit2;
61875 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61876+ if (!error && (saved_ino || saved_dev))
61877+ gr_handle_delete(saved_ino, saved_dev);
61878 exit2:
61879 dput(dentry);
61880 }
61881@@ -3805,9 +3961,17 @@ retry:
61882 if (IS_ERR(dentry))
61883 goto out_putname;
61884
61885+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61886+ error = -EACCES;
61887+ goto out;
61888+ }
61889+
61890 error = security_path_symlink(&path, dentry, from->name);
61891 if (!error)
61892 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61893+ if (!error)
61894+ gr_handle_create(dentry, path.mnt);
61895+out:
61896 done_path_create(&path, dentry);
61897 if (retry_estale(error, lookup_flags)) {
61898 lookup_flags |= LOOKUP_REVAL;
61899@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61900 struct dentry *new_dentry;
61901 struct path old_path, new_path;
61902 struct inode *delegated_inode = NULL;
61903+ struct filename *to = NULL;
61904 int how = 0;
61905 int error;
61906
61907@@ -3933,7 +4098,7 @@ retry:
61908 if (error)
61909 return error;
61910
61911- new_dentry = user_path_create(newdfd, newname, &new_path,
61912+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61913 (how & LOOKUP_REVAL));
61914 error = PTR_ERR(new_dentry);
61915 if (IS_ERR(new_dentry))
61916@@ -3945,11 +4110,28 @@ retry:
61917 error = may_linkat(&old_path);
61918 if (unlikely(error))
61919 goto out_dput;
61920+
61921+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61922+ old_path.dentry->d_inode,
61923+ old_path.dentry->d_inode->i_mode, to)) {
61924+ error = -EACCES;
61925+ goto out_dput;
61926+ }
61927+
61928+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61929+ old_path.dentry, old_path.mnt, to)) {
61930+ error = -EACCES;
61931+ goto out_dput;
61932+ }
61933+
61934 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61935 if (error)
61936 goto out_dput;
61937 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61938+ if (!error)
61939+ gr_handle_create(new_dentry, new_path.mnt);
61940 out_dput:
61941+ putname(to);
61942 done_path_create(&new_path, new_dentry);
61943 if (delegated_inode) {
61944 error = break_deleg_wait(&delegated_inode);
61945@@ -4236,6 +4418,12 @@ retry_deleg:
61946 if (new_dentry == trap)
61947 goto exit5;
61948
61949+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61950+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61951+ to);
61952+ if (error)
61953+ goto exit5;
61954+
61955 error = security_path_rename(&oldnd.path, old_dentry,
61956 &newnd.path, new_dentry);
61957 if (error)
61958@@ -4243,6 +4431,9 @@ retry_deleg:
61959 error = vfs_rename(old_dir->d_inode, old_dentry,
61960 new_dir->d_inode, new_dentry,
61961 &delegated_inode);
61962+ if (!error)
61963+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61964+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61965 exit5:
61966 dput(new_dentry);
61967 exit4:
61968@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61969
61970 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61971 {
61972+ char tmpbuf[64];
61973+ const char *newlink;
61974 int len;
61975
61976 len = PTR_ERR(link);
61977@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61978 len = strlen(link);
61979 if (len > (unsigned) buflen)
61980 len = buflen;
61981- if (copy_to_user(buffer, link, len))
61982+
61983+ if (len < sizeof(tmpbuf)) {
61984+ memcpy(tmpbuf, link, len);
61985+ newlink = tmpbuf;
61986+ } else
61987+ newlink = link;
61988+
61989+ if (copy_to_user(buffer, newlink, len))
61990 len = -EFAULT;
61991 out:
61992 return len;
61993diff --git a/fs/namespace.c b/fs/namespace.c
61994index 65233a5..82ac953 100644
61995--- a/fs/namespace.c
61996+++ b/fs/namespace.c
61997@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61998 if (!(sb->s_flags & MS_RDONLY))
61999 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62000 up_write(&sb->s_umount);
62001+
62002+ gr_log_remount(mnt->mnt_devname, retval);
62003+
62004 return retval;
62005 }
62006
62007@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62008 }
62009 unlock_mount_hash();
62010 namespace_unlock();
62011+
62012+ gr_log_unmount(mnt->mnt_devname, retval);
62013+
62014 return retval;
62015 }
62016
62017@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62018 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62019 */
62020
62021-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62022+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62023 {
62024 struct path path;
62025 struct mount *mnt;
62026@@ -1422,7 +1428,7 @@ out:
62027 /*
62028 * The 2.0 compatible umount. No flags.
62029 */
62030-SYSCALL_DEFINE1(oldumount, char __user *, name)
62031+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62032 {
62033 return sys_umount(name, 0);
62034 }
62035@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62036 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62037 MS_STRICTATIME);
62038
62039+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62040+ retval = -EPERM;
62041+ goto dput_out;
62042+ }
62043+
62044+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62045+ retval = -EPERM;
62046+ goto dput_out;
62047+ }
62048+
62049 if (flags & MS_REMOUNT)
62050 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62051 data_page);
62052@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62053 dev_name, data_page);
62054 dput_out:
62055 path_put(&path);
62056+
62057+ gr_log_mount(dev_name, dir_name, retval);
62058+
62059 return retval;
62060 }
62061
62062@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62063 * number incrementing at 10Ghz will take 12,427 years to wrap which
62064 * is effectively never, so we can ignore the possibility.
62065 */
62066-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62067+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62068
62069 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62070 {
62071@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62072 kfree(new_ns);
62073 return ERR_PTR(ret);
62074 }
62075- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62076+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62077 atomic_set(&new_ns->count, 1);
62078 new_ns->root = NULL;
62079 INIT_LIST_HEAD(&new_ns->list);
62080@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62081 return new_ns;
62082 }
62083
62084-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62085+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62086 struct user_namespace *user_ns, struct fs_struct *new_fs)
62087 {
62088 struct mnt_namespace *new_ns;
62089@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62090 }
62091 EXPORT_SYMBOL(mount_subtree);
62092
62093-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62094- char __user *, type, unsigned long, flags, void __user *, data)
62095+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62096+ const char __user *, type, unsigned long, flags, void __user *, data)
62097 {
62098 int ret;
62099 char *kernel_type;
62100@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62101 if (error)
62102 goto out2;
62103
62104+ if (gr_handle_chroot_pivot()) {
62105+ error = -EPERM;
62106+ goto out2;
62107+ }
62108+
62109 get_fs_root(current->fs, &root);
62110 old_mp = lock_mount(&old);
62111 error = PTR_ERR(old_mp);
62112@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62113 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62114 return -EPERM;
62115
62116- if (fs->users != 1)
62117+ if (atomic_read(&fs->users) != 1)
62118 return -EINVAL;
62119
62120 get_mnt_ns(mnt_ns);
62121diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62122index f4ccfe6..a5cf064 100644
62123--- a/fs/nfs/callback_xdr.c
62124+++ b/fs/nfs/callback_xdr.c
62125@@ -51,7 +51,7 @@ struct callback_op {
62126 callback_decode_arg_t decode_args;
62127 callback_encode_res_t encode_res;
62128 long res_maxsize;
62129-};
62130+} __do_const;
62131
62132 static struct callback_op callback_ops[];
62133
62134diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62135index 360114a..ac6e265 100644
62136--- a/fs/nfs/inode.c
62137+++ b/fs/nfs/inode.c
62138@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62139 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62140 }
62141
62142-static atomic_long_t nfs_attr_generation_counter;
62143+static atomic_long_unchecked_t nfs_attr_generation_counter;
62144
62145 static unsigned long nfs_read_attr_generation_counter(void)
62146 {
62147- return atomic_long_read(&nfs_attr_generation_counter);
62148+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62149 }
62150
62151 unsigned long nfs_inc_attr_generation_counter(void)
62152 {
62153- return atomic_long_inc_return(&nfs_attr_generation_counter);
62154+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62155 }
62156
62157 void nfs_fattr_init(struct nfs_fattr *fattr)
62158diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62159index 9a914e8..e89c0ea 100644
62160--- a/fs/nfsd/nfs4proc.c
62161+++ b/fs/nfsd/nfs4proc.c
62162@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62163 nfsd4op_rsize op_rsize_bop;
62164 stateid_getter op_get_currentstateid;
62165 stateid_setter op_set_currentstateid;
62166-};
62167+} __do_const;
62168
62169 static struct nfsd4_operation nfsd4_ops[];
62170
62171diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62172index 16e8fa7..b0803f6 100644
62173--- a/fs/nfsd/nfs4xdr.c
62174+++ b/fs/nfsd/nfs4xdr.c
62175@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62176
62177 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62178
62179-static nfsd4_dec nfsd4_dec_ops[] = {
62180+static const nfsd4_dec nfsd4_dec_ops[] = {
62181 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62182 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62183 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62184diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62185index f8f060f..c4ba09a 100644
62186--- a/fs/nfsd/nfscache.c
62187+++ b/fs/nfsd/nfscache.c
62188@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62189 {
62190 struct svc_cacherep *rp = rqstp->rq_cacherep;
62191 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62192- int len;
62193+ long len;
62194 size_t bufsize = 0;
62195
62196 if (!rp)
62197 return;
62198
62199- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62200- len >>= 2;
62201+ if (statp) {
62202+ len = (char*)statp - (char*)resv->iov_base;
62203+ len = resv->iov_len - len;
62204+ len >>= 2;
62205+ }
62206
62207 /* Don't cache excessive amounts of data and XDR failures */
62208 if (!statp || len > (256 >> 2)) {
62209diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62210index eea5ad1..5a84ac7 100644
62211--- a/fs/nfsd/vfs.c
62212+++ b/fs/nfsd/vfs.c
62213@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62214 } else {
62215 oldfs = get_fs();
62216 set_fs(KERNEL_DS);
62217- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62218+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62219 set_fs(oldfs);
62220 }
62221
62222@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62223
62224 /* Write the data. */
62225 oldfs = get_fs(); set_fs(KERNEL_DS);
62226- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62227+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62228 set_fs(oldfs);
62229 if (host_err < 0)
62230 goto out_nfserr;
62231@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62232 */
62233
62234 oldfs = get_fs(); set_fs(KERNEL_DS);
62235- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62236+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62237 set_fs(oldfs);
62238
62239 if (host_err < 0)
62240diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62241index 52ccd34..43a53b1 100644
62242--- a/fs/nls/nls_base.c
62243+++ b/fs/nls/nls_base.c
62244@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62245
62246 int __register_nls(struct nls_table *nls, struct module *owner)
62247 {
62248- struct nls_table ** tmp = &tables;
62249+ struct nls_table *tmp = tables;
62250
62251 if (nls->next)
62252 return -EBUSY;
62253
62254- nls->owner = owner;
62255+ pax_open_kernel();
62256+ *(void **)&nls->owner = owner;
62257+ pax_close_kernel();
62258 spin_lock(&nls_lock);
62259- while (*tmp) {
62260- if (nls == *tmp) {
62261+ while (tmp) {
62262+ if (nls == tmp) {
62263 spin_unlock(&nls_lock);
62264 return -EBUSY;
62265 }
62266- tmp = &(*tmp)->next;
62267+ tmp = tmp->next;
62268 }
62269- nls->next = tables;
62270+ pax_open_kernel();
62271+ *(struct nls_table **)&nls->next = tables;
62272+ pax_close_kernel();
62273 tables = nls;
62274 spin_unlock(&nls_lock);
62275 return 0;
62276@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62277
62278 int unregister_nls(struct nls_table * nls)
62279 {
62280- struct nls_table ** tmp = &tables;
62281+ struct nls_table * const * tmp = &tables;
62282
62283 spin_lock(&nls_lock);
62284 while (*tmp) {
62285 if (nls == *tmp) {
62286- *tmp = nls->next;
62287+ pax_open_kernel();
62288+ *(struct nls_table **)tmp = nls->next;
62289+ pax_close_kernel();
62290 spin_unlock(&nls_lock);
62291 return 0;
62292 }
62293diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62294index 162b3f1..6076a7c 100644
62295--- a/fs/nls/nls_euc-jp.c
62296+++ b/fs/nls/nls_euc-jp.c
62297@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62298 p_nls = load_nls("cp932");
62299
62300 if (p_nls) {
62301- table.charset2upper = p_nls->charset2upper;
62302- table.charset2lower = p_nls->charset2lower;
62303+ pax_open_kernel();
62304+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62305+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62306+ pax_close_kernel();
62307 return register_nls(&table);
62308 }
62309
62310diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62311index a80a741..7b96e1b 100644
62312--- a/fs/nls/nls_koi8-ru.c
62313+++ b/fs/nls/nls_koi8-ru.c
62314@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62315 p_nls = load_nls("koi8-u");
62316
62317 if (p_nls) {
62318- table.charset2upper = p_nls->charset2upper;
62319- table.charset2lower = p_nls->charset2lower;
62320+ pax_open_kernel();
62321+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62322+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62323+ pax_close_kernel();
62324 return register_nls(&table);
62325 }
62326
62327diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62328index 287a22c..4e56e4e 100644
62329--- a/fs/notify/fanotify/fanotify_user.c
62330+++ b/fs/notify/fanotify/fanotify_user.c
62331@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62332
62333 fd = fanotify_event_metadata.fd;
62334 ret = -EFAULT;
62335- if (copy_to_user(buf, &fanotify_event_metadata,
62336- fanotify_event_metadata.event_len))
62337+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62338+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62339 goto out_close_fd;
62340
62341 ret = prepare_for_access_response(group, event, fd);
62342@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62343 oevent->path.mnt = NULL;
62344 oevent->path.dentry = NULL;
62345
62346+ if (force_o_largefile())
62347+ event_f_flags |= O_LARGEFILE;
62348 group->fanotify_data.f_flags = event_f_flags;
62349 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62350 oevent->response = 0;
62351diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62352index 1e58402..bb2d6f4 100644
62353--- a/fs/notify/notification.c
62354+++ b/fs/notify/notification.c
62355@@ -48,7 +48,7 @@
62356 #include <linux/fsnotify_backend.h>
62357 #include "fsnotify.h"
62358
62359-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62360+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62361
62362 /**
62363 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62364@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62365 */
62366 u32 fsnotify_get_cookie(void)
62367 {
62368- return atomic_inc_return(&fsnotify_sync_cookie);
62369+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62370 }
62371 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62372
62373diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62374index 9e38daf..5727cae 100644
62375--- a/fs/ntfs/dir.c
62376+++ b/fs/ntfs/dir.c
62377@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62378 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62379 ~(s64)(ndir->itype.index.block_size - 1)));
62380 /* Bounds checks. */
62381- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62382+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62383 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62384 "inode 0x%lx or driver bug.", vdir->i_ino);
62385 goto err_out;
62386diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62387index db9bd8a..8338fb6 100644
62388--- a/fs/ntfs/file.c
62389+++ b/fs/ntfs/file.c
62390@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62391 char *addr;
62392 size_t total = 0;
62393 unsigned len;
62394- int left;
62395+ unsigned left;
62396
62397 do {
62398 len = PAGE_CACHE_SIZE - ofs;
62399diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62400index 82650d5..db37dcf 100644
62401--- a/fs/ntfs/super.c
62402+++ b/fs/ntfs/super.c
62403@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62404 if (!silent)
62405 ntfs_error(sb, "Primary boot sector is invalid.");
62406 } else if (!silent)
62407- ntfs_error(sb, read_err_str, "primary");
62408+ ntfs_error(sb, read_err_str, "%s", "primary");
62409 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62410 if (bh_primary)
62411 brelse(bh_primary);
62412@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62413 goto hotfix_primary_boot_sector;
62414 brelse(bh_backup);
62415 } else if (!silent)
62416- ntfs_error(sb, read_err_str, "backup");
62417+ ntfs_error(sb, read_err_str, "%s", "backup");
62418 /* Try to read NT3.51- backup boot sector. */
62419 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62420 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62421@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62422 "sector.");
62423 brelse(bh_backup);
62424 } else if (!silent)
62425- ntfs_error(sb, read_err_str, "backup");
62426+ ntfs_error(sb, read_err_str, "%s", "backup");
62427 /* We failed. Cleanup and return. */
62428 if (bh_primary)
62429 brelse(bh_primary);
62430diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62431index 0440134..d52c93a 100644
62432--- a/fs/ocfs2/localalloc.c
62433+++ b/fs/ocfs2/localalloc.c
62434@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62435 goto bail;
62436 }
62437
62438- atomic_inc(&osb->alloc_stats.moves);
62439+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62440
62441 bail:
62442 if (handle)
62443diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62444index 553f53c..aaf5133 100644
62445--- a/fs/ocfs2/ocfs2.h
62446+++ b/fs/ocfs2/ocfs2.h
62447@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62448
62449 struct ocfs2_alloc_stats
62450 {
62451- atomic_t moves;
62452- atomic_t local_data;
62453- atomic_t bitmap_data;
62454- atomic_t bg_allocs;
62455- atomic_t bg_extends;
62456+ atomic_unchecked_t moves;
62457+ atomic_unchecked_t local_data;
62458+ atomic_unchecked_t bitmap_data;
62459+ atomic_unchecked_t bg_allocs;
62460+ atomic_unchecked_t bg_extends;
62461 };
62462
62463 enum ocfs2_local_alloc_state
62464diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62465index 47ae266..6e8b793 100644
62466--- a/fs/ocfs2/suballoc.c
62467+++ b/fs/ocfs2/suballoc.c
62468@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62469 mlog_errno(status);
62470 goto bail;
62471 }
62472- atomic_inc(&osb->alloc_stats.bg_extends);
62473+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62474
62475 /* You should never ask for this much metadata */
62476 BUG_ON(bits_wanted >
62477@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62478 mlog_errno(status);
62479 goto bail;
62480 }
62481- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62482+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62483
62484 *suballoc_loc = res.sr_bg_blkno;
62485 *suballoc_bit_start = res.sr_bit_offset;
62486@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62487 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62488 res->sr_bits);
62489
62490- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62491+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62492
62493 BUG_ON(res->sr_bits != 1);
62494
62495@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62496 mlog_errno(status);
62497 goto bail;
62498 }
62499- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62500+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62501
62502 BUG_ON(res.sr_bits != 1);
62503
62504@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62505 cluster_start,
62506 num_clusters);
62507 if (!status)
62508- atomic_inc(&osb->alloc_stats.local_data);
62509+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62510 } else {
62511 if (min_clusters > (osb->bitmap_cpg - 1)) {
62512 /* The only paths asking for contiguousness
62513@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62514 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62515 res.sr_bg_blkno,
62516 res.sr_bit_offset);
62517- atomic_inc(&osb->alloc_stats.bitmap_data);
62518+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62519 *num_clusters = res.sr_bits;
62520 }
62521 }
62522diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62523index 49d84f8..4807e0b 100644
62524--- a/fs/ocfs2/super.c
62525+++ b/fs/ocfs2/super.c
62526@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62527 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62528 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62529 "Stats",
62530- atomic_read(&osb->alloc_stats.bitmap_data),
62531- atomic_read(&osb->alloc_stats.local_data),
62532- atomic_read(&osb->alloc_stats.bg_allocs),
62533- atomic_read(&osb->alloc_stats.moves),
62534- atomic_read(&osb->alloc_stats.bg_extends));
62535+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62536+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62537+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62538+ atomic_read_unchecked(&osb->alloc_stats.moves),
62539+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62540
62541 out += snprintf(buf + out, len - out,
62542 "%10s => State: %u Descriptor: %llu Size: %u bits "
62543@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62544 spin_lock_init(&osb->osb_xattr_lock);
62545 ocfs2_init_steal_slots(osb);
62546
62547- atomic_set(&osb->alloc_stats.moves, 0);
62548- atomic_set(&osb->alloc_stats.local_data, 0);
62549- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62550- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62551- atomic_set(&osb->alloc_stats.bg_extends, 0);
62552+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62553+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62554+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62555+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62556+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62557
62558 /* Copy the blockcheck stats from the superblock probe */
62559 osb->osb_ecc_stats = *stats;
62560diff --git a/fs/open.c b/fs/open.c
62561index b9ed8b2..0d5c7a0 100644
62562--- a/fs/open.c
62563+++ b/fs/open.c
62564@@ -32,6 +32,8 @@
62565 #include <linux/dnotify.h>
62566 #include <linux/compat.h>
62567
62568+#define CREATE_TRACE_POINTS
62569+#include <trace/events/fs.h>
62570 #include "internal.h"
62571
62572 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62573@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62574 error = locks_verify_truncate(inode, NULL, length);
62575 if (!error)
62576 error = security_path_truncate(path);
62577+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62578+ error = -EACCES;
62579 if (!error)
62580 error = do_truncate(path->dentry, length, 0, NULL);
62581
62582@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62583 error = locks_verify_truncate(inode, f.file, length);
62584 if (!error)
62585 error = security_path_truncate(&f.file->f_path);
62586+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62587+ error = -EACCES;
62588 if (!error)
62589 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62590 sb_end_write(inode->i_sb);
62591@@ -361,6 +367,9 @@ retry:
62592 if (__mnt_is_readonly(path.mnt))
62593 res = -EROFS;
62594
62595+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62596+ res = -EACCES;
62597+
62598 out_path_release:
62599 path_put(&path);
62600 if (retry_estale(res, lookup_flags)) {
62601@@ -392,6 +401,8 @@ retry:
62602 if (error)
62603 goto dput_and_out;
62604
62605+ gr_log_chdir(path.dentry, path.mnt);
62606+
62607 set_fs_pwd(current->fs, &path);
62608
62609 dput_and_out:
62610@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62611 goto out_putf;
62612
62613 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62614+
62615+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62616+ error = -EPERM;
62617+
62618+ if (!error)
62619+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62620+
62621 if (!error)
62622 set_fs_pwd(current->fs, &f.file->f_path);
62623 out_putf:
62624@@ -450,7 +468,13 @@ retry:
62625 if (error)
62626 goto dput_and_out;
62627
62628+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62629+ goto dput_and_out;
62630+
62631 set_fs_root(current->fs, &path);
62632+
62633+ gr_handle_chroot_chdir(&path);
62634+
62635 error = 0;
62636 dput_and_out:
62637 path_put(&path);
62638@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62639 return error;
62640 retry_deleg:
62641 mutex_lock(&inode->i_mutex);
62642+
62643+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62644+ error = -EACCES;
62645+ goto out_unlock;
62646+ }
62647+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62648+ error = -EACCES;
62649+ goto out_unlock;
62650+ }
62651+
62652 error = security_path_chmod(path, mode);
62653 if (error)
62654 goto out_unlock;
62655@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62656 uid = make_kuid(current_user_ns(), user);
62657 gid = make_kgid(current_user_ns(), group);
62658
62659+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62660+ return -EACCES;
62661+
62662 newattrs.ia_valid = ATTR_CTIME;
62663 if (user != (uid_t) -1) {
62664 if (!uid_valid(uid))
62665@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62666 } else {
62667 fsnotify_open(f);
62668 fd_install(fd, f);
62669+ trace_do_sys_open(tmp->name, flags, mode);
62670 }
62671 }
62672 putname(tmp);
62673diff --git a/fs/pipe.c b/fs/pipe.c
62674index 78fd0d0..f71fc09 100644
62675--- a/fs/pipe.c
62676+++ b/fs/pipe.c
62677@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62678
62679 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62680 {
62681- if (pipe->files)
62682+ if (atomic_read(&pipe->files))
62683 mutex_lock_nested(&pipe->mutex, subclass);
62684 }
62685
62686@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62687
62688 void pipe_unlock(struct pipe_inode_info *pipe)
62689 {
62690- if (pipe->files)
62691+ if (atomic_read(&pipe->files))
62692 mutex_unlock(&pipe->mutex);
62693 }
62694 EXPORT_SYMBOL(pipe_unlock);
62695@@ -449,9 +449,9 @@ redo:
62696 }
62697 if (bufs) /* More to do? */
62698 continue;
62699- if (!pipe->writers)
62700+ if (!atomic_read(&pipe->writers))
62701 break;
62702- if (!pipe->waiting_writers) {
62703+ if (!atomic_read(&pipe->waiting_writers)) {
62704 /* syscall merging: Usually we must not sleep
62705 * if O_NONBLOCK is set, or if we got some data.
62706 * But if a writer sleeps in kernel space, then
62707@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62708 ret = 0;
62709 __pipe_lock(pipe);
62710
62711- if (!pipe->readers) {
62712+ if (!atomic_read(&pipe->readers)) {
62713 send_sig(SIGPIPE, current, 0);
62714 ret = -EPIPE;
62715 goto out;
62716@@ -562,7 +562,7 @@ redo1:
62717 for (;;) {
62718 int bufs;
62719
62720- if (!pipe->readers) {
62721+ if (!atomic_read(&pipe->readers)) {
62722 send_sig(SIGPIPE, current, 0);
62723 if (!ret)
62724 ret = -EPIPE;
62725@@ -653,9 +653,9 @@ redo2:
62726 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62727 do_wakeup = 0;
62728 }
62729- pipe->waiting_writers++;
62730+ atomic_inc(&pipe->waiting_writers);
62731 pipe_wait(pipe);
62732- pipe->waiting_writers--;
62733+ atomic_dec(&pipe->waiting_writers);
62734 }
62735 out:
62736 __pipe_unlock(pipe);
62737@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62738 mask = 0;
62739 if (filp->f_mode & FMODE_READ) {
62740 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62741- if (!pipe->writers && filp->f_version != pipe->w_counter)
62742+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62743 mask |= POLLHUP;
62744 }
62745
62746@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62747 * Most Unices do not set POLLERR for FIFOs but on Linux they
62748 * behave exactly like pipes for poll().
62749 */
62750- if (!pipe->readers)
62751+ if (!atomic_read(&pipe->readers))
62752 mask |= POLLERR;
62753 }
62754
62755@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62756 int kill = 0;
62757
62758 spin_lock(&inode->i_lock);
62759- if (!--pipe->files) {
62760+ if (atomic_dec_and_test(&pipe->files)) {
62761 inode->i_pipe = NULL;
62762 kill = 1;
62763 }
62764@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62765
62766 __pipe_lock(pipe);
62767 if (file->f_mode & FMODE_READ)
62768- pipe->readers--;
62769+ atomic_dec(&pipe->readers);
62770 if (file->f_mode & FMODE_WRITE)
62771- pipe->writers--;
62772+ atomic_dec(&pipe->writers);
62773
62774- if (pipe->readers || pipe->writers) {
62775+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62776 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62777 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62778 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62779@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62780 kfree(pipe);
62781 }
62782
62783-static struct vfsmount *pipe_mnt __read_mostly;
62784+struct vfsmount *pipe_mnt __read_mostly;
62785
62786 /*
62787 * pipefs_dname() is called from d_path().
62788@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62789 goto fail_iput;
62790
62791 inode->i_pipe = pipe;
62792- pipe->files = 2;
62793- pipe->readers = pipe->writers = 1;
62794+ atomic_set(&pipe->files, 2);
62795+ atomic_set(&pipe->readers, 1);
62796+ atomic_set(&pipe->writers, 1);
62797 inode->i_fop = &pipefifo_fops;
62798
62799 /*
62800@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62801 spin_lock(&inode->i_lock);
62802 if (inode->i_pipe) {
62803 pipe = inode->i_pipe;
62804- pipe->files++;
62805+ atomic_inc(&pipe->files);
62806 spin_unlock(&inode->i_lock);
62807 } else {
62808 spin_unlock(&inode->i_lock);
62809 pipe = alloc_pipe_info();
62810 if (!pipe)
62811 return -ENOMEM;
62812- pipe->files = 1;
62813+ atomic_set(&pipe->files, 1);
62814 spin_lock(&inode->i_lock);
62815 if (unlikely(inode->i_pipe)) {
62816- inode->i_pipe->files++;
62817+ atomic_inc(&inode->i_pipe->files);
62818 spin_unlock(&inode->i_lock);
62819 free_pipe_info(pipe);
62820 pipe = inode->i_pipe;
62821@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62822 * opened, even when there is no process writing the FIFO.
62823 */
62824 pipe->r_counter++;
62825- if (pipe->readers++ == 0)
62826+ if (atomic_inc_return(&pipe->readers) == 1)
62827 wake_up_partner(pipe);
62828
62829- if (!is_pipe && !pipe->writers) {
62830+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62831 if ((filp->f_flags & O_NONBLOCK)) {
62832 /* suppress POLLHUP until we have
62833 * seen a writer */
62834@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62835 * errno=ENXIO when there is no process reading the FIFO.
62836 */
62837 ret = -ENXIO;
62838- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62839+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62840 goto err;
62841
62842 pipe->w_counter++;
62843- if (!pipe->writers++)
62844+ if (atomic_inc_return(&pipe->writers) == 1)
62845 wake_up_partner(pipe);
62846
62847- if (!is_pipe && !pipe->readers) {
62848+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62849 if (wait_for_partner(pipe, &pipe->r_counter))
62850 goto err_wr;
62851 }
62852@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62853 * the process can at least talk to itself.
62854 */
62855
62856- pipe->readers++;
62857- pipe->writers++;
62858+ atomic_inc(&pipe->readers);
62859+ atomic_inc(&pipe->writers);
62860 pipe->r_counter++;
62861 pipe->w_counter++;
62862- if (pipe->readers == 1 || pipe->writers == 1)
62863+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62864 wake_up_partner(pipe);
62865 break;
62866
62867@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62868 return 0;
62869
62870 err_rd:
62871- if (!--pipe->readers)
62872+ if (atomic_dec_and_test(&pipe->readers))
62873 wake_up_interruptible(&pipe->wait);
62874 ret = -ERESTARTSYS;
62875 goto err;
62876
62877 err_wr:
62878- if (!--pipe->writers)
62879+ if (atomic_dec_and_test(&pipe->writers))
62880 wake_up_interruptible(&pipe->wait);
62881 ret = -ERESTARTSYS;
62882 goto err;
62883diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62884index 9e363e4..d936d15 100644
62885--- a/fs/posix_acl.c
62886+++ b/fs/posix_acl.c
62887@@ -20,6 +20,7 @@
62888 #include <linux/xattr.h>
62889 #include <linux/export.h>
62890 #include <linux/user_namespace.h>
62891+#include <linux/grsecurity.h>
62892
62893 struct posix_acl **acl_by_type(struct inode *inode, int type)
62894 {
62895@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62896 }
62897 }
62898 if (mode_p)
62899- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62900+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62901 return not_equiv;
62902 }
62903 EXPORT_SYMBOL(posix_acl_equiv_mode);
62904@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62905 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62906 }
62907
62908- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62909+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62910 return not_equiv;
62911 }
62912
62913@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62914 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62915 int err = -ENOMEM;
62916 if (clone) {
62917+ *mode_p &= ~gr_acl_umask();
62918+
62919 err = posix_acl_create_masq(clone, mode_p);
62920 if (err < 0) {
62921 posix_acl_release(clone);
62922@@ -653,11 +656,12 @@ struct posix_acl *
62923 posix_acl_from_xattr(struct user_namespace *user_ns,
62924 const void *value, size_t size)
62925 {
62926- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62927- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62928+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62929+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62930 int count;
62931 struct posix_acl *acl;
62932 struct posix_acl_entry *acl_e;
62933+ umode_t umask = gr_acl_umask();
62934
62935 if (!value)
62936 return NULL;
62937@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62938
62939 switch(acl_e->e_tag) {
62940 case ACL_USER_OBJ:
62941+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62942+ break;
62943 case ACL_GROUP_OBJ:
62944 case ACL_MASK:
62945+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62946+ break;
62947 case ACL_OTHER:
62948+ acl_e->e_perm &= ~(umask & S_IRWXO);
62949 break;
62950
62951 case ACL_USER:
62952+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62953 acl_e->e_uid =
62954 make_kuid(user_ns,
62955 le32_to_cpu(entry->e_id));
62956@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62957 goto fail;
62958 break;
62959 case ACL_GROUP:
62960+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62961 acl_e->e_gid =
62962 make_kgid(user_ns,
62963 le32_to_cpu(entry->e_id));
62964diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62965index 2183fcf..3c32a98 100644
62966--- a/fs/proc/Kconfig
62967+++ b/fs/proc/Kconfig
62968@@ -30,7 +30,7 @@ config PROC_FS
62969
62970 config PROC_KCORE
62971 bool "/proc/kcore support" if !ARM
62972- depends on PROC_FS && MMU
62973+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62974 help
62975 Provides a virtual ELF core file of the live kernel. This can
62976 be read with gdb and other ELF tools. No modifications can be
62977@@ -38,8 +38,8 @@ config PROC_KCORE
62978
62979 config PROC_VMCORE
62980 bool "/proc/vmcore support"
62981- depends on PROC_FS && CRASH_DUMP
62982- default y
62983+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62984+ default n
62985 help
62986 Exports the dump image of crashed kernel in ELF format.
62987
62988@@ -63,8 +63,8 @@ config PROC_SYSCTL
62989 limited in memory.
62990
62991 config PROC_PAGE_MONITOR
62992- default y
62993- depends on PROC_FS && MMU
62994+ default n
62995+ depends on PROC_FS && MMU && !GRKERNSEC
62996 bool "Enable /proc page monitoring" if EXPERT
62997 help
62998 Various /proc files exist to monitor process memory utilization:
62999diff --git a/fs/proc/array.c b/fs/proc/array.c
63000index 656e401..b5b86b9 100644
63001--- a/fs/proc/array.c
63002+++ b/fs/proc/array.c
63003@@ -60,6 +60,7 @@
63004 #include <linux/tty.h>
63005 #include <linux/string.h>
63006 #include <linux/mman.h>
63007+#include <linux/grsecurity.h>
63008 #include <linux/proc_fs.h>
63009 #include <linux/ioport.h>
63010 #include <linux/uaccess.h>
63011@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63012 seq_putc(m, '\n');
63013 }
63014
63015+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63016+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63017+{
63018+ if (p->mm)
63019+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63020+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63021+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63022+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63023+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63024+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63025+ else
63026+ seq_printf(m, "PaX:\t-----\n");
63027+}
63028+#endif
63029+
63030 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63031 struct pid *pid, struct task_struct *task)
63032 {
63033@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63034 task_cpus_allowed(m, task);
63035 cpuset_task_status_allowed(m, task);
63036 task_context_switch_counts(m, task);
63037+
63038+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63039+ task_pax(m, task);
63040+#endif
63041+
63042+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63043+ task_grsec_rbac(m, task);
63044+#endif
63045+
63046 return 0;
63047 }
63048
63049+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63050+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63051+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63052+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63053+#endif
63054+
63055 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63056 struct pid *pid, struct task_struct *task, int whole)
63057 {
63058@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63059 char tcomm[sizeof(task->comm)];
63060 unsigned long flags;
63061
63062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63063+ if (current->exec_id != m->exec_id) {
63064+ gr_log_badprocpid("stat");
63065+ return 0;
63066+ }
63067+#endif
63068+
63069 state = *get_task_state(task);
63070 vsize = eip = esp = 0;
63071 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63072@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63073 gtime = task_gtime(task);
63074 }
63075
63076+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63077+ if (PAX_RAND_FLAGS(mm)) {
63078+ eip = 0;
63079+ esp = 0;
63080+ wchan = 0;
63081+ }
63082+#endif
63083+#ifdef CONFIG_GRKERNSEC_HIDESYM
63084+ wchan = 0;
63085+ eip =0;
63086+ esp =0;
63087+#endif
63088+
63089 /* scale priority and nice values from timeslices to -20..20 */
63090 /* to make it look like a "normal" Unix priority/nice value */
63091 priority = task_prio(task);
63092@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63093 seq_put_decimal_ull(m, ' ', vsize);
63094 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63095 seq_put_decimal_ull(m, ' ', rsslim);
63096+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63097+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63098+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63099+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63100+#else
63101 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63102 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63103 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63104+#endif
63105 seq_put_decimal_ull(m, ' ', esp);
63106 seq_put_decimal_ull(m, ' ', eip);
63107 /* The signal information here is obsolete.
63108@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63109 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63110 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63111
63112- if (mm && permitted) {
63113+ if (mm && permitted
63114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63115+ && !PAX_RAND_FLAGS(mm)
63116+#endif
63117+ ) {
63118 seq_put_decimal_ull(m, ' ', mm->start_data);
63119 seq_put_decimal_ull(m, ' ', mm->end_data);
63120 seq_put_decimal_ull(m, ' ', mm->start_brk);
63121@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63122 struct pid *pid, struct task_struct *task)
63123 {
63124 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63125- struct mm_struct *mm = get_task_mm(task);
63126+ struct mm_struct *mm;
63127
63128+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63129+ if (current->exec_id != m->exec_id) {
63130+ gr_log_badprocpid("statm");
63131+ return 0;
63132+ }
63133+#endif
63134+ mm = get_task_mm(task);
63135 if (mm) {
63136 size = task_statm(mm, &shared, &text, &data, &resident);
63137 mmput(mm);
63138@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63139 return 0;
63140 }
63141
63142+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63143+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63144+{
63145+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63146+}
63147+#endif
63148+
63149 #ifdef CONFIG_CHECKPOINT_RESTORE
63150 static struct pid *
63151 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63152diff --git a/fs/proc/base.c b/fs/proc/base.c
63153index b976062..584d0bc 100644
63154--- a/fs/proc/base.c
63155+++ b/fs/proc/base.c
63156@@ -113,6 +113,14 @@ struct pid_entry {
63157 union proc_op op;
63158 };
63159
63160+struct getdents_callback {
63161+ struct linux_dirent __user * current_dir;
63162+ struct linux_dirent __user * previous;
63163+ struct file * file;
63164+ int count;
63165+ int error;
63166+};
63167+
63168 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63169 .name = (NAME), \
63170 .len = sizeof(NAME) - 1, \
63171@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63172 if (!mm->arg_end)
63173 goto out_mm; /* Shh! No looking before we're done */
63174
63175+ if (gr_acl_handle_procpidmem(task))
63176+ goto out_mm;
63177+
63178 len = mm->arg_end - mm->arg_start;
63179
63180 if (len > PAGE_SIZE)
63181@@ -237,12 +248,28 @@ out:
63182 return res;
63183 }
63184
63185+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63186+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63187+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63188+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63189+#endif
63190+
63191 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63192 {
63193 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63194 int res = PTR_ERR(mm);
63195 if (mm && !IS_ERR(mm)) {
63196 unsigned int nwords = 0;
63197+
63198+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63199+ /* allow if we're currently ptracing this task */
63200+ if (PAX_RAND_FLAGS(mm) &&
63201+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63202+ mmput(mm);
63203+ return 0;
63204+ }
63205+#endif
63206+
63207 do {
63208 nwords += 2;
63209 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63210@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63211 }
63212
63213
63214-#ifdef CONFIG_KALLSYMS
63215+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63216 /*
63217 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63218 * Returns the resolved symbol. If that fails, simply return the address.
63219@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63220 mutex_unlock(&task->signal->cred_guard_mutex);
63221 }
63222
63223-#ifdef CONFIG_STACKTRACE
63224+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63225
63226 #define MAX_STACK_TRACE_DEPTH 64
63227
63228@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63229 return count;
63230 }
63231
63232-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63233+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63234 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63235 {
63236 long nr;
63237@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63238 /************************************************************************/
63239
63240 /* permission checks */
63241-static int proc_fd_access_allowed(struct inode *inode)
63242+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63243 {
63244 struct task_struct *task;
63245 int allowed = 0;
63246@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63247 */
63248 task = get_proc_task(inode);
63249 if (task) {
63250- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63251+ if (log)
63252+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63253+ else
63254+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63255 put_task_struct(task);
63256 }
63257 return allowed;
63258@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63259 struct task_struct *task,
63260 int hide_pid_min)
63261 {
63262+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63263+ return false;
63264+
63265+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63266+ rcu_read_lock();
63267+ {
63268+ const struct cred *tmpcred = current_cred();
63269+ const struct cred *cred = __task_cred(task);
63270+
63271+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63272+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63273+ || in_group_p(grsec_proc_gid)
63274+#endif
63275+ ) {
63276+ rcu_read_unlock();
63277+ return true;
63278+ }
63279+ }
63280+ rcu_read_unlock();
63281+
63282+ if (!pid->hide_pid)
63283+ return false;
63284+#endif
63285+
63286 if (pid->hide_pid < hide_pid_min)
63287 return true;
63288 if (in_group_p(pid->pid_gid))
63289 return true;
63290+
63291 return ptrace_may_access(task, PTRACE_MODE_READ);
63292 }
63293
63294@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63295 put_task_struct(task);
63296
63297 if (!has_perms) {
63298+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63299+ {
63300+#else
63301 if (pid->hide_pid == 2) {
63302+#endif
63303 /*
63304 * Let's make getdents(), stat(), and open()
63305 * consistent with each other. If a process
63306@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63307 if (!task)
63308 return -ESRCH;
63309
63310+ if (gr_acl_handle_procpidmem(task)) {
63311+ put_task_struct(task);
63312+ return -EPERM;
63313+ }
63314+
63315 mm = mm_access(task, mode);
63316 put_task_struct(task);
63317
63318@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63319
63320 file->private_data = mm;
63321
63322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63323+ file->f_version = current->exec_id;
63324+#endif
63325+
63326 return 0;
63327 }
63328
63329@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63330 ssize_t copied;
63331 char *page;
63332
63333+#ifdef CONFIG_GRKERNSEC
63334+ if (write)
63335+ return -EPERM;
63336+#endif
63337+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63338+ if (file->f_version != current->exec_id) {
63339+ gr_log_badprocpid("mem");
63340+ return 0;
63341+ }
63342+#endif
63343+
63344 if (!mm)
63345 return 0;
63346
63347@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63348 goto free;
63349
63350 while (count > 0) {
63351- int this_len = min_t(int, count, PAGE_SIZE);
63352+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63353
63354 if (write && copy_from_user(page, buf, this_len)) {
63355 copied = -EFAULT;
63356@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63357 if (!mm)
63358 return 0;
63359
63360+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63361+ if (file->f_version != current->exec_id) {
63362+ gr_log_badprocpid("environ");
63363+ return 0;
63364+ }
63365+#endif
63366+
63367 page = (char *)__get_free_page(GFP_TEMPORARY);
63368 if (!page)
63369 return -ENOMEM;
63370@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63371 goto free;
63372 while (count > 0) {
63373 size_t this_len, max_len;
63374- int retval;
63375+ ssize_t retval;
63376
63377 if (src >= (mm->env_end - mm->env_start))
63378 break;
63379@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63380 int error = -EACCES;
63381
63382 /* Are we allowed to snoop on the tasks file descriptors? */
63383- if (!proc_fd_access_allowed(inode))
63384+ if (!proc_fd_access_allowed(inode, 0))
63385 goto out;
63386
63387 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63388@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63389 struct path path;
63390
63391 /* Are we allowed to snoop on the tasks file descriptors? */
63392- if (!proc_fd_access_allowed(inode))
63393- goto out;
63394+ /* logging this is needed for learning on chromium to work properly,
63395+ but we don't want to flood the logs from 'ps' which does a readlink
63396+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63397+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63398+ */
63399+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63400+ if (!proc_fd_access_allowed(inode,0))
63401+ goto out;
63402+ } else {
63403+ if (!proc_fd_access_allowed(inode,1))
63404+ goto out;
63405+ }
63406
63407 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63408 if (error)
63409@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63410 rcu_read_lock();
63411 cred = __task_cred(task);
63412 inode->i_uid = cred->euid;
63413+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63414+ inode->i_gid = grsec_proc_gid;
63415+#else
63416 inode->i_gid = cred->egid;
63417+#endif
63418 rcu_read_unlock();
63419 }
63420 security_task_to_inode(task, inode);
63421@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63422 return -ENOENT;
63423 }
63424 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63425+#ifdef CONFIG_GRKERNSEC_PROC_USER
63426+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63427+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63428+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63429+#endif
63430 task_dumpable(task)) {
63431 cred = __task_cred(task);
63432 stat->uid = cred->euid;
63433+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63434+ stat->gid = grsec_proc_gid;
63435+#else
63436 stat->gid = cred->egid;
63437+#endif
63438 }
63439 }
63440 rcu_read_unlock();
63441@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63442
63443 if (task) {
63444 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63445+#ifdef CONFIG_GRKERNSEC_PROC_USER
63446+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63447+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63448+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63449+#endif
63450 task_dumpable(task)) {
63451 rcu_read_lock();
63452 cred = __task_cred(task);
63453 inode->i_uid = cred->euid;
63454+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63455+ inode->i_gid = grsec_proc_gid;
63456+#else
63457 inode->i_gid = cred->egid;
63458+#endif
63459 rcu_read_unlock();
63460 } else {
63461 inode->i_uid = GLOBAL_ROOT_UID;
63462@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63463 if (!task)
63464 goto out_no_task;
63465
63466+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63467+ goto out;
63468+
63469 /*
63470 * Yes, it does not scale. And it should not. Don't add
63471 * new entries into /proc/<tgid>/ without very good reasons.
63472@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63473 if (!task)
63474 return -ENOENT;
63475
63476+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63477+ goto out;
63478+
63479 if (!dir_emit_dots(file, ctx))
63480 goto out;
63481
63482@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63483 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63484 #endif
63485 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63486-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63487+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63488 INF("syscall", S_IRUGO, proc_pid_syscall),
63489 #endif
63490 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63491@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63492 #ifdef CONFIG_SECURITY
63493 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63494 #endif
63495-#ifdef CONFIG_KALLSYMS
63496+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63497 INF("wchan", S_IRUGO, proc_pid_wchan),
63498 #endif
63499-#ifdef CONFIG_STACKTRACE
63500+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63501 ONE("stack", S_IRUGO, proc_pid_stack),
63502 #endif
63503 #ifdef CONFIG_SCHEDSTATS
63504@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63505 #ifdef CONFIG_HARDWALL
63506 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63507 #endif
63508+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63509+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63510+#endif
63511 #ifdef CONFIG_USER_NS
63512 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63513 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63514@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63515 if (!inode)
63516 goto out;
63517
63518+#ifdef CONFIG_GRKERNSEC_PROC_USER
63519+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63520+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63521+ inode->i_gid = grsec_proc_gid;
63522+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63523+#else
63524 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63525+#endif
63526 inode->i_op = &proc_tgid_base_inode_operations;
63527 inode->i_fop = &proc_tgid_base_operations;
63528 inode->i_flags|=S_IMMUTABLE;
63529@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63530 if (!task)
63531 goto out;
63532
63533+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63534+ goto out_put_task;
63535+
63536 result = proc_pid_instantiate(dir, dentry, task, NULL);
63537+out_put_task:
63538 put_task_struct(task);
63539 out:
63540 return ERR_PTR(result);
63541@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63542 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63543 #endif
63544 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63545-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63546+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63547 INF("syscall", S_IRUGO, proc_pid_syscall),
63548 #endif
63549 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63550@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63551 #ifdef CONFIG_SECURITY
63552 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63553 #endif
63554-#ifdef CONFIG_KALLSYMS
63555+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63556 INF("wchan", S_IRUGO, proc_pid_wchan),
63557 #endif
63558-#ifdef CONFIG_STACKTRACE
63559+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63560 ONE("stack", S_IRUGO, proc_pid_stack),
63561 #endif
63562 #ifdef CONFIG_SCHEDSTATS
63563diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63564index cbd82df..c0407d2 100644
63565--- a/fs/proc/cmdline.c
63566+++ b/fs/proc/cmdline.c
63567@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63568
63569 static int __init proc_cmdline_init(void)
63570 {
63571+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63572+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63573+#else
63574 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63575+#endif
63576 return 0;
63577 }
63578 fs_initcall(proc_cmdline_init);
63579diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63580index 50493ed..248166b 100644
63581--- a/fs/proc/devices.c
63582+++ b/fs/proc/devices.c
63583@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63584
63585 static int __init proc_devices_init(void)
63586 {
63587+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63588+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63589+#else
63590 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63591+#endif
63592 return 0;
63593 }
63594 fs_initcall(proc_devices_init);
63595diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63596index 985ea88..d118a0a 100644
63597--- a/fs/proc/fd.c
63598+++ b/fs/proc/fd.c
63599@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63600 if (!task)
63601 return -ENOENT;
63602
63603- files = get_files_struct(task);
63604+ if (!gr_acl_handle_procpidmem(task))
63605+ files = get_files_struct(task);
63606 put_task_struct(task);
63607
63608 if (files) {
63609@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63610 */
63611 int proc_fd_permission(struct inode *inode, int mask)
63612 {
63613+ struct task_struct *task;
63614 int rv = generic_permission(inode, mask);
63615- if (rv == 0)
63616- return 0;
63617+
63618 if (task_tgid(current) == proc_pid(inode))
63619 rv = 0;
63620+
63621+ task = get_proc_task(inode);
63622+ if (task == NULL)
63623+ return rv;
63624+
63625+ if (gr_acl_handle_procpidmem(task))
63626+ rv = -EACCES;
63627+
63628+ put_task_struct(task);
63629+
63630 return rv;
63631 }
63632
63633diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63634index b7f268e..3bea6b7 100644
63635--- a/fs/proc/generic.c
63636+++ b/fs/proc/generic.c
63637@@ -23,6 +23,7 @@
63638 #include <linux/bitops.h>
63639 #include <linux/spinlock.h>
63640 #include <linux/completion.h>
63641+#include <linux/grsecurity.h>
63642 #include <asm/uaccess.h>
63643
63644 #include "internal.h"
63645@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63646 return proc_lookup_de(PDE(dir), dir, dentry);
63647 }
63648
63649+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63650+ unsigned int flags)
63651+{
63652+ if (gr_proc_is_restricted())
63653+ return ERR_PTR(-EACCES);
63654+
63655+ return proc_lookup_de(PDE(dir), dir, dentry);
63656+}
63657+
63658 /*
63659 * This returns non-zero if at EOF, so that the /proc
63660 * root directory can use this and check if it should
63661@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63662 return proc_readdir_de(PDE(inode), file, ctx);
63663 }
63664
63665+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63666+{
63667+ struct inode *inode = file_inode(file);
63668+
63669+ if (gr_proc_is_restricted())
63670+ return -EACCES;
63671+
63672+ return proc_readdir_de(PDE(inode), file, ctx);
63673+}
63674+
63675 /*
63676 * These are the generic /proc directory operations. They
63677 * use the in-memory "struct proc_dir_entry" tree to parse
63678@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63679 .iterate = proc_readdir,
63680 };
63681
63682+static const struct file_operations proc_dir_restricted_operations = {
63683+ .llseek = generic_file_llseek,
63684+ .read = generic_read_dir,
63685+ .iterate = proc_readdir_restrict,
63686+};
63687+
63688 /*
63689 * proc directories can do almost nothing..
63690 */
63691@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63692 .setattr = proc_notify_change,
63693 };
63694
63695+static const struct inode_operations proc_dir_restricted_inode_operations = {
63696+ .lookup = proc_lookup_restrict,
63697+ .getattr = proc_getattr,
63698+ .setattr = proc_notify_change,
63699+};
63700+
63701 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63702 {
63703 struct proc_dir_entry *tmp;
63704@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63705 return ret;
63706
63707 if (S_ISDIR(dp->mode)) {
63708- dp->proc_fops = &proc_dir_operations;
63709- dp->proc_iops = &proc_dir_inode_operations;
63710+ if (dp->restricted) {
63711+ dp->proc_fops = &proc_dir_restricted_operations;
63712+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63713+ } else {
63714+ dp->proc_fops = &proc_dir_operations;
63715+ dp->proc_iops = &proc_dir_inode_operations;
63716+ }
63717 dir->nlink++;
63718 } else if (S_ISLNK(dp->mode)) {
63719 dp->proc_iops = &proc_link_inode_operations;
63720@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63721 }
63722 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63723
63724+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63725+ struct proc_dir_entry *parent, void *data)
63726+{
63727+ struct proc_dir_entry *ent;
63728+
63729+ if (mode == 0)
63730+ mode = S_IRUGO | S_IXUGO;
63731+
63732+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63733+ if (ent) {
63734+ ent->data = data;
63735+ ent->restricted = 1;
63736+ if (proc_register(parent, ent) < 0) {
63737+ kfree(ent);
63738+ ent = NULL;
63739+ }
63740+ }
63741+ return ent;
63742+}
63743+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63744+
63745 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63746 struct proc_dir_entry *parent)
63747 {
63748@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63749 }
63750 EXPORT_SYMBOL(proc_mkdir);
63751
63752+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63753+ struct proc_dir_entry *parent)
63754+{
63755+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63756+}
63757+EXPORT_SYMBOL(proc_mkdir_restrict);
63758+
63759 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63760 struct proc_dir_entry *parent,
63761 const struct file_operations *proc_fops,
63762diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63763index 124fc43..8afbb02 100644
63764--- a/fs/proc/inode.c
63765+++ b/fs/proc/inode.c
63766@@ -23,11 +23,17 @@
63767 #include <linux/slab.h>
63768 #include <linux/mount.h>
63769 #include <linux/magic.h>
63770+#include <linux/grsecurity.h>
63771
63772 #include <asm/uaccess.h>
63773
63774 #include "internal.h"
63775
63776+#ifdef CONFIG_PROC_SYSCTL
63777+extern const struct inode_operations proc_sys_inode_operations;
63778+extern const struct inode_operations proc_sys_dir_operations;
63779+#endif
63780+
63781 static void proc_evict_inode(struct inode *inode)
63782 {
63783 struct proc_dir_entry *de;
63784@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63785 ns = PROC_I(inode)->ns.ns;
63786 if (ns_ops && ns)
63787 ns_ops->put(ns);
63788+
63789+#ifdef CONFIG_PROC_SYSCTL
63790+ if (inode->i_op == &proc_sys_inode_operations ||
63791+ inode->i_op == &proc_sys_dir_operations)
63792+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63793+#endif
63794+
63795 }
63796
63797 static struct kmem_cache * proc_inode_cachep;
63798@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63799 if (de->mode) {
63800 inode->i_mode = de->mode;
63801 inode->i_uid = de->uid;
63802+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63803+ inode->i_gid = grsec_proc_gid;
63804+#else
63805 inode->i_gid = de->gid;
63806+#endif
63807 }
63808 if (de->size)
63809 inode->i_size = de->size;
63810diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63811index 651d09a..6a4b495 100644
63812--- a/fs/proc/internal.h
63813+++ b/fs/proc/internal.h
63814@@ -46,9 +46,10 @@ struct proc_dir_entry {
63815 struct completion *pde_unload_completion;
63816 struct list_head pde_openers; /* who did ->open, but not ->release */
63817 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63818+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63819 u8 namelen;
63820 char name[];
63821-};
63822+} __randomize_layout;
63823
63824 union proc_op {
63825 int (*proc_get_link)(struct dentry *, struct path *);
63826@@ -67,7 +68,7 @@ struct proc_inode {
63827 struct ctl_table *sysctl_entry;
63828 struct proc_ns ns;
63829 struct inode vfs_inode;
63830-};
63831+} __randomize_layout;
63832
63833 /*
63834 * General functions
63835@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63836 struct pid *, struct task_struct *);
63837 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63838 struct pid *, struct task_struct *);
63839+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63840+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63841+#endif
63842
63843 /*
63844 * base.c
63845@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63846 extern spinlock_t proc_subdir_lock;
63847
63848 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63849+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63850 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63851 struct dentry *);
63852 extern int proc_readdir(struct file *, struct dir_context *);
63853+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63854 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63855
63856 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63857diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63858index a352d57..cb94a5c 100644
63859--- a/fs/proc/interrupts.c
63860+++ b/fs/proc/interrupts.c
63861@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63862
63863 static int __init proc_interrupts_init(void)
63864 {
63865+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63866+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63867+#else
63868 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63869+#endif
63870 return 0;
63871 }
63872 fs_initcall(proc_interrupts_init);
63873diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63874index 39e6ef3..2f9cb5e 100644
63875--- a/fs/proc/kcore.c
63876+++ b/fs/proc/kcore.c
63877@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63878 * the addresses in the elf_phdr on our list.
63879 */
63880 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63881- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63882+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63883+ if (tsz > buflen)
63884 tsz = buflen;
63885-
63886+
63887 while (buflen) {
63888 struct kcore_list *m;
63889
63890@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63891 kfree(elf_buf);
63892 } else {
63893 if (kern_addr_valid(start)) {
63894- unsigned long n;
63895+ char *elf_buf;
63896+ mm_segment_t oldfs;
63897
63898- n = copy_to_user(buffer, (char *)start, tsz);
63899- /*
63900- * We cannot distinguish between fault on source
63901- * and fault on destination. When this happens
63902- * we clear too and hope it will trigger the
63903- * EFAULT again.
63904- */
63905- if (n) {
63906- if (clear_user(buffer + tsz - n,
63907- n))
63908+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63909+ if (!elf_buf)
63910+ return -ENOMEM;
63911+ oldfs = get_fs();
63912+ set_fs(KERNEL_DS);
63913+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63914+ set_fs(oldfs);
63915+ if (copy_to_user(buffer, elf_buf, tsz)) {
63916+ kfree(elf_buf);
63917 return -EFAULT;
63918+ }
63919 }
63920+ set_fs(oldfs);
63921+ kfree(elf_buf);
63922 } else {
63923 if (clear_user(buffer, tsz))
63924 return -EFAULT;
63925@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63926
63927 static int open_kcore(struct inode *inode, struct file *filp)
63928 {
63929+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63930+ return -EPERM;
63931+#endif
63932 if (!capable(CAP_SYS_RAWIO))
63933 return -EPERM;
63934 if (kcore_need_update)
63935diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63936index 136e548..1f88922 100644
63937--- a/fs/proc/meminfo.c
63938+++ b/fs/proc/meminfo.c
63939@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63940 vmi.used >> 10,
63941 vmi.largest_chunk >> 10
63942 #ifdef CONFIG_MEMORY_FAILURE
63943- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63944+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63945 #endif
63946 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63947 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63948diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63949index d4a3574..b421ce9 100644
63950--- a/fs/proc/nommu.c
63951+++ b/fs/proc/nommu.c
63952@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63953
63954 if (file) {
63955 seq_pad(m, ' ');
63956- seq_path(m, &file->f_path, "");
63957+ seq_path(m, &file->f_path, "\n\\");
63958 }
63959
63960 seq_putc(m, '\n');
63961diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63962index 4677bb7..94067cd 100644
63963--- a/fs/proc/proc_net.c
63964+++ b/fs/proc/proc_net.c
63965@@ -23,6 +23,7 @@
63966 #include <linux/nsproxy.h>
63967 #include <net/net_namespace.h>
63968 #include <linux/seq_file.h>
63969+#include <linux/grsecurity.h>
63970
63971 #include "internal.h"
63972
63973@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
63974 return maybe_get_net(PDE_NET(PDE(inode)));
63975 }
63976
63977+extern const struct seq_operations dev_seq_ops;
63978+
63979 int seq_open_net(struct inode *ino, struct file *f,
63980 const struct seq_operations *ops, int size)
63981 {
63982@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
63983
63984 BUG_ON(size < sizeof(*p));
63985
63986+ /* only permit access to /proc/net/dev */
63987+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
63988+ return -EACCES;
63989+
63990 net = get_proc_net(ino);
63991 if (net == NULL)
63992 return -ENXIO;
63993@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
63994 int err;
63995 struct net *net;
63996
63997+ if (gr_proc_is_restricted())
63998+ return -EACCES;
63999+
64000 err = -ENXIO;
64001 net = get_proc_net(inode);
64002 if (net == NULL)
64003diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64004index 7129046..6914844 100644
64005--- a/fs/proc/proc_sysctl.c
64006+++ b/fs/proc/proc_sysctl.c
64007@@ -11,13 +11,21 @@
64008 #include <linux/namei.h>
64009 #include <linux/mm.h>
64010 #include <linux/module.h>
64011+#include <linux/nsproxy.h>
64012+#ifdef CONFIG_GRKERNSEC
64013+#include <net/net_namespace.h>
64014+#endif
64015 #include "internal.h"
64016
64017+extern int gr_handle_chroot_sysctl(const int op);
64018+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64019+ const int op);
64020+
64021 static const struct dentry_operations proc_sys_dentry_operations;
64022 static const struct file_operations proc_sys_file_operations;
64023-static const struct inode_operations proc_sys_inode_operations;
64024+const struct inode_operations proc_sys_inode_operations;
64025 static const struct file_operations proc_sys_dir_file_operations;
64026-static const struct inode_operations proc_sys_dir_operations;
64027+const struct inode_operations proc_sys_dir_operations;
64028
64029 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64030 {
64031@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64032
64033 err = NULL;
64034 d_set_d_op(dentry, &proc_sys_dentry_operations);
64035+
64036+ gr_handle_proc_create(dentry, inode);
64037+
64038 d_add(dentry, inode);
64039
64040 out:
64041@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64042 struct inode *inode = file_inode(filp);
64043 struct ctl_table_header *head = grab_header(inode);
64044 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64045+ int op = write ? MAY_WRITE : MAY_READ;
64046 ssize_t error;
64047 size_t res;
64048
64049@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64050 * and won't be until we finish.
64051 */
64052 error = -EPERM;
64053- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64054+ if (sysctl_perm(head, table, op))
64055 goto out;
64056
64057 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64058@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64059 if (!table->proc_handler)
64060 goto out;
64061
64062+#ifdef CONFIG_GRKERNSEC
64063+ error = -EPERM;
64064+ if (gr_handle_chroot_sysctl(op))
64065+ goto out;
64066+ dget(filp->f_path.dentry);
64067+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64068+ dput(filp->f_path.dentry);
64069+ goto out;
64070+ }
64071+ dput(filp->f_path.dentry);
64072+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64073+ goto out;
64074+ if (write) {
64075+ if (current->nsproxy->net_ns != table->extra2) {
64076+ if (!capable(CAP_SYS_ADMIN))
64077+ goto out;
64078+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64079+ goto out;
64080+ }
64081+#endif
64082+
64083 /* careful: calling conventions are nasty here */
64084 res = count;
64085 error = table->proc_handler(table, write, buf, &res, ppos);
64086@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64087 return false;
64088 } else {
64089 d_set_d_op(child, &proc_sys_dentry_operations);
64090+
64091+ gr_handle_proc_create(child, inode);
64092+
64093 d_add(child, inode);
64094 }
64095 } else {
64096@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64097 if ((*pos)++ < ctx->pos)
64098 return true;
64099
64100+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64101+ return 0;
64102+
64103 if (unlikely(S_ISLNK(table->mode)))
64104 res = proc_sys_link_fill_cache(file, ctx, head, table);
64105 else
64106@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64107 if (IS_ERR(head))
64108 return PTR_ERR(head);
64109
64110+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64111+ return -ENOENT;
64112+
64113 generic_fillattr(inode, stat);
64114 if (table)
64115 stat->mode = (stat->mode & S_IFMT) | table->mode;
64116@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64117 .llseek = generic_file_llseek,
64118 };
64119
64120-static const struct inode_operations proc_sys_inode_operations = {
64121+const struct inode_operations proc_sys_inode_operations = {
64122 .permission = proc_sys_permission,
64123 .setattr = proc_sys_setattr,
64124 .getattr = proc_sys_getattr,
64125 };
64126
64127-static const struct inode_operations proc_sys_dir_operations = {
64128+const struct inode_operations proc_sys_dir_operations = {
64129 .lookup = proc_sys_lookup,
64130 .permission = proc_sys_permission,
64131 .setattr = proc_sys_setattr,
64132@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64133 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64134 const char *name, int namelen)
64135 {
64136- struct ctl_table *table;
64137+ ctl_table_no_const *table;
64138 struct ctl_dir *new;
64139 struct ctl_node *node;
64140 char *new_name;
64141@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64142 return NULL;
64143
64144 node = (struct ctl_node *)(new + 1);
64145- table = (struct ctl_table *)(node + 1);
64146+ table = (ctl_table_no_const *)(node + 1);
64147 new_name = (char *)(table + 2);
64148 memcpy(new_name, name, namelen);
64149 new_name[namelen] = '\0';
64150@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64151 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64152 struct ctl_table_root *link_root)
64153 {
64154- struct ctl_table *link_table, *entry, *link;
64155+ ctl_table_no_const *link_table, *link;
64156+ struct ctl_table *entry;
64157 struct ctl_table_header *links;
64158 struct ctl_node *node;
64159 char *link_name;
64160@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64161 return NULL;
64162
64163 node = (struct ctl_node *)(links + 1);
64164- link_table = (struct ctl_table *)(node + nr_entries);
64165+ link_table = (ctl_table_no_const *)(node + nr_entries);
64166 link_name = (char *)&link_table[nr_entries + 1];
64167
64168 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64169@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64170 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64171 struct ctl_table *table)
64172 {
64173- struct ctl_table *ctl_table_arg = NULL;
64174- struct ctl_table *entry, *files;
64175+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64176+ struct ctl_table *entry;
64177 int nr_files = 0;
64178 int nr_dirs = 0;
64179 int err = -ENOMEM;
64180@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64181 nr_files++;
64182 }
64183
64184- files = table;
64185 /* If there are mixed files and directories we need a new table */
64186 if (nr_dirs && nr_files) {
64187- struct ctl_table *new;
64188+ ctl_table_no_const *new;
64189 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64190 GFP_KERNEL);
64191 if (!files)
64192@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64193 /* Register everything except a directory full of subdirectories */
64194 if (nr_files || !nr_dirs) {
64195 struct ctl_table_header *header;
64196- header = __register_sysctl_table(set, path, files);
64197+ header = __register_sysctl_table(set, path, files ? files : table);
64198 if (!header) {
64199 kfree(ctl_table_arg);
64200 goto out;
64201diff --git a/fs/proc/root.c b/fs/proc/root.c
64202index 87dbcbe..55e1b4d 100644
64203--- a/fs/proc/root.c
64204+++ b/fs/proc/root.c
64205@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64206 #ifdef CONFIG_PROC_DEVICETREE
64207 proc_device_tree_init();
64208 #endif
64209+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64210+#ifdef CONFIG_GRKERNSEC_PROC_USER
64211+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64212+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64213+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64214+#endif
64215+#else
64216 proc_mkdir("bus", NULL);
64217+#endif
64218 proc_sys_init();
64219 }
64220
64221diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64222index 6f599c6..8f4644f 100644
64223--- a/fs/proc/stat.c
64224+++ b/fs/proc/stat.c
64225@@ -11,6 +11,7 @@
64226 #include <linux/irqnr.h>
64227 #include <asm/cputime.h>
64228 #include <linux/tick.h>
64229+#include <linux/grsecurity.h>
64230
64231 #ifndef arch_irq_stat_cpu
64232 #define arch_irq_stat_cpu(cpu) 0
64233@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64234 u64 sum_softirq = 0;
64235 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64236 struct timespec boottime;
64237+ int unrestricted = 1;
64238+
64239+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64240+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64241+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64242+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64243+ && !in_group_p(grsec_proc_gid)
64244+#endif
64245+ )
64246+ unrestricted = 0;
64247+#endif
64248+#endif
64249
64250 user = nice = system = idle = iowait =
64251 irq = softirq = steal = 0;
64252@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
64253 getboottime(&boottime);
64254 jif = boottime.tv_sec;
64255
64256+ if (unrestricted) {
64257 for_each_possible_cpu(i) {
64258 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
64259 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64260@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
64261 }
64262 }
64263 sum += arch_irq_stat();
64264+ }
64265
64266 seq_puts(p, "cpu ");
64267 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64268@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
64269 seq_putc(p, '\n');
64270
64271 for_each_online_cpu(i) {
64272+ if (unrestricted) {
64273 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
64274 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
64275 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64276@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
64277 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64278 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64279 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64280+ }
64281 seq_printf(p, "cpu%d", i);
64282 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64283 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64284@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64285
64286 /* sum again ? it could be updated? */
64287 for_each_irq_nr(j)
64288- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64289+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64290
64291 seq_printf(p,
64292 "\nctxt %llu\n"
64293@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64294 "processes %lu\n"
64295 "procs_running %lu\n"
64296 "procs_blocked %lu\n",
64297- nr_context_switches(),
64298+ unrestricted ? nr_context_switches() : 0ULL,
64299 (unsigned long)jif,
64300- total_forks,
64301- nr_running(),
64302- nr_iowait());
64303+ unrestricted ? total_forks : 0UL,
64304+ unrestricted ? nr_running() : 0UL,
64305+ unrestricted ? nr_iowait() : 0UL);
64306
64307 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64308
64309diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64310index fb52b54..5fc7c14 100644
64311--- a/fs/proc/task_mmu.c
64312+++ b/fs/proc/task_mmu.c
64313@@ -12,12 +12,19 @@
64314 #include <linux/swap.h>
64315 #include <linux/swapops.h>
64316 #include <linux/mmu_notifier.h>
64317+#include <linux/grsecurity.h>
64318
64319 #include <asm/elf.h>
64320 #include <asm/uaccess.h>
64321 #include <asm/tlbflush.h>
64322 #include "internal.h"
64323
64324+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64325+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64326+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64327+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64328+#endif
64329+
64330 void task_mem(struct seq_file *m, struct mm_struct *mm)
64331 {
64332 unsigned long data, text, lib, swap;
64333@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64334 "VmExe:\t%8lu kB\n"
64335 "VmLib:\t%8lu kB\n"
64336 "VmPTE:\t%8lu kB\n"
64337- "VmSwap:\t%8lu kB\n",
64338- hiwater_vm << (PAGE_SHIFT-10),
64339+ "VmSwap:\t%8lu kB\n"
64340+
64341+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64342+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64343+#endif
64344+
64345+ ,hiwater_vm << (PAGE_SHIFT-10),
64346 total_vm << (PAGE_SHIFT-10),
64347 mm->locked_vm << (PAGE_SHIFT-10),
64348 mm->pinned_vm << (PAGE_SHIFT-10),
64349@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64350 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64351 (PTRS_PER_PTE * sizeof(pte_t) *
64352 atomic_long_read(&mm->nr_ptes)) >> 10,
64353- swap << (PAGE_SHIFT-10));
64354+ swap << (PAGE_SHIFT-10)
64355+
64356+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64357+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64358+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64359+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64360+#else
64361+ , mm->context.user_cs_base
64362+ , mm->context.user_cs_limit
64363+#endif
64364+#endif
64365+
64366+ );
64367 }
64368
64369 unsigned long task_vsize(struct mm_struct *mm)
64370@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64371 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64372 }
64373
64374- /* We don't show the stack guard page in /proc/maps */
64375+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64376+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64377+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64378+#else
64379 start = vma->vm_start;
64380- if (stack_guard_page_start(vma, start))
64381- start += PAGE_SIZE;
64382 end = vma->vm_end;
64383- if (stack_guard_page_end(vma, end))
64384- end -= PAGE_SIZE;
64385+#endif
64386
64387 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64388 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64389@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64390 flags & VM_WRITE ? 'w' : '-',
64391 flags & VM_EXEC ? 'x' : '-',
64392 flags & VM_MAYSHARE ? 's' : 'p',
64393+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64394+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64395+#else
64396 pgoff,
64397+#endif
64398 MAJOR(dev), MINOR(dev), ino);
64399
64400 /*
64401@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64402 */
64403 if (file) {
64404 seq_pad(m, ' ');
64405- seq_path(m, &file->f_path, "\n");
64406+ seq_path(m, &file->f_path, "\n\\");
64407 goto done;
64408 }
64409
64410@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64411 * Thread stack in /proc/PID/task/TID/maps or
64412 * the main process stack.
64413 */
64414- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64415- vma->vm_end >= mm->start_stack)) {
64416+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64417+ (vma->vm_start <= mm->start_stack &&
64418+ vma->vm_end >= mm->start_stack)) {
64419 name = "[stack]";
64420 } else {
64421 /* Thread stack in /proc/PID/maps */
64422@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64423 struct proc_maps_private *priv = m->private;
64424 struct task_struct *task = priv->task;
64425
64426+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64427+ if (current->exec_id != m->exec_id) {
64428+ gr_log_badprocpid("maps");
64429+ return 0;
64430+ }
64431+#endif
64432+
64433 show_map_vma(m, vma, is_pid);
64434
64435 if (m->count < m->size) /* vma is copied successfully */
64436@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64437 .private = &mss,
64438 };
64439
64440+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64441+ if (current->exec_id != m->exec_id) {
64442+ gr_log_badprocpid("smaps");
64443+ return 0;
64444+ }
64445+#endif
64446 memset(&mss, 0, sizeof mss);
64447- mss.vma = vma;
64448- /* mmap_sem is held in m_start */
64449- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64450- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64451-
64452+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64453+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64454+#endif
64455+ mss.vma = vma;
64456+ /* mmap_sem is held in m_start */
64457+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64458+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64459+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64460+ }
64461+#endif
64462 show_map_vma(m, vma, is_pid);
64463
64464 seq_printf(m,
64465@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64466 "KernelPageSize: %8lu kB\n"
64467 "MMUPageSize: %8lu kB\n"
64468 "Locked: %8lu kB\n",
64469+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64470+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64471+#else
64472 (vma->vm_end - vma->vm_start) >> 10,
64473+#endif
64474 mss.resident >> 10,
64475 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64476 mss.shared_clean >> 10,
64477@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64478 char buffer[64];
64479 int nid;
64480
64481+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64482+ if (current->exec_id != m->exec_id) {
64483+ gr_log_badprocpid("numa_maps");
64484+ return 0;
64485+ }
64486+#endif
64487+
64488 if (!mm)
64489 return 0;
64490
64491@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64492 mpol_to_str(buffer, sizeof(buffer), pol);
64493 mpol_cond_put(pol);
64494
64495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64496+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64497+#else
64498 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64499+#endif
64500
64501 if (file) {
64502 seq_printf(m, " file=");
64503- seq_path(m, &file->f_path, "\n\t= ");
64504+ seq_path(m, &file->f_path, "\n\t\\= ");
64505 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64506 seq_printf(m, " heap");
64507 } else {
64508diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64509index 678455d..ebd3245 100644
64510--- a/fs/proc/task_nommu.c
64511+++ b/fs/proc/task_nommu.c
64512@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64513 else
64514 bytes += kobjsize(mm);
64515
64516- if (current->fs && current->fs->users > 1)
64517+ if (current->fs && atomic_read(&current->fs->users) > 1)
64518 sbytes += kobjsize(current->fs);
64519 else
64520 bytes += kobjsize(current->fs);
64521@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64522
64523 if (file) {
64524 seq_pad(m, ' ');
64525- seq_path(m, &file->f_path, "");
64526+ seq_path(m, &file->f_path, "\n\\");
64527 } else if (mm) {
64528 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64529
64530diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64531index 88d4585..c10bfeb 100644
64532--- a/fs/proc/vmcore.c
64533+++ b/fs/proc/vmcore.c
64534@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64535 nr_bytes = count;
64536
64537 /* If pfn is not ram, return zeros for sparse dump files */
64538- if (pfn_is_ram(pfn) == 0)
64539- memset(buf, 0, nr_bytes);
64540- else {
64541+ if (pfn_is_ram(pfn) == 0) {
64542+ if (userbuf) {
64543+ if (clear_user((char __force_user *)buf, nr_bytes))
64544+ return -EFAULT;
64545+ } else
64546+ memset(buf, 0, nr_bytes);
64547+ } else {
64548 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64549 offset, userbuf);
64550 if (tmp < 0)
64551@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64552 static int copy_to(void *target, void *src, size_t size, int userbuf)
64553 {
64554 if (userbuf) {
64555- if (copy_to_user((char __user *) target, src, size))
64556+ if (copy_to_user((char __force_user *) target, src, size))
64557 return -EFAULT;
64558 } else {
64559 memcpy(target, src, size);
64560@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64561 if (*fpos < m->offset + m->size) {
64562 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64563 start = m->paddr + *fpos - m->offset;
64564- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64565+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64566 if (tmp < 0)
64567 return tmp;
64568 buflen -= tsz;
64569@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64570 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64571 size_t buflen, loff_t *fpos)
64572 {
64573- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64574+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64575 }
64576
64577 /*
64578diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64579index b00fcc9..e0c6381 100644
64580--- a/fs/qnx6/qnx6.h
64581+++ b/fs/qnx6/qnx6.h
64582@@ -74,7 +74,7 @@ enum {
64583 BYTESEX_BE,
64584 };
64585
64586-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64587+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64588 {
64589 if (sbi->s_bytesex == BYTESEX_LE)
64590 return le64_to_cpu((__force __le64)n);
64591@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64592 return (__force __fs64)cpu_to_be64(n);
64593 }
64594
64595-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64596+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64597 {
64598 if (sbi->s_bytesex == BYTESEX_LE)
64599 return le32_to_cpu((__force __le32)n);
64600diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64601index 72d2917..c917c12 100644
64602--- a/fs/quota/netlink.c
64603+++ b/fs/quota/netlink.c
64604@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64605 void quota_send_warning(struct kqid qid, dev_t dev,
64606 const char warntype)
64607 {
64608- static atomic_t seq;
64609+ static atomic_unchecked_t seq;
64610 struct sk_buff *skb;
64611 void *msg_head;
64612 int ret;
64613@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64614 "VFS: Not enough memory to send quota warning.\n");
64615 return;
64616 }
64617- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64618+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64619 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64620 if (!msg_head) {
64621 printk(KERN_ERR
64622diff --git a/fs/read_write.c b/fs/read_write.c
64623index 28cc9c8..208e4fb 100644
64624--- a/fs/read_write.c
64625+++ b/fs/read_write.c
64626@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64627
64628 old_fs = get_fs();
64629 set_fs(get_ds());
64630- p = (__force const char __user *)buf;
64631+ p = (const char __force_user *)buf;
64632 if (count > MAX_RW_COUNT)
64633 count = MAX_RW_COUNT;
64634 if (file->f_op->write)
64635diff --git a/fs/readdir.c b/fs/readdir.c
64636index 5b53d99..a6c3049 100644
64637--- a/fs/readdir.c
64638+++ b/fs/readdir.c
64639@@ -17,6 +17,7 @@
64640 #include <linux/security.h>
64641 #include <linux/syscalls.h>
64642 #include <linux/unistd.h>
64643+#include <linux/namei.h>
64644
64645 #include <asm/uaccess.h>
64646
64647@@ -69,6 +70,7 @@ struct old_linux_dirent {
64648 struct readdir_callback {
64649 struct dir_context ctx;
64650 struct old_linux_dirent __user * dirent;
64651+ struct file * file;
64652 int result;
64653 };
64654
64655@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64656 buf->result = -EOVERFLOW;
64657 return -EOVERFLOW;
64658 }
64659+
64660+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64661+ return 0;
64662+
64663 buf->result++;
64664 dirent = buf->dirent;
64665 if (!access_ok(VERIFY_WRITE, dirent,
64666@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64667 if (!f.file)
64668 return -EBADF;
64669
64670+ buf.file = f.file;
64671 error = iterate_dir(f.file, &buf.ctx);
64672 if (buf.result)
64673 error = buf.result;
64674@@ -142,6 +149,7 @@ struct getdents_callback {
64675 struct dir_context ctx;
64676 struct linux_dirent __user * current_dir;
64677 struct linux_dirent __user * previous;
64678+ struct file * file;
64679 int count;
64680 int error;
64681 };
64682@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64683 buf->error = -EOVERFLOW;
64684 return -EOVERFLOW;
64685 }
64686+
64687+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64688+ return 0;
64689+
64690 dirent = buf->previous;
64691 if (dirent) {
64692 if (__put_user(offset, &dirent->d_off))
64693@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64694 if (!f.file)
64695 return -EBADF;
64696
64697+ buf.file = f.file;
64698 error = iterate_dir(f.file, &buf.ctx);
64699 if (error >= 0)
64700 error = buf.error;
64701@@ -226,6 +239,7 @@ struct getdents_callback64 {
64702 struct dir_context ctx;
64703 struct linux_dirent64 __user * current_dir;
64704 struct linux_dirent64 __user * previous;
64705+ struct file *file;
64706 int count;
64707 int error;
64708 };
64709@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64710 buf->error = -EINVAL; /* only used if we fail.. */
64711 if (reclen > buf->count)
64712 return -EINVAL;
64713+
64714+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64715+ return 0;
64716+
64717 dirent = buf->previous;
64718 if (dirent) {
64719 if (__put_user(offset, &dirent->d_off))
64720@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64721 if (!f.file)
64722 return -EBADF;
64723
64724+ buf.file = f.file;
64725 error = iterate_dir(f.file, &buf.ctx);
64726 if (error >= 0)
64727 error = buf.error;
64728diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64729index 9a3c68c..767933e 100644
64730--- a/fs/reiserfs/do_balan.c
64731+++ b/fs/reiserfs/do_balan.c
64732@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64733 return;
64734 }
64735
64736- atomic_inc(&(fs_generation(tb->tb_sb)));
64737+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64738 do_balance_starts(tb);
64739
64740 /* balance leaf returns 0 except if combining L R and S into
64741diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64742index ee382ef..f4eb6eb5 100644
64743--- a/fs/reiserfs/item_ops.c
64744+++ b/fs/reiserfs/item_ops.c
64745@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64746 }
64747
64748 static struct item_operations errcatch_ops = {
64749- errcatch_bytes_number,
64750- errcatch_decrement_key,
64751- errcatch_is_left_mergeable,
64752- errcatch_print_item,
64753- errcatch_check_item,
64754+ .bytes_number = errcatch_bytes_number,
64755+ .decrement_key = errcatch_decrement_key,
64756+ .is_left_mergeable = errcatch_is_left_mergeable,
64757+ .print_item = errcatch_print_item,
64758+ .check_item = errcatch_check_item,
64759
64760- errcatch_create_vi,
64761- errcatch_check_left,
64762- errcatch_check_right,
64763- errcatch_part_size,
64764- errcatch_unit_num,
64765- errcatch_print_vi
64766+ .create_vi = errcatch_create_vi,
64767+ .check_left = errcatch_check_left,
64768+ .check_right = errcatch_check_right,
64769+ .part_size = errcatch_part_size,
64770+ .unit_num = errcatch_unit_num,
64771+ .print_vi = errcatch_print_vi
64772 };
64773
64774 //////////////////////////////////////////////////////////////////////////////
64775diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64776index 02b0b7d..c85018b 100644
64777--- a/fs/reiserfs/procfs.c
64778+++ b/fs/reiserfs/procfs.c
64779@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64780 "SMALL_TAILS " : "NO_TAILS ",
64781 replay_only(sb) ? "REPLAY_ONLY " : "",
64782 convert_reiserfs(sb) ? "CONV " : "",
64783- atomic_read(&r->s_generation_counter),
64784+ atomic_read_unchecked(&r->s_generation_counter),
64785 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64786 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64787 SF(s_good_search_by_key_reada), SF(s_bmaps),
64788diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64789index 8d06adf..7e1c9f8 100644
64790--- a/fs/reiserfs/reiserfs.h
64791+++ b/fs/reiserfs/reiserfs.h
64792@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64793 /* Comment? -Hans */
64794 wait_queue_head_t s_wait;
64795 /* To be obsoleted soon by per buffer seals.. -Hans */
64796- atomic_t s_generation_counter; // increased by one every time the
64797+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64798 // tree gets re-balanced
64799 unsigned long s_properties; /* File system properties. Currently holds
64800 on-disk FS format */
64801@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64802 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64803
64804 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64805-#define get_generation(s) atomic_read (&fs_generation(s))
64806+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64807 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64808 #define __fs_changed(gen,s) (gen != get_generation (s))
64809 #define fs_changed(gen,s) \
64810diff --git a/fs/select.c b/fs/select.c
64811index 467bb1c..cf9d65a 100644
64812--- a/fs/select.c
64813+++ b/fs/select.c
64814@@ -20,6 +20,7 @@
64815 #include <linux/export.h>
64816 #include <linux/slab.h>
64817 #include <linux/poll.h>
64818+#include <linux/security.h>
64819 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64820 #include <linux/file.h>
64821 #include <linux/fdtable.h>
64822@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64823 struct poll_list *walk = head;
64824 unsigned long todo = nfds;
64825
64826+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64827 if (nfds > rlimit(RLIMIT_NOFILE))
64828 return -EINVAL;
64829
64830diff --git a/fs/seq_file.c b/fs/seq_file.c
64831index 1d641bb..c2f4743 100644
64832--- a/fs/seq_file.c
64833+++ b/fs/seq_file.c
64834@@ -10,6 +10,8 @@
64835 #include <linux/seq_file.h>
64836 #include <linux/slab.h>
64837 #include <linux/cred.h>
64838+#include <linux/sched.h>
64839+#include <linux/grsecurity.h>
64840
64841 #include <asm/uaccess.h>
64842 #include <asm/page.h>
64843@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64844 #ifdef CONFIG_USER_NS
64845 p->user_ns = file->f_cred->user_ns;
64846 #endif
64847+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64848+ p->exec_id = current->exec_id;
64849+#endif
64850
64851 /*
64852 * Wrappers around seq_open(e.g. swaps_open) need to be
64853@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64854 }
64855 EXPORT_SYMBOL(seq_open);
64856
64857+
64858+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64859+{
64860+ if (gr_proc_is_restricted())
64861+ return -EACCES;
64862+
64863+ return seq_open(file, op);
64864+}
64865+EXPORT_SYMBOL(seq_open_restrict);
64866+
64867 static int traverse(struct seq_file *m, loff_t offset)
64868 {
64869 loff_t pos = 0, index;
64870@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64871 return 0;
64872 }
64873 if (!m->buf) {
64874- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64875+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64876 if (!m->buf)
64877 return -ENOMEM;
64878 }
64879@@ -137,7 +152,7 @@ Eoverflow:
64880 m->op->stop(m, p);
64881 kfree(m->buf);
64882 m->count = 0;
64883- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64884+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64885 return !m->buf ? -ENOMEM : -EAGAIN;
64886 }
64887
64888@@ -153,7 +168,7 @@ Eoverflow:
64889 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64890 {
64891 struct seq_file *m = file->private_data;
64892- size_t copied = 0;
64893+ ssize_t copied = 0;
64894 loff_t pos;
64895 size_t n;
64896 void *p;
64897@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64898
64899 /* grab buffer if we didn't have one */
64900 if (!m->buf) {
64901- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64902+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64903 if (!m->buf)
64904 goto Enomem;
64905 }
64906@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64907 m->op->stop(m, p);
64908 kfree(m->buf);
64909 m->count = 0;
64910- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64911+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64912 if (!m->buf)
64913 goto Enomem;
64914 m->version = 0;
64915@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
64916 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64917 void *data)
64918 {
64919- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64920+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64921 int res = -ENOMEM;
64922
64923 if (op) {
64924@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
64925 }
64926 EXPORT_SYMBOL(single_open_size);
64927
64928+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
64929+ void *data)
64930+{
64931+ if (gr_proc_is_restricted())
64932+ return -EACCES;
64933+
64934+ return single_open(file, show, data);
64935+}
64936+EXPORT_SYMBOL(single_open_restrict);
64937+
64938+
64939 int single_release(struct inode *inode, struct file *file)
64940 {
64941 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
64942diff --git a/fs/splice.c b/fs/splice.c
64943index 12028fa..a6f2619 100644
64944--- a/fs/splice.c
64945+++ b/fs/splice.c
64946@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64947 pipe_lock(pipe);
64948
64949 for (;;) {
64950- if (!pipe->readers) {
64951+ if (!atomic_read(&pipe->readers)) {
64952 send_sig(SIGPIPE, current, 0);
64953 if (!ret)
64954 ret = -EPIPE;
64955@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64956 page_nr++;
64957 ret += buf->len;
64958
64959- if (pipe->files)
64960+ if (atomic_read(&pipe->files))
64961 do_wakeup = 1;
64962
64963 if (!--spd->nr_pages)
64964@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64965 do_wakeup = 0;
64966 }
64967
64968- pipe->waiting_writers++;
64969+ atomic_inc(&pipe->waiting_writers);
64970 pipe_wait(pipe);
64971- pipe->waiting_writers--;
64972+ atomic_dec(&pipe->waiting_writers);
64973 }
64974
64975 pipe_unlock(pipe);
64976@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64977 old_fs = get_fs();
64978 set_fs(get_ds());
64979 /* The cast to a user pointer is valid due to the set_fs() */
64980- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64981+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64982 set_fs(old_fs);
64983
64984 return res;
64985@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64986 old_fs = get_fs();
64987 set_fs(get_ds());
64988 /* The cast to a user pointer is valid due to the set_fs() */
64989- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64990+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64991 set_fs(old_fs);
64992
64993 return res;
64994@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64995 goto err;
64996
64997 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64998- vec[i].iov_base = (void __user *) page_address(page);
64999+ vec[i].iov_base = (void __force_user *) page_address(page);
65000 vec[i].iov_len = this_len;
65001 spd.pages[i] = page;
65002 spd.nr_pages++;
65003@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65004 ops->release(pipe, buf);
65005 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65006 pipe->nrbufs--;
65007- if (pipe->files)
65008+ if (atomic_read(&pipe->files))
65009 sd->need_wakeup = true;
65010 }
65011
65012@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65013 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65014 {
65015 while (!pipe->nrbufs) {
65016- if (!pipe->writers)
65017+ if (!atomic_read(&pipe->writers))
65018 return 0;
65019
65020- if (!pipe->waiting_writers && sd->num_spliced)
65021+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65022 return 0;
65023
65024 if (sd->flags & SPLICE_F_NONBLOCK)
65025@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65026 * out of the pipe right after the splice_to_pipe(). So set
65027 * PIPE_READERS appropriately.
65028 */
65029- pipe->readers = 1;
65030+ atomic_set(&pipe->readers, 1);
65031
65032 current->splice_pipe = pipe;
65033 }
65034@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65035
65036 partial[buffers].offset = off;
65037 partial[buffers].len = plen;
65038+ partial[buffers].private = 0;
65039
65040 off = 0;
65041 len -= plen;
65042@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65043 ret = -ERESTARTSYS;
65044 break;
65045 }
65046- if (!pipe->writers)
65047+ if (!atomic_read(&pipe->writers))
65048 break;
65049- if (!pipe->waiting_writers) {
65050+ if (!atomic_read(&pipe->waiting_writers)) {
65051 if (flags & SPLICE_F_NONBLOCK) {
65052 ret = -EAGAIN;
65053 break;
65054@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65055 pipe_lock(pipe);
65056
65057 while (pipe->nrbufs >= pipe->buffers) {
65058- if (!pipe->readers) {
65059+ if (!atomic_read(&pipe->readers)) {
65060 send_sig(SIGPIPE, current, 0);
65061 ret = -EPIPE;
65062 break;
65063@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65064 ret = -ERESTARTSYS;
65065 break;
65066 }
65067- pipe->waiting_writers++;
65068+ atomic_inc(&pipe->waiting_writers);
65069 pipe_wait(pipe);
65070- pipe->waiting_writers--;
65071+ atomic_dec(&pipe->waiting_writers);
65072 }
65073
65074 pipe_unlock(pipe);
65075@@ -1880,14 +1881,14 @@ retry:
65076 pipe_double_lock(ipipe, opipe);
65077
65078 do {
65079- if (!opipe->readers) {
65080+ if (!atomic_read(&opipe->readers)) {
65081 send_sig(SIGPIPE, current, 0);
65082 if (!ret)
65083 ret = -EPIPE;
65084 break;
65085 }
65086
65087- if (!ipipe->nrbufs && !ipipe->writers)
65088+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65089 break;
65090
65091 /*
65092@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65093 pipe_double_lock(ipipe, opipe);
65094
65095 do {
65096- if (!opipe->readers) {
65097+ if (!atomic_read(&opipe->readers)) {
65098 send_sig(SIGPIPE, current, 0);
65099 if (!ret)
65100 ret = -EPIPE;
65101@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65102 * return EAGAIN if we have the potential of some data in the
65103 * future, otherwise just return 0
65104 */
65105- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65106+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65107 ret = -EAGAIN;
65108
65109 pipe_unlock(ipipe);
65110diff --git a/fs/stat.c b/fs/stat.c
65111index ae0c3ce..9ee641c 100644
65112--- a/fs/stat.c
65113+++ b/fs/stat.c
65114@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65115 stat->gid = inode->i_gid;
65116 stat->rdev = inode->i_rdev;
65117 stat->size = i_size_read(inode);
65118- stat->atime = inode->i_atime;
65119- stat->mtime = inode->i_mtime;
65120+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65121+ stat->atime = inode->i_ctime;
65122+ stat->mtime = inode->i_ctime;
65123+ } else {
65124+ stat->atime = inode->i_atime;
65125+ stat->mtime = inode->i_mtime;
65126+ }
65127 stat->ctime = inode->i_ctime;
65128 stat->blksize = (1 << inode->i_blkbits);
65129 stat->blocks = inode->i_blocks;
65130@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65131 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65132 {
65133 struct inode *inode = path->dentry->d_inode;
65134+ int retval;
65135
65136- if (inode->i_op->getattr)
65137- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65138+ if (inode->i_op->getattr) {
65139+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65140+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65141+ stat->atime = stat->ctime;
65142+ stat->mtime = stat->ctime;
65143+ }
65144+ return retval;
65145+ }
65146
65147 generic_fillattr(inode, stat);
65148 return 0;
65149diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65150index ee0d761..b346c58 100644
65151--- a/fs/sysfs/dir.c
65152+++ b/fs/sysfs/dir.c
65153@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65154 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65155 {
65156 struct kernfs_node *parent, *kn;
65157+ const char *name;
65158+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65159+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65160+ const char *parent_name;
65161+#endif
65162
65163 BUG_ON(!kobj);
65164
65165+ name = kobject_name(kobj);
65166+
65167 if (kobj->parent)
65168 parent = kobj->parent->sd;
65169 else
65170@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65171 if (!parent)
65172 return -ENOENT;
65173
65174- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65175- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65176+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65177+ parent_name = parent->name;
65178+ mode = S_IRWXU;
65179+
65180+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65181+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65182+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65183+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65184+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65185+#endif
65186+
65187+ kn = kernfs_create_dir_ns(parent, name,
65188+ mode, kobj, ns);
65189 if (IS_ERR(kn)) {
65190 if (PTR_ERR(kn) == -EEXIST)
65191- sysfs_warn_dup(parent, kobject_name(kobj));
65192+ sysfs_warn_dup(parent, name);
65193 return PTR_ERR(kn);
65194 }
65195
65196diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65197index 69d4889..a810bd4 100644
65198--- a/fs/sysv/sysv.h
65199+++ b/fs/sysv/sysv.h
65200@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65201 #endif
65202 }
65203
65204-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65205+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65206 {
65207 if (sbi->s_bytesex == BYTESEX_PDP)
65208 return PDP_swab((__force __u32)n);
65209diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65210index e18b988..f1d4ad0f 100644
65211--- a/fs/ubifs/io.c
65212+++ b/fs/ubifs/io.c
65213@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65214 return err;
65215 }
65216
65217-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65218+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65219 {
65220 int err;
65221
65222diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65223index c175b4d..8f36a16 100644
65224--- a/fs/udf/misc.c
65225+++ b/fs/udf/misc.c
65226@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65227
65228 u8 udf_tag_checksum(const struct tag *t)
65229 {
65230- u8 *data = (u8 *)t;
65231+ const u8 *data = (const u8 *)t;
65232 u8 checksum = 0;
65233 int i;
65234 for (i = 0; i < sizeof(struct tag); ++i)
65235diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65236index 8d974c4..b82f6ec 100644
65237--- a/fs/ufs/swab.h
65238+++ b/fs/ufs/swab.h
65239@@ -22,7 +22,7 @@ enum {
65240 BYTESEX_BE
65241 };
65242
65243-static inline u64
65244+static inline u64 __intentional_overflow(-1)
65245 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65246 {
65247 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65248@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65249 return (__force __fs64)cpu_to_be64(n);
65250 }
65251
65252-static inline u32
65253+static inline u32 __intentional_overflow(-1)
65254 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65255 {
65256 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65257diff --git a/fs/utimes.c b/fs/utimes.c
65258index aa138d6..5f3a811 100644
65259--- a/fs/utimes.c
65260+++ b/fs/utimes.c
65261@@ -1,6 +1,7 @@
65262 #include <linux/compiler.h>
65263 #include <linux/file.h>
65264 #include <linux/fs.h>
65265+#include <linux/security.h>
65266 #include <linux/linkage.h>
65267 #include <linux/mount.h>
65268 #include <linux/namei.h>
65269@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65270 }
65271 }
65272 retry_deleg:
65273+
65274+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65275+ error = -EACCES;
65276+ goto mnt_drop_write_and_out;
65277+ }
65278+
65279 mutex_lock(&inode->i_mutex);
65280 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65281 mutex_unlock(&inode->i_mutex);
65282diff --git a/fs/xattr.c b/fs/xattr.c
65283index 3377dff..f394815 100644
65284--- a/fs/xattr.c
65285+++ b/fs/xattr.c
65286@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65287 return rc;
65288 }
65289
65290+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65291+ssize_t
65292+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65293+{
65294+ struct inode *inode = dentry->d_inode;
65295+ ssize_t error;
65296+
65297+ error = inode_permission(inode, MAY_EXEC);
65298+ if (error)
65299+ return error;
65300+
65301+ if (inode->i_op->getxattr)
65302+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65303+ else
65304+ error = -EOPNOTSUPP;
65305+
65306+ return error;
65307+}
65308+EXPORT_SYMBOL(pax_getxattr);
65309+#endif
65310+
65311 ssize_t
65312 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65313 {
65314@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65315 * Extended attribute SET operations
65316 */
65317 static long
65318-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65319+setxattr(struct path *path, const char __user *name, const void __user *value,
65320 size_t size, int flags)
65321 {
65322 int error;
65323@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65324 posix_acl_fix_xattr_from_user(kvalue, size);
65325 }
65326
65327- error = vfs_setxattr(d, kname, kvalue, size, flags);
65328+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65329+ error = -EACCES;
65330+ goto out;
65331+ }
65332+
65333+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65334 out:
65335 if (vvalue)
65336 vfree(vvalue);
65337@@ -377,7 +403,7 @@ retry:
65338 return error;
65339 error = mnt_want_write(path.mnt);
65340 if (!error) {
65341- error = setxattr(path.dentry, name, value, size, flags);
65342+ error = setxattr(&path, name, value, size, flags);
65343 mnt_drop_write(path.mnt);
65344 }
65345 path_put(&path);
65346@@ -401,7 +427,7 @@ retry:
65347 return error;
65348 error = mnt_want_write(path.mnt);
65349 if (!error) {
65350- error = setxattr(path.dentry, name, value, size, flags);
65351+ error = setxattr(&path, name, value, size, flags);
65352 mnt_drop_write(path.mnt);
65353 }
65354 path_put(&path);
65355@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65356 const void __user *,value, size_t, size, int, flags)
65357 {
65358 struct fd f = fdget(fd);
65359- struct dentry *dentry;
65360 int error = -EBADF;
65361
65362 if (!f.file)
65363 return error;
65364- dentry = f.file->f_path.dentry;
65365- audit_inode(NULL, dentry, 0);
65366+ audit_inode(NULL, f.file->f_path.dentry, 0);
65367 error = mnt_want_write_file(f.file);
65368 if (!error) {
65369- error = setxattr(dentry, name, value, size, flags);
65370+ error = setxattr(&f.file->f_path, name, value, size, flags);
65371 mnt_drop_write_file(f.file);
65372 }
65373 fdput(f);
65374@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65375 * Extended attribute REMOVE operations
65376 */
65377 static long
65378-removexattr(struct dentry *d, const char __user *name)
65379+removexattr(struct path *path, const char __user *name)
65380 {
65381 int error;
65382 char kname[XATTR_NAME_MAX + 1];
65383@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65384 if (error < 0)
65385 return error;
65386
65387- return vfs_removexattr(d, kname);
65388+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65389+ return -EACCES;
65390+
65391+ return vfs_removexattr(path->dentry, kname);
65392 }
65393
65394 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65395@@ -652,7 +679,7 @@ retry:
65396 return error;
65397 error = mnt_want_write(path.mnt);
65398 if (!error) {
65399- error = removexattr(path.dentry, name);
65400+ error = removexattr(&path, name);
65401 mnt_drop_write(path.mnt);
65402 }
65403 path_put(&path);
65404@@ -675,7 +702,7 @@ retry:
65405 return error;
65406 error = mnt_want_write(path.mnt);
65407 if (!error) {
65408- error = removexattr(path.dentry, name);
65409+ error = removexattr(&path, name);
65410 mnt_drop_write(path.mnt);
65411 }
65412 path_put(&path);
65413@@ -689,16 +716,16 @@ retry:
65414 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65415 {
65416 struct fd f = fdget(fd);
65417- struct dentry *dentry;
65418+ struct path *path;
65419 int error = -EBADF;
65420
65421 if (!f.file)
65422 return error;
65423- dentry = f.file->f_path.dentry;
65424- audit_inode(NULL, dentry, 0);
65425+ path = &f.file->f_path;
65426+ audit_inode(NULL, path->dentry, 0);
65427 error = mnt_want_write_file(f.file);
65428 if (!error) {
65429- error = removexattr(dentry, name);
65430+ error = removexattr(path, name);
65431 mnt_drop_write_file(f.file);
65432 }
65433 fdput(f);
65434diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65435index 152543c..d80c361 100644
65436--- a/fs/xfs/xfs_bmap.c
65437+++ b/fs/xfs/xfs_bmap.c
65438@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65439
65440 #else
65441 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65442-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65443+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65444 #endif /* DEBUG */
65445
65446 /*
65447diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65448index aead369..0dfecfd 100644
65449--- a/fs/xfs/xfs_dir2_readdir.c
65450+++ b/fs/xfs/xfs_dir2_readdir.c
65451@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65452 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65453 filetype = dp->d_ops->sf_get_ftype(sfep);
65454 ctx->pos = off & 0x7fffffff;
65455- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65456+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65457+ char name[sfep->namelen];
65458+ memcpy(name, sfep->name, sfep->namelen);
65459+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65460+ return 0;
65461+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65462 xfs_dir3_get_dtype(mp, filetype)))
65463 return 0;
65464 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65465diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65466index bcfe612..aa399c0 100644
65467--- a/fs/xfs/xfs_ioctl.c
65468+++ b/fs/xfs/xfs_ioctl.c
65469@@ -122,7 +122,7 @@ xfs_find_handle(
65470 }
65471
65472 error = -EFAULT;
65473- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65474+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65475 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65476 goto out_put;
65477
65478diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65479new file mode 100644
65480index 0000000..3abaf02
65481--- /dev/null
65482+++ b/grsecurity/Kconfig
65483@@ -0,0 +1,1161 @@
65484+#
65485+# grecurity configuration
65486+#
65487+menu "Memory Protections"
65488+depends on GRKERNSEC
65489+
65490+config GRKERNSEC_KMEM
65491+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65492+ default y if GRKERNSEC_CONFIG_AUTO
65493+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65494+ help
65495+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65496+ be written to or read from to modify or leak the contents of the running
65497+ kernel. /dev/port will also not be allowed to be opened, writing to
65498+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65499+ If you have module support disabled, enabling this will close up several
65500+ ways that are currently used to insert malicious code into the running
65501+ kernel.
65502+
65503+ Even with this feature enabled, we still highly recommend that
65504+ you use the RBAC system, as it is still possible for an attacker to
65505+ modify the running kernel through other more obscure methods.
65506+
65507+ It is highly recommended that you say Y here if you meet all the
65508+ conditions above.
65509+
65510+config GRKERNSEC_VM86
65511+ bool "Restrict VM86 mode"
65512+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65513+ depends on X86_32
65514+
65515+ help
65516+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65517+ make use of a special execution mode on 32bit x86 processors called
65518+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65519+ video cards and will still work with this option enabled. The purpose
65520+ of the option is to prevent exploitation of emulation errors in
65521+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65522+ Nearly all users should be able to enable this option.
65523+
65524+config GRKERNSEC_IO
65525+ bool "Disable privileged I/O"
65526+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65527+ depends on X86
65528+ select RTC_CLASS
65529+ select RTC_INTF_DEV
65530+ select RTC_DRV_CMOS
65531+
65532+ help
65533+ If you say Y here, all ioperm and iopl calls will return an error.
65534+ Ioperm and iopl can be used to modify the running kernel.
65535+ Unfortunately, some programs need this access to operate properly,
65536+ the most notable of which are XFree86 and hwclock. hwclock can be
65537+ remedied by having RTC support in the kernel, so real-time
65538+ clock support is enabled if this option is enabled, to ensure
65539+ that hwclock operates correctly. If hwclock still does not work,
65540+ either update udev or symlink /dev/rtc to /dev/rtc0.
65541+
65542+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65543+ you may not be able to boot into a graphical environment with this
65544+ option enabled. In this case, you should use the RBAC system instead.
65545+
65546+config GRKERNSEC_JIT_HARDEN
65547+ bool "Harden BPF JIT against spray attacks"
65548+ default y if GRKERNSEC_CONFIG_AUTO
65549+ depends on BPF_JIT && X86
65550+ help
65551+ If you say Y here, the native code generated by the kernel's Berkeley
65552+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65553+ attacks that attempt to fit attacker-beneficial instructions in
65554+ 32bit immediate fields of JIT-generated native instructions. The
65555+ attacker will generally aim to cause an unintended instruction sequence
65556+ of JIT-generated native code to execute by jumping into the middle of
65557+ a generated instruction. This feature effectively randomizes the 32bit
65558+ immediate constants present in the generated code to thwart such attacks.
65559+
65560+ If you're using KERNEXEC, it's recommended that you enable this option
65561+ to supplement the hardening of the kernel.
65562+
65563+config GRKERNSEC_PERF_HARDEN
65564+ bool "Disable unprivileged PERF_EVENTS usage by default"
65565+ default y if GRKERNSEC_CONFIG_AUTO
65566+ depends on PERF_EVENTS
65567+ help
65568+ If you say Y here, the range of acceptable values for the
65569+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65570+ default to a new value: 3. When the sysctl is set to this value, no
65571+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65572+
65573+ Though PERF_EVENTS can be used legitimately for performance monitoring
65574+ and low-level application profiling, it is forced on regardless of
65575+ configuration, has been at fault for several vulnerabilities, and
65576+ creates new opportunities for side channels and other information leaks.
65577+
65578+ This feature puts PERF_EVENTS into a secure default state and permits
65579+ the administrator to change out of it temporarily if unprivileged
65580+ application profiling is needed.
65581+
65582+config GRKERNSEC_RAND_THREADSTACK
65583+ bool "Insert random gaps between thread stacks"
65584+ default y if GRKERNSEC_CONFIG_AUTO
65585+ depends on PAX_RANDMMAP && !PPC
65586+ help
65587+ If you say Y here, a random-sized gap will be enforced between allocated
65588+ thread stacks. Glibc's NPTL and other threading libraries that
65589+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65590+ The implementation currently provides 8 bits of entropy for the gap.
65591+
65592+ Many distributions do not compile threaded remote services with the
65593+ -fstack-check argument to GCC, causing the variable-sized stack-based
65594+ allocator, alloca(), to not probe the stack on allocation. This
65595+ permits an unbounded alloca() to skip over any guard page and potentially
65596+ modify another thread's stack reliably. An enforced random gap
65597+ reduces the reliability of such an attack and increases the chance
65598+ that such a read/write to another thread's stack instead lands in
65599+ an unmapped area, causing a crash and triggering grsecurity's
65600+ anti-bruteforcing logic.
65601+
65602+config GRKERNSEC_PROC_MEMMAP
65603+ bool "Harden ASLR against information leaks and entropy reduction"
65604+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65605+ depends on PAX_NOEXEC || PAX_ASLR
65606+ help
65607+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65608+ give no information about the addresses of its mappings if
65609+ PaX features that rely on random addresses are enabled on the task.
65610+ In addition to sanitizing this information and disabling other
65611+ dangerous sources of information, this option causes reads of sensitive
65612+ /proc/<pid> entries where the file descriptor was opened in a different
65613+ task than the one performing the read. Such attempts are logged.
65614+ This option also limits argv/env strings for suid/sgid binaries
65615+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65616+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65617+ binaries to prevent alternative mmap layouts from being abused.
65618+
65619+ If you use PaX it is essential that you say Y here as it closes up
65620+ several holes that make full ASLR useless locally.
65621+
65622+config GRKERNSEC_BRUTE
65623+ bool "Deter exploit bruteforcing"
65624+ default y if GRKERNSEC_CONFIG_AUTO
65625+ help
65626+ If you say Y here, attempts to bruteforce exploits against forking
65627+ daemons such as apache or sshd, as well as against suid/sgid binaries
65628+ will be deterred. When a child of a forking daemon is killed by PaX
65629+ or crashes due to an illegal instruction or other suspicious signal,
65630+ the parent process will be delayed 30 seconds upon every subsequent
65631+ fork until the administrator is able to assess the situation and
65632+ restart the daemon.
65633+ In the suid/sgid case, the attempt is logged, the user has all their
65634+ existing instances of the suid/sgid binary terminated and will
65635+ be unable to execute any suid/sgid binaries for 15 minutes.
65636+
65637+ It is recommended that you also enable signal logging in the auditing
65638+ section so that logs are generated when a process triggers a suspicious
65639+ signal.
65640+ If the sysctl option is enabled, a sysctl option with name
65641+ "deter_bruteforce" is created.
65642+
65643+config GRKERNSEC_MODHARDEN
65644+ bool "Harden module auto-loading"
65645+ default y if GRKERNSEC_CONFIG_AUTO
65646+ depends on MODULES
65647+ help
65648+ If you say Y here, module auto-loading in response to use of some
65649+ feature implemented by an unloaded module will be restricted to
65650+ root users. Enabling this option helps defend against attacks
65651+ by unprivileged users who abuse the auto-loading behavior to
65652+ cause a vulnerable module to load that is then exploited.
65653+
65654+ If this option prevents a legitimate use of auto-loading for a
65655+ non-root user, the administrator can execute modprobe manually
65656+ with the exact name of the module mentioned in the alert log.
65657+ Alternatively, the administrator can add the module to the list
65658+ of modules loaded at boot by modifying init scripts.
65659+
65660+ Modification of init scripts will most likely be needed on
65661+ Ubuntu servers with encrypted home directory support enabled,
65662+ as the first non-root user logging in will cause the ecb(aes),
65663+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65664+
65665+config GRKERNSEC_HIDESYM
65666+ bool "Hide kernel symbols"
65667+ default y if GRKERNSEC_CONFIG_AUTO
65668+ select PAX_USERCOPY_SLABS
65669+ help
65670+ If you say Y here, getting information on loaded modules, and
65671+ displaying all kernel symbols through a syscall will be restricted
65672+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65673+ /proc/kallsyms will be restricted to the root user. The RBAC
65674+ system can hide that entry even from root.
65675+
65676+ This option also prevents leaking of kernel addresses through
65677+ several /proc entries.
65678+
65679+ Note that this option is only effective provided the following
65680+ conditions are met:
65681+ 1) The kernel using grsecurity is not precompiled by some distribution
65682+ 2) You have also enabled GRKERNSEC_DMESG
65683+ 3) You are using the RBAC system and hiding other files such as your
65684+ kernel image and System.map. Alternatively, enabling this option
65685+ causes the permissions on /boot, /lib/modules, and the kernel
65686+ source directory to change at compile time to prevent
65687+ reading by non-root users.
65688+ If the above conditions are met, this option will aid in providing a
65689+ useful protection against local kernel exploitation of overflows
65690+ and arbitrary read/write vulnerabilities.
65691+
65692+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65693+ in addition to this feature.
65694+
65695+config GRKERNSEC_RANDSTRUCT
65696+ bool "Randomize layout of sensitive kernel structures"
65697+ default y if GRKERNSEC_CONFIG_AUTO
65698+ select GRKERNSEC_HIDESYM
65699+ select MODVERSIONS if MODULES
65700+ help
65701+ If you say Y here, the layouts of a number of sensitive kernel
65702+ structures (task, fs, cred, etc) and all structures composed entirely
65703+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65704+ This can introduce the requirement of an additional infoleak
65705+ vulnerability for exploits targeting these structure types.
65706+
65707+ Enabling this feature will introduce some performance impact, slightly
65708+ increase memory usage, and prevent the use of forensic tools like
65709+ Volatility against the system (unless the kernel source tree isn't
65710+ cleaned after kernel installation).
65711+
65712+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65713+ It remains after a make clean to allow for external modules to be compiled
65714+ with the existing seed and will be removed by a make mrproper or
65715+ make distclean.
65716+
65717+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65718+ to install the supporting headers explicitly in addition to the normal
65719+ gcc package.
65720+
65721+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65722+ bool "Use cacheline-aware structure randomization"
65723+ depends on GRKERNSEC_RANDSTRUCT
65724+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65725+ help
65726+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65727+ at restricting randomization to cacheline-sized groups of elements. It
65728+ will further not randomize bitfields in structures. This reduces the
65729+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65730+
65731+config GRKERNSEC_KERN_LOCKOUT
65732+ bool "Active kernel exploit response"
65733+ default y if GRKERNSEC_CONFIG_AUTO
65734+ depends on X86 || ARM || PPC || SPARC
65735+ help
65736+ If you say Y here, when a PaX alert is triggered due to suspicious
65737+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65738+ or an OOPS occurs due to bad memory accesses, instead of just
65739+ terminating the offending process (and potentially allowing
65740+ a subsequent exploit from the same user), we will take one of two
65741+ actions:
65742+ If the user was root, we will panic the system
65743+ If the user was non-root, we will log the attempt, terminate
65744+ all processes owned by the user, then prevent them from creating
65745+ any new processes until the system is restarted
65746+ This deters repeated kernel exploitation/bruteforcing attempts
65747+ and is useful for later forensics.
65748+
65749+config GRKERNSEC_OLD_ARM_USERLAND
65750+ bool "Old ARM userland compatibility"
65751+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65752+ help
65753+ If you say Y here, stubs of executable code to perform such operations
65754+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65755+ table. This is unfortunately needed for old ARM userland meant to run
65756+ across a wide range of processors. Without this option enabled,
65757+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65758+ which is enough for Linaro userlands or other userlands designed for v6
65759+ and newer ARM CPUs. It's recommended that you try without this option enabled
65760+ first, and only enable it if your userland does not boot (it will likely fail
65761+ at init time).
65762+
65763+endmenu
65764+menu "Role Based Access Control Options"
65765+depends on GRKERNSEC
65766+
65767+config GRKERNSEC_RBAC_DEBUG
65768+ bool
65769+
65770+config GRKERNSEC_NO_RBAC
65771+ bool "Disable RBAC system"
65772+ help
65773+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65774+ preventing the RBAC system from being enabled. You should only say Y
65775+ here if you have no intention of using the RBAC system, so as to prevent
65776+ an attacker with root access from misusing the RBAC system to hide files
65777+ and processes when loadable module support and /dev/[k]mem have been
65778+ locked down.
65779+
65780+config GRKERNSEC_ACL_HIDEKERN
65781+ bool "Hide kernel processes"
65782+ help
65783+ If you say Y here, all kernel threads will be hidden to all
65784+ processes but those whose subject has the "view hidden processes"
65785+ flag.
65786+
65787+config GRKERNSEC_ACL_MAXTRIES
65788+ int "Maximum tries before password lockout"
65789+ default 3
65790+ help
65791+ This option enforces the maximum number of times a user can attempt
65792+ to authorize themselves with the grsecurity RBAC system before being
65793+ denied the ability to attempt authorization again for a specified time.
65794+ The lower the number, the harder it will be to brute-force a password.
65795+
65796+config GRKERNSEC_ACL_TIMEOUT
65797+ int "Time to wait after max password tries, in seconds"
65798+ default 30
65799+ help
65800+ This option specifies the time the user must wait after attempting to
65801+ authorize to the RBAC system with the maximum number of invalid
65802+ passwords. The higher the number, the harder it will be to brute-force
65803+ a password.
65804+
65805+endmenu
65806+menu "Filesystem Protections"
65807+depends on GRKERNSEC
65808+
65809+config GRKERNSEC_PROC
65810+ bool "Proc restrictions"
65811+ default y if GRKERNSEC_CONFIG_AUTO
65812+ help
65813+ If you say Y here, the permissions of the /proc filesystem
65814+ will be altered to enhance system security and privacy. You MUST
65815+ choose either a user only restriction or a user and group restriction.
65816+ Depending upon the option you choose, you can either restrict users to
65817+ see only the processes they themselves run, or choose a group that can
65818+ view all processes and files normally restricted to root if you choose
65819+ the "restrict to user only" option. NOTE: If you're running identd or
65820+ ntpd as a non-root user, you will have to run it as the group you
65821+ specify here.
65822+
65823+config GRKERNSEC_PROC_USER
65824+ bool "Restrict /proc to user only"
65825+ depends on GRKERNSEC_PROC
65826+ help
65827+ If you say Y here, non-root users will only be able to view their own
65828+ processes, and restricts them from viewing network-related information,
65829+ and viewing kernel symbol and module information.
65830+
65831+config GRKERNSEC_PROC_USERGROUP
65832+ bool "Allow special group"
65833+ default y if GRKERNSEC_CONFIG_AUTO
65834+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65835+ help
65836+ If you say Y here, you will be able to select a group that will be
65837+ able to view all processes and network-related information. If you've
65838+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65839+ remain hidden. This option is useful if you want to run identd as
65840+ a non-root user. The group you select may also be chosen at boot time
65841+ via "grsec_proc_gid=" on the kernel commandline.
65842+
65843+config GRKERNSEC_PROC_GID
65844+ int "GID for special group"
65845+ depends on GRKERNSEC_PROC_USERGROUP
65846+ default 1001
65847+
65848+config GRKERNSEC_PROC_ADD
65849+ bool "Additional restrictions"
65850+ default y if GRKERNSEC_CONFIG_AUTO
65851+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65852+ help
65853+ If you say Y here, additional restrictions will be placed on
65854+ /proc that keep normal users from viewing device information and
65855+ slabinfo information that could be useful for exploits.
65856+
65857+config GRKERNSEC_LINK
65858+ bool "Linking restrictions"
65859+ default y if GRKERNSEC_CONFIG_AUTO
65860+ help
65861+ If you say Y here, /tmp race exploits will be prevented, since users
65862+ will no longer be able to follow symlinks owned by other users in
65863+ world-writable +t directories (e.g. /tmp), unless the owner of the
65864+ symlink is the owner of the directory. users will also not be
65865+ able to hardlink to files they do not own. If the sysctl option is
65866+ enabled, a sysctl option with name "linking_restrictions" is created.
65867+
65868+config GRKERNSEC_SYMLINKOWN
65869+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65870+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65871+ help
65872+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65873+ that prevents it from being used as a security feature. As Apache
65874+ verifies the symlink by performing a stat() against the target of
65875+ the symlink before it is followed, an attacker can setup a symlink
65876+ to point to a same-owned file, then replace the symlink with one
65877+ that targets another user's file just after Apache "validates" the
65878+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65879+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65880+ will be in place for the group you specify. If the sysctl option
65881+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65882+ created.
65883+
65884+config GRKERNSEC_SYMLINKOWN_GID
65885+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65886+ depends on GRKERNSEC_SYMLINKOWN
65887+ default 1006
65888+ help
65889+ Setting this GID determines what group kernel-enforced
65890+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65891+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65892+
65893+config GRKERNSEC_FIFO
65894+ bool "FIFO restrictions"
65895+ default y if GRKERNSEC_CONFIG_AUTO
65896+ help
65897+ If you say Y here, users will not be able to write to FIFOs they don't
65898+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65899+ the FIFO is the same owner of the directory it's held in. If the sysctl
65900+ option is enabled, a sysctl option with name "fifo_restrictions" is
65901+ created.
65902+
65903+config GRKERNSEC_SYSFS_RESTRICT
65904+ bool "Sysfs/debugfs restriction"
65905+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65906+ depends on SYSFS
65907+ help
65908+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65909+ any filesystem normally mounted under it (e.g. debugfs) will be
65910+ mostly accessible only by root. These filesystems generally provide access
65911+ to hardware and debug information that isn't appropriate for unprivileged
65912+ users of the system. Sysfs and debugfs have also become a large source
65913+ of new vulnerabilities, ranging from infoleaks to local compromise.
65914+ There has been very little oversight with an eye toward security involved
65915+ in adding new exporters of information to these filesystems, so their
65916+ use is discouraged.
65917+ For reasons of compatibility, a few directories have been whitelisted
65918+ for access by non-root users:
65919+ /sys/fs/selinux
65920+ /sys/fs/fuse
65921+ /sys/devices/system/cpu
65922+
65923+config GRKERNSEC_ROFS
65924+ bool "Runtime read-only mount protection"
65925+ depends on SYSCTL
65926+ help
65927+ If you say Y here, a sysctl option with name "romount_protect" will
65928+ be created. By setting this option to 1 at runtime, filesystems
65929+ will be protected in the following ways:
65930+ * No new writable mounts will be allowed
65931+ * Existing read-only mounts won't be able to be remounted read/write
65932+ * Write operations will be denied on all block devices
65933+ This option acts independently of grsec_lock: once it is set to 1,
65934+ it cannot be turned off. Therefore, please be mindful of the resulting
65935+ behavior if this option is enabled in an init script on a read-only
65936+ filesystem.
65937+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65938+ and GRKERNSEC_IO should be enabled and module loading disabled via
65939+ config or at runtime.
65940+ This feature is mainly intended for secure embedded systems.
65941+
65942+
65943+config GRKERNSEC_DEVICE_SIDECHANNEL
65944+ bool "Eliminate stat/notify-based device sidechannels"
65945+ default y if GRKERNSEC_CONFIG_AUTO
65946+ help
65947+ If you say Y here, timing analyses on block or character
65948+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65949+ will be thwarted for unprivileged users. If a process without
65950+ CAP_MKNOD stats such a device, the last access and last modify times
65951+ will match the device's create time. No access or modify events
65952+ will be triggered through inotify/dnotify/fanotify for such devices.
65953+ This feature will prevent attacks that may at a minimum
65954+ allow an attacker to determine the administrator's password length.
65955+
65956+config GRKERNSEC_CHROOT
65957+ bool "Chroot jail restrictions"
65958+ default y if GRKERNSEC_CONFIG_AUTO
65959+ help
65960+ If you say Y here, you will be able to choose several options that will
65961+ make breaking out of a chrooted jail much more difficult. If you
65962+ encounter no software incompatibilities with the following options, it
65963+ is recommended that you enable each one.
65964+
65965+ Note that the chroot restrictions are not intended to apply to "chroots"
65966+ to directories that are simple bind mounts of the global root filesystem.
65967+ For several other reasons, a user shouldn't expect any significant
65968+ security by performing such a chroot.
65969+
65970+config GRKERNSEC_CHROOT_MOUNT
65971+ bool "Deny mounts"
65972+ default y if GRKERNSEC_CONFIG_AUTO
65973+ depends on GRKERNSEC_CHROOT
65974+ help
65975+ If you say Y here, processes inside a chroot will not be able to
65976+ mount or remount filesystems. If the sysctl option is enabled, a
65977+ sysctl option with name "chroot_deny_mount" is created.
65978+
65979+config GRKERNSEC_CHROOT_DOUBLE
65980+ bool "Deny double-chroots"
65981+ default y if GRKERNSEC_CONFIG_AUTO
65982+ depends on GRKERNSEC_CHROOT
65983+ help
65984+ If you say Y here, processes inside a chroot will not be able to chroot
65985+ again outside the chroot. This is a widely used method of breaking
65986+ out of a chroot jail and should not be allowed. If the sysctl
65987+ option is enabled, a sysctl option with name
65988+ "chroot_deny_chroot" is created.
65989+
65990+config GRKERNSEC_CHROOT_PIVOT
65991+ bool "Deny pivot_root in chroot"
65992+ default y if GRKERNSEC_CONFIG_AUTO
65993+ depends on GRKERNSEC_CHROOT
65994+ help
65995+ If you say Y here, processes inside a chroot will not be able to use
65996+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65997+ works similar to chroot in that it changes the root filesystem. This
65998+ function could be misused in a chrooted process to attempt to break out
65999+ of the chroot, and therefore should not be allowed. If the sysctl
66000+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66001+ created.
66002+
66003+config GRKERNSEC_CHROOT_CHDIR
66004+ bool "Enforce chdir(\"/\") on all chroots"
66005+ default y if GRKERNSEC_CONFIG_AUTO
66006+ depends on GRKERNSEC_CHROOT
66007+ help
66008+ If you say Y here, the current working directory of all newly-chrooted
66009+ applications will be set to the the root directory of the chroot.
66010+ The man page on chroot(2) states:
66011+ Note that this call does not change the current working
66012+ directory, so that `.' can be outside the tree rooted at
66013+ `/'. In particular, the super-user can escape from a
66014+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66015+
66016+ It is recommended that you say Y here, since it's not known to break
66017+ any software. If the sysctl option is enabled, a sysctl option with
66018+ name "chroot_enforce_chdir" is created.
66019+
66020+config GRKERNSEC_CHROOT_CHMOD
66021+ bool "Deny (f)chmod +s"
66022+ default y if GRKERNSEC_CONFIG_AUTO
66023+ depends on GRKERNSEC_CHROOT
66024+ help
66025+ If you say Y here, processes inside a chroot will not be able to chmod
66026+ or fchmod files to make them have suid or sgid bits. This protects
66027+ against another published method of breaking a chroot. If the sysctl
66028+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66029+ created.
66030+
66031+config GRKERNSEC_CHROOT_FCHDIR
66032+ bool "Deny fchdir out of chroot"
66033+ default y if GRKERNSEC_CONFIG_AUTO
66034+ depends on GRKERNSEC_CHROOT
66035+ help
66036+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66037+ to a file descriptor of the chrooting process that points to a directory
66038+ outside the filesystem will be stopped. If the sysctl option
66039+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66040+
66041+config GRKERNSEC_CHROOT_MKNOD
66042+ bool "Deny mknod"
66043+ default y if GRKERNSEC_CONFIG_AUTO
66044+ depends on GRKERNSEC_CHROOT
66045+ help
66046+ If you say Y here, processes inside a chroot will not be allowed to
66047+ mknod. The problem with using mknod inside a chroot is that it
66048+ would allow an attacker to create a device entry that is the same
66049+ as one on the physical root of your system, which could range from
66050+ anything from the console device to a device for your harddrive (which
66051+ they could then use to wipe the drive or steal data). It is recommended
66052+ that you say Y here, unless you run into software incompatibilities.
66053+ If the sysctl option is enabled, a sysctl option with name
66054+ "chroot_deny_mknod" is created.
66055+
66056+config GRKERNSEC_CHROOT_SHMAT
66057+ bool "Deny shmat() out of chroot"
66058+ default y if GRKERNSEC_CONFIG_AUTO
66059+ depends on GRKERNSEC_CHROOT
66060+ help
66061+ If you say Y here, processes inside a chroot will not be able to attach
66062+ to shared memory segments that were created outside of the chroot jail.
66063+ It is recommended that you say Y here. If the sysctl option is enabled,
66064+ a sysctl option with name "chroot_deny_shmat" is created.
66065+
66066+config GRKERNSEC_CHROOT_UNIX
66067+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66068+ default y if GRKERNSEC_CONFIG_AUTO
66069+ depends on GRKERNSEC_CHROOT
66070+ help
66071+ If you say Y here, processes inside a chroot will not be able to
66072+ connect to abstract (meaning not belonging to a filesystem) Unix
66073+ domain sockets that were bound outside of a chroot. It is recommended
66074+ that you say Y here. If the sysctl option is enabled, a sysctl option
66075+ with name "chroot_deny_unix" is created.
66076+
66077+config GRKERNSEC_CHROOT_FINDTASK
66078+ bool "Protect outside processes"
66079+ default y if GRKERNSEC_CONFIG_AUTO
66080+ depends on GRKERNSEC_CHROOT
66081+ help
66082+ If you say Y here, processes inside a chroot will not be able to
66083+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66084+ getsid, or view any process outside of the chroot. If the sysctl
66085+ option is enabled, a sysctl option with name "chroot_findtask" is
66086+ created.
66087+
66088+config GRKERNSEC_CHROOT_NICE
66089+ bool "Restrict priority changes"
66090+ default y if GRKERNSEC_CONFIG_AUTO
66091+ depends on GRKERNSEC_CHROOT
66092+ help
66093+ If you say Y here, processes inside a chroot will not be able to raise
66094+ the priority of processes in the chroot, or alter the priority of
66095+ processes outside the chroot. This provides more security than simply
66096+ removing CAP_SYS_NICE from the process' capability set. If the
66097+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66098+ is created.
66099+
66100+config GRKERNSEC_CHROOT_SYSCTL
66101+ bool "Deny sysctl writes"
66102+ default y if GRKERNSEC_CONFIG_AUTO
66103+ depends on GRKERNSEC_CHROOT
66104+ help
66105+ If you say Y here, an attacker in a chroot will not be able to
66106+ write to sysctl entries, either by sysctl(2) or through a /proc
66107+ interface. It is strongly recommended that you say Y here. If the
66108+ sysctl option is enabled, a sysctl option with name
66109+ "chroot_deny_sysctl" is created.
66110+
66111+config GRKERNSEC_CHROOT_CAPS
66112+ bool "Capability restrictions"
66113+ default y if GRKERNSEC_CONFIG_AUTO
66114+ depends on GRKERNSEC_CHROOT
66115+ help
66116+ If you say Y here, the capabilities on all processes within a
66117+ chroot jail will be lowered to stop module insertion, raw i/o,
66118+ system and net admin tasks, rebooting the system, modifying immutable
66119+ files, modifying IPC owned by another, and changing the system time.
66120+ This is left an option because it can break some apps. Disable this
66121+ if your chrooted apps are having problems performing those kinds of
66122+ tasks. If the sysctl option is enabled, a sysctl option with
66123+ name "chroot_caps" is created.
66124+
66125+config GRKERNSEC_CHROOT_INITRD
66126+ bool "Exempt initrd tasks from restrictions"
66127+ default y if GRKERNSEC_CONFIG_AUTO
66128+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66129+ help
66130+ If you say Y here, tasks started prior to init will be exempted from
66131+ grsecurity's chroot restrictions. This option is mainly meant to
66132+ resolve Plymouth's performing privileged operations unnecessarily
66133+ in a chroot.
66134+
66135+endmenu
66136+menu "Kernel Auditing"
66137+depends on GRKERNSEC
66138+
66139+config GRKERNSEC_AUDIT_GROUP
66140+ bool "Single group for auditing"
66141+ help
66142+ If you say Y here, the exec and chdir logging features will only operate
66143+ on a group you specify. This option is recommended if you only want to
66144+ watch certain users instead of having a large amount of logs from the
66145+ entire system. If the sysctl option is enabled, a sysctl option with
66146+ name "audit_group" is created.
66147+
66148+config GRKERNSEC_AUDIT_GID
66149+ int "GID for auditing"
66150+ depends on GRKERNSEC_AUDIT_GROUP
66151+ default 1007
66152+
66153+config GRKERNSEC_EXECLOG
66154+ bool "Exec logging"
66155+ help
66156+ If you say Y here, all execve() calls will be logged (since the
66157+ other exec*() calls are frontends to execve(), all execution
66158+ will be logged). Useful for shell-servers that like to keep track
66159+ of their users. If the sysctl option is enabled, a sysctl option with
66160+ name "exec_logging" is created.
66161+ WARNING: This option when enabled will produce a LOT of logs, especially
66162+ on an active system.
66163+
66164+config GRKERNSEC_RESLOG
66165+ bool "Resource logging"
66166+ default y if GRKERNSEC_CONFIG_AUTO
66167+ help
66168+ If you say Y here, all attempts to overstep resource limits will
66169+ be logged with the resource name, the requested size, and the current
66170+ limit. It is highly recommended that you say Y here. If the sysctl
66171+ option is enabled, a sysctl option with name "resource_logging" is
66172+ created. If the RBAC system is enabled, the sysctl value is ignored.
66173+
66174+config GRKERNSEC_CHROOT_EXECLOG
66175+ bool "Log execs within chroot"
66176+ help
66177+ If you say Y here, all executions inside a chroot jail will be logged
66178+ to syslog. This can cause a large amount of logs if certain
66179+ applications (eg. djb's daemontools) are installed on the system, and
66180+ is therefore left as an option. If the sysctl option is enabled, a
66181+ sysctl option with name "chroot_execlog" is created.
66182+
66183+config GRKERNSEC_AUDIT_PTRACE
66184+ bool "Ptrace logging"
66185+ help
66186+ If you say Y here, all attempts to attach to a process via ptrace
66187+ will be logged. If the sysctl option is enabled, a sysctl option
66188+ with name "audit_ptrace" is created.
66189+
66190+config GRKERNSEC_AUDIT_CHDIR
66191+ bool "Chdir logging"
66192+ help
66193+ If you say Y here, all chdir() calls will be logged. If the sysctl
66194+ option is enabled, a sysctl option with name "audit_chdir" is created.
66195+
66196+config GRKERNSEC_AUDIT_MOUNT
66197+ bool "(Un)Mount logging"
66198+ help
66199+ If you say Y here, all mounts and unmounts will be logged. If the
66200+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66201+ created.
66202+
66203+config GRKERNSEC_SIGNAL
66204+ bool "Signal logging"
66205+ default y if GRKERNSEC_CONFIG_AUTO
66206+ help
66207+ If you say Y here, certain important signals will be logged, such as
66208+ SIGSEGV, which will as a result inform you of when a error in a program
66209+ occurred, which in some cases could mean a possible exploit attempt.
66210+ If the sysctl option is enabled, a sysctl option with name
66211+ "signal_logging" is created.
66212+
66213+config GRKERNSEC_FORKFAIL
66214+ bool "Fork failure logging"
66215+ help
66216+ If you say Y here, all failed fork() attempts will be logged.
66217+ This could suggest a fork bomb, or someone attempting to overstep
66218+ their process limit. If the sysctl option is enabled, a sysctl option
66219+ with name "forkfail_logging" is created.
66220+
66221+config GRKERNSEC_TIME
66222+ bool "Time change logging"
66223+ default y if GRKERNSEC_CONFIG_AUTO
66224+ help
66225+ If you say Y here, any changes of the system clock will be logged.
66226+ If the sysctl option is enabled, a sysctl option with name
66227+ "timechange_logging" is created.
66228+
66229+config GRKERNSEC_PROC_IPADDR
66230+ bool "/proc/<pid>/ipaddr support"
66231+ default y if GRKERNSEC_CONFIG_AUTO
66232+ help
66233+ If you say Y here, a new entry will be added to each /proc/<pid>
66234+ directory that contains the IP address of the person using the task.
66235+ The IP is carried across local TCP and AF_UNIX stream sockets.
66236+ This information can be useful for IDS/IPSes to perform remote response
66237+ to a local attack. The entry is readable by only the owner of the
66238+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66239+ the RBAC system), and thus does not create privacy concerns.
66240+
66241+config GRKERNSEC_RWXMAP_LOG
66242+ bool 'Denied RWX mmap/mprotect logging'
66243+ default y if GRKERNSEC_CONFIG_AUTO
66244+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66245+ help
66246+ If you say Y here, calls to mmap() and mprotect() with explicit
66247+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66248+ denied by the PAX_MPROTECT feature. This feature will also
66249+ log other problematic scenarios that can occur when PAX_MPROTECT
66250+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66251+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66252+ is created.
66253+
66254+endmenu
66255+
66256+menu "Executable Protections"
66257+depends on GRKERNSEC
66258+
66259+config GRKERNSEC_DMESG
66260+ bool "Dmesg(8) restriction"
66261+ default y if GRKERNSEC_CONFIG_AUTO
66262+ help
66263+ If you say Y here, non-root users will not be able to use dmesg(8)
66264+ to view the contents of the kernel's circular log buffer.
66265+ The kernel's log buffer often contains kernel addresses and other
66266+ identifying information useful to an attacker in fingerprinting a
66267+ system for a targeted exploit.
66268+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66269+ created.
66270+
66271+config GRKERNSEC_HARDEN_PTRACE
66272+ bool "Deter ptrace-based process snooping"
66273+ default y if GRKERNSEC_CONFIG_AUTO
66274+ help
66275+ If you say Y here, TTY sniffers and other malicious monitoring
66276+ programs implemented through ptrace will be defeated. If you
66277+ have been using the RBAC system, this option has already been
66278+ enabled for several years for all users, with the ability to make
66279+ fine-grained exceptions.
66280+
66281+ This option only affects the ability of non-root users to ptrace
66282+ processes that are not a descendent of the ptracing process.
66283+ This means that strace ./binary and gdb ./binary will still work,
66284+ but attaching to arbitrary processes will not. If the sysctl
66285+ option is enabled, a sysctl option with name "harden_ptrace" is
66286+ created.
66287+
66288+config GRKERNSEC_PTRACE_READEXEC
66289+ bool "Require read access to ptrace sensitive binaries"
66290+ default y if GRKERNSEC_CONFIG_AUTO
66291+ help
66292+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66293+ binaries. This option is useful in environments that
66294+ remove the read bits (e.g. file mode 4711) from suid binaries to
66295+ prevent infoleaking of their contents. This option adds
66296+ consistency to the use of that file mode, as the binary could normally
66297+ be read out when run without privileges while ptracing.
66298+
66299+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66300+ is created.
66301+
66302+config GRKERNSEC_SETXID
66303+ bool "Enforce consistent multithreaded privileges"
66304+ default y if GRKERNSEC_CONFIG_AUTO
66305+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66306+ help
66307+ If you say Y here, a change from a root uid to a non-root uid
66308+ in a multithreaded application will cause the resulting uids,
66309+ gids, supplementary groups, and capabilities in that thread
66310+ to be propagated to the other threads of the process. In most
66311+ cases this is unnecessary, as glibc will emulate this behavior
66312+ on behalf of the application. Other libcs do not act in the
66313+ same way, allowing the other threads of the process to continue
66314+ running with root privileges. If the sysctl option is enabled,
66315+ a sysctl option with name "consistent_setxid" is created.
66316+
66317+config GRKERNSEC_HARDEN_IPC
66318+ bool "Disallow access to overly-permissive IPC objects"
66319+ default y if GRKERNSEC_CONFIG_AUTO
66320+ depends on SYSVIPC
66321+ help
66322+ If you say Y here, access to overly-permissive IPC objects (shared
66323+ memory, message queues, and semaphores) will be denied for processes
66324+ given the following criteria beyond normal permission checks:
66325+ 1) If the IPC object is world-accessible and the euid doesn't match
66326+ that of the creator or current uid for the IPC object
66327+ 2) If the IPC object is group-accessible and the egid doesn't
66328+ match that of the creator or current gid for the IPC object
66329+ It's a common error to grant too much permission to these objects,
66330+ with impact ranging from denial of service and information leaking to
66331+ privilege escalation. This feature was developed in response to
66332+ research by Tim Brown:
66333+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66334+ who found hundreds of such insecure usages. Processes with
66335+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66336+ If the sysctl option is enabled, a sysctl option with name
66337+ "harden_ipc" is created.
66338+
66339+config GRKERNSEC_TPE
66340+ bool "Trusted Path Execution (TPE)"
66341+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66342+ help
66343+ If you say Y here, you will be able to choose a gid to add to the
66344+ supplementary groups of users you want to mark as "untrusted."
66345+ These users will not be able to execute any files that are not in
66346+ root-owned directories writable only by root. If the sysctl option
66347+ is enabled, a sysctl option with name "tpe" is created.
66348+
66349+config GRKERNSEC_TPE_ALL
66350+ bool "Partially restrict all non-root users"
66351+ depends on GRKERNSEC_TPE
66352+ help
66353+ If you say Y here, all non-root users will be covered under
66354+ a weaker TPE restriction. This is separate from, and in addition to,
66355+ the main TPE options that you have selected elsewhere. Thus, if a
66356+ "trusted" GID is chosen, this restriction applies to even that GID.
66357+ Under this restriction, all non-root users will only be allowed to
66358+ execute files in directories they own that are not group or
66359+ world-writable, or in directories owned by root and writable only by
66360+ root. If the sysctl option is enabled, a sysctl option with name
66361+ "tpe_restrict_all" is created.
66362+
66363+config GRKERNSEC_TPE_INVERT
66364+ bool "Invert GID option"
66365+ depends on GRKERNSEC_TPE
66366+ help
66367+ If you say Y here, the group you specify in the TPE configuration will
66368+ decide what group TPE restrictions will be *disabled* for. This
66369+ option is useful if you want TPE restrictions to be applied to most
66370+ users on the system. If the sysctl option is enabled, a sysctl option
66371+ with name "tpe_invert" is created. Unlike other sysctl options, this
66372+ entry will default to on for backward-compatibility.
66373+
66374+config GRKERNSEC_TPE_GID
66375+ int
66376+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66377+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66378+
66379+config GRKERNSEC_TPE_UNTRUSTED_GID
66380+ int "GID for TPE-untrusted users"
66381+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66382+ default 1005
66383+ help
66384+ Setting this GID determines what group TPE restrictions will be
66385+ *enabled* for. If the sysctl option is enabled, a sysctl option
66386+ with name "tpe_gid" is created.
66387+
66388+config GRKERNSEC_TPE_TRUSTED_GID
66389+ int "GID for TPE-trusted users"
66390+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66391+ default 1005
66392+ help
66393+ Setting this GID determines what group TPE restrictions will be
66394+ *disabled* for. If the sysctl option is enabled, a sysctl option
66395+ with name "tpe_gid" is created.
66396+
66397+endmenu
66398+menu "Network Protections"
66399+depends on GRKERNSEC
66400+
66401+config GRKERNSEC_RANDNET
66402+ bool "Larger entropy pools"
66403+ default y if GRKERNSEC_CONFIG_AUTO
66404+ help
66405+ If you say Y here, the entropy pools used for many features of Linux
66406+ and grsecurity will be doubled in size. Since several grsecurity
66407+ features use additional randomness, it is recommended that you say Y
66408+ here. Saying Y here has a similar effect as modifying
66409+ /proc/sys/kernel/random/poolsize.
66410+
66411+config GRKERNSEC_BLACKHOLE
66412+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66413+ default y if GRKERNSEC_CONFIG_AUTO
66414+ depends on NET
66415+ help
66416+ If you say Y here, neither TCP resets nor ICMP
66417+ destination-unreachable packets will be sent in response to packets
66418+ sent to ports for which no associated listening process exists.
66419+ This feature supports both IPV4 and IPV6 and exempts the
66420+ loopback interface from blackholing. Enabling this feature
66421+ makes a host more resilient to DoS attacks and reduces network
66422+ visibility against scanners.
66423+
66424+ The blackhole feature as-implemented is equivalent to the FreeBSD
66425+ blackhole feature, as it prevents RST responses to all packets, not
66426+ just SYNs. Under most application behavior this causes no
66427+ problems, but applications (like haproxy) may not close certain
66428+ connections in a way that cleanly terminates them on the remote
66429+ end, leaving the remote host in LAST_ACK state. Because of this
66430+ side-effect and to prevent intentional LAST_ACK DoSes, this
66431+ feature also adds automatic mitigation against such attacks.
66432+ The mitigation drastically reduces the amount of time a socket
66433+ can spend in LAST_ACK state. If you're using haproxy and not
66434+ all servers it connects to have this option enabled, consider
66435+ disabling this feature on the haproxy host.
66436+
66437+ If the sysctl option is enabled, two sysctl options with names
66438+ "ip_blackhole" and "lastack_retries" will be created.
66439+ While "ip_blackhole" takes the standard zero/non-zero on/off
66440+ toggle, "lastack_retries" uses the same kinds of values as
66441+ "tcp_retries1" and "tcp_retries2". The default value of 4
66442+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66443+ state.
66444+
66445+config GRKERNSEC_NO_SIMULT_CONNECT
66446+ bool "Disable TCP Simultaneous Connect"
66447+ default y if GRKERNSEC_CONFIG_AUTO
66448+ depends on NET
66449+ help
66450+ If you say Y here, a feature by Willy Tarreau will be enabled that
66451+ removes a weakness in Linux's strict implementation of TCP that
66452+ allows two clients to connect to each other without either entering
66453+ a listening state. The weakness allows an attacker to easily prevent
66454+ a client from connecting to a known server provided the source port
66455+ for the connection is guessed correctly.
66456+
66457+ As the weakness could be used to prevent an antivirus or IPS from
66458+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66459+ it should be eliminated by enabling this option. Though Linux is
66460+ one of few operating systems supporting simultaneous connect, it
66461+ has no legitimate use in practice and is rarely supported by firewalls.
66462+
66463+config GRKERNSEC_SOCKET
66464+ bool "Socket restrictions"
66465+ depends on NET
66466+ help
66467+ If you say Y here, you will be able to choose from several options.
66468+ If you assign a GID on your system and add it to the supplementary
66469+ groups of users you want to restrict socket access to, this patch
66470+ will perform up to three things, based on the option(s) you choose.
66471+
66472+config GRKERNSEC_SOCKET_ALL
66473+ bool "Deny any sockets to group"
66474+ depends on GRKERNSEC_SOCKET
66475+ help
66476+ If you say Y here, you will be able to choose a GID of whose users will
66477+ be unable to connect to other hosts from your machine or run server
66478+ applications from your machine. If the sysctl option is enabled, a
66479+ sysctl option with name "socket_all" is created.
66480+
66481+config GRKERNSEC_SOCKET_ALL_GID
66482+ int "GID to deny all sockets for"
66483+ depends on GRKERNSEC_SOCKET_ALL
66484+ default 1004
66485+ help
66486+ Here you can choose the GID to disable socket access for. Remember to
66487+ add the users you want socket access disabled for to the GID
66488+ specified here. If the sysctl option is enabled, a sysctl option
66489+ with name "socket_all_gid" is created.
66490+
66491+config GRKERNSEC_SOCKET_CLIENT
66492+ bool "Deny client sockets to group"
66493+ depends on GRKERNSEC_SOCKET
66494+ help
66495+ If you say Y here, you will be able to choose a GID of whose users will
66496+ be unable to connect to other hosts from your machine, but will be
66497+ able to run servers. If this option is enabled, all users in the group
66498+ you specify will have to use passive mode when initiating ftp transfers
66499+ from the shell on your machine. If the sysctl option is enabled, a
66500+ sysctl option with name "socket_client" is created.
66501+
66502+config GRKERNSEC_SOCKET_CLIENT_GID
66503+ int "GID to deny client sockets for"
66504+ depends on GRKERNSEC_SOCKET_CLIENT
66505+ default 1003
66506+ help
66507+ Here you can choose the GID to disable client socket access for.
66508+ Remember to add the users you want client socket access disabled for to
66509+ the GID specified here. If the sysctl option is enabled, a sysctl
66510+ option with name "socket_client_gid" is created.
66511+
66512+config GRKERNSEC_SOCKET_SERVER
66513+ bool "Deny server sockets to group"
66514+ depends on GRKERNSEC_SOCKET
66515+ help
66516+ If you say Y here, you will be able to choose a GID of whose users will
66517+ be unable to run server applications from your machine. If the sysctl
66518+ option is enabled, a sysctl option with name "socket_server" is created.
66519+
66520+config GRKERNSEC_SOCKET_SERVER_GID
66521+ int "GID to deny server sockets for"
66522+ depends on GRKERNSEC_SOCKET_SERVER
66523+ default 1002
66524+ help
66525+ Here you can choose the GID to disable server socket access for.
66526+ Remember to add the users you want server socket access disabled for to
66527+ the GID specified here. If the sysctl option is enabled, a sysctl
66528+ option with name "socket_server_gid" is created.
66529+
66530+endmenu
66531+
66532+menu "Physical Protections"
66533+depends on GRKERNSEC
66534+
66535+config GRKERNSEC_DENYUSB
66536+ bool "Deny new USB connections after toggle"
66537+ default y if GRKERNSEC_CONFIG_AUTO
66538+ depends on SYSCTL && USB_SUPPORT
66539+ help
66540+ If you say Y here, a new sysctl option with name "deny_new_usb"
66541+ will be created. Setting its value to 1 will prevent any new
66542+ USB devices from being recognized by the OS. Any attempted USB
66543+ device insertion will be logged. This option is intended to be
66544+ used against custom USB devices designed to exploit vulnerabilities
66545+ in various USB device drivers.
66546+
66547+ For greatest effectiveness, this sysctl should be set after any
66548+ relevant init scripts. This option is safe to enable in distros
66549+ as each user can choose whether or not to toggle the sysctl.
66550+
66551+config GRKERNSEC_DENYUSB_FORCE
66552+ bool "Reject all USB devices not connected at boot"
66553+ select USB
66554+ depends on GRKERNSEC_DENYUSB
66555+ help
66556+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66557+ that doesn't involve a sysctl entry. This option should only be
66558+ enabled if you're sure you want to deny all new USB connections
66559+ at runtime and don't want to modify init scripts. This should not
66560+ be enabled by distros. It forces the core USB code to be built
66561+ into the kernel image so that all devices connected at boot time
66562+ can be recognized and new USB device connections can be prevented
66563+ prior to init running.
66564+
66565+endmenu
66566+
66567+menu "Sysctl Support"
66568+depends on GRKERNSEC && SYSCTL
66569+
66570+config GRKERNSEC_SYSCTL
66571+ bool "Sysctl support"
66572+ default y if GRKERNSEC_CONFIG_AUTO
66573+ help
66574+ If you say Y here, you will be able to change the options that
66575+ grsecurity runs with at bootup, without having to recompile your
66576+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66577+ to enable (1) or disable (0) various features. All the sysctl entries
66578+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66579+ All features enabled in the kernel configuration are disabled at boot
66580+ if you do not say Y to the "Turn on features by default" option.
66581+ All options should be set at startup, and the grsec_lock entry should
66582+ be set to a non-zero value after all the options are set.
66583+ *THIS IS EXTREMELY IMPORTANT*
66584+
66585+config GRKERNSEC_SYSCTL_DISTRO
66586+ bool "Extra sysctl support for distro makers (READ HELP)"
66587+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66588+ help
66589+ If you say Y here, additional sysctl options will be created
66590+ for features that affect processes running as root. Therefore,
66591+ it is critical when using this option that the grsec_lock entry be
66592+ enabled after boot. Only distros with prebuilt kernel packages
66593+ with this option enabled that can ensure grsec_lock is enabled
66594+ after boot should use this option.
66595+ *Failure to set grsec_lock after boot makes all grsec features
66596+ this option covers useless*
66597+
66598+ Currently this option creates the following sysctl entries:
66599+ "Disable Privileged I/O": "disable_priv_io"
66600+
66601+config GRKERNSEC_SYSCTL_ON
66602+ bool "Turn on features by default"
66603+ default y if GRKERNSEC_CONFIG_AUTO
66604+ depends on GRKERNSEC_SYSCTL
66605+ help
66606+ If you say Y here, instead of having all features enabled in the
66607+ kernel configuration disabled at boot time, the features will be
66608+ enabled at boot time. It is recommended you say Y here unless
66609+ there is some reason you would want all sysctl-tunable features to
66610+ be disabled by default. As mentioned elsewhere, it is important
66611+ to enable the grsec_lock entry once you have finished modifying
66612+ the sysctl entries.
66613+
66614+endmenu
66615+menu "Logging Options"
66616+depends on GRKERNSEC
66617+
66618+config GRKERNSEC_FLOODTIME
66619+ int "Seconds in between log messages (minimum)"
66620+ default 10
66621+ help
66622+ This option allows you to enforce the number of seconds between
66623+ grsecurity log messages. The default should be suitable for most
66624+ people, however, if you choose to change it, choose a value small enough
66625+ to allow informative logs to be produced, but large enough to
66626+ prevent flooding.
66627+
66628+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66629+ any rate limiting on grsecurity log messages.
66630+
66631+config GRKERNSEC_FLOODBURST
66632+ int "Number of messages in a burst (maximum)"
66633+ default 6
66634+ help
66635+ This option allows you to choose the maximum number of messages allowed
66636+ within the flood time interval you chose in a separate option. The
66637+ default should be suitable for most people, however if you find that
66638+ many of your logs are being interpreted as flooding, you may want to
66639+ raise this value.
66640+
66641+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66642+ any rate limiting on grsecurity log messages.
66643+
66644+endmenu
66645diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66646new file mode 100644
66647index 0000000..30ababb
66648--- /dev/null
66649+++ b/grsecurity/Makefile
66650@@ -0,0 +1,54 @@
66651+# grsecurity – access control and security hardening for Linux
66652+# All code in this directory and various hooks located throughout the Linux kernel are
66653+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66654+# http://www.grsecurity.net spender@grsecurity.net
66655+#
66656+# This program is free software; you can redistribute it and/or
66657+# modify it under the terms of the GNU General Public License version 2
66658+# as published by the Free Software Foundation.
66659+#
66660+# This program is distributed in the hope that it will be useful,
66661+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66662+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66663+# GNU General Public License for more details.
66664+#
66665+# You should have received a copy of the GNU General Public License
66666+# along with this program; if not, write to the Free Software
66667+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66668+
66669+KBUILD_CFLAGS += -Werror
66670+
66671+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66672+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66673+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66674+ grsec_usb.o grsec_ipc.o grsec_proc.o
66675+
66676+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66677+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66678+ gracl_learn.o grsec_log.o gracl_policy.o
66679+ifdef CONFIG_COMPAT
66680+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66681+endif
66682+
66683+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66684+
66685+ifdef CONFIG_NET
66686+obj-y += grsec_sock.o
66687+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66688+endif
66689+
66690+ifndef CONFIG_GRKERNSEC
66691+obj-y += grsec_disabled.o
66692+endif
66693+
66694+ifdef CONFIG_GRKERNSEC_HIDESYM
66695+extra-y := grsec_hidesym.o
66696+$(obj)/grsec_hidesym.o:
66697+ @-chmod -f 500 /boot
66698+ @-chmod -f 500 /lib/modules
66699+ @-chmod -f 500 /lib64/modules
66700+ @-chmod -f 500 /lib32/modules
66701+ @-chmod -f 700 .
66702+ @-chmod -f 700 $(objtree)
66703+ @echo ' grsec: protected kernel image paths'
66704+endif
66705diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66706new file mode 100644
66707index 0000000..e56396f
66708--- /dev/null
66709+++ b/grsecurity/gracl.c
66710@@ -0,0 +1,2679 @@
66711+#include <linux/kernel.h>
66712+#include <linux/module.h>
66713+#include <linux/sched.h>
66714+#include <linux/mm.h>
66715+#include <linux/file.h>
66716+#include <linux/fs.h>
66717+#include <linux/namei.h>
66718+#include <linux/mount.h>
66719+#include <linux/tty.h>
66720+#include <linux/proc_fs.h>
66721+#include <linux/lglock.h>
66722+#include <linux/slab.h>
66723+#include <linux/vmalloc.h>
66724+#include <linux/types.h>
66725+#include <linux/sysctl.h>
66726+#include <linux/netdevice.h>
66727+#include <linux/ptrace.h>
66728+#include <linux/gracl.h>
66729+#include <linux/gralloc.h>
66730+#include <linux/security.h>
66731+#include <linux/grinternal.h>
66732+#include <linux/pid_namespace.h>
66733+#include <linux/stop_machine.h>
66734+#include <linux/fdtable.h>
66735+#include <linux/percpu.h>
66736+#include <linux/lglock.h>
66737+#include <linux/hugetlb.h>
66738+#include <linux/posix-timers.h>
66739+#include <linux/prefetch.h>
66740+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66741+#include <linux/magic.h>
66742+#include <linux/pagemap.h>
66743+#include "../fs/btrfs/async-thread.h"
66744+#include "../fs/btrfs/ctree.h"
66745+#include "../fs/btrfs/btrfs_inode.h"
66746+#endif
66747+#include "../fs/mount.h"
66748+
66749+#include <asm/uaccess.h>
66750+#include <asm/errno.h>
66751+#include <asm/mman.h>
66752+
66753+#define FOR_EACH_ROLE_START(role) \
66754+ role = running_polstate.role_list; \
66755+ while (role) {
66756+
66757+#define FOR_EACH_ROLE_END(role) \
66758+ role = role->prev; \
66759+ }
66760+
66761+extern struct path gr_real_root;
66762+
66763+static struct gr_policy_state running_polstate;
66764+struct gr_policy_state *polstate = &running_polstate;
66765+extern struct gr_alloc_state *current_alloc_state;
66766+
66767+extern char *gr_shared_page[4];
66768+DEFINE_RWLOCK(gr_inode_lock);
66769+
66770+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66771+
66772+#ifdef CONFIG_NET
66773+extern struct vfsmount *sock_mnt;
66774+#endif
66775+
66776+extern struct vfsmount *pipe_mnt;
66777+extern struct vfsmount *shm_mnt;
66778+
66779+#ifdef CONFIG_HUGETLBFS
66780+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66781+#endif
66782+
66783+extern u16 acl_sp_role_value;
66784+extern struct acl_object_label *fakefs_obj_rw;
66785+extern struct acl_object_label *fakefs_obj_rwx;
66786+
66787+int gr_acl_is_enabled(void)
66788+{
66789+ return (gr_status & GR_READY);
66790+}
66791+
66792+void gr_enable_rbac_system(void)
66793+{
66794+ pax_open_kernel();
66795+ gr_status |= GR_READY;
66796+ pax_close_kernel();
66797+}
66798+
66799+int gr_rbac_disable(void *unused)
66800+{
66801+ pax_open_kernel();
66802+ gr_status &= ~GR_READY;
66803+ pax_close_kernel();
66804+
66805+ return 0;
66806+}
66807+
66808+static inline dev_t __get_dev(const struct dentry *dentry)
66809+{
66810+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66811+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66812+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66813+ else
66814+#endif
66815+ return dentry->d_sb->s_dev;
66816+}
66817+
66818+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66819+{
66820+ return __get_dev(dentry);
66821+}
66822+
66823+static char gr_task_roletype_to_char(struct task_struct *task)
66824+{
66825+ switch (task->role->roletype &
66826+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66827+ GR_ROLE_SPECIAL)) {
66828+ case GR_ROLE_DEFAULT:
66829+ return 'D';
66830+ case GR_ROLE_USER:
66831+ return 'U';
66832+ case GR_ROLE_GROUP:
66833+ return 'G';
66834+ case GR_ROLE_SPECIAL:
66835+ return 'S';
66836+ }
66837+
66838+ return 'X';
66839+}
66840+
66841+char gr_roletype_to_char(void)
66842+{
66843+ return gr_task_roletype_to_char(current);
66844+}
66845+
66846+__inline__ int
66847+gr_acl_tpe_check(void)
66848+{
66849+ if (unlikely(!(gr_status & GR_READY)))
66850+ return 0;
66851+ if (current->role->roletype & GR_ROLE_TPE)
66852+ return 1;
66853+ else
66854+ return 0;
66855+}
66856+
66857+int
66858+gr_handle_rawio(const struct inode *inode)
66859+{
66860+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66861+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66862+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66863+ !capable(CAP_SYS_RAWIO))
66864+ return 1;
66865+#endif
66866+ return 0;
66867+}
66868+
66869+int
66870+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66871+{
66872+ if (likely(lena != lenb))
66873+ return 0;
66874+
66875+ return !memcmp(a, b, lena);
66876+}
66877+
66878+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66879+{
66880+ *buflen -= namelen;
66881+ if (*buflen < 0)
66882+ return -ENAMETOOLONG;
66883+ *buffer -= namelen;
66884+ memcpy(*buffer, str, namelen);
66885+ return 0;
66886+}
66887+
66888+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66889+{
66890+ return prepend(buffer, buflen, name->name, name->len);
66891+}
66892+
66893+static int prepend_path(const struct path *path, struct path *root,
66894+ char **buffer, int *buflen)
66895+{
66896+ struct dentry *dentry = path->dentry;
66897+ struct vfsmount *vfsmnt = path->mnt;
66898+ struct mount *mnt = real_mount(vfsmnt);
66899+ bool slash = false;
66900+ int error = 0;
66901+
66902+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66903+ struct dentry * parent;
66904+
66905+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66906+ /* Global root? */
66907+ if (!mnt_has_parent(mnt)) {
66908+ goto out;
66909+ }
66910+ dentry = mnt->mnt_mountpoint;
66911+ mnt = mnt->mnt_parent;
66912+ vfsmnt = &mnt->mnt;
66913+ continue;
66914+ }
66915+ parent = dentry->d_parent;
66916+ prefetch(parent);
66917+ spin_lock(&dentry->d_lock);
66918+ error = prepend_name(buffer, buflen, &dentry->d_name);
66919+ spin_unlock(&dentry->d_lock);
66920+ if (!error)
66921+ error = prepend(buffer, buflen, "/", 1);
66922+ if (error)
66923+ break;
66924+
66925+ slash = true;
66926+ dentry = parent;
66927+ }
66928+
66929+out:
66930+ if (!error && !slash)
66931+ error = prepend(buffer, buflen, "/", 1);
66932+
66933+ return error;
66934+}
66935+
66936+/* this must be called with mount_lock and rename_lock held */
66937+
66938+static char *__our_d_path(const struct path *path, struct path *root,
66939+ char *buf, int buflen)
66940+{
66941+ char *res = buf + buflen;
66942+ int error;
66943+
66944+ prepend(&res, &buflen, "\0", 1);
66945+ error = prepend_path(path, root, &res, &buflen);
66946+ if (error)
66947+ return ERR_PTR(error);
66948+
66949+ return res;
66950+}
66951+
66952+static char *
66953+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66954+{
66955+ char *retval;
66956+
66957+ retval = __our_d_path(path, root, buf, buflen);
66958+ if (unlikely(IS_ERR(retval)))
66959+ retval = strcpy(buf, "<path too long>");
66960+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66961+ retval[1] = '\0';
66962+
66963+ return retval;
66964+}
66965+
66966+static char *
66967+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66968+ char *buf, int buflen)
66969+{
66970+ struct path path;
66971+ char *res;
66972+
66973+ path.dentry = (struct dentry *)dentry;
66974+ path.mnt = (struct vfsmount *)vfsmnt;
66975+
66976+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66977+ by the RBAC system */
66978+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66979+
66980+ return res;
66981+}
66982+
66983+static char *
66984+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66985+ char *buf, int buflen)
66986+{
66987+ char *res;
66988+ struct path path;
66989+ struct path root;
66990+ struct task_struct *reaper = init_pid_ns.child_reaper;
66991+
66992+ path.dentry = (struct dentry *)dentry;
66993+ path.mnt = (struct vfsmount *)vfsmnt;
66994+
66995+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66996+ get_fs_root(reaper->fs, &root);
66997+
66998+ read_seqlock_excl(&mount_lock);
66999+ write_seqlock(&rename_lock);
67000+ res = gen_full_path(&path, &root, buf, buflen);
67001+ write_sequnlock(&rename_lock);
67002+ read_sequnlock_excl(&mount_lock);
67003+
67004+ path_put(&root);
67005+ return res;
67006+}
67007+
67008+char *
67009+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67010+{
67011+ char *ret;
67012+ read_seqlock_excl(&mount_lock);
67013+ write_seqlock(&rename_lock);
67014+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67015+ PAGE_SIZE);
67016+ write_sequnlock(&rename_lock);
67017+ read_sequnlock_excl(&mount_lock);
67018+ return ret;
67019+}
67020+
67021+static char *
67022+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67023+{
67024+ char *ret;
67025+ char *buf;
67026+ int buflen;
67027+
67028+ read_seqlock_excl(&mount_lock);
67029+ write_seqlock(&rename_lock);
67030+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67031+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67032+ buflen = (int)(ret - buf);
67033+ if (buflen >= 5)
67034+ prepend(&ret, &buflen, "/proc", 5);
67035+ else
67036+ ret = strcpy(buf, "<path too long>");
67037+ write_sequnlock(&rename_lock);
67038+ read_sequnlock_excl(&mount_lock);
67039+ return ret;
67040+}
67041+
67042+char *
67043+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67044+{
67045+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67046+ PAGE_SIZE);
67047+}
67048+
67049+char *
67050+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67051+{
67052+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67053+ PAGE_SIZE);
67054+}
67055+
67056+char *
67057+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67058+{
67059+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67060+ PAGE_SIZE);
67061+}
67062+
67063+char *
67064+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67065+{
67066+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67067+ PAGE_SIZE);
67068+}
67069+
67070+char *
67071+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67072+{
67073+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67074+ PAGE_SIZE);
67075+}
67076+
67077+__inline__ __u32
67078+to_gr_audit(const __u32 reqmode)
67079+{
67080+ /* masks off auditable permission flags, then shifts them to create
67081+ auditing flags, and adds the special case of append auditing if
67082+ we're requesting write */
67083+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67084+}
67085+
67086+struct acl_role_label *
67087+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67088+ const gid_t gid)
67089+{
67090+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67091+ struct acl_role_label *match;
67092+ struct role_allowed_ip *ipp;
67093+ unsigned int x;
67094+ u32 curr_ip = task->signal->saved_ip;
67095+
67096+ match = state->acl_role_set.r_hash[index];
67097+
67098+ while (match) {
67099+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67100+ for (x = 0; x < match->domain_child_num; x++) {
67101+ if (match->domain_children[x] == uid)
67102+ goto found;
67103+ }
67104+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67105+ break;
67106+ match = match->next;
67107+ }
67108+found:
67109+ if (match == NULL) {
67110+ try_group:
67111+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67112+ match = state->acl_role_set.r_hash[index];
67113+
67114+ while (match) {
67115+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67116+ for (x = 0; x < match->domain_child_num; x++) {
67117+ if (match->domain_children[x] == gid)
67118+ goto found2;
67119+ }
67120+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67121+ break;
67122+ match = match->next;
67123+ }
67124+found2:
67125+ if (match == NULL)
67126+ match = state->default_role;
67127+ if (match->allowed_ips == NULL)
67128+ return match;
67129+ else {
67130+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67131+ if (likely
67132+ ((ntohl(curr_ip) & ipp->netmask) ==
67133+ (ntohl(ipp->addr) & ipp->netmask)))
67134+ return match;
67135+ }
67136+ match = state->default_role;
67137+ }
67138+ } else if (match->allowed_ips == NULL) {
67139+ return match;
67140+ } else {
67141+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67142+ if (likely
67143+ ((ntohl(curr_ip) & ipp->netmask) ==
67144+ (ntohl(ipp->addr) & ipp->netmask)))
67145+ return match;
67146+ }
67147+ goto try_group;
67148+ }
67149+
67150+ return match;
67151+}
67152+
67153+static struct acl_role_label *
67154+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67155+ const gid_t gid)
67156+{
67157+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67158+}
67159+
67160+struct acl_subject_label *
67161+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67162+ const struct acl_role_label *role)
67163+{
67164+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67165+ struct acl_subject_label *match;
67166+
67167+ match = role->subj_hash[index];
67168+
67169+ while (match && (match->inode != ino || match->device != dev ||
67170+ (match->mode & GR_DELETED))) {
67171+ match = match->next;
67172+ }
67173+
67174+ if (match && !(match->mode & GR_DELETED))
67175+ return match;
67176+ else
67177+ return NULL;
67178+}
67179+
67180+struct acl_subject_label *
67181+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67182+ const struct acl_role_label *role)
67183+{
67184+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67185+ struct acl_subject_label *match;
67186+
67187+ match = role->subj_hash[index];
67188+
67189+ while (match && (match->inode != ino || match->device != dev ||
67190+ !(match->mode & GR_DELETED))) {
67191+ match = match->next;
67192+ }
67193+
67194+ if (match && (match->mode & GR_DELETED))
67195+ return match;
67196+ else
67197+ return NULL;
67198+}
67199+
67200+static struct acl_object_label *
67201+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67202+ const struct acl_subject_label *subj)
67203+{
67204+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67205+ struct acl_object_label *match;
67206+
67207+ match = subj->obj_hash[index];
67208+
67209+ while (match && (match->inode != ino || match->device != dev ||
67210+ (match->mode & GR_DELETED))) {
67211+ match = match->next;
67212+ }
67213+
67214+ if (match && !(match->mode & GR_DELETED))
67215+ return match;
67216+ else
67217+ return NULL;
67218+}
67219+
67220+static struct acl_object_label *
67221+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67222+ const struct acl_subject_label *subj)
67223+{
67224+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67225+ struct acl_object_label *match;
67226+
67227+ match = subj->obj_hash[index];
67228+
67229+ while (match && (match->inode != ino || match->device != dev ||
67230+ !(match->mode & GR_DELETED))) {
67231+ match = match->next;
67232+ }
67233+
67234+ if (match && (match->mode & GR_DELETED))
67235+ return match;
67236+
67237+ match = subj->obj_hash[index];
67238+
67239+ while (match && (match->inode != ino || match->device != dev ||
67240+ (match->mode & GR_DELETED))) {
67241+ match = match->next;
67242+ }
67243+
67244+ if (match && !(match->mode & GR_DELETED))
67245+ return match;
67246+ else
67247+ return NULL;
67248+}
67249+
67250+struct name_entry *
67251+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67252+{
67253+ unsigned int len = strlen(name);
67254+ unsigned int key = full_name_hash(name, len);
67255+ unsigned int index = key % state->name_set.n_size;
67256+ struct name_entry *match;
67257+
67258+ match = state->name_set.n_hash[index];
67259+
67260+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67261+ match = match->next;
67262+
67263+ return match;
67264+}
67265+
67266+static struct name_entry *
67267+lookup_name_entry(const char *name)
67268+{
67269+ return __lookup_name_entry(&running_polstate, name);
67270+}
67271+
67272+static struct name_entry *
67273+lookup_name_entry_create(const char *name)
67274+{
67275+ unsigned int len = strlen(name);
67276+ unsigned int key = full_name_hash(name, len);
67277+ unsigned int index = key % running_polstate.name_set.n_size;
67278+ struct name_entry *match;
67279+
67280+ match = running_polstate.name_set.n_hash[index];
67281+
67282+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67283+ !match->deleted))
67284+ match = match->next;
67285+
67286+ if (match && match->deleted)
67287+ return match;
67288+
67289+ match = running_polstate.name_set.n_hash[index];
67290+
67291+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67292+ match->deleted))
67293+ match = match->next;
67294+
67295+ if (match && !match->deleted)
67296+ return match;
67297+ else
67298+ return NULL;
67299+}
67300+
67301+static struct inodev_entry *
67302+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67303+{
67304+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67305+ struct inodev_entry *match;
67306+
67307+ match = running_polstate.inodev_set.i_hash[index];
67308+
67309+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67310+ match = match->next;
67311+
67312+ return match;
67313+}
67314+
67315+void
67316+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67317+{
67318+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67319+ state->inodev_set.i_size);
67320+ struct inodev_entry **curr;
67321+
67322+ entry->prev = NULL;
67323+
67324+ curr = &state->inodev_set.i_hash[index];
67325+ if (*curr != NULL)
67326+ (*curr)->prev = entry;
67327+
67328+ entry->next = *curr;
67329+ *curr = entry;
67330+
67331+ return;
67332+}
67333+
67334+static void
67335+insert_inodev_entry(struct inodev_entry *entry)
67336+{
67337+ __insert_inodev_entry(&running_polstate, entry);
67338+}
67339+
67340+void
67341+insert_acl_obj_label(struct acl_object_label *obj,
67342+ struct acl_subject_label *subj)
67343+{
67344+ unsigned int index =
67345+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67346+ struct acl_object_label **curr;
67347+
67348+ obj->prev = NULL;
67349+
67350+ curr = &subj->obj_hash[index];
67351+ if (*curr != NULL)
67352+ (*curr)->prev = obj;
67353+
67354+ obj->next = *curr;
67355+ *curr = obj;
67356+
67357+ return;
67358+}
67359+
67360+void
67361+insert_acl_subj_label(struct acl_subject_label *obj,
67362+ struct acl_role_label *role)
67363+{
67364+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67365+ struct acl_subject_label **curr;
67366+
67367+ obj->prev = NULL;
67368+
67369+ curr = &role->subj_hash[index];
67370+ if (*curr != NULL)
67371+ (*curr)->prev = obj;
67372+
67373+ obj->next = *curr;
67374+ *curr = obj;
67375+
67376+ return;
67377+}
67378+
67379+/* derived from glibc fnmatch() 0: match, 1: no match*/
67380+
67381+static int
67382+glob_match(const char *p, const char *n)
67383+{
67384+ char c;
67385+
67386+ while ((c = *p++) != '\0') {
67387+ switch (c) {
67388+ case '?':
67389+ if (*n == '\0')
67390+ return 1;
67391+ else if (*n == '/')
67392+ return 1;
67393+ break;
67394+ case '\\':
67395+ if (*n != c)
67396+ return 1;
67397+ break;
67398+ case '*':
67399+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67400+ if (*n == '/')
67401+ return 1;
67402+ else if (c == '?') {
67403+ if (*n == '\0')
67404+ return 1;
67405+ else
67406+ ++n;
67407+ }
67408+ }
67409+ if (c == '\0') {
67410+ return 0;
67411+ } else {
67412+ const char *endp;
67413+
67414+ if ((endp = strchr(n, '/')) == NULL)
67415+ endp = n + strlen(n);
67416+
67417+ if (c == '[') {
67418+ for (--p; n < endp; ++n)
67419+ if (!glob_match(p, n))
67420+ return 0;
67421+ } else if (c == '/') {
67422+ while (*n != '\0' && *n != '/')
67423+ ++n;
67424+ if (*n == '/' && !glob_match(p, n + 1))
67425+ return 0;
67426+ } else {
67427+ for (--p; n < endp; ++n)
67428+ if (*n == c && !glob_match(p, n))
67429+ return 0;
67430+ }
67431+
67432+ return 1;
67433+ }
67434+ case '[':
67435+ {
67436+ int not;
67437+ char cold;
67438+
67439+ if (*n == '\0' || *n == '/')
67440+ return 1;
67441+
67442+ not = (*p == '!' || *p == '^');
67443+ if (not)
67444+ ++p;
67445+
67446+ c = *p++;
67447+ for (;;) {
67448+ unsigned char fn = (unsigned char)*n;
67449+
67450+ if (c == '\0')
67451+ return 1;
67452+ else {
67453+ if (c == fn)
67454+ goto matched;
67455+ cold = c;
67456+ c = *p++;
67457+
67458+ if (c == '-' && *p != ']') {
67459+ unsigned char cend = *p++;
67460+
67461+ if (cend == '\0')
67462+ return 1;
67463+
67464+ if (cold <= fn && fn <= cend)
67465+ goto matched;
67466+
67467+ c = *p++;
67468+ }
67469+ }
67470+
67471+ if (c == ']')
67472+ break;
67473+ }
67474+ if (!not)
67475+ return 1;
67476+ break;
67477+ matched:
67478+ while (c != ']') {
67479+ if (c == '\0')
67480+ return 1;
67481+
67482+ c = *p++;
67483+ }
67484+ if (not)
67485+ return 1;
67486+ }
67487+ break;
67488+ default:
67489+ if (c != *n)
67490+ return 1;
67491+ }
67492+
67493+ ++n;
67494+ }
67495+
67496+ if (*n == '\0')
67497+ return 0;
67498+
67499+ if (*n == '/')
67500+ return 0;
67501+
67502+ return 1;
67503+}
67504+
67505+static struct acl_object_label *
67506+chk_glob_label(struct acl_object_label *globbed,
67507+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67508+{
67509+ struct acl_object_label *tmp;
67510+
67511+ if (*path == NULL)
67512+ *path = gr_to_filename_nolock(dentry, mnt);
67513+
67514+ tmp = globbed;
67515+
67516+ while (tmp) {
67517+ if (!glob_match(tmp->filename, *path))
67518+ return tmp;
67519+ tmp = tmp->next;
67520+ }
67521+
67522+ return NULL;
67523+}
67524+
67525+static struct acl_object_label *
67526+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67527+ const ino_t curr_ino, const dev_t curr_dev,
67528+ const struct acl_subject_label *subj, char **path, const int checkglob)
67529+{
67530+ struct acl_subject_label *tmpsubj;
67531+ struct acl_object_label *retval;
67532+ struct acl_object_label *retval2;
67533+
67534+ tmpsubj = (struct acl_subject_label *) subj;
67535+ read_lock(&gr_inode_lock);
67536+ do {
67537+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67538+ if (retval) {
67539+ if (checkglob && retval->globbed) {
67540+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67541+ if (retval2)
67542+ retval = retval2;
67543+ }
67544+ break;
67545+ }
67546+ } while ((tmpsubj = tmpsubj->parent_subject));
67547+ read_unlock(&gr_inode_lock);
67548+
67549+ return retval;
67550+}
67551+
67552+static __inline__ struct acl_object_label *
67553+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67554+ struct dentry *curr_dentry,
67555+ const struct acl_subject_label *subj, char **path, const int checkglob)
67556+{
67557+ int newglob = checkglob;
67558+ ino_t inode;
67559+ dev_t device;
67560+
67561+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67562+ as we don't want a / * rule to match instead of the / object
67563+ don't do this for create lookups that call this function though, since they're looking up
67564+ on the parent and thus need globbing checks on all paths
67565+ */
67566+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67567+ newglob = GR_NO_GLOB;
67568+
67569+ spin_lock(&curr_dentry->d_lock);
67570+ inode = curr_dentry->d_inode->i_ino;
67571+ device = __get_dev(curr_dentry);
67572+ spin_unlock(&curr_dentry->d_lock);
67573+
67574+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67575+}
67576+
67577+#ifdef CONFIG_HUGETLBFS
67578+static inline bool
67579+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67580+{
67581+ int i;
67582+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67583+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67584+ return true;
67585+ }
67586+
67587+ return false;
67588+}
67589+#endif
67590+
67591+static struct acl_object_label *
67592+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67593+ const struct acl_subject_label *subj, char *path, const int checkglob)
67594+{
67595+ struct dentry *dentry = (struct dentry *) l_dentry;
67596+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67597+ struct mount *real_mnt = real_mount(mnt);
67598+ struct acl_object_label *retval;
67599+ struct dentry *parent;
67600+
67601+ read_seqlock_excl(&mount_lock);
67602+ write_seqlock(&rename_lock);
67603+
67604+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67605+#ifdef CONFIG_NET
67606+ mnt == sock_mnt ||
67607+#endif
67608+#ifdef CONFIG_HUGETLBFS
67609+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67610+#endif
67611+ /* ignore Eric Biederman */
67612+ IS_PRIVATE(l_dentry->d_inode))) {
67613+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67614+ goto out;
67615+ }
67616+
67617+ for (;;) {
67618+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67619+ break;
67620+
67621+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67622+ if (!mnt_has_parent(real_mnt))
67623+ break;
67624+
67625+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67626+ if (retval != NULL)
67627+ goto out;
67628+
67629+ dentry = real_mnt->mnt_mountpoint;
67630+ real_mnt = real_mnt->mnt_parent;
67631+ mnt = &real_mnt->mnt;
67632+ continue;
67633+ }
67634+
67635+ parent = dentry->d_parent;
67636+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67637+ if (retval != NULL)
67638+ goto out;
67639+
67640+ dentry = parent;
67641+ }
67642+
67643+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67644+
67645+ /* gr_real_root is pinned so we don't have to hold a reference */
67646+ if (retval == NULL)
67647+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67648+out:
67649+ write_sequnlock(&rename_lock);
67650+ read_sequnlock_excl(&mount_lock);
67651+
67652+ BUG_ON(retval == NULL);
67653+
67654+ return retval;
67655+}
67656+
67657+static __inline__ struct acl_object_label *
67658+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67659+ const struct acl_subject_label *subj)
67660+{
67661+ char *path = NULL;
67662+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67663+}
67664+
67665+static __inline__ struct acl_object_label *
67666+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67667+ const struct acl_subject_label *subj)
67668+{
67669+ char *path = NULL;
67670+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67671+}
67672+
67673+static __inline__ struct acl_object_label *
67674+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67675+ const struct acl_subject_label *subj, char *path)
67676+{
67677+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67678+}
67679+
67680+struct acl_subject_label *
67681+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67682+ const struct acl_role_label *role)
67683+{
67684+ struct dentry *dentry = (struct dentry *) l_dentry;
67685+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67686+ struct mount *real_mnt = real_mount(mnt);
67687+ struct acl_subject_label *retval;
67688+ struct dentry *parent;
67689+
67690+ read_seqlock_excl(&mount_lock);
67691+ write_seqlock(&rename_lock);
67692+
67693+ for (;;) {
67694+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67695+ break;
67696+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67697+ if (!mnt_has_parent(real_mnt))
67698+ break;
67699+
67700+ spin_lock(&dentry->d_lock);
67701+ read_lock(&gr_inode_lock);
67702+ retval =
67703+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67704+ __get_dev(dentry), role);
67705+ read_unlock(&gr_inode_lock);
67706+ spin_unlock(&dentry->d_lock);
67707+ if (retval != NULL)
67708+ goto out;
67709+
67710+ dentry = real_mnt->mnt_mountpoint;
67711+ real_mnt = real_mnt->mnt_parent;
67712+ mnt = &real_mnt->mnt;
67713+ continue;
67714+ }
67715+
67716+ spin_lock(&dentry->d_lock);
67717+ read_lock(&gr_inode_lock);
67718+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67719+ __get_dev(dentry), role);
67720+ read_unlock(&gr_inode_lock);
67721+ parent = dentry->d_parent;
67722+ spin_unlock(&dentry->d_lock);
67723+
67724+ if (retval != NULL)
67725+ goto out;
67726+
67727+ dentry = parent;
67728+ }
67729+
67730+ spin_lock(&dentry->d_lock);
67731+ read_lock(&gr_inode_lock);
67732+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67733+ __get_dev(dentry), role);
67734+ read_unlock(&gr_inode_lock);
67735+ spin_unlock(&dentry->d_lock);
67736+
67737+ if (unlikely(retval == NULL)) {
67738+ /* gr_real_root is pinned, we don't need to hold a reference */
67739+ read_lock(&gr_inode_lock);
67740+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67741+ __get_dev(gr_real_root.dentry), role);
67742+ read_unlock(&gr_inode_lock);
67743+ }
67744+out:
67745+ write_sequnlock(&rename_lock);
67746+ read_sequnlock_excl(&mount_lock);
67747+
67748+ BUG_ON(retval == NULL);
67749+
67750+ return retval;
67751+}
67752+
67753+void
67754+assign_special_role(const char *rolename)
67755+{
67756+ struct acl_object_label *obj;
67757+ struct acl_role_label *r;
67758+ struct acl_role_label *assigned = NULL;
67759+ struct task_struct *tsk;
67760+ struct file *filp;
67761+
67762+ FOR_EACH_ROLE_START(r)
67763+ if (!strcmp(rolename, r->rolename) &&
67764+ (r->roletype & GR_ROLE_SPECIAL)) {
67765+ assigned = r;
67766+ break;
67767+ }
67768+ FOR_EACH_ROLE_END(r)
67769+
67770+ if (!assigned)
67771+ return;
67772+
67773+ read_lock(&tasklist_lock);
67774+ read_lock(&grsec_exec_file_lock);
67775+
67776+ tsk = current->real_parent;
67777+ if (tsk == NULL)
67778+ goto out_unlock;
67779+
67780+ filp = tsk->exec_file;
67781+ if (filp == NULL)
67782+ goto out_unlock;
67783+
67784+ tsk->is_writable = 0;
67785+ tsk->inherited = 0;
67786+
67787+ tsk->acl_sp_role = 1;
67788+ tsk->acl_role_id = ++acl_sp_role_value;
67789+ tsk->role = assigned;
67790+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67791+
67792+ /* ignore additional mmap checks for processes that are writable
67793+ by the default ACL */
67794+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67795+ if (unlikely(obj->mode & GR_WRITE))
67796+ tsk->is_writable = 1;
67797+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67798+ if (unlikely(obj->mode & GR_WRITE))
67799+ tsk->is_writable = 1;
67800+
67801+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67802+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67803+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67804+#endif
67805+
67806+out_unlock:
67807+ read_unlock(&grsec_exec_file_lock);
67808+ read_unlock(&tasklist_lock);
67809+ return;
67810+}
67811+
67812+
67813+static void
67814+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67815+{
67816+ struct task_struct *task = current;
67817+ const struct cred *cred = current_cred();
67818+
67819+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67820+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67821+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67822+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67823+
67824+ return;
67825+}
67826+
67827+static void
67828+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67829+{
67830+ struct task_struct *task = current;
67831+ const struct cred *cred = current_cred();
67832+
67833+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67834+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67835+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67836+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67837+
67838+ return;
67839+}
67840+
67841+static void
67842+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67843+{
67844+ struct task_struct *task = current;
67845+ const struct cred *cred = current_cred();
67846+
67847+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67848+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67849+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67850+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67851+
67852+ return;
67853+}
67854+
67855+static void
67856+gr_set_proc_res(struct task_struct *task)
67857+{
67858+ struct acl_subject_label *proc;
67859+ unsigned short i;
67860+
67861+ proc = task->acl;
67862+
67863+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67864+ return;
67865+
67866+ for (i = 0; i < RLIM_NLIMITS; i++) {
67867+ if (!(proc->resmask & (1U << i)))
67868+ continue;
67869+
67870+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67871+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67872+
67873+ if (i == RLIMIT_CPU)
67874+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67875+ }
67876+
67877+ return;
67878+}
67879+
67880+/* both of the below must be called with
67881+ rcu_read_lock();
67882+ read_lock(&tasklist_lock);
67883+ read_lock(&grsec_exec_file_lock);
67884+*/
67885+
67886+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67887+{
67888+ char *tmpname;
67889+ struct acl_subject_label *tmpsubj;
67890+ struct file *filp;
67891+ struct name_entry *nmatch;
67892+
67893+ filp = task->exec_file;
67894+ if (filp == NULL)
67895+ return NULL;
67896+
67897+ /* the following is to apply the correct subject
67898+ on binaries running when the RBAC system
67899+ is enabled, when the binaries have been
67900+ replaced or deleted since their execution
67901+ -----
67902+ when the RBAC system starts, the inode/dev
67903+ from exec_file will be one the RBAC system
67904+ is unaware of. It only knows the inode/dev
67905+ of the present file on disk, or the absence
67906+ of it.
67907+ */
67908+
67909+ if (filename)
67910+ nmatch = __lookup_name_entry(state, filename);
67911+ else {
67912+ preempt_disable();
67913+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67914+
67915+ nmatch = __lookup_name_entry(state, tmpname);
67916+ preempt_enable();
67917+ }
67918+ tmpsubj = NULL;
67919+ if (nmatch) {
67920+ if (nmatch->deleted)
67921+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67922+ else
67923+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67924+ }
67925+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67926+ then we fall back to a normal lookup based on the binary's ino/dev
67927+ */
67928+ if (tmpsubj == NULL)
67929+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67930+
67931+ return tmpsubj;
67932+}
67933+
67934+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67935+{
67936+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67937+}
67938+
67939+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67940+{
67941+ struct acl_object_label *obj;
67942+ struct file *filp;
67943+
67944+ filp = task->exec_file;
67945+
67946+ task->acl = subj;
67947+ task->is_writable = 0;
67948+ /* ignore additional mmap checks for processes that are writable
67949+ by the default ACL */
67950+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67951+ if (unlikely(obj->mode & GR_WRITE))
67952+ task->is_writable = 1;
67953+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67954+ if (unlikely(obj->mode & GR_WRITE))
67955+ task->is_writable = 1;
67956+
67957+ gr_set_proc_res(task);
67958+
67959+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67960+ 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);
67961+#endif
67962+}
67963+
67964+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67965+{
67966+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67967+}
67968+
67969+__u32
67970+gr_search_file(const struct dentry * dentry, const __u32 mode,
67971+ const struct vfsmount * mnt)
67972+{
67973+ __u32 retval = mode;
67974+ struct acl_subject_label *curracl;
67975+ struct acl_object_label *currobj;
67976+
67977+ if (unlikely(!(gr_status & GR_READY)))
67978+ return (mode & ~GR_AUDITS);
67979+
67980+ curracl = current->acl;
67981+
67982+ currobj = chk_obj_label(dentry, mnt, curracl);
67983+ retval = currobj->mode & mode;
67984+
67985+ /* if we're opening a specified transfer file for writing
67986+ (e.g. /dev/initctl), then transfer our role to init
67987+ */
67988+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67989+ current->role->roletype & GR_ROLE_PERSIST)) {
67990+ struct task_struct *task = init_pid_ns.child_reaper;
67991+
67992+ if (task->role != current->role) {
67993+ struct acl_subject_label *subj;
67994+
67995+ task->acl_sp_role = 0;
67996+ task->acl_role_id = current->acl_role_id;
67997+ task->role = current->role;
67998+ rcu_read_lock();
67999+ read_lock(&grsec_exec_file_lock);
68000+ subj = gr_get_subject_for_task(task, NULL);
68001+ gr_apply_subject_to_task(task, subj);
68002+ read_unlock(&grsec_exec_file_lock);
68003+ rcu_read_unlock();
68004+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68005+ }
68006+ }
68007+
68008+ if (unlikely
68009+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68010+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68011+ __u32 new_mode = mode;
68012+
68013+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68014+
68015+ retval = new_mode;
68016+
68017+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68018+ new_mode |= GR_INHERIT;
68019+
68020+ if (!(mode & GR_NOLEARN))
68021+ gr_log_learn(dentry, mnt, new_mode);
68022+ }
68023+
68024+ return retval;
68025+}
68026+
68027+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68028+ const struct dentry *parent,
68029+ const struct vfsmount *mnt)
68030+{
68031+ struct name_entry *match;
68032+ struct acl_object_label *matchpo;
68033+ struct acl_subject_label *curracl;
68034+ char *path;
68035+
68036+ if (unlikely(!(gr_status & GR_READY)))
68037+ return NULL;
68038+
68039+ preempt_disable();
68040+ path = gr_to_filename_rbac(new_dentry, mnt);
68041+ match = lookup_name_entry_create(path);
68042+
68043+ curracl = current->acl;
68044+
68045+ if (match) {
68046+ read_lock(&gr_inode_lock);
68047+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68048+ read_unlock(&gr_inode_lock);
68049+
68050+ if (matchpo) {
68051+ preempt_enable();
68052+ return matchpo;
68053+ }
68054+ }
68055+
68056+ // lookup parent
68057+
68058+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68059+
68060+ preempt_enable();
68061+ return matchpo;
68062+}
68063+
68064+__u32
68065+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68066+ const struct vfsmount * mnt, const __u32 mode)
68067+{
68068+ struct acl_object_label *matchpo;
68069+ __u32 retval;
68070+
68071+ if (unlikely(!(gr_status & GR_READY)))
68072+ return (mode & ~GR_AUDITS);
68073+
68074+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68075+
68076+ retval = matchpo->mode & mode;
68077+
68078+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68079+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68080+ __u32 new_mode = mode;
68081+
68082+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68083+
68084+ gr_log_learn(new_dentry, mnt, new_mode);
68085+ return new_mode;
68086+ }
68087+
68088+ return retval;
68089+}
68090+
68091+__u32
68092+gr_check_link(const struct dentry * new_dentry,
68093+ const struct dentry * parent_dentry,
68094+ const struct vfsmount * parent_mnt,
68095+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68096+{
68097+ struct acl_object_label *obj;
68098+ __u32 oldmode, newmode;
68099+ __u32 needmode;
68100+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68101+ GR_DELETE | GR_INHERIT;
68102+
68103+ if (unlikely(!(gr_status & GR_READY)))
68104+ return (GR_CREATE | GR_LINK);
68105+
68106+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68107+ oldmode = obj->mode;
68108+
68109+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68110+ newmode = obj->mode;
68111+
68112+ needmode = newmode & checkmodes;
68113+
68114+ // old name for hardlink must have at least the permissions of the new name
68115+ if ((oldmode & needmode) != needmode)
68116+ goto bad;
68117+
68118+ // if old name had restrictions/auditing, make sure the new name does as well
68119+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68120+
68121+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68122+ if (is_privileged_binary(old_dentry))
68123+ needmode |= GR_SETID;
68124+
68125+ if ((newmode & needmode) != needmode)
68126+ goto bad;
68127+
68128+ // enforce minimum permissions
68129+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68130+ return newmode;
68131+bad:
68132+ needmode = oldmode;
68133+ if (is_privileged_binary(old_dentry))
68134+ needmode |= GR_SETID;
68135+
68136+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68137+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68138+ return (GR_CREATE | GR_LINK);
68139+ } else if (newmode & GR_SUPPRESS)
68140+ return GR_SUPPRESS;
68141+ else
68142+ return 0;
68143+}
68144+
68145+int
68146+gr_check_hidden_task(const struct task_struct *task)
68147+{
68148+ if (unlikely(!(gr_status & GR_READY)))
68149+ return 0;
68150+
68151+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68152+ return 1;
68153+
68154+ return 0;
68155+}
68156+
68157+int
68158+gr_check_protected_task(const struct task_struct *task)
68159+{
68160+ if (unlikely(!(gr_status & GR_READY) || !task))
68161+ return 0;
68162+
68163+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68164+ task->acl != current->acl)
68165+ return 1;
68166+
68167+ return 0;
68168+}
68169+
68170+int
68171+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68172+{
68173+ struct task_struct *p;
68174+ int ret = 0;
68175+
68176+ if (unlikely(!(gr_status & GR_READY) || !pid))
68177+ return ret;
68178+
68179+ read_lock(&tasklist_lock);
68180+ do_each_pid_task(pid, type, p) {
68181+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68182+ p->acl != current->acl) {
68183+ ret = 1;
68184+ goto out;
68185+ }
68186+ } while_each_pid_task(pid, type, p);
68187+out:
68188+ read_unlock(&tasklist_lock);
68189+
68190+ return ret;
68191+}
68192+
68193+void
68194+gr_copy_label(struct task_struct *tsk)
68195+{
68196+ struct task_struct *p = current;
68197+
68198+ tsk->inherited = p->inherited;
68199+ tsk->acl_sp_role = 0;
68200+ tsk->acl_role_id = p->acl_role_id;
68201+ tsk->acl = p->acl;
68202+ tsk->role = p->role;
68203+ tsk->signal->used_accept = 0;
68204+ tsk->signal->curr_ip = p->signal->curr_ip;
68205+ tsk->signal->saved_ip = p->signal->saved_ip;
68206+ if (p->exec_file)
68207+ get_file(p->exec_file);
68208+ tsk->exec_file = p->exec_file;
68209+ tsk->is_writable = p->is_writable;
68210+ if (unlikely(p->signal->used_accept)) {
68211+ p->signal->curr_ip = 0;
68212+ p->signal->saved_ip = 0;
68213+ }
68214+
68215+ return;
68216+}
68217+
68218+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68219+
68220+int
68221+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68222+{
68223+ unsigned int i;
68224+ __u16 num;
68225+ uid_t *uidlist;
68226+ uid_t curuid;
68227+ int realok = 0;
68228+ int effectiveok = 0;
68229+ int fsok = 0;
68230+ uid_t globalreal, globaleffective, globalfs;
68231+
68232+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68233+ struct user_struct *user;
68234+
68235+ if (!uid_valid(real))
68236+ goto skipit;
68237+
68238+ /* find user based on global namespace */
68239+
68240+ globalreal = GR_GLOBAL_UID(real);
68241+
68242+ user = find_user(make_kuid(&init_user_ns, globalreal));
68243+ if (user == NULL)
68244+ goto skipit;
68245+
68246+ if (gr_process_kernel_setuid_ban(user)) {
68247+ /* for find_user */
68248+ free_uid(user);
68249+ return 1;
68250+ }
68251+
68252+ /* for find_user */
68253+ free_uid(user);
68254+
68255+skipit:
68256+#endif
68257+
68258+ if (unlikely(!(gr_status & GR_READY)))
68259+ return 0;
68260+
68261+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68262+ gr_log_learn_uid_change(real, effective, fs);
68263+
68264+ num = current->acl->user_trans_num;
68265+ uidlist = current->acl->user_transitions;
68266+
68267+ if (uidlist == NULL)
68268+ return 0;
68269+
68270+ if (!uid_valid(real)) {
68271+ realok = 1;
68272+ globalreal = (uid_t)-1;
68273+ } else {
68274+ globalreal = GR_GLOBAL_UID(real);
68275+ }
68276+ if (!uid_valid(effective)) {
68277+ effectiveok = 1;
68278+ globaleffective = (uid_t)-1;
68279+ } else {
68280+ globaleffective = GR_GLOBAL_UID(effective);
68281+ }
68282+ if (!uid_valid(fs)) {
68283+ fsok = 1;
68284+ globalfs = (uid_t)-1;
68285+ } else {
68286+ globalfs = GR_GLOBAL_UID(fs);
68287+ }
68288+
68289+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68290+ for (i = 0; i < num; i++) {
68291+ curuid = uidlist[i];
68292+ if (globalreal == curuid)
68293+ realok = 1;
68294+ if (globaleffective == curuid)
68295+ effectiveok = 1;
68296+ if (globalfs == curuid)
68297+ fsok = 1;
68298+ }
68299+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68300+ for (i = 0; i < num; i++) {
68301+ curuid = uidlist[i];
68302+ if (globalreal == curuid)
68303+ break;
68304+ if (globaleffective == curuid)
68305+ break;
68306+ if (globalfs == curuid)
68307+ break;
68308+ }
68309+ /* not in deny list */
68310+ if (i == num) {
68311+ realok = 1;
68312+ effectiveok = 1;
68313+ fsok = 1;
68314+ }
68315+ }
68316+
68317+ if (realok && effectiveok && fsok)
68318+ return 0;
68319+ else {
68320+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68321+ return 1;
68322+ }
68323+}
68324+
68325+int
68326+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68327+{
68328+ unsigned int i;
68329+ __u16 num;
68330+ gid_t *gidlist;
68331+ gid_t curgid;
68332+ int realok = 0;
68333+ int effectiveok = 0;
68334+ int fsok = 0;
68335+ gid_t globalreal, globaleffective, globalfs;
68336+
68337+ if (unlikely(!(gr_status & GR_READY)))
68338+ return 0;
68339+
68340+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68341+ gr_log_learn_gid_change(real, effective, fs);
68342+
68343+ num = current->acl->group_trans_num;
68344+ gidlist = current->acl->group_transitions;
68345+
68346+ if (gidlist == NULL)
68347+ return 0;
68348+
68349+ if (!gid_valid(real)) {
68350+ realok = 1;
68351+ globalreal = (gid_t)-1;
68352+ } else {
68353+ globalreal = GR_GLOBAL_GID(real);
68354+ }
68355+ if (!gid_valid(effective)) {
68356+ effectiveok = 1;
68357+ globaleffective = (gid_t)-1;
68358+ } else {
68359+ globaleffective = GR_GLOBAL_GID(effective);
68360+ }
68361+ if (!gid_valid(fs)) {
68362+ fsok = 1;
68363+ globalfs = (gid_t)-1;
68364+ } else {
68365+ globalfs = GR_GLOBAL_GID(fs);
68366+ }
68367+
68368+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68369+ for (i = 0; i < num; i++) {
68370+ curgid = gidlist[i];
68371+ if (globalreal == curgid)
68372+ realok = 1;
68373+ if (globaleffective == curgid)
68374+ effectiveok = 1;
68375+ if (globalfs == curgid)
68376+ fsok = 1;
68377+ }
68378+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68379+ for (i = 0; i < num; i++) {
68380+ curgid = gidlist[i];
68381+ if (globalreal == curgid)
68382+ break;
68383+ if (globaleffective == curgid)
68384+ break;
68385+ if (globalfs == curgid)
68386+ break;
68387+ }
68388+ /* not in deny list */
68389+ if (i == num) {
68390+ realok = 1;
68391+ effectiveok = 1;
68392+ fsok = 1;
68393+ }
68394+ }
68395+
68396+ if (realok && effectiveok && fsok)
68397+ return 0;
68398+ else {
68399+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68400+ return 1;
68401+ }
68402+}
68403+
68404+extern int gr_acl_is_capable(const int cap);
68405+
68406+void
68407+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68408+{
68409+ struct acl_role_label *role = task->role;
68410+ struct acl_subject_label *subj = NULL;
68411+ struct acl_object_label *obj;
68412+ struct file *filp;
68413+ uid_t uid;
68414+ gid_t gid;
68415+
68416+ if (unlikely(!(gr_status & GR_READY)))
68417+ return;
68418+
68419+ uid = GR_GLOBAL_UID(kuid);
68420+ gid = GR_GLOBAL_GID(kgid);
68421+
68422+ filp = task->exec_file;
68423+
68424+ /* kernel process, we'll give them the kernel role */
68425+ if (unlikely(!filp)) {
68426+ task->role = running_polstate.kernel_role;
68427+ task->acl = running_polstate.kernel_role->root_label;
68428+ return;
68429+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68430+ /* save the current ip at time of role lookup so that the proper
68431+ IP will be learned for role_allowed_ip */
68432+ task->signal->saved_ip = task->signal->curr_ip;
68433+ role = lookup_acl_role_label(task, uid, gid);
68434+ }
68435+
68436+ /* don't change the role if we're not a privileged process */
68437+ if (role && task->role != role &&
68438+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68439+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68440+ return;
68441+
68442+ /* perform subject lookup in possibly new role
68443+ we can use this result below in the case where role == task->role
68444+ */
68445+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68446+
68447+ /* if we changed uid/gid, but result in the same role
68448+ and are using inheritance, don't lose the inherited subject
68449+ if current subject is other than what normal lookup
68450+ would result in, we arrived via inheritance, don't
68451+ lose subject
68452+ */
68453+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68454+ (subj == task->acl)))
68455+ task->acl = subj;
68456+
68457+ /* leave task->inherited unaffected */
68458+
68459+ task->role = role;
68460+
68461+ task->is_writable = 0;
68462+
68463+ /* ignore additional mmap checks for processes that are writable
68464+ by the default ACL */
68465+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68466+ if (unlikely(obj->mode & GR_WRITE))
68467+ task->is_writable = 1;
68468+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68469+ if (unlikely(obj->mode & GR_WRITE))
68470+ task->is_writable = 1;
68471+
68472+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68473+ 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);
68474+#endif
68475+
68476+ gr_set_proc_res(task);
68477+
68478+ return;
68479+}
68480+
68481+int
68482+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68483+ const int unsafe_flags)
68484+{
68485+ struct task_struct *task = current;
68486+ struct acl_subject_label *newacl;
68487+ struct acl_object_label *obj;
68488+ __u32 retmode;
68489+
68490+ if (unlikely(!(gr_status & GR_READY)))
68491+ return 0;
68492+
68493+ newacl = chk_subj_label(dentry, mnt, task->role);
68494+
68495+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68496+ did an exec
68497+ */
68498+ rcu_read_lock();
68499+ read_lock(&tasklist_lock);
68500+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68501+ (task->parent->acl->mode & GR_POVERRIDE))) {
68502+ read_unlock(&tasklist_lock);
68503+ rcu_read_unlock();
68504+ goto skip_check;
68505+ }
68506+ read_unlock(&tasklist_lock);
68507+ rcu_read_unlock();
68508+
68509+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68510+ !(task->role->roletype & GR_ROLE_GOD) &&
68511+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68512+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68513+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68514+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68515+ else
68516+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68517+ return -EACCES;
68518+ }
68519+
68520+skip_check:
68521+
68522+ obj = chk_obj_label(dentry, mnt, task->acl);
68523+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68524+
68525+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68526+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68527+ if (obj->nested)
68528+ task->acl = obj->nested;
68529+ else
68530+ task->acl = newacl;
68531+ task->inherited = 0;
68532+ } else {
68533+ task->inherited = 1;
68534+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68535+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68536+ }
68537+
68538+ task->is_writable = 0;
68539+
68540+ /* ignore additional mmap checks for processes that are writable
68541+ by the default ACL */
68542+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68543+ if (unlikely(obj->mode & GR_WRITE))
68544+ task->is_writable = 1;
68545+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68546+ if (unlikely(obj->mode & GR_WRITE))
68547+ task->is_writable = 1;
68548+
68549+ gr_set_proc_res(task);
68550+
68551+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68552+ 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);
68553+#endif
68554+ return 0;
68555+}
68556+
68557+/* always called with valid inodev ptr */
68558+static void
68559+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68560+{
68561+ struct acl_object_label *matchpo;
68562+ struct acl_subject_label *matchps;
68563+ struct acl_subject_label *subj;
68564+ struct acl_role_label *role;
68565+ unsigned int x;
68566+
68567+ FOR_EACH_ROLE_START(role)
68568+ FOR_EACH_SUBJECT_START(role, subj, x)
68569+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68570+ matchpo->mode |= GR_DELETED;
68571+ FOR_EACH_SUBJECT_END(subj,x)
68572+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68573+ /* nested subjects aren't in the role's subj_hash table */
68574+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68575+ matchpo->mode |= GR_DELETED;
68576+ FOR_EACH_NESTED_SUBJECT_END(subj)
68577+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68578+ matchps->mode |= GR_DELETED;
68579+ FOR_EACH_ROLE_END(role)
68580+
68581+ inodev->nentry->deleted = 1;
68582+
68583+ return;
68584+}
68585+
68586+void
68587+gr_handle_delete(const ino_t ino, const dev_t dev)
68588+{
68589+ struct inodev_entry *inodev;
68590+
68591+ if (unlikely(!(gr_status & GR_READY)))
68592+ return;
68593+
68594+ write_lock(&gr_inode_lock);
68595+ inodev = lookup_inodev_entry(ino, dev);
68596+ if (inodev != NULL)
68597+ do_handle_delete(inodev, ino, dev);
68598+ write_unlock(&gr_inode_lock);
68599+
68600+ return;
68601+}
68602+
68603+static void
68604+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68605+ const ino_t newinode, const dev_t newdevice,
68606+ struct acl_subject_label *subj)
68607+{
68608+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68609+ struct acl_object_label *match;
68610+
68611+ match = subj->obj_hash[index];
68612+
68613+ while (match && (match->inode != oldinode ||
68614+ match->device != olddevice ||
68615+ !(match->mode & GR_DELETED)))
68616+ match = match->next;
68617+
68618+ if (match && (match->inode == oldinode)
68619+ && (match->device == olddevice)
68620+ && (match->mode & GR_DELETED)) {
68621+ if (match->prev == NULL) {
68622+ subj->obj_hash[index] = match->next;
68623+ if (match->next != NULL)
68624+ match->next->prev = NULL;
68625+ } else {
68626+ match->prev->next = match->next;
68627+ if (match->next != NULL)
68628+ match->next->prev = match->prev;
68629+ }
68630+ match->prev = NULL;
68631+ match->next = NULL;
68632+ match->inode = newinode;
68633+ match->device = newdevice;
68634+ match->mode &= ~GR_DELETED;
68635+
68636+ insert_acl_obj_label(match, subj);
68637+ }
68638+
68639+ return;
68640+}
68641+
68642+static void
68643+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68644+ const ino_t newinode, const dev_t newdevice,
68645+ struct acl_role_label *role)
68646+{
68647+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68648+ struct acl_subject_label *match;
68649+
68650+ match = role->subj_hash[index];
68651+
68652+ while (match && (match->inode != oldinode ||
68653+ match->device != olddevice ||
68654+ !(match->mode & GR_DELETED)))
68655+ match = match->next;
68656+
68657+ if (match && (match->inode == oldinode)
68658+ && (match->device == olddevice)
68659+ && (match->mode & GR_DELETED)) {
68660+ if (match->prev == NULL) {
68661+ role->subj_hash[index] = match->next;
68662+ if (match->next != NULL)
68663+ match->next->prev = NULL;
68664+ } else {
68665+ match->prev->next = match->next;
68666+ if (match->next != NULL)
68667+ match->next->prev = match->prev;
68668+ }
68669+ match->prev = NULL;
68670+ match->next = NULL;
68671+ match->inode = newinode;
68672+ match->device = newdevice;
68673+ match->mode &= ~GR_DELETED;
68674+
68675+ insert_acl_subj_label(match, role);
68676+ }
68677+
68678+ return;
68679+}
68680+
68681+static void
68682+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68683+ const ino_t newinode, const dev_t newdevice)
68684+{
68685+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68686+ struct inodev_entry *match;
68687+
68688+ match = running_polstate.inodev_set.i_hash[index];
68689+
68690+ while (match && (match->nentry->inode != oldinode ||
68691+ match->nentry->device != olddevice || !match->nentry->deleted))
68692+ match = match->next;
68693+
68694+ if (match && (match->nentry->inode == oldinode)
68695+ && (match->nentry->device == olddevice) &&
68696+ match->nentry->deleted) {
68697+ if (match->prev == NULL) {
68698+ running_polstate.inodev_set.i_hash[index] = match->next;
68699+ if (match->next != NULL)
68700+ match->next->prev = NULL;
68701+ } else {
68702+ match->prev->next = match->next;
68703+ if (match->next != NULL)
68704+ match->next->prev = match->prev;
68705+ }
68706+ match->prev = NULL;
68707+ match->next = NULL;
68708+ match->nentry->inode = newinode;
68709+ match->nentry->device = newdevice;
68710+ match->nentry->deleted = 0;
68711+
68712+ insert_inodev_entry(match);
68713+ }
68714+
68715+ return;
68716+}
68717+
68718+static void
68719+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68720+{
68721+ struct acl_subject_label *subj;
68722+ struct acl_role_label *role;
68723+ unsigned int x;
68724+
68725+ FOR_EACH_ROLE_START(role)
68726+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68727+
68728+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68729+ if ((subj->inode == ino) && (subj->device == dev)) {
68730+ subj->inode = ino;
68731+ subj->device = dev;
68732+ }
68733+ /* nested subjects aren't in the role's subj_hash table */
68734+ update_acl_obj_label(matchn->inode, matchn->device,
68735+ ino, dev, subj);
68736+ FOR_EACH_NESTED_SUBJECT_END(subj)
68737+ FOR_EACH_SUBJECT_START(role, subj, x)
68738+ update_acl_obj_label(matchn->inode, matchn->device,
68739+ ino, dev, subj);
68740+ FOR_EACH_SUBJECT_END(subj,x)
68741+ FOR_EACH_ROLE_END(role)
68742+
68743+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68744+
68745+ return;
68746+}
68747+
68748+static void
68749+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68750+ const struct vfsmount *mnt)
68751+{
68752+ ino_t ino = dentry->d_inode->i_ino;
68753+ dev_t dev = __get_dev(dentry);
68754+
68755+ __do_handle_create(matchn, ino, dev);
68756+
68757+ return;
68758+}
68759+
68760+void
68761+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68762+{
68763+ struct name_entry *matchn;
68764+
68765+ if (unlikely(!(gr_status & GR_READY)))
68766+ return;
68767+
68768+ preempt_disable();
68769+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68770+
68771+ if (unlikely((unsigned long)matchn)) {
68772+ write_lock(&gr_inode_lock);
68773+ do_handle_create(matchn, dentry, mnt);
68774+ write_unlock(&gr_inode_lock);
68775+ }
68776+ preempt_enable();
68777+
68778+ return;
68779+}
68780+
68781+void
68782+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68783+{
68784+ struct name_entry *matchn;
68785+
68786+ if (unlikely(!(gr_status & GR_READY)))
68787+ return;
68788+
68789+ preempt_disable();
68790+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68791+
68792+ if (unlikely((unsigned long)matchn)) {
68793+ write_lock(&gr_inode_lock);
68794+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68795+ write_unlock(&gr_inode_lock);
68796+ }
68797+ preempt_enable();
68798+
68799+ return;
68800+}
68801+
68802+void
68803+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68804+ struct dentry *old_dentry,
68805+ struct dentry *new_dentry,
68806+ struct vfsmount *mnt, const __u8 replace)
68807+{
68808+ struct name_entry *matchn;
68809+ struct inodev_entry *inodev;
68810+ struct inode *inode = new_dentry->d_inode;
68811+ ino_t old_ino = old_dentry->d_inode->i_ino;
68812+ dev_t old_dev = __get_dev(old_dentry);
68813+
68814+ /* vfs_rename swaps the name and parent link for old_dentry and
68815+ new_dentry
68816+ at this point, old_dentry has the new name, parent link, and inode
68817+ for the renamed file
68818+ if a file is being replaced by a rename, new_dentry has the inode
68819+ and name for the replaced file
68820+ */
68821+
68822+ if (unlikely(!(gr_status & GR_READY)))
68823+ return;
68824+
68825+ preempt_disable();
68826+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68827+
68828+ /* we wouldn't have to check d_inode if it weren't for
68829+ NFS silly-renaming
68830+ */
68831+
68832+ write_lock(&gr_inode_lock);
68833+ if (unlikely(replace && inode)) {
68834+ ino_t new_ino = inode->i_ino;
68835+ dev_t new_dev = __get_dev(new_dentry);
68836+
68837+ inodev = lookup_inodev_entry(new_ino, new_dev);
68838+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68839+ do_handle_delete(inodev, new_ino, new_dev);
68840+ }
68841+
68842+ inodev = lookup_inodev_entry(old_ino, old_dev);
68843+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68844+ do_handle_delete(inodev, old_ino, old_dev);
68845+
68846+ if (unlikely((unsigned long)matchn))
68847+ do_handle_create(matchn, old_dentry, mnt);
68848+
68849+ write_unlock(&gr_inode_lock);
68850+ preempt_enable();
68851+
68852+ return;
68853+}
68854+
68855+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68856+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68857+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68858+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68859+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68860+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68861+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68862+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68863+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68864+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68865+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68866+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68867+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68868+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68869+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68870+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68871+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68872+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68873+};
68874+
68875+void
68876+gr_learn_resource(const struct task_struct *task,
68877+ const int res, const unsigned long wanted, const int gt)
68878+{
68879+ struct acl_subject_label *acl;
68880+ const struct cred *cred;
68881+
68882+ if (unlikely((gr_status & GR_READY) &&
68883+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68884+ goto skip_reslog;
68885+
68886+ gr_log_resource(task, res, wanted, gt);
68887+skip_reslog:
68888+
68889+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68890+ return;
68891+
68892+ acl = task->acl;
68893+
68894+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68895+ !(acl->resmask & (1U << (unsigned short) res))))
68896+ return;
68897+
68898+ if (wanted >= acl->res[res].rlim_cur) {
68899+ unsigned long res_add;
68900+
68901+ res_add = wanted + res_learn_bumps[res];
68902+
68903+ acl->res[res].rlim_cur = res_add;
68904+
68905+ if (wanted > acl->res[res].rlim_max)
68906+ acl->res[res].rlim_max = res_add;
68907+
68908+ /* only log the subject filename, since resource logging is supported for
68909+ single-subject learning only */
68910+ rcu_read_lock();
68911+ cred = __task_cred(task);
68912+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68913+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68914+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68915+ "", (unsigned long) res, &task->signal->saved_ip);
68916+ rcu_read_unlock();
68917+ }
68918+
68919+ return;
68920+}
68921+EXPORT_SYMBOL_GPL(gr_learn_resource);
68922+#endif
68923+
68924+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68925+void
68926+pax_set_initial_flags(struct linux_binprm *bprm)
68927+{
68928+ struct task_struct *task = current;
68929+ struct acl_subject_label *proc;
68930+ unsigned long flags;
68931+
68932+ if (unlikely(!(gr_status & GR_READY)))
68933+ return;
68934+
68935+ flags = pax_get_flags(task);
68936+
68937+ proc = task->acl;
68938+
68939+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68940+ flags &= ~MF_PAX_PAGEEXEC;
68941+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68942+ flags &= ~MF_PAX_SEGMEXEC;
68943+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68944+ flags &= ~MF_PAX_RANDMMAP;
68945+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68946+ flags &= ~MF_PAX_EMUTRAMP;
68947+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68948+ flags &= ~MF_PAX_MPROTECT;
68949+
68950+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68951+ flags |= MF_PAX_PAGEEXEC;
68952+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68953+ flags |= MF_PAX_SEGMEXEC;
68954+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68955+ flags |= MF_PAX_RANDMMAP;
68956+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68957+ flags |= MF_PAX_EMUTRAMP;
68958+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68959+ flags |= MF_PAX_MPROTECT;
68960+
68961+ pax_set_flags(task, flags);
68962+
68963+ return;
68964+}
68965+#endif
68966+
68967+int
68968+gr_handle_proc_ptrace(struct task_struct *task)
68969+{
68970+ struct file *filp;
68971+ struct task_struct *tmp = task;
68972+ struct task_struct *curtemp = current;
68973+ __u32 retmode;
68974+
68975+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68976+ if (unlikely(!(gr_status & GR_READY)))
68977+ return 0;
68978+#endif
68979+
68980+ read_lock(&tasklist_lock);
68981+ read_lock(&grsec_exec_file_lock);
68982+ filp = task->exec_file;
68983+
68984+ while (task_pid_nr(tmp) > 0) {
68985+ if (tmp == curtemp)
68986+ break;
68987+ tmp = tmp->real_parent;
68988+ }
68989+
68990+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68991+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68992+ read_unlock(&grsec_exec_file_lock);
68993+ read_unlock(&tasklist_lock);
68994+ return 1;
68995+ }
68996+
68997+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68998+ if (!(gr_status & GR_READY)) {
68999+ read_unlock(&grsec_exec_file_lock);
69000+ read_unlock(&tasklist_lock);
69001+ return 0;
69002+ }
69003+#endif
69004+
69005+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69006+ read_unlock(&grsec_exec_file_lock);
69007+ read_unlock(&tasklist_lock);
69008+
69009+ if (retmode & GR_NOPTRACE)
69010+ return 1;
69011+
69012+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69013+ && (current->acl != task->acl || (current->acl != current->role->root_label
69014+ && task_pid_nr(current) != task_pid_nr(task))))
69015+ return 1;
69016+
69017+ return 0;
69018+}
69019+
69020+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69021+{
69022+ if (unlikely(!(gr_status & GR_READY)))
69023+ return;
69024+
69025+ if (!(current->role->roletype & GR_ROLE_GOD))
69026+ return;
69027+
69028+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69029+ p->role->rolename, gr_task_roletype_to_char(p),
69030+ p->acl->filename);
69031+}
69032+
69033+int
69034+gr_handle_ptrace(struct task_struct *task, const long request)
69035+{
69036+ struct task_struct *tmp = task;
69037+ struct task_struct *curtemp = current;
69038+ __u32 retmode;
69039+
69040+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69041+ if (unlikely(!(gr_status & GR_READY)))
69042+ return 0;
69043+#endif
69044+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69045+ read_lock(&tasklist_lock);
69046+ while (task_pid_nr(tmp) > 0) {
69047+ if (tmp == curtemp)
69048+ break;
69049+ tmp = tmp->real_parent;
69050+ }
69051+
69052+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69053+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69054+ read_unlock(&tasklist_lock);
69055+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69056+ return 1;
69057+ }
69058+ read_unlock(&tasklist_lock);
69059+ }
69060+
69061+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69062+ if (!(gr_status & GR_READY))
69063+ return 0;
69064+#endif
69065+
69066+ read_lock(&grsec_exec_file_lock);
69067+ if (unlikely(!task->exec_file)) {
69068+ read_unlock(&grsec_exec_file_lock);
69069+ return 0;
69070+ }
69071+
69072+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69073+ read_unlock(&grsec_exec_file_lock);
69074+
69075+ if (retmode & GR_NOPTRACE) {
69076+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69077+ return 1;
69078+ }
69079+
69080+ if (retmode & GR_PTRACERD) {
69081+ switch (request) {
69082+ case PTRACE_SEIZE:
69083+ case PTRACE_POKETEXT:
69084+ case PTRACE_POKEDATA:
69085+ case PTRACE_POKEUSR:
69086+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69087+ case PTRACE_SETREGS:
69088+ case PTRACE_SETFPREGS:
69089+#endif
69090+#ifdef CONFIG_X86
69091+ case PTRACE_SETFPXREGS:
69092+#endif
69093+#ifdef CONFIG_ALTIVEC
69094+ case PTRACE_SETVRREGS:
69095+#endif
69096+ return 1;
69097+ default:
69098+ return 0;
69099+ }
69100+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69101+ !(current->role->roletype & GR_ROLE_GOD) &&
69102+ (current->acl != task->acl)) {
69103+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69104+ return 1;
69105+ }
69106+
69107+ return 0;
69108+}
69109+
69110+static int is_writable_mmap(const struct file *filp)
69111+{
69112+ struct task_struct *task = current;
69113+ struct acl_object_label *obj, *obj2;
69114+
69115+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69116+ !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))) {
69117+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69118+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69119+ task->role->root_label);
69120+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69121+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69122+ return 1;
69123+ }
69124+ }
69125+ return 0;
69126+}
69127+
69128+int
69129+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69130+{
69131+ __u32 mode;
69132+
69133+ if (unlikely(!file || !(prot & PROT_EXEC)))
69134+ return 1;
69135+
69136+ if (is_writable_mmap(file))
69137+ return 0;
69138+
69139+ mode =
69140+ gr_search_file(file->f_path.dentry,
69141+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69142+ file->f_path.mnt);
69143+
69144+ if (!gr_tpe_allow(file))
69145+ return 0;
69146+
69147+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69148+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69149+ return 0;
69150+ } else if (unlikely(!(mode & GR_EXEC))) {
69151+ return 0;
69152+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69153+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69154+ return 1;
69155+ }
69156+
69157+ return 1;
69158+}
69159+
69160+int
69161+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69162+{
69163+ __u32 mode;
69164+
69165+ if (unlikely(!file || !(prot & PROT_EXEC)))
69166+ return 1;
69167+
69168+ if (is_writable_mmap(file))
69169+ return 0;
69170+
69171+ mode =
69172+ gr_search_file(file->f_path.dentry,
69173+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69174+ file->f_path.mnt);
69175+
69176+ if (!gr_tpe_allow(file))
69177+ return 0;
69178+
69179+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69180+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69181+ return 0;
69182+ } else if (unlikely(!(mode & GR_EXEC))) {
69183+ return 0;
69184+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69185+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69186+ return 1;
69187+ }
69188+
69189+ return 1;
69190+}
69191+
69192+void
69193+gr_acl_handle_psacct(struct task_struct *task, const long code)
69194+{
69195+ unsigned long runtime, cputime;
69196+ cputime_t utime, stime;
69197+ unsigned int wday, cday;
69198+ __u8 whr, chr;
69199+ __u8 wmin, cmin;
69200+ __u8 wsec, csec;
69201+ struct timespec timeval;
69202+
69203+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69204+ !(task->acl->mode & GR_PROCACCT)))
69205+ return;
69206+
69207+ do_posix_clock_monotonic_gettime(&timeval);
69208+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69209+ wday = runtime / (60 * 60 * 24);
69210+ runtime -= wday * (60 * 60 * 24);
69211+ whr = runtime / (60 * 60);
69212+ runtime -= whr * (60 * 60);
69213+ wmin = runtime / 60;
69214+ runtime -= wmin * 60;
69215+ wsec = runtime;
69216+
69217+ task_cputime(task, &utime, &stime);
69218+ cputime = cputime_to_secs(utime + stime);
69219+ cday = cputime / (60 * 60 * 24);
69220+ cputime -= cday * (60 * 60 * 24);
69221+ chr = cputime / (60 * 60);
69222+ cputime -= chr * (60 * 60);
69223+ cmin = cputime / 60;
69224+ cputime -= cmin * 60;
69225+ csec = cputime;
69226+
69227+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69228+
69229+ return;
69230+}
69231+
69232+#ifdef CONFIG_TASKSTATS
69233+int gr_is_taskstats_denied(int pid)
69234+{
69235+ struct task_struct *task;
69236+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69237+ const struct cred *cred;
69238+#endif
69239+ int ret = 0;
69240+
69241+ /* restrict taskstats viewing to un-chrooted root users
69242+ who have the 'view' subject flag if the RBAC system is enabled
69243+ */
69244+
69245+ rcu_read_lock();
69246+ read_lock(&tasklist_lock);
69247+ task = find_task_by_vpid(pid);
69248+ if (task) {
69249+#ifdef CONFIG_GRKERNSEC_CHROOT
69250+ if (proc_is_chrooted(task))
69251+ ret = -EACCES;
69252+#endif
69253+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69254+ cred = __task_cred(task);
69255+#ifdef CONFIG_GRKERNSEC_PROC_USER
69256+ if (gr_is_global_nonroot(cred->uid))
69257+ ret = -EACCES;
69258+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69259+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69260+ ret = -EACCES;
69261+#endif
69262+#endif
69263+ if (gr_status & GR_READY) {
69264+ if (!(task->acl->mode & GR_VIEW))
69265+ ret = -EACCES;
69266+ }
69267+ } else
69268+ ret = -ENOENT;
69269+
69270+ read_unlock(&tasklist_lock);
69271+ rcu_read_unlock();
69272+
69273+ return ret;
69274+}
69275+#endif
69276+
69277+/* AUXV entries are filled via a descendant of search_binary_handler
69278+ after we've already applied the subject for the target
69279+*/
69280+int gr_acl_enable_at_secure(void)
69281+{
69282+ if (unlikely(!(gr_status & GR_READY)))
69283+ return 0;
69284+
69285+ if (current->acl->mode & GR_ATSECURE)
69286+ return 1;
69287+
69288+ return 0;
69289+}
69290+
69291+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69292+{
69293+ struct task_struct *task = current;
69294+ struct dentry *dentry = file->f_path.dentry;
69295+ struct vfsmount *mnt = file->f_path.mnt;
69296+ struct acl_object_label *obj, *tmp;
69297+ struct acl_subject_label *subj;
69298+ unsigned int bufsize;
69299+ int is_not_root;
69300+ char *path;
69301+ dev_t dev = __get_dev(dentry);
69302+
69303+ if (unlikely(!(gr_status & GR_READY)))
69304+ return 1;
69305+
69306+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69307+ return 1;
69308+
69309+ /* ignore Eric Biederman */
69310+ if (IS_PRIVATE(dentry->d_inode))
69311+ return 1;
69312+
69313+ subj = task->acl;
69314+ read_lock(&gr_inode_lock);
69315+ do {
69316+ obj = lookup_acl_obj_label(ino, dev, subj);
69317+ if (obj != NULL) {
69318+ read_unlock(&gr_inode_lock);
69319+ return (obj->mode & GR_FIND) ? 1 : 0;
69320+ }
69321+ } while ((subj = subj->parent_subject));
69322+ read_unlock(&gr_inode_lock);
69323+
69324+ /* this is purely an optimization since we're looking for an object
69325+ for the directory we're doing a readdir on
69326+ if it's possible for any globbed object to match the entry we're
69327+ filling into the directory, then the object we find here will be
69328+ an anchor point with attached globbed objects
69329+ */
69330+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69331+ if (obj->globbed == NULL)
69332+ return (obj->mode & GR_FIND) ? 1 : 0;
69333+
69334+ is_not_root = ((obj->filename[0] == '/') &&
69335+ (obj->filename[1] == '\0')) ? 0 : 1;
69336+ bufsize = PAGE_SIZE - namelen - is_not_root;
69337+
69338+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69339+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69340+ return 1;
69341+
69342+ preempt_disable();
69343+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69344+ bufsize);
69345+
69346+ bufsize = strlen(path);
69347+
69348+ /* if base is "/", don't append an additional slash */
69349+ if (is_not_root)
69350+ *(path + bufsize) = '/';
69351+ memcpy(path + bufsize + is_not_root, name, namelen);
69352+ *(path + bufsize + namelen + is_not_root) = '\0';
69353+
69354+ tmp = obj->globbed;
69355+ while (tmp) {
69356+ if (!glob_match(tmp->filename, path)) {
69357+ preempt_enable();
69358+ return (tmp->mode & GR_FIND) ? 1 : 0;
69359+ }
69360+ tmp = tmp->next;
69361+ }
69362+ preempt_enable();
69363+ return (obj->mode & GR_FIND) ? 1 : 0;
69364+}
69365+
69366+void gr_put_exec_file(struct task_struct *task)
69367+{
69368+ struct file *filp;
69369+
69370+ write_lock(&grsec_exec_file_lock);
69371+ filp = task->exec_file;
69372+ task->exec_file = NULL;
69373+ write_unlock(&grsec_exec_file_lock);
69374+
69375+ if (filp)
69376+ fput(filp);
69377+
69378+ return;
69379+}
69380+
69381+
69382+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69383+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69384+#endif
69385+#ifdef CONFIG_SECURITY
69386+EXPORT_SYMBOL_GPL(gr_check_user_change);
69387+EXPORT_SYMBOL_GPL(gr_check_group_change);
69388+#endif
69389+
69390diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69391new file mode 100644
69392index 0000000..18ffbbd
69393--- /dev/null
69394+++ b/grsecurity/gracl_alloc.c
69395@@ -0,0 +1,105 @@
69396+#include <linux/kernel.h>
69397+#include <linux/mm.h>
69398+#include <linux/slab.h>
69399+#include <linux/vmalloc.h>
69400+#include <linux/gracl.h>
69401+#include <linux/grsecurity.h>
69402+
69403+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69404+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69405+
69406+static __inline__ int
69407+alloc_pop(void)
69408+{
69409+ if (current_alloc_state->alloc_stack_next == 1)
69410+ return 0;
69411+
69412+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69413+
69414+ current_alloc_state->alloc_stack_next--;
69415+
69416+ return 1;
69417+}
69418+
69419+static __inline__ int
69420+alloc_push(void *buf)
69421+{
69422+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69423+ return 1;
69424+
69425+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69426+
69427+ current_alloc_state->alloc_stack_next++;
69428+
69429+ return 0;
69430+}
69431+
69432+void *
69433+acl_alloc(unsigned long len)
69434+{
69435+ void *ret = NULL;
69436+
69437+ if (!len || len > PAGE_SIZE)
69438+ goto out;
69439+
69440+ ret = kmalloc(len, GFP_KERNEL);
69441+
69442+ if (ret) {
69443+ if (alloc_push(ret)) {
69444+ kfree(ret);
69445+ ret = NULL;
69446+ }
69447+ }
69448+
69449+out:
69450+ return ret;
69451+}
69452+
69453+void *
69454+acl_alloc_num(unsigned long num, unsigned long len)
69455+{
69456+ if (!len || (num > (PAGE_SIZE / len)))
69457+ return NULL;
69458+
69459+ return acl_alloc(num * len);
69460+}
69461+
69462+void
69463+acl_free_all(void)
69464+{
69465+ if (!current_alloc_state->alloc_stack)
69466+ return;
69467+
69468+ while (alloc_pop()) ;
69469+
69470+ if (current_alloc_state->alloc_stack) {
69471+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69472+ kfree(current_alloc_state->alloc_stack);
69473+ else
69474+ vfree(current_alloc_state->alloc_stack);
69475+ }
69476+
69477+ current_alloc_state->alloc_stack = NULL;
69478+ current_alloc_state->alloc_stack_size = 1;
69479+ current_alloc_state->alloc_stack_next = 1;
69480+
69481+ return;
69482+}
69483+
69484+int
69485+acl_alloc_stack_init(unsigned long size)
69486+{
69487+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69488+ current_alloc_state->alloc_stack =
69489+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69490+ else
69491+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69492+
69493+ current_alloc_state->alloc_stack_size = size;
69494+ current_alloc_state->alloc_stack_next = 1;
69495+
69496+ if (!current_alloc_state->alloc_stack)
69497+ return 0;
69498+ else
69499+ return 1;
69500+}
69501diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69502new file mode 100644
69503index 0000000..bdd51ea
69504--- /dev/null
69505+++ b/grsecurity/gracl_cap.c
69506@@ -0,0 +1,110 @@
69507+#include <linux/kernel.h>
69508+#include <linux/module.h>
69509+#include <linux/sched.h>
69510+#include <linux/gracl.h>
69511+#include <linux/grsecurity.h>
69512+#include <linux/grinternal.h>
69513+
69514+extern const char *captab_log[];
69515+extern int captab_log_entries;
69516+
69517+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69518+{
69519+ struct acl_subject_label *curracl;
69520+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69521+ kernel_cap_t cap_audit = __cap_empty_set;
69522+
69523+ if (!gr_acl_is_enabled())
69524+ return 1;
69525+
69526+ curracl = task->acl;
69527+
69528+ cap_drop = curracl->cap_lower;
69529+ cap_mask = curracl->cap_mask;
69530+ cap_audit = curracl->cap_invert_audit;
69531+
69532+ while ((curracl = curracl->parent_subject)) {
69533+ /* if the cap isn't specified in the current computed mask but is specified in the
69534+ current level subject, and is lowered in the current level subject, then add
69535+ it to the set of dropped capabilities
69536+ otherwise, add the current level subject's mask to the current computed mask
69537+ */
69538+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69539+ cap_raise(cap_mask, cap);
69540+ if (cap_raised(curracl->cap_lower, cap))
69541+ cap_raise(cap_drop, cap);
69542+ if (cap_raised(curracl->cap_invert_audit, cap))
69543+ cap_raise(cap_audit, cap);
69544+ }
69545+ }
69546+
69547+ if (!cap_raised(cap_drop, cap)) {
69548+ if (cap_raised(cap_audit, cap))
69549+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69550+ return 1;
69551+ }
69552+
69553+ curracl = task->acl;
69554+
69555+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69556+ && cap_raised(cred->cap_effective, cap)) {
69557+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69558+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69559+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69560+ gr_to_filename(task->exec_file->f_path.dentry,
69561+ task->exec_file->f_path.mnt) : curracl->filename,
69562+ curracl->filename, 0UL,
69563+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69564+ return 1;
69565+ }
69566+
69567+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69568+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69569+
69570+ return 0;
69571+}
69572+
69573+int
69574+gr_acl_is_capable(const int cap)
69575+{
69576+ return gr_task_acl_is_capable(current, current_cred(), cap);
69577+}
69578+
69579+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69580+{
69581+ struct acl_subject_label *curracl;
69582+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69583+
69584+ if (!gr_acl_is_enabled())
69585+ return 1;
69586+
69587+ curracl = task->acl;
69588+
69589+ cap_drop = curracl->cap_lower;
69590+ cap_mask = curracl->cap_mask;
69591+
69592+ while ((curracl = curracl->parent_subject)) {
69593+ /* if the cap isn't specified in the current computed mask but is specified in the
69594+ current level subject, and is lowered in the current level subject, then add
69595+ it to the set of dropped capabilities
69596+ otherwise, add the current level subject's mask to the current computed mask
69597+ */
69598+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69599+ cap_raise(cap_mask, cap);
69600+ if (cap_raised(curracl->cap_lower, cap))
69601+ cap_raise(cap_drop, cap);
69602+ }
69603+ }
69604+
69605+ if (!cap_raised(cap_drop, cap))
69606+ return 1;
69607+
69608+ return 0;
69609+}
69610+
69611+int
69612+gr_acl_is_capable_nolog(const int cap)
69613+{
69614+ return gr_task_acl_is_capable_nolog(current, cap);
69615+}
69616+
69617diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69618new file mode 100644
69619index 0000000..ca25605
69620--- /dev/null
69621+++ b/grsecurity/gracl_compat.c
69622@@ -0,0 +1,270 @@
69623+#include <linux/kernel.h>
69624+#include <linux/gracl.h>
69625+#include <linux/compat.h>
69626+#include <linux/gracl_compat.h>
69627+
69628+#include <asm/uaccess.h>
69629+
69630+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69631+{
69632+ struct gr_arg_wrapper_compat uwrapcompat;
69633+
69634+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69635+ return -EFAULT;
69636+
69637+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69638+ (uwrapcompat.version != 0x2901)) ||
69639+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69640+ return -EINVAL;
69641+
69642+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69643+ uwrap->version = uwrapcompat.version;
69644+ uwrap->size = sizeof(struct gr_arg);
69645+
69646+ return 0;
69647+}
69648+
69649+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69650+{
69651+ struct gr_arg_compat argcompat;
69652+
69653+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69654+ return -EFAULT;
69655+
69656+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69657+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69658+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69659+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69660+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69661+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69662+
69663+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69664+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69665+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69666+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69667+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69668+ arg->segv_device = argcompat.segv_device;
69669+ arg->segv_inode = argcompat.segv_inode;
69670+ arg->segv_uid = argcompat.segv_uid;
69671+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69672+ arg->mode = argcompat.mode;
69673+
69674+ return 0;
69675+}
69676+
69677+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69678+{
69679+ struct acl_object_label_compat objcompat;
69680+
69681+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69682+ return -EFAULT;
69683+
69684+ obj->filename = compat_ptr(objcompat.filename);
69685+ obj->inode = objcompat.inode;
69686+ obj->device = objcompat.device;
69687+ obj->mode = objcompat.mode;
69688+
69689+ obj->nested = compat_ptr(objcompat.nested);
69690+ obj->globbed = compat_ptr(objcompat.globbed);
69691+
69692+ obj->prev = compat_ptr(objcompat.prev);
69693+ obj->next = compat_ptr(objcompat.next);
69694+
69695+ return 0;
69696+}
69697+
69698+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69699+{
69700+ unsigned int i;
69701+ struct acl_subject_label_compat subjcompat;
69702+
69703+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69704+ return -EFAULT;
69705+
69706+ subj->filename = compat_ptr(subjcompat.filename);
69707+ subj->inode = subjcompat.inode;
69708+ subj->device = subjcompat.device;
69709+ subj->mode = subjcompat.mode;
69710+ subj->cap_mask = subjcompat.cap_mask;
69711+ subj->cap_lower = subjcompat.cap_lower;
69712+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69713+
69714+ for (i = 0; i < GR_NLIMITS; i++) {
69715+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69716+ subj->res[i].rlim_cur = RLIM_INFINITY;
69717+ else
69718+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69719+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69720+ subj->res[i].rlim_max = RLIM_INFINITY;
69721+ else
69722+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69723+ }
69724+ subj->resmask = subjcompat.resmask;
69725+
69726+ subj->user_trans_type = subjcompat.user_trans_type;
69727+ subj->group_trans_type = subjcompat.group_trans_type;
69728+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69729+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69730+ subj->user_trans_num = subjcompat.user_trans_num;
69731+ subj->group_trans_num = subjcompat.group_trans_num;
69732+
69733+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69734+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69735+ subj->ip_type = subjcompat.ip_type;
69736+ subj->ips = compat_ptr(subjcompat.ips);
69737+ subj->ip_num = subjcompat.ip_num;
69738+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69739+
69740+ subj->crashes = subjcompat.crashes;
69741+ subj->expires = subjcompat.expires;
69742+
69743+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69744+ subj->hash = compat_ptr(subjcompat.hash);
69745+ subj->prev = compat_ptr(subjcompat.prev);
69746+ subj->next = compat_ptr(subjcompat.next);
69747+
69748+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69749+ subj->obj_hash_size = subjcompat.obj_hash_size;
69750+ subj->pax_flags = subjcompat.pax_flags;
69751+
69752+ return 0;
69753+}
69754+
69755+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69756+{
69757+ struct acl_role_label_compat rolecompat;
69758+
69759+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69760+ return -EFAULT;
69761+
69762+ role->rolename = compat_ptr(rolecompat.rolename);
69763+ role->uidgid = rolecompat.uidgid;
69764+ role->roletype = rolecompat.roletype;
69765+
69766+ role->auth_attempts = rolecompat.auth_attempts;
69767+ role->expires = rolecompat.expires;
69768+
69769+ role->root_label = compat_ptr(rolecompat.root_label);
69770+ role->hash = compat_ptr(rolecompat.hash);
69771+
69772+ role->prev = compat_ptr(rolecompat.prev);
69773+ role->next = compat_ptr(rolecompat.next);
69774+
69775+ role->transitions = compat_ptr(rolecompat.transitions);
69776+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69777+ role->domain_children = compat_ptr(rolecompat.domain_children);
69778+ role->domain_child_num = rolecompat.domain_child_num;
69779+
69780+ role->umask = rolecompat.umask;
69781+
69782+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69783+ role->subj_hash_size = rolecompat.subj_hash_size;
69784+
69785+ return 0;
69786+}
69787+
69788+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69789+{
69790+ struct role_allowed_ip_compat roleip_compat;
69791+
69792+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69793+ return -EFAULT;
69794+
69795+ roleip->addr = roleip_compat.addr;
69796+ roleip->netmask = roleip_compat.netmask;
69797+
69798+ roleip->prev = compat_ptr(roleip_compat.prev);
69799+ roleip->next = compat_ptr(roleip_compat.next);
69800+
69801+ return 0;
69802+}
69803+
69804+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69805+{
69806+ struct role_transition_compat trans_compat;
69807+
69808+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69809+ return -EFAULT;
69810+
69811+ trans->rolename = compat_ptr(trans_compat.rolename);
69812+
69813+ trans->prev = compat_ptr(trans_compat.prev);
69814+ trans->next = compat_ptr(trans_compat.next);
69815+
69816+ return 0;
69817+
69818+}
69819+
69820+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69821+{
69822+ struct gr_hash_struct_compat hash_compat;
69823+
69824+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69825+ return -EFAULT;
69826+
69827+ hash->table = compat_ptr(hash_compat.table);
69828+ hash->nametable = compat_ptr(hash_compat.nametable);
69829+ hash->first = compat_ptr(hash_compat.first);
69830+
69831+ hash->table_size = hash_compat.table_size;
69832+ hash->used_size = hash_compat.used_size;
69833+
69834+ hash->type = hash_compat.type;
69835+
69836+ return 0;
69837+}
69838+
69839+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69840+{
69841+ compat_uptr_t ptrcompat;
69842+
69843+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69844+ return -EFAULT;
69845+
69846+ *(void **)ptr = compat_ptr(ptrcompat);
69847+
69848+ return 0;
69849+}
69850+
69851+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69852+{
69853+ struct acl_ip_label_compat ip_compat;
69854+
69855+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69856+ return -EFAULT;
69857+
69858+ ip->iface = compat_ptr(ip_compat.iface);
69859+ ip->addr = ip_compat.addr;
69860+ ip->netmask = ip_compat.netmask;
69861+ ip->low = ip_compat.low;
69862+ ip->high = ip_compat.high;
69863+ ip->mode = ip_compat.mode;
69864+ ip->type = ip_compat.type;
69865+
69866+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69867+
69868+ ip->prev = compat_ptr(ip_compat.prev);
69869+ ip->next = compat_ptr(ip_compat.next);
69870+
69871+ return 0;
69872+}
69873+
69874+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69875+{
69876+ struct sprole_pw_compat pw_compat;
69877+
69878+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69879+ return -EFAULT;
69880+
69881+ pw->rolename = compat_ptr(pw_compat.rolename);
69882+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69883+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69884+
69885+ return 0;
69886+}
69887+
69888+size_t get_gr_arg_wrapper_size_compat(void)
69889+{
69890+ return sizeof(struct gr_arg_wrapper_compat);
69891+}
69892+
69893diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69894new file mode 100644
69895index 0000000..a89b1f4
69896--- /dev/null
69897+++ b/grsecurity/gracl_fs.c
69898@@ -0,0 +1,437 @@
69899+#include <linux/kernel.h>
69900+#include <linux/sched.h>
69901+#include <linux/types.h>
69902+#include <linux/fs.h>
69903+#include <linux/file.h>
69904+#include <linux/stat.h>
69905+#include <linux/grsecurity.h>
69906+#include <linux/grinternal.h>
69907+#include <linux/gracl.h>
69908+
69909+umode_t
69910+gr_acl_umask(void)
69911+{
69912+ if (unlikely(!gr_acl_is_enabled()))
69913+ return 0;
69914+
69915+ return current->role->umask;
69916+}
69917+
69918+__u32
69919+gr_acl_handle_hidden_file(const struct dentry * dentry,
69920+ const struct vfsmount * mnt)
69921+{
69922+ __u32 mode;
69923+
69924+ if (unlikely(d_is_negative(dentry)))
69925+ return GR_FIND;
69926+
69927+ mode =
69928+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69929+
69930+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69931+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69932+ return mode;
69933+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69934+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69935+ return 0;
69936+ } else if (unlikely(!(mode & GR_FIND)))
69937+ return 0;
69938+
69939+ return GR_FIND;
69940+}
69941+
69942+__u32
69943+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69944+ int acc_mode)
69945+{
69946+ __u32 reqmode = GR_FIND;
69947+ __u32 mode;
69948+
69949+ if (unlikely(d_is_negative(dentry)))
69950+ return reqmode;
69951+
69952+ if (acc_mode & MAY_APPEND)
69953+ reqmode |= GR_APPEND;
69954+ else if (acc_mode & MAY_WRITE)
69955+ reqmode |= GR_WRITE;
69956+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69957+ reqmode |= GR_READ;
69958+
69959+ mode =
69960+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69961+ mnt);
69962+
69963+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69964+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69965+ reqmode & GR_READ ? " reading" : "",
69966+ reqmode & GR_WRITE ? " writing" : reqmode &
69967+ GR_APPEND ? " appending" : "");
69968+ return reqmode;
69969+ } else
69970+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69971+ {
69972+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69973+ reqmode & GR_READ ? " reading" : "",
69974+ reqmode & GR_WRITE ? " writing" : reqmode &
69975+ GR_APPEND ? " appending" : "");
69976+ return 0;
69977+ } else if (unlikely((mode & reqmode) != reqmode))
69978+ return 0;
69979+
69980+ return reqmode;
69981+}
69982+
69983+__u32
69984+gr_acl_handle_creat(const struct dentry * dentry,
69985+ const struct dentry * p_dentry,
69986+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69987+ const int imode)
69988+{
69989+ __u32 reqmode = GR_WRITE | GR_CREATE;
69990+ __u32 mode;
69991+
69992+ if (acc_mode & MAY_APPEND)
69993+ reqmode |= GR_APPEND;
69994+ // if a directory was required or the directory already exists, then
69995+ // don't count this open as a read
69996+ if ((acc_mode & MAY_READ) &&
69997+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69998+ reqmode |= GR_READ;
69999+ if ((open_flags & O_CREAT) &&
70000+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70001+ reqmode |= GR_SETID;
70002+
70003+ mode =
70004+ gr_check_create(dentry, p_dentry, p_mnt,
70005+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70006+
70007+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70008+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70009+ reqmode & GR_READ ? " reading" : "",
70010+ reqmode & GR_WRITE ? " writing" : reqmode &
70011+ GR_APPEND ? " appending" : "");
70012+ return reqmode;
70013+ } else
70014+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70015+ {
70016+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70017+ reqmode & GR_READ ? " reading" : "",
70018+ reqmode & GR_WRITE ? " writing" : reqmode &
70019+ GR_APPEND ? " appending" : "");
70020+ return 0;
70021+ } else if (unlikely((mode & reqmode) != reqmode))
70022+ return 0;
70023+
70024+ return reqmode;
70025+}
70026+
70027+__u32
70028+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70029+ const int fmode)
70030+{
70031+ __u32 mode, reqmode = GR_FIND;
70032+
70033+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70034+ reqmode |= GR_EXEC;
70035+ if (fmode & S_IWOTH)
70036+ reqmode |= GR_WRITE;
70037+ if (fmode & S_IROTH)
70038+ reqmode |= GR_READ;
70039+
70040+ mode =
70041+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70042+ mnt);
70043+
70044+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70045+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70046+ reqmode & GR_READ ? " reading" : "",
70047+ reqmode & GR_WRITE ? " writing" : "",
70048+ reqmode & GR_EXEC ? " executing" : "");
70049+ return reqmode;
70050+ } else
70051+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70052+ {
70053+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70054+ reqmode & GR_READ ? " reading" : "",
70055+ reqmode & GR_WRITE ? " writing" : "",
70056+ reqmode & GR_EXEC ? " executing" : "");
70057+ return 0;
70058+ } else if (unlikely((mode & reqmode) != reqmode))
70059+ return 0;
70060+
70061+ return reqmode;
70062+}
70063+
70064+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70065+{
70066+ __u32 mode;
70067+
70068+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70069+
70070+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70071+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70072+ return mode;
70073+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70074+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70075+ return 0;
70076+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70077+ return 0;
70078+
70079+ return (reqmode);
70080+}
70081+
70082+__u32
70083+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70084+{
70085+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70086+}
70087+
70088+__u32
70089+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70090+{
70091+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70092+}
70093+
70094+__u32
70095+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70096+{
70097+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70098+}
70099+
70100+__u32
70101+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70102+{
70103+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70104+}
70105+
70106+__u32
70107+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70108+ umode_t *modeptr)
70109+{
70110+ umode_t mode;
70111+
70112+ *modeptr &= ~gr_acl_umask();
70113+ mode = *modeptr;
70114+
70115+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70116+ return 1;
70117+
70118+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70119+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70120+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70121+ GR_CHMOD_ACL_MSG);
70122+ } else {
70123+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70124+ }
70125+}
70126+
70127+__u32
70128+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70129+{
70130+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70131+}
70132+
70133+__u32
70134+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70135+{
70136+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70137+}
70138+
70139+__u32
70140+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70141+{
70142+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70143+}
70144+
70145+__u32
70146+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70147+{
70148+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70149+}
70150+
70151+__u32
70152+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70153+{
70154+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70155+ GR_UNIXCONNECT_ACL_MSG);
70156+}
70157+
70158+/* hardlinks require at minimum create and link permission,
70159+ any additional privilege required is based on the
70160+ privilege of the file being linked to
70161+*/
70162+__u32
70163+gr_acl_handle_link(const struct dentry * new_dentry,
70164+ const struct dentry * parent_dentry,
70165+ const struct vfsmount * parent_mnt,
70166+ const struct dentry * old_dentry,
70167+ const struct vfsmount * old_mnt, const struct filename *to)
70168+{
70169+ __u32 mode;
70170+ __u32 needmode = GR_CREATE | GR_LINK;
70171+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70172+
70173+ mode =
70174+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70175+ old_mnt);
70176+
70177+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70178+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70179+ return mode;
70180+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70181+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70182+ return 0;
70183+ } else if (unlikely((mode & needmode) != needmode))
70184+ return 0;
70185+
70186+ return 1;
70187+}
70188+
70189+__u32
70190+gr_acl_handle_symlink(const struct dentry * new_dentry,
70191+ const struct dentry * parent_dentry,
70192+ const struct vfsmount * parent_mnt, const struct filename *from)
70193+{
70194+ __u32 needmode = GR_WRITE | GR_CREATE;
70195+ __u32 mode;
70196+
70197+ mode =
70198+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70199+ GR_CREATE | GR_AUDIT_CREATE |
70200+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70201+
70202+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70203+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70204+ return mode;
70205+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70206+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70207+ return 0;
70208+ } else if (unlikely((mode & needmode) != needmode))
70209+ return 0;
70210+
70211+ return (GR_WRITE | GR_CREATE);
70212+}
70213+
70214+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)
70215+{
70216+ __u32 mode;
70217+
70218+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70219+
70220+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70221+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70222+ return mode;
70223+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70224+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70225+ return 0;
70226+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70227+ return 0;
70228+
70229+ return (reqmode);
70230+}
70231+
70232+__u32
70233+gr_acl_handle_mknod(const struct dentry * new_dentry,
70234+ const struct dentry * parent_dentry,
70235+ const struct vfsmount * parent_mnt,
70236+ const int mode)
70237+{
70238+ __u32 reqmode = GR_WRITE | GR_CREATE;
70239+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70240+ reqmode |= GR_SETID;
70241+
70242+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70243+ reqmode, GR_MKNOD_ACL_MSG);
70244+}
70245+
70246+__u32
70247+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70248+ const struct dentry *parent_dentry,
70249+ const struct vfsmount *parent_mnt)
70250+{
70251+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70252+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70253+}
70254+
70255+#define RENAME_CHECK_SUCCESS(old, new) \
70256+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70257+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70258+
70259+int
70260+gr_acl_handle_rename(struct dentry *new_dentry,
70261+ struct dentry *parent_dentry,
70262+ const struct vfsmount *parent_mnt,
70263+ struct dentry *old_dentry,
70264+ struct inode *old_parent_inode,
70265+ struct vfsmount *old_mnt, const struct filename *newname)
70266+{
70267+ __u32 comp1, comp2;
70268+ int error = 0;
70269+
70270+ if (unlikely(!gr_acl_is_enabled()))
70271+ return 0;
70272+
70273+ if (d_is_negative(new_dentry)) {
70274+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70275+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70276+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70277+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70278+ GR_DELETE | GR_AUDIT_DELETE |
70279+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70280+ GR_SUPPRESS, old_mnt);
70281+ } else {
70282+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70283+ GR_CREATE | GR_DELETE |
70284+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70285+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70286+ GR_SUPPRESS, parent_mnt);
70287+ comp2 =
70288+ gr_search_file(old_dentry,
70289+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70290+ GR_DELETE | GR_AUDIT_DELETE |
70291+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70292+ }
70293+
70294+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70295+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70296+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70297+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70298+ && !(comp2 & GR_SUPPRESS)) {
70299+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70300+ error = -EACCES;
70301+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70302+ error = -EACCES;
70303+
70304+ return error;
70305+}
70306+
70307+void
70308+gr_acl_handle_exit(void)
70309+{
70310+ u16 id;
70311+ char *rolename;
70312+
70313+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70314+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70315+ id = current->acl_role_id;
70316+ rolename = current->role->rolename;
70317+ gr_set_acls(1);
70318+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70319+ }
70320+
70321+ gr_put_exec_file(current);
70322+ return;
70323+}
70324+
70325+int
70326+gr_acl_handle_procpidmem(const struct task_struct *task)
70327+{
70328+ if (unlikely(!gr_acl_is_enabled()))
70329+ return 0;
70330+
70331+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70332+ return -EACCES;
70333+
70334+ return 0;
70335+}
70336diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70337new file mode 100644
70338index 0000000..f056b81
70339--- /dev/null
70340+++ b/grsecurity/gracl_ip.c
70341@@ -0,0 +1,386 @@
70342+#include <linux/kernel.h>
70343+#include <asm/uaccess.h>
70344+#include <asm/errno.h>
70345+#include <net/sock.h>
70346+#include <linux/file.h>
70347+#include <linux/fs.h>
70348+#include <linux/net.h>
70349+#include <linux/in.h>
70350+#include <linux/skbuff.h>
70351+#include <linux/ip.h>
70352+#include <linux/udp.h>
70353+#include <linux/types.h>
70354+#include <linux/sched.h>
70355+#include <linux/netdevice.h>
70356+#include <linux/inetdevice.h>
70357+#include <linux/gracl.h>
70358+#include <linux/grsecurity.h>
70359+#include <linux/grinternal.h>
70360+
70361+#define GR_BIND 0x01
70362+#define GR_CONNECT 0x02
70363+#define GR_INVERT 0x04
70364+#define GR_BINDOVERRIDE 0x08
70365+#define GR_CONNECTOVERRIDE 0x10
70366+#define GR_SOCK_FAMILY 0x20
70367+
70368+static const char * gr_protocols[IPPROTO_MAX] = {
70369+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70370+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70371+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70372+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70373+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70374+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70375+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70376+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70377+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70378+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70379+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70380+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70381+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70382+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70383+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70384+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70385+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70386+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70387+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70388+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70389+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70390+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70391+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70392+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70393+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70394+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70395+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70396+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70397+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70398+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70399+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70400+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70401+ };
70402+
70403+static const char * gr_socktypes[SOCK_MAX] = {
70404+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70405+ "unknown:7", "unknown:8", "unknown:9", "packet"
70406+ };
70407+
70408+static const char * gr_sockfamilies[AF_MAX+1] = {
70409+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70410+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70411+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70412+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70413+ };
70414+
70415+const char *
70416+gr_proto_to_name(unsigned char proto)
70417+{
70418+ return gr_protocols[proto];
70419+}
70420+
70421+const char *
70422+gr_socktype_to_name(unsigned char type)
70423+{
70424+ return gr_socktypes[type];
70425+}
70426+
70427+const char *
70428+gr_sockfamily_to_name(unsigned char family)
70429+{
70430+ return gr_sockfamilies[family];
70431+}
70432+
70433+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70434+
70435+int
70436+gr_search_socket(const int domain, const int type, const int protocol)
70437+{
70438+ struct acl_subject_label *curr;
70439+ const struct cred *cred = current_cred();
70440+
70441+ if (unlikely(!gr_acl_is_enabled()))
70442+ goto exit;
70443+
70444+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70445+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70446+ goto exit; // let the kernel handle it
70447+
70448+ curr = current->acl;
70449+
70450+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70451+ /* the family is allowed, if this is PF_INET allow it only if
70452+ the extra sock type/protocol checks pass */
70453+ if (domain == PF_INET)
70454+ goto inet_check;
70455+ goto exit;
70456+ } else {
70457+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70458+ __u32 fakeip = 0;
70459+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70460+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70461+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70462+ gr_to_filename(current->exec_file->f_path.dentry,
70463+ current->exec_file->f_path.mnt) :
70464+ curr->filename, curr->filename,
70465+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70466+ &current->signal->saved_ip);
70467+ goto exit;
70468+ }
70469+ goto exit_fail;
70470+ }
70471+
70472+inet_check:
70473+ /* the rest of this checking is for IPv4 only */
70474+ if (!curr->ips)
70475+ goto exit;
70476+
70477+ if ((curr->ip_type & (1U << type)) &&
70478+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70479+ goto exit;
70480+
70481+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70482+ /* we don't place acls on raw sockets , and sometimes
70483+ dgram/ip sockets are opened for ioctl and not
70484+ bind/connect, so we'll fake a bind learn log */
70485+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70486+ __u32 fakeip = 0;
70487+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70488+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70489+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70490+ gr_to_filename(current->exec_file->f_path.dentry,
70491+ current->exec_file->f_path.mnt) :
70492+ curr->filename, curr->filename,
70493+ &fakeip, 0, type,
70494+ protocol, GR_CONNECT, &current->signal->saved_ip);
70495+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70496+ __u32 fakeip = 0;
70497+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70498+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70499+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70500+ gr_to_filename(current->exec_file->f_path.dentry,
70501+ current->exec_file->f_path.mnt) :
70502+ curr->filename, curr->filename,
70503+ &fakeip, 0, type,
70504+ protocol, GR_BIND, &current->signal->saved_ip);
70505+ }
70506+ /* we'll log when they use connect or bind */
70507+ goto exit;
70508+ }
70509+
70510+exit_fail:
70511+ if (domain == PF_INET)
70512+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70513+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70514+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70515+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70516+ gr_socktype_to_name(type), protocol);
70517+
70518+ return 0;
70519+exit:
70520+ return 1;
70521+}
70522+
70523+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)
70524+{
70525+ if ((ip->mode & mode) &&
70526+ (ip_port >= ip->low) &&
70527+ (ip_port <= ip->high) &&
70528+ ((ntohl(ip_addr) & our_netmask) ==
70529+ (ntohl(our_addr) & our_netmask))
70530+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70531+ && (ip->type & (1U << type))) {
70532+ if (ip->mode & GR_INVERT)
70533+ return 2; // specifically denied
70534+ else
70535+ return 1; // allowed
70536+ }
70537+
70538+ return 0; // not specifically allowed, may continue parsing
70539+}
70540+
70541+static int
70542+gr_search_connectbind(const int full_mode, struct sock *sk,
70543+ struct sockaddr_in *addr, const int type)
70544+{
70545+ char iface[IFNAMSIZ] = {0};
70546+ struct acl_subject_label *curr;
70547+ struct acl_ip_label *ip;
70548+ struct inet_sock *isk;
70549+ struct net_device *dev;
70550+ struct in_device *idev;
70551+ unsigned long i;
70552+ int ret;
70553+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70554+ __u32 ip_addr = 0;
70555+ __u32 our_addr;
70556+ __u32 our_netmask;
70557+ char *p;
70558+ __u16 ip_port = 0;
70559+ const struct cred *cred = current_cred();
70560+
70561+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70562+ return 0;
70563+
70564+ curr = current->acl;
70565+ isk = inet_sk(sk);
70566+
70567+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70568+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70569+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70570+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70571+ struct sockaddr_in saddr;
70572+ int err;
70573+
70574+ saddr.sin_family = AF_INET;
70575+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70576+ saddr.sin_port = isk->inet_sport;
70577+
70578+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70579+ if (err)
70580+ return err;
70581+
70582+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70583+ if (err)
70584+ return err;
70585+ }
70586+
70587+ if (!curr->ips)
70588+ return 0;
70589+
70590+ ip_addr = addr->sin_addr.s_addr;
70591+ ip_port = ntohs(addr->sin_port);
70592+
70593+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70594+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70595+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70596+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70597+ gr_to_filename(current->exec_file->f_path.dentry,
70598+ current->exec_file->f_path.mnt) :
70599+ curr->filename, curr->filename,
70600+ &ip_addr, ip_port, type,
70601+ sk->sk_protocol, mode, &current->signal->saved_ip);
70602+ return 0;
70603+ }
70604+
70605+ for (i = 0; i < curr->ip_num; i++) {
70606+ ip = *(curr->ips + i);
70607+ if (ip->iface != NULL) {
70608+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70609+ p = strchr(iface, ':');
70610+ if (p != NULL)
70611+ *p = '\0';
70612+ dev = dev_get_by_name(sock_net(sk), iface);
70613+ if (dev == NULL)
70614+ continue;
70615+ idev = in_dev_get(dev);
70616+ if (idev == NULL) {
70617+ dev_put(dev);
70618+ continue;
70619+ }
70620+ rcu_read_lock();
70621+ for_ifa(idev) {
70622+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70623+ our_addr = ifa->ifa_address;
70624+ our_netmask = 0xffffffff;
70625+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70626+ if (ret == 1) {
70627+ rcu_read_unlock();
70628+ in_dev_put(idev);
70629+ dev_put(dev);
70630+ return 0;
70631+ } else if (ret == 2) {
70632+ rcu_read_unlock();
70633+ in_dev_put(idev);
70634+ dev_put(dev);
70635+ goto denied;
70636+ }
70637+ }
70638+ } endfor_ifa(idev);
70639+ rcu_read_unlock();
70640+ in_dev_put(idev);
70641+ dev_put(dev);
70642+ } else {
70643+ our_addr = ip->addr;
70644+ our_netmask = ip->netmask;
70645+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70646+ if (ret == 1)
70647+ return 0;
70648+ else if (ret == 2)
70649+ goto denied;
70650+ }
70651+ }
70652+
70653+denied:
70654+ if (mode == GR_BIND)
70655+ 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));
70656+ else if (mode == GR_CONNECT)
70657+ 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));
70658+
70659+ return -EACCES;
70660+}
70661+
70662+int
70663+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70664+{
70665+ /* always allow disconnection of dgram sockets with connect */
70666+ if (addr->sin_family == AF_UNSPEC)
70667+ return 0;
70668+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70669+}
70670+
70671+int
70672+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70673+{
70674+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70675+}
70676+
70677+int gr_search_listen(struct socket *sock)
70678+{
70679+ struct sock *sk = sock->sk;
70680+ struct sockaddr_in addr;
70681+
70682+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70683+ addr.sin_port = inet_sk(sk)->inet_sport;
70684+
70685+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70686+}
70687+
70688+int gr_search_accept(struct socket *sock)
70689+{
70690+ struct sock *sk = sock->sk;
70691+ struct sockaddr_in addr;
70692+
70693+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70694+ addr.sin_port = inet_sk(sk)->inet_sport;
70695+
70696+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70697+}
70698+
70699+int
70700+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70701+{
70702+ if (addr)
70703+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70704+ else {
70705+ struct sockaddr_in sin;
70706+ const struct inet_sock *inet = inet_sk(sk);
70707+
70708+ sin.sin_addr.s_addr = inet->inet_daddr;
70709+ sin.sin_port = inet->inet_dport;
70710+
70711+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70712+ }
70713+}
70714+
70715+int
70716+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70717+{
70718+ struct sockaddr_in sin;
70719+
70720+ if (unlikely(skb->len < sizeof (struct udphdr)))
70721+ return 0; // skip this packet
70722+
70723+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70724+ sin.sin_port = udp_hdr(skb)->source;
70725+
70726+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70727+}
70728diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70729new file mode 100644
70730index 0000000..25f54ef
70731--- /dev/null
70732+++ b/grsecurity/gracl_learn.c
70733@@ -0,0 +1,207 @@
70734+#include <linux/kernel.h>
70735+#include <linux/mm.h>
70736+#include <linux/sched.h>
70737+#include <linux/poll.h>
70738+#include <linux/string.h>
70739+#include <linux/file.h>
70740+#include <linux/types.h>
70741+#include <linux/vmalloc.h>
70742+#include <linux/grinternal.h>
70743+
70744+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70745+ size_t count, loff_t *ppos);
70746+extern int gr_acl_is_enabled(void);
70747+
70748+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70749+static int gr_learn_attached;
70750+
70751+/* use a 512k buffer */
70752+#define LEARN_BUFFER_SIZE (512 * 1024)
70753+
70754+static DEFINE_SPINLOCK(gr_learn_lock);
70755+static DEFINE_MUTEX(gr_learn_user_mutex);
70756+
70757+/* we need to maintain two buffers, so that the kernel context of grlearn
70758+ uses a semaphore around the userspace copying, and the other kernel contexts
70759+ use a spinlock when copying into the buffer, since they cannot sleep
70760+*/
70761+static char *learn_buffer;
70762+static char *learn_buffer_user;
70763+static int learn_buffer_len;
70764+static int learn_buffer_user_len;
70765+
70766+static ssize_t
70767+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70768+{
70769+ DECLARE_WAITQUEUE(wait, current);
70770+ ssize_t retval = 0;
70771+
70772+ add_wait_queue(&learn_wait, &wait);
70773+ set_current_state(TASK_INTERRUPTIBLE);
70774+ do {
70775+ mutex_lock(&gr_learn_user_mutex);
70776+ spin_lock(&gr_learn_lock);
70777+ if (learn_buffer_len)
70778+ break;
70779+ spin_unlock(&gr_learn_lock);
70780+ mutex_unlock(&gr_learn_user_mutex);
70781+ if (file->f_flags & O_NONBLOCK) {
70782+ retval = -EAGAIN;
70783+ goto out;
70784+ }
70785+ if (signal_pending(current)) {
70786+ retval = -ERESTARTSYS;
70787+ goto out;
70788+ }
70789+
70790+ schedule();
70791+ } while (1);
70792+
70793+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70794+ learn_buffer_user_len = learn_buffer_len;
70795+ retval = learn_buffer_len;
70796+ learn_buffer_len = 0;
70797+
70798+ spin_unlock(&gr_learn_lock);
70799+
70800+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70801+ retval = -EFAULT;
70802+
70803+ mutex_unlock(&gr_learn_user_mutex);
70804+out:
70805+ set_current_state(TASK_RUNNING);
70806+ remove_wait_queue(&learn_wait, &wait);
70807+ return retval;
70808+}
70809+
70810+static unsigned int
70811+poll_learn(struct file * file, poll_table * wait)
70812+{
70813+ poll_wait(file, &learn_wait, wait);
70814+
70815+ if (learn_buffer_len)
70816+ return (POLLIN | POLLRDNORM);
70817+
70818+ return 0;
70819+}
70820+
70821+void
70822+gr_clear_learn_entries(void)
70823+{
70824+ char *tmp;
70825+
70826+ mutex_lock(&gr_learn_user_mutex);
70827+ spin_lock(&gr_learn_lock);
70828+ tmp = learn_buffer;
70829+ learn_buffer = NULL;
70830+ spin_unlock(&gr_learn_lock);
70831+ if (tmp)
70832+ vfree(tmp);
70833+ if (learn_buffer_user != NULL) {
70834+ vfree(learn_buffer_user);
70835+ learn_buffer_user = NULL;
70836+ }
70837+ learn_buffer_len = 0;
70838+ mutex_unlock(&gr_learn_user_mutex);
70839+
70840+ return;
70841+}
70842+
70843+void
70844+gr_add_learn_entry(const char *fmt, ...)
70845+{
70846+ va_list args;
70847+ unsigned int len;
70848+
70849+ if (!gr_learn_attached)
70850+ return;
70851+
70852+ spin_lock(&gr_learn_lock);
70853+
70854+ /* leave a gap at the end so we know when it's "full" but don't have to
70855+ compute the exact length of the string we're trying to append
70856+ */
70857+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70858+ spin_unlock(&gr_learn_lock);
70859+ wake_up_interruptible(&learn_wait);
70860+ return;
70861+ }
70862+ if (learn_buffer == NULL) {
70863+ spin_unlock(&gr_learn_lock);
70864+ return;
70865+ }
70866+
70867+ va_start(args, fmt);
70868+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70869+ va_end(args);
70870+
70871+ learn_buffer_len += len + 1;
70872+
70873+ spin_unlock(&gr_learn_lock);
70874+ wake_up_interruptible(&learn_wait);
70875+
70876+ return;
70877+}
70878+
70879+static int
70880+open_learn(struct inode *inode, struct file *file)
70881+{
70882+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70883+ return -EBUSY;
70884+ if (file->f_mode & FMODE_READ) {
70885+ int retval = 0;
70886+ mutex_lock(&gr_learn_user_mutex);
70887+ if (learn_buffer == NULL)
70888+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70889+ if (learn_buffer_user == NULL)
70890+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70891+ if (learn_buffer == NULL) {
70892+ retval = -ENOMEM;
70893+ goto out_error;
70894+ }
70895+ if (learn_buffer_user == NULL) {
70896+ retval = -ENOMEM;
70897+ goto out_error;
70898+ }
70899+ learn_buffer_len = 0;
70900+ learn_buffer_user_len = 0;
70901+ gr_learn_attached = 1;
70902+out_error:
70903+ mutex_unlock(&gr_learn_user_mutex);
70904+ return retval;
70905+ }
70906+ return 0;
70907+}
70908+
70909+static int
70910+close_learn(struct inode *inode, struct file *file)
70911+{
70912+ if (file->f_mode & FMODE_READ) {
70913+ char *tmp = NULL;
70914+ mutex_lock(&gr_learn_user_mutex);
70915+ spin_lock(&gr_learn_lock);
70916+ tmp = learn_buffer;
70917+ learn_buffer = NULL;
70918+ spin_unlock(&gr_learn_lock);
70919+ if (tmp)
70920+ vfree(tmp);
70921+ if (learn_buffer_user != NULL) {
70922+ vfree(learn_buffer_user);
70923+ learn_buffer_user = NULL;
70924+ }
70925+ learn_buffer_len = 0;
70926+ learn_buffer_user_len = 0;
70927+ gr_learn_attached = 0;
70928+ mutex_unlock(&gr_learn_user_mutex);
70929+ }
70930+
70931+ return 0;
70932+}
70933+
70934+const struct file_operations grsec_fops = {
70935+ .read = read_learn,
70936+ .write = write_grsec_handler,
70937+ .open = open_learn,
70938+ .release = close_learn,
70939+ .poll = poll_learn,
70940+};
70941diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70942new file mode 100644
70943index 0000000..361a099
70944--- /dev/null
70945+++ b/grsecurity/gracl_policy.c
70946@@ -0,0 +1,1782 @@
70947+#include <linux/kernel.h>
70948+#include <linux/module.h>
70949+#include <linux/sched.h>
70950+#include <linux/mm.h>
70951+#include <linux/file.h>
70952+#include <linux/fs.h>
70953+#include <linux/namei.h>
70954+#include <linux/mount.h>
70955+#include <linux/tty.h>
70956+#include <linux/proc_fs.h>
70957+#include <linux/lglock.h>
70958+#include <linux/slab.h>
70959+#include <linux/vmalloc.h>
70960+#include <linux/types.h>
70961+#include <linux/sysctl.h>
70962+#include <linux/netdevice.h>
70963+#include <linux/ptrace.h>
70964+#include <linux/gracl.h>
70965+#include <linux/gralloc.h>
70966+#include <linux/security.h>
70967+#include <linux/grinternal.h>
70968+#include <linux/pid_namespace.h>
70969+#include <linux/stop_machine.h>
70970+#include <linux/fdtable.h>
70971+#include <linux/percpu.h>
70972+#include <linux/lglock.h>
70973+#include <linux/hugetlb.h>
70974+#include <linux/posix-timers.h>
70975+#include "../fs/mount.h"
70976+
70977+#include <asm/uaccess.h>
70978+#include <asm/errno.h>
70979+#include <asm/mman.h>
70980+
70981+extern struct gr_policy_state *polstate;
70982+
70983+#define FOR_EACH_ROLE_START(role) \
70984+ role = polstate->role_list; \
70985+ while (role) {
70986+
70987+#define FOR_EACH_ROLE_END(role) \
70988+ role = role->prev; \
70989+ }
70990+
70991+struct path gr_real_root;
70992+
70993+extern struct gr_alloc_state *current_alloc_state;
70994+
70995+u16 acl_sp_role_value;
70996+
70997+static DEFINE_MUTEX(gr_dev_mutex);
70998+
70999+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71000+extern void gr_clear_learn_entries(void);
71001+
71002+static struct gr_arg gr_usermode;
71003+static unsigned char gr_system_salt[GR_SALT_LEN];
71004+static unsigned char gr_system_sum[GR_SHA_LEN];
71005+
71006+static unsigned int gr_auth_attempts = 0;
71007+static unsigned long gr_auth_expires = 0UL;
71008+
71009+struct acl_object_label *fakefs_obj_rw;
71010+struct acl_object_label *fakefs_obj_rwx;
71011+
71012+extern int gr_init_uidset(void);
71013+extern void gr_free_uidset(void);
71014+extern void gr_remove_uid(uid_t uid);
71015+extern int gr_find_uid(uid_t uid);
71016+
71017+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71018+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71019+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71020+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71021+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);
71022+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71023+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71024+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71025+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71026+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71027+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71028+extern void assign_special_role(const char *rolename);
71029+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71030+extern int gr_rbac_disable(void *unused);
71031+extern void gr_enable_rbac_system(void);
71032+
71033+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71034+{
71035+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71036+ return -EFAULT;
71037+
71038+ return 0;
71039+}
71040+
71041+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71042+{
71043+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71044+ return -EFAULT;
71045+
71046+ return 0;
71047+}
71048+
71049+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71050+{
71051+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71052+ return -EFAULT;
71053+
71054+ return 0;
71055+}
71056+
71057+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71058+{
71059+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71060+ return -EFAULT;
71061+
71062+ return 0;
71063+}
71064+
71065+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71066+{
71067+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71068+ return -EFAULT;
71069+
71070+ return 0;
71071+}
71072+
71073+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71074+{
71075+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71076+ return -EFAULT;
71077+
71078+ return 0;
71079+}
71080+
71081+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71082+{
71083+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71084+ return -EFAULT;
71085+
71086+ return 0;
71087+}
71088+
71089+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71090+{
71091+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71092+ return -EFAULT;
71093+
71094+ return 0;
71095+}
71096+
71097+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71098+{
71099+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71100+ return -EFAULT;
71101+
71102+ return 0;
71103+}
71104+
71105+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71106+{
71107+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71108+ return -EFAULT;
71109+
71110+ if (((uwrap->version != GRSECURITY_VERSION) &&
71111+ (uwrap->version != 0x2901)) ||
71112+ (uwrap->size != sizeof(struct gr_arg)))
71113+ return -EINVAL;
71114+
71115+ return 0;
71116+}
71117+
71118+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71119+{
71120+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71121+ return -EFAULT;
71122+
71123+ return 0;
71124+}
71125+
71126+static size_t get_gr_arg_wrapper_size_normal(void)
71127+{
71128+ return sizeof(struct gr_arg_wrapper);
71129+}
71130+
71131+#ifdef CONFIG_COMPAT
71132+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71133+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71134+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71135+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71136+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71137+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71138+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71139+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71140+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71141+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71142+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71143+extern size_t get_gr_arg_wrapper_size_compat(void);
71144+
71145+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71146+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71147+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71148+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71149+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71150+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71151+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71152+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71153+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71154+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71155+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71156+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71157+
71158+#else
71159+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71160+#define copy_gr_arg copy_gr_arg_normal
71161+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71162+#define copy_acl_object_label copy_acl_object_label_normal
71163+#define copy_acl_subject_label copy_acl_subject_label_normal
71164+#define copy_acl_role_label copy_acl_role_label_normal
71165+#define copy_acl_ip_label copy_acl_ip_label_normal
71166+#define copy_pointer_from_array copy_pointer_from_array_normal
71167+#define copy_sprole_pw copy_sprole_pw_normal
71168+#define copy_role_transition copy_role_transition_normal
71169+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71170+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71171+#endif
71172+
71173+static struct acl_subject_label *
71174+lookup_subject_map(const struct acl_subject_label *userp)
71175+{
71176+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71177+ struct subject_map *match;
71178+
71179+ match = polstate->subj_map_set.s_hash[index];
71180+
71181+ while (match && match->user != userp)
71182+ match = match->next;
71183+
71184+ if (match != NULL)
71185+ return match->kernel;
71186+ else
71187+ return NULL;
71188+}
71189+
71190+static void
71191+insert_subj_map_entry(struct subject_map *subjmap)
71192+{
71193+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71194+ struct subject_map **curr;
71195+
71196+ subjmap->prev = NULL;
71197+
71198+ curr = &polstate->subj_map_set.s_hash[index];
71199+ if (*curr != NULL)
71200+ (*curr)->prev = subjmap;
71201+
71202+ subjmap->next = *curr;
71203+ *curr = subjmap;
71204+
71205+ return;
71206+}
71207+
71208+static void
71209+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71210+{
71211+ unsigned int index =
71212+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71213+ struct acl_role_label **curr;
71214+ struct acl_role_label *tmp, *tmp2;
71215+
71216+ curr = &polstate->acl_role_set.r_hash[index];
71217+
71218+ /* simple case, slot is empty, just set it to our role */
71219+ if (*curr == NULL) {
71220+ *curr = role;
71221+ } else {
71222+ /* example:
71223+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71224+ 2 -> 3
71225+ */
71226+ /* first check to see if we can already be reached via this slot */
71227+ tmp = *curr;
71228+ while (tmp && tmp != role)
71229+ tmp = tmp->next;
71230+ if (tmp == role) {
71231+ /* we don't need to add ourselves to this slot's chain */
71232+ return;
71233+ }
71234+ /* we need to add ourselves to this chain, two cases */
71235+ if (role->next == NULL) {
71236+ /* simple case, append the current chain to our role */
71237+ role->next = *curr;
71238+ *curr = role;
71239+ } else {
71240+ /* 1 -> 2 -> 3 -> 4
71241+ 2 -> 3 -> 4
71242+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71243+ */
71244+ /* trickier case: walk our role's chain until we find
71245+ the role for the start of the current slot's chain */
71246+ tmp = role;
71247+ tmp2 = *curr;
71248+ while (tmp->next && tmp->next != tmp2)
71249+ tmp = tmp->next;
71250+ if (tmp->next == tmp2) {
71251+ /* from example above, we found 3, so just
71252+ replace this slot's chain with ours */
71253+ *curr = role;
71254+ } else {
71255+ /* we didn't find a subset of our role's chain
71256+ in the current slot's chain, so append their
71257+ chain to ours, and set us as the first role in
71258+ the slot's chain
71259+
71260+ we could fold this case with the case above,
71261+ but making it explicit for clarity
71262+ */
71263+ tmp->next = tmp2;
71264+ *curr = role;
71265+ }
71266+ }
71267+ }
71268+
71269+ return;
71270+}
71271+
71272+static void
71273+insert_acl_role_label(struct acl_role_label *role)
71274+{
71275+ int i;
71276+
71277+ if (polstate->role_list == NULL) {
71278+ polstate->role_list = role;
71279+ role->prev = NULL;
71280+ } else {
71281+ role->prev = polstate->role_list;
71282+ polstate->role_list = role;
71283+ }
71284+
71285+ /* used for hash chains */
71286+ role->next = NULL;
71287+
71288+ if (role->roletype & GR_ROLE_DOMAIN) {
71289+ for (i = 0; i < role->domain_child_num; i++)
71290+ __insert_acl_role_label(role, role->domain_children[i]);
71291+ } else
71292+ __insert_acl_role_label(role, role->uidgid);
71293+}
71294+
71295+static int
71296+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71297+{
71298+ struct name_entry **curr, *nentry;
71299+ struct inodev_entry *ientry;
71300+ unsigned int len = strlen(name);
71301+ unsigned int key = full_name_hash(name, len);
71302+ unsigned int index = key % polstate->name_set.n_size;
71303+
71304+ curr = &polstate->name_set.n_hash[index];
71305+
71306+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71307+ curr = &((*curr)->next);
71308+
71309+ if (*curr != NULL)
71310+ return 1;
71311+
71312+ nentry = acl_alloc(sizeof (struct name_entry));
71313+ if (nentry == NULL)
71314+ return 0;
71315+ ientry = acl_alloc(sizeof (struct inodev_entry));
71316+ if (ientry == NULL)
71317+ return 0;
71318+ ientry->nentry = nentry;
71319+
71320+ nentry->key = key;
71321+ nentry->name = name;
71322+ nentry->inode = inode;
71323+ nentry->device = device;
71324+ nentry->len = len;
71325+ nentry->deleted = deleted;
71326+
71327+ nentry->prev = NULL;
71328+ curr = &polstate->name_set.n_hash[index];
71329+ if (*curr != NULL)
71330+ (*curr)->prev = nentry;
71331+ nentry->next = *curr;
71332+ *curr = nentry;
71333+
71334+ /* insert us into the table searchable by inode/dev */
71335+ __insert_inodev_entry(polstate, ientry);
71336+
71337+ return 1;
71338+}
71339+
71340+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71341+
71342+static void *
71343+create_table(__u32 * len, int elementsize)
71344+{
71345+ unsigned int table_sizes[] = {
71346+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71347+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71348+ 4194301, 8388593, 16777213, 33554393, 67108859
71349+ };
71350+ void *newtable = NULL;
71351+ unsigned int pwr = 0;
71352+
71353+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71354+ table_sizes[pwr] <= *len)
71355+ pwr++;
71356+
71357+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71358+ return newtable;
71359+
71360+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71361+ newtable =
71362+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71363+ else
71364+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71365+
71366+ *len = table_sizes[pwr];
71367+
71368+ return newtable;
71369+}
71370+
71371+static int
71372+init_variables(const struct gr_arg *arg, bool reload)
71373+{
71374+ struct task_struct *reaper = init_pid_ns.child_reaper;
71375+ unsigned int stacksize;
71376+
71377+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71378+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71379+ polstate->name_set.n_size = arg->role_db.num_objects;
71380+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71381+
71382+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71383+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71384+ return 1;
71385+
71386+ if (!reload) {
71387+ if (!gr_init_uidset())
71388+ return 1;
71389+ }
71390+
71391+ /* set up the stack that holds allocation info */
71392+
71393+ stacksize = arg->role_db.num_pointers + 5;
71394+
71395+ if (!acl_alloc_stack_init(stacksize))
71396+ return 1;
71397+
71398+ if (!reload) {
71399+ /* grab reference for the real root dentry and vfsmount */
71400+ get_fs_root(reaper->fs, &gr_real_root);
71401+
71402+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71403+ 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);
71404+#endif
71405+
71406+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71407+ if (fakefs_obj_rw == NULL)
71408+ return 1;
71409+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71410+
71411+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71412+ if (fakefs_obj_rwx == NULL)
71413+ return 1;
71414+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71415+ }
71416+
71417+ polstate->subj_map_set.s_hash =
71418+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71419+ polstate->acl_role_set.r_hash =
71420+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71421+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71422+ polstate->inodev_set.i_hash =
71423+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71424+
71425+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71426+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71427+ return 1;
71428+
71429+ memset(polstate->subj_map_set.s_hash, 0,
71430+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71431+ memset(polstate->acl_role_set.r_hash, 0,
71432+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71433+ memset(polstate->name_set.n_hash, 0,
71434+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71435+ memset(polstate->inodev_set.i_hash, 0,
71436+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71437+
71438+ return 0;
71439+}
71440+
71441+/* free information not needed after startup
71442+ currently contains user->kernel pointer mappings for subjects
71443+*/
71444+
71445+static void
71446+free_init_variables(void)
71447+{
71448+ __u32 i;
71449+
71450+ if (polstate->subj_map_set.s_hash) {
71451+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71452+ if (polstate->subj_map_set.s_hash[i]) {
71453+ kfree(polstate->subj_map_set.s_hash[i]);
71454+ polstate->subj_map_set.s_hash[i] = NULL;
71455+ }
71456+ }
71457+
71458+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71459+ PAGE_SIZE)
71460+ kfree(polstate->subj_map_set.s_hash);
71461+ else
71462+ vfree(polstate->subj_map_set.s_hash);
71463+ }
71464+
71465+ return;
71466+}
71467+
71468+static void
71469+free_variables(bool reload)
71470+{
71471+ struct acl_subject_label *s;
71472+ struct acl_role_label *r;
71473+ struct task_struct *task, *task2;
71474+ unsigned int x;
71475+
71476+ if (!reload) {
71477+ gr_clear_learn_entries();
71478+
71479+ read_lock(&tasklist_lock);
71480+ do_each_thread(task2, task) {
71481+ task->acl_sp_role = 0;
71482+ task->acl_role_id = 0;
71483+ task->inherited = 0;
71484+ task->acl = NULL;
71485+ task->role = NULL;
71486+ } while_each_thread(task2, task);
71487+ read_unlock(&tasklist_lock);
71488+
71489+ kfree(fakefs_obj_rw);
71490+ fakefs_obj_rw = NULL;
71491+ kfree(fakefs_obj_rwx);
71492+ fakefs_obj_rwx = NULL;
71493+
71494+ /* release the reference to the real root dentry and vfsmount */
71495+ path_put(&gr_real_root);
71496+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71497+ }
71498+
71499+ /* free all object hash tables */
71500+
71501+ FOR_EACH_ROLE_START(r)
71502+ if (r->subj_hash == NULL)
71503+ goto next_role;
71504+ FOR_EACH_SUBJECT_START(r, s, x)
71505+ if (s->obj_hash == NULL)
71506+ break;
71507+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71508+ kfree(s->obj_hash);
71509+ else
71510+ vfree(s->obj_hash);
71511+ FOR_EACH_SUBJECT_END(s, x)
71512+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71513+ if (s->obj_hash == NULL)
71514+ break;
71515+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71516+ kfree(s->obj_hash);
71517+ else
71518+ vfree(s->obj_hash);
71519+ FOR_EACH_NESTED_SUBJECT_END(s)
71520+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71521+ kfree(r->subj_hash);
71522+ else
71523+ vfree(r->subj_hash);
71524+ r->subj_hash = NULL;
71525+next_role:
71526+ FOR_EACH_ROLE_END(r)
71527+
71528+ acl_free_all();
71529+
71530+ if (polstate->acl_role_set.r_hash) {
71531+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71532+ PAGE_SIZE)
71533+ kfree(polstate->acl_role_set.r_hash);
71534+ else
71535+ vfree(polstate->acl_role_set.r_hash);
71536+ }
71537+ if (polstate->name_set.n_hash) {
71538+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71539+ PAGE_SIZE)
71540+ kfree(polstate->name_set.n_hash);
71541+ else
71542+ vfree(polstate->name_set.n_hash);
71543+ }
71544+
71545+ if (polstate->inodev_set.i_hash) {
71546+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71547+ PAGE_SIZE)
71548+ kfree(polstate->inodev_set.i_hash);
71549+ else
71550+ vfree(polstate->inodev_set.i_hash);
71551+ }
71552+
71553+ if (!reload)
71554+ gr_free_uidset();
71555+
71556+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71557+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71558+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71559+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71560+
71561+ polstate->default_role = NULL;
71562+ polstate->kernel_role = NULL;
71563+ polstate->role_list = NULL;
71564+
71565+ return;
71566+}
71567+
71568+static struct acl_subject_label *
71569+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71570+
71571+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71572+{
71573+ unsigned int len = strnlen_user(*name, maxlen);
71574+ char *tmp;
71575+
71576+ if (!len || len >= maxlen)
71577+ return -EINVAL;
71578+
71579+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71580+ return -ENOMEM;
71581+
71582+ if (copy_from_user(tmp, *name, len))
71583+ return -EFAULT;
71584+
71585+ tmp[len-1] = '\0';
71586+ *name = tmp;
71587+
71588+ return 0;
71589+}
71590+
71591+static int
71592+copy_user_glob(struct acl_object_label *obj)
71593+{
71594+ struct acl_object_label *g_tmp, **guser;
71595+ int error;
71596+
71597+ if (obj->globbed == NULL)
71598+ return 0;
71599+
71600+ guser = &obj->globbed;
71601+ while (*guser) {
71602+ g_tmp = (struct acl_object_label *)
71603+ acl_alloc(sizeof (struct acl_object_label));
71604+ if (g_tmp == NULL)
71605+ return -ENOMEM;
71606+
71607+ if (copy_acl_object_label(g_tmp, *guser))
71608+ return -EFAULT;
71609+
71610+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71611+ if (error)
71612+ return error;
71613+
71614+ *guser = g_tmp;
71615+ guser = &(g_tmp->next);
71616+ }
71617+
71618+ return 0;
71619+}
71620+
71621+static int
71622+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71623+ struct acl_role_label *role)
71624+{
71625+ struct acl_object_label *o_tmp;
71626+ int ret;
71627+
71628+ while (userp) {
71629+ if ((o_tmp = (struct acl_object_label *)
71630+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71631+ return -ENOMEM;
71632+
71633+ if (copy_acl_object_label(o_tmp, userp))
71634+ return -EFAULT;
71635+
71636+ userp = o_tmp->prev;
71637+
71638+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71639+ if (ret)
71640+ return ret;
71641+
71642+ insert_acl_obj_label(o_tmp, subj);
71643+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71644+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71645+ return -ENOMEM;
71646+
71647+ ret = copy_user_glob(o_tmp);
71648+ if (ret)
71649+ return ret;
71650+
71651+ if (o_tmp->nested) {
71652+ int already_copied;
71653+
71654+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71655+ if (IS_ERR(o_tmp->nested))
71656+ return PTR_ERR(o_tmp->nested);
71657+
71658+ /* insert into nested subject list if we haven't copied this one yet
71659+ to prevent duplicate entries */
71660+ if (!already_copied) {
71661+ o_tmp->nested->next = role->hash->first;
71662+ role->hash->first = o_tmp->nested;
71663+ }
71664+ }
71665+ }
71666+
71667+ return 0;
71668+}
71669+
71670+static __u32
71671+count_user_subjs(struct acl_subject_label *userp)
71672+{
71673+ struct acl_subject_label s_tmp;
71674+ __u32 num = 0;
71675+
71676+ while (userp) {
71677+ if (copy_acl_subject_label(&s_tmp, userp))
71678+ break;
71679+
71680+ userp = s_tmp.prev;
71681+ }
71682+
71683+ return num;
71684+}
71685+
71686+static int
71687+copy_user_allowedips(struct acl_role_label *rolep)
71688+{
71689+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71690+
71691+ ruserip = rolep->allowed_ips;
71692+
71693+ while (ruserip) {
71694+ rlast = rtmp;
71695+
71696+ if ((rtmp = (struct role_allowed_ip *)
71697+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71698+ return -ENOMEM;
71699+
71700+ if (copy_role_allowed_ip(rtmp, ruserip))
71701+ return -EFAULT;
71702+
71703+ ruserip = rtmp->prev;
71704+
71705+ if (!rlast) {
71706+ rtmp->prev = NULL;
71707+ rolep->allowed_ips = rtmp;
71708+ } else {
71709+ rlast->next = rtmp;
71710+ rtmp->prev = rlast;
71711+ }
71712+
71713+ if (!ruserip)
71714+ rtmp->next = NULL;
71715+ }
71716+
71717+ return 0;
71718+}
71719+
71720+static int
71721+copy_user_transitions(struct acl_role_label *rolep)
71722+{
71723+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71724+ int error;
71725+
71726+ rusertp = rolep->transitions;
71727+
71728+ while (rusertp) {
71729+ rlast = rtmp;
71730+
71731+ if ((rtmp = (struct role_transition *)
71732+ acl_alloc(sizeof (struct role_transition))) == NULL)
71733+ return -ENOMEM;
71734+
71735+ if (copy_role_transition(rtmp, rusertp))
71736+ return -EFAULT;
71737+
71738+ rusertp = rtmp->prev;
71739+
71740+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71741+ if (error)
71742+ return error;
71743+
71744+ if (!rlast) {
71745+ rtmp->prev = NULL;
71746+ rolep->transitions = rtmp;
71747+ } else {
71748+ rlast->next = rtmp;
71749+ rtmp->prev = rlast;
71750+ }
71751+
71752+ if (!rusertp)
71753+ rtmp->next = NULL;
71754+ }
71755+
71756+ return 0;
71757+}
71758+
71759+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71760+{
71761+ struct acl_object_label o_tmp;
71762+ __u32 num = 0;
71763+
71764+ while (userp) {
71765+ if (copy_acl_object_label(&o_tmp, userp))
71766+ break;
71767+
71768+ userp = o_tmp.prev;
71769+ num++;
71770+ }
71771+
71772+ return num;
71773+}
71774+
71775+static struct acl_subject_label *
71776+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71777+{
71778+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71779+ __u32 num_objs;
71780+ struct acl_ip_label **i_tmp, *i_utmp2;
71781+ struct gr_hash_struct ghash;
71782+ struct subject_map *subjmap;
71783+ unsigned int i_num;
71784+ int err;
71785+
71786+ if (already_copied != NULL)
71787+ *already_copied = 0;
71788+
71789+ s_tmp = lookup_subject_map(userp);
71790+
71791+ /* we've already copied this subject into the kernel, just return
71792+ the reference to it, and don't copy it over again
71793+ */
71794+ if (s_tmp) {
71795+ if (already_copied != NULL)
71796+ *already_copied = 1;
71797+ return(s_tmp);
71798+ }
71799+
71800+ if ((s_tmp = (struct acl_subject_label *)
71801+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71802+ return ERR_PTR(-ENOMEM);
71803+
71804+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71805+ if (subjmap == NULL)
71806+ return ERR_PTR(-ENOMEM);
71807+
71808+ subjmap->user = userp;
71809+ subjmap->kernel = s_tmp;
71810+ insert_subj_map_entry(subjmap);
71811+
71812+ if (copy_acl_subject_label(s_tmp, userp))
71813+ return ERR_PTR(-EFAULT);
71814+
71815+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71816+ if (err)
71817+ return ERR_PTR(err);
71818+
71819+ if (!strcmp(s_tmp->filename, "/"))
71820+ role->root_label = s_tmp;
71821+
71822+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71823+ return ERR_PTR(-EFAULT);
71824+
71825+ /* copy user and group transition tables */
71826+
71827+ if (s_tmp->user_trans_num) {
71828+ uid_t *uidlist;
71829+
71830+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71831+ if (uidlist == NULL)
71832+ return ERR_PTR(-ENOMEM);
71833+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71834+ return ERR_PTR(-EFAULT);
71835+
71836+ s_tmp->user_transitions = uidlist;
71837+ }
71838+
71839+ if (s_tmp->group_trans_num) {
71840+ gid_t *gidlist;
71841+
71842+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71843+ if (gidlist == NULL)
71844+ return ERR_PTR(-ENOMEM);
71845+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71846+ return ERR_PTR(-EFAULT);
71847+
71848+ s_tmp->group_transitions = gidlist;
71849+ }
71850+
71851+ /* set up object hash table */
71852+ num_objs = count_user_objs(ghash.first);
71853+
71854+ s_tmp->obj_hash_size = num_objs;
71855+ s_tmp->obj_hash =
71856+ (struct acl_object_label **)
71857+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71858+
71859+ if (!s_tmp->obj_hash)
71860+ return ERR_PTR(-ENOMEM);
71861+
71862+ memset(s_tmp->obj_hash, 0,
71863+ s_tmp->obj_hash_size *
71864+ sizeof (struct acl_object_label *));
71865+
71866+ /* add in objects */
71867+ err = copy_user_objs(ghash.first, s_tmp, role);
71868+
71869+ if (err)
71870+ return ERR_PTR(err);
71871+
71872+ /* set pointer for parent subject */
71873+ if (s_tmp->parent_subject) {
71874+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71875+
71876+ if (IS_ERR(s_tmp2))
71877+ return s_tmp2;
71878+
71879+ s_tmp->parent_subject = s_tmp2;
71880+ }
71881+
71882+ /* add in ip acls */
71883+
71884+ if (!s_tmp->ip_num) {
71885+ s_tmp->ips = NULL;
71886+ goto insert;
71887+ }
71888+
71889+ i_tmp =
71890+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71891+ sizeof (struct acl_ip_label *));
71892+
71893+ if (!i_tmp)
71894+ return ERR_PTR(-ENOMEM);
71895+
71896+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71897+ *(i_tmp + i_num) =
71898+ (struct acl_ip_label *)
71899+ acl_alloc(sizeof (struct acl_ip_label));
71900+ if (!*(i_tmp + i_num))
71901+ return ERR_PTR(-ENOMEM);
71902+
71903+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71904+ return ERR_PTR(-EFAULT);
71905+
71906+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71907+ return ERR_PTR(-EFAULT);
71908+
71909+ if ((*(i_tmp + i_num))->iface == NULL)
71910+ continue;
71911+
71912+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71913+ if (err)
71914+ return ERR_PTR(err);
71915+ }
71916+
71917+ s_tmp->ips = i_tmp;
71918+
71919+insert:
71920+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71921+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71922+ return ERR_PTR(-ENOMEM);
71923+
71924+ return s_tmp;
71925+}
71926+
71927+static int
71928+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71929+{
71930+ struct acl_subject_label s_pre;
71931+ struct acl_subject_label * ret;
71932+ int err;
71933+
71934+ while (userp) {
71935+ if (copy_acl_subject_label(&s_pre, userp))
71936+ return -EFAULT;
71937+
71938+ ret = do_copy_user_subj(userp, role, NULL);
71939+
71940+ err = PTR_ERR(ret);
71941+ if (IS_ERR(ret))
71942+ return err;
71943+
71944+ insert_acl_subj_label(ret, role);
71945+
71946+ userp = s_pre.prev;
71947+ }
71948+
71949+ return 0;
71950+}
71951+
71952+static int
71953+copy_user_acl(struct gr_arg *arg)
71954+{
71955+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71956+ struct acl_subject_label *subj_list;
71957+ struct sprole_pw *sptmp;
71958+ struct gr_hash_struct *ghash;
71959+ uid_t *domainlist;
71960+ unsigned int r_num;
71961+ int err = 0;
71962+ __u16 i;
71963+ __u32 num_subjs;
71964+
71965+ /* we need a default and kernel role */
71966+ if (arg->role_db.num_roles < 2)
71967+ return -EINVAL;
71968+
71969+ /* copy special role authentication info from userspace */
71970+
71971+ polstate->num_sprole_pws = arg->num_sprole_pws;
71972+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71973+
71974+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71975+ return -ENOMEM;
71976+
71977+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71978+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71979+ if (!sptmp)
71980+ return -ENOMEM;
71981+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71982+ return -EFAULT;
71983+
71984+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71985+ if (err)
71986+ return err;
71987+
71988+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71989+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71990+#endif
71991+
71992+ polstate->acl_special_roles[i] = sptmp;
71993+ }
71994+
71995+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71996+
71997+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71998+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
71999+
72000+ if (!r_tmp)
72001+ return -ENOMEM;
72002+
72003+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72004+ return -EFAULT;
72005+
72006+ if (copy_acl_role_label(r_tmp, r_utmp2))
72007+ return -EFAULT;
72008+
72009+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72010+ if (err)
72011+ return err;
72012+
72013+ if (!strcmp(r_tmp->rolename, "default")
72014+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72015+ polstate->default_role = r_tmp;
72016+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72017+ polstate->kernel_role = r_tmp;
72018+ }
72019+
72020+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72021+ return -ENOMEM;
72022+
72023+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72024+ return -EFAULT;
72025+
72026+ r_tmp->hash = ghash;
72027+
72028+ num_subjs = count_user_subjs(r_tmp->hash->first);
72029+
72030+ r_tmp->subj_hash_size = num_subjs;
72031+ r_tmp->subj_hash =
72032+ (struct acl_subject_label **)
72033+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72034+
72035+ if (!r_tmp->subj_hash)
72036+ return -ENOMEM;
72037+
72038+ err = copy_user_allowedips(r_tmp);
72039+ if (err)
72040+ return err;
72041+
72042+ /* copy domain info */
72043+ if (r_tmp->domain_children != NULL) {
72044+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72045+ if (domainlist == NULL)
72046+ return -ENOMEM;
72047+
72048+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72049+ return -EFAULT;
72050+
72051+ r_tmp->domain_children = domainlist;
72052+ }
72053+
72054+ err = copy_user_transitions(r_tmp);
72055+ if (err)
72056+ return err;
72057+
72058+ memset(r_tmp->subj_hash, 0,
72059+ r_tmp->subj_hash_size *
72060+ sizeof (struct acl_subject_label *));
72061+
72062+ /* acquire the list of subjects, then NULL out
72063+ the list prior to parsing the subjects for this role,
72064+ as during this parsing the list is replaced with a list
72065+ of *nested* subjects for the role
72066+ */
72067+ subj_list = r_tmp->hash->first;
72068+
72069+ /* set nested subject list to null */
72070+ r_tmp->hash->first = NULL;
72071+
72072+ err = copy_user_subjs(subj_list, r_tmp);
72073+
72074+ if (err)
72075+ return err;
72076+
72077+ insert_acl_role_label(r_tmp);
72078+ }
72079+
72080+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72081+ return -EINVAL;
72082+
72083+ return err;
72084+}
72085+
72086+static int gracl_reload_apply_policies(void *reload)
72087+{
72088+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72089+ struct task_struct *task, *task2;
72090+ struct acl_role_label *role, *rtmp;
72091+ struct acl_subject_label *subj;
72092+ const struct cred *cred;
72093+ int role_applied;
72094+ int ret = 0;
72095+
72096+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72097+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72098+
72099+ /* first make sure we'll be able to apply the new policy cleanly */
72100+ do_each_thread(task2, task) {
72101+ if (task->exec_file == NULL)
72102+ continue;
72103+ role_applied = 0;
72104+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72105+ /* preserve special roles */
72106+ FOR_EACH_ROLE_START(role)
72107+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72108+ rtmp = task->role;
72109+ task->role = role;
72110+ role_applied = 1;
72111+ break;
72112+ }
72113+ FOR_EACH_ROLE_END(role)
72114+ }
72115+ if (!role_applied) {
72116+ cred = __task_cred(task);
72117+ rtmp = task->role;
72118+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72119+ }
72120+ /* this handles non-nested inherited subjects, nested subjects will still
72121+ be dropped currently */
72122+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72123+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72124+ /* change the role back so that we've made no modifications to the policy */
72125+ task->role = rtmp;
72126+
72127+ if (subj == NULL || task->tmpacl == NULL) {
72128+ ret = -EINVAL;
72129+ goto out;
72130+ }
72131+ } while_each_thread(task2, task);
72132+
72133+ /* now actually apply the policy */
72134+
72135+ do_each_thread(task2, task) {
72136+ if (task->exec_file) {
72137+ role_applied = 0;
72138+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72139+ /* preserve special roles */
72140+ FOR_EACH_ROLE_START(role)
72141+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72142+ task->role = role;
72143+ role_applied = 1;
72144+ break;
72145+ }
72146+ FOR_EACH_ROLE_END(role)
72147+ }
72148+ if (!role_applied) {
72149+ cred = __task_cred(task);
72150+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72151+ }
72152+ /* this handles non-nested inherited subjects, nested subjects will still
72153+ be dropped currently */
72154+ if (!reload_state->oldmode && task->inherited)
72155+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72156+ else {
72157+ /* looked up and tagged to the task previously */
72158+ subj = task->tmpacl;
72159+ }
72160+ /* subj will be non-null */
72161+ __gr_apply_subject_to_task(polstate, task, subj);
72162+ if (reload_state->oldmode) {
72163+ task->acl_role_id = 0;
72164+ task->acl_sp_role = 0;
72165+ task->inherited = 0;
72166+ }
72167+ } else {
72168+ // it's a kernel process
72169+ task->role = polstate->kernel_role;
72170+ task->acl = polstate->kernel_role->root_label;
72171+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72172+ task->acl->mode &= ~GR_PROCFIND;
72173+#endif
72174+ }
72175+ } while_each_thread(task2, task);
72176+
72177+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72178+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72179+
72180+out:
72181+
72182+ return ret;
72183+}
72184+
72185+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72186+{
72187+ struct gr_reload_state new_reload_state = { };
72188+ int err;
72189+
72190+ new_reload_state.oldpolicy_ptr = polstate;
72191+ new_reload_state.oldalloc_ptr = current_alloc_state;
72192+ new_reload_state.oldmode = oldmode;
72193+
72194+ current_alloc_state = &new_reload_state.newalloc;
72195+ polstate = &new_reload_state.newpolicy;
72196+
72197+ /* everything relevant is now saved off, copy in the new policy */
72198+ if (init_variables(args, true)) {
72199+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72200+ err = -ENOMEM;
72201+ goto error;
72202+ }
72203+
72204+ err = copy_user_acl(args);
72205+ free_init_variables();
72206+ if (err)
72207+ goto error;
72208+ /* the new policy is copied in, with the old policy available via saved_state
72209+ first go through applying roles, making sure to preserve special roles
72210+ then apply new subjects, making sure to preserve inherited and nested subjects,
72211+ though currently only inherited subjects will be preserved
72212+ */
72213+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72214+ if (err)
72215+ goto error;
72216+
72217+ /* we've now applied the new policy, so restore the old policy state to free it */
72218+ polstate = &new_reload_state.oldpolicy;
72219+ current_alloc_state = &new_reload_state.oldalloc;
72220+ free_variables(true);
72221+
72222+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72223+ to running_polstate/current_alloc_state inside stop_machine
72224+ */
72225+ err = 0;
72226+ goto out;
72227+error:
72228+ /* on error of loading the new policy, we'll just keep the previous
72229+ policy set around
72230+ */
72231+ free_variables(true);
72232+
72233+ /* doesn't affect runtime, but maintains consistent state */
72234+out:
72235+ polstate = new_reload_state.oldpolicy_ptr;
72236+ current_alloc_state = new_reload_state.oldalloc_ptr;
72237+
72238+ return err;
72239+}
72240+
72241+static int
72242+gracl_init(struct gr_arg *args)
72243+{
72244+ int error = 0;
72245+
72246+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72247+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72248+
72249+ if (init_variables(args, false)) {
72250+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72251+ error = -ENOMEM;
72252+ goto out;
72253+ }
72254+
72255+ error = copy_user_acl(args);
72256+ free_init_variables();
72257+ if (error)
72258+ goto out;
72259+
72260+ error = gr_set_acls(0);
72261+ if (error)
72262+ goto out;
72263+
72264+ gr_enable_rbac_system();
72265+
72266+ return 0;
72267+
72268+out:
72269+ free_variables(false);
72270+ return error;
72271+}
72272+
72273+static int
72274+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72275+ unsigned char **sum)
72276+{
72277+ struct acl_role_label *r;
72278+ struct role_allowed_ip *ipp;
72279+ struct role_transition *trans;
72280+ unsigned int i;
72281+ int found = 0;
72282+ u32 curr_ip = current->signal->curr_ip;
72283+
72284+ current->signal->saved_ip = curr_ip;
72285+
72286+ /* check transition table */
72287+
72288+ for (trans = current->role->transitions; trans; trans = trans->next) {
72289+ if (!strcmp(rolename, trans->rolename)) {
72290+ found = 1;
72291+ break;
72292+ }
72293+ }
72294+
72295+ if (!found)
72296+ return 0;
72297+
72298+ /* handle special roles that do not require authentication
72299+ and check ip */
72300+
72301+ FOR_EACH_ROLE_START(r)
72302+ if (!strcmp(rolename, r->rolename) &&
72303+ (r->roletype & GR_ROLE_SPECIAL)) {
72304+ found = 0;
72305+ if (r->allowed_ips != NULL) {
72306+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72307+ if ((ntohl(curr_ip) & ipp->netmask) ==
72308+ (ntohl(ipp->addr) & ipp->netmask))
72309+ found = 1;
72310+ }
72311+ } else
72312+ found = 2;
72313+ if (!found)
72314+ return 0;
72315+
72316+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72317+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72318+ *salt = NULL;
72319+ *sum = NULL;
72320+ return 1;
72321+ }
72322+ }
72323+ FOR_EACH_ROLE_END(r)
72324+
72325+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72326+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72327+ *salt = polstate->acl_special_roles[i]->salt;
72328+ *sum = polstate->acl_special_roles[i]->sum;
72329+ return 1;
72330+ }
72331+ }
72332+
72333+ return 0;
72334+}
72335+
72336+int gr_check_secure_terminal(struct task_struct *task)
72337+{
72338+ struct task_struct *p, *p2, *p3;
72339+ struct files_struct *files;
72340+ struct fdtable *fdt;
72341+ struct file *our_file = NULL, *file;
72342+ int i;
72343+
72344+ if (task->signal->tty == NULL)
72345+ return 1;
72346+
72347+ files = get_files_struct(task);
72348+ if (files != NULL) {
72349+ rcu_read_lock();
72350+ fdt = files_fdtable(files);
72351+ for (i=0; i < fdt->max_fds; i++) {
72352+ file = fcheck_files(files, i);
72353+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72354+ get_file(file);
72355+ our_file = file;
72356+ }
72357+ }
72358+ rcu_read_unlock();
72359+ put_files_struct(files);
72360+ }
72361+
72362+ if (our_file == NULL)
72363+ return 1;
72364+
72365+ read_lock(&tasklist_lock);
72366+ do_each_thread(p2, p) {
72367+ files = get_files_struct(p);
72368+ if (files == NULL ||
72369+ (p->signal && p->signal->tty == task->signal->tty)) {
72370+ if (files != NULL)
72371+ put_files_struct(files);
72372+ continue;
72373+ }
72374+ rcu_read_lock();
72375+ fdt = files_fdtable(files);
72376+ for (i=0; i < fdt->max_fds; i++) {
72377+ file = fcheck_files(files, i);
72378+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72379+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72380+ p3 = task;
72381+ while (task_pid_nr(p3) > 0) {
72382+ if (p3 == p)
72383+ break;
72384+ p3 = p3->real_parent;
72385+ }
72386+ if (p3 == p)
72387+ break;
72388+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72389+ gr_handle_alertkill(p);
72390+ rcu_read_unlock();
72391+ put_files_struct(files);
72392+ read_unlock(&tasklist_lock);
72393+ fput(our_file);
72394+ return 0;
72395+ }
72396+ }
72397+ rcu_read_unlock();
72398+ put_files_struct(files);
72399+ } while_each_thread(p2, p);
72400+ read_unlock(&tasklist_lock);
72401+
72402+ fput(our_file);
72403+ return 1;
72404+}
72405+
72406+ssize_t
72407+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72408+{
72409+ struct gr_arg_wrapper uwrap;
72410+ unsigned char *sprole_salt = NULL;
72411+ unsigned char *sprole_sum = NULL;
72412+ int error = 0;
72413+ int error2 = 0;
72414+ size_t req_count = 0;
72415+ unsigned char oldmode = 0;
72416+
72417+ mutex_lock(&gr_dev_mutex);
72418+
72419+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72420+ error = -EPERM;
72421+ goto out;
72422+ }
72423+
72424+#ifdef CONFIG_COMPAT
72425+ pax_open_kernel();
72426+ if (is_compat_task()) {
72427+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72428+ copy_gr_arg = &copy_gr_arg_compat;
72429+ copy_acl_object_label = &copy_acl_object_label_compat;
72430+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72431+ copy_acl_role_label = &copy_acl_role_label_compat;
72432+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72433+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72434+ copy_role_transition = &copy_role_transition_compat;
72435+ copy_sprole_pw = &copy_sprole_pw_compat;
72436+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72437+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72438+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72439+ } else {
72440+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72441+ copy_gr_arg = &copy_gr_arg_normal;
72442+ copy_acl_object_label = &copy_acl_object_label_normal;
72443+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72444+ copy_acl_role_label = &copy_acl_role_label_normal;
72445+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72446+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72447+ copy_role_transition = &copy_role_transition_normal;
72448+ copy_sprole_pw = &copy_sprole_pw_normal;
72449+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72450+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72451+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72452+ }
72453+ pax_close_kernel();
72454+#endif
72455+
72456+ req_count = get_gr_arg_wrapper_size();
72457+
72458+ if (count != req_count) {
72459+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72460+ error = -EINVAL;
72461+ goto out;
72462+ }
72463+
72464+
72465+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72466+ gr_auth_expires = 0;
72467+ gr_auth_attempts = 0;
72468+ }
72469+
72470+ error = copy_gr_arg_wrapper(buf, &uwrap);
72471+ if (error)
72472+ goto out;
72473+
72474+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72475+ if (error)
72476+ goto out;
72477+
72478+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72479+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72480+ time_after(gr_auth_expires, get_seconds())) {
72481+ error = -EBUSY;
72482+ goto out;
72483+ }
72484+
72485+ /* if non-root trying to do anything other than use a special role,
72486+ do not attempt authentication, do not count towards authentication
72487+ locking
72488+ */
72489+
72490+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72491+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72492+ gr_is_global_nonroot(current_uid())) {
72493+ error = -EPERM;
72494+ goto out;
72495+ }
72496+
72497+ /* ensure pw and special role name are null terminated */
72498+
72499+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72500+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72501+
72502+ /* Okay.
72503+ * We have our enough of the argument structure..(we have yet
72504+ * to copy_from_user the tables themselves) . Copy the tables
72505+ * only if we need them, i.e. for loading operations. */
72506+
72507+ switch (gr_usermode.mode) {
72508+ case GR_STATUS:
72509+ if (gr_acl_is_enabled()) {
72510+ error = 1;
72511+ if (!gr_check_secure_terminal(current))
72512+ error = 3;
72513+ } else
72514+ error = 2;
72515+ goto out;
72516+ case GR_SHUTDOWN:
72517+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72518+ stop_machine(gr_rbac_disable, NULL, NULL);
72519+ free_variables(false);
72520+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72521+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72522+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72523+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72524+ } else if (gr_acl_is_enabled()) {
72525+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72526+ error = -EPERM;
72527+ } else {
72528+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72529+ error = -EAGAIN;
72530+ }
72531+ break;
72532+ case GR_ENABLE:
72533+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72534+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72535+ else {
72536+ if (gr_acl_is_enabled())
72537+ error = -EAGAIN;
72538+ else
72539+ error = error2;
72540+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72541+ }
72542+ break;
72543+ case GR_OLDRELOAD:
72544+ oldmode = 1;
72545+ case GR_RELOAD:
72546+ if (!gr_acl_is_enabled()) {
72547+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72548+ error = -EAGAIN;
72549+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72550+ error2 = gracl_reload(&gr_usermode, oldmode);
72551+ if (!error2)
72552+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72553+ else {
72554+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72555+ error = error2;
72556+ }
72557+ } else {
72558+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72559+ error = -EPERM;
72560+ }
72561+ break;
72562+ case GR_SEGVMOD:
72563+ if (unlikely(!gr_acl_is_enabled())) {
72564+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72565+ error = -EAGAIN;
72566+ break;
72567+ }
72568+
72569+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72570+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72571+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72572+ struct acl_subject_label *segvacl;
72573+ segvacl =
72574+ lookup_acl_subj_label(gr_usermode.segv_inode,
72575+ gr_usermode.segv_device,
72576+ current->role);
72577+ if (segvacl) {
72578+ segvacl->crashes = 0;
72579+ segvacl->expires = 0;
72580+ }
72581+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72582+ gr_remove_uid(gr_usermode.segv_uid);
72583+ }
72584+ } else {
72585+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72586+ error = -EPERM;
72587+ }
72588+ break;
72589+ case GR_SPROLE:
72590+ case GR_SPROLEPAM:
72591+ if (unlikely(!gr_acl_is_enabled())) {
72592+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72593+ error = -EAGAIN;
72594+ break;
72595+ }
72596+
72597+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72598+ current->role->expires = 0;
72599+ current->role->auth_attempts = 0;
72600+ }
72601+
72602+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72603+ time_after(current->role->expires, get_seconds())) {
72604+ error = -EBUSY;
72605+ goto out;
72606+ }
72607+
72608+ if (lookup_special_role_auth
72609+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72610+ && ((!sprole_salt && !sprole_sum)
72611+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72612+ char *p = "";
72613+ assign_special_role(gr_usermode.sp_role);
72614+ read_lock(&tasklist_lock);
72615+ if (current->real_parent)
72616+ p = current->real_parent->role->rolename;
72617+ read_unlock(&tasklist_lock);
72618+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72619+ p, acl_sp_role_value);
72620+ } else {
72621+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72622+ error = -EPERM;
72623+ if(!(current->role->auth_attempts++))
72624+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72625+
72626+ goto out;
72627+ }
72628+ break;
72629+ case GR_UNSPROLE:
72630+ if (unlikely(!gr_acl_is_enabled())) {
72631+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72632+ error = -EAGAIN;
72633+ break;
72634+ }
72635+
72636+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72637+ char *p = "";
72638+ int i = 0;
72639+
72640+ read_lock(&tasklist_lock);
72641+ if (current->real_parent) {
72642+ p = current->real_parent->role->rolename;
72643+ i = current->real_parent->acl_role_id;
72644+ }
72645+ read_unlock(&tasklist_lock);
72646+
72647+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72648+ gr_set_acls(1);
72649+ } else {
72650+ error = -EPERM;
72651+ goto out;
72652+ }
72653+ break;
72654+ default:
72655+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72656+ error = -EINVAL;
72657+ break;
72658+ }
72659+
72660+ if (error != -EPERM)
72661+ goto out;
72662+
72663+ if(!(gr_auth_attempts++))
72664+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72665+
72666+ out:
72667+ mutex_unlock(&gr_dev_mutex);
72668+
72669+ if (!error)
72670+ error = req_count;
72671+
72672+ return error;
72673+}
72674+
72675+int
72676+gr_set_acls(const int type)
72677+{
72678+ struct task_struct *task, *task2;
72679+ struct acl_role_label *role = current->role;
72680+ struct acl_subject_label *subj;
72681+ __u16 acl_role_id = current->acl_role_id;
72682+ const struct cred *cred;
72683+ int ret;
72684+
72685+ rcu_read_lock();
72686+ read_lock(&tasklist_lock);
72687+ read_lock(&grsec_exec_file_lock);
72688+ do_each_thread(task2, task) {
72689+ /* check to see if we're called from the exit handler,
72690+ if so, only replace ACLs that have inherited the admin
72691+ ACL */
72692+
72693+ if (type && (task->role != role ||
72694+ task->acl_role_id != acl_role_id))
72695+ continue;
72696+
72697+ task->acl_role_id = 0;
72698+ task->acl_sp_role = 0;
72699+ task->inherited = 0;
72700+
72701+ if (task->exec_file) {
72702+ cred = __task_cred(task);
72703+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72704+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72705+ if (subj == NULL) {
72706+ ret = -EINVAL;
72707+ read_unlock(&grsec_exec_file_lock);
72708+ read_unlock(&tasklist_lock);
72709+ rcu_read_unlock();
72710+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72711+ return ret;
72712+ }
72713+ __gr_apply_subject_to_task(polstate, task, subj);
72714+ } else {
72715+ // it's a kernel process
72716+ task->role = polstate->kernel_role;
72717+ task->acl = polstate->kernel_role->root_label;
72718+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72719+ task->acl->mode &= ~GR_PROCFIND;
72720+#endif
72721+ }
72722+ } while_each_thread(task2, task);
72723+ read_unlock(&grsec_exec_file_lock);
72724+ read_unlock(&tasklist_lock);
72725+ rcu_read_unlock();
72726+
72727+ return 0;
72728+}
72729diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72730new file mode 100644
72731index 0000000..39645c9
72732--- /dev/null
72733+++ b/grsecurity/gracl_res.c
72734@@ -0,0 +1,68 @@
72735+#include <linux/kernel.h>
72736+#include <linux/sched.h>
72737+#include <linux/gracl.h>
72738+#include <linux/grinternal.h>
72739+
72740+static const char *restab_log[] = {
72741+ [RLIMIT_CPU] = "RLIMIT_CPU",
72742+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72743+ [RLIMIT_DATA] = "RLIMIT_DATA",
72744+ [RLIMIT_STACK] = "RLIMIT_STACK",
72745+ [RLIMIT_CORE] = "RLIMIT_CORE",
72746+ [RLIMIT_RSS] = "RLIMIT_RSS",
72747+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72748+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72749+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72750+ [RLIMIT_AS] = "RLIMIT_AS",
72751+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72752+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72753+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72754+ [RLIMIT_NICE] = "RLIMIT_NICE",
72755+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72756+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72757+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72758+};
72759+
72760+void
72761+gr_log_resource(const struct task_struct *task,
72762+ const int res, const unsigned long wanted, const int gt)
72763+{
72764+ const struct cred *cred;
72765+ unsigned long rlim;
72766+
72767+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72768+ return;
72769+
72770+ // not yet supported resource
72771+ if (unlikely(!restab_log[res]))
72772+ return;
72773+
72774+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72775+ rlim = task_rlimit_max(task, res);
72776+ else
72777+ rlim = task_rlimit(task, res);
72778+
72779+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72780+ return;
72781+
72782+ rcu_read_lock();
72783+ cred = __task_cred(task);
72784+
72785+ if (res == RLIMIT_NPROC &&
72786+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72787+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72788+ goto out_rcu_unlock;
72789+ else if (res == RLIMIT_MEMLOCK &&
72790+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72791+ goto out_rcu_unlock;
72792+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72793+ goto out_rcu_unlock;
72794+ rcu_read_unlock();
72795+
72796+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72797+
72798+ return;
72799+out_rcu_unlock:
72800+ rcu_read_unlock();
72801+ return;
72802+}
72803diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72804new file mode 100644
72805index 0000000..2040e61
72806--- /dev/null
72807+++ b/grsecurity/gracl_segv.c
72808@@ -0,0 +1,313 @@
72809+#include <linux/kernel.h>
72810+#include <linux/mm.h>
72811+#include <asm/uaccess.h>
72812+#include <asm/errno.h>
72813+#include <asm/mman.h>
72814+#include <net/sock.h>
72815+#include <linux/file.h>
72816+#include <linux/fs.h>
72817+#include <linux/net.h>
72818+#include <linux/in.h>
72819+#include <linux/slab.h>
72820+#include <linux/types.h>
72821+#include <linux/sched.h>
72822+#include <linux/timer.h>
72823+#include <linux/gracl.h>
72824+#include <linux/grsecurity.h>
72825+#include <linux/grinternal.h>
72826+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72827+#include <linux/magic.h>
72828+#include <linux/pagemap.h>
72829+#include "../fs/btrfs/async-thread.h"
72830+#include "../fs/btrfs/ctree.h"
72831+#include "../fs/btrfs/btrfs_inode.h"
72832+#endif
72833+
72834+static struct crash_uid *uid_set;
72835+static unsigned short uid_used;
72836+static DEFINE_SPINLOCK(gr_uid_lock);
72837+extern rwlock_t gr_inode_lock;
72838+extern struct acl_subject_label *
72839+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72840+ struct acl_role_label *role);
72841+
72842+static inline dev_t __get_dev(const struct dentry *dentry)
72843+{
72844+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72845+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72846+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72847+ else
72848+#endif
72849+ return dentry->d_sb->s_dev;
72850+}
72851+
72852+int
72853+gr_init_uidset(void)
72854+{
72855+ uid_set =
72856+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72857+ uid_used = 0;
72858+
72859+ return uid_set ? 1 : 0;
72860+}
72861+
72862+void
72863+gr_free_uidset(void)
72864+{
72865+ if (uid_set) {
72866+ struct crash_uid *tmpset;
72867+ spin_lock(&gr_uid_lock);
72868+ tmpset = uid_set;
72869+ uid_set = NULL;
72870+ uid_used = 0;
72871+ spin_unlock(&gr_uid_lock);
72872+ if (tmpset)
72873+ kfree(tmpset);
72874+ }
72875+
72876+ return;
72877+}
72878+
72879+int
72880+gr_find_uid(const uid_t uid)
72881+{
72882+ struct crash_uid *tmp = uid_set;
72883+ uid_t buid;
72884+ int low = 0, high = uid_used - 1, mid;
72885+
72886+ while (high >= low) {
72887+ mid = (low + high) >> 1;
72888+ buid = tmp[mid].uid;
72889+ if (buid == uid)
72890+ return mid;
72891+ if (buid > uid)
72892+ high = mid - 1;
72893+ if (buid < uid)
72894+ low = mid + 1;
72895+ }
72896+
72897+ return -1;
72898+}
72899+
72900+static __inline__ void
72901+gr_insertsort(void)
72902+{
72903+ unsigned short i, j;
72904+ struct crash_uid index;
72905+
72906+ for (i = 1; i < uid_used; i++) {
72907+ index = uid_set[i];
72908+ j = i;
72909+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72910+ uid_set[j] = uid_set[j - 1];
72911+ j--;
72912+ }
72913+ uid_set[j] = index;
72914+ }
72915+
72916+ return;
72917+}
72918+
72919+static __inline__ void
72920+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72921+{
72922+ int loc;
72923+ uid_t uid = GR_GLOBAL_UID(kuid);
72924+
72925+ if (uid_used == GR_UIDTABLE_MAX)
72926+ return;
72927+
72928+ loc = gr_find_uid(uid);
72929+
72930+ if (loc >= 0) {
72931+ uid_set[loc].expires = expires;
72932+ return;
72933+ }
72934+
72935+ uid_set[uid_used].uid = uid;
72936+ uid_set[uid_used].expires = expires;
72937+ uid_used++;
72938+
72939+ gr_insertsort();
72940+
72941+ return;
72942+}
72943+
72944+void
72945+gr_remove_uid(const unsigned short loc)
72946+{
72947+ unsigned short i;
72948+
72949+ for (i = loc + 1; i < uid_used; i++)
72950+ uid_set[i - 1] = uid_set[i];
72951+
72952+ uid_used--;
72953+
72954+ return;
72955+}
72956+
72957+int
72958+gr_check_crash_uid(const kuid_t kuid)
72959+{
72960+ int loc;
72961+ int ret = 0;
72962+ uid_t uid;
72963+
72964+ if (unlikely(!gr_acl_is_enabled()))
72965+ return 0;
72966+
72967+ uid = GR_GLOBAL_UID(kuid);
72968+
72969+ spin_lock(&gr_uid_lock);
72970+ loc = gr_find_uid(uid);
72971+
72972+ if (loc < 0)
72973+ goto out_unlock;
72974+
72975+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
72976+ gr_remove_uid(loc);
72977+ else
72978+ ret = 1;
72979+
72980+out_unlock:
72981+ spin_unlock(&gr_uid_lock);
72982+ return ret;
72983+}
72984+
72985+static __inline__ int
72986+proc_is_setxid(const struct cred *cred)
72987+{
72988+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72989+ !uid_eq(cred->uid, cred->fsuid))
72990+ return 1;
72991+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72992+ !gid_eq(cred->gid, cred->fsgid))
72993+ return 1;
72994+
72995+ return 0;
72996+}
72997+
72998+extern int gr_fake_force_sig(int sig, struct task_struct *t);
72999+
73000+void
73001+gr_handle_crash(struct task_struct *task, const int sig)
73002+{
73003+ struct acl_subject_label *curr;
73004+ struct task_struct *tsk, *tsk2;
73005+ const struct cred *cred;
73006+ const struct cred *cred2;
73007+
73008+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73009+ return;
73010+
73011+ if (unlikely(!gr_acl_is_enabled()))
73012+ return;
73013+
73014+ curr = task->acl;
73015+
73016+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73017+ return;
73018+
73019+ if (time_before_eq(curr->expires, get_seconds())) {
73020+ curr->expires = 0;
73021+ curr->crashes = 0;
73022+ }
73023+
73024+ curr->crashes++;
73025+
73026+ if (!curr->expires)
73027+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73028+
73029+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73030+ time_after(curr->expires, get_seconds())) {
73031+ rcu_read_lock();
73032+ cred = __task_cred(task);
73033+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73034+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73035+ spin_lock(&gr_uid_lock);
73036+ gr_insert_uid(cred->uid, curr->expires);
73037+ spin_unlock(&gr_uid_lock);
73038+ curr->expires = 0;
73039+ curr->crashes = 0;
73040+ read_lock(&tasklist_lock);
73041+ do_each_thread(tsk2, tsk) {
73042+ cred2 = __task_cred(tsk);
73043+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73044+ gr_fake_force_sig(SIGKILL, tsk);
73045+ } while_each_thread(tsk2, tsk);
73046+ read_unlock(&tasklist_lock);
73047+ } else {
73048+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73049+ read_lock(&tasklist_lock);
73050+ read_lock(&grsec_exec_file_lock);
73051+ do_each_thread(tsk2, tsk) {
73052+ if (likely(tsk != task)) {
73053+ // if this thread has the same subject as the one that triggered
73054+ // RES_CRASH and it's the same binary, kill it
73055+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73056+ gr_fake_force_sig(SIGKILL, tsk);
73057+ }
73058+ } while_each_thread(tsk2, tsk);
73059+ read_unlock(&grsec_exec_file_lock);
73060+ read_unlock(&tasklist_lock);
73061+ }
73062+ rcu_read_unlock();
73063+ }
73064+
73065+ return;
73066+}
73067+
73068+int
73069+gr_check_crash_exec(const struct file *filp)
73070+{
73071+ struct acl_subject_label *curr;
73072+
73073+ if (unlikely(!gr_acl_is_enabled()))
73074+ return 0;
73075+
73076+ read_lock(&gr_inode_lock);
73077+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73078+ __get_dev(filp->f_path.dentry),
73079+ current->role);
73080+ read_unlock(&gr_inode_lock);
73081+
73082+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73083+ (!curr->crashes && !curr->expires))
73084+ return 0;
73085+
73086+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73087+ time_after(curr->expires, get_seconds()))
73088+ return 1;
73089+ else if (time_before_eq(curr->expires, get_seconds())) {
73090+ curr->crashes = 0;
73091+ curr->expires = 0;
73092+ }
73093+
73094+ return 0;
73095+}
73096+
73097+void
73098+gr_handle_alertkill(struct task_struct *task)
73099+{
73100+ struct acl_subject_label *curracl;
73101+ __u32 curr_ip;
73102+ struct task_struct *p, *p2;
73103+
73104+ if (unlikely(!gr_acl_is_enabled()))
73105+ return;
73106+
73107+ curracl = task->acl;
73108+ curr_ip = task->signal->curr_ip;
73109+
73110+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73111+ read_lock(&tasklist_lock);
73112+ do_each_thread(p2, p) {
73113+ if (p->signal->curr_ip == curr_ip)
73114+ gr_fake_force_sig(SIGKILL, p);
73115+ } while_each_thread(p2, p);
73116+ read_unlock(&tasklist_lock);
73117+ } else if (curracl->mode & GR_KILLPROC)
73118+ gr_fake_force_sig(SIGKILL, task);
73119+
73120+ return;
73121+}
73122diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73123new file mode 100644
73124index 0000000..98011b0
73125--- /dev/null
73126+++ b/grsecurity/gracl_shm.c
73127@@ -0,0 +1,40 @@
73128+#include <linux/kernel.h>
73129+#include <linux/mm.h>
73130+#include <linux/sched.h>
73131+#include <linux/file.h>
73132+#include <linux/ipc.h>
73133+#include <linux/gracl.h>
73134+#include <linux/grsecurity.h>
73135+#include <linux/grinternal.h>
73136+
73137+int
73138+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73139+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73140+{
73141+ struct task_struct *task;
73142+
73143+ if (!gr_acl_is_enabled())
73144+ return 1;
73145+
73146+ rcu_read_lock();
73147+ read_lock(&tasklist_lock);
73148+
73149+ task = find_task_by_vpid(shm_cprid);
73150+
73151+ if (unlikely(!task))
73152+ task = find_task_by_vpid(shm_lapid);
73153+
73154+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73155+ (task_pid_nr(task) == shm_lapid)) &&
73156+ (task->acl->mode & GR_PROTSHM) &&
73157+ (task->acl != current->acl))) {
73158+ read_unlock(&tasklist_lock);
73159+ rcu_read_unlock();
73160+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73161+ return 0;
73162+ }
73163+ read_unlock(&tasklist_lock);
73164+ rcu_read_unlock();
73165+
73166+ return 1;
73167+}
73168diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73169new file mode 100644
73170index 0000000..bc0be01
73171--- /dev/null
73172+++ b/grsecurity/grsec_chdir.c
73173@@ -0,0 +1,19 @@
73174+#include <linux/kernel.h>
73175+#include <linux/sched.h>
73176+#include <linux/fs.h>
73177+#include <linux/file.h>
73178+#include <linux/grsecurity.h>
73179+#include <linux/grinternal.h>
73180+
73181+void
73182+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73183+{
73184+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73185+ if ((grsec_enable_chdir && grsec_enable_group &&
73186+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73187+ !grsec_enable_group)) {
73188+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73189+ }
73190+#endif
73191+ return;
73192+}
73193diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73194new file mode 100644
73195index 0000000..651d6c2
73196--- /dev/null
73197+++ b/grsecurity/grsec_chroot.c
73198@@ -0,0 +1,370 @@
73199+#include <linux/kernel.h>
73200+#include <linux/module.h>
73201+#include <linux/sched.h>
73202+#include <linux/file.h>
73203+#include <linux/fs.h>
73204+#include <linux/mount.h>
73205+#include <linux/types.h>
73206+#include "../fs/mount.h"
73207+#include <linux/grsecurity.h>
73208+#include <linux/grinternal.h>
73209+
73210+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73211+int gr_init_ran;
73212+#endif
73213+
73214+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73215+{
73216+#ifdef CONFIG_GRKERNSEC
73217+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73218+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73219+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73220+ && gr_init_ran
73221+#endif
73222+ )
73223+ task->gr_is_chrooted = 1;
73224+ else {
73225+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73226+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73227+ gr_init_ran = 1;
73228+#endif
73229+ task->gr_is_chrooted = 0;
73230+ }
73231+
73232+ task->gr_chroot_dentry = path->dentry;
73233+#endif
73234+ return;
73235+}
73236+
73237+void gr_clear_chroot_entries(struct task_struct *task)
73238+{
73239+#ifdef CONFIG_GRKERNSEC
73240+ task->gr_is_chrooted = 0;
73241+ task->gr_chroot_dentry = NULL;
73242+#endif
73243+ return;
73244+}
73245+
73246+int
73247+gr_handle_chroot_unix(const pid_t pid)
73248+{
73249+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73250+ struct task_struct *p;
73251+
73252+ if (unlikely(!grsec_enable_chroot_unix))
73253+ return 1;
73254+
73255+ if (likely(!proc_is_chrooted(current)))
73256+ return 1;
73257+
73258+ rcu_read_lock();
73259+ read_lock(&tasklist_lock);
73260+ p = find_task_by_vpid_unrestricted(pid);
73261+ if (unlikely(p && !have_same_root(current, p))) {
73262+ read_unlock(&tasklist_lock);
73263+ rcu_read_unlock();
73264+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73265+ return 0;
73266+ }
73267+ read_unlock(&tasklist_lock);
73268+ rcu_read_unlock();
73269+#endif
73270+ return 1;
73271+}
73272+
73273+int
73274+gr_handle_chroot_nice(void)
73275+{
73276+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73277+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73278+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73279+ return -EPERM;
73280+ }
73281+#endif
73282+ return 0;
73283+}
73284+
73285+int
73286+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73287+{
73288+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73289+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73290+ && proc_is_chrooted(current)) {
73291+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73292+ return -EACCES;
73293+ }
73294+#endif
73295+ return 0;
73296+}
73297+
73298+int
73299+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73300+{
73301+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73302+ struct task_struct *p;
73303+ int ret = 0;
73304+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73305+ return ret;
73306+
73307+ read_lock(&tasklist_lock);
73308+ do_each_pid_task(pid, type, p) {
73309+ if (!have_same_root(current, p)) {
73310+ ret = 1;
73311+ goto out;
73312+ }
73313+ } while_each_pid_task(pid, type, p);
73314+out:
73315+ read_unlock(&tasklist_lock);
73316+ return ret;
73317+#endif
73318+ return 0;
73319+}
73320+
73321+int
73322+gr_pid_is_chrooted(struct task_struct *p)
73323+{
73324+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73325+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73326+ return 0;
73327+
73328+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73329+ !have_same_root(current, p)) {
73330+ return 1;
73331+ }
73332+#endif
73333+ return 0;
73334+}
73335+
73336+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73337+
73338+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73339+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73340+{
73341+ struct path path, currentroot;
73342+ int ret = 0;
73343+
73344+ path.dentry = (struct dentry *)u_dentry;
73345+ path.mnt = (struct vfsmount *)u_mnt;
73346+ get_fs_root(current->fs, &currentroot);
73347+ if (path_is_under(&path, &currentroot))
73348+ ret = 1;
73349+ path_put(&currentroot);
73350+
73351+ return ret;
73352+}
73353+#endif
73354+
73355+int
73356+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73357+{
73358+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73359+ if (!grsec_enable_chroot_fchdir)
73360+ return 1;
73361+
73362+ if (!proc_is_chrooted(current))
73363+ return 1;
73364+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73365+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73366+ return 0;
73367+ }
73368+#endif
73369+ return 1;
73370+}
73371+
73372+int
73373+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73374+ const time_t shm_createtime)
73375+{
73376+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73377+ struct task_struct *p;
73378+ time_t starttime;
73379+
73380+ if (unlikely(!grsec_enable_chroot_shmat))
73381+ return 1;
73382+
73383+ if (likely(!proc_is_chrooted(current)))
73384+ return 1;
73385+
73386+ rcu_read_lock();
73387+ read_lock(&tasklist_lock);
73388+
73389+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73390+ starttime = p->start_time.tv_sec;
73391+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73392+ if (have_same_root(current, p)) {
73393+ goto allow;
73394+ } else {
73395+ read_unlock(&tasklist_lock);
73396+ rcu_read_unlock();
73397+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73398+ return 0;
73399+ }
73400+ }
73401+ /* creator exited, pid reuse, fall through to next check */
73402+ }
73403+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73404+ if (unlikely(!have_same_root(current, p))) {
73405+ read_unlock(&tasklist_lock);
73406+ rcu_read_unlock();
73407+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73408+ return 0;
73409+ }
73410+ }
73411+
73412+allow:
73413+ read_unlock(&tasklist_lock);
73414+ rcu_read_unlock();
73415+#endif
73416+ return 1;
73417+}
73418+
73419+void
73420+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73421+{
73422+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73423+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73424+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73425+#endif
73426+ return;
73427+}
73428+
73429+int
73430+gr_handle_chroot_mknod(const struct dentry *dentry,
73431+ const struct vfsmount *mnt, const int mode)
73432+{
73433+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73434+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73435+ proc_is_chrooted(current)) {
73436+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73437+ return -EPERM;
73438+ }
73439+#endif
73440+ return 0;
73441+}
73442+
73443+int
73444+gr_handle_chroot_mount(const struct dentry *dentry,
73445+ const struct vfsmount *mnt, const char *dev_name)
73446+{
73447+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73448+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73449+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73450+ return -EPERM;
73451+ }
73452+#endif
73453+ return 0;
73454+}
73455+
73456+int
73457+gr_handle_chroot_pivot(void)
73458+{
73459+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73460+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73461+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73462+ return -EPERM;
73463+ }
73464+#endif
73465+ return 0;
73466+}
73467+
73468+int
73469+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73470+{
73471+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73472+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73473+ !gr_is_outside_chroot(dentry, mnt)) {
73474+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73475+ return -EPERM;
73476+ }
73477+#endif
73478+ return 0;
73479+}
73480+
73481+extern const char *captab_log[];
73482+extern int captab_log_entries;
73483+
73484+int
73485+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73486+{
73487+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73488+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73489+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73490+ if (cap_raised(chroot_caps, cap)) {
73491+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73492+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73493+ }
73494+ return 0;
73495+ }
73496+ }
73497+#endif
73498+ return 1;
73499+}
73500+
73501+int
73502+gr_chroot_is_capable(const int cap)
73503+{
73504+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73505+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73506+#endif
73507+ return 1;
73508+}
73509+
73510+int
73511+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73512+{
73513+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73514+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73515+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73516+ if (cap_raised(chroot_caps, cap)) {
73517+ return 0;
73518+ }
73519+ }
73520+#endif
73521+ return 1;
73522+}
73523+
73524+int
73525+gr_chroot_is_capable_nolog(const int cap)
73526+{
73527+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73528+ return gr_task_chroot_is_capable_nolog(current, cap);
73529+#endif
73530+ return 1;
73531+}
73532+
73533+int
73534+gr_handle_chroot_sysctl(const int op)
73535+{
73536+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73537+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73538+ proc_is_chrooted(current))
73539+ return -EACCES;
73540+#endif
73541+ return 0;
73542+}
73543+
73544+void
73545+gr_handle_chroot_chdir(const struct path *path)
73546+{
73547+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73548+ if (grsec_enable_chroot_chdir)
73549+ set_fs_pwd(current->fs, path);
73550+#endif
73551+ return;
73552+}
73553+
73554+int
73555+gr_handle_chroot_chmod(const struct dentry *dentry,
73556+ const struct vfsmount *mnt, const int mode)
73557+{
73558+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73559+ /* allow chmod +s on directories, but not files */
73560+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73561+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73562+ proc_is_chrooted(current)) {
73563+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73564+ return -EPERM;
73565+ }
73566+#endif
73567+ return 0;
73568+}
73569diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73570new file mode 100644
73571index 0000000..4d6fce8
73572--- /dev/null
73573+++ b/grsecurity/grsec_disabled.c
73574@@ -0,0 +1,433 @@
73575+#include <linux/kernel.h>
73576+#include <linux/module.h>
73577+#include <linux/sched.h>
73578+#include <linux/file.h>
73579+#include <linux/fs.h>
73580+#include <linux/kdev_t.h>
73581+#include <linux/net.h>
73582+#include <linux/in.h>
73583+#include <linux/ip.h>
73584+#include <linux/skbuff.h>
73585+#include <linux/sysctl.h>
73586+
73587+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73588+void
73589+pax_set_initial_flags(struct linux_binprm *bprm)
73590+{
73591+ return;
73592+}
73593+#endif
73594+
73595+#ifdef CONFIG_SYSCTL
73596+__u32
73597+gr_handle_sysctl(const struct ctl_table * table, const int op)
73598+{
73599+ return 0;
73600+}
73601+#endif
73602+
73603+#ifdef CONFIG_TASKSTATS
73604+int gr_is_taskstats_denied(int pid)
73605+{
73606+ return 0;
73607+}
73608+#endif
73609+
73610+int
73611+gr_acl_is_enabled(void)
73612+{
73613+ return 0;
73614+}
73615+
73616+void
73617+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73618+{
73619+ return;
73620+}
73621+
73622+int
73623+gr_handle_rawio(const struct inode *inode)
73624+{
73625+ return 0;
73626+}
73627+
73628+void
73629+gr_acl_handle_psacct(struct task_struct *task, const long code)
73630+{
73631+ return;
73632+}
73633+
73634+int
73635+gr_handle_ptrace(struct task_struct *task, const long request)
73636+{
73637+ return 0;
73638+}
73639+
73640+int
73641+gr_handle_proc_ptrace(struct task_struct *task)
73642+{
73643+ return 0;
73644+}
73645+
73646+int
73647+gr_set_acls(const int type)
73648+{
73649+ return 0;
73650+}
73651+
73652+int
73653+gr_check_hidden_task(const struct task_struct *tsk)
73654+{
73655+ return 0;
73656+}
73657+
73658+int
73659+gr_check_protected_task(const struct task_struct *task)
73660+{
73661+ return 0;
73662+}
73663+
73664+int
73665+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73666+{
73667+ return 0;
73668+}
73669+
73670+void
73671+gr_copy_label(struct task_struct *tsk)
73672+{
73673+ return;
73674+}
73675+
73676+void
73677+gr_set_pax_flags(struct task_struct *task)
73678+{
73679+ return;
73680+}
73681+
73682+int
73683+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73684+ const int unsafe_share)
73685+{
73686+ return 0;
73687+}
73688+
73689+void
73690+gr_handle_delete(const ino_t ino, const dev_t dev)
73691+{
73692+ return;
73693+}
73694+
73695+void
73696+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73697+{
73698+ return;
73699+}
73700+
73701+void
73702+gr_handle_crash(struct task_struct *task, const int sig)
73703+{
73704+ return;
73705+}
73706+
73707+int
73708+gr_check_crash_exec(const struct file *filp)
73709+{
73710+ return 0;
73711+}
73712+
73713+int
73714+gr_check_crash_uid(const kuid_t uid)
73715+{
73716+ return 0;
73717+}
73718+
73719+void
73720+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73721+ struct dentry *old_dentry,
73722+ struct dentry *new_dentry,
73723+ struct vfsmount *mnt, const __u8 replace)
73724+{
73725+ return;
73726+}
73727+
73728+int
73729+gr_search_socket(const int family, const int type, const int protocol)
73730+{
73731+ return 1;
73732+}
73733+
73734+int
73735+gr_search_connectbind(const int mode, const struct socket *sock,
73736+ const struct sockaddr_in *addr)
73737+{
73738+ return 0;
73739+}
73740+
73741+void
73742+gr_handle_alertkill(struct task_struct *task)
73743+{
73744+ return;
73745+}
73746+
73747+__u32
73748+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73749+{
73750+ return 1;
73751+}
73752+
73753+__u32
73754+gr_acl_handle_hidden_file(const struct dentry * dentry,
73755+ const struct vfsmount * mnt)
73756+{
73757+ return 1;
73758+}
73759+
73760+__u32
73761+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73762+ int acc_mode)
73763+{
73764+ return 1;
73765+}
73766+
73767+__u32
73768+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73769+{
73770+ return 1;
73771+}
73772+
73773+__u32
73774+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73775+{
73776+ return 1;
73777+}
73778+
73779+int
73780+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73781+ unsigned int *vm_flags)
73782+{
73783+ return 1;
73784+}
73785+
73786+__u32
73787+gr_acl_handle_truncate(const struct dentry * dentry,
73788+ const struct vfsmount * mnt)
73789+{
73790+ return 1;
73791+}
73792+
73793+__u32
73794+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73795+{
73796+ return 1;
73797+}
73798+
73799+__u32
73800+gr_acl_handle_access(const struct dentry * dentry,
73801+ const struct vfsmount * mnt, const int fmode)
73802+{
73803+ return 1;
73804+}
73805+
73806+__u32
73807+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73808+ umode_t *mode)
73809+{
73810+ return 1;
73811+}
73812+
73813+__u32
73814+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73815+{
73816+ return 1;
73817+}
73818+
73819+__u32
73820+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73821+{
73822+ return 1;
73823+}
73824+
73825+__u32
73826+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73827+{
73828+ return 1;
73829+}
73830+
73831+void
73832+grsecurity_init(void)
73833+{
73834+ return;
73835+}
73836+
73837+umode_t gr_acl_umask(void)
73838+{
73839+ return 0;
73840+}
73841+
73842+__u32
73843+gr_acl_handle_mknod(const struct dentry * new_dentry,
73844+ const struct dentry * parent_dentry,
73845+ const struct vfsmount * parent_mnt,
73846+ const int mode)
73847+{
73848+ return 1;
73849+}
73850+
73851+__u32
73852+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73853+ const struct dentry * parent_dentry,
73854+ const struct vfsmount * parent_mnt)
73855+{
73856+ return 1;
73857+}
73858+
73859+__u32
73860+gr_acl_handle_symlink(const struct dentry * new_dentry,
73861+ const struct dentry * parent_dentry,
73862+ const struct vfsmount * parent_mnt, const struct filename *from)
73863+{
73864+ return 1;
73865+}
73866+
73867+__u32
73868+gr_acl_handle_link(const struct dentry * new_dentry,
73869+ const struct dentry * parent_dentry,
73870+ const struct vfsmount * parent_mnt,
73871+ const struct dentry * old_dentry,
73872+ const struct vfsmount * old_mnt, const struct filename *to)
73873+{
73874+ return 1;
73875+}
73876+
73877+int
73878+gr_acl_handle_rename(const struct dentry *new_dentry,
73879+ const struct dentry *parent_dentry,
73880+ const struct vfsmount *parent_mnt,
73881+ const struct dentry *old_dentry,
73882+ const struct inode *old_parent_inode,
73883+ const struct vfsmount *old_mnt, const struct filename *newname)
73884+{
73885+ return 0;
73886+}
73887+
73888+int
73889+gr_acl_handle_filldir(const struct file *file, const char *name,
73890+ const int namelen, const ino_t ino)
73891+{
73892+ return 1;
73893+}
73894+
73895+int
73896+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73897+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73898+{
73899+ return 1;
73900+}
73901+
73902+int
73903+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73904+{
73905+ return 0;
73906+}
73907+
73908+int
73909+gr_search_accept(const struct socket *sock)
73910+{
73911+ return 0;
73912+}
73913+
73914+int
73915+gr_search_listen(const struct socket *sock)
73916+{
73917+ return 0;
73918+}
73919+
73920+int
73921+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73922+{
73923+ return 0;
73924+}
73925+
73926+__u32
73927+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73928+{
73929+ return 1;
73930+}
73931+
73932+__u32
73933+gr_acl_handle_creat(const struct dentry * dentry,
73934+ const struct dentry * p_dentry,
73935+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73936+ const int imode)
73937+{
73938+ return 1;
73939+}
73940+
73941+void
73942+gr_acl_handle_exit(void)
73943+{
73944+ return;
73945+}
73946+
73947+int
73948+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73949+{
73950+ return 1;
73951+}
73952+
73953+void
73954+gr_set_role_label(const kuid_t uid, const kgid_t gid)
73955+{
73956+ return;
73957+}
73958+
73959+int
73960+gr_acl_handle_procpidmem(const struct task_struct *task)
73961+{
73962+ return 0;
73963+}
73964+
73965+int
73966+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73967+{
73968+ return 0;
73969+}
73970+
73971+int
73972+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73973+{
73974+ return 0;
73975+}
73976+
73977+int
73978+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73979+{
73980+ return 0;
73981+}
73982+
73983+int
73984+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73985+{
73986+ return 0;
73987+}
73988+
73989+int gr_acl_enable_at_secure(void)
73990+{
73991+ return 0;
73992+}
73993+
73994+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73995+{
73996+ return dentry->d_sb->s_dev;
73997+}
73998+
73999+void gr_put_exec_file(struct task_struct *task)
74000+{
74001+ return;
74002+}
74003+
74004+#ifdef CONFIG_SECURITY
74005+EXPORT_SYMBOL_GPL(gr_check_user_change);
74006+EXPORT_SYMBOL_GPL(gr_check_group_change);
74007+#endif
74008diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74009new file mode 100644
74010index 0000000..f35f454
74011--- /dev/null
74012+++ b/grsecurity/grsec_exec.c
74013@@ -0,0 +1,187 @@
74014+#include <linux/kernel.h>
74015+#include <linux/sched.h>
74016+#include <linux/file.h>
74017+#include <linux/binfmts.h>
74018+#include <linux/fs.h>
74019+#include <linux/types.h>
74020+#include <linux/grdefs.h>
74021+#include <linux/grsecurity.h>
74022+#include <linux/grinternal.h>
74023+#include <linux/capability.h>
74024+#include <linux/module.h>
74025+#include <linux/compat.h>
74026+
74027+#include <asm/uaccess.h>
74028+
74029+#ifdef CONFIG_GRKERNSEC_EXECLOG
74030+static char gr_exec_arg_buf[132];
74031+static DEFINE_MUTEX(gr_exec_arg_mutex);
74032+#endif
74033+
74034+struct user_arg_ptr {
74035+#ifdef CONFIG_COMPAT
74036+ bool is_compat;
74037+#endif
74038+ union {
74039+ const char __user *const __user *native;
74040+#ifdef CONFIG_COMPAT
74041+ const compat_uptr_t __user *compat;
74042+#endif
74043+ } ptr;
74044+};
74045+
74046+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74047+
74048+void
74049+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74050+{
74051+#ifdef CONFIG_GRKERNSEC_EXECLOG
74052+ char *grarg = gr_exec_arg_buf;
74053+ unsigned int i, x, execlen = 0;
74054+ char c;
74055+
74056+ if (!((grsec_enable_execlog && grsec_enable_group &&
74057+ in_group_p(grsec_audit_gid))
74058+ || (grsec_enable_execlog && !grsec_enable_group)))
74059+ return;
74060+
74061+ mutex_lock(&gr_exec_arg_mutex);
74062+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74063+
74064+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74065+ const char __user *p;
74066+ unsigned int len;
74067+
74068+ p = get_user_arg_ptr(argv, i);
74069+ if (IS_ERR(p))
74070+ goto log;
74071+
74072+ len = strnlen_user(p, 128 - execlen);
74073+ if (len > 128 - execlen)
74074+ len = 128 - execlen;
74075+ else if (len > 0)
74076+ len--;
74077+ if (copy_from_user(grarg + execlen, p, len))
74078+ goto log;
74079+
74080+ /* rewrite unprintable characters */
74081+ for (x = 0; x < len; x++) {
74082+ c = *(grarg + execlen + x);
74083+ if (c < 32 || c > 126)
74084+ *(grarg + execlen + x) = ' ';
74085+ }
74086+
74087+ execlen += len;
74088+ *(grarg + execlen) = ' ';
74089+ *(grarg + execlen + 1) = '\0';
74090+ execlen++;
74091+ }
74092+
74093+ log:
74094+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74095+ bprm->file->f_path.mnt, grarg);
74096+ mutex_unlock(&gr_exec_arg_mutex);
74097+#endif
74098+ return;
74099+}
74100+
74101+#ifdef CONFIG_GRKERNSEC
74102+extern int gr_acl_is_capable(const int cap);
74103+extern int gr_acl_is_capable_nolog(const int cap);
74104+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74105+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74106+extern int gr_chroot_is_capable(const int cap);
74107+extern int gr_chroot_is_capable_nolog(const int cap);
74108+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74109+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74110+#endif
74111+
74112+const char *captab_log[] = {
74113+ "CAP_CHOWN",
74114+ "CAP_DAC_OVERRIDE",
74115+ "CAP_DAC_READ_SEARCH",
74116+ "CAP_FOWNER",
74117+ "CAP_FSETID",
74118+ "CAP_KILL",
74119+ "CAP_SETGID",
74120+ "CAP_SETUID",
74121+ "CAP_SETPCAP",
74122+ "CAP_LINUX_IMMUTABLE",
74123+ "CAP_NET_BIND_SERVICE",
74124+ "CAP_NET_BROADCAST",
74125+ "CAP_NET_ADMIN",
74126+ "CAP_NET_RAW",
74127+ "CAP_IPC_LOCK",
74128+ "CAP_IPC_OWNER",
74129+ "CAP_SYS_MODULE",
74130+ "CAP_SYS_RAWIO",
74131+ "CAP_SYS_CHROOT",
74132+ "CAP_SYS_PTRACE",
74133+ "CAP_SYS_PACCT",
74134+ "CAP_SYS_ADMIN",
74135+ "CAP_SYS_BOOT",
74136+ "CAP_SYS_NICE",
74137+ "CAP_SYS_RESOURCE",
74138+ "CAP_SYS_TIME",
74139+ "CAP_SYS_TTY_CONFIG",
74140+ "CAP_MKNOD",
74141+ "CAP_LEASE",
74142+ "CAP_AUDIT_WRITE",
74143+ "CAP_AUDIT_CONTROL",
74144+ "CAP_SETFCAP",
74145+ "CAP_MAC_OVERRIDE",
74146+ "CAP_MAC_ADMIN",
74147+ "CAP_SYSLOG",
74148+ "CAP_WAKE_ALARM"
74149+};
74150+
74151+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74152+
74153+int gr_is_capable(const int cap)
74154+{
74155+#ifdef CONFIG_GRKERNSEC
74156+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74157+ return 1;
74158+ return 0;
74159+#else
74160+ return 1;
74161+#endif
74162+}
74163+
74164+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74165+{
74166+#ifdef CONFIG_GRKERNSEC
74167+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74168+ return 1;
74169+ return 0;
74170+#else
74171+ return 1;
74172+#endif
74173+}
74174+
74175+int gr_is_capable_nolog(const int cap)
74176+{
74177+#ifdef CONFIG_GRKERNSEC
74178+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74179+ return 1;
74180+ return 0;
74181+#else
74182+ return 1;
74183+#endif
74184+}
74185+
74186+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74187+{
74188+#ifdef CONFIG_GRKERNSEC
74189+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74190+ return 1;
74191+ return 0;
74192+#else
74193+ return 1;
74194+#endif
74195+}
74196+
74197+EXPORT_SYMBOL_GPL(gr_is_capable);
74198+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74199+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74200+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74201diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74202new file mode 100644
74203index 0000000..06cc6ea
74204--- /dev/null
74205+++ b/grsecurity/grsec_fifo.c
74206@@ -0,0 +1,24 @@
74207+#include <linux/kernel.h>
74208+#include <linux/sched.h>
74209+#include <linux/fs.h>
74210+#include <linux/file.h>
74211+#include <linux/grinternal.h>
74212+
74213+int
74214+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74215+ const struct dentry *dir, const int flag, const int acc_mode)
74216+{
74217+#ifdef CONFIG_GRKERNSEC_FIFO
74218+ const struct cred *cred = current_cred();
74219+
74220+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74221+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74222+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74223+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74224+ if (!inode_permission(dentry->d_inode, acc_mode))
74225+ 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));
74226+ return -EACCES;
74227+ }
74228+#endif
74229+ return 0;
74230+}
74231diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74232new file mode 100644
74233index 0000000..8ca18bf
74234--- /dev/null
74235+++ b/grsecurity/grsec_fork.c
74236@@ -0,0 +1,23 @@
74237+#include <linux/kernel.h>
74238+#include <linux/sched.h>
74239+#include <linux/grsecurity.h>
74240+#include <linux/grinternal.h>
74241+#include <linux/errno.h>
74242+
74243+void
74244+gr_log_forkfail(const int retval)
74245+{
74246+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74247+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74248+ switch (retval) {
74249+ case -EAGAIN:
74250+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74251+ break;
74252+ case -ENOMEM:
74253+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74254+ break;
74255+ }
74256+ }
74257+#endif
74258+ return;
74259+}
74260diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74261new file mode 100644
74262index 0000000..ae6c028
74263--- /dev/null
74264+++ b/grsecurity/grsec_init.c
74265@@ -0,0 +1,272 @@
74266+#include <linux/kernel.h>
74267+#include <linux/sched.h>
74268+#include <linux/mm.h>
74269+#include <linux/gracl.h>
74270+#include <linux/slab.h>
74271+#include <linux/vmalloc.h>
74272+#include <linux/percpu.h>
74273+#include <linux/module.h>
74274+
74275+int grsec_enable_ptrace_readexec;
74276+int grsec_enable_setxid;
74277+int grsec_enable_symlinkown;
74278+kgid_t grsec_symlinkown_gid;
74279+int grsec_enable_brute;
74280+int grsec_enable_link;
74281+int grsec_enable_dmesg;
74282+int grsec_enable_harden_ptrace;
74283+int grsec_enable_harden_ipc;
74284+int grsec_enable_fifo;
74285+int grsec_enable_execlog;
74286+int grsec_enable_signal;
74287+int grsec_enable_forkfail;
74288+int grsec_enable_audit_ptrace;
74289+int grsec_enable_time;
74290+int grsec_enable_group;
74291+kgid_t grsec_audit_gid;
74292+int grsec_enable_chdir;
74293+int grsec_enable_mount;
74294+int grsec_enable_rofs;
74295+int grsec_deny_new_usb;
74296+int grsec_enable_chroot_findtask;
74297+int grsec_enable_chroot_mount;
74298+int grsec_enable_chroot_shmat;
74299+int grsec_enable_chroot_fchdir;
74300+int grsec_enable_chroot_double;
74301+int grsec_enable_chroot_pivot;
74302+int grsec_enable_chroot_chdir;
74303+int grsec_enable_chroot_chmod;
74304+int grsec_enable_chroot_mknod;
74305+int grsec_enable_chroot_nice;
74306+int grsec_enable_chroot_execlog;
74307+int grsec_enable_chroot_caps;
74308+int grsec_enable_chroot_sysctl;
74309+int grsec_enable_chroot_unix;
74310+int grsec_enable_tpe;
74311+kgid_t grsec_tpe_gid;
74312+int grsec_enable_blackhole;
74313+#ifdef CONFIG_IPV6_MODULE
74314+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74315+#endif
74316+int grsec_lastack_retries;
74317+int grsec_enable_tpe_all;
74318+int grsec_enable_tpe_invert;
74319+int grsec_enable_socket_all;
74320+kgid_t grsec_socket_all_gid;
74321+int grsec_enable_socket_client;
74322+kgid_t grsec_socket_client_gid;
74323+int grsec_enable_socket_server;
74324+kgid_t grsec_socket_server_gid;
74325+int grsec_resource_logging;
74326+int grsec_disable_privio;
74327+int grsec_enable_log_rwxmaps;
74328+int grsec_lock;
74329+
74330+DEFINE_SPINLOCK(grsec_alert_lock);
74331+unsigned long grsec_alert_wtime = 0;
74332+unsigned long grsec_alert_fyet = 0;
74333+
74334+DEFINE_SPINLOCK(grsec_audit_lock);
74335+
74336+DEFINE_RWLOCK(grsec_exec_file_lock);
74337+
74338+char *gr_shared_page[4];
74339+
74340+char *gr_alert_log_fmt;
74341+char *gr_audit_log_fmt;
74342+char *gr_alert_log_buf;
74343+char *gr_audit_log_buf;
74344+
74345+void __init
74346+grsecurity_init(void)
74347+{
74348+ int j;
74349+ /* create the per-cpu shared pages */
74350+
74351+#ifdef CONFIG_X86
74352+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74353+#endif
74354+
74355+ for (j = 0; j < 4; j++) {
74356+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74357+ if (gr_shared_page[j] == NULL) {
74358+ panic("Unable to allocate grsecurity shared page");
74359+ return;
74360+ }
74361+ }
74362+
74363+ /* allocate log buffers */
74364+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74365+ if (!gr_alert_log_fmt) {
74366+ panic("Unable to allocate grsecurity alert log format buffer");
74367+ return;
74368+ }
74369+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74370+ if (!gr_audit_log_fmt) {
74371+ panic("Unable to allocate grsecurity audit log format buffer");
74372+ return;
74373+ }
74374+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74375+ if (!gr_alert_log_buf) {
74376+ panic("Unable to allocate grsecurity alert log buffer");
74377+ return;
74378+ }
74379+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74380+ if (!gr_audit_log_buf) {
74381+ panic("Unable to allocate grsecurity audit log buffer");
74382+ return;
74383+ }
74384+
74385+#ifdef CONFIG_GRKERNSEC_IO
74386+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74387+ grsec_disable_privio = 1;
74388+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74389+ grsec_disable_privio = 1;
74390+#else
74391+ grsec_disable_privio = 0;
74392+#endif
74393+#endif
74394+
74395+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74396+ /* for backward compatibility, tpe_invert always defaults to on if
74397+ enabled in the kernel
74398+ */
74399+ grsec_enable_tpe_invert = 1;
74400+#endif
74401+
74402+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74403+#ifndef CONFIG_GRKERNSEC_SYSCTL
74404+ grsec_lock = 1;
74405+#endif
74406+
74407+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74408+ grsec_enable_log_rwxmaps = 1;
74409+#endif
74410+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74411+ grsec_enable_group = 1;
74412+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74413+#endif
74414+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74415+ grsec_enable_ptrace_readexec = 1;
74416+#endif
74417+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74418+ grsec_enable_chdir = 1;
74419+#endif
74420+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74421+ grsec_enable_harden_ptrace = 1;
74422+#endif
74423+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74424+ grsec_enable_harden_ipc = 1;
74425+#endif
74426+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74427+ grsec_enable_mount = 1;
74428+#endif
74429+#ifdef CONFIG_GRKERNSEC_LINK
74430+ grsec_enable_link = 1;
74431+#endif
74432+#ifdef CONFIG_GRKERNSEC_BRUTE
74433+ grsec_enable_brute = 1;
74434+#endif
74435+#ifdef CONFIG_GRKERNSEC_DMESG
74436+ grsec_enable_dmesg = 1;
74437+#endif
74438+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74439+ grsec_enable_blackhole = 1;
74440+ grsec_lastack_retries = 4;
74441+#endif
74442+#ifdef CONFIG_GRKERNSEC_FIFO
74443+ grsec_enable_fifo = 1;
74444+#endif
74445+#ifdef CONFIG_GRKERNSEC_EXECLOG
74446+ grsec_enable_execlog = 1;
74447+#endif
74448+#ifdef CONFIG_GRKERNSEC_SETXID
74449+ grsec_enable_setxid = 1;
74450+#endif
74451+#ifdef CONFIG_GRKERNSEC_SIGNAL
74452+ grsec_enable_signal = 1;
74453+#endif
74454+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74455+ grsec_enable_forkfail = 1;
74456+#endif
74457+#ifdef CONFIG_GRKERNSEC_TIME
74458+ grsec_enable_time = 1;
74459+#endif
74460+#ifdef CONFIG_GRKERNSEC_RESLOG
74461+ grsec_resource_logging = 1;
74462+#endif
74463+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74464+ grsec_enable_chroot_findtask = 1;
74465+#endif
74466+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74467+ grsec_enable_chroot_unix = 1;
74468+#endif
74469+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74470+ grsec_enable_chroot_mount = 1;
74471+#endif
74472+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74473+ grsec_enable_chroot_fchdir = 1;
74474+#endif
74475+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74476+ grsec_enable_chroot_shmat = 1;
74477+#endif
74478+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74479+ grsec_enable_audit_ptrace = 1;
74480+#endif
74481+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74482+ grsec_enable_chroot_double = 1;
74483+#endif
74484+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74485+ grsec_enable_chroot_pivot = 1;
74486+#endif
74487+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74488+ grsec_enable_chroot_chdir = 1;
74489+#endif
74490+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74491+ grsec_enable_chroot_chmod = 1;
74492+#endif
74493+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74494+ grsec_enable_chroot_mknod = 1;
74495+#endif
74496+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74497+ grsec_enable_chroot_nice = 1;
74498+#endif
74499+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74500+ grsec_enable_chroot_execlog = 1;
74501+#endif
74502+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74503+ grsec_enable_chroot_caps = 1;
74504+#endif
74505+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74506+ grsec_enable_chroot_sysctl = 1;
74507+#endif
74508+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74509+ grsec_enable_symlinkown = 1;
74510+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74511+#endif
74512+#ifdef CONFIG_GRKERNSEC_TPE
74513+ grsec_enable_tpe = 1;
74514+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74515+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74516+ grsec_enable_tpe_all = 1;
74517+#endif
74518+#endif
74519+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74520+ grsec_enable_socket_all = 1;
74521+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74522+#endif
74523+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74524+ grsec_enable_socket_client = 1;
74525+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74526+#endif
74527+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74528+ grsec_enable_socket_server = 1;
74529+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74530+#endif
74531+#endif
74532+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74533+ grsec_deny_new_usb = 1;
74534+#endif
74535+
74536+ return;
74537+}
74538diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74539new file mode 100644
74540index 0000000..1773300
74541--- /dev/null
74542+++ b/grsecurity/grsec_ipc.c
74543@@ -0,0 +1,48 @@
74544+#include <linux/kernel.h>
74545+#include <linux/mm.h>
74546+#include <linux/sched.h>
74547+#include <linux/file.h>
74548+#include <linux/ipc.h>
74549+#include <linux/ipc_namespace.h>
74550+#include <linux/grsecurity.h>
74551+#include <linux/grinternal.h>
74552+
74553+int
74554+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74555+{
74556+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74557+ int write;
74558+ int orig_granted_mode;
74559+ kuid_t euid;
74560+ kgid_t egid;
74561+
74562+ if (!grsec_enable_harden_ipc)
74563+ return 1;
74564+
74565+ euid = current_euid();
74566+ egid = current_egid();
74567+
74568+ write = requested_mode & 00002;
74569+ orig_granted_mode = ipcp->mode;
74570+
74571+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74572+ orig_granted_mode >>= 6;
74573+ else {
74574+ /* if likely wrong permissions, lock to user */
74575+ if (orig_granted_mode & 0007)
74576+ orig_granted_mode = 0;
74577+ /* otherwise do a egid-only check */
74578+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74579+ orig_granted_mode >>= 3;
74580+ /* otherwise, no access */
74581+ else
74582+ orig_granted_mode = 0;
74583+ }
74584+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74585+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74586+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74587+ return 0;
74588+ }
74589+#endif
74590+ return 1;
74591+}
74592diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74593new file mode 100644
74594index 0000000..5e05e20
74595--- /dev/null
74596+++ b/grsecurity/grsec_link.c
74597@@ -0,0 +1,58 @@
74598+#include <linux/kernel.h>
74599+#include <linux/sched.h>
74600+#include <linux/fs.h>
74601+#include <linux/file.h>
74602+#include <linux/grinternal.h>
74603+
74604+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74605+{
74606+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74607+ const struct inode *link_inode = link->dentry->d_inode;
74608+
74609+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74610+ /* ignore root-owned links, e.g. /proc/self */
74611+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74612+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74613+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74614+ return 1;
74615+ }
74616+#endif
74617+ return 0;
74618+}
74619+
74620+int
74621+gr_handle_follow_link(const struct inode *parent,
74622+ const struct inode *inode,
74623+ const struct dentry *dentry, const struct vfsmount *mnt)
74624+{
74625+#ifdef CONFIG_GRKERNSEC_LINK
74626+ const struct cred *cred = current_cred();
74627+
74628+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74629+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74630+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74631+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74632+ return -EACCES;
74633+ }
74634+#endif
74635+ return 0;
74636+}
74637+
74638+int
74639+gr_handle_hardlink(const struct dentry *dentry,
74640+ const struct vfsmount *mnt,
74641+ struct inode *inode, const int mode, const struct filename *to)
74642+{
74643+#ifdef CONFIG_GRKERNSEC_LINK
74644+ const struct cred *cred = current_cred();
74645+
74646+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74647+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74648+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74649+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74650+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74651+ return -EPERM;
74652+ }
74653+#endif
74654+ return 0;
74655+}
74656diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74657new file mode 100644
74658index 0000000..dbe0a6b
74659--- /dev/null
74660+++ b/grsecurity/grsec_log.c
74661@@ -0,0 +1,341 @@
74662+#include <linux/kernel.h>
74663+#include <linux/sched.h>
74664+#include <linux/file.h>
74665+#include <linux/tty.h>
74666+#include <linux/fs.h>
74667+#include <linux/mm.h>
74668+#include <linux/grinternal.h>
74669+
74670+#ifdef CONFIG_TREE_PREEMPT_RCU
74671+#define DISABLE_PREEMPT() preempt_disable()
74672+#define ENABLE_PREEMPT() preempt_enable()
74673+#else
74674+#define DISABLE_PREEMPT()
74675+#define ENABLE_PREEMPT()
74676+#endif
74677+
74678+#define BEGIN_LOCKS(x) \
74679+ DISABLE_PREEMPT(); \
74680+ rcu_read_lock(); \
74681+ read_lock(&tasklist_lock); \
74682+ read_lock(&grsec_exec_file_lock); \
74683+ if (x != GR_DO_AUDIT) \
74684+ spin_lock(&grsec_alert_lock); \
74685+ else \
74686+ spin_lock(&grsec_audit_lock)
74687+
74688+#define END_LOCKS(x) \
74689+ if (x != GR_DO_AUDIT) \
74690+ spin_unlock(&grsec_alert_lock); \
74691+ else \
74692+ spin_unlock(&grsec_audit_lock); \
74693+ read_unlock(&grsec_exec_file_lock); \
74694+ read_unlock(&tasklist_lock); \
74695+ rcu_read_unlock(); \
74696+ ENABLE_PREEMPT(); \
74697+ if (x == GR_DONT_AUDIT) \
74698+ gr_handle_alertkill(current)
74699+
74700+enum {
74701+ FLOODING,
74702+ NO_FLOODING
74703+};
74704+
74705+extern char *gr_alert_log_fmt;
74706+extern char *gr_audit_log_fmt;
74707+extern char *gr_alert_log_buf;
74708+extern char *gr_audit_log_buf;
74709+
74710+static int gr_log_start(int audit)
74711+{
74712+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74713+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74714+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74715+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74716+ unsigned long curr_secs = get_seconds();
74717+
74718+ if (audit == GR_DO_AUDIT)
74719+ goto set_fmt;
74720+
74721+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74722+ grsec_alert_wtime = curr_secs;
74723+ grsec_alert_fyet = 0;
74724+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74725+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74726+ grsec_alert_fyet++;
74727+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74728+ grsec_alert_wtime = curr_secs;
74729+ grsec_alert_fyet++;
74730+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74731+ return FLOODING;
74732+ }
74733+ else return FLOODING;
74734+
74735+set_fmt:
74736+#endif
74737+ memset(buf, 0, PAGE_SIZE);
74738+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74739+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74740+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74741+ } else if (current->signal->curr_ip) {
74742+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74743+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74744+ } else if (gr_acl_is_enabled()) {
74745+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74746+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74747+ } else {
74748+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74749+ strcpy(buf, fmt);
74750+ }
74751+
74752+ return NO_FLOODING;
74753+}
74754+
74755+static void gr_log_middle(int audit, const char *msg, va_list ap)
74756+ __attribute__ ((format (printf, 2, 0)));
74757+
74758+static void gr_log_middle(int audit, const char *msg, va_list ap)
74759+{
74760+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74761+ unsigned int len = strlen(buf);
74762+
74763+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74764+
74765+ return;
74766+}
74767+
74768+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74769+ __attribute__ ((format (printf, 2, 3)));
74770+
74771+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74772+{
74773+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74774+ unsigned int len = strlen(buf);
74775+ va_list ap;
74776+
74777+ va_start(ap, msg);
74778+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74779+ va_end(ap);
74780+
74781+ return;
74782+}
74783+
74784+static void gr_log_end(int audit, int append_default)
74785+{
74786+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74787+ if (append_default) {
74788+ struct task_struct *task = current;
74789+ struct task_struct *parent = task->real_parent;
74790+ const struct cred *cred = __task_cred(task);
74791+ const struct cred *pcred = __task_cred(parent);
74792+ unsigned int len = strlen(buf);
74793+
74794+ 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));
74795+ }
74796+
74797+ printk("%s\n", buf);
74798+
74799+ return;
74800+}
74801+
74802+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74803+{
74804+ int logtype;
74805+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74806+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74807+ void *voidptr = NULL;
74808+ int num1 = 0, num2 = 0;
74809+ unsigned long ulong1 = 0, ulong2 = 0;
74810+ struct dentry *dentry = NULL;
74811+ struct vfsmount *mnt = NULL;
74812+ struct file *file = NULL;
74813+ struct task_struct *task = NULL;
74814+ struct vm_area_struct *vma = NULL;
74815+ const struct cred *cred, *pcred;
74816+ va_list ap;
74817+
74818+ BEGIN_LOCKS(audit);
74819+ logtype = gr_log_start(audit);
74820+ if (logtype == FLOODING) {
74821+ END_LOCKS(audit);
74822+ return;
74823+ }
74824+ va_start(ap, argtypes);
74825+ switch (argtypes) {
74826+ case GR_TTYSNIFF:
74827+ task = va_arg(ap, struct task_struct *);
74828+ 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));
74829+ break;
74830+ case GR_SYSCTL_HIDDEN:
74831+ str1 = va_arg(ap, char *);
74832+ gr_log_middle_varargs(audit, msg, result, str1);
74833+ break;
74834+ case GR_RBAC:
74835+ dentry = va_arg(ap, struct dentry *);
74836+ mnt = va_arg(ap, struct vfsmount *);
74837+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74838+ break;
74839+ case GR_RBAC_STR:
74840+ dentry = va_arg(ap, struct dentry *);
74841+ mnt = va_arg(ap, struct vfsmount *);
74842+ str1 = va_arg(ap, char *);
74843+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74844+ break;
74845+ case GR_STR_RBAC:
74846+ str1 = va_arg(ap, char *);
74847+ dentry = va_arg(ap, struct dentry *);
74848+ mnt = va_arg(ap, struct vfsmount *);
74849+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74850+ break;
74851+ case GR_RBAC_MODE2:
74852+ dentry = va_arg(ap, struct dentry *);
74853+ mnt = va_arg(ap, struct vfsmount *);
74854+ str1 = va_arg(ap, char *);
74855+ str2 = va_arg(ap, char *);
74856+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74857+ break;
74858+ case GR_RBAC_MODE3:
74859+ dentry = va_arg(ap, struct dentry *);
74860+ mnt = va_arg(ap, struct vfsmount *);
74861+ str1 = va_arg(ap, char *);
74862+ str2 = va_arg(ap, char *);
74863+ str3 = va_arg(ap, char *);
74864+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74865+ break;
74866+ case GR_FILENAME:
74867+ dentry = va_arg(ap, struct dentry *);
74868+ mnt = va_arg(ap, struct vfsmount *);
74869+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74870+ break;
74871+ case GR_STR_FILENAME:
74872+ str1 = va_arg(ap, char *);
74873+ dentry = va_arg(ap, struct dentry *);
74874+ mnt = va_arg(ap, struct vfsmount *);
74875+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74876+ break;
74877+ case GR_FILENAME_STR:
74878+ dentry = va_arg(ap, struct dentry *);
74879+ mnt = va_arg(ap, struct vfsmount *);
74880+ str1 = va_arg(ap, char *);
74881+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74882+ break;
74883+ case GR_FILENAME_TWO_INT:
74884+ dentry = va_arg(ap, struct dentry *);
74885+ mnt = va_arg(ap, struct vfsmount *);
74886+ num1 = va_arg(ap, int);
74887+ num2 = va_arg(ap, int);
74888+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74889+ break;
74890+ case GR_FILENAME_TWO_INT_STR:
74891+ dentry = va_arg(ap, struct dentry *);
74892+ mnt = va_arg(ap, struct vfsmount *);
74893+ num1 = va_arg(ap, int);
74894+ num2 = va_arg(ap, int);
74895+ str1 = va_arg(ap, char *);
74896+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74897+ break;
74898+ case GR_TEXTREL:
74899+ file = va_arg(ap, struct file *);
74900+ ulong1 = va_arg(ap, unsigned long);
74901+ ulong2 = va_arg(ap, unsigned long);
74902+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74903+ break;
74904+ case GR_PTRACE:
74905+ task = va_arg(ap, struct task_struct *);
74906+ 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));
74907+ break;
74908+ case GR_RESOURCE:
74909+ task = va_arg(ap, struct task_struct *);
74910+ cred = __task_cred(task);
74911+ pcred = __task_cred(task->real_parent);
74912+ ulong1 = va_arg(ap, unsigned long);
74913+ str1 = va_arg(ap, char *);
74914+ ulong2 = va_arg(ap, unsigned long);
74915+ 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));
74916+ break;
74917+ case GR_CAP:
74918+ task = va_arg(ap, struct task_struct *);
74919+ cred = __task_cred(task);
74920+ pcred = __task_cred(task->real_parent);
74921+ str1 = va_arg(ap, char *);
74922+ 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));
74923+ break;
74924+ case GR_SIG:
74925+ str1 = va_arg(ap, char *);
74926+ voidptr = va_arg(ap, void *);
74927+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74928+ break;
74929+ case GR_SIG2:
74930+ task = va_arg(ap, struct task_struct *);
74931+ cred = __task_cred(task);
74932+ pcred = __task_cred(task->real_parent);
74933+ num1 = va_arg(ap, int);
74934+ 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));
74935+ break;
74936+ case GR_CRASH1:
74937+ task = va_arg(ap, struct task_struct *);
74938+ cred = __task_cred(task);
74939+ pcred = __task_cred(task->real_parent);
74940+ ulong1 = va_arg(ap, unsigned long);
74941+ 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);
74942+ break;
74943+ case GR_CRASH2:
74944+ task = va_arg(ap, struct task_struct *);
74945+ cred = __task_cred(task);
74946+ pcred = __task_cred(task->real_parent);
74947+ ulong1 = va_arg(ap, unsigned long);
74948+ 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);
74949+ break;
74950+ case GR_RWXMAP:
74951+ file = va_arg(ap, struct file *);
74952+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74953+ break;
74954+ case GR_RWXMAPVMA:
74955+ vma = va_arg(ap, struct vm_area_struct *);
74956+ if (vma->vm_file)
74957+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74958+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74959+ str1 = "<stack>";
74960+ else if (vma->vm_start <= current->mm->brk &&
74961+ vma->vm_end >= current->mm->start_brk)
74962+ str1 = "<heap>";
74963+ else
74964+ str1 = "<anonymous mapping>";
74965+ gr_log_middle_varargs(audit, msg, str1);
74966+ break;
74967+ case GR_PSACCT:
74968+ {
74969+ unsigned int wday, cday;
74970+ __u8 whr, chr;
74971+ __u8 wmin, cmin;
74972+ __u8 wsec, csec;
74973+ char cur_tty[64] = { 0 };
74974+ char parent_tty[64] = { 0 };
74975+
74976+ task = va_arg(ap, struct task_struct *);
74977+ wday = va_arg(ap, unsigned int);
74978+ cday = va_arg(ap, unsigned int);
74979+ whr = va_arg(ap, int);
74980+ chr = va_arg(ap, int);
74981+ wmin = va_arg(ap, int);
74982+ cmin = va_arg(ap, int);
74983+ wsec = va_arg(ap, int);
74984+ csec = va_arg(ap, int);
74985+ ulong1 = va_arg(ap, unsigned long);
74986+ cred = __task_cred(task);
74987+ pcred = __task_cred(task->real_parent);
74988+
74989+ 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));
74990+ }
74991+ break;
74992+ default:
74993+ gr_log_middle(audit, msg, ap);
74994+ }
74995+ va_end(ap);
74996+ // these don't need DEFAULTSECARGS printed on the end
74997+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74998+ gr_log_end(audit, 0);
74999+ else
75000+ gr_log_end(audit, 1);
75001+ END_LOCKS(audit);
75002+}
75003diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75004new file mode 100644
75005index 0000000..0e39d8c
75006--- /dev/null
75007+++ b/grsecurity/grsec_mem.c
75008@@ -0,0 +1,48 @@
75009+#include <linux/kernel.h>
75010+#include <linux/sched.h>
75011+#include <linux/mm.h>
75012+#include <linux/mman.h>
75013+#include <linux/module.h>
75014+#include <linux/grinternal.h>
75015+
75016+void gr_handle_msr_write(void)
75017+{
75018+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75019+ return;
75020+}
75021+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75022+
75023+void
75024+gr_handle_ioperm(void)
75025+{
75026+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75027+ return;
75028+}
75029+
75030+void
75031+gr_handle_iopl(void)
75032+{
75033+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75034+ return;
75035+}
75036+
75037+void
75038+gr_handle_mem_readwrite(u64 from, u64 to)
75039+{
75040+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75041+ return;
75042+}
75043+
75044+void
75045+gr_handle_vm86(void)
75046+{
75047+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75048+ return;
75049+}
75050+
75051+void
75052+gr_log_badprocpid(const char *entry)
75053+{
75054+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75055+ return;
75056+}
75057diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75058new file mode 100644
75059index 0000000..cd9e124
75060--- /dev/null
75061+++ b/grsecurity/grsec_mount.c
75062@@ -0,0 +1,65 @@
75063+#include <linux/kernel.h>
75064+#include <linux/sched.h>
75065+#include <linux/mount.h>
75066+#include <linux/major.h>
75067+#include <linux/grsecurity.h>
75068+#include <linux/grinternal.h>
75069+
75070+void
75071+gr_log_remount(const char *devname, const int retval)
75072+{
75073+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75074+ if (grsec_enable_mount && (retval >= 0))
75075+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75076+#endif
75077+ return;
75078+}
75079+
75080+void
75081+gr_log_unmount(const char *devname, const int retval)
75082+{
75083+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75084+ if (grsec_enable_mount && (retval >= 0))
75085+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75086+#endif
75087+ return;
75088+}
75089+
75090+void
75091+gr_log_mount(const char *from, const char *to, const int retval)
75092+{
75093+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75094+ if (grsec_enable_mount && (retval >= 0))
75095+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75096+#endif
75097+ return;
75098+}
75099+
75100+int
75101+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75102+{
75103+#ifdef CONFIG_GRKERNSEC_ROFS
75104+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75105+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75106+ return -EPERM;
75107+ } else
75108+ return 0;
75109+#endif
75110+ return 0;
75111+}
75112+
75113+int
75114+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75115+{
75116+#ifdef CONFIG_GRKERNSEC_ROFS
75117+ struct inode *inode = dentry->d_inode;
75118+
75119+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75120+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75121+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75122+ return -EPERM;
75123+ } else
75124+ return 0;
75125+#endif
75126+ return 0;
75127+}
75128diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75129new file mode 100644
75130index 0000000..6ee9d50
75131--- /dev/null
75132+++ b/grsecurity/grsec_pax.c
75133@@ -0,0 +1,45 @@
75134+#include <linux/kernel.h>
75135+#include <linux/sched.h>
75136+#include <linux/mm.h>
75137+#include <linux/file.h>
75138+#include <linux/grinternal.h>
75139+#include <linux/grsecurity.h>
75140+
75141+void
75142+gr_log_textrel(struct vm_area_struct * vma)
75143+{
75144+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75145+ if (grsec_enable_log_rwxmaps)
75146+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75147+#endif
75148+ return;
75149+}
75150+
75151+void gr_log_ptgnustack(struct file *file)
75152+{
75153+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75154+ if (grsec_enable_log_rwxmaps)
75155+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75156+#endif
75157+ return;
75158+}
75159+
75160+void
75161+gr_log_rwxmmap(struct file *file)
75162+{
75163+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75164+ if (grsec_enable_log_rwxmaps)
75165+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75166+#endif
75167+ return;
75168+}
75169+
75170+void
75171+gr_log_rwxmprotect(struct vm_area_struct *vma)
75172+{
75173+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75174+ if (grsec_enable_log_rwxmaps)
75175+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75176+#endif
75177+ return;
75178+}
75179diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75180new file mode 100644
75181index 0000000..2005a3a
75182--- /dev/null
75183+++ b/grsecurity/grsec_proc.c
75184@@ -0,0 +1,20 @@
75185+#include <linux/kernel.h>
75186+#include <linux/sched.h>
75187+#include <linux/grsecurity.h>
75188+#include <linux/grinternal.h>
75189+
75190+int gr_proc_is_restricted(void)
75191+{
75192+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75193+ const struct cred *cred = current_cred();
75194+#endif
75195+
75196+#ifdef CONFIG_GRKERNSEC_PROC_USER
75197+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75198+ return -EACCES;
75199+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75200+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75201+ return -EACCES;
75202+#endif
75203+ return 0;
75204+}
75205diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75206new file mode 100644
75207index 0000000..f7f29aa
75208--- /dev/null
75209+++ b/grsecurity/grsec_ptrace.c
75210@@ -0,0 +1,30 @@
75211+#include <linux/kernel.h>
75212+#include <linux/sched.h>
75213+#include <linux/grinternal.h>
75214+#include <linux/security.h>
75215+
75216+void
75217+gr_audit_ptrace(struct task_struct *task)
75218+{
75219+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75220+ if (grsec_enable_audit_ptrace)
75221+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75222+#endif
75223+ return;
75224+}
75225+
75226+int
75227+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75228+{
75229+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75230+ const struct dentry *dentry = file->f_path.dentry;
75231+ const struct vfsmount *mnt = file->f_path.mnt;
75232+
75233+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75234+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75235+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75236+ return -EACCES;
75237+ }
75238+#endif
75239+ return 0;
75240+}
75241diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75242new file mode 100644
75243index 0000000..3860c7e
75244--- /dev/null
75245+++ b/grsecurity/grsec_sig.c
75246@@ -0,0 +1,236 @@
75247+#include <linux/kernel.h>
75248+#include <linux/sched.h>
75249+#include <linux/fs.h>
75250+#include <linux/delay.h>
75251+#include <linux/grsecurity.h>
75252+#include <linux/grinternal.h>
75253+#include <linux/hardirq.h>
75254+
75255+char *signames[] = {
75256+ [SIGSEGV] = "Segmentation fault",
75257+ [SIGILL] = "Illegal instruction",
75258+ [SIGABRT] = "Abort",
75259+ [SIGBUS] = "Invalid alignment/Bus error"
75260+};
75261+
75262+void
75263+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75264+{
75265+#ifdef CONFIG_GRKERNSEC_SIGNAL
75266+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75267+ (sig == SIGABRT) || (sig == SIGBUS))) {
75268+ if (task_pid_nr(t) == task_pid_nr(current)) {
75269+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75270+ } else {
75271+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75272+ }
75273+ }
75274+#endif
75275+ return;
75276+}
75277+
75278+int
75279+gr_handle_signal(const struct task_struct *p, const int sig)
75280+{
75281+#ifdef CONFIG_GRKERNSEC
75282+ /* ignore the 0 signal for protected task checks */
75283+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75284+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75285+ return -EPERM;
75286+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75287+ return -EPERM;
75288+ }
75289+#endif
75290+ return 0;
75291+}
75292+
75293+#ifdef CONFIG_GRKERNSEC
75294+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75295+
75296+int gr_fake_force_sig(int sig, struct task_struct *t)
75297+{
75298+ unsigned long int flags;
75299+ int ret, blocked, ignored;
75300+ struct k_sigaction *action;
75301+
75302+ spin_lock_irqsave(&t->sighand->siglock, flags);
75303+ action = &t->sighand->action[sig-1];
75304+ ignored = action->sa.sa_handler == SIG_IGN;
75305+ blocked = sigismember(&t->blocked, sig);
75306+ if (blocked || ignored) {
75307+ action->sa.sa_handler = SIG_DFL;
75308+ if (blocked) {
75309+ sigdelset(&t->blocked, sig);
75310+ recalc_sigpending_and_wake(t);
75311+ }
75312+ }
75313+ if (action->sa.sa_handler == SIG_DFL)
75314+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75315+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75316+
75317+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75318+
75319+ return ret;
75320+}
75321+#endif
75322+
75323+#define GR_USER_BAN_TIME (15 * 60)
75324+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75325+
75326+void gr_handle_brute_attach(int dumpable)
75327+{
75328+#ifdef CONFIG_GRKERNSEC_BRUTE
75329+ struct task_struct *p = current;
75330+ kuid_t uid = GLOBAL_ROOT_UID;
75331+ int daemon = 0;
75332+
75333+ if (!grsec_enable_brute)
75334+ return;
75335+
75336+ rcu_read_lock();
75337+ read_lock(&tasklist_lock);
75338+ read_lock(&grsec_exec_file_lock);
75339+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75340+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75341+ p->real_parent->brute = 1;
75342+ daemon = 1;
75343+ } else {
75344+ const struct cred *cred = __task_cred(p), *cred2;
75345+ struct task_struct *tsk, *tsk2;
75346+
75347+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75348+ struct user_struct *user;
75349+
75350+ uid = cred->uid;
75351+
75352+ /* this is put upon execution past expiration */
75353+ user = find_user(uid);
75354+ if (user == NULL)
75355+ goto unlock;
75356+ user->suid_banned = 1;
75357+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75358+ if (user->suid_ban_expires == ~0UL)
75359+ user->suid_ban_expires--;
75360+
75361+ /* only kill other threads of the same binary, from the same user */
75362+ do_each_thread(tsk2, tsk) {
75363+ cred2 = __task_cred(tsk);
75364+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75365+ gr_fake_force_sig(SIGKILL, tsk);
75366+ } while_each_thread(tsk2, tsk);
75367+ }
75368+ }
75369+unlock:
75370+ read_unlock(&grsec_exec_file_lock);
75371+ read_unlock(&tasklist_lock);
75372+ rcu_read_unlock();
75373+
75374+ if (gr_is_global_nonroot(uid))
75375+ 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);
75376+ else if (daemon)
75377+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75378+
75379+#endif
75380+ return;
75381+}
75382+
75383+void gr_handle_brute_check(void)
75384+{
75385+#ifdef CONFIG_GRKERNSEC_BRUTE
75386+ struct task_struct *p = current;
75387+
75388+ if (unlikely(p->brute)) {
75389+ if (!grsec_enable_brute)
75390+ p->brute = 0;
75391+ else if (time_before(get_seconds(), p->brute_expires))
75392+ msleep(30 * 1000);
75393+ }
75394+#endif
75395+ return;
75396+}
75397+
75398+void gr_handle_kernel_exploit(void)
75399+{
75400+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75401+ const struct cred *cred;
75402+ struct task_struct *tsk, *tsk2;
75403+ struct user_struct *user;
75404+ kuid_t uid;
75405+
75406+ if (in_irq() || in_serving_softirq() || in_nmi())
75407+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75408+
75409+ uid = current_uid();
75410+
75411+ if (gr_is_global_root(uid))
75412+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75413+ else {
75414+ /* kill all the processes of this user, hold a reference
75415+ to their creds struct, and prevent them from creating
75416+ another process until system reset
75417+ */
75418+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75419+ GR_GLOBAL_UID(uid));
75420+ /* we intentionally leak this ref */
75421+ user = get_uid(current->cred->user);
75422+ if (user)
75423+ user->kernel_banned = 1;
75424+
75425+ /* kill all processes of this user */
75426+ read_lock(&tasklist_lock);
75427+ do_each_thread(tsk2, tsk) {
75428+ cred = __task_cred(tsk);
75429+ if (uid_eq(cred->uid, uid))
75430+ gr_fake_force_sig(SIGKILL, tsk);
75431+ } while_each_thread(tsk2, tsk);
75432+ read_unlock(&tasklist_lock);
75433+ }
75434+#endif
75435+}
75436+
75437+#ifdef CONFIG_GRKERNSEC_BRUTE
75438+static bool suid_ban_expired(struct user_struct *user)
75439+{
75440+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75441+ user->suid_banned = 0;
75442+ user->suid_ban_expires = 0;
75443+ free_uid(user);
75444+ return true;
75445+ }
75446+
75447+ return false;
75448+}
75449+#endif
75450+
75451+int gr_process_kernel_exec_ban(void)
75452+{
75453+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75454+ if (unlikely(current->cred->user->kernel_banned))
75455+ return -EPERM;
75456+#endif
75457+ return 0;
75458+}
75459+
75460+int gr_process_kernel_setuid_ban(struct user_struct *user)
75461+{
75462+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75463+ if (unlikely(user->kernel_banned))
75464+ gr_fake_force_sig(SIGKILL, current);
75465+#endif
75466+ return 0;
75467+}
75468+
75469+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75470+{
75471+#ifdef CONFIG_GRKERNSEC_BRUTE
75472+ struct user_struct *user = current->cred->user;
75473+ if (unlikely(user->suid_banned)) {
75474+ if (suid_ban_expired(user))
75475+ return 0;
75476+ /* disallow execution of suid binaries only */
75477+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75478+ return -EPERM;
75479+ }
75480+#endif
75481+ return 0;
75482+}
75483diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75484new file mode 100644
75485index 0000000..c0aef3a
75486--- /dev/null
75487+++ b/grsecurity/grsec_sock.c
75488@@ -0,0 +1,244 @@
75489+#include <linux/kernel.h>
75490+#include <linux/module.h>
75491+#include <linux/sched.h>
75492+#include <linux/file.h>
75493+#include <linux/net.h>
75494+#include <linux/in.h>
75495+#include <linux/ip.h>
75496+#include <net/sock.h>
75497+#include <net/inet_sock.h>
75498+#include <linux/grsecurity.h>
75499+#include <linux/grinternal.h>
75500+#include <linux/gracl.h>
75501+
75502+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75503+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75504+
75505+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75506+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75507+
75508+#ifdef CONFIG_UNIX_MODULE
75509+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75510+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75511+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75512+EXPORT_SYMBOL_GPL(gr_handle_create);
75513+#endif
75514+
75515+#ifdef CONFIG_GRKERNSEC
75516+#define gr_conn_table_size 32749
75517+struct conn_table_entry {
75518+ struct conn_table_entry *next;
75519+ struct signal_struct *sig;
75520+};
75521+
75522+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75523+DEFINE_SPINLOCK(gr_conn_table_lock);
75524+
75525+extern const char * gr_socktype_to_name(unsigned char type);
75526+extern const char * gr_proto_to_name(unsigned char proto);
75527+extern const char * gr_sockfamily_to_name(unsigned char family);
75528+
75529+static __inline__ int
75530+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75531+{
75532+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75533+}
75534+
75535+static __inline__ int
75536+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75537+ __u16 sport, __u16 dport)
75538+{
75539+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75540+ sig->gr_sport == sport && sig->gr_dport == dport))
75541+ return 1;
75542+ else
75543+ return 0;
75544+}
75545+
75546+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75547+{
75548+ struct conn_table_entry **match;
75549+ unsigned int index;
75550+
75551+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75552+ sig->gr_sport, sig->gr_dport,
75553+ gr_conn_table_size);
75554+
75555+ newent->sig = sig;
75556+
75557+ match = &gr_conn_table[index];
75558+ newent->next = *match;
75559+ *match = newent;
75560+
75561+ return;
75562+}
75563+
75564+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75565+{
75566+ struct conn_table_entry *match, *last = NULL;
75567+ unsigned int index;
75568+
75569+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75570+ sig->gr_sport, sig->gr_dport,
75571+ gr_conn_table_size);
75572+
75573+ match = gr_conn_table[index];
75574+ while (match && !conn_match(match->sig,
75575+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75576+ sig->gr_dport)) {
75577+ last = match;
75578+ match = match->next;
75579+ }
75580+
75581+ if (match) {
75582+ if (last)
75583+ last->next = match->next;
75584+ else
75585+ gr_conn_table[index] = NULL;
75586+ kfree(match);
75587+ }
75588+
75589+ return;
75590+}
75591+
75592+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75593+ __u16 sport, __u16 dport)
75594+{
75595+ struct conn_table_entry *match;
75596+ unsigned int index;
75597+
75598+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75599+
75600+ match = gr_conn_table[index];
75601+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75602+ match = match->next;
75603+
75604+ if (match)
75605+ return match->sig;
75606+ else
75607+ return NULL;
75608+}
75609+
75610+#endif
75611+
75612+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75613+{
75614+#ifdef CONFIG_GRKERNSEC
75615+ struct signal_struct *sig = task->signal;
75616+ struct conn_table_entry *newent;
75617+
75618+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75619+ if (newent == NULL)
75620+ return;
75621+ /* no bh lock needed since we are called with bh disabled */
75622+ spin_lock(&gr_conn_table_lock);
75623+ gr_del_task_from_ip_table_nolock(sig);
75624+ sig->gr_saddr = inet->inet_rcv_saddr;
75625+ sig->gr_daddr = inet->inet_daddr;
75626+ sig->gr_sport = inet->inet_sport;
75627+ sig->gr_dport = inet->inet_dport;
75628+ gr_add_to_task_ip_table_nolock(sig, newent);
75629+ spin_unlock(&gr_conn_table_lock);
75630+#endif
75631+ return;
75632+}
75633+
75634+void gr_del_task_from_ip_table(struct task_struct *task)
75635+{
75636+#ifdef CONFIG_GRKERNSEC
75637+ spin_lock_bh(&gr_conn_table_lock);
75638+ gr_del_task_from_ip_table_nolock(task->signal);
75639+ spin_unlock_bh(&gr_conn_table_lock);
75640+#endif
75641+ return;
75642+}
75643+
75644+void
75645+gr_attach_curr_ip(const struct sock *sk)
75646+{
75647+#ifdef CONFIG_GRKERNSEC
75648+ struct signal_struct *p, *set;
75649+ const struct inet_sock *inet = inet_sk(sk);
75650+
75651+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75652+ return;
75653+
75654+ set = current->signal;
75655+
75656+ spin_lock_bh(&gr_conn_table_lock);
75657+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75658+ inet->inet_dport, inet->inet_sport);
75659+ if (unlikely(p != NULL)) {
75660+ set->curr_ip = p->curr_ip;
75661+ set->used_accept = 1;
75662+ gr_del_task_from_ip_table_nolock(p);
75663+ spin_unlock_bh(&gr_conn_table_lock);
75664+ return;
75665+ }
75666+ spin_unlock_bh(&gr_conn_table_lock);
75667+
75668+ set->curr_ip = inet->inet_daddr;
75669+ set->used_accept = 1;
75670+#endif
75671+ return;
75672+}
75673+
75674+int
75675+gr_handle_sock_all(const int family, const int type, const int protocol)
75676+{
75677+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75678+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75679+ (family != AF_UNIX)) {
75680+ if (family == AF_INET)
75681+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75682+ else
75683+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75684+ return -EACCES;
75685+ }
75686+#endif
75687+ return 0;
75688+}
75689+
75690+int
75691+gr_handle_sock_server(const struct sockaddr *sck)
75692+{
75693+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75694+ if (grsec_enable_socket_server &&
75695+ in_group_p(grsec_socket_server_gid) &&
75696+ sck && (sck->sa_family != AF_UNIX) &&
75697+ (sck->sa_family != AF_LOCAL)) {
75698+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75699+ return -EACCES;
75700+ }
75701+#endif
75702+ return 0;
75703+}
75704+
75705+int
75706+gr_handle_sock_server_other(const struct sock *sck)
75707+{
75708+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75709+ if (grsec_enable_socket_server &&
75710+ in_group_p(grsec_socket_server_gid) &&
75711+ sck && (sck->sk_family != AF_UNIX) &&
75712+ (sck->sk_family != AF_LOCAL)) {
75713+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75714+ return -EACCES;
75715+ }
75716+#endif
75717+ return 0;
75718+}
75719+
75720+int
75721+gr_handle_sock_client(const struct sockaddr *sck)
75722+{
75723+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75724+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75725+ sck && (sck->sa_family != AF_UNIX) &&
75726+ (sck->sa_family != AF_LOCAL)) {
75727+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75728+ return -EACCES;
75729+ }
75730+#endif
75731+ return 0;
75732+}
75733diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75734new file mode 100644
75735index 0000000..8159888
75736--- /dev/null
75737+++ b/grsecurity/grsec_sysctl.c
75738@@ -0,0 +1,479 @@
75739+#include <linux/kernel.h>
75740+#include <linux/sched.h>
75741+#include <linux/sysctl.h>
75742+#include <linux/grsecurity.h>
75743+#include <linux/grinternal.h>
75744+
75745+int
75746+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75747+{
75748+#ifdef CONFIG_GRKERNSEC_SYSCTL
75749+ if (dirname == NULL || name == NULL)
75750+ return 0;
75751+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75752+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75753+ return -EACCES;
75754+ }
75755+#endif
75756+ return 0;
75757+}
75758+
75759+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75760+static int __maybe_unused __read_only one = 1;
75761+#endif
75762+
75763+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75764+ defined(CONFIG_GRKERNSEC_DENYUSB)
75765+struct ctl_table grsecurity_table[] = {
75766+#ifdef CONFIG_GRKERNSEC_SYSCTL
75767+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75768+#ifdef CONFIG_GRKERNSEC_IO
75769+ {
75770+ .procname = "disable_priv_io",
75771+ .data = &grsec_disable_privio,
75772+ .maxlen = sizeof(int),
75773+ .mode = 0600,
75774+ .proc_handler = &proc_dointvec,
75775+ },
75776+#endif
75777+#endif
75778+#ifdef CONFIG_GRKERNSEC_LINK
75779+ {
75780+ .procname = "linking_restrictions",
75781+ .data = &grsec_enable_link,
75782+ .maxlen = sizeof(int),
75783+ .mode = 0600,
75784+ .proc_handler = &proc_dointvec,
75785+ },
75786+#endif
75787+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75788+ {
75789+ .procname = "enforce_symlinksifowner",
75790+ .data = &grsec_enable_symlinkown,
75791+ .maxlen = sizeof(int),
75792+ .mode = 0600,
75793+ .proc_handler = &proc_dointvec,
75794+ },
75795+ {
75796+ .procname = "symlinkown_gid",
75797+ .data = &grsec_symlinkown_gid,
75798+ .maxlen = sizeof(int),
75799+ .mode = 0600,
75800+ .proc_handler = &proc_dointvec,
75801+ },
75802+#endif
75803+#ifdef CONFIG_GRKERNSEC_BRUTE
75804+ {
75805+ .procname = "deter_bruteforce",
75806+ .data = &grsec_enable_brute,
75807+ .maxlen = sizeof(int),
75808+ .mode = 0600,
75809+ .proc_handler = &proc_dointvec,
75810+ },
75811+#endif
75812+#ifdef CONFIG_GRKERNSEC_FIFO
75813+ {
75814+ .procname = "fifo_restrictions",
75815+ .data = &grsec_enable_fifo,
75816+ .maxlen = sizeof(int),
75817+ .mode = 0600,
75818+ .proc_handler = &proc_dointvec,
75819+ },
75820+#endif
75821+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75822+ {
75823+ .procname = "ptrace_readexec",
75824+ .data = &grsec_enable_ptrace_readexec,
75825+ .maxlen = sizeof(int),
75826+ .mode = 0600,
75827+ .proc_handler = &proc_dointvec,
75828+ },
75829+#endif
75830+#ifdef CONFIG_GRKERNSEC_SETXID
75831+ {
75832+ .procname = "consistent_setxid",
75833+ .data = &grsec_enable_setxid,
75834+ .maxlen = sizeof(int),
75835+ .mode = 0600,
75836+ .proc_handler = &proc_dointvec,
75837+ },
75838+#endif
75839+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75840+ {
75841+ .procname = "ip_blackhole",
75842+ .data = &grsec_enable_blackhole,
75843+ .maxlen = sizeof(int),
75844+ .mode = 0600,
75845+ .proc_handler = &proc_dointvec,
75846+ },
75847+ {
75848+ .procname = "lastack_retries",
75849+ .data = &grsec_lastack_retries,
75850+ .maxlen = sizeof(int),
75851+ .mode = 0600,
75852+ .proc_handler = &proc_dointvec,
75853+ },
75854+#endif
75855+#ifdef CONFIG_GRKERNSEC_EXECLOG
75856+ {
75857+ .procname = "exec_logging",
75858+ .data = &grsec_enable_execlog,
75859+ .maxlen = sizeof(int),
75860+ .mode = 0600,
75861+ .proc_handler = &proc_dointvec,
75862+ },
75863+#endif
75864+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75865+ {
75866+ .procname = "rwxmap_logging",
75867+ .data = &grsec_enable_log_rwxmaps,
75868+ .maxlen = sizeof(int),
75869+ .mode = 0600,
75870+ .proc_handler = &proc_dointvec,
75871+ },
75872+#endif
75873+#ifdef CONFIG_GRKERNSEC_SIGNAL
75874+ {
75875+ .procname = "signal_logging",
75876+ .data = &grsec_enable_signal,
75877+ .maxlen = sizeof(int),
75878+ .mode = 0600,
75879+ .proc_handler = &proc_dointvec,
75880+ },
75881+#endif
75882+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75883+ {
75884+ .procname = "forkfail_logging",
75885+ .data = &grsec_enable_forkfail,
75886+ .maxlen = sizeof(int),
75887+ .mode = 0600,
75888+ .proc_handler = &proc_dointvec,
75889+ },
75890+#endif
75891+#ifdef CONFIG_GRKERNSEC_TIME
75892+ {
75893+ .procname = "timechange_logging",
75894+ .data = &grsec_enable_time,
75895+ .maxlen = sizeof(int),
75896+ .mode = 0600,
75897+ .proc_handler = &proc_dointvec,
75898+ },
75899+#endif
75900+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75901+ {
75902+ .procname = "chroot_deny_shmat",
75903+ .data = &grsec_enable_chroot_shmat,
75904+ .maxlen = sizeof(int),
75905+ .mode = 0600,
75906+ .proc_handler = &proc_dointvec,
75907+ },
75908+#endif
75909+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75910+ {
75911+ .procname = "chroot_deny_unix",
75912+ .data = &grsec_enable_chroot_unix,
75913+ .maxlen = sizeof(int),
75914+ .mode = 0600,
75915+ .proc_handler = &proc_dointvec,
75916+ },
75917+#endif
75918+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75919+ {
75920+ .procname = "chroot_deny_mount",
75921+ .data = &grsec_enable_chroot_mount,
75922+ .maxlen = sizeof(int),
75923+ .mode = 0600,
75924+ .proc_handler = &proc_dointvec,
75925+ },
75926+#endif
75927+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75928+ {
75929+ .procname = "chroot_deny_fchdir",
75930+ .data = &grsec_enable_chroot_fchdir,
75931+ .maxlen = sizeof(int),
75932+ .mode = 0600,
75933+ .proc_handler = &proc_dointvec,
75934+ },
75935+#endif
75936+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75937+ {
75938+ .procname = "chroot_deny_chroot",
75939+ .data = &grsec_enable_chroot_double,
75940+ .maxlen = sizeof(int),
75941+ .mode = 0600,
75942+ .proc_handler = &proc_dointvec,
75943+ },
75944+#endif
75945+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75946+ {
75947+ .procname = "chroot_deny_pivot",
75948+ .data = &grsec_enable_chroot_pivot,
75949+ .maxlen = sizeof(int),
75950+ .mode = 0600,
75951+ .proc_handler = &proc_dointvec,
75952+ },
75953+#endif
75954+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75955+ {
75956+ .procname = "chroot_enforce_chdir",
75957+ .data = &grsec_enable_chroot_chdir,
75958+ .maxlen = sizeof(int),
75959+ .mode = 0600,
75960+ .proc_handler = &proc_dointvec,
75961+ },
75962+#endif
75963+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75964+ {
75965+ .procname = "chroot_deny_chmod",
75966+ .data = &grsec_enable_chroot_chmod,
75967+ .maxlen = sizeof(int),
75968+ .mode = 0600,
75969+ .proc_handler = &proc_dointvec,
75970+ },
75971+#endif
75972+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75973+ {
75974+ .procname = "chroot_deny_mknod",
75975+ .data = &grsec_enable_chroot_mknod,
75976+ .maxlen = sizeof(int),
75977+ .mode = 0600,
75978+ .proc_handler = &proc_dointvec,
75979+ },
75980+#endif
75981+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75982+ {
75983+ .procname = "chroot_restrict_nice",
75984+ .data = &grsec_enable_chroot_nice,
75985+ .maxlen = sizeof(int),
75986+ .mode = 0600,
75987+ .proc_handler = &proc_dointvec,
75988+ },
75989+#endif
75990+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75991+ {
75992+ .procname = "chroot_execlog",
75993+ .data = &grsec_enable_chroot_execlog,
75994+ .maxlen = sizeof(int),
75995+ .mode = 0600,
75996+ .proc_handler = &proc_dointvec,
75997+ },
75998+#endif
75999+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76000+ {
76001+ .procname = "chroot_caps",
76002+ .data = &grsec_enable_chroot_caps,
76003+ .maxlen = sizeof(int),
76004+ .mode = 0600,
76005+ .proc_handler = &proc_dointvec,
76006+ },
76007+#endif
76008+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76009+ {
76010+ .procname = "chroot_deny_sysctl",
76011+ .data = &grsec_enable_chroot_sysctl,
76012+ .maxlen = sizeof(int),
76013+ .mode = 0600,
76014+ .proc_handler = &proc_dointvec,
76015+ },
76016+#endif
76017+#ifdef CONFIG_GRKERNSEC_TPE
76018+ {
76019+ .procname = "tpe",
76020+ .data = &grsec_enable_tpe,
76021+ .maxlen = sizeof(int),
76022+ .mode = 0600,
76023+ .proc_handler = &proc_dointvec,
76024+ },
76025+ {
76026+ .procname = "tpe_gid",
76027+ .data = &grsec_tpe_gid,
76028+ .maxlen = sizeof(int),
76029+ .mode = 0600,
76030+ .proc_handler = &proc_dointvec,
76031+ },
76032+#endif
76033+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76034+ {
76035+ .procname = "tpe_invert",
76036+ .data = &grsec_enable_tpe_invert,
76037+ .maxlen = sizeof(int),
76038+ .mode = 0600,
76039+ .proc_handler = &proc_dointvec,
76040+ },
76041+#endif
76042+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76043+ {
76044+ .procname = "tpe_restrict_all",
76045+ .data = &grsec_enable_tpe_all,
76046+ .maxlen = sizeof(int),
76047+ .mode = 0600,
76048+ .proc_handler = &proc_dointvec,
76049+ },
76050+#endif
76051+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76052+ {
76053+ .procname = "socket_all",
76054+ .data = &grsec_enable_socket_all,
76055+ .maxlen = sizeof(int),
76056+ .mode = 0600,
76057+ .proc_handler = &proc_dointvec,
76058+ },
76059+ {
76060+ .procname = "socket_all_gid",
76061+ .data = &grsec_socket_all_gid,
76062+ .maxlen = sizeof(int),
76063+ .mode = 0600,
76064+ .proc_handler = &proc_dointvec,
76065+ },
76066+#endif
76067+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76068+ {
76069+ .procname = "socket_client",
76070+ .data = &grsec_enable_socket_client,
76071+ .maxlen = sizeof(int),
76072+ .mode = 0600,
76073+ .proc_handler = &proc_dointvec,
76074+ },
76075+ {
76076+ .procname = "socket_client_gid",
76077+ .data = &grsec_socket_client_gid,
76078+ .maxlen = sizeof(int),
76079+ .mode = 0600,
76080+ .proc_handler = &proc_dointvec,
76081+ },
76082+#endif
76083+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76084+ {
76085+ .procname = "socket_server",
76086+ .data = &grsec_enable_socket_server,
76087+ .maxlen = sizeof(int),
76088+ .mode = 0600,
76089+ .proc_handler = &proc_dointvec,
76090+ },
76091+ {
76092+ .procname = "socket_server_gid",
76093+ .data = &grsec_socket_server_gid,
76094+ .maxlen = sizeof(int),
76095+ .mode = 0600,
76096+ .proc_handler = &proc_dointvec,
76097+ },
76098+#endif
76099+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76100+ {
76101+ .procname = "audit_group",
76102+ .data = &grsec_enable_group,
76103+ .maxlen = sizeof(int),
76104+ .mode = 0600,
76105+ .proc_handler = &proc_dointvec,
76106+ },
76107+ {
76108+ .procname = "audit_gid",
76109+ .data = &grsec_audit_gid,
76110+ .maxlen = sizeof(int),
76111+ .mode = 0600,
76112+ .proc_handler = &proc_dointvec,
76113+ },
76114+#endif
76115+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76116+ {
76117+ .procname = "audit_chdir",
76118+ .data = &grsec_enable_chdir,
76119+ .maxlen = sizeof(int),
76120+ .mode = 0600,
76121+ .proc_handler = &proc_dointvec,
76122+ },
76123+#endif
76124+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76125+ {
76126+ .procname = "audit_mount",
76127+ .data = &grsec_enable_mount,
76128+ .maxlen = sizeof(int),
76129+ .mode = 0600,
76130+ .proc_handler = &proc_dointvec,
76131+ },
76132+#endif
76133+#ifdef CONFIG_GRKERNSEC_DMESG
76134+ {
76135+ .procname = "dmesg",
76136+ .data = &grsec_enable_dmesg,
76137+ .maxlen = sizeof(int),
76138+ .mode = 0600,
76139+ .proc_handler = &proc_dointvec,
76140+ },
76141+#endif
76142+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76143+ {
76144+ .procname = "chroot_findtask",
76145+ .data = &grsec_enable_chroot_findtask,
76146+ .maxlen = sizeof(int),
76147+ .mode = 0600,
76148+ .proc_handler = &proc_dointvec,
76149+ },
76150+#endif
76151+#ifdef CONFIG_GRKERNSEC_RESLOG
76152+ {
76153+ .procname = "resource_logging",
76154+ .data = &grsec_resource_logging,
76155+ .maxlen = sizeof(int),
76156+ .mode = 0600,
76157+ .proc_handler = &proc_dointvec,
76158+ },
76159+#endif
76160+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76161+ {
76162+ .procname = "audit_ptrace",
76163+ .data = &grsec_enable_audit_ptrace,
76164+ .maxlen = sizeof(int),
76165+ .mode = 0600,
76166+ .proc_handler = &proc_dointvec,
76167+ },
76168+#endif
76169+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76170+ {
76171+ .procname = "harden_ptrace",
76172+ .data = &grsec_enable_harden_ptrace,
76173+ .maxlen = sizeof(int),
76174+ .mode = 0600,
76175+ .proc_handler = &proc_dointvec,
76176+ },
76177+#endif
76178+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76179+ {
76180+ .procname = "harden_ipc",
76181+ .data = &grsec_enable_harden_ipc,
76182+ .maxlen = sizeof(int),
76183+ .mode = 0600,
76184+ .proc_handler = &proc_dointvec,
76185+ },
76186+#endif
76187+ {
76188+ .procname = "grsec_lock",
76189+ .data = &grsec_lock,
76190+ .maxlen = sizeof(int),
76191+ .mode = 0600,
76192+ .proc_handler = &proc_dointvec,
76193+ },
76194+#endif
76195+#ifdef CONFIG_GRKERNSEC_ROFS
76196+ {
76197+ .procname = "romount_protect",
76198+ .data = &grsec_enable_rofs,
76199+ .maxlen = sizeof(int),
76200+ .mode = 0600,
76201+ .proc_handler = &proc_dointvec_minmax,
76202+ .extra1 = &one,
76203+ .extra2 = &one,
76204+ },
76205+#endif
76206+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76207+ {
76208+ .procname = "deny_new_usb",
76209+ .data = &grsec_deny_new_usb,
76210+ .maxlen = sizeof(int),
76211+ .mode = 0600,
76212+ .proc_handler = &proc_dointvec,
76213+ },
76214+#endif
76215+ { }
76216+};
76217+#endif
76218diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76219new file mode 100644
76220index 0000000..61b514e
76221--- /dev/null
76222+++ b/grsecurity/grsec_time.c
76223@@ -0,0 +1,16 @@
76224+#include <linux/kernel.h>
76225+#include <linux/sched.h>
76226+#include <linux/grinternal.h>
76227+#include <linux/module.h>
76228+
76229+void
76230+gr_log_timechange(void)
76231+{
76232+#ifdef CONFIG_GRKERNSEC_TIME
76233+ if (grsec_enable_time)
76234+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76235+#endif
76236+ return;
76237+}
76238+
76239+EXPORT_SYMBOL_GPL(gr_log_timechange);
76240diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76241new file mode 100644
76242index 0000000..ee57dcf
76243--- /dev/null
76244+++ b/grsecurity/grsec_tpe.c
76245@@ -0,0 +1,73 @@
76246+#include <linux/kernel.h>
76247+#include <linux/sched.h>
76248+#include <linux/file.h>
76249+#include <linux/fs.h>
76250+#include <linux/grinternal.h>
76251+
76252+extern int gr_acl_tpe_check(void);
76253+
76254+int
76255+gr_tpe_allow(const struct file *file)
76256+{
76257+#ifdef CONFIG_GRKERNSEC
76258+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76259+ const struct cred *cred = current_cred();
76260+ char *msg = NULL;
76261+ char *msg2 = NULL;
76262+
76263+ // never restrict root
76264+ if (gr_is_global_root(cred->uid))
76265+ return 1;
76266+
76267+ if (grsec_enable_tpe) {
76268+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76269+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76270+ msg = "not being in trusted group";
76271+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76272+ msg = "being in untrusted group";
76273+#else
76274+ if (in_group_p(grsec_tpe_gid))
76275+ msg = "being in untrusted group";
76276+#endif
76277+ }
76278+ if (!msg && gr_acl_tpe_check())
76279+ msg = "being in untrusted role";
76280+
76281+ // not in any affected group/role
76282+ if (!msg)
76283+ goto next_check;
76284+
76285+ if (gr_is_global_nonroot(inode->i_uid))
76286+ msg2 = "file in non-root-owned directory";
76287+ else if (inode->i_mode & S_IWOTH)
76288+ msg2 = "file in world-writable directory";
76289+ else if (inode->i_mode & S_IWGRP)
76290+ msg2 = "file in group-writable directory";
76291+
76292+ if (msg && msg2) {
76293+ char fullmsg[70] = {0};
76294+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76295+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76296+ return 0;
76297+ }
76298+ msg = NULL;
76299+next_check:
76300+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76301+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76302+ return 1;
76303+
76304+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76305+ msg = "directory not owned by user";
76306+ else if (inode->i_mode & S_IWOTH)
76307+ msg = "file in world-writable directory";
76308+ else if (inode->i_mode & S_IWGRP)
76309+ msg = "file in group-writable directory";
76310+
76311+ if (msg) {
76312+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76313+ return 0;
76314+ }
76315+#endif
76316+#endif
76317+ return 1;
76318+}
76319diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76320new file mode 100644
76321index 0000000..ae02d8e
76322--- /dev/null
76323+++ b/grsecurity/grsec_usb.c
76324@@ -0,0 +1,15 @@
76325+#include <linux/kernel.h>
76326+#include <linux/grinternal.h>
76327+#include <linux/module.h>
76328+
76329+int gr_handle_new_usb(void)
76330+{
76331+#ifdef CONFIG_GRKERNSEC_DENYUSB
76332+ if (grsec_deny_new_usb) {
76333+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76334+ return 1;
76335+ }
76336+#endif
76337+ return 0;
76338+}
76339+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76340diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76341new file mode 100644
76342index 0000000..9f7b1ac
76343--- /dev/null
76344+++ b/grsecurity/grsum.c
76345@@ -0,0 +1,61 @@
76346+#include <linux/err.h>
76347+#include <linux/kernel.h>
76348+#include <linux/sched.h>
76349+#include <linux/mm.h>
76350+#include <linux/scatterlist.h>
76351+#include <linux/crypto.h>
76352+#include <linux/gracl.h>
76353+
76354+
76355+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76356+#error "crypto and sha256 must be built into the kernel"
76357+#endif
76358+
76359+int
76360+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76361+{
76362+ char *p;
76363+ struct crypto_hash *tfm;
76364+ struct hash_desc desc;
76365+ struct scatterlist sg;
76366+ unsigned char temp_sum[GR_SHA_LEN];
76367+ volatile int retval = 0;
76368+ volatile int dummy = 0;
76369+ unsigned int i;
76370+
76371+ sg_init_table(&sg, 1);
76372+
76373+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76374+ if (IS_ERR(tfm)) {
76375+ /* should never happen, since sha256 should be built in */
76376+ return 1;
76377+ }
76378+
76379+ desc.tfm = tfm;
76380+ desc.flags = 0;
76381+
76382+ crypto_hash_init(&desc);
76383+
76384+ p = salt;
76385+ sg_set_buf(&sg, p, GR_SALT_LEN);
76386+ crypto_hash_update(&desc, &sg, sg.length);
76387+
76388+ p = entry->pw;
76389+ sg_set_buf(&sg, p, strlen(p));
76390+
76391+ crypto_hash_update(&desc, &sg, sg.length);
76392+
76393+ crypto_hash_final(&desc, temp_sum);
76394+
76395+ memset(entry->pw, 0, GR_PW_LEN);
76396+
76397+ for (i = 0; i < GR_SHA_LEN; i++)
76398+ if (sum[i] != temp_sum[i])
76399+ retval = 1;
76400+ else
76401+ dummy = 1; // waste a cycle
76402+
76403+ crypto_free_hash(tfm);
76404+
76405+ return retval;
76406+}
76407diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76408index 77ff547..181834f 100644
76409--- a/include/asm-generic/4level-fixup.h
76410+++ b/include/asm-generic/4level-fixup.h
76411@@ -13,8 +13,10 @@
76412 #define pmd_alloc(mm, pud, address) \
76413 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76414 NULL: pmd_offset(pud, address))
76415+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76416
76417 #define pud_alloc(mm, pgd, address) (pgd)
76418+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76419 #define pud_offset(pgd, start) (pgd)
76420 #define pud_none(pud) 0
76421 #define pud_bad(pud) 0
76422diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76423index b7babf0..97f4c4f 100644
76424--- a/include/asm-generic/atomic-long.h
76425+++ b/include/asm-generic/atomic-long.h
76426@@ -22,6 +22,12 @@
76427
76428 typedef atomic64_t atomic_long_t;
76429
76430+#ifdef CONFIG_PAX_REFCOUNT
76431+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76432+#else
76433+typedef atomic64_t atomic_long_unchecked_t;
76434+#endif
76435+
76436 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76437
76438 static inline long atomic_long_read(atomic_long_t *l)
76439@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76440 return (long)atomic64_read(v);
76441 }
76442
76443+#ifdef CONFIG_PAX_REFCOUNT
76444+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76445+{
76446+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76447+
76448+ return (long)atomic64_read_unchecked(v);
76449+}
76450+#endif
76451+
76452 static inline void atomic_long_set(atomic_long_t *l, long i)
76453 {
76454 atomic64_t *v = (atomic64_t *)l;
76455@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76456 atomic64_set(v, i);
76457 }
76458
76459+#ifdef CONFIG_PAX_REFCOUNT
76460+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76461+{
76462+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76463+
76464+ atomic64_set_unchecked(v, i);
76465+}
76466+#endif
76467+
76468 static inline void atomic_long_inc(atomic_long_t *l)
76469 {
76470 atomic64_t *v = (atomic64_t *)l;
76471@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76472 atomic64_inc(v);
76473 }
76474
76475+#ifdef CONFIG_PAX_REFCOUNT
76476+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76477+{
76478+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76479+
76480+ atomic64_inc_unchecked(v);
76481+}
76482+#endif
76483+
76484 static inline void atomic_long_dec(atomic_long_t *l)
76485 {
76486 atomic64_t *v = (atomic64_t *)l;
76487@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76488 atomic64_dec(v);
76489 }
76490
76491+#ifdef CONFIG_PAX_REFCOUNT
76492+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76493+{
76494+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76495+
76496+ atomic64_dec_unchecked(v);
76497+}
76498+#endif
76499+
76500 static inline void atomic_long_add(long i, atomic_long_t *l)
76501 {
76502 atomic64_t *v = (atomic64_t *)l;
76503@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76504 atomic64_add(i, v);
76505 }
76506
76507+#ifdef CONFIG_PAX_REFCOUNT
76508+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76509+{
76510+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76511+
76512+ atomic64_add_unchecked(i, v);
76513+}
76514+#endif
76515+
76516 static inline void atomic_long_sub(long i, atomic_long_t *l)
76517 {
76518 atomic64_t *v = (atomic64_t *)l;
76519@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76520 atomic64_sub(i, v);
76521 }
76522
76523+#ifdef CONFIG_PAX_REFCOUNT
76524+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76525+{
76526+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76527+
76528+ atomic64_sub_unchecked(i, v);
76529+}
76530+#endif
76531+
76532 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76533 {
76534 atomic64_t *v = (atomic64_t *)l;
76535@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76536 return atomic64_add_negative(i, v);
76537 }
76538
76539-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76540+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76541 {
76542 atomic64_t *v = (atomic64_t *)l;
76543
76544 return (long)atomic64_add_return(i, v);
76545 }
76546
76547+#ifdef CONFIG_PAX_REFCOUNT
76548+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76549+{
76550+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76551+
76552+ return (long)atomic64_add_return_unchecked(i, v);
76553+}
76554+#endif
76555+
76556 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76557 {
76558 atomic64_t *v = (atomic64_t *)l;
76559@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76560 return (long)atomic64_inc_return(v);
76561 }
76562
76563+#ifdef CONFIG_PAX_REFCOUNT
76564+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76565+{
76566+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76567+
76568+ return (long)atomic64_inc_return_unchecked(v);
76569+}
76570+#endif
76571+
76572 static inline long atomic_long_dec_return(atomic_long_t *l)
76573 {
76574 atomic64_t *v = (atomic64_t *)l;
76575@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76576
76577 typedef atomic_t atomic_long_t;
76578
76579+#ifdef CONFIG_PAX_REFCOUNT
76580+typedef atomic_unchecked_t atomic_long_unchecked_t;
76581+#else
76582+typedef atomic_t atomic_long_unchecked_t;
76583+#endif
76584+
76585 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76586 static inline long atomic_long_read(atomic_long_t *l)
76587 {
76588@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76589 return (long)atomic_read(v);
76590 }
76591
76592+#ifdef CONFIG_PAX_REFCOUNT
76593+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76594+{
76595+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76596+
76597+ return (long)atomic_read_unchecked(v);
76598+}
76599+#endif
76600+
76601 static inline void atomic_long_set(atomic_long_t *l, long i)
76602 {
76603 atomic_t *v = (atomic_t *)l;
76604@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76605 atomic_set(v, i);
76606 }
76607
76608+#ifdef CONFIG_PAX_REFCOUNT
76609+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76610+{
76611+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76612+
76613+ atomic_set_unchecked(v, i);
76614+}
76615+#endif
76616+
76617 static inline void atomic_long_inc(atomic_long_t *l)
76618 {
76619 atomic_t *v = (atomic_t *)l;
76620@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76621 atomic_inc(v);
76622 }
76623
76624+#ifdef CONFIG_PAX_REFCOUNT
76625+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76626+{
76627+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76628+
76629+ atomic_inc_unchecked(v);
76630+}
76631+#endif
76632+
76633 static inline void atomic_long_dec(atomic_long_t *l)
76634 {
76635 atomic_t *v = (atomic_t *)l;
76636@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76637 atomic_dec(v);
76638 }
76639
76640+#ifdef CONFIG_PAX_REFCOUNT
76641+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76642+{
76643+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76644+
76645+ atomic_dec_unchecked(v);
76646+}
76647+#endif
76648+
76649 static inline void atomic_long_add(long i, atomic_long_t *l)
76650 {
76651 atomic_t *v = (atomic_t *)l;
76652@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76653 atomic_add(i, v);
76654 }
76655
76656+#ifdef CONFIG_PAX_REFCOUNT
76657+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76658+{
76659+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76660+
76661+ atomic_add_unchecked(i, v);
76662+}
76663+#endif
76664+
76665 static inline void atomic_long_sub(long i, atomic_long_t *l)
76666 {
76667 atomic_t *v = (atomic_t *)l;
76668@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76669 atomic_sub(i, v);
76670 }
76671
76672+#ifdef CONFIG_PAX_REFCOUNT
76673+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76674+{
76675+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76676+
76677+ atomic_sub_unchecked(i, v);
76678+}
76679+#endif
76680+
76681 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76682 {
76683 atomic_t *v = (atomic_t *)l;
76684@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76685 return (long)atomic_add_return(i, v);
76686 }
76687
76688+#ifdef CONFIG_PAX_REFCOUNT
76689+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76690+{
76691+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76692+
76693+ return (long)atomic_add_return_unchecked(i, v);
76694+}
76695+
76696+#endif
76697+
76698 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76699 {
76700 atomic_t *v = (atomic_t *)l;
76701@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76702 return (long)atomic_inc_return(v);
76703 }
76704
76705+#ifdef CONFIG_PAX_REFCOUNT
76706+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76707+{
76708+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76709+
76710+ return (long)atomic_inc_return_unchecked(v);
76711+}
76712+#endif
76713+
76714 static inline long atomic_long_dec_return(atomic_long_t *l)
76715 {
76716 atomic_t *v = (atomic_t *)l;
76717@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76718
76719 #endif /* BITS_PER_LONG == 64 */
76720
76721+#ifdef CONFIG_PAX_REFCOUNT
76722+static inline void pax_refcount_needs_these_functions(void)
76723+{
76724+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76725+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76726+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76727+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76728+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76729+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76730+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76731+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76732+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76733+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76734+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76735+#ifdef CONFIG_X86
76736+ atomic_clear_mask_unchecked(0, NULL);
76737+ atomic_set_mask_unchecked(0, NULL);
76738+#endif
76739+
76740+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76741+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76742+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76743+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76744+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76745+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76746+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76747+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76748+}
76749+#else
76750+#define atomic_read_unchecked(v) atomic_read(v)
76751+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76752+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76753+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76754+#define atomic_inc_unchecked(v) atomic_inc(v)
76755+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76756+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76757+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76758+#define atomic_dec_unchecked(v) atomic_dec(v)
76759+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76760+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76761+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76762+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76763+
76764+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76765+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76766+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76767+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76768+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76769+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76770+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76771+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76772+#endif
76773+
76774 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76775diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76776index 33bd2de..f31bff97 100644
76777--- a/include/asm-generic/atomic.h
76778+++ b/include/asm-generic/atomic.h
76779@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76780 * Atomically clears the bits set in @mask from @v
76781 */
76782 #ifndef atomic_clear_mask
76783-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76784+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76785 {
76786 unsigned long flags;
76787
76788diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76789index b18ce4f..2ee2843 100644
76790--- a/include/asm-generic/atomic64.h
76791+++ b/include/asm-generic/atomic64.h
76792@@ -16,6 +16,8 @@ typedef struct {
76793 long long counter;
76794 } atomic64_t;
76795
76796+typedef atomic64_t atomic64_unchecked_t;
76797+
76798 #define ATOMIC64_INIT(i) { (i) }
76799
76800 extern long long atomic64_read(const atomic64_t *v);
76801@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76802 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76803 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76804
76805+#define atomic64_read_unchecked(v) atomic64_read(v)
76806+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76807+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76808+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76809+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76810+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76811+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76812+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76813+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76814+
76815 #endif /* _ASM_GENERIC_ATOMIC64_H */
76816diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76817index a60a7cc..0fe12f2 100644
76818--- a/include/asm-generic/bitops/__fls.h
76819+++ b/include/asm-generic/bitops/__fls.h
76820@@ -9,7 +9,7 @@
76821 *
76822 * Undefined if no set bit exists, so code should check against 0 first.
76823 */
76824-static __always_inline unsigned long __fls(unsigned long word)
76825+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76826 {
76827 int num = BITS_PER_LONG - 1;
76828
76829diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76830index 0576d1f..dad6c71 100644
76831--- a/include/asm-generic/bitops/fls.h
76832+++ b/include/asm-generic/bitops/fls.h
76833@@ -9,7 +9,7 @@
76834 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76835 */
76836
76837-static __always_inline int fls(int x)
76838+static __always_inline int __intentional_overflow(-1) fls(int x)
76839 {
76840 int r = 32;
76841
76842diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76843index b097cf8..3d40e14 100644
76844--- a/include/asm-generic/bitops/fls64.h
76845+++ b/include/asm-generic/bitops/fls64.h
76846@@ -15,7 +15,7 @@
76847 * at position 64.
76848 */
76849 #if BITS_PER_LONG == 32
76850-static __always_inline int fls64(__u64 x)
76851+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76852 {
76853 __u32 h = x >> 32;
76854 if (h)
76855@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76856 return fls(x);
76857 }
76858 #elif BITS_PER_LONG == 64
76859-static __always_inline int fls64(__u64 x)
76860+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76861 {
76862 if (x == 0)
76863 return 0;
76864diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76865index 1bfcfe5..e04c5c9 100644
76866--- a/include/asm-generic/cache.h
76867+++ b/include/asm-generic/cache.h
76868@@ -6,7 +6,7 @@
76869 * cache lines need to provide their own cache.h.
76870 */
76871
76872-#define L1_CACHE_SHIFT 5
76873-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76874+#define L1_CACHE_SHIFT 5UL
76875+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76876
76877 #endif /* __ASM_GENERIC_CACHE_H */
76878diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76879index 0d68a1e..b74a761 100644
76880--- a/include/asm-generic/emergency-restart.h
76881+++ b/include/asm-generic/emergency-restart.h
76882@@ -1,7 +1,7 @@
76883 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76884 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76885
76886-static inline void machine_emergency_restart(void)
76887+static inline __noreturn void machine_emergency_restart(void)
76888 {
76889 machine_restart(NULL);
76890 }
76891diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76892index 90f99c7..00ce236 100644
76893--- a/include/asm-generic/kmap_types.h
76894+++ b/include/asm-generic/kmap_types.h
76895@@ -2,9 +2,9 @@
76896 #define _ASM_GENERIC_KMAP_TYPES_H
76897
76898 #ifdef __WITH_KM_FENCE
76899-# define KM_TYPE_NR 41
76900+# define KM_TYPE_NR 42
76901 #else
76902-# define KM_TYPE_NR 20
76903+# define KM_TYPE_NR 21
76904 #endif
76905
76906 #endif
76907diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76908index 9ceb03b..62b0b8f 100644
76909--- a/include/asm-generic/local.h
76910+++ b/include/asm-generic/local.h
76911@@ -23,24 +23,37 @@ typedef struct
76912 atomic_long_t a;
76913 } local_t;
76914
76915+typedef struct {
76916+ atomic_long_unchecked_t a;
76917+} local_unchecked_t;
76918+
76919 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76920
76921 #define local_read(l) atomic_long_read(&(l)->a)
76922+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76923 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76924+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76925 #define local_inc(l) atomic_long_inc(&(l)->a)
76926+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76927 #define local_dec(l) atomic_long_dec(&(l)->a)
76928+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76929 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76930+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76931 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76932+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76933
76934 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76935 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76936 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76937 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76938 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76939+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76940 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76941 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76942+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76943
76944 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76945+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76946 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76947 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76948 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76949diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76950index 725612b..9cc513a 100644
76951--- a/include/asm-generic/pgtable-nopmd.h
76952+++ b/include/asm-generic/pgtable-nopmd.h
76953@@ -1,14 +1,19 @@
76954 #ifndef _PGTABLE_NOPMD_H
76955 #define _PGTABLE_NOPMD_H
76956
76957-#ifndef __ASSEMBLY__
76958-
76959 #include <asm-generic/pgtable-nopud.h>
76960
76961-struct mm_struct;
76962-
76963 #define __PAGETABLE_PMD_FOLDED
76964
76965+#define PMD_SHIFT PUD_SHIFT
76966+#define PTRS_PER_PMD 1
76967+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76968+#define PMD_MASK (~(PMD_SIZE-1))
76969+
76970+#ifndef __ASSEMBLY__
76971+
76972+struct mm_struct;
76973+
76974 /*
76975 * Having the pmd type consist of a pud gets the size right, and allows
76976 * us to conceptually access the pud entry that this pmd is folded into
76977@@ -16,11 +21,6 @@ struct mm_struct;
76978 */
76979 typedef struct { pud_t pud; } pmd_t;
76980
76981-#define PMD_SHIFT PUD_SHIFT
76982-#define PTRS_PER_PMD 1
76983-#define PMD_SIZE (1UL << PMD_SHIFT)
76984-#define PMD_MASK (~(PMD_SIZE-1))
76985-
76986 /*
76987 * The "pud_xxx()" functions here are trivial for a folded two-level
76988 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76989diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76990index 810431d..0ec4804f 100644
76991--- a/include/asm-generic/pgtable-nopud.h
76992+++ b/include/asm-generic/pgtable-nopud.h
76993@@ -1,10 +1,15 @@
76994 #ifndef _PGTABLE_NOPUD_H
76995 #define _PGTABLE_NOPUD_H
76996
76997-#ifndef __ASSEMBLY__
76998-
76999 #define __PAGETABLE_PUD_FOLDED
77000
77001+#define PUD_SHIFT PGDIR_SHIFT
77002+#define PTRS_PER_PUD 1
77003+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77004+#define PUD_MASK (~(PUD_SIZE-1))
77005+
77006+#ifndef __ASSEMBLY__
77007+
77008 /*
77009 * Having the pud type consist of a pgd gets the size right, and allows
77010 * us to conceptually access the pgd entry that this pud is folded into
77011@@ -12,11 +17,6 @@
77012 */
77013 typedef struct { pgd_t pgd; } pud_t;
77014
77015-#define PUD_SHIFT PGDIR_SHIFT
77016-#define PTRS_PER_PUD 1
77017-#define PUD_SIZE (1UL << PUD_SHIFT)
77018-#define PUD_MASK (~(PUD_SIZE-1))
77019-
77020 /*
77021 * The "pgd_xxx()" functions here are trivial for a folded two-level
77022 * setup: the pud is never bad, and a pud always exists (as it's folded
77023@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77024 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77025
77026 #define pgd_populate(mm, pgd, pud) do { } while (0)
77027+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77028 /*
77029 * (puds are folded into pgds so this doesn't get actually called,
77030 * but the define is needed for a generic inline function.)
77031diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77032index 34c7bdc..38d4f3b 100644
77033--- a/include/asm-generic/pgtable.h
77034+++ b/include/asm-generic/pgtable.h
77035@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77036 }
77037 #endif /* CONFIG_NUMA_BALANCING */
77038
77039+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77040+#ifdef CONFIG_PAX_KERNEXEC
77041+#error KERNEXEC requires pax_open_kernel
77042+#else
77043+static inline unsigned long pax_open_kernel(void) { return 0; }
77044+#endif
77045+#endif
77046+
77047+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77048+#ifdef CONFIG_PAX_KERNEXEC
77049+#error KERNEXEC requires pax_close_kernel
77050+#else
77051+static inline unsigned long pax_close_kernel(void) { return 0; }
77052+#endif
77053+#endif
77054+
77055 #endif /* CONFIG_MMU */
77056
77057 #endif /* !__ASSEMBLY__ */
77058diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77059index 72d8803..cb9749c 100644
77060--- a/include/asm-generic/uaccess.h
77061+++ b/include/asm-generic/uaccess.h
77062@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77063 return __clear_user(to, n);
77064 }
77065
77066+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77067+#ifdef CONFIG_PAX_MEMORY_UDEREF
77068+#error UDEREF requires pax_open_userland
77069+#else
77070+static inline unsigned long pax_open_userland(void) { return 0; }
77071+#endif
77072+#endif
77073+
77074+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77075+#ifdef CONFIG_PAX_MEMORY_UDEREF
77076+#error UDEREF requires pax_close_userland
77077+#else
77078+static inline unsigned long pax_close_userland(void) { return 0; }
77079+#endif
77080+#endif
77081+
77082 #endif /* __ASM_GENERIC_UACCESS_H */
77083diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77084index bc2121f..2f41f9a 100644
77085--- a/include/asm-generic/vmlinux.lds.h
77086+++ b/include/asm-generic/vmlinux.lds.h
77087@@ -232,6 +232,7 @@
77088 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77089 VMLINUX_SYMBOL(__start_rodata) = .; \
77090 *(.rodata) *(.rodata.*) \
77091+ *(.data..read_only) \
77092 *(__vermagic) /* Kernel version magic */ \
77093 . = ALIGN(8); \
77094 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77095@@ -716,17 +717,18 @@
77096 * section in the linker script will go there too. @phdr should have
77097 * a leading colon.
77098 *
77099- * Note that this macros defines __per_cpu_load as an absolute symbol.
77100+ * Note that this macros defines per_cpu_load as an absolute symbol.
77101 * If there is no need to put the percpu section at a predetermined
77102 * address, use PERCPU_SECTION.
77103 */
77104 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77105- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77106- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77107+ per_cpu_load = .; \
77108+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77109 - LOAD_OFFSET) { \
77110+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77111 PERCPU_INPUT(cacheline) \
77112 } phdr \
77113- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77114+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77115
77116 /**
77117 * PERCPU_SECTION - define output section for percpu area, simple version
77118diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77119index e73c19e..5b89e00 100644
77120--- a/include/crypto/algapi.h
77121+++ b/include/crypto/algapi.h
77122@@ -34,7 +34,7 @@ struct crypto_type {
77123 unsigned int maskclear;
77124 unsigned int maskset;
77125 unsigned int tfmsize;
77126-};
77127+} __do_const;
77128
77129 struct crypto_instance {
77130 struct crypto_alg alg;
77131diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77132index 04a7f31..668d424 100644
77133--- a/include/drm/drmP.h
77134+++ b/include/drm/drmP.h
77135@@ -67,6 +67,7 @@
77136 #include <linux/workqueue.h>
77137 #include <linux/poll.h>
77138 #include <asm/pgalloc.h>
77139+#include <asm/local.h>
77140 #include <drm/drm.h>
77141 #include <drm/drm_sarea.h>
77142 #include <drm/drm_vma_manager.h>
77143@@ -297,10 +298,12 @@ do { \
77144 * \param cmd command.
77145 * \param arg argument.
77146 */
77147-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77148+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77149+ struct drm_file *file_priv);
77150+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77151 struct drm_file *file_priv);
77152
77153-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77154+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77155 unsigned long arg);
77156
77157 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77158@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77159 struct drm_ioctl_desc {
77160 unsigned int cmd;
77161 int flags;
77162- drm_ioctl_t *func;
77163+ drm_ioctl_t func;
77164 unsigned int cmd_drv;
77165 const char *name;
77166-};
77167+} __do_const;
77168
77169 /**
77170 * Creates a driver or general drm_ioctl_desc array entry for the given
77171@@ -1022,7 +1025,8 @@ struct drm_info_list {
77172 int (*show)(struct seq_file*, void*); /** show callback */
77173 u32 driver_features; /**< Required driver features for this entry */
77174 void *data;
77175-};
77176+} __do_const;
77177+typedef struct drm_info_list __no_const drm_info_list_no_const;
77178
77179 /**
77180 * debugfs node structure. This structure represents a debugfs file.
77181@@ -1106,7 +1110,7 @@ struct drm_device {
77182
77183 /** \name Usage Counters */
77184 /*@{ */
77185- int open_count; /**< Outstanding files open */
77186+ local_t open_count; /**< Outstanding files open */
77187 int buf_use; /**< Buffers in use -- cannot alloc */
77188 atomic_t buf_alloc; /**< Buffer allocation in progress */
77189 /*@} */
77190diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77191index b1388b5..e1d1163 100644
77192--- a/include/drm/drm_crtc_helper.h
77193+++ b/include/drm/drm_crtc_helper.h
77194@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77195 struct drm_connector *connector);
77196 /* disable encoder when not in use - more explicit than dpms off */
77197 void (*disable)(struct drm_encoder *encoder);
77198-};
77199+} __no_const;
77200
77201 /**
77202 * drm_connector_helper_funcs - helper operations for connectors
77203diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77204index 940ece4..8cb727f 100644
77205--- a/include/drm/i915_pciids.h
77206+++ b/include/drm/i915_pciids.h
77207@@ -37,7 +37,7 @@
77208 */
77209 #define INTEL_VGA_DEVICE(id, info) { \
77210 0x8086, id, \
77211- ~0, ~0, \
77212+ PCI_ANY_ID, PCI_ANY_ID, \
77213 0x030000, 0xff0000, \
77214 (unsigned long) info }
77215
77216diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77217index 72dcbe8..8db58d7 100644
77218--- a/include/drm/ttm/ttm_memory.h
77219+++ b/include/drm/ttm/ttm_memory.h
77220@@ -48,7 +48,7 @@
77221
77222 struct ttm_mem_shrink {
77223 int (*do_shrink) (struct ttm_mem_shrink *);
77224-};
77225+} __no_const;
77226
77227 /**
77228 * struct ttm_mem_global - Global memory accounting structure.
77229diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77230index 49a8284..9643967 100644
77231--- a/include/drm/ttm/ttm_page_alloc.h
77232+++ b/include/drm/ttm/ttm_page_alloc.h
77233@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77234 */
77235 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77236
77237+struct device;
77238 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77239 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77240
77241diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77242index 4b840e8..155d235 100644
77243--- a/include/keys/asymmetric-subtype.h
77244+++ b/include/keys/asymmetric-subtype.h
77245@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77246 /* Verify the signature on a key of this subtype (optional) */
77247 int (*verify_signature)(const struct key *key,
77248 const struct public_key_signature *sig);
77249-};
77250+} __do_const;
77251
77252 /**
77253 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77254diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77255index c1da539..1dcec55 100644
77256--- a/include/linux/atmdev.h
77257+++ b/include/linux/atmdev.h
77258@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77259 #endif
77260
77261 struct k_atm_aal_stats {
77262-#define __HANDLE_ITEM(i) atomic_t i
77263+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77264 __AAL_STAT_ITEMS
77265 #undef __HANDLE_ITEM
77266 };
77267@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77268 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77269 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77270 struct module *owner;
77271-};
77272+} __do_const ;
77273
77274 struct atmphy_ops {
77275 int (*start)(struct atm_dev *dev);
77276diff --git a/include/linux/audit.h b/include/linux/audit.h
77277index ec1464d..833274b 100644
77278--- a/include/linux/audit.h
77279+++ b/include/linux/audit.h
77280@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77281 extern unsigned int audit_serial(void);
77282 extern int auditsc_get_stamp(struct audit_context *ctx,
77283 struct timespec *t, unsigned int *serial);
77284-extern int audit_set_loginuid(kuid_t loginuid);
77285+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77286
77287 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77288 {
77289diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77290index b4a745d..e3c0942 100644
77291--- a/include/linux/binfmts.h
77292+++ b/include/linux/binfmts.h
77293@@ -45,7 +45,7 @@ struct linux_binprm {
77294 unsigned interp_data;
77295 unsigned long loader, exec;
77296 char tcomm[TASK_COMM_LEN];
77297-};
77298+} __randomize_layout;
77299
77300 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77301 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77302@@ -74,8 +74,10 @@ struct linux_binfmt {
77303 int (*load_binary)(struct linux_binprm *);
77304 int (*load_shlib)(struct file *);
77305 int (*core_dump)(struct coredump_params *cprm);
77306+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77307+ void (*handle_mmap)(struct file *);
77308 unsigned long min_coredump; /* minimal dump size */
77309-};
77310+} __do_const __randomize_layout;
77311
77312 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77313
77314diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77315index be5fd38..d71192a 100644
77316--- a/include/linux/bitops.h
77317+++ b/include/linux/bitops.h
77318@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77319 * @word: value to rotate
77320 * @shift: bits to roll
77321 */
77322-static inline __u32 rol32(__u32 word, unsigned int shift)
77323+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77324 {
77325 return (word << shift) | (word >> (32 - shift));
77326 }
77327@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77328 * @word: value to rotate
77329 * @shift: bits to roll
77330 */
77331-static inline __u32 ror32(__u32 word, unsigned int shift)
77332+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77333 {
77334 return (word >> shift) | (word << (32 - shift));
77335 }
77336@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77337 return (__s32)(value << shift) >> shift;
77338 }
77339
77340-static inline unsigned fls_long(unsigned long l)
77341+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77342 {
77343 if (sizeof(l) == 4)
77344 return fls(l);
77345diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77346index 4afa4f8..1ed7824 100644
77347--- a/include/linux/blkdev.h
77348+++ b/include/linux/blkdev.h
77349@@ -1572,7 +1572,7 @@ struct block_device_operations {
77350 /* this callback is with swap_lock and sometimes page table lock held */
77351 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77352 struct module *owner;
77353-};
77354+} __do_const;
77355
77356 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77357 unsigned long);
77358diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77359index afc1343..9735539 100644
77360--- a/include/linux/blktrace_api.h
77361+++ b/include/linux/blktrace_api.h
77362@@ -25,7 +25,7 @@ struct blk_trace {
77363 struct dentry *dropped_file;
77364 struct dentry *msg_file;
77365 struct list_head running_list;
77366- atomic_t dropped;
77367+ atomic_unchecked_t dropped;
77368 };
77369
77370 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77371diff --git a/include/linux/cache.h b/include/linux/cache.h
77372index 17e7e82..1d7da26 100644
77373--- a/include/linux/cache.h
77374+++ b/include/linux/cache.h
77375@@ -16,6 +16,14 @@
77376 #define __read_mostly
77377 #endif
77378
77379+#ifndef __read_only
77380+#ifdef CONFIG_PAX_KERNEXEC
77381+#error KERNEXEC requires __read_only
77382+#else
77383+#define __read_only __read_mostly
77384+#endif
77385+#endif
77386+
77387 #ifndef ____cacheline_aligned
77388 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77389 #endif
77390diff --git a/include/linux/capability.h b/include/linux/capability.h
77391index a6ee1f9..e1ca49d 100644
77392--- a/include/linux/capability.h
77393+++ b/include/linux/capability.h
77394@@ -212,8 +212,13 @@ extern bool capable(int cap);
77395 extern bool ns_capable(struct user_namespace *ns, int cap);
77396 extern bool inode_capable(const struct inode *inode, int cap);
77397 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77398+extern bool capable_nolog(int cap);
77399+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77400+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77401
77402 /* audit system wants to get cap info from files as well */
77403 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77404
77405+extern int is_privileged_binary(const struct dentry *dentry);
77406+
77407 #endif /* !_LINUX_CAPABILITY_H */
77408diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77409index 8609d57..86e4d79 100644
77410--- a/include/linux/cdrom.h
77411+++ b/include/linux/cdrom.h
77412@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77413
77414 /* driver specifications */
77415 const int capability; /* capability flags */
77416- int n_minors; /* number of active minor devices */
77417 /* handle uniform packets for scsi type devices (scsi,atapi) */
77418 int (*generic_packet) (struct cdrom_device_info *,
77419 struct packet_command *);
77420diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77421index 4ce9056..86caac6 100644
77422--- a/include/linux/cleancache.h
77423+++ b/include/linux/cleancache.h
77424@@ -31,7 +31,7 @@ struct cleancache_ops {
77425 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77426 void (*invalidate_inode)(int, struct cleancache_filekey);
77427 void (*invalidate_fs)(int);
77428-};
77429+} __no_const;
77430
77431 extern struct cleancache_ops *
77432 cleancache_register_ops(struct cleancache_ops *ops);
77433diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77434index 939533d..cf0a57c 100644
77435--- a/include/linux/clk-provider.h
77436+++ b/include/linux/clk-provider.h
77437@@ -166,6 +166,7 @@ struct clk_ops {
77438 unsigned long parent_accuracy);
77439 void (*init)(struct clk_hw *hw);
77440 };
77441+typedef struct clk_ops __no_const clk_ops_no_const;
77442
77443 /**
77444 * struct clk_init_data - holds init data that's common to all clocks and is
77445diff --git a/include/linux/compat.h b/include/linux/compat.h
77446index 3f448c6..df3ce1d 100644
77447--- a/include/linux/compat.h
77448+++ b/include/linux/compat.h
77449@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77450 compat_size_t __user *len_ptr);
77451
77452 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77453-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77454+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77455 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77456 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77457 compat_ssize_t msgsz, int msgflg);
77458@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77459 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77460 compat_ulong_t addr, compat_ulong_t data);
77461 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77462- compat_long_t addr, compat_long_t data);
77463+ compat_ulong_t addr, compat_ulong_t data);
77464
77465 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77466 /*
77467diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77468index 2507fd2..55203f8 100644
77469--- a/include/linux/compiler-gcc4.h
77470+++ b/include/linux/compiler-gcc4.h
77471@@ -39,9 +39,34 @@
77472 # define __compiletime_warning(message) __attribute__((warning(message)))
77473 # define __compiletime_error(message) __attribute__((error(message)))
77474 #endif /* __CHECKER__ */
77475+
77476+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77477+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77478+#define __bos0(ptr) __bos((ptr), 0)
77479+#define __bos1(ptr) __bos((ptr), 1)
77480 #endif /* GCC_VERSION >= 40300 */
77481
77482 #if GCC_VERSION >= 40500
77483+
77484+#ifdef RANDSTRUCT_PLUGIN
77485+#define __randomize_layout __attribute__((randomize_layout))
77486+#define __no_randomize_layout __attribute__((no_randomize_layout))
77487+#endif
77488+
77489+#ifdef CONSTIFY_PLUGIN
77490+#define __no_const __attribute__((no_const))
77491+#define __do_const __attribute__((do_const))
77492+#endif
77493+
77494+#ifdef SIZE_OVERFLOW_PLUGIN
77495+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77496+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77497+#endif
77498+
77499+#ifdef LATENT_ENTROPY_PLUGIN
77500+#define __latent_entropy __attribute__((latent_entropy))
77501+#endif
77502+
77503 /*
77504 * Mark a position in code as unreachable. This can be used to
77505 * suppress control flow warnings after asm blocks that transfer
77506diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77507index 2472740..4857634 100644
77508--- a/include/linux/compiler.h
77509+++ b/include/linux/compiler.h
77510@@ -5,11 +5,14 @@
77511
77512 #ifdef __CHECKER__
77513 # define __user __attribute__((noderef, address_space(1)))
77514+# define __force_user __force __user
77515 # define __kernel __attribute__((address_space(0)))
77516+# define __force_kernel __force __kernel
77517 # define __safe __attribute__((safe))
77518 # define __force __attribute__((force))
77519 # define __nocast __attribute__((nocast))
77520 # define __iomem __attribute__((noderef, address_space(2)))
77521+# define __force_iomem __force __iomem
77522 # define __must_hold(x) __attribute__((context(x,1,1)))
77523 # define __acquires(x) __attribute__((context(x,0,1)))
77524 # define __releases(x) __attribute__((context(x,1,0)))
77525@@ -17,20 +20,37 @@
77526 # define __release(x) __context__(x,-1)
77527 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77528 # define __percpu __attribute__((noderef, address_space(3)))
77529+# define __force_percpu __force __percpu
77530 #ifdef CONFIG_SPARSE_RCU_POINTER
77531 # define __rcu __attribute__((noderef, address_space(4)))
77532+# define __force_rcu __force __rcu
77533 #else
77534 # define __rcu
77535+# define __force_rcu
77536 #endif
77537 extern void __chk_user_ptr(const volatile void __user *);
77538 extern void __chk_io_ptr(const volatile void __iomem *);
77539 #else
77540-# define __user
77541-# define __kernel
77542+# ifdef CHECKER_PLUGIN
77543+//# define __user
77544+//# define __force_user
77545+//# define __kernel
77546+//# define __force_kernel
77547+# else
77548+# ifdef STRUCTLEAK_PLUGIN
77549+# define __user __attribute__((user))
77550+# else
77551+# define __user
77552+# endif
77553+# define __force_user
77554+# define __kernel
77555+# define __force_kernel
77556+# endif
77557 # define __safe
77558 # define __force
77559 # define __nocast
77560 # define __iomem
77561+# define __force_iomem
77562 # define __chk_user_ptr(x) (void)0
77563 # define __chk_io_ptr(x) (void)0
77564 # define __builtin_warning(x, y...) (1)
77565@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77566 # define __release(x) (void)0
77567 # define __cond_lock(x,c) (c)
77568 # define __percpu
77569+# define __force_percpu
77570 # define __rcu
77571+# define __force_rcu
77572 #endif
77573
77574 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77575@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77576 # define __attribute_const__ /* unimplemented */
77577 #endif
77578
77579+#ifndef __randomize_layout
77580+# define __randomize_layout
77581+#endif
77582+
77583+#ifndef __no_randomize_layout
77584+# define __no_randomize_layout
77585+#endif
77586+
77587+#ifndef __no_const
77588+# define __no_const
77589+#endif
77590+
77591+#ifndef __do_const
77592+# define __do_const
77593+#endif
77594+
77595+#ifndef __size_overflow
77596+# define __size_overflow(...)
77597+#endif
77598+
77599+#ifndef __intentional_overflow
77600+# define __intentional_overflow(...)
77601+#endif
77602+
77603+#ifndef __latent_entropy
77604+# define __latent_entropy
77605+#endif
77606+
77607 /*
77608 * Tell gcc if a function is cold. The compiler will assume any path
77609 * directly leading to the call is unlikely.
77610@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77611 #define __cold
77612 #endif
77613
77614+#ifndef __alloc_size
77615+#define __alloc_size(...)
77616+#endif
77617+
77618+#ifndef __bos
77619+#define __bos(ptr, arg)
77620+#endif
77621+
77622+#ifndef __bos0
77623+#define __bos0(ptr)
77624+#endif
77625+
77626+#ifndef __bos1
77627+#define __bos1(ptr)
77628+#endif
77629+
77630 /* Simple shorthand for a section definition */
77631 #ifndef __section
77632 # define __section(S) __attribute__ ((__section__(#S)))
77633@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77634 * use is to mediate communication between process-level code and irq/NMI
77635 * handlers, all running on the same CPU.
77636 */
77637-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77638+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77639+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77640
77641 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77642 #ifdef CONFIG_KPROBES
77643diff --git a/include/linux/completion.h b/include/linux/completion.h
77644index 5d5aaae..0ea9b84 100644
77645--- a/include/linux/completion.h
77646+++ b/include/linux/completion.h
77647@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77648
77649 extern void wait_for_completion(struct completion *);
77650 extern void wait_for_completion_io(struct completion *);
77651-extern int wait_for_completion_interruptible(struct completion *x);
77652-extern int wait_for_completion_killable(struct completion *x);
77653+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77654+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77655 extern unsigned long wait_for_completion_timeout(struct completion *x,
77656- unsigned long timeout);
77657+ unsigned long timeout) __intentional_overflow(-1);
77658 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77659- unsigned long timeout);
77660+ unsigned long timeout) __intentional_overflow(-1);
77661 extern long wait_for_completion_interruptible_timeout(
77662- struct completion *x, unsigned long timeout);
77663+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77664 extern long wait_for_completion_killable_timeout(
77665- struct completion *x, unsigned long timeout);
77666+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77667 extern bool try_wait_for_completion(struct completion *x);
77668 extern bool completion_done(struct completion *x);
77669
77670diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77671index 34025df..d94bbbc 100644
77672--- a/include/linux/configfs.h
77673+++ b/include/linux/configfs.h
77674@@ -125,7 +125,7 @@ struct configfs_attribute {
77675 const char *ca_name;
77676 struct module *ca_owner;
77677 umode_t ca_mode;
77678-};
77679+} __do_const;
77680
77681 /*
77682 * Users often need to create attribute structures for their configurable
77683diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77684index 4d89e0e..5281847 100644
77685--- a/include/linux/cpufreq.h
77686+++ b/include/linux/cpufreq.h
77687@@ -191,6 +191,7 @@ struct global_attr {
77688 ssize_t (*store)(struct kobject *a, struct attribute *b,
77689 const char *c, size_t count);
77690 };
77691+typedef struct global_attr __no_const global_attr_no_const;
77692
77693 #define define_one_global_ro(_name) \
77694 static struct global_attr _name = \
77695@@ -232,7 +233,7 @@ struct cpufreq_driver {
77696 bool boost_supported;
77697 bool boost_enabled;
77698 int (*set_boost) (int state);
77699-};
77700+} __do_const;
77701
77702 /* flags */
77703 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77704diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77705index 50fcbb0..9d2dbd9 100644
77706--- a/include/linux/cpuidle.h
77707+++ b/include/linux/cpuidle.h
77708@@ -50,7 +50,8 @@ struct cpuidle_state {
77709 int index);
77710
77711 int (*enter_dead) (struct cpuidle_device *dev, int index);
77712-};
77713+} __do_const;
77714+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77715
77716 /* Idle State Flags */
77717 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77718@@ -192,7 +193,7 @@ struct cpuidle_governor {
77719 void (*reflect) (struct cpuidle_device *dev, int index);
77720
77721 struct module *owner;
77722-};
77723+} __do_const;
77724
77725 #ifdef CONFIG_CPU_IDLE
77726 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77727diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77728index d08e4d2..95fad61 100644
77729--- a/include/linux/cpumask.h
77730+++ b/include/linux/cpumask.h
77731@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77732 }
77733
77734 /* Valid inputs for n are -1 and 0. */
77735-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77736+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77737 {
77738 return n+1;
77739 }
77740
77741-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77742+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77743 {
77744 return n+1;
77745 }
77746
77747-static inline unsigned int cpumask_next_and(int n,
77748+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77749 const struct cpumask *srcp,
77750 const struct cpumask *andp)
77751 {
77752@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77753 *
77754 * Returns >= nr_cpu_ids if no further cpus set.
77755 */
77756-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77757+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77758 {
77759 /* -1 is a legal arg here. */
77760 if (n != -1)
77761@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77762 *
77763 * Returns >= nr_cpu_ids if no further cpus unset.
77764 */
77765-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77766+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77767 {
77768 /* -1 is a legal arg here. */
77769 if (n != -1)
77770@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77771 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77772 }
77773
77774-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77775+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77776 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77777
77778 /**
77779diff --git a/include/linux/cred.h b/include/linux/cred.h
77780index 04421e8..117e17a 100644
77781--- a/include/linux/cred.h
77782+++ b/include/linux/cred.h
77783@@ -35,7 +35,7 @@ struct group_info {
77784 int nblocks;
77785 kgid_t small_block[NGROUPS_SMALL];
77786 kgid_t *blocks[0];
77787-};
77788+} __randomize_layout;
77789
77790 /**
77791 * get_group_info - Get a reference to a group info structure
77792@@ -136,7 +136,7 @@ struct cred {
77793 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77794 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77795 struct rcu_head rcu; /* RCU deletion hook */
77796-};
77797+} __randomize_layout;
77798
77799 extern void __put_cred(struct cred *);
77800 extern void exit_creds(struct task_struct *);
77801@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77802 static inline void validate_process_creds(void)
77803 {
77804 }
77805+static inline void validate_task_creds(struct task_struct *task)
77806+{
77807+}
77808 #endif
77809
77810 /**
77811diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77812index b92eadf..b4ecdc1 100644
77813--- a/include/linux/crypto.h
77814+++ b/include/linux/crypto.h
77815@@ -373,7 +373,7 @@ struct cipher_tfm {
77816 const u8 *key, unsigned int keylen);
77817 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77818 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77819-};
77820+} __no_const;
77821
77822 struct hash_tfm {
77823 int (*init)(struct hash_desc *desc);
77824@@ -394,13 +394,13 @@ struct compress_tfm {
77825 int (*cot_decompress)(struct crypto_tfm *tfm,
77826 const u8 *src, unsigned int slen,
77827 u8 *dst, unsigned int *dlen);
77828-};
77829+} __no_const;
77830
77831 struct rng_tfm {
77832 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77833 unsigned int dlen);
77834 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77835-};
77836+} __no_const;
77837
77838 #define crt_ablkcipher crt_u.ablkcipher
77839 #define crt_aead crt_u.aead
77840diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77841index 653589e..4ef254a 100644
77842--- a/include/linux/ctype.h
77843+++ b/include/linux/ctype.h
77844@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77845 * Fast implementation of tolower() for internal usage. Do not use in your
77846 * code.
77847 */
77848-static inline char _tolower(const char c)
77849+static inline unsigned char _tolower(const unsigned char c)
77850 {
77851 return c | 0x20;
77852 }
77853diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77854index bf72e9a..4ca7927 100644
77855--- a/include/linux/dcache.h
77856+++ b/include/linux/dcache.h
77857@@ -133,7 +133,7 @@ struct dentry {
77858 } d_u;
77859 struct list_head d_subdirs; /* our children */
77860 struct hlist_node d_alias; /* inode alias list */
77861-};
77862+} __randomize_layout;
77863
77864 /*
77865 * dentry->d_lock spinlock nesting subclasses:
77866diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77867index 7925bf0..d5143d2 100644
77868--- a/include/linux/decompress/mm.h
77869+++ b/include/linux/decompress/mm.h
77870@@ -77,7 +77,7 @@ static void free(void *where)
77871 * warnings when not needed (indeed large_malloc / large_free are not
77872 * needed by inflate */
77873
77874-#define malloc(a) kmalloc(a, GFP_KERNEL)
77875+#define malloc(a) kmalloc((a), GFP_KERNEL)
77876 #define free(a) kfree(a)
77877
77878 #define large_malloc(a) vmalloc(a)
77879diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77880index d48dc00..211ee54 100644
77881--- a/include/linux/devfreq.h
77882+++ b/include/linux/devfreq.h
77883@@ -114,7 +114,7 @@ struct devfreq_governor {
77884 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77885 int (*event_handler)(struct devfreq *devfreq,
77886 unsigned int event, void *data);
77887-};
77888+} __do_const;
77889
77890 /**
77891 * struct devfreq - Device devfreq structure
77892diff --git a/include/linux/device.h b/include/linux/device.h
77893index 952b010..d5b7691 100644
77894--- a/include/linux/device.h
77895+++ b/include/linux/device.h
77896@@ -310,7 +310,7 @@ struct subsys_interface {
77897 struct list_head node;
77898 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77899 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77900-};
77901+} __do_const;
77902
77903 int subsys_interface_register(struct subsys_interface *sif);
77904 void subsys_interface_unregister(struct subsys_interface *sif);
77905@@ -506,7 +506,7 @@ struct device_type {
77906 void (*release)(struct device *dev);
77907
77908 const struct dev_pm_ops *pm;
77909-};
77910+} __do_const;
77911
77912 /* interface for exporting device attributes */
77913 struct device_attribute {
77914@@ -516,11 +516,12 @@ struct device_attribute {
77915 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77916 const char *buf, size_t count);
77917 };
77918+typedef struct device_attribute __no_const device_attribute_no_const;
77919
77920 struct dev_ext_attribute {
77921 struct device_attribute attr;
77922 void *var;
77923-};
77924+} __do_const;
77925
77926 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77927 char *buf);
77928diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77929index fd4aee2..1f28db9 100644
77930--- a/include/linux/dma-mapping.h
77931+++ b/include/linux/dma-mapping.h
77932@@ -54,7 +54,7 @@ struct dma_map_ops {
77933 u64 (*get_required_mask)(struct device *dev);
77934 #endif
77935 int is_phys;
77936-};
77937+} __do_const;
77938
77939 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77940
77941diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77942index c5c92d5..6a5c2b2 100644
77943--- a/include/linux/dmaengine.h
77944+++ b/include/linux/dmaengine.h
77945@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
77946 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77947 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77948
77949-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77950+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77951 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77952-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77953+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77954 struct dma_pinned_list *pinned_list, struct page *page,
77955 unsigned int offset, size_t len);
77956
77957diff --git a/include/linux/efi.h b/include/linux/efi.h
77958index 0a819e7..8ed47f1 100644
77959--- a/include/linux/efi.h
77960+++ b/include/linux/efi.h
77961@@ -768,6 +768,7 @@ struct efivar_operations {
77962 efi_set_variable_t *set_variable;
77963 efi_query_variable_store_t *query_variable_store;
77964 };
77965+typedef struct efivar_operations __no_const efivar_operations_no_const;
77966
77967 struct efivars {
77968 /*
77969diff --git a/include/linux/elf.h b/include/linux/elf.h
77970index 67a5fa7..b817372 100644
77971--- a/include/linux/elf.h
77972+++ b/include/linux/elf.h
77973@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77974 #define elf_note elf32_note
77975 #define elf_addr_t Elf32_Off
77976 #define Elf_Half Elf32_Half
77977+#define elf_dyn Elf32_Dyn
77978
77979 #else
77980
77981@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77982 #define elf_note elf64_note
77983 #define elf_addr_t Elf64_Off
77984 #define Elf_Half Elf64_Half
77985+#define elf_dyn Elf64_Dyn
77986
77987 #endif
77988
77989diff --git a/include/linux/err.h b/include/linux/err.h
77990index 15f92e0..e825a8e 100644
77991--- a/include/linux/err.h
77992+++ b/include/linux/err.h
77993@@ -19,12 +19,12 @@
77994
77995 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77996
77997-static inline void * __must_check ERR_PTR(long error)
77998+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77999 {
78000 return (void *) error;
78001 }
78002
78003-static inline long __must_check PTR_ERR(__force const void *ptr)
78004+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78005 {
78006 return (long) ptr;
78007 }
78008diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78009index 21c59af..6057a03 100644
78010--- a/include/linux/extcon.h
78011+++ b/include/linux/extcon.h
78012@@ -135,7 +135,7 @@ struct extcon_dev {
78013 /* /sys/class/extcon/.../mutually_exclusive/... */
78014 struct attribute_group attr_g_muex;
78015 struct attribute **attrs_muex;
78016- struct device_attribute *d_attrs_muex;
78017+ device_attribute_no_const *d_attrs_muex;
78018 };
78019
78020 /**
78021diff --git a/include/linux/fb.h b/include/linux/fb.h
78022index fe6ac95..898d41d 100644
78023--- a/include/linux/fb.h
78024+++ b/include/linux/fb.h
78025@@ -304,7 +304,7 @@ struct fb_ops {
78026 /* called at KDB enter and leave time to prepare the console */
78027 int (*fb_debug_enter)(struct fb_info *info);
78028 int (*fb_debug_leave)(struct fb_info *info);
78029-};
78030+} __do_const;
78031
78032 #ifdef CONFIG_FB_TILEBLITTING
78033 #define FB_TILE_CURSOR_NONE 0
78034diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78035index 70e8e21..1939916 100644
78036--- a/include/linux/fdtable.h
78037+++ b/include/linux/fdtable.h
78038@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78039 void put_files_struct(struct files_struct *fs);
78040 void reset_files_struct(struct files_struct *);
78041 int unshare_files(struct files_struct **);
78042-struct files_struct *dup_fd(struct files_struct *, int *);
78043+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78044 void do_close_on_exec(struct files_struct *);
78045 int iterate_fd(struct files_struct *, unsigned,
78046 int (*)(const void *, struct file *, unsigned),
78047diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78048index 8293262..2b3b8bd 100644
78049--- a/include/linux/frontswap.h
78050+++ b/include/linux/frontswap.h
78051@@ -11,7 +11,7 @@ struct frontswap_ops {
78052 int (*load)(unsigned, pgoff_t, struct page *);
78053 void (*invalidate_page)(unsigned, pgoff_t);
78054 void (*invalidate_area)(unsigned);
78055-};
78056+} __no_const;
78057
78058 extern bool frontswap_enabled;
78059 extern struct frontswap_ops *
78060diff --git a/include/linux/fs.h b/include/linux/fs.h
78061index 23b2a35..8764ab7 100644
78062--- a/include/linux/fs.h
78063+++ b/include/linux/fs.h
78064@@ -426,7 +426,7 @@ struct address_space {
78065 spinlock_t private_lock; /* for use by the address_space */
78066 struct list_head private_list; /* ditto */
78067 void *private_data; /* ditto */
78068-} __attribute__((aligned(sizeof(long))));
78069+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78070 /*
78071 * On most architectures that alignment is already the case; but
78072 * must be enforced here for CRIS, to let the least significant bit
78073@@ -469,7 +469,7 @@ struct block_device {
78074 int bd_fsfreeze_count;
78075 /* Mutex for freeze */
78076 struct mutex bd_fsfreeze_mutex;
78077-};
78078+} __randomize_layout;
78079
78080 /*
78081 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78082@@ -613,7 +613,7 @@ struct inode {
78083 atomic_t i_readcount; /* struct files open RO */
78084 #endif
78085 void *i_private; /* fs or device private pointer */
78086-};
78087+} __randomize_layout;
78088
78089 static inline int inode_unhashed(struct inode *inode)
78090 {
78091@@ -812,7 +812,7 @@ struct file {
78092 #ifdef CONFIG_DEBUG_WRITECOUNT
78093 unsigned long f_mnt_write_state;
78094 #endif
78095-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78096+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78097
78098 struct file_handle {
78099 __u32 handle_bytes;
78100@@ -982,7 +982,7 @@ struct file_lock {
78101 int state; /* state of grant or error if -ve */
78102 } afs;
78103 } fl_u;
78104-};
78105+} __randomize_layout;
78106
78107 /* The following constant reflects the upper bound of the file/locking space */
78108 #ifndef OFFSET_MAX
78109@@ -1329,7 +1329,7 @@ struct super_block {
78110 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78111 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78112 struct rcu_head rcu;
78113-};
78114+} __randomize_layout;
78115
78116 extern struct timespec current_fs_time(struct super_block *sb);
78117
78118@@ -1551,7 +1551,8 @@ struct file_operations {
78119 long (*fallocate)(struct file *file, int mode, loff_t offset,
78120 loff_t len);
78121 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78122-};
78123+} __do_const __randomize_layout;
78124+typedef struct file_operations __no_const file_operations_no_const;
78125
78126 struct inode_operations {
78127 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78128@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78129 return !IS_DEADDIR(inode);
78130 }
78131
78132+static inline bool is_sidechannel_device(const struct inode *inode)
78133+{
78134+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78135+ umode_t mode = inode->i_mode;
78136+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78137+#else
78138+ return false;
78139+#endif
78140+}
78141+
78142 #endif /* _LINUX_FS_H */
78143diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78144index 0efc3e6..fd23610 100644
78145--- a/include/linux/fs_struct.h
78146+++ b/include/linux/fs_struct.h
78147@@ -6,13 +6,13 @@
78148 #include <linux/seqlock.h>
78149
78150 struct fs_struct {
78151- int users;
78152+ atomic_t users;
78153 spinlock_t lock;
78154 seqcount_t seq;
78155 int umask;
78156 int in_exec;
78157 struct path root, pwd;
78158-};
78159+} __randomize_layout;
78160
78161 extern struct kmem_cache *fs_cachep;
78162
78163diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78164index 7714849..a4a5c7a 100644
78165--- a/include/linux/fscache-cache.h
78166+++ b/include/linux/fscache-cache.h
78167@@ -113,7 +113,7 @@ struct fscache_operation {
78168 fscache_operation_release_t release;
78169 };
78170
78171-extern atomic_t fscache_op_debug_id;
78172+extern atomic_unchecked_t fscache_op_debug_id;
78173 extern void fscache_op_work_func(struct work_struct *work);
78174
78175 extern void fscache_enqueue_operation(struct fscache_operation *);
78176@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78177 INIT_WORK(&op->work, fscache_op_work_func);
78178 atomic_set(&op->usage, 1);
78179 op->state = FSCACHE_OP_ST_INITIALISED;
78180- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78181+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78182 op->processor = processor;
78183 op->release = release;
78184 INIT_LIST_HEAD(&op->pend_link);
78185diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78186index 115bb81..e7b812b 100644
78187--- a/include/linux/fscache.h
78188+++ b/include/linux/fscache.h
78189@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78190 * - this is mandatory for any object that may have data
78191 */
78192 void (*now_uncached)(void *cookie_netfs_data);
78193-};
78194+} __do_const;
78195
78196 /*
78197 * fscache cached network filesystem type
78198diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78199index 1c804b0..1432c2b 100644
78200--- a/include/linux/fsnotify.h
78201+++ b/include/linux/fsnotify.h
78202@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78203 struct inode *inode = file_inode(file);
78204 __u32 mask = FS_ACCESS;
78205
78206+ if (is_sidechannel_device(inode))
78207+ return;
78208+
78209 if (S_ISDIR(inode->i_mode))
78210 mask |= FS_ISDIR;
78211
78212@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78213 struct inode *inode = file_inode(file);
78214 __u32 mask = FS_MODIFY;
78215
78216+ if (is_sidechannel_device(inode))
78217+ return;
78218+
78219 if (S_ISDIR(inode->i_mode))
78220 mask |= FS_ISDIR;
78221
78222@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78223 */
78224 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78225 {
78226- return kstrdup(name, GFP_KERNEL);
78227+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78228 }
78229
78230 /*
78231diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78232index 9f3c275..8bdff5d 100644
78233--- a/include/linux/genhd.h
78234+++ b/include/linux/genhd.h
78235@@ -194,7 +194,7 @@ struct gendisk {
78236 struct kobject *slave_dir;
78237
78238 struct timer_rand_state *random;
78239- atomic_t sync_io; /* RAID */
78240+ atomic_unchecked_t sync_io; /* RAID */
78241 struct disk_events *ev;
78242 #ifdef CONFIG_BLK_DEV_INTEGRITY
78243 struct blk_integrity *integrity;
78244@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78245 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78246
78247 /* drivers/char/random.c */
78248-extern void add_disk_randomness(struct gendisk *disk);
78249+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78250 extern void rand_initialize_disk(struct gendisk *disk);
78251
78252 static inline sector_t get_start_sect(struct block_device *bdev)
78253diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78254index c0894dd..2fbf10c 100644
78255--- a/include/linux/genl_magic_func.h
78256+++ b/include/linux/genl_magic_func.h
78257@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78258 },
78259
78260 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78261-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78262+static struct genl_ops ZZZ_genl_ops[] = {
78263 #include GENL_MAGIC_INCLUDE_FILE
78264 };
78265
78266diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78267index 39b81dc..819dc51 100644
78268--- a/include/linux/gfp.h
78269+++ b/include/linux/gfp.h
78270@@ -36,6 +36,13 @@ struct vm_area_struct;
78271 #define ___GFP_NO_KSWAPD 0x400000u
78272 #define ___GFP_OTHER_NODE 0x800000u
78273 #define ___GFP_WRITE 0x1000000u
78274+
78275+#ifdef CONFIG_PAX_USERCOPY_SLABS
78276+#define ___GFP_USERCOPY 0x2000000u
78277+#else
78278+#define ___GFP_USERCOPY 0
78279+#endif
78280+
78281 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78282
78283 /*
78284@@ -93,6 +100,7 @@ struct vm_area_struct;
78285 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78286 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78287 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78288+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78289
78290 /*
78291 * This may seem redundant, but it's a way of annotating false positives vs.
78292@@ -100,7 +108,7 @@ struct vm_area_struct;
78293 */
78294 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78295
78296-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78297+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78298 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78299
78300 /* This equals 0, but use constants in case they ever change */
78301@@ -158,6 +166,8 @@ struct vm_area_struct;
78302 /* 4GB DMA on some platforms */
78303 #define GFP_DMA32 __GFP_DMA32
78304
78305+#define GFP_USERCOPY __GFP_USERCOPY
78306+
78307 /* Convert GFP flags to their corresponding migrate type */
78308 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78309 {
78310diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78311new file mode 100644
78312index 0000000..edb2cb6
78313--- /dev/null
78314+++ b/include/linux/gracl.h
78315@@ -0,0 +1,340 @@
78316+#ifndef GR_ACL_H
78317+#define GR_ACL_H
78318+
78319+#include <linux/grdefs.h>
78320+#include <linux/resource.h>
78321+#include <linux/capability.h>
78322+#include <linux/dcache.h>
78323+#include <asm/resource.h>
78324+
78325+/* Major status information */
78326+
78327+#define GR_VERSION "grsecurity 3.0"
78328+#define GRSECURITY_VERSION 0x3000
78329+
78330+enum {
78331+ GR_SHUTDOWN = 0,
78332+ GR_ENABLE = 1,
78333+ GR_SPROLE = 2,
78334+ GR_OLDRELOAD = 3,
78335+ GR_SEGVMOD = 4,
78336+ GR_STATUS = 5,
78337+ GR_UNSPROLE = 6,
78338+ GR_PASSSET = 7,
78339+ GR_SPROLEPAM = 8,
78340+ GR_RELOAD = 9,
78341+};
78342+
78343+/* Password setup definitions
78344+ * kernel/grhash.c */
78345+enum {
78346+ GR_PW_LEN = 128,
78347+ GR_SALT_LEN = 16,
78348+ GR_SHA_LEN = 32,
78349+};
78350+
78351+enum {
78352+ GR_SPROLE_LEN = 64,
78353+};
78354+
78355+enum {
78356+ GR_NO_GLOB = 0,
78357+ GR_REG_GLOB,
78358+ GR_CREATE_GLOB
78359+};
78360+
78361+#define GR_NLIMITS 32
78362+
78363+/* Begin Data Structures */
78364+
78365+struct sprole_pw {
78366+ unsigned char *rolename;
78367+ unsigned char salt[GR_SALT_LEN];
78368+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78369+};
78370+
78371+struct name_entry {
78372+ __u32 key;
78373+ ino_t inode;
78374+ dev_t device;
78375+ char *name;
78376+ __u16 len;
78377+ __u8 deleted;
78378+ struct name_entry *prev;
78379+ struct name_entry *next;
78380+};
78381+
78382+struct inodev_entry {
78383+ struct name_entry *nentry;
78384+ struct inodev_entry *prev;
78385+ struct inodev_entry *next;
78386+};
78387+
78388+struct acl_role_db {
78389+ struct acl_role_label **r_hash;
78390+ __u32 r_size;
78391+};
78392+
78393+struct inodev_db {
78394+ struct inodev_entry **i_hash;
78395+ __u32 i_size;
78396+};
78397+
78398+struct name_db {
78399+ struct name_entry **n_hash;
78400+ __u32 n_size;
78401+};
78402+
78403+struct crash_uid {
78404+ uid_t uid;
78405+ unsigned long expires;
78406+};
78407+
78408+struct gr_hash_struct {
78409+ void **table;
78410+ void **nametable;
78411+ void *first;
78412+ __u32 table_size;
78413+ __u32 used_size;
78414+ int type;
78415+};
78416+
78417+/* Userspace Grsecurity ACL data structures */
78418+
78419+struct acl_subject_label {
78420+ char *filename;
78421+ ino_t inode;
78422+ dev_t device;
78423+ __u32 mode;
78424+ kernel_cap_t cap_mask;
78425+ kernel_cap_t cap_lower;
78426+ kernel_cap_t cap_invert_audit;
78427+
78428+ struct rlimit res[GR_NLIMITS];
78429+ __u32 resmask;
78430+
78431+ __u8 user_trans_type;
78432+ __u8 group_trans_type;
78433+ uid_t *user_transitions;
78434+ gid_t *group_transitions;
78435+ __u16 user_trans_num;
78436+ __u16 group_trans_num;
78437+
78438+ __u32 sock_families[2];
78439+ __u32 ip_proto[8];
78440+ __u32 ip_type;
78441+ struct acl_ip_label **ips;
78442+ __u32 ip_num;
78443+ __u32 inaddr_any_override;
78444+
78445+ __u32 crashes;
78446+ unsigned long expires;
78447+
78448+ struct acl_subject_label *parent_subject;
78449+ struct gr_hash_struct *hash;
78450+ struct acl_subject_label *prev;
78451+ struct acl_subject_label *next;
78452+
78453+ struct acl_object_label **obj_hash;
78454+ __u32 obj_hash_size;
78455+ __u16 pax_flags;
78456+};
78457+
78458+struct role_allowed_ip {
78459+ __u32 addr;
78460+ __u32 netmask;
78461+
78462+ struct role_allowed_ip *prev;
78463+ struct role_allowed_ip *next;
78464+};
78465+
78466+struct role_transition {
78467+ char *rolename;
78468+
78469+ struct role_transition *prev;
78470+ struct role_transition *next;
78471+};
78472+
78473+struct acl_role_label {
78474+ char *rolename;
78475+ uid_t uidgid;
78476+ __u16 roletype;
78477+
78478+ __u16 auth_attempts;
78479+ unsigned long expires;
78480+
78481+ struct acl_subject_label *root_label;
78482+ struct gr_hash_struct *hash;
78483+
78484+ struct acl_role_label *prev;
78485+ struct acl_role_label *next;
78486+
78487+ struct role_transition *transitions;
78488+ struct role_allowed_ip *allowed_ips;
78489+ uid_t *domain_children;
78490+ __u16 domain_child_num;
78491+
78492+ umode_t umask;
78493+
78494+ struct acl_subject_label **subj_hash;
78495+ __u32 subj_hash_size;
78496+};
78497+
78498+struct user_acl_role_db {
78499+ struct acl_role_label **r_table;
78500+ __u32 num_pointers; /* Number of allocations to track */
78501+ __u32 num_roles; /* Number of roles */
78502+ __u32 num_domain_children; /* Number of domain children */
78503+ __u32 num_subjects; /* Number of subjects */
78504+ __u32 num_objects; /* Number of objects */
78505+};
78506+
78507+struct acl_object_label {
78508+ char *filename;
78509+ ino_t inode;
78510+ dev_t device;
78511+ __u32 mode;
78512+
78513+ struct acl_subject_label *nested;
78514+ struct acl_object_label *globbed;
78515+
78516+ /* next two structures not used */
78517+
78518+ struct acl_object_label *prev;
78519+ struct acl_object_label *next;
78520+};
78521+
78522+struct acl_ip_label {
78523+ char *iface;
78524+ __u32 addr;
78525+ __u32 netmask;
78526+ __u16 low, high;
78527+ __u8 mode;
78528+ __u32 type;
78529+ __u32 proto[8];
78530+
78531+ /* next two structures not used */
78532+
78533+ struct acl_ip_label *prev;
78534+ struct acl_ip_label *next;
78535+};
78536+
78537+struct gr_arg {
78538+ struct user_acl_role_db role_db;
78539+ unsigned char pw[GR_PW_LEN];
78540+ unsigned char salt[GR_SALT_LEN];
78541+ unsigned char sum[GR_SHA_LEN];
78542+ unsigned char sp_role[GR_SPROLE_LEN];
78543+ struct sprole_pw *sprole_pws;
78544+ dev_t segv_device;
78545+ ino_t segv_inode;
78546+ uid_t segv_uid;
78547+ __u16 num_sprole_pws;
78548+ __u16 mode;
78549+};
78550+
78551+struct gr_arg_wrapper {
78552+ struct gr_arg *arg;
78553+ __u32 version;
78554+ __u32 size;
78555+};
78556+
78557+struct subject_map {
78558+ struct acl_subject_label *user;
78559+ struct acl_subject_label *kernel;
78560+ struct subject_map *prev;
78561+ struct subject_map *next;
78562+};
78563+
78564+struct acl_subj_map_db {
78565+ struct subject_map **s_hash;
78566+ __u32 s_size;
78567+};
78568+
78569+struct gr_policy_state {
78570+ struct sprole_pw **acl_special_roles;
78571+ __u16 num_sprole_pws;
78572+ struct acl_role_label *kernel_role;
78573+ struct acl_role_label *role_list;
78574+ struct acl_role_label *default_role;
78575+ struct acl_role_db acl_role_set;
78576+ struct acl_subj_map_db subj_map_set;
78577+ struct name_db name_set;
78578+ struct inodev_db inodev_set;
78579+};
78580+
78581+struct gr_alloc_state {
78582+ unsigned long alloc_stack_next;
78583+ unsigned long alloc_stack_size;
78584+ void **alloc_stack;
78585+};
78586+
78587+struct gr_reload_state {
78588+ struct gr_policy_state oldpolicy;
78589+ struct gr_alloc_state oldalloc;
78590+ struct gr_policy_state newpolicy;
78591+ struct gr_alloc_state newalloc;
78592+ struct gr_policy_state *oldpolicy_ptr;
78593+ struct gr_alloc_state *oldalloc_ptr;
78594+ unsigned char oldmode;
78595+};
78596+
78597+/* End Data Structures Section */
78598+
78599+/* Hash functions generated by empirical testing by Brad Spengler
78600+ Makes good use of the low bits of the inode. Generally 0-1 times
78601+ in loop for successful match. 0-3 for unsuccessful match.
78602+ Shift/add algorithm with modulus of table size and an XOR*/
78603+
78604+static __inline__ unsigned int
78605+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78606+{
78607+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78608+}
78609+
78610+ static __inline__ unsigned int
78611+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78612+{
78613+ return ((const unsigned long)userp % sz);
78614+}
78615+
78616+static __inline__ unsigned int
78617+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78618+{
78619+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78620+}
78621+
78622+static __inline__ unsigned int
78623+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78624+{
78625+ return full_name_hash((const unsigned char *)name, len) % sz;
78626+}
78627+
78628+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78629+ subj = NULL; \
78630+ iter = 0; \
78631+ while (iter < role->subj_hash_size) { \
78632+ if (subj == NULL) \
78633+ subj = role->subj_hash[iter]; \
78634+ if (subj == NULL) { \
78635+ iter++; \
78636+ continue; \
78637+ }
78638+
78639+#define FOR_EACH_SUBJECT_END(subj,iter) \
78640+ subj = subj->next; \
78641+ if (subj == NULL) \
78642+ iter++; \
78643+ }
78644+
78645+
78646+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78647+ subj = role->hash->first; \
78648+ while (subj != NULL) {
78649+
78650+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78651+ subj = subj->next; \
78652+ }
78653+
78654+#endif
78655+
78656diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78657new file mode 100644
78658index 0000000..33ebd1f
78659--- /dev/null
78660+++ b/include/linux/gracl_compat.h
78661@@ -0,0 +1,156 @@
78662+#ifndef GR_ACL_COMPAT_H
78663+#define GR_ACL_COMPAT_H
78664+
78665+#include <linux/resource.h>
78666+#include <asm/resource.h>
78667+
78668+struct sprole_pw_compat {
78669+ compat_uptr_t rolename;
78670+ unsigned char salt[GR_SALT_LEN];
78671+ unsigned char sum[GR_SHA_LEN];
78672+};
78673+
78674+struct gr_hash_struct_compat {
78675+ compat_uptr_t table;
78676+ compat_uptr_t nametable;
78677+ compat_uptr_t first;
78678+ __u32 table_size;
78679+ __u32 used_size;
78680+ int type;
78681+};
78682+
78683+struct acl_subject_label_compat {
78684+ compat_uptr_t filename;
78685+ compat_ino_t inode;
78686+ __u32 device;
78687+ __u32 mode;
78688+ kernel_cap_t cap_mask;
78689+ kernel_cap_t cap_lower;
78690+ kernel_cap_t cap_invert_audit;
78691+
78692+ struct compat_rlimit res[GR_NLIMITS];
78693+ __u32 resmask;
78694+
78695+ __u8 user_trans_type;
78696+ __u8 group_trans_type;
78697+ compat_uptr_t user_transitions;
78698+ compat_uptr_t group_transitions;
78699+ __u16 user_trans_num;
78700+ __u16 group_trans_num;
78701+
78702+ __u32 sock_families[2];
78703+ __u32 ip_proto[8];
78704+ __u32 ip_type;
78705+ compat_uptr_t ips;
78706+ __u32 ip_num;
78707+ __u32 inaddr_any_override;
78708+
78709+ __u32 crashes;
78710+ compat_ulong_t expires;
78711+
78712+ compat_uptr_t parent_subject;
78713+ compat_uptr_t hash;
78714+ compat_uptr_t prev;
78715+ compat_uptr_t next;
78716+
78717+ compat_uptr_t obj_hash;
78718+ __u32 obj_hash_size;
78719+ __u16 pax_flags;
78720+};
78721+
78722+struct role_allowed_ip_compat {
78723+ __u32 addr;
78724+ __u32 netmask;
78725+
78726+ compat_uptr_t prev;
78727+ compat_uptr_t next;
78728+};
78729+
78730+struct role_transition_compat {
78731+ compat_uptr_t rolename;
78732+
78733+ compat_uptr_t prev;
78734+ compat_uptr_t next;
78735+};
78736+
78737+struct acl_role_label_compat {
78738+ compat_uptr_t rolename;
78739+ uid_t uidgid;
78740+ __u16 roletype;
78741+
78742+ __u16 auth_attempts;
78743+ compat_ulong_t expires;
78744+
78745+ compat_uptr_t root_label;
78746+ compat_uptr_t hash;
78747+
78748+ compat_uptr_t prev;
78749+ compat_uptr_t next;
78750+
78751+ compat_uptr_t transitions;
78752+ compat_uptr_t allowed_ips;
78753+ compat_uptr_t domain_children;
78754+ __u16 domain_child_num;
78755+
78756+ umode_t umask;
78757+
78758+ compat_uptr_t subj_hash;
78759+ __u32 subj_hash_size;
78760+};
78761+
78762+struct user_acl_role_db_compat {
78763+ compat_uptr_t r_table;
78764+ __u32 num_pointers;
78765+ __u32 num_roles;
78766+ __u32 num_domain_children;
78767+ __u32 num_subjects;
78768+ __u32 num_objects;
78769+};
78770+
78771+struct acl_object_label_compat {
78772+ compat_uptr_t filename;
78773+ compat_ino_t inode;
78774+ __u32 device;
78775+ __u32 mode;
78776+
78777+ compat_uptr_t nested;
78778+ compat_uptr_t globbed;
78779+
78780+ compat_uptr_t prev;
78781+ compat_uptr_t next;
78782+};
78783+
78784+struct acl_ip_label_compat {
78785+ compat_uptr_t iface;
78786+ __u32 addr;
78787+ __u32 netmask;
78788+ __u16 low, high;
78789+ __u8 mode;
78790+ __u32 type;
78791+ __u32 proto[8];
78792+
78793+ compat_uptr_t prev;
78794+ compat_uptr_t next;
78795+};
78796+
78797+struct gr_arg_compat {
78798+ struct user_acl_role_db_compat role_db;
78799+ unsigned char pw[GR_PW_LEN];
78800+ unsigned char salt[GR_SALT_LEN];
78801+ unsigned char sum[GR_SHA_LEN];
78802+ unsigned char sp_role[GR_SPROLE_LEN];
78803+ compat_uptr_t sprole_pws;
78804+ __u32 segv_device;
78805+ compat_ino_t segv_inode;
78806+ uid_t segv_uid;
78807+ __u16 num_sprole_pws;
78808+ __u16 mode;
78809+};
78810+
78811+struct gr_arg_wrapper_compat {
78812+ compat_uptr_t arg;
78813+ __u32 version;
78814+ __u32 size;
78815+};
78816+
78817+#endif
78818diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78819new file mode 100644
78820index 0000000..323ecf2
78821--- /dev/null
78822+++ b/include/linux/gralloc.h
78823@@ -0,0 +1,9 @@
78824+#ifndef __GRALLOC_H
78825+#define __GRALLOC_H
78826+
78827+void acl_free_all(void);
78828+int acl_alloc_stack_init(unsigned long size);
78829+void *acl_alloc(unsigned long len);
78830+void *acl_alloc_num(unsigned long num, unsigned long len);
78831+
78832+#endif
78833diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78834new file mode 100644
78835index 0000000..be66033
78836--- /dev/null
78837+++ b/include/linux/grdefs.h
78838@@ -0,0 +1,140 @@
78839+#ifndef GRDEFS_H
78840+#define GRDEFS_H
78841+
78842+/* Begin grsecurity status declarations */
78843+
78844+enum {
78845+ GR_READY = 0x01,
78846+ GR_STATUS_INIT = 0x00 // disabled state
78847+};
78848+
78849+/* Begin ACL declarations */
78850+
78851+/* Role flags */
78852+
78853+enum {
78854+ GR_ROLE_USER = 0x0001,
78855+ GR_ROLE_GROUP = 0x0002,
78856+ GR_ROLE_DEFAULT = 0x0004,
78857+ GR_ROLE_SPECIAL = 0x0008,
78858+ GR_ROLE_AUTH = 0x0010,
78859+ GR_ROLE_NOPW = 0x0020,
78860+ GR_ROLE_GOD = 0x0040,
78861+ GR_ROLE_LEARN = 0x0080,
78862+ GR_ROLE_TPE = 0x0100,
78863+ GR_ROLE_DOMAIN = 0x0200,
78864+ GR_ROLE_PAM = 0x0400,
78865+ GR_ROLE_PERSIST = 0x0800
78866+};
78867+
78868+/* ACL Subject and Object mode flags */
78869+enum {
78870+ GR_DELETED = 0x80000000
78871+};
78872+
78873+/* ACL Object-only mode flags */
78874+enum {
78875+ GR_READ = 0x00000001,
78876+ GR_APPEND = 0x00000002,
78877+ GR_WRITE = 0x00000004,
78878+ GR_EXEC = 0x00000008,
78879+ GR_FIND = 0x00000010,
78880+ GR_INHERIT = 0x00000020,
78881+ GR_SETID = 0x00000040,
78882+ GR_CREATE = 0x00000080,
78883+ GR_DELETE = 0x00000100,
78884+ GR_LINK = 0x00000200,
78885+ GR_AUDIT_READ = 0x00000400,
78886+ GR_AUDIT_APPEND = 0x00000800,
78887+ GR_AUDIT_WRITE = 0x00001000,
78888+ GR_AUDIT_EXEC = 0x00002000,
78889+ GR_AUDIT_FIND = 0x00004000,
78890+ GR_AUDIT_INHERIT= 0x00008000,
78891+ GR_AUDIT_SETID = 0x00010000,
78892+ GR_AUDIT_CREATE = 0x00020000,
78893+ GR_AUDIT_DELETE = 0x00040000,
78894+ GR_AUDIT_LINK = 0x00080000,
78895+ GR_PTRACERD = 0x00100000,
78896+ GR_NOPTRACE = 0x00200000,
78897+ GR_SUPPRESS = 0x00400000,
78898+ GR_NOLEARN = 0x00800000,
78899+ GR_INIT_TRANSFER= 0x01000000
78900+};
78901+
78902+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78903+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78904+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78905+
78906+/* ACL subject-only mode flags */
78907+enum {
78908+ GR_KILL = 0x00000001,
78909+ GR_VIEW = 0x00000002,
78910+ GR_PROTECTED = 0x00000004,
78911+ GR_LEARN = 0x00000008,
78912+ GR_OVERRIDE = 0x00000010,
78913+ /* just a placeholder, this mode is only used in userspace */
78914+ GR_DUMMY = 0x00000020,
78915+ GR_PROTSHM = 0x00000040,
78916+ GR_KILLPROC = 0x00000080,
78917+ GR_KILLIPPROC = 0x00000100,
78918+ /* just a placeholder, this mode is only used in userspace */
78919+ GR_NOTROJAN = 0x00000200,
78920+ GR_PROTPROCFD = 0x00000400,
78921+ GR_PROCACCT = 0x00000800,
78922+ GR_RELAXPTRACE = 0x00001000,
78923+ //GR_NESTED = 0x00002000,
78924+ GR_INHERITLEARN = 0x00004000,
78925+ GR_PROCFIND = 0x00008000,
78926+ GR_POVERRIDE = 0x00010000,
78927+ GR_KERNELAUTH = 0x00020000,
78928+ GR_ATSECURE = 0x00040000,
78929+ GR_SHMEXEC = 0x00080000
78930+};
78931+
78932+enum {
78933+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78934+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78935+ GR_PAX_ENABLE_MPROTECT = 0x0004,
78936+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
78937+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78938+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78939+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78940+ GR_PAX_DISABLE_MPROTECT = 0x0400,
78941+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
78942+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78943+};
78944+
78945+enum {
78946+ GR_ID_USER = 0x01,
78947+ GR_ID_GROUP = 0x02,
78948+};
78949+
78950+enum {
78951+ GR_ID_ALLOW = 0x01,
78952+ GR_ID_DENY = 0x02,
78953+};
78954+
78955+#define GR_CRASH_RES 31
78956+#define GR_UIDTABLE_MAX 500
78957+
78958+/* begin resource learning section */
78959+enum {
78960+ GR_RLIM_CPU_BUMP = 60,
78961+ GR_RLIM_FSIZE_BUMP = 50000,
78962+ GR_RLIM_DATA_BUMP = 10000,
78963+ GR_RLIM_STACK_BUMP = 1000,
78964+ GR_RLIM_CORE_BUMP = 10000,
78965+ GR_RLIM_RSS_BUMP = 500000,
78966+ GR_RLIM_NPROC_BUMP = 1,
78967+ GR_RLIM_NOFILE_BUMP = 5,
78968+ GR_RLIM_MEMLOCK_BUMP = 50000,
78969+ GR_RLIM_AS_BUMP = 500000,
78970+ GR_RLIM_LOCKS_BUMP = 2,
78971+ GR_RLIM_SIGPENDING_BUMP = 5,
78972+ GR_RLIM_MSGQUEUE_BUMP = 10000,
78973+ GR_RLIM_NICE_BUMP = 1,
78974+ GR_RLIM_RTPRIO_BUMP = 1,
78975+ GR_RLIM_RTTIME_BUMP = 1000000
78976+};
78977+
78978+#endif
78979diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78980new file mode 100644
78981index 0000000..d25522e
78982--- /dev/null
78983+++ b/include/linux/grinternal.h
78984@@ -0,0 +1,229 @@
78985+#ifndef __GRINTERNAL_H
78986+#define __GRINTERNAL_H
78987+
78988+#ifdef CONFIG_GRKERNSEC
78989+
78990+#include <linux/fs.h>
78991+#include <linux/mnt_namespace.h>
78992+#include <linux/nsproxy.h>
78993+#include <linux/gracl.h>
78994+#include <linux/grdefs.h>
78995+#include <linux/grmsg.h>
78996+
78997+void gr_add_learn_entry(const char *fmt, ...)
78998+ __attribute__ ((format (printf, 1, 2)));
78999+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79000+ const struct vfsmount *mnt);
79001+__u32 gr_check_create(const struct dentry *new_dentry,
79002+ const struct dentry *parent,
79003+ const struct vfsmount *mnt, const __u32 mode);
79004+int gr_check_protected_task(const struct task_struct *task);
79005+__u32 to_gr_audit(const __u32 reqmode);
79006+int gr_set_acls(const int type);
79007+int gr_acl_is_enabled(void);
79008+char gr_roletype_to_char(void);
79009+
79010+void gr_handle_alertkill(struct task_struct *task);
79011+char *gr_to_filename(const struct dentry *dentry,
79012+ const struct vfsmount *mnt);
79013+char *gr_to_filename1(const struct dentry *dentry,
79014+ const struct vfsmount *mnt);
79015+char *gr_to_filename2(const struct dentry *dentry,
79016+ const struct vfsmount *mnt);
79017+char *gr_to_filename3(const struct dentry *dentry,
79018+ const struct vfsmount *mnt);
79019+
79020+extern int grsec_enable_ptrace_readexec;
79021+extern int grsec_enable_harden_ptrace;
79022+extern int grsec_enable_link;
79023+extern int grsec_enable_fifo;
79024+extern int grsec_enable_execve;
79025+extern int grsec_enable_shm;
79026+extern int grsec_enable_execlog;
79027+extern int grsec_enable_signal;
79028+extern int grsec_enable_audit_ptrace;
79029+extern int grsec_enable_forkfail;
79030+extern int grsec_enable_time;
79031+extern int grsec_enable_rofs;
79032+extern int grsec_deny_new_usb;
79033+extern int grsec_enable_chroot_shmat;
79034+extern int grsec_enable_chroot_mount;
79035+extern int grsec_enable_chroot_double;
79036+extern int grsec_enable_chroot_pivot;
79037+extern int grsec_enable_chroot_chdir;
79038+extern int grsec_enable_chroot_chmod;
79039+extern int grsec_enable_chroot_mknod;
79040+extern int grsec_enable_chroot_fchdir;
79041+extern int grsec_enable_chroot_nice;
79042+extern int grsec_enable_chroot_execlog;
79043+extern int grsec_enable_chroot_caps;
79044+extern int grsec_enable_chroot_sysctl;
79045+extern int grsec_enable_chroot_unix;
79046+extern int grsec_enable_symlinkown;
79047+extern kgid_t grsec_symlinkown_gid;
79048+extern int grsec_enable_tpe;
79049+extern kgid_t grsec_tpe_gid;
79050+extern int grsec_enable_tpe_all;
79051+extern int grsec_enable_tpe_invert;
79052+extern int grsec_enable_socket_all;
79053+extern kgid_t grsec_socket_all_gid;
79054+extern int grsec_enable_socket_client;
79055+extern kgid_t grsec_socket_client_gid;
79056+extern int grsec_enable_socket_server;
79057+extern kgid_t grsec_socket_server_gid;
79058+extern kgid_t grsec_audit_gid;
79059+extern int grsec_enable_group;
79060+extern int grsec_enable_log_rwxmaps;
79061+extern int grsec_enable_mount;
79062+extern int grsec_enable_chdir;
79063+extern int grsec_resource_logging;
79064+extern int grsec_enable_blackhole;
79065+extern int grsec_lastack_retries;
79066+extern int grsec_enable_brute;
79067+extern int grsec_enable_harden_ipc;
79068+extern int grsec_lock;
79069+
79070+extern spinlock_t grsec_alert_lock;
79071+extern unsigned long grsec_alert_wtime;
79072+extern unsigned long grsec_alert_fyet;
79073+
79074+extern spinlock_t grsec_audit_lock;
79075+
79076+extern rwlock_t grsec_exec_file_lock;
79077+
79078+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79079+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79080+ (tsk)->exec_file->f_path.mnt) : "/")
79081+
79082+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79083+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79084+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79085+
79086+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79087+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79088+ (tsk)->exec_file->f_path.mnt) : "/")
79089+
79090+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79091+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79092+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79093+
79094+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79095+
79096+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79097+
79098+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79099+{
79100+ if (file1 && file2) {
79101+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79102+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79103+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79104+ return true;
79105+ }
79106+
79107+ return false;
79108+}
79109+
79110+#define GR_CHROOT_CAPS {{ \
79111+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79112+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79113+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79114+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79115+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79116+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79117+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79118+
79119+#define security_learn(normal_msg,args...) \
79120+({ \
79121+ read_lock(&grsec_exec_file_lock); \
79122+ gr_add_learn_entry(normal_msg "\n", ## args); \
79123+ read_unlock(&grsec_exec_file_lock); \
79124+})
79125+
79126+enum {
79127+ GR_DO_AUDIT,
79128+ GR_DONT_AUDIT,
79129+ /* used for non-audit messages that we shouldn't kill the task on */
79130+ GR_DONT_AUDIT_GOOD
79131+};
79132+
79133+enum {
79134+ GR_TTYSNIFF,
79135+ GR_RBAC,
79136+ GR_RBAC_STR,
79137+ GR_STR_RBAC,
79138+ GR_RBAC_MODE2,
79139+ GR_RBAC_MODE3,
79140+ GR_FILENAME,
79141+ GR_SYSCTL_HIDDEN,
79142+ GR_NOARGS,
79143+ GR_ONE_INT,
79144+ GR_ONE_INT_TWO_STR,
79145+ GR_ONE_STR,
79146+ GR_STR_INT,
79147+ GR_TWO_STR_INT,
79148+ GR_TWO_INT,
79149+ GR_TWO_U64,
79150+ GR_THREE_INT,
79151+ GR_FIVE_INT_TWO_STR,
79152+ GR_TWO_STR,
79153+ GR_THREE_STR,
79154+ GR_FOUR_STR,
79155+ GR_STR_FILENAME,
79156+ GR_FILENAME_STR,
79157+ GR_FILENAME_TWO_INT,
79158+ GR_FILENAME_TWO_INT_STR,
79159+ GR_TEXTREL,
79160+ GR_PTRACE,
79161+ GR_RESOURCE,
79162+ GR_CAP,
79163+ GR_SIG,
79164+ GR_SIG2,
79165+ GR_CRASH1,
79166+ GR_CRASH2,
79167+ GR_PSACCT,
79168+ GR_RWXMAP,
79169+ GR_RWXMAPVMA
79170+};
79171+
79172+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79173+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79174+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79175+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79176+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79177+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79178+#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)
79179+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79180+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79181+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79182+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79183+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79184+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79185+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79186+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79187+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79188+#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)
79189+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79190+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79191+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79192+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79193+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79194+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79195+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79196+#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)
79197+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79198+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79199+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79200+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79201+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79202+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79203+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79204+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79205+#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)
79206+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79207+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79208+
79209+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79210+
79211+#endif
79212+
79213+#endif
79214diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79215new file mode 100644
79216index 0000000..ba93581
79217--- /dev/null
79218+++ b/include/linux/grmsg.h
79219@@ -0,0 +1,116 @@
79220+#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"
79221+#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"
79222+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79223+#define GR_STOPMOD_MSG "denied modification of module state by "
79224+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79225+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79226+#define GR_IOPERM_MSG "denied use of ioperm() by "
79227+#define GR_IOPL_MSG "denied use of iopl() by "
79228+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79229+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79230+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79231+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79232+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79233+#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"
79234+#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"
79235+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79236+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79237+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79238+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79239+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79240+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79241+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79242+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79243+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79244+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79245+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79246+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79247+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79248+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79249+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79250+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79251+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79252+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79253+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79254+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79255+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79256+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79257+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79258+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79259+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79260+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79261+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79262+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79263+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79264+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79265+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79266+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79267+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79268+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79269+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79270+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79271+#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"
79272+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79273+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79274+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79275+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79276+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79277+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79278+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79279+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79280+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79281+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79282+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79283+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79284+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79285+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79286+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79287+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79288+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79289+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79290+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79291+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79292+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79293+#define GR_NICE_CHROOT_MSG "denied priority change by "
79294+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79295+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79296+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79297+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79298+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79299+#define GR_TIME_MSG "time set by "
79300+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79301+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79302+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79303+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79304+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79305+#define GR_BIND_MSG "denied bind() by "
79306+#define GR_CONNECT_MSG "denied connect() by "
79307+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79308+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79309+#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"
79310+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79311+#define GR_CAP_ACL_MSG "use of %s denied for "
79312+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79313+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79314+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79315+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79316+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79317+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79318+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79319+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79320+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79321+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79322+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79323+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79324+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79325+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79326+#define GR_VM86_MSG "denied use of vm86 by "
79327+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79328+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79329+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79330+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79331+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79332+#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 "
79333+#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 "
79334+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79335+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79336diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79337new file mode 100644
79338index 0000000..f2d8c6c
79339--- /dev/null
79340+++ b/include/linux/grsecurity.h
79341@@ -0,0 +1,248 @@
79342+#ifndef GR_SECURITY_H
79343+#define GR_SECURITY_H
79344+#include <linux/fs.h>
79345+#include <linux/fs_struct.h>
79346+#include <linux/binfmts.h>
79347+#include <linux/gracl.h>
79348+
79349+/* notify of brain-dead configs */
79350+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79351+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79352+#endif
79353+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79354+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79355+#endif
79356+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79357+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79358+#endif
79359+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79360+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79361+#endif
79362+
79363+int gr_handle_new_usb(void);
79364+
79365+void gr_handle_brute_attach(int dumpable);
79366+void gr_handle_brute_check(void);
79367+void gr_handle_kernel_exploit(void);
79368+
79369+char gr_roletype_to_char(void);
79370+
79371+int gr_proc_is_restricted(void);
79372+
79373+int gr_acl_enable_at_secure(void);
79374+
79375+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79376+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79377+
79378+void gr_del_task_from_ip_table(struct task_struct *p);
79379+
79380+int gr_pid_is_chrooted(struct task_struct *p);
79381+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79382+int gr_handle_chroot_nice(void);
79383+int gr_handle_chroot_sysctl(const int op);
79384+int gr_handle_chroot_setpriority(struct task_struct *p,
79385+ const int niceval);
79386+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79387+int gr_handle_chroot_chroot(const struct dentry *dentry,
79388+ const struct vfsmount *mnt);
79389+void gr_handle_chroot_chdir(const struct path *path);
79390+int gr_handle_chroot_chmod(const struct dentry *dentry,
79391+ const struct vfsmount *mnt, const int mode);
79392+int gr_handle_chroot_mknod(const struct dentry *dentry,
79393+ const struct vfsmount *mnt, const int mode);
79394+int gr_handle_chroot_mount(const struct dentry *dentry,
79395+ const struct vfsmount *mnt,
79396+ const char *dev_name);
79397+int gr_handle_chroot_pivot(void);
79398+int gr_handle_chroot_unix(const pid_t pid);
79399+
79400+int gr_handle_rawio(const struct inode *inode);
79401+
79402+void gr_handle_ioperm(void);
79403+void gr_handle_iopl(void);
79404+void gr_handle_msr_write(void);
79405+
79406+umode_t gr_acl_umask(void);
79407+
79408+int gr_tpe_allow(const struct file *file);
79409+
79410+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79411+void gr_clear_chroot_entries(struct task_struct *task);
79412+
79413+void gr_log_forkfail(const int retval);
79414+void gr_log_timechange(void);
79415+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79416+void gr_log_chdir(const struct dentry *dentry,
79417+ const struct vfsmount *mnt);
79418+void gr_log_chroot_exec(const struct dentry *dentry,
79419+ const struct vfsmount *mnt);
79420+void gr_log_remount(const char *devname, const int retval);
79421+void gr_log_unmount(const char *devname, const int retval);
79422+void gr_log_mount(const char *from, const char *to, const int retval);
79423+void gr_log_textrel(struct vm_area_struct *vma);
79424+void gr_log_ptgnustack(struct file *file);
79425+void gr_log_rwxmmap(struct file *file);
79426+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79427+
79428+int gr_handle_follow_link(const struct inode *parent,
79429+ const struct inode *inode,
79430+ const struct dentry *dentry,
79431+ const struct vfsmount *mnt);
79432+int gr_handle_fifo(const struct dentry *dentry,
79433+ const struct vfsmount *mnt,
79434+ const struct dentry *dir, const int flag,
79435+ const int acc_mode);
79436+int gr_handle_hardlink(const struct dentry *dentry,
79437+ const struct vfsmount *mnt,
79438+ struct inode *inode,
79439+ const int mode, const struct filename *to);
79440+
79441+int gr_is_capable(const int cap);
79442+int gr_is_capable_nolog(const int cap);
79443+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79444+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79445+
79446+void gr_copy_label(struct task_struct *tsk);
79447+void gr_handle_crash(struct task_struct *task, const int sig);
79448+int gr_handle_signal(const struct task_struct *p, const int sig);
79449+int gr_check_crash_uid(const kuid_t uid);
79450+int gr_check_protected_task(const struct task_struct *task);
79451+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79452+int gr_acl_handle_mmap(const struct file *file,
79453+ const unsigned long prot);
79454+int gr_acl_handle_mprotect(const struct file *file,
79455+ const unsigned long prot);
79456+int gr_check_hidden_task(const struct task_struct *tsk);
79457+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79458+ const struct vfsmount *mnt);
79459+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79460+ const struct vfsmount *mnt);
79461+__u32 gr_acl_handle_access(const struct dentry *dentry,
79462+ const struct vfsmount *mnt, const int fmode);
79463+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79464+ const struct vfsmount *mnt, umode_t *mode);
79465+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79466+ const struct vfsmount *mnt);
79467+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79468+ const struct vfsmount *mnt);
79469+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79470+ const struct vfsmount *mnt);
79471+int gr_handle_ptrace(struct task_struct *task, const long request);
79472+int gr_handle_proc_ptrace(struct task_struct *task);
79473+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79474+ const struct vfsmount *mnt);
79475+int gr_check_crash_exec(const struct file *filp);
79476+int gr_acl_is_enabled(void);
79477+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79478+ const kgid_t gid);
79479+int gr_set_proc_label(const struct dentry *dentry,
79480+ const struct vfsmount *mnt,
79481+ const int unsafe_flags);
79482+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79483+ const struct vfsmount *mnt);
79484+__u32 gr_acl_handle_open(const struct dentry *dentry,
79485+ const struct vfsmount *mnt, int acc_mode);
79486+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79487+ const struct dentry *p_dentry,
79488+ const struct vfsmount *p_mnt,
79489+ int open_flags, int acc_mode, const int imode);
79490+void gr_handle_create(const struct dentry *dentry,
79491+ const struct vfsmount *mnt);
79492+void gr_handle_proc_create(const struct dentry *dentry,
79493+ const struct inode *inode);
79494+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79495+ const struct dentry *parent_dentry,
79496+ const struct vfsmount *parent_mnt,
79497+ const int mode);
79498+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79499+ const struct dentry *parent_dentry,
79500+ const struct vfsmount *parent_mnt);
79501+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79502+ const struct vfsmount *mnt);
79503+void gr_handle_delete(const ino_t ino, const dev_t dev);
79504+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79505+ const struct vfsmount *mnt);
79506+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79507+ const struct dentry *parent_dentry,
79508+ const struct vfsmount *parent_mnt,
79509+ const struct filename *from);
79510+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79511+ const struct dentry *parent_dentry,
79512+ const struct vfsmount *parent_mnt,
79513+ const struct dentry *old_dentry,
79514+ const struct vfsmount *old_mnt, const struct filename *to);
79515+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79516+int gr_acl_handle_rename(struct dentry *new_dentry,
79517+ struct dentry *parent_dentry,
79518+ const struct vfsmount *parent_mnt,
79519+ struct dentry *old_dentry,
79520+ struct inode *old_parent_inode,
79521+ struct vfsmount *old_mnt, const struct filename *newname);
79522+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79523+ struct dentry *old_dentry,
79524+ struct dentry *new_dentry,
79525+ struct vfsmount *mnt, const __u8 replace);
79526+__u32 gr_check_link(const struct dentry *new_dentry,
79527+ const struct dentry *parent_dentry,
79528+ const struct vfsmount *parent_mnt,
79529+ const struct dentry *old_dentry,
79530+ const struct vfsmount *old_mnt);
79531+int gr_acl_handle_filldir(const struct file *file, const char *name,
79532+ const unsigned int namelen, const ino_t ino);
79533+
79534+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79535+ const struct vfsmount *mnt);
79536+void gr_acl_handle_exit(void);
79537+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79538+int gr_acl_handle_procpidmem(const struct task_struct *task);
79539+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79540+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79541+void gr_audit_ptrace(struct task_struct *task);
79542+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79543+void gr_put_exec_file(struct task_struct *task);
79544+
79545+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79546+
79547+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79548+extern void gr_learn_resource(const struct task_struct *task, const int res,
79549+ const unsigned long wanted, const int gt);
79550+#else
79551+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79552+ const unsigned long wanted, const int gt)
79553+{
79554+}
79555+#endif
79556+
79557+#ifdef CONFIG_GRKERNSEC_RESLOG
79558+extern void gr_log_resource(const struct task_struct *task, const int res,
79559+ const unsigned long wanted, const int gt);
79560+#else
79561+static inline void gr_log_resource(const struct task_struct *task, const int res,
79562+ const unsigned long wanted, const int gt)
79563+{
79564+}
79565+#endif
79566+
79567+#ifdef CONFIG_GRKERNSEC
79568+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79569+void gr_handle_vm86(void);
79570+void gr_handle_mem_readwrite(u64 from, u64 to);
79571+
79572+void gr_log_badprocpid(const char *entry);
79573+
79574+extern int grsec_enable_dmesg;
79575+extern int grsec_disable_privio;
79576+
79577+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79578+extern kgid_t grsec_proc_gid;
79579+#endif
79580+
79581+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79582+extern int grsec_enable_chroot_findtask;
79583+#endif
79584+#ifdef CONFIG_GRKERNSEC_SETXID
79585+extern int grsec_enable_setxid;
79586+#endif
79587+#endif
79588+
79589+#endif
79590diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79591new file mode 100644
79592index 0000000..e7ffaaf
79593--- /dev/null
79594+++ b/include/linux/grsock.h
79595@@ -0,0 +1,19 @@
79596+#ifndef __GRSOCK_H
79597+#define __GRSOCK_H
79598+
79599+extern void gr_attach_curr_ip(const struct sock *sk);
79600+extern int gr_handle_sock_all(const int family, const int type,
79601+ const int protocol);
79602+extern int gr_handle_sock_server(const struct sockaddr *sck);
79603+extern int gr_handle_sock_server_other(const struct sock *sck);
79604+extern int gr_handle_sock_client(const struct sockaddr *sck);
79605+extern int gr_search_connect(struct socket * sock,
79606+ struct sockaddr_in * addr);
79607+extern int gr_search_bind(struct socket * sock,
79608+ struct sockaddr_in * addr);
79609+extern int gr_search_listen(struct socket * sock);
79610+extern int gr_search_accept(struct socket * sock);
79611+extern int gr_search_socket(const int domain, const int type,
79612+ const int protocol);
79613+
79614+#endif
79615diff --git a/include/linux/hash.h b/include/linux/hash.h
79616index bd1754c..8240892 100644
79617--- a/include/linux/hash.h
79618+++ b/include/linux/hash.h
79619@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79620 struct fast_hash_ops {
79621 u32 (*hash)(const void *data, u32 len, u32 seed);
79622 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79623-};
79624+} __no_const;
79625
79626 /**
79627 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79628diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79629index 7fb31da..08b5114 100644
79630--- a/include/linux/highmem.h
79631+++ b/include/linux/highmem.h
79632@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79633 kunmap_atomic(kaddr);
79634 }
79635
79636+static inline void sanitize_highpage(struct page *page)
79637+{
79638+ void *kaddr;
79639+ unsigned long flags;
79640+
79641+ local_irq_save(flags);
79642+ kaddr = kmap_atomic(page);
79643+ clear_page(kaddr);
79644+ kunmap_atomic(kaddr);
79645+ local_irq_restore(flags);
79646+}
79647+
79648 static inline void zero_user_segments(struct page *page,
79649 unsigned start1, unsigned end1,
79650 unsigned start2, unsigned end2)
79651diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79652index 1c7b89a..7dda400 100644
79653--- a/include/linux/hwmon-sysfs.h
79654+++ b/include/linux/hwmon-sysfs.h
79655@@ -25,7 +25,8 @@
79656 struct sensor_device_attribute{
79657 struct device_attribute dev_attr;
79658 int index;
79659-};
79660+} __do_const;
79661+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79662 #define to_sensor_dev_attr(_dev_attr) \
79663 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79664
79665@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79666 struct device_attribute dev_attr;
79667 u8 index;
79668 u8 nr;
79669-};
79670+} __do_const;
79671+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79672 #define to_sensor_dev_attr_2(_dev_attr) \
79673 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79674
79675diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79676index deddeb8..bcaf62d 100644
79677--- a/include/linux/i2c.h
79678+++ b/include/linux/i2c.h
79679@@ -378,6 +378,7 @@ struct i2c_algorithm {
79680 /* To determine what the adapter supports */
79681 u32 (*functionality) (struct i2c_adapter *);
79682 };
79683+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79684
79685 /**
79686 * struct i2c_bus_recovery_info - I2C bus recovery information
79687diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79688index d23c3c2..eb63c81 100644
79689--- a/include/linux/i2o.h
79690+++ b/include/linux/i2o.h
79691@@ -565,7 +565,7 @@ struct i2o_controller {
79692 struct i2o_device *exec; /* Executive */
79693 #if BITS_PER_LONG == 64
79694 spinlock_t context_list_lock; /* lock for context_list */
79695- atomic_t context_list_counter; /* needed for unique contexts */
79696+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79697 struct list_head context_list; /* list of context id's
79698 and pointers */
79699 #endif
79700diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79701index aff7ad8..3942bbd 100644
79702--- a/include/linux/if_pppox.h
79703+++ b/include/linux/if_pppox.h
79704@@ -76,7 +76,7 @@ struct pppox_proto {
79705 int (*ioctl)(struct socket *sock, unsigned int cmd,
79706 unsigned long arg);
79707 struct module *owner;
79708-};
79709+} __do_const;
79710
79711 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79712 extern void unregister_pppox_proto(int proto_num);
79713diff --git a/include/linux/init.h b/include/linux/init.h
79714index e168880..d9b489d 100644
79715--- a/include/linux/init.h
79716+++ b/include/linux/init.h
79717@@ -37,9 +37,17 @@
79718 * section.
79719 */
79720
79721+#define add_init_latent_entropy __latent_entropy
79722+
79723+#ifdef CONFIG_MEMORY_HOTPLUG
79724+#define add_meminit_latent_entropy
79725+#else
79726+#define add_meminit_latent_entropy __latent_entropy
79727+#endif
79728+
79729 /* These are for everybody (although not all archs will actually
79730 discard it in modules) */
79731-#define __init __section(.init.text) __cold notrace
79732+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79733 #define __initdata __section(.init.data)
79734 #define __initconst __constsection(.init.rodata)
79735 #define __exitdata __section(.exit.data)
79736@@ -100,7 +108,7 @@
79737 #define __cpuexitconst
79738
79739 /* Used for MEMORY_HOTPLUG */
79740-#define __meminit __section(.meminit.text) __cold notrace
79741+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79742 #define __meminitdata __section(.meminit.data)
79743 #define __meminitconst __constsection(.meminit.rodata)
79744 #define __memexit __section(.memexit.text) __exitused __cold notrace
79745diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79746index 6df7f9f..d0bf699 100644
79747--- a/include/linux/init_task.h
79748+++ b/include/linux/init_task.h
79749@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79750
79751 #define INIT_TASK_COMM "swapper"
79752
79753+#ifdef CONFIG_X86
79754+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79755+#else
79756+#define INIT_TASK_THREAD_INFO
79757+#endif
79758+
79759 #ifdef CONFIG_RT_MUTEXES
79760 # define INIT_RT_MUTEXES(tsk) \
79761 .pi_waiters = RB_ROOT, \
79762@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79763 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79764 .comm = INIT_TASK_COMM, \
79765 .thread = INIT_THREAD, \
79766+ INIT_TASK_THREAD_INFO \
79767 .fs = &init_fs, \
79768 .files = &init_files, \
79769 .signal = &init_signals, \
79770diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79771index a2678d3..e411b1b 100644
79772--- a/include/linux/interrupt.h
79773+++ b/include/linux/interrupt.h
79774@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79775
79776 struct softirq_action
79777 {
79778- void (*action)(struct softirq_action *);
79779-};
79780+ void (*action)(void);
79781+} __no_const;
79782
79783 asmlinkage void do_softirq(void);
79784 asmlinkage void __do_softirq(void);
79785@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79786 }
79787 #endif
79788
79789-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79790+extern void open_softirq(int nr, void (*action)(void));
79791 extern void softirq_init(void);
79792 extern void __raise_softirq_irqoff(unsigned int nr);
79793
79794diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79795index b96a5b2..2732d1c 100644
79796--- a/include/linux/iommu.h
79797+++ b/include/linux/iommu.h
79798@@ -131,7 +131,7 @@ struct iommu_ops {
79799 u32 (*domain_get_windows)(struct iommu_domain *domain);
79800
79801 unsigned long pgsize_bitmap;
79802-};
79803+} __do_const;
79804
79805 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79806 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79807diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79808index 89b7c24..382af74 100644
79809--- a/include/linux/ioport.h
79810+++ b/include/linux/ioport.h
79811@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79812 int adjust_resource(struct resource *res, resource_size_t start,
79813 resource_size_t size);
79814 resource_size_t resource_alignment(struct resource *res);
79815-static inline resource_size_t resource_size(const struct resource *res)
79816+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79817 {
79818 return res->end - res->start + 1;
79819 }
79820diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79821index 35e7eca..6afb7ad 100644
79822--- a/include/linux/ipc_namespace.h
79823+++ b/include/linux/ipc_namespace.h
79824@@ -69,7 +69,7 @@ struct ipc_namespace {
79825 struct user_namespace *user_ns;
79826
79827 unsigned int proc_inum;
79828-};
79829+} __randomize_layout;
79830
79831 extern struct ipc_namespace init_ipc_ns;
79832 extern atomic_t nr_ipc_ns;
79833diff --git a/include/linux/irq.h b/include/linux/irq.h
79834index 7dc1003..407327b 100644
79835--- a/include/linux/irq.h
79836+++ b/include/linux/irq.h
79837@@ -338,7 +338,8 @@ struct irq_chip {
79838 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79839
79840 unsigned long flags;
79841-};
79842+} __do_const;
79843+typedef struct irq_chip __no_const irq_chip_no_const;
79844
79845 /*
79846 * irq_chip specific flags
79847diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79848index 0ceb389..eed3fb8 100644
79849--- a/include/linux/irqchip/arm-gic.h
79850+++ b/include/linux/irqchip/arm-gic.h
79851@@ -73,9 +73,11 @@
79852
79853 #ifndef __ASSEMBLY__
79854
79855+#include <linux/irq.h>
79856+
79857 struct device_node;
79858
79859-extern struct irq_chip gic_arch_extn;
79860+extern irq_chip_no_const gic_arch_extn;
79861
79862 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79863 u32 offset, struct device_node *);
79864diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79865index 1f44466..b481806 100644
79866--- a/include/linux/jiffies.h
79867+++ b/include/linux/jiffies.h
79868@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79869 /*
79870 * Convert various time units to each other:
79871 */
79872-extern unsigned int jiffies_to_msecs(const unsigned long j);
79873-extern unsigned int jiffies_to_usecs(const unsigned long j);
79874+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79875+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79876
79877-static inline u64 jiffies_to_nsecs(const unsigned long j)
79878+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79879 {
79880 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79881 }
79882
79883-extern unsigned long msecs_to_jiffies(const unsigned int m);
79884-extern unsigned long usecs_to_jiffies(const unsigned int u);
79885+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79886+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79887 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79888 extern void jiffies_to_timespec(const unsigned long jiffies,
79889- struct timespec *value);
79890-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79891+ struct timespec *value) __intentional_overflow(-1);
79892+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79893 extern void jiffies_to_timeval(const unsigned long jiffies,
79894 struct timeval *value);
79895
79896diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79897index 6883e19..e854fcb 100644
79898--- a/include/linux/kallsyms.h
79899+++ b/include/linux/kallsyms.h
79900@@ -15,7 +15,8 @@
79901
79902 struct module;
79903
79904-#ifdef CONFIG_KALLSYMS
79905+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79906+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79907 /* Lookup the address for a symbol. Returns 0 if not found. */
79908 unsigned long kallsyms_lookup_name(const char *name);
79909
79910@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79911 /* Stupid that this does nothing, but I didn't create this mess. */
79912 #define __print_symbol(fmt, addr)
79913 #endif /*CONFIG_KALLSYMS*/
79914+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79915+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79916+extern unsigned long kallsyms_lookup_name(const char *name);
79917+extern void __print_symbol(const char *fmt, unsigned long address);
79918+extern int sprint_backtrace(char *buffer, unsigned long address);
79919+extern int sprint_symbol(char *buffer, unsigned long address);
79920+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79921+const char *kallsyms_lookup(unsigned long addr,
79922+ unsigned long *symbolsize,
79923+ unsigned long *offset,
79924+ char **modname, char *namebuf);
79925+extern int kallsyms_lookup_size_offset(unsigned long addr,
79926+ unsigned long *symbolsize,
79927+ unsigned long *offset);
79928+#endif
79929
79930 /* This macro allows us to keep printk typechecking */
79931 static __printf(1, 2)
79932diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79933index a74c3a8..28d3f21 100644
79934--- a/include/linux/key-type.h
79935+++ b/include/linux/key-type.h
79936@@ -131,7 +131,7 @@ struct key_type {
79937 /* internal fields */
79938 struct list_head link; /* link in types list */
79939 struct lock_class_key lock_class; /* key->sem lock class */
79940-};
79941+} __do_const;
79942
79943 extern struct key_type key_type_keyring;
79944
79945diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79946index 6b06d37..c134867 100644
79947--- a/include/linux/kgdb.h
79948+++ b/include/linux/kgdb.h
79949@@ -52,7 +52,7 @@ extern int kgdb_connected;
79950 extern int kgdb_io_module_registered;
79951
79952 extern atomic_t kgdb_setting_breakpoint;
79953-extern atomic_t kgdb_cpu_doing_single_step;
79954+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79955
79956 extern struct task_struct *kgdb_usethread;
79957 extern struct task_struct *kgdb_contthread;
79958@@ -254,7 +254,7 @@ struct kgdb_arch {
79959 void (*correct_hw_break)(void);
79960
79961 void (*enable_nmi)(bool on);
79962-};
79963+} __do_const;
79964
79965 /**
79966 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79967@@ -279,7 +279,7 @@ struct kgdb_io {
79968 void (*pre_exception) (void);
79969 void (*post_exception) (void);
79970 int is_console;
79971-};
79972+} __do_const;
79973
79974 extern struct kgdb_arch arch_kgdb_ops;
79975
79976diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79977index 0555cc6..40116ce 100644
79978--- a/include/linux/kmod.h
79979+++ b/include/linux/kmod.h
79980@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79981 * usually useless though. */
79982 extern __printf(2, 3)
79983 int __request_module(bool wait, const char *name, ...);
79984+extern __printf(3, 4)
79985+int ___request_module(bool wait, char *param_name, const char *name, ...);
79986 #define request_module(mod...) __request_module(true, mod)
79987 #define request_module_nowait(mod...) __request_module(false, mod)
79988 #define try_then_request_module(x, mod...) \
79989@@ -57,6 +59,9 @@ struct subprocess_info {
79990 struct work_struct work;
79991 struct completion *complete;
79992 char *path;
79993+#ifdef CONFIG_GRKERNSEC
79994+ char *origpath;
79995+#endif
79996 char **argv;
79997 char **envp;
79998 int wait;
79999diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80000index 926afb6..58dd6e5 100644
80001--- a/include/linux/kobject.h
80002+++ b/include/linux/kobject.h
80003@@ -116,7 +116,7 @@ struct kobj_type {
80004 struct attribute **default_attrs;
80005 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80006 const void *(*namespace)(struct kobject *kobj);
80007-};
80008+} __do_const;
80009
80010 struct kobj_uevent_env {
80011 char *envp[UEVENT_NUM_ENVP];
80012@@ -139,6 +139,7 @@ struct kobj_attribute {
80013 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80014 const char *buf, size_t count);
80015 };
80016+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80017
80018 extern const struct sysfs_ops kobj_sysfs_ops;
80019
80020@@ -166,7 +167,7 @@ struct kset {
80021 spinlock_t list_lock;
80022 struct kobject kobj;
80023 const struct kset_uevent_ops *uevent_ops;
80024-};
80025+} __randomize_layout;
80026
80027 extern void kset_init(struct kset *kset);
80028 extern int __must_check kset_register(struct kset *kset);
80029diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80030index df32d25..fb52e27 100644
80031--- a/include/linux/kobject_ns.h
80032+++ b/include/linux/kobject_ns.h
80033@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80034 const void *(*netlink_ns)(struct sock *sk);
80035 const void *(*initial_ns)(void);
80036 void (*drop_ns)(void *);
80037-};
80038+} __do_const;
80039
80040 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80041 int kobj_ns_type_registered(enum kobj_ns_type type);
80042diff --git a/include/linux/kref.h b/include/linux/kref.h
80043index 484604d..0f6c5b6 100644
80044--- a/include/linux/kref.h
80045+++ b/include/linux/kref.h
80046@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80047 static inline int kref_sub(struct kref *kref, unsigned int count,
80048 void (*release)(struct kref *kref))
80049 {
80050- WARN_ON(release == NULL);
80051+ BUG_ON(release == NULL);
80052
80053 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80054 release(kref);
80055diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80056index b8e9a43..632678d 100644
80057--- a/include/linux/kvm_host.h
80058+++ b/include/linux/kvm_host.h
80059@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80060 {
80061 }
80062 #endif
80063-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80064+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80065 struct module *module);
80066 void kvm_exit(void);
80067
80068@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80069 struct kvm_guest_debug *dbg);
80070 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80071
80072-int kvm_arch_init(void *opaque);
80073+int kvm_arch_init(const void *opaque);
80074 void kvm_arch_exit(void);
80075
80076 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80077diff --git a/include/linux/libata.h b/include/linux/libata.h
80078index bec6dbe..2873d64 100644
80079--- a/include/linux/libata.h
80080+++ b/include/linux/libata.h
80081@@ -975,7 +975,7 @@ struct ata_port_operations {
80082 * fields must be pointers.
80083 */
80084 const struct ata_port_operations *inherits;
80085-};
80086+} __do_const;
80087
80088 struct ata_port_info {
80089 unsigned long flags;
80090diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80091index a6a42dd..6c5ebce 100644
80092--- a/include/linux/linkage.h
80093+++ b/include/linux/linkage.h
80094@@ -36,6 +36,7 @@
80095 #endif
80096
80097 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80098+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80099 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80100
80101 /*
80102diff --git a/include/linux/list.h b/include/linux/list.h
80103index ef95941..82db65a 100644
80104--- a/include/linux/list.h
80105+++ b/include/linux/list.h
80106@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80107 extern void list_del(struct list_head *entry);
80108 #endif
80109
80110+extern void __pax_list_add(struct list_head *new,
80111+ struct list_head *prev,
80112+ struct list_head *next);
80113+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80114+{
80115+ __pax_list_add(new, head, head->next);
80116+}
80117+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80118+{
80119+ __pax_list_add(new, head->prev, head);
80120+}
80121+extern void pax_list_del(struct list_head *entry);
80122+
80123 /**
80124 * list_replace - replace old entry by new one
80125 * @old : the element to be replaced
80126@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80127 INIT_LIST_HEAD(entry);
80128 }
80129
80130+extern void pax_list_del_init(struct list_head *entry);
80131+
80132 /**
80133 * list_move - delete from one list and add as another's head
80134 * @list: the entry to move
80135diff --git a/include/linux/math64.h b/include/linux/math64.h
80136index c45c089..298841c 100644
80137--- a/include/linux/math64.h
80138+++ b/include/linux/math64.h
80139@@ -15,7 +15,7 @@
80140 * This is commonly provided by 32bit archs to provide an optimized 64bit
80141 * divide.
80142 */
80143-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80144+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80145 {
80146 *remainder = dividend % divisor;
80147 return dividend / divisor;
80148@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80149 /**
80150 * div64_u64 - unsigned 64bit divide with 64bit divisor
80151 */
80152-static inline u64 div64_u64(u64 dividend, u64 divisor)
80153+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80154 {
80155 return dividend / divisor;
80156 }
80157@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80158 #define div64_ul(x, y) div_u64((x), (y))
80159
80160 #ifndef div_u64_rem
80161-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80162+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80163 {
80164 *remainder = do_div(dividend, divisor);
80165 return dividend;
80166@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80167 #endif
80168
80169 #ifndef div64_u64
80170-extern u64 div64_u64(u64 dividend, u64 divisor);
80171+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80172 #endif
80173
80174 #ifndef div64_s64
80175@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80176 * divide.
80177 */
80178 #ifndef div_u64
80179-static inline u64 div_u64(u64 dividend, u32 divisor)
80180+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80181 {
80182 u32 remainder;
80183 return div_u64_rem(dividend, divisor, &remainder);
80184diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80185index 5f1ea75..5125ac5 100644
80186--- a/include/linux/mempolicy.h
80187+++ b/include/linux/mempolicy.h
80188@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80189 }
80190
80191 #define vma_policy(vma) ((vma)->vm_policy)
80192+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80193+{
80194+ vma->vm_policy = pol;
80195+}
80196
80197 static inline void mpol_get(struct mempolicy *pol)
80198 {
80199@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80200 }
80201
80202 #define vma_policy(vma) NULL
80203+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80204+{
80205+}
80206
80207 static inline int
80208 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80209diff --git a/include/linux/mm.h b/include/linux/mm.h
80210index c1b7414..5ea2ad8 100644
80211--- a/include/linux/mm.h
80212+++ b/include/linux/mm.h
80213@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80214 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80215 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80216 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80217+
80218+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80219+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80220+#endif
80221+
80222 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80223
80224 #ifdef CONFIG_MEM_SOFT_DIRTY
80225@@ -229,8 +234,8 @@ struct vm_operations_struct {
80226 /* called by access_process_vm when get_user_pages() fails, typically
80227 * for use by special VMAs that can switch between memory and hardware
80228 */
80229- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80230- void *buf, int len, int write);
80231+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80232+ void *buf, size_t len, int write);
80233 #ifdef CONFIG_NUMA
80234 /*
80235 * set_policy() op must add a reference to any non-NULL @new mempolicy
80236@@ -260,6 +265,7 @@ struct vm_operations_struct {
80237 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80238 unsigned long size, pgoff_t pgoff);
80239 };
80240+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80241
80242 struct mmu_gather;
80243 struct inode;
80244@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80245 unsigned long *pfn);
80246 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80247 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80248-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80249- void *buf, int len, int write);
80250+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80251+ void *buf, size_t len, int write);
80252
80253 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80254 loff_t const holebegin, loff_t const holelen)
80255@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80256 }
80257 #endif
80258
80259-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80260-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80261- void *buf, int len, int write);
80262+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80263+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80264+ void *buf, size_t len, int write);
80265
80266 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80267 unsigned long start, unsigned long nr_pages,
80268@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80269 int set_page_dirty_lock(struct page *page);
80270 int clear_page_dirty_for_io(struct page *page);
80271
80272-/* Is the vma a continuation of the stack vma above it? */
80273-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80274-{
80275- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80276-}
80277-
80278-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80279- unsigned long addr)
80280-{
80281- return (vma->vm_flags & VM_GROWSDOWN) &&
80282- (vma->vm_start == addr) &&
80283- !vma_growsdown(vma->vm_prev, addr);
80284-}
80285-
80286-/* Is the vma a continuation of the stack vma below it? */
80287-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80288-{
80289- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80290-}
80291-
80292-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80293- unsigned long addr)
80294-{
80295- return (vma->vm_flags & VM_GROWSUP) &&
80296- (vma->vm_end == addr) &&
80297- !vma_growsup(vma->vm_next, addr);
80298-}
80299-
80300 extern pid_t
80301 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80302
80303@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80304 }
80305 #endif
80306
80307+#ifdef CONFIG_MMU
80308+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80309+#else
80310+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80311+{
80312+ return __pgprot(0);
80313+}
80314+#endif
80315+
80316 int vma_wants_writenotify(struct vm_area_struct *vma);
80317
80318 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80319@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80320 {
80321 return 0;
80322 }
80323+
80324+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80325+ unsigned long address)
80326+{
80327+ return 0;
80328+}
80329 #else
80330 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80331+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80332 #endif
80333
80334 #ifdef __PAGETABLE_PMD_FOLDED
80335@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80336 {
80337 return 0;
80338 }
80339+
80340+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80341+ unsigned long address)
80342+{
80343+ return 0;
80344+}
80345 #else
80346 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80347+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80348 #endif
80349
80350 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80351@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80352 NULL: pud_offset(pgd, address);
80353 }
80354
80355+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80356+{
80357+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80358+ NULL: pud_offset(pgd, address);
80359+}
80360+
80361 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80362 {
80363 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80364 NULL: pmd_offset(pud, address);
80365 }
80366+
80367+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80368+{
80369+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80370+ NULL: pmd_offset(pud, address);
80371+}
80372 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80373
80374 #if USE_SPLIT_PTE_PTLOCKS
80375@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80376 unsigned long addr, unsigned long len,
80377 unsigned long flags, struct page **pages);
80378
80379-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80380+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80381
80382 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80383 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80384@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80385 unsigned long len, unsigned long prot, unsigned long flags,
80386 unsigned long pgoff, unsigned long *populate);
80387 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80388+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80389
80390 #ifdef CONFIG_MMU
80391 extern int __mm_populate(unsigned long addr, unsigned long len,
80392@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80393 unsigned long high_limit;
80394 unsigned long align_mask;
80395 unsigned long align_offset;
80396+ unsigned long threadstack_offset;
80397 };
80398
80399-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80400-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80401+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80402+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80403
80404 /*
80405 * Search for an unmapped address range.
80406@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80407 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80408 */
80409 static inline unsigned long
80410-vm_unmapped_area(struct vm_unmapped_area_info *info)
80411+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80412 {
80413 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80414 return unmapped_area(info);
80415@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80416 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80417 struct vm_area_struct **pprev);
80418
80419+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80420+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80421+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80422+
80423 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80424 NULL if none. Assume start_addr < end_addr. */
80425 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80426@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80427 return vma;
80428 }
80429
80430-#ifdef CONFIG_MMU
80431-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80432-#else
80433-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80434-{
80435- return __pgprot(0);
80436-}
80437-#endif
80438-
80439 #ifdef CONFIG_NUMA_BALANCING
80440 unsigned long change_prot_numa(struct vm_area_struct *vma,
80441 unsigned long start, unsigned long end);
80442@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80443 static inline void vm_stat_account(struct mm_struct *mm,
80444 unsigned long flags, struct file *file, long pages)
80445 {
80446+
80447+#ifdef CONFIG_PAX_RANDMMAP
80448+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80449+#endif
80450+
80451 mm->total_vm += pages;
80452 }
80453 #endif /* CONFIG_PROC_FS */
80454@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80455 extern int sysctl_memory_failure_early_kill;
80456 extern int sysctl_memory_failure_recovery;
80457 extern void shake_page(struct page *p, int access);
80458-extern atomic_long_t num_poisoned_pages;
80459+extern atomic_long_unchecked_t num_poisoned_pages;
80460 extern int soft_offline_page(struct page *page, int flags);
80461
80462 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80463@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80464 static inline void setup_nr_node_ids(void) {}
80465 #endif
80466
80467+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80468+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80469+#else
80470+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80471+#endif
80472+
80473 #endif /* __KERNEL__ */
80474 #endif /* _LINUX_MM_H */
80475diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80476index 290901a..e99b01c 100644
80477--- a/include/linux/mm_types.h
80478+++ b/include/linux/mm_types.h
80479@@ -307,7 +307,9 @@ struct vm_area_struct {
80480 #ifdef CONFIG_NUMA
80481 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80482 #endif
80483-};
80484+
80485+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80486+} __randomize_layout;
80487
80488 struct core_thread {
80489 struct task_struct *task;
80490@@ -453,7 +455,25 @@ struct mm_struct {
80491 bool tlb_flush_pending;
80492 #endif
80493 struct uprobes_state uprobes_state;
80494-};
80495+
80496+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80497+ unsigned long pax_flags;
80498+#endif
80499+
80500+#ifdef CONFIG_PAX_DLRESOLVE
80501+ unsigned long call_dl_resolve;
80502+#endif
80503+
80504+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80505+ unsigned long call_syscall;
80506+#endif
80507+
80508+#ifdef CONFIG_PAX_ASLR
80509+ unsigned long delta_mmap; /* randomized offset */
80510+ unsigned long delta_stack; /* randomized offset */
80511+#endif
80512+
80513+} __randomize_layout;
80514
80515 static inline void mm_init_cpumask(struct mm_struct *mm)
80516 {
80517diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80518index c5d5278..f0b68c8 100644
80519--- a/include/linux/mmiotrace.h
80520+++ b/include/linux/mmiotrace.h
80521@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80522 /* Called from ioremap.c */
80523 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80524 void __iomem *addr);
80525-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80526+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80527
80528 /* For anyone to insert markers. Remember trailing newline. */
80529 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80530@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80531 {
80532 }
80533
80534-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80535+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80536 {
80537 }
80538
80539diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80540index 9b61b9b..52147d6b 100644
80541--- a/include/linux/mmzone.h
80542+++ b/include/linux/mmzone.h
80543@@ -396,7 +396,7 @@ struct zone {
80544 unsigned long flags; /* zone flags, see below */
80545
80546 /* Zone statistics */
80547- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80548+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80549
80550 /*
80551 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80552diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80553index 45e9214..a7227d6 100644
80554--- a/include/linux/mod_devicetable.h
80555+++ b/include/linux/mod_devicetable.h
80556@@ -13,7 +13,7 @@
80557 typedef unsigned long kernel_ulong_t;
80558 #endif
80559
80560-#define PCI_ANY_ID (~0)
80561+#define PCI_ANY_ID ((__u16)~0)
80562
80563 struct pci_device_id {
80564 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80565@@ -139,7 +139,7 @@ struct usb_device_id {
80566 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80567 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80568
80569-#define HID_ANY_ID (~0)
80570+#define HID_ANY_ID (~0U)
80571 #define HID_BUS_ANY 0xffff
80572 #define HID_GROUP_ANY 0x0000
80573
80574@@ -467,7 +467,7 @@ struct dmi_system_id {
80575 const char *ident;
80576 struct dmi_strmatch matches[4];
80577 void *driver_data;
80578-};
80579+} __do_const;
80580 /*
80581 * struct dmi_device_id appears during expansion of
80582 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80583diff --git a/include/linux/module.h b/include/linux/module.h
80584index eaf60ff..641979a 100644
80585--- a/include/linux/module.h
80586+++ b/include/linux/module.h
80587@@ -17,9 +17,11 @@
80588 #include <linux/moduleparam.h>
80589 #include <linux/tracepoint.h>
80590 #include <linux/export.h>
80591+#include <linux/fs.h>
80592
80593 #include <linux/percpu.h>
80594 #include <asm/module.h>
80595+#include <asm/pgtable.h>
80596
80597 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80598 #define MODULE_SIG_STRING "~Module signature appended~\n"
80599@@ -42,7 +44,7 @@ struct module_kobject {
80600 struct kobject *drivers_dir;
80601 struct module_param_attrs *mp;
80602 struct completion *kobj_completion;
80603-};
80604+} __randomize_layout;
80605
80606 struct module_attribute {
80607 struct attribute attr;
80608@@ -54,12 +56,13 @@ struct module_attribute {
80609 int (*test)(struct module *);
80610 void (*free)(struct module *);
80611 };
80612+typedef struct module_attribute __no_const module_attribute_no_const;
80613
80614 struct module_version_attribute {
80615 struct module_attribute mattr;
80616 const char *module_name;
80617 const char *version;
80618-} __attribute__ ((__aligned__(sizeof(void *))));
80619+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80620
80621 extern ssize_t __modver_version_show(struct module_attribute *,
80622 struct module_kobject *, char *);
80623@@ -238,7 +241,7 @@ struct module {
80624
80625 /* Sysfs stuff. */
80626 struct module_kobject mkobj;
80627- struct module_attribute *modinfo_attrs;
80628+ module_attribute_no_const *modinfo_attrs;
80629 const char *version;
80630 const char *srcversion;
80631 struct kobject *holders_dir;
80632@@ -287,19 +290,16 @@ struct module {
80633 int (*init)(void);
80634
80635 /* If this is non-NULL, vfree after init() returns */
80636- void *module_init;
80637+ void *module_init_rx, *module_init_rw;
80638
80639 /* Here is the actual code + data, vfree'd on unload. */
80640- void *module_core;
80641+ void *module_core_rx, *module_core_rw;
80642
80643 /* Here are the sizes of the init and core sections */
80644- unsigned int init_size, core_size;
80645+ unsigned int init_size_rw, core_size_rw;
80646
80647 /* The size of the executable code in each section. */
80648- unsigned int init_text_size, core_text_size;
80649-
80650- /* Size of RO sections of the module (text+rodata) */
80651- unsigned int init_ro_size, core_ro_size;
80652+ unsigned int init_size_rx, core_size_rx;
80653
80654 /* Arch-specific module values */
80655 struct mod_arch_specific arch;
80656@@ -355,6 +355,10 @@ struct module {
80657 #ifdef CONFIG_EVENT_TRACING
80658 struct ftrace_event_call **trace_events;
80659 unsigned int num_trace_events;
80660+ struct file_operations trace_id;
80661+ struct file_operations trace_enable;
80662+ struct file_operations trace_format;
80663+ struct file_operations trace_filter;
80664 #endif
80665 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80666 unsigned int num_ftrace_callsites;
80667@@ -378,7 +382,7 @@ struct module {
80668 ctor_fn_t *ctors;
80669 unsigned int num_ctors;
80670 #endif
80671-};
80672+} __randomize_layout;
80673 #ifndef MODULE_ARCH_INIT
80674 #define MODULE_ARCH_INIT {}
80675 #endif
80676@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80677 bool is_module_percpu_address(unsigned long addr);
80678 bool is_module_text_address(unsigned long addr);
80679
80680+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80681+{
80682+
80683+#ifdef CONFIG_PAX_KERNEXEC
80684+ if (ktla_ktva(addr) >= (unsigned long)start &&
80685+ ktla_ktva(addr) < (unsigned long)start + size)
80686+ return 1;
80687+#endif
80688+
80689+ return ((void *)addr >= start && (void *)addr < start + size);
80690+}
80691+
80692+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80693+{
80694+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80695+}
80696+
80697+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80698+{
80699+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80700+}
80701+
80702+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80703+{
80704+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80705+}
80706+
80707+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80708+{
80709+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80710+}
80711+
80712 static inline int within_module_core(unsigned long addr, const struct module *mod)
80713 {
80714- return (unsigned long)mod->module_core <= addr &&
80715- addr < (unsigned long)mod->module_core + mod->core_size;
80716+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80717 }
80718
80719 static inline int within_module_init(unsigned long addr, const struct module *mod)
80720 {
80721- return (unsigned long)mod->module_init <= addr &&
80722- addr < (unsigned long)mod->module_init + mod->init_size;
80723+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80724 }
80725
80726 /* Search for module by name: must hold module_mutex. */
80727diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80728index 560ca53..ef621ef 100644
80729--- a/include/linux/moduleloader.h
80730+++ b/include/linux/moduleloader.h
80731@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80732 sections. Returns NULL on failure. */
80733 void *module_alloc(unsigned long size);
80734
80735+#ifdef CONFIG_PAX_KERNEXEC
80736+void *module_alloc_exec(unsigned long size);
80737+#else
80738+#define module_alloc_exec(x) module_alloc(x)
80739+#endif
80740+
80741 /* Free memory returned from module_alloc. */
80742 void module_free(struct module *mod, void *module_region);
80743
80744+#ifdef CONFIG_PAX_KERNEXEC
80745+void module_free_exec(struct module *mod, void *module_region);
80746+#else
80747+#define module_free_exec(x, y) module_free((x), (y))
80748+#endif
80749+
80750 /*
80751 * Apply the given relocation to the (simplified) ELF. Return -error
80752 * or 0.
80753@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80754 unsigned int relsec,
80755 struct module *me)
80756 {
80757+#ifdef CONFIG_MODULES
80758 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80759+#endif
80760 return -ENOEXEC;
80761 }
80762 #endif
80763@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80764 unsigned int relsec,
80765 struct module *me)
80766 {
80767+#ifdef CONFIG_MODULES
80768 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80769+#endif
80770 return -ENOEXEC;
80771 }
80772 #endif
80773diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80774index c3eb102..073c4a6 100644
80775--- a/include/linux/moduleparam.h
80776+++ b/include/linux/moduleparam.h
80777@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80778 * @len is usually just sizeof(string).
80779 */
80780 #define module_param_string(name, string, len, perm) \
80781- static const struct kparam_string __param_string_##name \
80782+ static const struct kparam_string __param_string_##name __used \
80783 = { len, string }; \
80784 __module_param_call(MODULE_PARAM_PREFIX, name, \
80785 &param_ops_string, \
80786@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80787 */
80788 #define module_param_array_named(name, array, type, nump, perm) \
80789 param_check_##type(name, &(array)[0]); \
80790- static const struct kparam_array __param_arr_##name \
80791+ static const struct kparam_array __param_arr_##name __used \
80792 = { .max = ARRAY_SIZE(array), .num = nump, \
80793 .ops = &param_ops_##type, \
80794 .elemsize = sizeof(array[0]), .elem = array }; \
80795diff --git a/include/linux/mount.h b/include/linux/mount.h
80796index 839bac2..a96b37c 100644
80797--- a/include/linux/mount.h
80798+++ b/include/linux/mount.h
80799@@ -59,7 +59,7 @@ struct vfsmount {
80800 struct dentry *mnt_root; /* root of the mounted tree */
80801 struct super_block *mnt_sb; /* pointer to superblock */
80802 int mnt_flags;
80803-};
80804+} __randomize_layout;
80805
80806 struct file; /* forward dec */
80807
80808diff --git a/include/linux/namei.h b/include/linux/namei.h
80809index 492de72..1bddcd4 100644
80810--- a/include/linux/namei.h
80811+++ b/include/linux/namei.h
80812@@ -19,7 +19,7 @@ struct nameidata {
80813 unsigned seq, m_seq;
80814 int last_type;
80815 unsigned depth;
80816- char *saved_names[MAX_NESTED_LINKS + 1];
80817+ const char *saved_names[MAX_NESTED_LINKS + 1];
80818 };
80819
80820 /*
80821@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80822
80823 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80824
80825-static inline void nd_set_link(struct nameidata *nd, char *path)
80826+static inline void nd_set_link(struct nameidata *nd, const char *path)
80827 {
80828 nd->saved_names[nd->depth] = path;
80829 }
80830
80831-static inline char *nd_get_link(struct nameidata *nd)
80832+static inline const char *nd_get_link(const struct nameidata *nd)
80833 {
80834 return nd->saved_names[nd->depth];
80835 }
80836diff --git a/include/linux/net.h b/include/linux/net.h
80837index 94734a6..d8d6931 100644
80838--- a/include/linux/net.h
80839+++ b/include/linux/net.h
80840@@ -192,7 +192,7 @@ struct net_proto_family {
80841 int (*create)(struct net *net, struct socket *sock,
80842 int protocol, int kern);
80843 struct module *owner;
80844-};
80845+} __do_const;
80846
80847 struct iovec;
80848 struct kvec;
80849diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80850index daafd95..74c5d1e 100644
80851--- a/include/linux/netdevice.h
80852+++ b/include/linux/netdevice.h
80853@@ -1146,6 +1146,7 @@ struct net_device_ops {
80854 struct net_device *dev,
80855 void *priv);
80856 };
80857+typedef struct net_device_ops __no_const net_device_ops_no_const;
80858
80859 /*
80860 * The DEVICE structure.
80861@@ -1228,7 +1229,7 @@ struct net_device {
80862 int iflink;
80863
80864 struct net_device_stats stats;
80865- atomic_long_t rx_dropped; /* dropped packets by core network
80866+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80867 * Do not use this in drivers.
80868 */
80869
80870diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80871index 2077489..a15e561 100644
80872--- a/include/linux/netfilter.h
80873+++ b/include/linux/netfilter.h
80874@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80875 #endif
80876 /* Use the module struct to lock set/get code in place */
80877 struct module *owner;
80878-};
80879+} __do_const;
80880
80881 /* Function to register/unregister hook points. */
80882 int nf_register_hook(struct nf_hook_ops *reg);
80883diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80884index 28c7436..2d6156a 100644
80885--- a/include/linux/netfilter/nfnetlink.h
80886+++ b/include/linux/netfilter/nfnetlink.h
80887@@ -19,7 +19,7 @@ struct nfnl_callback {
80888 const struct nlattr * const cda[]);
80889 const struct nla_policy *policy; /* netlink attribute policy */
80890 const u_int16_t attr_count; /* number of nlattr's */
80891-};
80892+} __do_const;
80893
80894 struct nfnetlink_subsystem {
80895 const char *name;
80896diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80897new file mode 100644
80898index 0000000..33f4af8
80899--- /dev/null
80900+++ b/include/linux/netfilter/xt_gradm.h
80901@@ -0,0 +1,9 @@
80902+#ifndef _LINUX_NETFILTER_XT_GRADM_H
80903+#define _LINUX_NETFILTER_XT_GRADM_H 1
80904+
80905+struct xt_gradm_mtinfo {
80906+ __u16 flags;
80907+ __u16 invflags;
80908+};
80909+
80910+#endif
80911diff --git a/include/linux/nls.h b/include/linux/nls.h
80912index 520681b..1d67ed2 100644
80913--- a/include/linux/nls.h
80914+++ b/include/linux/nls.h
80915@@ -31,7 +31,7 @@ struct nls_table {
80916 const unsigned char *charset2upper;
80917 struct module *owner;
80918 struct nls_table *next;
80919-};
80920+} __do_const;
80921
80922 /* this value hold the maximum octet of charset */
80923 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80924diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80925index d14a4c3..a078786 100644
80926--- a/include/linux/notifier.h
80927+++ b/include/linux/notifier.h
80928@@ -54,7 +54,8 @@ struct notifier_block {
80929 notifier_fn_t notifier_call;
80930 struct notifier_block __rcu *next;
80931 int priority;
80932-};
80933+} __do_const;
80934+typedef struct notifier_block __no_const notifier_block_no_const;
80935
80936 struct atomic_notifier_head {
80937 spinlock_t lock;
80938diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80939index b2a0f15..4d7da32 100644
80940--- a/include/linux/oprofile.h
80941+++ b/include/linux/oprofile.h
80942@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80943 int oprofilefs_create_ro_ulong(struct dentry * root,
80944 char const * name, ulong * val);
80945
80946-/** Create a file for read-only access to an atomic_t. */
80947+/** Create a file for read-only access to an atomic_unchecked_t. */
80948 int oprofilefs_create_ro_atomic(struct dentry * root,
80949- char const * name, atomic_t * val);
80950+ char const * name, atomic_unchecked_t * val);
80951
80952 /** create a directory */
80953 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80954diff --git a/include/linux/padata.h b/include/linux/padata.h
80955index 4386946..f50c615 100644
80956--- a/include/linux/padata.h
80957+++ b/include/linux/padata.h
80958@@ -129,7 +129,7 @@ struct parallel_data {
80959 struct padata_serial_queue __percpu *squeue;
80960 atomic_t reorder_objects;
80961 atomic_t refcnt;
80962- atomic_t seq_nr;
80963+ atomic_unchecked_t seq_nr;
80964 struct padata_cpumask cpumask;
80965 spinlock_t lock ____cacheline_aligned;
80966 unsigned int processed;
80967diff --git a/include/linux/path.h b/include/linux/path.h
80968index d137218..be0c176 100644
80969--- a/include/linux/path.h
80970+++ b/include/linux/path.h
80971@@ -1,13 +1,15 @@
80972 #ifndef _LINUX_PATH_H
80973 #define _LINUX_PATH_H
80974
80975+#include <linux/compiler.h>
80976+
80977 struct dentry;
80978 struct vfsmount;
80979
80980 struct path {
80981 struct vfsmount *mnt;
80982 struct dentry *dentry;
80983-};
80984+} __randomize_layout;
80985
80986 extern void path_get(const struct path *);
80987 extern void path_put(const struct path *);
80988diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80989index 5f2e559..7d59314 100644
80990--- a/include/linux/pci_hotplug.h
80991+++ b/include/linux/pci_hotplug.h
80992@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80993 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80994 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80995 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80996-};
80997+} __do_const;
80998+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80999
81000 /**
81001 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81002diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81003index e56b07f..aef789b 100644
81004--- a/include/linux/perf_event.h
81005+++ b/include/linux/perf_event.h
81006@@ -328,8 +328,8 @@ struct perf_event {
81007
81008 enum perf_event_active_state state;
81009 unsigned int attach_state;
81010- local64_t count;
81011- atomic64_t child_count;
81012+ local64_t count; /* PaX: fix it one day */
81013+ atomic64_unchecked_t child_count;
81014
81015 /*
81016 * These are the total time in nanoseconds that the event
81017@@ -380,8 +380,8 @@ struct perf_event {
81018 * These accumulate total time (in nanoseconds) that children
81019 * events have been enabled and running, respectively.
81020 */
81021- atomic64_t child_total_time_enabled;
81022- atomic64_t child_total_time_running;
81023+ atomic64_unchecked_t child_total_time_enabled;
81024+ atomic64_unchecked_t child_total_time_running;
81025
81026 /*
81027 * Protect attach/detach and child_list:
81028@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81029 entry->ip[entry->nr++] = ip;
81030 }
81031
81032-extern int sysctl_perf_event_paranoid;
81033+extern int sysctl_perf_event_legitimately_concerned;
81034 extern int sysctl_perf_event_mlock;
81035 extern int sysctl_perf_event_sample_rate;
81036 extern int sysctl_perf_cpu_time_max_percent;
81037@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81038 loff_t *ppos);
81039
81040
81041+static inline bool perf_paranoid_any(void)
81042+{
81043+ return sysctl_perf_event_legitimately_concerned > 2;
81044+}
81045+
81046 static inline bool perf_paranoid_tracepoint_raw(void)
81047 {
81048- return sysctl_perf_event_paranoid > -1;
81049+ return sysctl_perf_event_legitimately_concerned > -1;
81050 }
81051
81052 static inline bool perf_paranoid_cpu(void)
81053 {
81054- return sysctl_perf_event_paranoid > 0;
81055+ return sysctl_perf_event_legitimately_concerned > 0;
81056 }
81057
81058 static inline bool perf_paranoid_kernel(void)
81059 {
81060- return sysctl_perf_event_paranoid > 1;
81061+ return sysctl_perf_event_legitimately_concerned > 1;
81062 }
81063
81064 extern void perf_event_init(void);
81065@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81066 struct device_attribute attr;
81067 u64 id;
81068 const char *event_str;
81069-};
81070+} __do_const;
81071
81072 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81073 static struct perf_pmu_events_attr _var = { \
81074diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81075index 7246ef3..1539ea4 100644
81076--- a/include/linux/pid_namespace.h
81077+++ b/include/linux/pid_namespace.h
81078@@ -43,7 +43,7 @@ struct pid_namespace {
81079 int hide_pid;
81080 int reboot; /* group exit code if this pidns was rebooted */
81081 unsigned int proc_inum;
81082-};
81083+} __randomize_layout;
81084
81085 extern struct pid_namespace init_pid_ns;
81086
81087diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81088index ab57526..94598804 100644
81089--- a/include/linux/pipe_fs_i.h
81090+++ b/include/linux/pipe_fs_i.h
81091@@ -47,10 +47,10 @@ struct pipe_inode_info {
81092 struct mutex mutex;
81093 wait_queue_head_t wait;
81094 unsigned int nrbufs, curbuf, buffers;
81095- unsigned int readers;
81096- unsigned int writers;
81097- unsigned int files;
81098- unsigned int waiting_writers;
81099+ atomic_t readers;
81100+ atomic_t writers;
81101+ atomic_t files;
81102+ atomic_t waiting_writers;
81103 unsigned int r_counter;
81104 unsigned int w_counter;
81105 struct page *tmp_page;
81106diff --git a/include/linux/pm.h b/include/linux/pm.h
81107index 8c6583a..febb84c 100644
81108--- a/include/linux/pm.h
81109+++ b/include/linux/pm.h
81110@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81111 struct dev_pm_domain {
81112 struct dev_pm_ops ops;
81113 };
81114+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81115
81116 /*
81117 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81118diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81119index 7c1d252..0e7061d 100644
81120--- a/include/linux/pm_domain.h
81121+++ b/include/linux/pm_domain.h
81122@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81123 int (*thaw_early)(struct device *dev);
81124 int (*thaw)(struct device *dev);
81125 bool (*active_wakeup)(struct device *dev);
81126-};
81127+} __no_const;
81128
81129 struct gpd_cpu_data {
81130 unsigned int saved_exit_latency;
81131- struct cpuidle_state *idle_state;
81132+ cpuidle_state_no_const *idle_state;
81133 };
81134
81135 struct generic_pm_domain {
81136diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81137index 16c9a62..f9f0838 100644
81138--- a/include/linux/pm_runtime.h
81139+++ b/include/linux/pm_runtime.h
81140@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81141
81142 static inline void pm_runtime_mark_last_busy(struct device *dev)
81143 {
81144- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81145+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81146 }
81147
81148 #else /* !CONFIG_PM_RUNTIME */
81149diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81150index 195aafc..49a7bc2 100644
81151--- a/include/linux/pnp.h
81152+++ b/include/linux/pnp.h
81153@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81154 struct pnp_fixup {
81155 char id[7];
81156 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81157-};
81158+} __do_const;
81159
81160 /* config parameters */
81161 #define PNP_CONFIG_NORMAL 0x0001
81162diff --git a/include/linux/poison.h b/include/linux/poison.h
81163index 2110a81..13a11bb 100644
81164--- a/include/linux/poison.h
81165+++ b/include/linux/poison.h
81166@@ -19,8 +19,8 @@
81167 * under normal circumstances, used to verify that nobody uses
81168 * non-initialized list entries.
81169 */
81170-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81171-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81172+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81173+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81174
81175 /********** include/linux/timer.h **********/
81176 /*
81177diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81178index d8b187c3..9a9257a 100644
81179--- a/include/linux/power/smartreflex.h
81180+++ b/include/linux/power/smartreflex.h
81181@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81182 int (*notify)(struct omap_sr *sr, u32 status);
81183 u8 notify_flags;
81184 u8 class_type;
81185-};
81186+} __do_const;
81187
81188 /**
81189 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81190diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81191index 4ea1d37..80f4b33 100644
81192--- a/include/linux/ppp-comp.h
81193+++ b/include/linux/ppp-comp.h
81194@@ -84,7 +84,7 @@ struct compressor {
81195 struct module *owner;
81196 /* Extra skb space needed by the compressor algorithm */
81197 unsigned int comp_extra;
81198-};
81199+} __do_const;
81200
81201 /*
81202 * The return value from decompress routine is the length of the
81203diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81204index de83b4e..c4b997d 100644
81205--- a/include/linux/preempt.h
81206+++ b/include/linux/preempt.h
81207@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81208 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81209 #endif
81210
81211+#define raw_preempt_count_add(val) __preempt_count_add(val)
81212+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81213+
81214 #define __preempt_count_inc() __preempt_count_add(1)
81215 #define __preempt_count_dec() __preempt_count_sub(1)
81216
81217 #define preempt_count_inc() preempt_count_add(1)
81218+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81219 #define preempt_count_dec() preempt_count_sub(1)
81220+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81221
81222 #ifdef CONFIG_PREEMPT_COUNT
81223
81224@@ -41,6 +46,12 @@ do { \
81225 barrier(); \
81226 } while (0)
81227
81228+#define raw_preempt_disable() \
81229+do { \
81230+ raw_preempt_count_inc(); \
81231+ barrier(); \
81232+} while (0)
81233+
81234 #define sched_preempt_enable_no_resched() \
81235 do { \
81236 barrier(); \
81237@@ -49,6 +60,12 @@ do { \
81238
81239 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81240
81241+#define raw_preempt_enable_no_resched() \
81242+do { \
81243+ barrier(); \
81244+ raw_preempt_count_dec(); \
81245+} while (0)
81246+
81247 #ifdef CONFIG_PREEMPT
81248 #define preempt_enable() \
81249 do { \
81250@@ -113,8 +130,10 @@ do { \
81251 * region.
81252 */
81253 #define preempt_disable() barrier()
81254+#define raw_preempt_disable() barrier()
81255 #define sched_preempt_enable_no_resched() barrier()
81256 #define preempt_enable_no_resched() barrier()
81257+#define raw_preempt_enable_no_resched() barrier()
81258 #define preempt_enable() barrier()
81259 #define preempt_check_resched() do { } while (0)
81260
81261@@ -128,11 +147,13 @@ do { \
81262 /*
81263 * Modules have no business playing preemption tricks.
81264 */
81265+#ifndef CONFIG_PAX_KERNEXEC
81266 #undef sched_preempt_enable_no_resched
81267 #undef preempt_enable_no_resched
81268 #undef preempt_enable_no_resched_notrace
81269 #undef preempt_check_resched
81270 #endif
81271+#endif
81272
81273 #define preempt_set_need_resched() \
81274 do { \
81275diff --git a/include/linux/printk.h b/include/linux/printk.h
81276index fa47e27..c08e034 100644
81277--- a/include/linux/printk.h
81278+++ b/include/linux/printk.h
81279@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81280 void early_printk(const char *s, ...) { }
81281 #endif
81282
81283+extern int kptr_restrict;
81284+
81285 #ifdef CONFIG_PRINTK
81286 asmlinkage __printf(5, 0)
81287 int vprintk_emit(int facility, int level,
81288@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81289
81290 extern int printk_delay_msec;
81291 extern int dmesg_restrict;
81292-extern int kptr_restrict;
81293
81294 extern void wake_up_klogd(void);
81295
81296diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81297index 608e60a..bbcb1a0 100644
81298--- a/include/linux/proc_fs.h
81299+++ b/include/linux/proc_fs.h
81300@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81301 extern struct proc_dir_entry *proc_symlink(const char *,
81302 struct proc_dir_entry *, const char *);
81303 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81304+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81305 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81306 struct proc_dir_entry *, void *);
81307+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81308+ struct proc_dir_entry *, void *);
81309 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81310 struct proc_dir_entry *);
81311
81312@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81313 return proc_create_data(name, mode, parent, proc_fops, NULL);
81314 }
81315
81316+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81317+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81318+{
81319+#ifdef CONFIG_GRKERNSEC_PROC_USER
81320+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81321+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81322+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81323+#else
81324+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81325+#endif
81326+}
81327+
81328+
81329 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81330 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81331 extern void *PDE_DATA(const struct inode *);
81332@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81333 static inline struct proc_dir_entry *proc_net_mkdir(
81334 struct net *net, const char *name, struct proc_dir_entry *parent)
81335 {
81336- return proc_mkdir_data(name, 0, parent, net);
81337+ return proc_mkdir_data_restrict(name, 0, parent, net);
81338 }
81339
81340 #endif /* _LINUX_PROC_FS_H */
81341diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81342index 34a1e10..70f6bde 100644
81343--- a/include/linux/proc_ns.h
81344+++ b/include/linux/proc_ns.h
81345@@ -14,7 +14,7 @@ struct proc_ns_operations {
81346 void (*put)(void *ns);
81347 int (*install)(struct nsproxy *nsproxy, void *ns);
81348 unsigned int (*inum)(void *ns);
81349-};
81350+} __do_const __randomize_layout;
81351
81352 struct proc_ns {
81353 void *ns;
81354diff --git a/include/linux/quota.h b/include/linux/quota.h
81355index cc7494a..1e27036 100644
81356--- a/include/linux/quota.h
81357+++ b/include/linux/quota.h
81358@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81359
81360 extern bool qid_eq(struct kqid left, struct kqid right);
81361 extern bool qid_lt(struct kqid left, struct kqid right);
81362-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81363+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81364 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81365 extern bool qid_valid(struct kqid qid);
81366
81367diff --git a/include/linux/random.h b/include/linux/random.h
81368index 1cfce0e..b0b9235 100644
81369--- a/include/linux/random.h
81370+++ b/include/linux/random.h
81371@@ -9,9 +9,19 @@
81372 #include <uapi/linux/random.h>
81373
81374 extern void add_device_randomness(const void *, unsigned int);
81375+
81376+static inline void add_latent_entropy(void)
81377+{
81378+
81379+#ifdef LATENT_ENTROPY_PLUGIN
81380+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81381+#endif
81382+
81383+}
81384+
81385 extern void add_input_randomness(unsigned int type, unsigned int code,
81386- unsigned int value);
81387-extern void add_interrupt_randomness(int irq, int irq_flags);
81388+ unsigned int value) __latent_entropy;
81389+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81390
81391 extern void get_random_bytes(void *buf, int nbytes);
81392 extern void get_random_bytes_arch(void *buf, int nbytes);
81393@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81394 extern const struct file_operations random_fops, urandom_fops;
81395 #endif
81396
81397-unsigned int get_random_int(void);
81398+unsigned int __intentional_overflow(-1) get_random_int(void);
81399 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81400
81401-u32 prandom_u32(void);
81402+u32 prandom_u32(void) __intentional_overflow(-1);
81403 void prandom_bytes(void *buf, int nbytes);
81404 void prandom_seed(u32 seed);
81405 void prandom_reseed_late(void);
81406@@ -37,6 +47,11 @@ struct rnd_state {
81407 u32 prandom_u32_state(struct rnd_state *state);
81408 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81409
81410+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81411+{
81412+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81413+}
81414+
81415 /**
81416 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81417 * @ep_ro: right open interval endpoint
81418diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81419index fea49b5..2ac22bb 100644
81420--- a/include/linux/rbtree_augmented.h
81421+++ b/include/linux/rbtree_augmented.h
81422@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81423 old->rbaugmented = rbcompute(old); \
81424 } \
81425 rbstatic const struct rb_augment_callbacks rbname = { \
81426- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81427+ .propagate = rbname ## _propagate, \
81428+ .copy = rbname ## _copy, \
81429+ .rotate = rbname ## _rotate \
81430 };
81431
81432
81433diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81434index dbaf990..52e07b8 100644
81435--- a/include/linux/rculist.h
81436+++ b/include/linux/rculist.h
81437@@ -29,8 +29,8 @@
81438 */
81439 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81440 {
81441- ACCESS_ONCE(list->next) = list;
81442- ACCESS_ONCE(list->prev) = list;
81443+ ACCESS_ONCE_RW(list->next) = list;
81444+ ACCESS_ONCE_RW(list->prev) = list;
81445 }
81446
81447 /*
81448@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81449 struct list_head *prev, struct list_head *next);
81450 #endif
81451
81452+void __pax_list_add_rcu(struct list_head *new,
81453+ struct list_head *prev, struct list_head *next);
81454+
81455 /**
81456 * list_add_rcu - add a new entry to rcu-protected list
81457 * @new: new entry to be added
81458@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81459 __list_add_rcu(new, head, head->next);
81460 }
81461
81462+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81463+{
81464+ __pax_list_add_rcu(new, head, head->next);
81465+}
81466+
81467 /**
81468 * list_add_tail_rcu - add a new entry to rcu-protected list
81469 * @new: new entry to be added
81470@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81471 __list_add_rcu(new, head->prev, head);
81472 }
81473
81474+static inline void pax_list_add_tail_rcu(struct list_head *new,
81475+ struct list_head *head)
81476+{
81477+ __pax_list_add_rcu(new, head->prev, head);
81478+}
81479+
81480 /**
81481 * list_del_rcu - deletes entry from list without re-initialization
81482 * @entry: the element to delete from the list.
81483@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81484 entry->prev = LIST_POISON2;
81485 }
81486
81487+extern void pax_list_del_rcu(struct list_head *entry);
81488+
81489 /**
81490 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81491 * @n: the element to delete from the hash list.
81492diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81493index 72bf3a0..853347f 100644
81494--- a/include/linux/rcupdate.h
81495+++ b/include/linux/rcupdate.h
81496@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81497 #define rcu_assign_pointer(p, v) \
81498 do { \
81499 smp_wmb(); \
81500- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81501+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81502 } while (0)
81503
81504
81505diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81506index 9e7db9e..7d4fd72 100644
81507--- a/include/linux/reboot.h
81508+++ b/include/linux/reboot.h
81509@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81510 */
81511
81512 extern void migrate_to_reboot_cpu(void);
81513-extern void machine_restart(char *cmd);
81514-extern void machine_halt(void);
81515-extern void machine_power_off(void);
81516+extern void machine_restart(char *cmd) __noreturn;
81517+extern void machine_halt(void) __noreturn;
81518+extern void machine_power_off(void) __noreturn;
81519
81520 extern void machine_shutdown(void);
81521 struct pt_regs;
81522@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81523 */
81524
81525 extern void kernel_restart_prepare(char *cmd);
81526-extern void kernel_restart(char *cmd);
81527-extern void kernel_halt(void);
81528-extern void kernel_power_off(void);
81529+extern void kernel_restart(char *cmd) __noreturn;
81530+extern void kernel_halt(void) __noreturn;
81531+extern void kernel_power_off(void) __noreturn;
81532
81533 extern int C_A_D; /* for sysctl */
81534 void ctrl_alt_del(void);
81535@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81536 * Emergency restart, callable from an interrupt handler.
81537 */
81538
81539-extern void emergency_restart(void);
81540+extern void emergency_restart(void) __noreturn;
81541 #include <asm/emergency-restart.h>
81542
81543 #endif /* _LINUX_REBOOT_H */
81544diff --git a/include/linux/regset.h b/include/linux/regset.h
81545index 8e0c9fe..ac4d221 100644
81546--- a/include/linux/regset.h
81547+++ b/include/linux/regset.h
81548@@ -161,7 +161,8 @@ struct user_regset {
81549 unsigned int align;
81550 unsigned int bias;
81551 unsigned int core_note_type;
81552-};
81553+} __do_const;
81554+typedef struct user_regset __no_const user_regset_no_const;
81555
81556 /**
81557 * struct user_regset_view - available regsets
81558diff --git a/include/linux/relay.h b/include/linux/relay.h
81559index d7c8359..818daf5 100644
81560--- a/include/linux/relay.h
81561+++ b/include/linux/relay.h
81562@@ -157,7 +157,7 @@ struct rchan_callbacks
81563 * The callback should return 0 if successful, negative if not.
81564 */
81565 int (*remove_buf_file)(struct dentry *dentry);
81566-};
81567+} __no_const;
81568
81569 /*
81570 * CONFIG_RELAY kernel API, kernel/relay.c
81571diff --git a/include/linux/rio.h b/include/linux/rio.h
81572index b71d573..2f940bd 100644
81573--- a/include/linux/rio.h
81574+++ b/include/linux/rio.h
81575@@ -355,7 +355,7 @@ struct rio_ops {
81576 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81577 u64 rstart, u32 size, u32 flags);
81578 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81579-};
81580+} __no_const;
81581
81582 #define RIO_RESOURCE_MEM 0x00000100
81583 #define RIO_RESOURCE_DOORBELL 0x00000200
81584diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81585index b66c211..13d2915 100644
81586--- a/include/linux/rmap.h
81587+++ b/include/linux/rmap.h
81588@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81589 void anon_vma_init(void); /* create anon_vma_cachep */
81590 int anon_vma_prepare(struct vm_area_struct *);
81591 void unlink_anon_vmas(struct vm_area_struct *);
81592-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81593-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81594+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81595+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81596
81597 static inline void anon_vma_merge(struct vm_area_struct *vma,
81598 struct vm_area_struct *next)
81599diff --git a/include/linux/sched.h b/include/linux/sched.h
81600index a781dec..be1d2a3 100644
81601--- a/include/linux/sched.h
81602+++ b/include/linux/sched.h
81603@@ -129,6 +129,7 @@ struct fs_struct;
81604 struct perf_event_context;
81605 struct blk_plug;
81606 struct filename;
81607+struct linux_binprm;
81608
81609 /*
81610 * List of flags we want to share for kernel threads,
81611@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81612 extern int in_sched_functions(unsigned long addr);
81613
81614 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81615-extern signed long schedule_timeout(signed long timeout);
81616+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81617 extern signed long schedule_timeout_interruptible(signed long timeout);
81618 extern signed long schedule_timeout_killable(signed long timeout);
81619 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81620@@ -380,6 +381,19 @@ struct nsproxy;
81621 struct user_namespace;
81622
81623 #ifdef CONFIG_MMU
81624+
81625+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81626+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81627+#else
81628+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81629+{
81630+ return 0;
81631+}
81632+#endif
81633+
81634+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81635+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81636+
81637 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81638 extern unsigned long
81639 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81640@@ -677,6 +691,17 @@ struct signal_struct {
81641 #ifdef CONFIG_TASKSTATS
81642 struct taskstats *stats;
81643 #endif
81644+
81645+#ifdef CONFIG_GRKERNSEC
81646+ u32 curr_ip;
81647+ u32 saved_ip;
81648+ u32 gr_saddr;
81649+ u32 gr_daddr;
81650+ u16 gr_sport;
81651+ u16 gr_dport;
81652+ u8 used_accept:1;
81653+#endif
81654+
81655 #ifdef CONFIG_AUDIT
81656 unsigned audit_tty;
81657 unsigned audit_tty_log_passwd;
81658@@ -703,7 +728,7 @@ struct signal_struct {
81659 struct mutex cred_guard_mutex; /* guard against foreign influences on
81660 * credential calculations
81661 * (notably. ptrace) */
81662-};
81663+} __randomize_layout;
81664
81665 /*
81666 * Bits in flags field of signal_struct.
81667@@ -757,6 +782,14 @@ struct user_struct {
81668 struct key *session_keyring; /* UID's default session keyring */
81669 #endif
81670
81671+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81672+ unsigned char kernel_banned;
81673+#endif
81674+#ifdef CONFIG_GRKERNSEC_BRUTE
81675+ unsigned char suid_banned;
81676+ unsigned long suid_ban_expires;
81677+#endif
81678+
81679 /* Hash table maintenance information */
81680 struct hlist_node uidhash_node;
81681 kuid_t uid;
81682@@ -764,7 +797,7 @@ struct user_struct {
81683 #ifdef CONFIG_PERF_EVENTS
81684 atomic_long_t locked_vm;
81685 #endif
81686-};
81687+} __randomize_layout;
81688
81689 extern int uids_sysfs_init(void);
81690
81691@@ -1286,8 +1319,8 @@ struct task_struct {
81692 struct list_head thread_node;
81693
81694 struct completion *vfork_done; /* for vfork() */
81695- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81696- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81697+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81698+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81699
81700 cputime_t utime, stime, utimescaled, stimescaled;
81701 cputime_t gtime;
81702@@ -1312,11 +1345,6 @@ struct task_struct {
81703 struct task_cputime cputime_expires;
81704 struct list_head cpu_timers[3];
81705
81706-/* process credentials */
81707- const struct cred __rcu *real_cred; /* objective and real subjective task
81708- * credentials (COW) */
81709- const struct cred __rcu *cred; /* effective (overridable) subjective task
81710- * credentials (COW) */
81711 char comm[TASK_COMM_LEN]; /* executable name excluding path
81712 - access with [gs]et_task_comm (which lock
81713 it with task_lock())
81714@@ -1333,6 +1361,10 @@ struct task_struct {
81715 #endif
81716 /* CPU-specific state of this task */
81717 struct thread_struct thread;
81718+/* thread_info moved to task_struct */
81719+#ifdef CONFIG_X86
81720+ struct thread_info tinfo;
81721+#endif
81722 /* filesystem information */
81723 struct fs_struct *fs;
81724 /* open file information */
81725@@ -1409,6 +1441,10 @@ struct task_struct {
81726 gfp_t lockdep_reclaim_gfp;
81727 #endif
81728
81729+/* process credentials */
81730+ const struct cred __rcu *real_cred; /* objective and real subjective task
81731+ * credentials (COW) */
81732+
81733 /* journalling filesystem info */
81734 void *journal_info;
81735
81736@@ -1447,6 +1483,10 @@ struct task_struct {
81737 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81738 struct list_head cg_list;
81739 #endif
81740+
81741+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81742+ * credentials (COW) */
81743+
81744 #ifdef CONFIG_FUTEX
81745 struct robust_list_head __user *robust_list;
81746 #ifdef CONFIG_COMPAT
81747@@ -1581,7 +1621,78 @@ struct task_struct {
81748 unsigned int sequential_io;
81749 unsigned int sequential_io_avg;
81750 #endif
81751-};
81752+
81753+#ifdef CONFIG_GRKERNSEC
81754+ /* grsecurity */
81755+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81756+ u64 exec_id;
81757+#endif
81758+#ifdef CONFIG_GRKERNSEC_SETXID
81759+ const struct cred *delayed_cred;
81760+#endif
81761+ struct dentry *gr_chroot_dentry;
81762+ struct acl_subject_label *acl;
81763+ struct acl_subject_label *tmpacl;
81764+ struct acl_role_label *role;
81765+ struct file *exec_file;
81766+ unsigned long brute_expires;
81767+ u16 acl_role_id;
81768+ u8 inherited;
81769+ /* is this the task that authenticated to the special role */
81770+ u8 acl_sp_role;
81771+ u8 is_writable;
81772+ u8 brute;
81773+ u8 gr_is_chrooted;
81774+#endif
81775+
81776+} __randomize_layout;
81777+
81778+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81779+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81780+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81781+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81782+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81783+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81784+
81785+#ifdef CONFIG_PAX_SOFTMODE
81786+extern int pax_softmode;
81787+#endif
81788+
81789+extern int pax_check_flags(unsigned long *);
81790+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81791+
81792+/* if tsk != current then task_lock must be held on it */
81793+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81794+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81795+{
81796+ if (likely(tsk->mm))
81797+ return tsk->mm->pax_flags;
81798+ else
81799+ return 0UL;
81800+}
81801+
81802+/* if tsk != current then task_lock must be held on it */
81803+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81804+{
81805+ if (likely(tsk->mm)) {
81806+ tsk->mm->pax_flags = flags;
81807+ return 0;
81808+ }
81809+ return -EINVAL;
81810+}
81811+#endif
81812+
81813+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81814+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81815+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81816+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81817+#endif
81818+
81819+struct path;
81820+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81821+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81822+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81823+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81824
81825 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81826 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81827@@ -1658,7 +1769,7 @@ struct pid_namespace;
81828 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81829 struct pid_namespace *ns);
81830
81831-static inline pid_t task_pid_nr(struct task_struct *tsk)
81832+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81833 {
81834 return tsk->pid;
81835 }
81836@@ -2112,7 +2223,9 @@ void yield(void);
81837 extern struct exec_domain default_exec_domain;
81838
81839 union thread_union {
81840+#ifndef CONFIG_X86
81841 struct thread_info thread_info;
81842+#endif
81843 unsigned long stack[THREAD_SIZE/sizeof(long)];
81844 };
81845
81846@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81847 */
81848
81849 extern struct task_struct *find_task_by_vpid(pid_t nr);
81850+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81851 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81852 struct pid_namespace *ns);
81853
81854@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81855 extern void exit_itimers(struct signal_struct *);
81856 extern void flush_itimer_signals(void);
81857
81858-extern void do_group_exit(int);
81859+extern __noreturn void do_group_exit(int);
81860
81861 extern int allow_signal(int);
81862 extern int disallow_signal(int);
81863@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81864
81865 #endif
81866
81867-static inline int object_is_on_stack(void *obj)
81868+static inline int object_starts_on_stack(void *obj)
81869 {
81870- void *stack = task_stack_page(current);
81871+ const void *stack = task_stack_page(current);
81872
81873 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81874 }
81875diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81876index 8045a55..c959cd5 100644
81877--- a/include/linux/sched/sysctl.h
81878+++ b/include/linux/sched/sysctl.h
81879@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81880 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81881
81882 extern int sysctl_max_map_count;
81883+extern unsigned long sysctl_heap_stack_gap;
81884
81885 extern unsigned int sysctl_sched_latency;
81886 extern unsigned int sysctl_sched_min_granularity;
81887diff --git a/include/linux/security.h b/include/linux/security.h
81888index 2fc42d1..4d802f2 100644
81889--- a/include/linux/security.h
81890+++ b/include/linux/security.h
81891@@ -27,6 +27,7 @@
81892 #include <linux/slab.h>
81893 #include <linux/err.h>
81894 #include <linux/string.h>
81895+#include <linux/grsecurity.h>
81896
81897 struct linux_binprm;
81898 struct cred;
81899@@ -116,8 +117,6 @@ struct seq_file;
81900
81901 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81902
81903-void reset_security_ops(void);
81904-
81905 #ifdef CONFIG_MMU
81906 extern unsigned long mmap_min_addr;
81907 extern unsigned long dac_mmap_min_addr;
81908@@ -1719,7 +1718,7 @@ struct security_operations {
81909 struct audit_context *actx);
81910 void (*audit_rule_free) (void *lsmrule);
81911 #endif /* CONFIG_AUDIT */
81912-};
81913+} __randomize_layout;
81914
81915 /* prototypes */
81916 extern int security_init(void);
81917diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81918index dc368b8..e895209 100644
81919--- a/include/linux/semaphore.h
81920+++ b/include/linux/semaphore.h
81921@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81922 }
81923
81924 extern void down(struct semaphore *sem);
81925-extern int __must_check down_interruptible(struct semaphore *sem);
81926+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81927 extern int __must_check down_killable(struct semaphore *sem);
81928 extern int __must_check down_trylock(struct semaphore *sem);
81929 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81930diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81931index 52e0097..383f21d 100644
81932--- a/include/linux/seq_file.h
81933+++ b/include/linux/seq_file.h
81934@@ -27,6 +27,9 @@ struct seq_file {
81935 struct mutex lock;
81936 const struct seq_operations *op;
81937 int poll_event;
81938+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81939+ u64 exec_id;
81940+#endif
81941 #ifdef CONFIG_USER_NS
81942 struct user_namespace *user_ns;
81943 #endif
81944@@ -39,6 +42,7 @@ struct seq_operations {
81945 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81946 int (*show) (struct seq_file *m, void *v);
81947 };
81948+typedef struct seq_operations __no_const seq_operations_no_const;
81949
81950 #define SEQ_SKIP 1
81951
81952@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
81953
81954 char *mangle_path(char *s, const char *p, const char *esc);
81955 int seq_open(struct file *, const struct seq_operations *);
81956+int seq_open_restrict(struct file *, const struct seq_operations *);
81957 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
81958 loff_t seq_lseek(struct file *, loff_t, int);
81959 int seq_release(struct inode *, struct file *);
81960@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
81961 }
81962
81963 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
81964+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
81965 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
81966 int single_release(struct inode *, struct file *);
81967 void *__seq_open_private(struct file *, const struct seq_operations *, int);
81968diff --git a/include/linux/shm.h b/include/linux/shm.h
81969index 1e2cd2e..0288750 100644
81970--- a/include/linux/shm.h
81971+++ b/include/linux/shm.h
81972@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81973
81974 /* The task created the shm object. NULL if the task is dead. */
81975 struct task_struct *shm_creator;
81976+#ifdef CONFIG_GRKERNSEC
81977+ time_t shm_createtime;
81978+ pid_t shm_lapid;
81979+#endif
81980 };
81981
81982 /* shm_mode upper byte flags */
81983diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81984index 15ede6a..80161c3 100644
81985--- a/include/linux/skbuff.h
81986+++ b/include/linux/skbuff.h
81987@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81988 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81989 int node);
81990 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81991-static inline struct sk_buff *alloc_skb(unsigned int size,
81992+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81993 gfp_t priority)
81994 {
81995 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81996@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81997 return skb->inner_transport_header - skb->inner_network_header;
81998 }
81999
82000-static inline int skb_network_offset(const struct sk_buff *skb)
82001+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82002 {
82003 return skb_network_header(skb) - skb->data;
82004 }
82005@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82006 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82007 */
82008 #ifndef NET_SKB_PAD
82009-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82010+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82011 #endif
82012
82013 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82014@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82015 int *err);
82016 unsigned int datagram_poll(struct file *file, struct socket *sock,
82017 struct poll_table_struct *wait);
82018-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82019+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82020 struct iovec *to, int size);
82021 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82022 struct iovec *iov);
82023@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82024 nf_bridge_put(skb->nf_bridge);
82025 skb->nf_bridge = NULL;
82026 #endif
82027+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82028+ skb->nf_trace = 0;
82029+#endif
82030 }
82031
82032 static inline void nf_reset_trace(struct sk_buff *skb)
82033diff --git a/include/linux/slab.h b/include/linux/slab.h
82034index b5b2df6..69f5734 100644
82035--- a/include/linux/slab.h
82036+++ b/include/linux/slab.h
82037@@ -14,15 +14,29 @@
82038 #include <linux/gfp.h>
82039 #include <linux/types.h>
82040 #include <linux/workqueue.h>
82041-
82042+#include <linux/err.h>
82043
82044 /*
82045 * Flags to pass to kmem_cache_create().
82046 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82047 */
82048 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82049+
82050+#ifdef CONFIG_PAX_USERCOPY_SLABS
82051+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82052+#else
82053+#define SLAB_USERCOPY 0x00000000UL
82054+#endif
82055+
82056 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82057 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82058+
82059+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82060+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82061+#else
82062+#define SLAB_NO_SANITIZE 0x00000000UL
82063+#endif
82064+
82065 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82066 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82067 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82068@@ -98,10 +112,13 @@
82069 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82070 * Both make kfree a no-op.
82071 */
82072-#define ZERO_SIZE_PTR ((void *)16)
82073+#define ZERO_SIZE_PTR \
82074+({ \
82075+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82076+ (void *)(-MAX_ERRNO-1L); \
82077+})
82078
82079-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82080- (unsigned long)ZERO_SIZE_PTR)
82081+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82082
82083 #include <linux/kmemleak.h>
82084
82085@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82086 void kfree(const void *);
82087 void kzfree(const void *);
82088 size_t ksize(const void *);
82089+const char *check_heap_object(const void *ptr, unsigned long n);
82090+bool is_usercopy_object(const void *ptr);
82091
82092 /*
82093 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82094@@ -174,7 +193,7 @@ struct kmem_cache {
82095 unsigned int align; /* Alignment as calculated */
82096 unsigned long flags; /* Active flags on the slab */
82097 const char *name; /* Slab name for sysfs */
82098- int refcount; /* Use counter */
82099+ atomic_t refcount; /* Use counter */
82100 void (*ctor)(void *); /* Called on object slot creation */
82101 struct list_head list; /* List of all slab caches on the system */
82102 };
82103@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82104 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82105 #endif
82106
82107+#ifdef CONFIG_PAX_USERCOPY_SLABS
82108+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82109+#endif
82110+
82111 /*
82112 * Figure out which kmalloc slab an allocation of a certain size
82113 * belongs to.
82114@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82115 * 2 = 120 .. 192 bytes
82116 * n = 2^(n-1) .. 2^n -1
82117 */
82118-static __always_inline int kmalloc_index(size_t size)
82119+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82120 {
82121 if (!size)
82122 return 0;
82123@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82124 }
82125 #endif /* !CONFIG_SLOB */
82126
82127-void *__kmalloc(size_t size, gfp_t flags);
82128+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82129 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82130
82131 #ifdef CONFIG_NUMA
82132-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82133+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82134 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82135 #else
82136 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82137diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82138index 8235dfb..47ce586 100644
82139--- a/include/linux/slab_def.h
82140+++ b/include/linux/slab_def.h
82141@@ -38,7 +38,7 @@ struct kmem_cache {
82142 /* 4) cache creation/removal */
82143 const char *name;
82144 struct list_head list;
82145- int refcount;
82146+ atomic_t refcount;
82147 int object_size;
82148 int align;
82149
82150@@ -54,10 +54,14 @@ struct kmem_cache {
82151 unsigned long node_allocs;
82152 unsigned long node_frees;
82153 unsigned long node_overflow;
82154- atomic_t allochit;
82155- atomic_t allocmiss;
82156- atomic_t freehit;
82157- atomic_t freemiss;
82158+ atomic_unchecked_t allochit;
82159+ atomic_unchecked_t allocmiss;
82160+ atomic_unchecked_t freehit;
82161+ atomic_unchecked_t freemiss;
82162+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82163+ atomic_unchecked_t sanitized;
82164+ atomic_unchecked_t not_sanitized;
82165+#endif
82166
82167 /*
82168 * If debugging is enabled, then the allocator can add additional
82169diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82170index f56bfa9..8378a26 100644
82171--- a/include/linux/slub_def.h
82172+++ b/include/linux/slub_def.h
82173@@ -74,7 +74,7 @@ struct kmem_cache {
82174 struct kmem_cache_order_objects max;
82175 struct kmem_cache_order_objects min;
82176 gfp_t allocflags; /* gfp flags to use on each alloc */
82177- int refcount; /* Refcount for slab cache destroy */
82178+ atomic_t refcount; /* Refcount for slab cache destroy */
82179 void (*ctor)(void *);
82180 int inuse; /* Offset to metadata */
82181 int align; /* Alignment */
82182diff --git a/include/linux/smp.h b/include/linux/smp.h
82183index 6ae004e..2743532 100644
82184--- a/include/linux/smp.h
82185+++ b/include/linux/smp.h
82186@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82187 #endif
82188
82189 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82190+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82191 #define put_cpu() preempt_enable()
82192+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82193
82194 /*
82195 * Callback to arch code if there's nosmp or maxcpus=0 on the
82196diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82197index 54f91d3..be2c379 100644
82198--- a/include/linux/sock_diag.h
82199+++ b/include/linux/sock_diag.h
82200@@ -11,7 +11,7 @@ struct sock;
82201 struct sock_diag_handler {
82202 __u8 family;
82203 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82204-};
82205+} __do_const;
82206
82207 int sock_diag_register(const struct sock_diag_handler *h);
82208 void sock_diag_unregister(const struct sock_diag_handler *h);
82209diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82210index 680f9a3..f13aeb0 100644
82211--- a/include/linux/sonet.h
82212+++ b/include/linux/sonet.h
82213@@ -7,7 +7,7 @@
82214 #include <uapi/linux/sonet.h>
82215
82216 struct k_sonet_stats {
82217-#define __HANDLE_ITEM(i) atomic_t i
82218+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82219 __SONET_ITEMS
82220 #undef __HANDLE_ITEM
82221 };
82222diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82223index 07d8e53..dc934c9 100644
82224--- a/include/linux/sunrpc/addr.h
82225+++ b/include/linux/sunrpc/addr.h
82226@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82227 {
82228 switch (sap->sa_family) {
82229 case AF_INET:
82230- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82231+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82232 case AF_INET6:
82233- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82234+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82235 }
82236 return 0;
82237 }
82238@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82239 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82240 const struct sockaddr *src)
82241 {
82242- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82243+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82244 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82245
82246 dsin->sin_family = ssin->sin_family;
82247@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82248 if (sa->sa_family != AF_INET6)
82249 return 0;
82250
82251- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82252+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82253 }
82254
82255 #endif /* _LINUX_SUNRPC_ADDR_H */
82256diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82257index 8af2804..c7414ef 100644
82258--- a/include/linux/sunrpc/clnt.h
82259+++ b/include/linux/sunrpc/clnt.h
82260@@ -97,7 +97,7 @@ struct rpc_procinfo {
82261 unsigned int p_timer; /* Which RTT timer to use */
82262 u32 p_statidx; /* Which procedure to account */
82263 const char * p_name; /* name of procedure */
82264-};
82265+} __do_const;
82266
82267 #ifdef __KERNEL__
82268
82269diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82270index 04e7632..2e2a8a3 100644
82271--- a/include/linux/sunrpc/svc.h
82272+++ b/include/linux/sunrpc/svc.h
82273@@ -412,7 +412,7 @@ struct svc_procedure {
82274 unsigned int pc_count; /* call count */
82275 unsigned int pc_cachetype; /* cache info (NFS) */
82276 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82277-};
82278+} __do_const;
82279
82280 /*
82281 * Function prototypes.
82282diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82283index 0b8e3e6..33e0a01 100644
82284--- a/include/linux/sunrpc/svc_rdma.h
82285+++ b/include/linux/sunrpc/svc_rdma.h
82286@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82287 extern unsigned int svcrdma_max_requests;
82288 extern unsigned int svcrdma_max_req_size;
82289
82290-extern atomic_t rdma_stat_recv;
82291-extern atomic_t rdma_stat_read;
82292-extern atomic_t rdma_stat_write;
82293-extern atomic_t rdma_stat_sq_starve;
82294-extern atomic_t rdma_stat_rq_starve;
82295-extern atomic_t rdma_stat_rq_poll;
82296-extern atomic_t rdma_stat_rq_prod;
82297-extern atomic_t rdma_stat_sq_poll;
82298-extern atomic_t rdma_stat_sq_prod;
82299+extern atomic_unchecked_t rdma_stat_recv;
82300+extern atomic_unchecked_t rdma_stat_read;
82301+extern atomic_unchecked_t rdma_stat_write;
82302+extern atomic_unchecked_t rdma_stat_sq_starve;
82303+extern atomic_unchecked_t rdma_stat_rq_starve;
82304+extern atomic_unchecked_t rdma_stat_rq_poll;
82305+extern atomic_unchecked_t rdma_stat_rq_prod;
82306+extern atomic_unchecked_t rdma_stat_sq_poll;
82307+extern atomic_unchecked_t rdma_stat_sq_prod;
82308
82309 #define RPCRDMA_VERSION 1
82310
82311diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82312index 8d71d65..f79586e 100644
82313--- a/include/linux/sunrpc/svcauth.h
82314+++ b/include/linux/sunrpc/svcauth.h
82315@@ -120,7 +120,7 @@ struct auth_ops {
82316 int (*release)(struct svc_rqst *rq);
82317 void (*domain_release)(struct auth_domain *);
82318 int (*set_client)(struct svc_rqst *rq);
82319-};
82320+} __do_const;
82321
82322 #define SVC_GARBAGE 1
82323 #define SVC_SYSERR 2
82324diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82325index a5ffd32..0935dea 100644
82326--- a/include/linux/swiotlb.h
82327+++ b/include/linux/swiotlb.h
82328@@ -60,7 +60,8 @@ extern void
82329
82330 extern void
82331 swiotlb_free_coherent(struct device *hwdev, size_t size,
82332- void *vaddr, dma_addr_t dma_handle);
82333+ void *vaddr, dma_addr_t dma_handle,
82334+ struct dma_attrs *attrs);
82335
82336 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82337 unsigned long offset, size_t size,
82338diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82339index a747a77..9e14df7 100644
82340--- a/include/linux/syscalls.h
82341+++ b/include/linux/syscalls.h
82342@@ -98,8 +98,14 @@ struct sigaltstack;
82343 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82344
82345 #define __SC_DECL(t, a) t a
82346+#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))
82347 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82348-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82349+#define __SC_LONG(t, a) __typeof( \
82350+ __builtin_choose_expr( \
82351+ sizeof(t) > sizeof(int), \
82352+ (t) 0, \
82353+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82354+ )) a
82355 #define __SC_CAST(t, a) (t) a
82356 #define __SC_ARGS(t, a) a
82357 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82358@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82359 asmlinkage long sys_fsync(unsigned int fd);
82360 asmlinkage long sys_fdatasync(unsigned int fd);
82361 asmlinkage long sys_bdflush(int func, long data);
82362-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82363- char __user *type, unsigned long flags,
82364+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82365+ const char __user *type, unsigned long flags,
82366 void __user *data);
82367-asmlinkage long sys_umount(char __user *name, int flags);
82368-asmlinkage long sys_oldumount(char __user *name);
82369+asmlinkage long sys_umount(const char __user *name, int flags);
82370+asmlinkage long sys_oldumount(const char __user *name);
82371 asmlinkage long sys_truncate(const char __user *path, long length);
82372 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82373 asmlinkage long sys_stat(const char __user *filename,
82374@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82375 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82376 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82377 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82378- struct sockaddr __user *, int);
82379+ struct sockaddr __user *, int) __intentional_overflow(0);
82380 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82381 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82382 unsigned int vlen, unsigned flags);
82383diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82384index 27b3b0b..e093dd9 100644
82385--- a/include/linux/syscore_ops.h
82386+++ b/include/linux/syscore_ops.h
82387@@ -16,7 +16,7 @@ struct syscore_ops {
82388 int (*suspend)(void);
82389 void (*resume)(void);
82390 void (*shutdown)(void);
82391-};
82392+} __do_const;
82393
82394 extern void register_syscore_ops(struct syscore_ops *ops);
82395 extern void unregister_syscore_ops(struct syscore_ops *ops);
82396diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82397index 14a8ff2..fa95f3a 100644
82398--- a/include/linux/sysctl.h
82399+++ b/include/linux/sysctl.h
82400@@ -34,13 +34,13 @@ struct ctl_table_root;
82401 struct ctl_table_header;
82402 struct ctl_dir;
82403
82404-typedef struct ctl_table ctl_table;
82405-
82406 typedef int proc_handler (struct ctl_table *ctl, int write,
82407 void __user *buffer, size_t *lenp, loff_t *ppos);
82408
82409 extern int proc_dostring(struct ctl_table *, int,
82410 void __user *, size_t *, loff_t *);
82411+extern int proc_dostring_modpriv(struct ctl_table *, int,
82412+ void __user *, size_t *, loff_t *);
82413 extern int proc_dointvec(struct ctl_table *, int,
82414 void __user *, size_t *, loff_t *);
82415 extern int proc_dointvec_minmax(struct ctl_table *, int,
82416@@ -115,7 +115,9 @@ struct ctl_table
82417 struct ctl_table_poll *poll;
82418 void *extra1;
82419 void *extra2;
82420-};
82421+} __do_const __randomize_layout;
82422+typedef struct ctl_table __no_const ctl_table_no_const;
82423+typedef struct ctl_table ctl_table;
82424
82425 struct ctl_node {
82426 struct rb_node node;
82427diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82428index 30b2ebe..37412ef 100644
82429--- a/include/linux/sysfs.h
82430+++ b/include/linux/sysfs.h
82431@@ -34,7 +34,8 @@ struct attribute {
82432 struct lock_class_key *key;
82433 struct lock_class_key skey;
82434 #endif
82435-};
82436+} __do_const;
82437+typedef struct attribute __no_const attribute_no_const;
82438
82439 /**
82440 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82441@@ -63,7 +64,8 @@ struct attribute_group {
82442 struct attribute *, int);
82443 struct attribute **attrs;
82444 struct bin_attribute **bin_attrs;
82445-};
82446+} __do_const;
82447+typedef struct attribute_group __no_const attribute_group_no_const;
82448
82449 /**
82450 * Use these macros to make defining attributes easier. See include/linux/device.h
82451@@ -127,7 +129,8 @@ struct bin_attribute {
82452 char *, loff_t, size_t);
82453 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82454 struct vm_area_struct *vma);
82455-};
82456+} __do_const;
82457+typedef struct bin_attribute __no_const bin_attribute_no_const;
82458
82459 /**
82460 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82461diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82462index 387fa7d..3fcde6b 100644
82463--- a/include/linux/sysrq.h
82464+++ b/include/linux/sysrq.h
82465@@ -16,6 +16,7 @@
82466
82467 #include <linux/errno.h>
82468 #include <linux/types.h>
82469+#include <linux/compiler.h>
82470
82471 /* Possible values of bitmask for enabling sysrq functions */
82472 /* 0x0001 is reserved for enable everything */
82473@@ -33,7 +34,7 @@ struct sysrq_key_op {
82474 char *help_msg;
82475 char *action_msg;
82476 int enable_mask;
82477-};
82478+} __do_const;
82479
82480 #ifdef CONFIG_MAGIC_SYSRQ
82481
82482diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82483index fddbe20..0312de8 100644
82484--- a/include/linux/thread_info.h
82485+++ b/include/linux/thread_info.h
82486@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82487 #error "no set_restore_sigmask() provided and default one won't work"
82488 #endif
82489
82490+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82491+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82492+{
82493+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82494+ if (!__builtin_constant_p(n))
82495+#endif
82496+ __check_object_size(ptr, n, to_user);
82497+}
82498+
82499 #endif /* __KERNEL__ */
82500
82501 #endif /* _LINUX_THREAD_INFO_H */
82502diff --git a/include/linux/tty.h b/include/linux/tty.h
82503index b90b5c2..e23a512 100644
82504--- a/include/linux/tty.h
82505+++ b/include/linux/tty.h
82506@@ -202,7 +202,7 @@ struct tty_port {
82507 const struct tty_port_operations *ops; /* Port operations */
82508 spinlock_t lock; /* Lock protecting tty field */
82509 int blocked_open; /* Waiting to open */
82510- int count; /* Usage count */
82511+ atomic_t count; /* Usage count */
82512 wait_queue_head_t open_wait; /* Open waiters */
82513 wait_queue_head_t close_wait; /* Close waiters */
82514 wait_queue_head_t delta_msr_wait; /* Modem status change */
82515@@ -284,7 +284,7 @@ struct tty_struct {
82516 /* If the tty has a pending do_SAK, queue it here - akpm */
82517 struct work_struct SAK_work;
82518 struct tty_port *port;
82519-};
82520+} __randomize_layout;
82521
82522 /* Each of a tty's open files has private_data pointing to tty_file_private */
82523 struct tty_file_private {
82524@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82525 struct tty_struct *tty, struct file *filp);
82526 static inline int tty_port_users(struct tty_port *port)
82527 {
82528- return port->count + port->blocked_open;
82529+ return atomic_read(&port->count) + port->blocked_open;
82530 }
82531
82532 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82533diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82534index 756a609..89db85e 100644
82535--- a/include/linux/tty_driver.h
82536+++ b/include/linux/tty_driver.h
82537@@ -285,7 +285,7 @@ struct tty_operations {
82538 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82539 #endif
82540 const struct file_operations *proc_fops;
82541-};
82542+} __do_const __randomize_layout;
82543
82544 struct tty_driver {
82545 int magic; /* magic number for this structure */
82546@@ -319,7 +319,7 @@ struct tty_driver {
82547
82548 const struct tty_operations *ops;
82549 struct list_head tty_drivers;
82550-};
82551+} __randomize_layout;
82552
82553 extern struct list_head tty_drivers;
82554
82555diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82556index b8347c2..85d8b0f 100644
82557--- a/include/linux/tty_ldisc.h
82558+++ b/include/linux/tty_ldisc.h
82559@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82560
82561 struct module *owner;
82562
82563- int refcount;
82564+ atomic_t refcount;
82565 };
82566
82567 struct tty_ldisc {
82568diff --git a/include/linux/types.h b/include/linux/types.h
82569index 4d118ba..c3ee9bf 100644
82570--- a/include/linux/types.h
82571+++ b/include/linux/types.h
82572@@ -176,10 +176,26 @@ typedef struct {
82573 int counter;
82574 } atomic_t;
82575
82576+#ifdef CONFIG_PAX_REFCOUNT
82577+typedef struct {
82578+ int counter;
82579+} atomic_unchecked_t;
82580+#else
82581+typedef atomic_t atomic_unchecked_t;
82582+#endif
82583+
82584 #ifdef CONFIG_64BIT
82585 typedef struct {
82586 long counter;
82587 } atomic64_t;
82588+
82589+#ifdef CONFIG_PAX_REFCOUNT
82590+typedef struct {
82591+ long counter;
82592+} atomic64_unchecked_t;
82593+#else
82594+typedef atomic64_t atomic64_unchecked_t;
82595+#endif
82596 #endif
82597
82598 struct list_head {
82599diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82600index ecd3319..8a36ded 100644
82601--- a/include/linux/uaccess.h
82602+++ b/include/linux/uaccess.h
82603@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82604 long ret; \
82605 mm_segment_t old_fs = get_fs(); \
82606 \
82607- set_fs(KERNEL_DS); \
82608 pagefault_disable(); \
82609- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82610- pagefault_enable(); \
82611+ set_fs(KERNEL_DS); \
82612+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82613 set_fs(old_fs); \
82614+ pagefault_enable(); \
82615 ret; \
82616 })
82617
82618diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82619index 2d1f9b6..d7a9fce 100644
82620--- a/include/linux/uidgid.h
82621+++ b/include/linux/uidgid.h
82622@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82623
82624 #endif /* CONFIG_USER_NS */
82625
82626+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82627+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82628+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82629+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82630+
82631 #endif /* _LINUX_UIDGID_H */
82632diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82633index 99c1b4d..562e6f3 100644
82634--- a/include/linux/unaligned/access_ok.h
82635+++ b/include/linux/unaligned/access_ok.h
82636@@ -4,34 +4,34 @@
82637 #include <linux/kernel.h>
82638 #include <asm/byteorder.h>
82639
82640-static inline u16 get_unaligned_le16(const void *p)
82641+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82642 {
82643- return le16_to_cpup((__le16 *)p);
82644+ return le16_to_cpup((const __le16 *)p);
82645 }
82646
82647-static inline u32 get_unaligned_le32(const void *p)
82648+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82649 {
82650- return le32_to_cpup((__le32 *)p);
82651+ return le32_to_cpup((const __le32 *)p);
82652 }
82653
82654-static inline u64 get_unaligned_le64(const void *p)
82655+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82656 {
82657- return le64_to_cpup((__le64 *)p);
82658+ return le64_to_cpup((const __le64 *)p);
82659 }
82660
82661-static inline u16 get_unaligned_be16(const void *p)
82662+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82663 {
82664- return be16_to_cpup((__be16 *)p);
82665+ return be16_to_cpup((const __be16 *)p);
82666 }
82667
82668-static inline u32 get_unaligned_be32(const void *p)
82669+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82670 {
82671- return be32_to_cpup((__be32 *)p);
82672+ return be32_to_cpup((const __be32 *)p);
82673 }
82674
82675-static inline u64 get_unaligned_be64(const void *p)
82676+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82677 {
82678- return be64_to_cpup((__be64 *)p);
82679+ return be64_to_cpup((const __be64 *)p);
82680 }
82681
82682 static inline void put_unaligned_le16(u16 val, void *p)
82683diff --git a/include/linux/usb.h b/include/linux/usb.h
82684index 7f6eb85..656e806 100644
82685--- a/include/linux/usb.h
82686+++ b/include/linux/usb.h
82687@@ -563,7 +563,7 @@ struct usb_device {
82688 int maxchild;
82689
82690 u32 quirks;
82691- atomic_t urbnum;
82692+ atomic_unchecked_t urbnum;
82693
82694 unsigned long active_duration;
82695
82696@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82697
82698 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82699 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82700- void *data, __u16 size, int timeout);
82701+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82702 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82703 void *data, int len, int *actual_length, int timeout);
82704 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82705diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82706index e452ba6..78f8e80 100644
82707--- a/include/linux/usb/renesas_usbhs.h
82708+++ b/include/linux/usb/renesas_usbhs.h
82709@@ -39,7 +39,7 @@ enum {
82710 */
82711 struct renesas_usbhs_driver_callback {
82712 int (*notify_hotplug)(struct platform_device *pdev);
82713-};
82714+} __no_const;
82715
82716 /*
82717 * callback functions for platform
82718diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82719index 4836ba3..603f6ee 100644
82720--- a/include/linux/user_namespace.h
82721+++ b/include/linux/user_namespace.h
82722@@ -33,7 +33,7 @@ struct user_namespace {
82723 struct key *persistent_keyring_register;
82724 struct rw_semaphore persistent_keyring_register_sem;
82725 #endif
82726-};
82727+} __randomize_layout;
82728
82729 extern struct user_namespace init_user_ns;
82730
82731diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82732index 239e277..22a5cf5 100644
82733--- a/include/linux/utsname.h
82734+++ b/include/linux/utsname.h
82735@@ -24,7 +24,7 @@ struct uts_namespace {
82736 struct new_utsname name;
82737 struct user_namespace *user_ns;
82738 unsigned int proc_inum;
82739-};
82740+} __randomize_layout;
82741 extern struct uts_namespace init_uts_ns;
82742
82743 #ifdef CONFIG_UTS_NS
82744diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82745index 6f8fbcf..4efc177 100644
82746--- a/include/linux/vermagic.h
82747+++ b/include/linux/vermagic.h
82748@@ -25,9 +25,42 @@
82749 #define MODULE_ARCH_VERMAGIC ""
82750 #endif
82751
82752+#ifdef CONFIG_PAX_REFCOUNT
82753+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82754+#else
82755+#define MODULE_PAX_REFCOUNT ""
82756+#endif
82757+
82758+#ifdef CONSTIFY_PLUGIN
82759+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82760+#else
82761+#define MODULE_CONSTIFY_PLUGIN ""
82762+#endif
82763+
82764+#ifdef STACKLEAK_PLUGIN
82765+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82766+#else
82767+#define MODULE_STACKLEAK_PLUGIN ""
82768+#endif
82769+
82770+#ifdef RANDSTRUCT_PLUGIN
82771+#include <generated/randomize_layout_hash.h>
82772+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82773+#else
82774+#define MODULE_RANDSTRUCT_PLUGIN
82775+#endif
82776+
82777+#ifdef CONFIG_GRKERNSEC
82778+#define MODULE_GRSEC "GRSEC "
82779+#else
82780+#define MODULE_GRSEC ""
82781+#endif
82782+
82783 #define VERMAGIC_STRING \
82784 UTS_RELEASE " " \
82785 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82786 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82787- MODULE_ARCH_VERMAGIC
82788+ MODULE_ARCH_VERMAGIC \
82789+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82790+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82791
82792diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82793index 502073a..a7de024 100644
82794--- a/include/linux/vga_switcheroo.h
82795+++ b/include/linux/vga_switcheroo.h
82796@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82797
82798 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82799
82800-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82801-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82802+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82803+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82804 #else
82805
82806 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82807@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82808
82809 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82810
82811-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82812-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82813+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82814+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82815
82816 #endif
82817 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82818diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82819index 4b8a891..cb8df6e 100644
82820--- a/include/linux/vmalloc.h
82821+++ b/include/linux/vmalloc.h
82822@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82823 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82824 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82825 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82826+
82827+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82828+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82829+#endif
82830+
82831 /* bits [20..32] reserved for arch specific ioremap internals */
82832
82833 /*
82834@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82835
82836 /* for /dev/kmem */
82837 extern long vread(char *buf, char *addr, unsigned long count);
82838-extern long vwrite(char *buf, char *addr, unsigned long count);
82839+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82840
82841 /*
82842 * Internals. Dont't use..
82843diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82844index 67ce70c..d540954 100644
82845--- a/include/linux/vmstat.h
82846+++ b/include/linux/vmstat.h
82847@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82848 /*
82849 * Zone based page accounting with per cpu differentials.
82850 */
82851-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82852+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82853
82854 static inline void zone_page_state_add(long x, struct zone *zone,
82855 enum zone_stat_item item)
82856 {
82857- atomic_long_add(x, &zone->vm_stat[item]);
82858- atomic_long_add(x, &vm_stat[item]);
82859+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82860+ atomic_long_add_unchecked(x, &vm_stat[item]);
82861 }
82862
82863-static inline unsigned long global_page_state(enum zone_stat_item item)
82864+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82865 {
82866- long x = atomic_long_read(&vm_stat[item]);
82867+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82868 #ifdef CONFIG_SMP
82869 if (x < 0)
82870 x = 0;
82871@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82872 return x;
82873 }
82874
82875-static inline unsigned long zone_page_state(struct zone *zone,
82876+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82877 enum zone_stat_item item)
82878 {
82879- long x = atomic_long_read(&zone->vm_stat[item]);
82880+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82881 #ifdef CONFIG_SMP
82882 if (x < 0)
82883 x = 0;
82884@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82885 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82886 enum zone_stat_item item)
82887 {
82888- long x = atomic_long_read(&zone->vm_stat[item]);
82889+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82890
82891 #ifdef CONFIG_SMP
82892 int cpu;
82893@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82894
82895 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82896 {
82897- atomic_long_inc(&zone->vm_stat[item]);
82898- atomic_long_inc(&vm_stat[item]);
82899+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
82900+ atomic_long_inc_unchecked(&vm_stat[item]);
82901 }
82902
82903 static inline void __inc_zone_page_state(struct page *page,
82904@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
82905
82906 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82907 {
82908- atomic_long_dec(&zone->vm_stat[item]);
82909- atomic_long_dec(&vm_stat[item]);
82910+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
82911+ atomic_long_dec_unchecked(&vm_stat[item]);
82912 }
82913
82914 static inline void __dec_zone_page_state(struct page *page,
82915diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82916index 91b0a68..0e9adf6 100644
82917--- a/include/linux/xattr.h
82918+++ b/include/linux/xattr.h
82919@@ -28,7 +28,7 @@ struct xattr_handler {
82920 size_t size, int handler_flags);
82921 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82922 size_t size, int flags, int handler_flags);
82923-};
82924+} __do_const;
82925
82926 struct xattr {
82927 const char *name;
82928@@ -37,6 +37,9 @@ struct xattr {
82929 };
82930
82931 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82932+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82933+ssize_t pax_getxattr(struct dentry *, void *, size_t);
82934+#endif
82935 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82936 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82937 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82938diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82939index 9c5a6b4..09c9438 100644
82940--- a/include/linux/zlib.h
82941+++ b/include/linux/zlib.h
82942@@ -31,6 +31,7 @@
82943 #define _ZLIB_H
82944
82945 #include <linux/zconf.h>
82946+#include <linux/compiler.h>
82947
82948 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82949 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82950@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82951
82952 /* basic functions */
82953
82954-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82955+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82956 /*
82957 Returns the number of bytes that needs to be allocated for a per-
82958 stream workspace with the specified parameters. A pointer to this
82959diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82960index c768c9f..bdcaa5a 100644
82961--- a/include/media/v4l2-dev.h
82962+++ b/include/media/v4l2-dev.h
82963@@ -76,7 +76,7 @@ struct v4l2_file_operations {
82964 int (*mmap) (struct file *, struct vm_area_struct *);
82965 int (*open) (struct file *);
82966 int (*release) (struct file *);
82967-};
82968+} __do_const;
82969
82970 /*
82971 * Newer version of video_device, handled by videodev2.c
82972diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82973index c9b1593..a572459 100644
82974--- a/include/media/v4l2-device.h
82975+++ b/include/media/v4l2-device.h
82976@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82977 this function returns 0. If the name ends with a digit (e.g. cx18),
82978 then the name will be set to cx18-0 since cx180 looks really odd. */
82979 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82980- atomic_t *instance);
82981+ atomic_unchecked_t *instance);
82982
82983 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82984 Since the parent disappears this ensures that v4l2_dev doesn't have an
82985diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82986index 9a36d92..0aafe2a 100644
82987--- a/include/net/9p/transport.h
82988+++ b/include/net/9p/transport.h
82989@@ -60,7 +60,7 @@ struct p9_trans_module {
82990 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82991 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82992 char *, char *, int , int, int, int);
82993-};
82994+} __do_const;
82995
82996 void v9fs_register_trans(struct p9_trans_module *m);
82997 void v9fs_unregister_trans(struct p9_trans_module *m);
82998diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82999index a175ba4..196eb82 100644
83000--- a/include/net/af_unix.h
83001+++ b/include/net/af_unix.h
83002@@ -36,7 +36,7 @@ struct unix_skb_parms {
83003 u32 secid; /* Security ID */
83004 #endif
83005 u32 consumed;
83006-};
83007+} __randomize_layout;
83008
83009 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83010 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83011diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83012index dbc4a89..4a59b5d 100644
83013--- a/include/net/bluetooth/l2cap.h
83014+++ b/include/net/bluetooth/l2cap.h
83015@@ -600,7 +600,7 @@ struct l2cap_ops {
83016 long (*get_sndtimeo) (struct l2cap_chan *chan);
83017 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83018 unsigned long len, int nb);
83019-};
83020+} __do_const;
83021
83022 struct l2cap_conn {
83023 struct hci_conn *hcon;
83024diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83025index f2ae33d..c457cf0 100644
83026--- a/include/net/caif/cfctrl.h
83027+++ b/include/net/caif/cfctrl.h
83028@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83029 void (*radioset_rsp)(void);
83030 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83031 struct cflayer *client_layer);
83032-};
83033+} __no_const;
83034
83035 /* Link Setup Parameters for CAIF-Links. */
83036 struct cfctrl_link_param {
83037@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83038 struct cfctrl {
83039 struct cfsrvl serv;
83040 struct cfctrl_rsp res;
83041- atomic_t req_seq_no;
83042- atomic_t rsp_seq_no;
83043+ atomic_unchecked_t req_seq_no;
83044+ atomic_unchecked_t rsp_seq_no;
83045 struct list_head list;
83046 /* Protects from simultaneous access to first_req list */
83047 spinlock_t info_list_lock;
83048diff --git a/include/net/flow.h b/include/net/flow.h
83049index d23e7fa..e188307 100644
83050--- a/include/net/flow.h
83051+++ b/include/net/flow.h
83052@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83053
83054 void flow_cache_flush(void);
83055 void flow_cache_flush_deferred(void);
83056-extern atomic_t flow_cache_genid;
83057+extern atomic_unchecked_t flow_cache_genid;
83058
83059 #endif
83060diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83061index 93695f0..766d71c 100644
83062--- a/include/net/genetlink.h
83063+++ b/include/net/genetlink.h
83064@@ -120,7 +120,7 @@ struct genl_ops {
83065 u8 cmd;
83066 u8 internal_flags;
83067 u8 flags;
83068-};
83069+} __do_const;
83070
83071 int __genl_register_family(struct genl_family *family);
83072
83073diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83074index 734d9b5..48a9a4b 100644
83075--- a/include/net/gro_cells.h
83076+++ b/include/net/gro_cells.h
83077@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83078 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83079
83080 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83081- atomic_long_inc(&dev->rx_dropped);
83082+ atomic_long_inc_unchecked(&dev->rx_dropped);
83083 kfree_skb(skb);
83084 return;
83085 }
83086diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83087index c55aeed..b3393f4 100644
83088--- a/include/net/inet_connection_sock.h
83089+++ b/include/net/inet_connection_sock.h
83090@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83091 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83092 int (*bind_conflict)(const struct sock *sk,
83093 const struct inet_bind_bucket *tb, bool relax);
83094-};
83095+} __do_const;
83096
83097 /** inet_connection_sock - INET connection oriented sock
83098 *
83099diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83100index 6efe73c..fa94270 100644
83101--- a/include/net/inetpeer.h
83102+++ b/include/net/inetpeer.h
83103@@ -47,8 +47,8 @@ struct inet_peer {
83104 */
83105 union {
83106 struct {
83107- atomic_t rid; /* Frag reception counter */
83108- atomic_t ip_id_count; /* IP ID for the next packet */
83109+ atomic_unchecked_t rid; /* Frag reception counter */
83110+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83111 };
83112 struct rcu_head rcu;
83113 struct inet_peer *gc_next;
83114@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83115 /* can be called with or without local BH being disabled */
83116 static inline int inet_getid(struct inet_peer *p, int more)
83117 {
83118- int old, new;
83119+ int id;
83120 more++;
83121 inet_peer_refcheck(p);
83122- do {
83123- old = atomic_read(&p->ip_id_count);
83124- new = old + more;
83125- if (!new)
83126- new = 1;
83127- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83128- return new;
83129+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83130+ if (!id)
83131+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83132+ return id;
83133 }
83134
83135 #endif /* _NET_INETPEER_H */
83136diff --git a/include/net/ip.h b/include/net/ip.h
83137index 23be0fd..0cb3e2c 100644
83138--- a/include/net/ip.h
83139+++ b/include/net/ip.h
83140@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83141
83142 void inet_get_local_port_range(struct net *net, int *low, int *high);
83143
83144-extern unsigned long *sysctl_local_reserved_ports;
83145+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83146 static inline int inet_is_reserved_local_port(int port)
83147 {
83148 return test_bit(port, sysctl_local_reserved_ports);
83149diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83150index 9922093..a1755d6 100644
83151--- a/include/net/ip_fib.h
83152+++ b/include/net/ip_fib.h
83153@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83154
83155 #define FIB_RES_SADDR(net, res) \
83156 ((FIB_RES_NH(res).nh_saddr_genid == \
83157- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83158+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83159 FIB_RES_NH(res).nh_saddr : \
83160 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83161 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83162diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83163index 5679d92..2e7a690 100644
83164--- a/include/net/ip_vs.h
83165+++ b/include/net/ip_vs.h
83166@@ -558,7 +558,7 @@ struct ip_vs_conn {
83167 struct ip_vs_conn *control; /* Master control connection */
83168 atomic_t n_control; /* Number of controlled ones */
83169 struct ip_vs_dest *dest; /* real server */
83170- atomic_t in_pkts; /* incoming packet counter */
83171+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83172
83173 /* packet transmitter for different forwarding methods. If it
83174 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83175@@ -705,7 +705,7 @@ struct ip_vs_dest {
83176 __be16 port; /* port number of the server */
83177 union nf_inet_addr addr; /* IP address of the server */
83178 volatile unsigned int flags; /* dest status flags */
83179- atomic_t conn_flags; /* flags to copy to conn */
83180+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83181 atomic_t weight; /* server weight */
83182
83183 atomic_t refcnt; /* reference counter */
83184@@ -960,11 +960,11 @@ struct netns_ipvs {
83185 /* ip_vs_lblc */
83186 int sysctl_lblc_expiration;
83187 struct ctl_table_header *lblc_ctl_header;
83188- struct ctl_table *lblc_ctl_table;
83189+ ctl_table_no_const *lblc_ctl_table;
83190 /* ip_vs_lblcr */
83191 int sysctl_lblcr_expiration;
83192 struct ctl_table_header *lblcr_ctl_header;
83193- struct ctl_table *lblcr_ctl_table;
83194+ ctl_table_no_const *lblcr_ctl_table;
83195 /* ip_vs_est */
83196 struct list_head est_list; /* estimator list */
83197 spinlock_t est_lock;
83198diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83199index 8d4f588..2e37ad2 100644
83200--- a/include/net/irda/ircomm_tty.h
83201+++ b/include/net/irda/ircomm_tty.h
83202@@ -33,6 +33,7 @@
83203 #include <linux/termios.h>
83204 #include <linux/timer.h>
83205 #include <linux/tty.h> /* struct tty_struct */
83206+#include <asm/local.h>
83207
83208 #include <net/irda/irias_object.h>
83209 #include <net/irda/ircomm_core.h>
83210diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83211index 714cc9a..ea05f3e 100644
83212--- a/include/net/iucv/af_iucv.h
83213+++ b/include/net/iucv/af_iucv.h
83214@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83215 struct iucv_sock_list {
83216 struct hlist_head head;
83217 rwlock_t lock;
83218- atomic_t autobind_name;
83219+ atomic_unchecked_t autobind_name;
83220 };
83221
83222 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83223diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83224index f3be818..bf46196 100644
83225--- a/include/net/llc_c_ac.h
83226+++ b/include/net/llc_c_ac.h
83227@@ -87,7 +87,7 @@
83228 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83229 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83230
83231-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83232+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83233
83234 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83235 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83236diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83237index 3948cf1..83b28c4 100644
83238--- a/include/net/llc_c_ev.h
83239+++ b/include/net/llc_c_ev.h
83240@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83241 return (struct llc_conn_state_ev *)skb->cb;
83242 }
83243
83244-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83245-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83246+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83247+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83248
83249 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83250 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83251diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83252index 0e79cfb..f46db31 100644
83253--- a/include/net/llc_c_st.h
83254+++ b/include/net/llc_c_st.h
83255@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83256 u8 next_state;
83257 llc_conn_ev_qfyr_t *ev_qualifiers;
83258 llc_conn_action_t *ev_actions;
83259-};
83260+} __do_const;
83261
83262 struct llc_conn_state {
83263 u8 current_state;
83264diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83265index a61b98c..aade1eb 100644
83266--- a/include/net/llc_s_ac.h
83267+++ b/include/net/llc_s_ac.h
83268@@ -23,7 +23,7 @@
83269 #define SAP_ACT_TEST_IND 9
83270
83271 /* All action functions must look like this */
83272-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83273+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83274
83275 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83276 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83277diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83278index 567c681..cd73ac0 100644
83279--- a/include/net/llc_s_st.h
83280+++ b/include/net/llc_s_st.h
83281@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83282 llc_sap_ev_t ev;
83283 u8 next_state;
83284 llc_sap_action_t *ev_actions;
83285-};
83286+} __do_const;
83287
83288 struct llc_sap_state {
83289 u8 curr_state;
83290diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83291index f4ab2fb..71a85ba 100644
83292--- a/include/net/mac80211.h
83293+++ b/include/net/mac80211.h
83294@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83295 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83296 struct dentry *dir);
83297 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83298-};
83299+} __do_const;
83300
83301 static inline int rate_supported(struct ieee80211_sta *sta,
83302 enum ieee80211_band band,
83303diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83304index 7277caf..fd095bc 100644
83305--- a/include/net/neighbour.h
83306+++ b/include/net/neighbour.h
83307@@ -163,7 +163,7 @@ struct neigh_ops {
83308 void (*error_report)(struct neighbour *, struct sk_buff *);
83309 int (*output)(struct neighbour *, struct sk_buff *);
83310 int (*connected_output)(struct neighbour *, struct sk_buff *);
83311-};
83312+} __do_const;
83313
83314 struct pneigh_entry {
83315 struct pneigh_entry *next;
83316@@ -203,7 +203,6 @@ struct neigh_table {
83317 void (*proxy_redo)(struct sk_buff *skb);
83318 char *id;
83319 struct neigh_parms parms;
83320- /* HACK. gc_* should follow parms without a gap! */
83321 int gc_interval;
83322 int gc_thresh1;
83323 int gc_thresh2;
83324@@ -218,7 +217,7 @@ struct neigh_table {
83325 struct neigh_statistics __percpu *stats;
83326 struct neigh_hash_table __rcu *nht;
83327 struct pneigh_entry **phash_buckets;
83328-};
83329+} __randomize_layout;
83330
83331 static inline int neigh_parms_family(struct neigh_parms *p)
83332 {
83333diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83334index 991dcd9..ab58d00 100644
83335--- a/include/net/net_namespace.h
83336+++ b/include/net/net_namespace.h
83337@@ -124,8 +124,8 @@ struct net {
83338 struct netns_ipvs *ipvs;
83339 #endif
83340 struct sock *diag_nlsk;
83341- atomic_t fnhe_genid;
83342-};
83343+ atomic_unchecked_t fnhe_genid;
83344+} __randomize_layout;
83345
83346 /*
83347 * ifindex generation is per-net namespace, and loopback is
83348@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83349 #define __net_init __init
83350 #define __net_exit __exit_refok
83351 #define __net_initdata __initdata
83352+#ifdef CONSTIFY_PLUGIN
83353 #define __net_initconst __initconst
83354+#else
83355+#define __net_initconst __initdata
83356+#endif
83357 #endif
83358
83359 struct pernet_operations {
83360@@ -299,7 +303,7 @@ struct pernet_operations {
83361 void (*exit_batch)(struct list_head *net_exit_list);
83362 int *id;
83363 size_t size;
83364-};
83365+} __do_const;
83366
83367 /*
83368 * Use these carefully. If you implement a network device and it
83369@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83370
83371 static inline int rt_genid_ipv4(struct net *net)
83372 {
83373- return atomic_read(&net->ipv4.rt_genid);
83374+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83375 }
83376
83377 static inline void rt_genid_bump_ipv4(struct net *net)
83378 {
83379- atomic_inc(&net->ipv4.rt_genid);
83380+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83381 }
83382
83383 #if IS_ENABLED(CONFIG_IPV6)
83384 static inline int rt_genid_ipv6(struct net *net)
83385 {
83386- return atomic_read(&net->ipv6.rt_genid);
83387+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83388 }
83389
83390 static inline void rt_genid_bump_ipv6(struct net *net)
83391 {
83392- atomic_inc(&net->ipv6.rt_genid);
83393+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83394 }
83395 #else
83396 static inline int rt_genid_ipv6(struct net *net)
83397@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83398
83399 static inline int fnhe_genid(struct net *net)
83400 {
83401- return atomic_read(&net->fnhe_genid);
83402+ return atomic_read_unchecked(&net->fnhe_genid);
83403 }
83404
83405 static inline void fnhe_genid_bump(struct net *net)
83406 {
83407- atomic_inc(&net->fnhe_genid);
83408+ atomic_inc_unchecked(&net->fnhe_genid);
83409 }
83410
83411 #endif /* __NET_NET_NAMESPACE_H */
83412diff --git a/include/net/netdma.h b/include/net/netdma.h
83413index 8ba8ce2..99b7fff 100644
83414--- a/include/net/netdma.h
83415+++ b/include/net/netdma.h
83416@@ -24,7 +24,7 @@
83417 #include <linux/dmaengine.h>
83418 #include <linux/skbuff.h>
83419
83420-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83421+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83422 struct sk_buff *skb, int offset, struct iovec *to,
83423 size_t len, struct dma_pinned_list *pinned_list);
83424
83425diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83426index 956b175..55d1504 100644
83427--- a/include/net/netfilter/nf_conntrack_extend.h
83428+++ b/include/net/netfilter/nf_conntrack_extend.h
83429@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83430 /* Extensions: optional stuff which isn't permanently in struct. */
83431 struct nf_ct_ext {
83432 struct rcu_head rcu;
83433- u8 offset[NF_CT_EXT_NUM];
83434- u8 len;
83435+ u16 offset[NF_CT_EXT_NUM];
83436+ u16 len;
83437 char data[0];
83438 };
83439
83440diff --git a/include/net/netlink.h b/include/net/netlink.h
83441index 2b47eaa..6d5bcc2 100644
83442--- a/include/net/netlink.h
83443+++ b/include/net/netlink.h
83444@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83445 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83446 {
83447 if (mark)
83448- skb_trim(skb, (unsigned char *) mark - skb->data);
83449+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83450 }
83451
83452 /**
83453diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83454index fbcc7fa..03c7e51 100644
83455--- a/include/net/netns/conntrack.h
83456+++ b/include/net/netns/conntrack.h
83457@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83458 struct nf_proto_net {
83459 #ifdef CONFIG_SYSCTL
83460 struct ctl_table_header *ctl_table_header;
83461- struct ctl_table *ctl_table;
83462+ ctl_table_no_const *ctl_table;
83463 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83464 struct ctl_table_header *ctl_compat_header;
83465- struct ctl_table *ctl_compat_table;
83466+ ctl_table_no_const *ctl_compat_table;
83467 #endif
83468 #endif
83469 unsigned int users;
83470@@ -58,7 +58,7 @@ struct nf_ip_net {
83471 struct nf_icmp_net icmpv6;
83472 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83473 struct ctl_table_header *ctl_table_header;
83474- struct ctl_table *ctl_table;
83475+ ctl_table_no_const *ctl_table;
83476 #endif
83477 };
83478
83479diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83480index 80f500a..f0c23c2 100644
83481--- a/include/net/netns/ipv4.h
83482+++ b/include/net/netns/ipv4.h
83483@@ -74,7 +74,7 @@ struct netns_ipv4 {
83484
83485 kgid_t sysctl_ping_group_range[2];
83486
83487- atomic_t dev_addr_genid;
83488+ atomic_unchecked_t dev_addr_genid;
83489
83490 #ifdef CONFIG_IP_MROUTE
83491 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83492@@ -84,6 +84,6 @@ struct netns_ipv4 {
83493 struct fib_rules_ops *mr_rules_ops;
83494 #endif
83495 #endif
83496- atomic_t rt_genid;
83497+ atomic_unchecked_t rt_genid;
83498 };
83499 #endif
83500diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83501index 21edaf1..4c5faae 100644
83502--- a/include/net/netns/ipv6.h
83503+++ b/include/net/netns/ipv6.h
83504@@ -73,8 +73,8 @@ struct netns_ipv6 {
83505 struct fib_rules_ops *mr6_rules_ops;
83506 #endif
83507 #endif
83508- atomic_t dev_addr_genid;
83509- atomic_t rt_genid;
83510+ atomic_unchecked_t dev_addr_genid;
83511+ atomic_unchecked_t rt_genid;
83512 };
83513
83514 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83515diff --git a/include/net/ping.h b/include/net/ping.h
83516index 026479b..d9b2829 100644
83517--- a/include/net/ping.h
83518+++ b/include/net/ping.h
83519@@ -54,7 +54,7 @@ struct ping_iter_state {
83520
83521 extern struct proto ping_prot;
83522 #if IS_ENABLED(CONFIG_IPV6)
83523-extern struct pingv6_ops pingv6_ops;
83524+extern struct pingv6_ops *pingv6_ops;
83525 #endif
83526
83527 struct pingfakehdr {
83528diff --git a/include/net/protocol.h b/include/net/protocol.h
83529index a7e986b..dc67bce 100644
83530--- a/include/net/protocol.h
83531+++ b/include/net/protocol.h
83532@@ -49,7 +49,7 @@ struct net_protocol {
83533 * socket lookup?
83534 */
83535 icmp_strict_tag_validation:1;
83536-};
83537+} __do_const;
83538
83539 #if IS_ENABLED(CONFIG_IPV6)
83540 struct inet6_protocol {
83541@@ -62,7 +62,7 @@ struct inet6_protocol {
83542 u8 type, u8 code, int offset,
83543 __be32 info);
83544 unsigned int flags; /* INET6_PROTO_xxx */
83545-};
83546+} __do_const;
83547
83548 #define INET6_PROTO_NOPOLICY 0x1
83549 #define INET6_PROTO_FINAL 0x2
83550diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83551index 661e45d..54c39df 100644
83552--- a/include/net/rtnetlink.h
83553+++ b/include/net/rtnetlink.h
83554@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83555 int (*fill_slave_info)(struct sk_buff *skb,
83556 const struct net_device *dev,
83557 const struct net_device *slave_dev);
83558-};
83559+} __do_const;
83560
83561 int __rtnl_link_register(struct rtnl_link_ops *ops);
83562 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83563diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83564index 4a5b9a3..ca27d73 100644
83565--- a/include/net/sctp/checksum.h
83566+++ b/include/net/sctp/checksum.h
83567@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83568 unsigned int offset)
83569 {
83570 struct sctphdr *sh = sctp_hdr(skb);
83571- __le32 ret, old = sh->checksum;
83572- const struct skb_checksum_ops ops = {
83573+ __le32 ret, old = sh->checksum;
83574+ static const struct skb_checksum_ops ops = {
83575 .update = sctp_csum_update,
83576 .combine = sctp_csum_combine,
83577 };
83578diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83579index 7f4eeb3..37e8fe1 100644
83580--- a/include/net/sctp/sm.h
83581+++ b/include/net/sctp/sm.h
83582@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83583 typedef struct {
83584 sctp_state_fn_t *fn;
83585 const char *name;
83586-} sctp_sm_table_entry_t;
83587+} __do_const sctp_sm_table_entry_t;
83588
83589 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83590 * currently in use.
83591@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83592 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83593
83594 /* Extern declarations for major data structures. */
83595-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83596+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83597
83598
83599 /* Get the size of a DATA chunk payload. */
83600diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83601index 6ee76c8..45f2609 100644
83602--- a/include/net/sctp/structs.h
83603+++ b/include/net/sctp/structs.h
83604@@ -507,7 +507,7 @@ struct sctp_pf {
83605 struct sctp_association *asoc);
83606 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83607 struct sctp_af *af;
83608-};
83609+} __do_const;
83610
83611
83612 /* Structure to track chunk fragments that have been acked, but peer
83613diff --git a/include/net/sock.h b/include/net/sock.h
83614index b9586a1..b2948c0 100644
83615--- a/include/net/sock.h
83616+++ b/include/net/sock.h
83617@@ -348,7 +348,7 @@ struct sock {
83618 unsigned int sk_napi_id;
83619 unsigned int sk_ll_usec;
83620 #endif
83621- atomic_t sk_drops;
83622+ atomic_unchecked_t sk_drops;
83623 int sk_rcvbuf;
83624
83625 struct sk_filter __rcu *sk_filter;
83626@@ -1036,7 +1036,7 @@ struct proto {
83627 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83628 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83629 #endif
83630-};
83631+} __randomize_layout;
83632
83633 /*
83634 * Bits in struct cg_proto.flags
83635@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83636 return ret >> PAGE_SHIFT;
83637 }
83638
83639-static inline long
83640+static inline long __intentional_overflow(-1)
83641 sk_memory_allocated(const struct sock *sk)
83642 {
83643 struct proto *prot = sk->sk_prot;
83644@@ -1368,7 +1368,7 @@ struct sock_iocb {
83645 struct scm_cookie *scm;
83646 struct msghdr *msg, async_msg;
83647 struct kiocb *kiocb;
83648-};
83649+} __randomize_layout;
83650
83651 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83652 {
83653@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83654 }
83655
83656 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83657- char __user *from, char *to,
83658+ char __user *from, unsigned char *to,
83659 int copy, int offset)
83660 {
83661 if (skb->ip_summed == CHECKSUM_NONE) {
83662@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83663 }
83664 }
83665
83666-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83667+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83668
83669 /**
83670 * sk_page_frag - return an appropriate page_frag
83671diff --git a/include/net/tcp.h b/include/net/tcp.h
83672index 743acce..44a58b0 100644
83673--- a/include/net/tcp.h
83674+++ b/include/net/tcp.h
83675@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83676 void tcp_xmit_retransmit_queue(struct sock *);
83677 void tcp_simple_retransmit(struct sock *);
83678 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83679-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83680+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83681
83682 void tcp_send_probe0(struct sock *);
83683 void tcp_send_partial(struct sock *);
83684@@ -710,8 +710,8 @@ struct tcp_skb_cb {
83685 struct inet6_skb_parm h6;
83686 #endif
83687 } header; /* For incoming frames */
83688- __u32 seq; /* Starting sequence number */
83689- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83690+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83691+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83692 __u32 when; /* used to compute rtt's */
83693 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83694
83695@@ -725,7 +725,7 @@ struct tcp_skb_cb {
83696
83697 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83698 /* 1 byte hole */
83699- __u32 ack_seq; /* Sequence number ACK'd */
83700+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83701 };
83702
83703 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83704diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83705index fb5654a..4457522 100644
83706--- a/include/net/xfrm.h
83707+++ b/include/net/xfrm.h
83708@@ -286,7 +286,6 @@ struct xfrm_dst;
83709 struct xfrm_policy_afinfo {
83710 unsigned short family;
83711 struct dst_ops *dst_ops;
83712- void (*garbage_collect)(struct net *net);
83713 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83714 const xfrm_address_t *saddr,
83715 const xfrm_address_t *daddr);
83716@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83717 struct net_device *dev,
83718 const struct flowi *fl);
83719 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83720-};
83721+} __do_const;
83722
83723 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83724 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83725@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83726 int (*transport_finish)(struct sk_buff *skb,
83727 int async);
83728 void (*local_error)(struct sk_buff *skb, u32 mtu);
83729-};
83730+} __do_const;
83731
83732 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83733 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83734@@ -428,7 +427,7 @@ struct xfrm_mode {
83735 struct module *owner;
83736 unsigned int encap;
83737 int flags;
83738-};
83739+} __do_const;
83740
83741 /* Flags for xfrm_mode. */
83742 enum {
83743@@ -525,7 +524,7 @@ struct xfrm_policy {
83744 struct timer_list timer;
83745
83746 struct flow_cache_object flo;
83747- atomic_t genid;
83748+ atomic_unchecked_t genid;
83749 u32 priority;
83750 u32 index;
83751 struct xfrm_mark mark;
83752@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83753 }
83754
83755 void xfrm_garbage_collect(struct net *net);
83756+void xfrm_garbage_collect_deferred(struct net *net);
83757
83758 #else
83759
83760@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83761 static inline void xfrm_garbage_collect(struct net *net)
83762 {
83763 }
83764+static inline void xfrm_garbage_collect_deferred(struct net *net)
83765+{
83766+}
83767 #endif
83768
83769 static __inline__
83770diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83771index 1017e0b..227aa4d 100644
83772--- a/include/rdma/iw_cm.h
83773+++ b/include/rdma/iw_cm.h
83774@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83775 int backlog);
83776
83777 int (*destroy_listen)(struct iw_cm_id *cm_id);
83778-};
83779+} __no_const;
83780
83781 /**
83782 * iw_create_cm_id - Create an IW CM identifier.
83783diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83784index 52beadf..598734c 100644
83785--- a/include/scsi/libfc.h
83786+++ b/include/scsi/libfc.h
83787@@ -771,6 +771,7 @@ struct libfc_function_template {
83788 */
83789 void (*disc_stop_final) (struct fc_lport *);
83790 };
83791+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83792
83793 /**
83794 * struct fc_disc - Discovery context
83795@@ -875,7 +876,7 @@ struct fc_lport {
83796 struct fc_vport *vport;
83797
83798 /* Operational Information */
83799- struct libfc_function_template tt;
83800+ libfc_function_template_no_const tt;
83801 u8 link_up;
83802 u8 qfull;
83803 enum fc_lport_state state;
83804diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83805index d65fbec..f80fef2 100644
83806--- a/include/scsi/scsi_device.h
83807+++ b/include/scsi/scsi_device.h
83808@@ -180,9 +180,9 @@ struct scsi_device {
83809 unsigned int max_device_blocked; /* what device_blocked counts down from */
83810 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83811
83812- atomic_t iorequest_cnt;
83813- atomic_t iodone_cnt;
83814- atomic_t ioerr_cnt;
83815+ atomic_unchecked_t iorequest_cnt;
83816+ atomic_unchecked_t iodone_cnt;
83817+ atomic_unchecked_t ioerr_cnt;
83818
83819 struct device sdev_gendev,
83820 sdev_dev;
83821diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83822index b797e8f..8e2c3aa 100644
83823--- a/include/scsi/scsi_transport_fc.h
83824+++ b/include/scsi/scsi_transport_fc.h
83825@@ -751,7 +751,8 @@ struct fc_function_template {
83826 unsigned long show_host_system_hostname:1;
83827
83828 unsigned long disable_target_scan:1;
83829-};
83830+} __do_const;
83831+typedef struct fc_function_template __no_const fc_function_template_no_const;
83832
83833
83834 /**
83835diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83836index ae6c3b8..fd748ac 100644
83837--- a/include/sound/compress_driver.h
83838+++ b/include/sound/compress_driver.h
83839@@ -128,7 +128,7 @@ struct snd_compr_ops {
83840 struct snd_compr_caps *caps);
83841 int (*get_codec_caps) (struct snd_compr_stream *stream,
83842 struct snd_compr_codec_caps *codec);
83843-};
83844+} __no_const;
83845
83846 /**
83847 * struct snd_compr: Compressed device
83848diff --git a/include/sound/soc.h b/include/sound/soc.h
83849index 9a00147..d814573 100644
83850--- a/include/sound/soc.h
83851+++ b/include/sound/soc.h
83852@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83853 /* probe ordering - for components with runtime dependencies */
83854 int probe_order;
83855 int remove_order;
83856-};
83857+} __do_const;
83858
83859 /* SoC platform interface */
83860 struct snd_soc_platform_driver {
83861@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83862 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83863 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83864 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83865-};
83866+} __do_const;
83867
83868 struct snd_soc_platform {
83869 const char *name;
83870diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83871index 1772fad..282e3e2 100644
83872--- a/include/target/target_core_base.h
83873+++ b/include/target/target_core_base.h
83874@@ -754,7 +754,7 @@ struct se_device {
83875 atomic_long_t write_bytes;
83876 /* Active commands on this virtual SE device */
83877 atomic_t simple_cmds;
83878- atomic_t dev_ordered_id;
83879+ atomic_unchecked_t dev_ordered_id;
83880 atomic_t dev_ordered_sync;
83881 atomic_t dev_qf_count;
83882 int export_count;
83883diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83884new file mode 100644
83885index 0000000..fb634b7
83886--- /dev/null
83887+++ b/include/trace/events/fs.h
83888@@ -0,0 +1,53 @@
83889+#undef TRACE_SYSTEM
83890+#define TRACE_SYSTEM fs
83891+
83892+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83893+#define _TRACE_FS_H
83894+
83895+#include <linux/fs.h>
83896+#include <linux/tracepoint.h>
83897+
83898+TRACE_EVENT(do_sys_open,
83899+
83900+ TP_PROTO(const char *filename, int flags, int mode),
83901+
83902+ TP_ARGS(filename, flags, mode),
83903+
83904+ TP_STRUCT__entry(
83905+ __string( filename, filename )
83906+ __field( int, flags )
83907+ __field( int, mode )
83908+ ),
83909+
83910+ TP_fast_assign(
83911+ __assign_str(filename, filename);
83912+ __entry->flags = flags;
83913+ __entry->mode = mode;
83914+ ),
83915+
83916+ TP_printk("\"%s\" %x %o",
83917+ __get_str(filename), __entry->flags, __entry->mode)
83918+);
83919+
83920+TRACE_EVENT(open_exec,
83921+
83922+ TP_PROTO(const char *filename),
83923+
83924+ TP_ARGS(filename),
83925+
83926+ TP_STRUCT__entry(
83927+ __string( filename, filename )
83928+ ),
83929+
83930+ TP_fast_assign(
83931+ __assign_str(filename, filename);
83932+ ),
83933+
83934+ TP_printk("\"%s\"",
83935+ __get_str(filename))
83936+);
83937+
83938+#endif /* _TRACE_FS_H */
83939+
83940+/* This part must be outside protection */
83941+#include <trace/define_trace.h>
83942diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83943index 1c09820..7f5ec79 100644
83944--- a/include/trace/events/irq.h
83945+++ b/include/trace/events/irq.h
83946@@ -36,7 +36,7 @@ struct softirq_action;
83947 */
83948 TRACE_EVENT(irq_handler_entry,
83949
83950- TP_PROTO(int irq, struct irqaction *action),
83951+ TP_PROTO(int irq, const struct irqaction *action),
83952
83953 TP_ARGS(irq, action),
83954
83955@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83956 */
83957 TRACE_EVENT(irq_handler_exit,
83958
83959- TP_PROTO(int irq, struct irqaction *action, int ret),
83960+ TP_PROTO(int irq, const struct irqaction *action, int ret),
83961
83962 TP_ARGS(irq, action, ret),
83963
83964diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83965index 7caf44c..23c6f27 100644
83966--- a/include/uapi/linux/a.out.h
83967+++ b/include/uapi/linux/a.out.h
83968@@ -39,6 +39,14 @@ enum machine_type {
83969 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83970 };
83971
83972+/* Constants for the N_FLAGS field */
83973+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83974+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83975+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83976+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83977+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83978+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83979+
83980 #if !defined (N_MAGIC)
83981 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83982 #endif
83983diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83984index 22b6ad3..aeba37e 100644
83985--- a/include/uapi/linux/bcache.h
83986+++ b/include/uapi/linux/bcache.h
83987@@ -5,6 +5,7 @@
83988 * Bcache on disk data structures
83989 */
83990
83991+#include <linux/compiler.h>
83992 #include <asm/types.h>
83993
83994 #define BITMASK(name, type, field, offset, size) \
83995@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83996 /* Btree keys - all units are in sectors */
83997
83998 struct bkey {
83999- __u64 high;
84000- __u64 low;
84001+ __u64 high __intentional_overflow(-1);
84002+ __u64 low __intentional_overflow(-1);
84003 __u64 ptr[];
84004 };
84005
84006diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84007index d876736..ccce5c0 100644
84008--- a/include/uapi/linux/byteorder/little_endian.h
84009+++ b/include/uapi/linux/byteorder/little_endian.h
84010@@ -42,51 +42,51 @@
84011
84012 static inline __le64 __cpu_to_le64p(const __u64 *p)
84013 {
84014- return (__force __le64)*p;
84015+ return (__force const __le64)*p;
84016 }
84017-static inline __u64 __le64_to_cpup(const __le64 *p)
84018+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84019 {
84020- return (__force __u64)*p;
84021+ return (__force const __u64)*p;
84022 }
84023 static inline __le32 __cpu_to_le32p(const __u32 *p)
84024 {
84025- return (__force __le32)*p;
84026+ return (__force const __le32)*p;
84027 }
84028 static inline __u32 __le32_to_cpup(const __le32 *p)
84029 {
84030- return (__force __u32)*p;
84031+ return (__force const __u32)*p;
84032 }
84033 static inline __le16 __cpu_to_le16p(const __u16 *p)
84034 {
84035- return (__force __le16)*p;
84036+ return (__force const __le16)*p;
84037 }
84038 static inline __u16 __le16_to_cpup(const __le16 *p)
84039 {
84040- return (__force __u16)*p;
84041+ return (__force const __u16)*p;
84042 }
84043 static inline __be64 __cpu_to_be64p(const __u64 *p)
84044 {
84045- return (__force __be64)__swab64p(p);
84046+ return (__force const __be64)__swab64p(p);
84047 }
84048 static inline __u64 __be64_to_cpup(const __be64 *p)
84049 {
84050- return __swab64p((__u64 *)p);
84051+ return __swab64p((const __u64 *)p);
84052 }
84053 static inline __be32 __cpu_to_be32p(const __u32 *p)
84054 {
84055- return (__force __be32)__swab32p(p);
84056+ return (__force const __be32)__swab32p(p);
84057 }
84058-static inline __u32 __be32_to_cpup(const __be32 *p)
84059+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84060 {
84061- return __swab32p((__u32 *)p);
84062+ return __swab32p((const __u32 *)p);
84063 }
84064 static inline __be16 __cpu_to_be16p(const __u16 *p)
84065 {
84066- return (__force __be16)__swab16p(p);
84067+ return (__force const __be16)__swab16p(p);
84068 }
84069 static inline __u16 __be16_to_cpup(const __be16 *p)
84070 {
84071- return __swab16p((__u16 *)p);
84072+ return __swab16p((const __u16 *)p);
84073 }
84074 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84075 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84076diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84077index ef6103b..d4e65dd 100644
84078--- a/include/uapi/linux/elf.h
84079+++ b/include/uapi/linux/elf.h
84080@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84081 #define PT_GNU_EH_FRAME 0x6474e550
84082
84083 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84084+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84085+
84086+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84087+
84088+/* Constants for the e_flags field */
84089+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84090+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84091+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84092+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84093+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84094+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84095
84096 /*
84097 * Extended Numbering
84098@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84099 #define DT_DEBUG 21
84100 #define DT_TEXTREL 22
84101 #define DT_JMPREL 23
84102+#define DT_FLAGS 30
84103+ #define DF_TEXTREL 0x00000004
84104 #define DT_ENCODING 32
84105 #define OLD_DT_LOOS 0x60000000
84106 #define DT_LOOS 0x6000000d
84107@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84108 #define PF_W 0x2
84109 #define PF_X 0x1
84110
84111+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84112+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84113+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84114+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84115+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84116+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84117+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84118+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84119+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84120+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84121+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84122+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84123+
84124 typedef struct elf32_phdr{
84125 Elf32_Word p_type;
84126 Elf32_Off p_offset;
84127@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84128 #define EI_OSABI 7
84129 #define EI_PAD 8
84130
84131+#define EI_PAX 14
84132+
84133 #define ELFMAG0 0x7f /* EI_MAG */
84134 #define ELFMAG1 'E'
84135 #define ELFMAG2 'L'
84136diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84137index aa169c4..6a2771d 100644
84138--- a/include/uapi/linux/personality.h
84139+++ b/include/uapi/linux/personality.h
84140@@ -30,6 +30,7 @@ enum {
84141 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84142 ADDR_NO_RANDOMIZE | \
84143 ADDR_COMPAT_LAYOUT | \
84144+ ADDR_LIMIT_3GB | \
84145 MMAP_PAGE_ZERO)
84146
84147 /*
84148diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84149index 7530e74..e714828 100644
84150--- a/include/uapi/linux/screen_info.h
84151+++ b/include/uapi/linux/screen_info.h
84152@@ -43,7 +43,8 @@ struct screen_info {
84153 __u16 pages; /* 0x32 */
84154 __u16 vesa_attributes; /* 0x34 */
84155 __u32 capabilities; /* 0x36 */
84156- __u8 _reserved[6]; /* 0x3a */
84157+ __u16 vesapm_size; /* 0x3a */
84158+ __u8 _reserved[4]; /* 0x3c */
84159 } __attribute__((packed));
84160
84161 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84162diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84163index 0e011eb..82681b1 100644
84164--- a/include/uapi/linux/swab.h
84165+++ b/include/uapi/linux/swab.h
84166@@ -43,7 +43,7 @@
84167 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84168 */
84169
84170-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84171+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84172 {
84173 #ifdef __HAVE_BUILTIN_BSWAP16__
84174 return __builtin_bswap16(val);
84175@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84176 #endif
84177 }
84178
84179-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84180+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84181 {
84182 #ifdef __HAVE_BUILTIN_BSWAP32__
84183 return __builtin_bswap32(val);
84184@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84185 #endif
84186 }
84187
84188-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84189+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84190 {
84191 #ifdef __HAVE_BUILTIN_BSWAP64__
84192 return __builtin_bswap64(val);
84193diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84194index 6d67213..552fdd9 100644
84195--- a/include/uapi/linux/sysctl.h
84196+++ b/include/uapi/linux/sysctl.h
84197@@ -155,8 +155,6 @@ enum
84198 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84199 };
84200
84201-
84202-
84203 /* CTL_VM names: */
84204 enum
84205 {
84206diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84207index fe94bb9..c9e51c2 100644
84208--- a/include/uapi/linux/videodev2.h
84209+++ b/include/uapi/linux/videodev2.h
84210@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84211 union {
84212 __s32 value;
84213 __s64 value64;
84214- char *string;
84215+ char __user *string;
84216 };
84217 } __attribute__ ((packed));
84218
84219diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84220index c38355c..17a57bc 100644
84221--- a/include/uapi/linux/xattr.h
84222+++ b/include/uapi/linux/xattr.h
84223@@ -73,5 +73,9 @@
84224 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84225 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84226
84227+/* User namespace */
84228+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84229+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84230+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84231
84232 #endif /* _UAPI_LINUX_XATTR_H */
84233diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84234index f9466fa..f4e2b81 100644
84235--- a/include/video/udlfb.h
84236+++ b/include/video/udlfb.h
84237@@ -53,10 +53,10 @@ struct dlfb_data {
84238 u32 pseudo_palette[256];
84239 int blank_mode; /*one of FB_BLANK_ */
84240 /* blit-only rendering path metrics, exposed through sysfs */
84241- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84242- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84243- atomic_t bytes_sent; /* to usb, after compression including overhead */
84244- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84245+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84246+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84247+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84248+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84249 };
84250
84251 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84252diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84253index 30f5362..8ed8ac9 100644
84254--- a/include/video/uvesafb.h
84255+++ b/include/video/uvesafb.h
84256@@ -122,6 +122,7 @@ struct uvesafb_par {
84257 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84258 u8 pmi_setpal; /* PMI for palette changes */
84259 u16 *pmi_base; /* protected mode interface location */
84260+ u8 *pmi_code; /* protected mode code location */
84261 void *pmi_start;
84262 void *pmi_pal;
84263 u8 *vbe_state_orig; /*
84264diff --git a/init/Kconfig b/init/Kconfig
84265index d56cb03..7e6d5dc 100644
84266--- a/init/Kconfig
84267+++ b/init/Kconfig
84268@@ -1079,6 +1079,7 @@ endif # CGROUPS
84269
84270 config CHECKPOINT_RESTORE
84271 bool "Checkpoint/restore support" if EXPERT
84272+ depends on !GRKERNSEC
84273 default n
84274 help
84275 Enables additional kernel features in a sake of checkpoint/restore.
84276@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84277
84278 config COMPAT_BRK
84279 bool "Disable heap randomization"
84280- default y
84281+ default n
84282 help
84283 Randomizing heap placement makes heap exploits harder, but it
84284 also breaks ancient binaries (including anything libc5 based).
84285@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84286 config STOP_MACHINE
84287 bool
84288 default y
84289- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84290+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84291 help
84292 Need stop_machine() primitive.
84293
84294diff --git a/init/Makefile b/init/Makefile
84295index 7bc47ee..6da2dc7 100644
84296--- a/init/Makefile
84297+++ b/init/Makefile
84298@@ -2,6 +2,9 @@
84299 # Makefile for the linux kernel.
84300 #
84301
84302+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84303+asflags-y := $(GCC_PLUGINS_AFLAGS)
84304+
84305 obj-y := main.o version.o mounts.o
84306 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84307 obj-y += noinitramfs.o
84308diff --git a/init/do_mounts.c b/init/do_mounts.c
84309index 8e5addc..c96ea61 100644
84310--- a/init/do_mounts.c
84311+++ b/init/do_mounts.c
84312@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84313 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84314 {
84315 struct super_block *s;
84316- int err = sys_mount(name, "/root", fs, flags, data);
84317+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84318 if (err)
84319 return err;
84320
84321- sys_chdir("/root");
84322+ sys_chdir((const char __force_user *)"/root");
84323 s = current->fs->pwd.dentry->d_sb;
84324 ROOT_DEV = s->s_dev;
84325 printk(KERN_INFO
84326@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84327 va_start(args, fmt);
84328 vsprintf(buf, fmt, args);
84329 va_end(args);
84330- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84331+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84332 if (fd >= 0) {
84333 sys_ioctl(fd, FDEJECT, 0);
84334 sys_close(fd);
84335 }
84336 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84337- fd = sys_open("/dev/console", O_RDWR, 0);
84338+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84339 if (fd >= 0) {
84340 sys_ioctl(fd, TCGETS, (long)&termios);
84341 termios.c_lflag &= ~ICANON;
84342 sys_ioctl(fd, TCSETSF, (long)&termios);
84343- sys_read(fd, &c, 1);
84344+ sys_read(fd, (char __user *)&c, 1);
84345 termios.c_lflag |= ICANON;
84346 sys_ioctl(fd, TCSETSF, (long)&termios);
84347 sys_close(fd);
84348@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84349 mount_root();
84350 out:
84351 devtmpfs_mount("dev");
84352- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84353- sys_chroot(".");
84354+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84355+ sys_chroot((const char __force_user *)".");
84356 }
84357
84358 static bool is_tmpfs;
84359diff --git a/init/do_mounts.h b/init/do_mounts.h
84360index f5b978a..69dbfe8 100644
84361--- a/init/do_mounts.h
84362+++ b/init/do_mounts.h
84363@@ -15,15 +15,15 @@ extern int root_mountflags;
84364
84365 static inline int create_dev(char *name, dev_t dev)
84366 {
84367- sys_unlink(name);
84368- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84369+ sys_unlink((char __force_user *)name);
84370+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84371 }
84372
84373 #if BITS_PER_LONG == 32
84374 static inline u32 bstat(char *name)
84375 {
84376 struct stat64 stat;
84377- if (sys_stat64(name, &stat) != 0)
84378+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84379 return 0;
84380 if (!S_ISBLK(stat.st_mode))
84381 return 0;
84382@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84383 static inline u32 bstat(char *name)
84384 {
84385 struct stat stat;
84386- if (sys_newstat(name, &stat) != 0)
84387+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84388 return 0;
84389 if (!S_ISBLK(stat.st_mode))
84390 return 0;
84391diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84392index 3e0878e..8a9d7a0 100644
84393--- a/init/do_mounts_initrd.c
84394+++ b/init/do_mounts_initrd.c
84395@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84396 {
84397 sys_unshare(CLONE_FS | CLONE_FILES);
84398 /* stdin/stdout/stderr for /linuxrc */
84399- sys_open("/dev/console", O_RDWR, 0);
84400+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84401 sys_dup(0);
84402 sys_dup(0);
84403 /* move initrd over / and chdir/chroot in initrd root */
84404- sys_chdir("/root");
84405- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84406- sys_chroot(".");
84407+ sys_chdir((const char __force_user *)"/root");
84408+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84409+ sys_chroot((const char __force_user *)".");
84410 sys_setsid();
84411 return 0;
84412 }
84413@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84414 create_dev("/dev/root.old", Root_RAM0);
84415 /* mount initrd on rootfs' /root */
84416 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84417- sys_mkdir("/old", 0700);
84418- sys_chdir("/old");
84419+ sys_mkdir((const char __force_user *)"/old", 0700);
84420+ sys_chdir((const char __force_user *)"/old");
84421
84422 /* try loading default modules from initrd */
84423 load_default_modules();
84424@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84425 current->flags &= ~PF_FREEZER_SKIP;
84426
84427 /* move initrd to rootfs' /old */
84428- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84429+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84430 /* switch root and cwd back to / of rootfs */
84431- sys_chroot("..");
84432+ sys_chroot((const char __force_user *)"..");
84433
84434 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84435- sys_chdir("/old");
84436+ sys_chdir((const char __force_user *)"/old");
84437 return;
84438 }
84439
84440- sys_chdir("/");
84441+ sys_chdir((const char __force_user *)"/");
84442 ROOT_DEV = new_decode_dev(real_root_dev);
84443 mount_root();
84444
84445 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84446- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84447+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84448 if (!error)
84449 printk("okay\n");
84450 else {
84451- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84452+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84453 if (error == -ENOENT)
84454 printk("/initrd does not exist. Ignored.\n");
84455 else
84456 printk("failed\n");
84457 printk(KERN_NOTICE "Unmounting old root\n");
84458- sys_umount("/old", MNT_DETACH);
84459+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84460 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84461 if (fd < 0) {
84462 error = fd;
84463@@ -127,11 +127,11 @@ int __init initrd_load(void)
84464 * mounted in the normal path.
84465 */
84466 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84467- sys_unlink("/initrd.image");
84468+ sys_unlink((const char __force_user *)"/initrd.image");
84469 handle_initrd();
84470 return 1;
84471 }
84472 }
84473- sys_unlink("/initrd.image");
84474+ sys_unlink((const char __force_user *)"/initrd.image");
84475 return 0;
84476 }
84477diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84478index 8cb6db5..d729f50 100644
84479--- a/init/do_mounts_md.c
84480+++ b/init/do_mounts_md.c
84481@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84482 partitioned ? "_d" : "", minor,
84483 md_setup_args[ent].device_names);
84484
84485- fd = sys_open(name, 0, 0);
84486+ fd = sys_open((char __force_user *)name, 0, 0);
84487 if (fd < 0) {
84488 printk(KERN_ERR "md: open failed - cannot start "
84489 "array %s\n", name);
84490@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84491 * array without it
84492 */
84493 sys_close(fd);
84494- fd = sys_open(name, 0, 0);
84495+ fd = sys_open((char __force_user *)name, 0, 0);
84496 sys_ioctl(fd, BLKRRPART, 0);
84497 }
84498 sys_close(fd);
84499@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84500
84501 wait_for_device_probe();
84502
84503- fd = sys_open("/dev/md0", 0, 0);
84504+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84505 if (fd >= 0) {
84506 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84507 sys_close(fd);
84508diff --git a/init/init_task.c b/init/init_task.c
84509index ba0a7f36..2bcf1d5 100644
84510--- a/init/init_task.c
84511+++ b/init/init_task.c
84512@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84513 * Initial thread structure. Alignment of this is handled by a special
84514 * linker map entry.
84515 */
84516+#ifdef CONFIG_X86
84517+union thread_union init_thread_union __init_task_data;
84518+#else
84519 union thread_union init_thread_union __init_task_data =
84520 { INIT_THREAD_INFO(init_task) };
84521+#endif
84522diff --git a/init/initramfs.c b/init/initramfs.c
84523index 93b6139..8d628b7 100644
84524--- a/init/initramfs.c
84525+++ b/init/initramfs.c
84526@@ -84,7 +84,7 @@ static void __init free_hash(void)
84527 }
84528 }
84529
84530-static long __init do_utime(char *filename, time_t mtime)
84531+static long __init do_utime(char __force_user *filename, time_t mtime)
84532 {
84533 struct timespec t[2];
84534
84535@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84536 struct dir_entry *de, *tmp;
84537 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84538 list_del(&de->list);
84539- do_utime(de->name, de->mtime);
84540+ do_utime((char __force_user *)de->name, de->mtime);
84541 kfree(de->name);
84542 kfree(de);
84543 }
84544@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84545 if (nlink >= 2) {
84546 char *old = find_link(major, minor, ino, mode, collected);
84547 if (old)
84548- return (sys_link(old, collected) < 0) ? -1 : 1;
84549+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84550 }
84551 return 0;
84552 }
84553@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84554 {
84555 struct stat st;
84556
84557- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84558+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84559 if (S_ISDIR(st.st_mode))
84560- sys_rmdir(path);
84561+ sys_rmdir((char __force_user *)path);
84562 else
84563- sys_unlink(path);
84564+ sys_unlink((char __force_user *)path);
84565 }
84566 }
84567
84568@@ -315,7 +315,7 @@ static int __init do_name(void)
84569 int openflags = O_WRONLY|O_CREAT;
84570 if (ml != 1)
84571 openflags |= O_TRUNC;
84572- wfd = sys_open(collected, openflags, mode);
84573+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84574
84575 if (wfd >= 0) {
84576 sys_fchown(wfd, uid, gid);
84577@@ -327,17 +327,17 @@ static int __init do_name(void)
84578 }
84579 }
84580 } else if (S_ISDIR(mode)) {
84581- sys_mkdir(collected, mode);
84582- sys_chown(collected, uid, gid);
84583- sys_chmod(collected, mode);
84584+ sys_mkdir((char __force_user *)collected, mode);
84585+ sys_chown((char __force_user *)collected, uid, gid);
84586+ sys_chmod((char __force_user *)collected, mode);
84587 dir_add(collected, mtime);
84588 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84589 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84590 if (maybe_link() == 0) {
84591- sys_mknod(collected, mode, rdev);
84592- sys_chown(collected, uid, gid);
84593- sys_chmod(collected, mode);
84594- do_utime(collected, mtime);
84595+ sys_mknod((char __force_user *)collected, mode, rdev);
84596+ sys_chown((char __force_user *)collected, uid, gid);
84597+ sys_chmod((char __force_user *)collected, mode);
84598+ do_utime((char __force_user *)collected, mtime);
84599 }
84600 }
84601 return 0;
84602@@ -346,15 +346,15 @@ static int __init do_name(void)
84603 static int __init do_copy(void)
84604 {
84605 if (count >= body_len) {
84606- sys_write(wfd, victim, body_len);
84607+ sys_write(wfd, (char __force_user *)victim, body_len);
84608 sys_close(wfd);
84609- do_utime(vcollected, mtime);
84610+ do_utime((char __force_user *)vcollected, mtime);
84611 kfree(vcollected);
84612 eat(body_len);
84613 state = SkipIt;
84614 return 0;
84615 } else {
84616- sys_write(wfd, victim, count);
84617+ sys_write(wfd, (char __force_user *)victim, count);
84618 body_len -= count;
84619 eat(count);
84620 return 1;
84621@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84622 {
84623 collected[N_ALIGN(name_len) + body_len] = '\0';
84624 clean_path(collected, 0);
84625- sys_symlink(collected + N_ALIGN(name_len), collected);
84626- sys_lchown(collected, uid, gid);
84627- do_utime(collected, mtime);
84628+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84629+ sys_lchown((char __force_user *)collected, uid, gid);
84630+ do_utime((char __force_user *)collected, mtime);
84631 state = SkipIt;
84632 next_state = Reset;
84633 return 0;
84634diff --git a/init/main.c b/init/main.c
84635index 9c7fd4c..650b4f1 100644
84636--- a/init/main.c
84637+++ b/init/main.c
84638@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84639 static inline void mark_rodata_ro(void) { }
84640 #endif
84641
84642+extern void grsecurity_init(void);
84643+
84644 /*
84645 * Debug helper: via this flag we know that we are in 'early bootup code'
84646 * where only the boot processor is running with IRQ disabled. This means
84647@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84648
84649 __setup("reset_devices", set_reset_devices);
84650
84651+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84652+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84653+static int __init setup_grsec_proc_gid(char *str)
84654+{
84655+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84656+ return 1;
84657+}
84658+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84659+#endif
84660+
84661+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84662+unsigned long pax_user_shadow_base __read_only;
84663+EXPORT_SYMBOL(pax_user_shadow_base);
84664+extern char pax_enter_kernel_user[];
84665+extern char pax_exit_kernel_user[];
84666+#endif
84667+
84668+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84669+static int __init setup_pax_nouderef(char *str)
84670+{
84671+#ifdef CONFIG_X86_32
84672+ unsigned int cpu;
84673+ struct desc_struct *gdt;
84674+
84675+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84676+ gdt = get_cpu_gdt_table(cpu);
84677+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84678+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84679+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84680+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84681+ }
84682+ loadsegment(ds, __KERNEL_DS);
84683+ loadsegment(es, __KERNEL_DS);
84684+ loadsegment(ss, __KERNEL_DS);
84685+#else
84686+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84687+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84688+ clone_pgd_mask = ~(pgdval_t)0UL;
84689+ pax_user_shadow_base = 0UL;
84690+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84691+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84692+#endif
84693+
84694+ return 0;
84695+}
84696+early_param("pax_nouderef", setup_pax_nouderef);
84697+
84698+#ifdef CONFIG_X86_64
84699+static int __init setup_pax_weakuderef(char *str)
84700+{
84701+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84702+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84703+ return 1;
84704+}
84705+__setup("pax_weakuderef", setup_pax_weakuderef);
84706+#endif
84707+#endif
84708+
84709+#ifdef CONFIG_PAX_SOFTMODE
84710+int pax_softmode;
84711+
84712+static int __init setup_pax_softmode(char *str)
84713+{
84714+ get_option(&str, &pax_softmode);
84715+ return 1;
84716+}
84717+__setup("pax_softmode=", setup_pax_softmode);
84718+#endif
84719+
84720 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84721 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84722 static const char *panic_later, *panic_param;
84723@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84724 {
84725 int count = preempt_count();
84726 int ret;
84727- char msgbuf[64];
84728+ const char *msg1 = "", *msg2 = "";
84729
84730 if (initcall_debug)
84731 ret = do_one_initcall_debug(fn);
84732 else
84733 ret = fn();
84734
84735- msgbuf[0] = 0;
84736-
84737 if (preempt_count() != count) {
84738- sprintf(msgbuf, "preemption imbalance ");
84739+ msg1 = " preemption imbalance";
84740 preempt_count_set(count);
84741 }
84742 if (irqs_disabled()) {
84743- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84744+ msg2 = " disabled interrupts";
84745 local_irq_enable();
84746 }
84747- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84748+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84749
84750+ add_latent_entropy();
84751 return ret;
84752 }
84753
84754@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84755 {
84756 argv_init[0] = init_filename;
84757 return do_execve(getname_kernel(init_filename),
84758- (const char __user *const __user *)argv_init,
84759- (const char __user *const __user *)envp_init);
84760+ (const char __user *const __force_user *)argv_init,
84761+ (const char __user *const __force_user *)envp_init);
84762 }
84763
84764 static int try_to_run_init_process(const char *init_filename)
84765@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84766 return ret;
84767 }
84768
84769+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84770+extern int gr_init_ran;
84771+#endif
84772+
84773 static noinline void __init kernel_init_freeable(void);
84774
84775 static int __ref kernel_init(void *unused)
84776@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84777 ramdisk_execute_command, ret);
84778 }
84779
84780+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84781+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84782+ gr_init_ran = 1;
84783+#endif
84784+
84785 /*
84786 * We try each of these until one succeeds.
84787 *
84788@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84789 do_basic_setup();
84790
84791 /* Open the /dev/console on the rootfs, this should never fail */
84792- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84793+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84794 pr_err("Warning: unable to open an initial console.\n");
84795
84796 (void) sys_dup(0);
84797@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84798 if (!ramdisk_execute_command)
84799 ramdisk_execute_command = "/init";
84800
84801- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84802+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84803 ramdisk_execute_command = NULL;
84804 prepare_namespace();
84805 }
84806
84807+ grsecurity_init();
84808+
84809 /*
84810 * Ok, we have completed the initial bootup, and
84811 * we're essentially up and running. Get rid of the
84812diff --git a/ipc/compat.c b/ipc/compat.c
84813index f486b00..442867f 100644
84814--- a/ipc/compat.c
84815+++ b/ipc/compat.c
84816@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84817 COMPAT_SHMLBA);
84818 if (err < 0)
84819 return err;
84820- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84821+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84822 }
84823 case SHMDT:
84824 return sys_shmdt(compat_ptr(ptr));
84825diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84826index 1702864..797fa84 100644
84827--- a/ipc/ipc_sysctl.c
84828+++ b/ipc/ipc_sysctl.c
84829@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84830 static int proc_ipc_dointvec(ctl_table *table, int write,
84831 void __user *buffer, size_t *lenp, loff_t *ppos)
84832 {
84833- struct ctl_table ipc_table;
84834+ ctl_table_no_const ipc_table;
84835
84836 memcpy(&ipc_table, table, sizeof(ipc_table));
84837 ipc_table.data = get_ipc(table);
84838@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84839 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84840 void __user *buffer, size_t *lenp, loff_t *ppos)
84841 {
84842- struct ctl_table ipc_table;
84843+ ctl_table_no_const ipc_table;
84844
84845 memcpy(&ipc_table, table, sizeof(ipc_table));
84846 ipc_table.data = get_ipc(table);
84847@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84848 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84849 void __user *buffer, size_t *lenp, loff_t *ppos)
84850 {
84851- struct ctl_table ipc_table;
84852+ ctl_table_no_const ipc_table;
84853 size_t lenp_bef = *lenp;
84854 int rc;
84855
84856@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84857 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84858 void __user *buffer, size_t *lenp, loff_t *ppos)
84859 {
84860- struct ctl_table ipc_table;
84861+ ctl_table_no_const ipc_table;
84862 memcpy(&ipc_table, table, sizeof(ipc_table));
84863 ipc_table.data = get_ipc(table);
84864
84865@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84866 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84867 void __user *buffer, size_t *lenp, loff_t *ppos)
84868 {
84869- struct ctl_table ipc_table;
84870+ ctl_table_no_const ipc_table;
84871 size_t lenp_bef = *lenp;
84872 int oldval;
84873 int rc;
84874diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84875index 5bb8bfe..a38ec05 100644
84876--- a/ipc/mq_sysctl.c
84877+++ b/ipc/mq_sysctl.c
84878@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84879 static int proc_mq_dointvec(ctl_table *table, int write,
84880 void __user *buffer, size_t *lenp, loff_t *ppos)
84881 {
84882- struct ctl_table mq_table;
84883+ ctl_table_no_const mq_table;
84884 memcpy(&mq_table, table, sizeof(mq_table));
84885 mq_table.data = get_mq(table);
84886
84887@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84888 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84889 void __user *buffer, size_t *lenp, loff_t *ppos)
84890 {
84891- struct ctl_table mq_table;
84892+ ctl_table_no_const mq_table;
84893 memcpy(&mq_table, table, sizeof(mq_table));
84894 mq_table.data = get_mq(table);
84895
84896diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84897index c3b3117..1efa933 100644
84898--- a/ipc/mqueue.c
84899+++ b/ipc/mqueue.c
84900@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84901 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84902 info->attr.mq_msgsize);
84903
84904+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84905 spin_lock(&mq_lock);
84906 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84907 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84908diff --git a/ipc/msg.c b/ipc/msg.c
84909index 6498531..b0ff3c8 100644
84910--- a/ipc/msg.c
84911+++ b/ipc/msg.c
84912@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84913 return security_msg_queue_associate(msq, msgflg);
84914 }
84915
84916+static struct ipc_ops msg_ops = {
84917+ .getnew = newque,
84918+ .associate = msg_security,
84919+ .more_checks = NULL
84920+};
84921+
84922 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84923 {
84924 struct ipc_namespace *ns;
84925- struct ipc_ops msg_ops;
84926 struct ipc_params msg_params;
84927
84928 ns = current->nsproxy->ipc_ns;
84929
84930- msg_ops.getnew = newque;
84931- msg_ops.associate = msg_security;
84932- msg_ops.more_checks = NULL;
84933-
84934 msg_params.key = key;
84935 msg_params.flg = msgflg;
84936
84937diff --git a/ipc/sem.c b/ipc/sem.c
84938index bee5554..e9af81dd 100644
84939--- a/ipc/sem.c
84940+++ b/ipc/sem.c
84941@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84942 return 0;
84943 }
84944
84945+static struct ipc_ops sem_ops = {
84946+ .getnew = newary,
84947+ .associate = sem_security,
84948+ .more_checks = sem_more_checks
84949+};
84950+
84951 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84952 {
84953 struct ipc_namespace *ns;
84954- struct ipc_ops sem_ops;
84955 struct ipc_params sem_params;
84956
84957 ns = current->nsproxy->ipc_ns;
84958@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84959 if (nsems < 0 || nsems > ns->sc_semmsl)
84960 return -EINVAL;
84961
84962- sem_ops.getnew = newary;
84963- sem_ops.associate = sem_security;
84964- sem_ops.more_checks = sem_more_checks;
84965-
84966 sem_params.key = key;
84967 sem_params.flg = semflg;
84968 sem_params.u.nsems = nsems;
84969diff --git a/ipc/shm.c b/ipc/shm.c
84970index 7645961..afc7f02 100644
84971--- a/ipc/shm.c
84972+++ b/ipc/shm.c
84973@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
84974 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84975 #endif
84976
84977+#ifdef CONFIG_GRKERNSEC
84978+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84979+ const time_t shm_createtime, const kuid_t cuid,
84980+ const int shmid);
84981+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84982+ const time_t shm_createtime);
84983+#endif
84984+
84985 void shm_init_ns(struct ipc_namespace *ns)
84986 {
84987 ns->shm_ctlmax = SHMMAX;
84988@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84989 shp->shm_lprid = 0;
84990 shp->shm_atim = shp->shm_dtim = 0;
84991 shp->shm_ctim = get_seconds();
84992+#ifdef CONFIG_GRKERNSEC
84993+ {
84994+ struct timespec timeval;
84995+ do_posix_clock_monotonic_gettime(&timeval);
84996+
84997+ shp->shm_createtime = timeval.tv_sec;
84998+ }
84999+#endif
85000 shp->shm_segsz = size;
85001 shp->shm_nattch = 0;
85002 shp->shm_file = file;
85003@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85004 return 0;
85005 }
85006
85007+static struct ipc_ops shm_ops = {
85008+ .getnew = newseg,
85009+ .associate = shm_security,
85010+ .more_checks = shm_more_checks
85011+};
85012+
85013 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85014 {
85015 struct ipc_namespace *ns;
85016- struct ipc_ops shm_ops;
85017 struct ipc_params shm_params;
85018
85019 ns = current->nsproxy->ipc_ns;
85020
85021- shm_ops.getnew = newseg;
85022- shm_ops.associate = shm_security;
85023- shm_ops.more_checks = shm_more_checks;
85024-
85025 shm_params.key = key;
85026 shm_params.flg = shmflg;
85027 shm_params.u.size = size;
85028@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85029 f_mode = FMODE_READ | FMODE_WRITE;
85030 }
85031 if (shmflg & SHM_EXEC) {
85032+
85033+#ifdef CONFIG_PAX_MPROTECT
85034+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85035+ goto out;
85036+#endif
85037+
85038 prot |= PROT_EXEC;
85039 acc_mode |= S_IXUGO;
85040 }
85041@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85042 if (err)
85043 goto out_unlock;
85044
85045+#ifdef CONFIG_GRKERNSEC
85046+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85047+ shp->shm_perm.cuid, shmid) ||
85048+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85049+ err = -EACCES;
85050+ goto out_unlock;
85051+ }
85052+#endif
85053+
85054 ipc_lock_object(&shp->shm_perm);
85055
85056 /* check if shm_destroy() is tearing down shp */
85057@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85058 path = shp->shm_file->f_path;
85059 path_get(&path);
85060 shp->shm_nattch++;
85061+#ifdef CONFIG_GRKERNSEC
85062+ shp->shm_lapid = current->pid;
85063+#endif
85064 size = i_size_read(path.dentry->d_inode);
85065 ipc_unlock_object(&shp->shm_perm);
85066 rcu_read_unlock();
85067diff --git a/ipc/util.c b/ipc/util.c
85068index e1b4c6d..8174204 100644
85069--- a/ipc/util.c
85070+++ b/ipc/util.c
85071@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85072 int (*show)(struct seq_file *, void *);
85073 };
85074
85075+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85076+
85077 static void ipc_memory_notifier(struct work_struct *work)
85078 {
85079 ipcns_notify(IPCNS_MEMCHANGED);
85080@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85081 granted_mode >>= 6;
85082 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85083 granted_mode >>= 3;
85084+
85085+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85086+ return -1;
85087+
85088 /* is there some bit set in requested_mode but not in granted_mode? */
85089 if ((requested_mode & ~granted_mode & 0007) &&
85090 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85091diff --git a/kernel/acct.c b/kernel/acct.c
85092index 8d6e145..33e0b1e 100644
85093--- a/kernel/acct.c
85094+++ b/kernel/acct.c
85095@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85096 */
85097 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85098 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85099- file->f_op->write(file, (char *)&ac,
85100+ file->f_op->write(file, (char __force_user *)&ac,
85101 sizeof(acct_t), &file->f_pos);
85102 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85103 set_fs(fs);
85104diff --git a/kernel/audit.c b/kernel/audit.c
85105index 95a20f3..e1cb300 100644
85106--- a/kernel/audit.c
85107+++ b/kernel/audit.c
85108@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85109 3) suppressed due to audit_rate_limit
85110 4) suppressed due to audit_backlog_limit
85111 */
85112-static atomic_t audit_lost = ATOMIC_INIT(0);
85113+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85114
85115 /* The netlink socket. */
85116 static struct sock *audit_sock;
85117@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85118 unsigned long now;
85119 int print;
85120
85121- atomic_inc(&audit_lost);
85122+ atomic_inc_unchecked(&audit_lost);
85123
85124 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85125
85126@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85127 if (print) {
85128 if (printk_ratelimit())
85129 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85130- atomic_read(&audit_lost),
85131+ atomic_read_unchecked(&audit_lost),
85132 audit_rate_limit,
85133 audit_backlog_limit);
85134 audit_panic(message);
85135@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85136 s.pid = audit_pid;
85137 s.rate_limit = audit_rate_limit;
85138 s.backlog_limit = audit_backlog_limit;
85139- s.lost = atomic_read(&audit_lost);
85140+ s.lost = atomic_read_unchecked(&audit_lost);
85141 s.backlog = skb_queue_len(&audit_skb_queue);
85142 s.version = AUDIT_VERSION_LATEST;
85143 s.backlog_wait_time = audit_backlog_wait_time;
85144diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85145index 7aef2f4..db6ced2 100644
85146--- a/kernel/auditsc.c
85147+++ b/kernel/auditsc.c
85148@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85149 }
85150
85151 /* global counter which is incremented every time something logs in */
85152-static atomic_t session_id = ATOMIC_INIT(0);
85153+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85154
85155 static int audit_set_loginuid_perm(kuid_t loginuid)
85156 {
85157@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85158
85159 /* are we setting or clearing? */
85160 if (uid_valid(loginuid))
85161- sessionid = (unsigned int)atomic_inc_return(&session_id);
85162+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85163
85164 task->sessionid = sessionid;
85165 task->loginuid = loginuid;
85166diff --git a/kernel/capability.c b/kernel/capability.c
85167index 34019c5..363f279 100644
85168--- a/kernel/capability.c
85169+++ b/kernel/capability.c
85170@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85171 * before modification is attempted and the application
85172 * fails.
85173 */
85174+ if (tocopy > ARRAY_SIZE(kdata))
85175+ return -EFAULT;
85176+
85177 if (copy_to_user(dataptr, kdata, tocopy
85178 * sizeof(struct __user_cap_data_struct))) {
85179 return -EFAULT;
85180@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85181 int ret;
85182
85183 rcu_read_lock();
85184- ret = security_capable(__task_cred(t), ns, cap);
85185+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85186+ gr_task_is_capable(t, __task_cred(t), cap);
85187 rcu_read_unlock();
85188
85189- return (ret == 0);
85190+ return ret;
85191 }
85192
85193 /**
85194@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85195 int ret;
85196
85197 rcu_read_lock();
85198- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85199+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85200 rcu_read_unlock();
85201
85202- return (ret == 0);
85203+ return ret;
85204 }
85205
85206 /**
85207@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85208 BUG();
85209 }
85210
85211- if (security_capable(current_cred(), ns, cap) == 0) {
85212+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85213 current->flags |= PF_SUPERPRIV;
85214 return true;
85215 }
85216@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85217 }
85218 EXPORT_SYMBOL(ns_capable);
85219
85220+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85221+{
85222+ if (unlikely(!cap_valid(cap))) {
85223+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85224+ BUG();
85225+ }
85226+
85227+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85228+ current->flags |= PF_SUPERPRIV;
85229+ return true;
85230+ }
85231+ return false;
85232+}
85233+EXPORT_SYMBOL(ns_capable_nolog);
85234+
85235 /**
85236 * file_ns_capable - Determine if the file's opener had a capability in effect
85237 * @file: The file we want to check
85238@@ -432,6 +451,12 @@ bool capable(int cap)
85239 }
85240 EXPORT_SYMBOL(capable);
85241
85242+bool capable_nolog(int cap)
85243+{
85244+ return ns_capable_nolog(&init_user_ns, cap);
85245+}
85246+EXPORT_SYMBOL(capable_nolog);
85247+
85248 /**
85249 * inode_capable - Check superior capability over inode
85250 * @inode: The inode in question
85251@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85252 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85253 }
85254 EXPORT_SYMBOL(inode_capable);
85255+
85256+bool inode_capable_nolog(const struct inode *inode, int cap)
85257+{
85258+ struct user_namespace *ns = current_user_ns();
85259+
85260+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85261+}
85262+EXPORT_SYMBOL(inode_capable_nolog);
85263diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85264index 0c753dd..dd7d3d6 100644
85265--- a/kernel/cgroup.c
85266+++ b/kernel/cgroup.c
85267@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85268 struct css_set *cset = link->cset;
85269 struct task_struct *task;
85270 int count = 0;
85271- seq_printf(seq, "css_set %p\n", cset);
85272+ seq_printf(seq, "css_set %pK\n", cset);
85273 list_for_each_entry(task, &cset->tasks, cg_list) {
85274 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85275 seq_puts(seq, " ...\n");
85276diff --git a/kernel/compat.c b/kernel/compat.c
85277index 0a09e48..b46b3d78 100644
85278--- a/kernel/compat.c
85279+++ b/kernel/compat.c
85280@@ -13,6 +13,7 @@
85281
85282 #include <linux/linkage.h>
85283 #include <linux/compat.h>
85284+#include <linux/module.h>
85285 #include <linux/errno.h>
85286 #include <linux/time.h>
85287 #include <linux/signal.h>
85288@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85289 mm_segment_t oldfs;
85290 long ret;
85291
85292- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85293+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85294 oldfs = get_fs();
85295 set_fs(KERNEL_DS);
85296 ret = hrtimer_nanosleep_restart(restart);
85297@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85298 oldfs = get_fs();
85299 set_fs(KERNEL_DS);
85300 ret = hrtimer_nanosleep(&tu,
85301- rmtp ? (struct timespec __user *)&rmt : NULL,
85302+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85303 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85304 set_fs(oldfs);
85305
85306@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85307 mm_segment_t old_fs = get_fs();
85308
85309 set_fs(KERNEL_DS);
85310- ret = sys_sigpending((old_sigset_t __user *) &s);
85311+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85312 set_fs(old_fs);
85313 if (ret == 0)
85314 ret = put_user(s, set);
85315@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85316 mm_segment_t old_fs = get_fs();
85317
85318 set_fs(KERNEL_DS);
85319- ret = sys_old_getrlimit(resource, &r);
85320+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85321 set_fs(old_fs);
85322
85323 if (!ret) {
85324@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85325 set_fs (KERNEL_DS);
85326 ret = sys_wait4(pid,
85327 (stat_addr ?
85328- (unsigned int __user *) &status : NULL),
85329- options, (struct rusage __user *) &r);
85330+ (unsigned int __force_user *) &status : NULL),
85331+ options, (struct rusage __force_user *) &r);
85332 set_fs (old_fs);
85333
85334 if (ret > 0) {
85335@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85336 memset(&info, 0, sizeof(info));
85337
85338 set_fs(KERNEL_DS);
85339- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85340- uru ? (struct rusage __user *)&ru : NULL);
85341+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85342+ uru ? (struct rusage __force_user *)&ru : NULL);
85343 set_fs(old_fs);
85344
85345 if ((ret < 0) || (info.si_signo == 0))
85346@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85347 oldfs = get_fs();
85348 set_fs(KERNEL_DS);
85349 err = sys_timer_settime(timer_id, flags,
85350- (struct itimerspec __user *) &newts,
85351- (struct itimerspec __user *) &oldts);
85352+ (struct itimerspec __force_user *) &newts,
85353+ (struct itimerspec __force_user *) &oldts);
85354 set_fs(oldfs);
85355 if (!err && old && put_compat_itimerspec(old, &oldts))
85356 return -EFAULT;
85357@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85358 oldfs = get_fs();
85359 set_fs(KERNEL_DS);
85360 err = sys_timer_gettime(timer_id,
85361- (struct itimerspec __user *) &ts);
85362+ (struct itimerspec __force_user *) &ts);
85363 set_fs(oldfs);
85364 if (!err && put_compat_itimerspec(setting, &ts))
85365 return -EFAULT;
85366@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85367 oldfs = get_fs();
85368 set_fs(KERNEL_DS);
85369 err = sys_clock_settime(which_clock,
85370- (struct timespec __user *) &ts);
85371+ (struct timespec __force_user *) &ts);
85372 set_fs(oldfs);
85373 return err;
85374 }
85375@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85376 oldfs = get_fs();
85377 set_fs(KERNEL_DS);
85378 err = sys_clock_gettime(which_clock,
85379- (struct timespec __user *) &ts);
85380+ (struct timespec __force_user *) &ts);
85381 set_fs(oldfs);
85382 if (!err && put_compat_timespec(&ts, tp))
85383 return -EFAULT;
85384@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85385
85386 oldfs = get_fs();
85387 set_fs(KERNEL_DS);
85388- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85389+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85390 set_fs(oldfs);
85391
85392 err = compat_put_timex(utp, &txc);
85393@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85394 oldfs = get_fs();
85395 set_fs(KERNEL_DS);
85396 err = sys_clock_getres(which_clock,
85397- (struct timespec __user *) &ts);
85398+ (struct timespec __force_user *) &ts);
85399 set_fs(oldfs);
85400 if (!err && tp && put_compat_timespec(&ts, tp))
85401 return -EFAULT;
85402@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85403 long err;
85404 mm_segment_t oldfs;
85405 struct timespec tu;
85406- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85407+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85408
85409- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85410+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85411 oldfs = get_fs();
85412 set_fs(KERNEL_DS);
85413 err = clock_nanosleep_restart(restart);
85414@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85415 oldfs = get_fs();
85416 set_fs(KERNEL_DS);
85417 err = sys_clock_nanosleep(which_clock, flags,
85418- (struct timespec __user *) &in,
85419- (struct timespec __user *) &out);
85420+ (struct timespec __force_user *) &in,
85421+ (struct timespec __force_user *) &out);
85422 set_fs(oldfs);
85423
85424 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85425@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85426 mm_segment_t old_fs = get_fs();
85427
85428 set_fs(KERNEL_DS);
85429- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85430+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85431 set_fs(old_fs);
85432 if (put_compat_timespec(&t, interval))
85433 return -EFAULT;
85434diff --git a/kernel/configs.c b/kernel/configs.c
85435index c18b1f1..b9a0132 100644
85436--- a/kernel/configs.c
85437+++ b/kernel/configs.c
85438@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85439 struct proc_dir_entry *entry;
85440
85441 /* create the current config file */
85442+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85443+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85444+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85445+ &ikconfig_file_ops);
85446+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85447+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85448+ &ikconfig_file_ops);
85449+#endif
85450+#else
85451 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85452 &ikconfig_file_ops);
85453+#endif
85454+
85455 if (!entry)
85456 return -ENOMEM;
85457
85458diff --git a/kernel/cred.c b/kernel/cred.c
85459index e0573a4..3874e41 100644
85460--- a/kernel/cred.c
85461+++ b/kernel/cred.c
85462@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85463 validate_creds(cred);
85464 alter_cred_subscribers(cred, -1);
85465 put_cred(cred);
85466+
85467+#ifdef CONFIG_GRKERNSEC_SETXID
85468+ cred = (struct cred *) tsk->delayed_cred;
85469+ if (cred != NULL) {
85470+ tsk->delayed_cred = NULL;
85471+ validate_creds(cred);
85472+ alter_cred_subscribers(cred, -1);
85473+ put_cred(cred);
85474+ }
85475+#endif
85476 }
85477
85478 /**
85479@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85480 * Always returns 0 thus allowing this function to be tail-called at the end
85481 * of, say, sys_setgid().
85482 */
85483-int commit_creds(struct cred *new)
85484+static int __commit_creds(struct cred *new)
85485 {
85486 struct task_struct *task = current;
85487 const struct cred *old = task->real_cred;
85488@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85489
85490 get_cred(new); /* we will require a ref for the subj creds too */
85491
85492+ gr_set_role_label(task, new->uid, new->gid);
85493+
85494 /* dumpability changes */
85495 if (!uid_eq(old->euid, new->euid) ||
85496 !gid_eq(old->egid, new->egid) ||
85497@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85498 put_cred(old);
85499 return 0;
85500 }
85501+#ifdef CONFIG_GRKERNSEC_SETXID
85502+extern int set_user(struct cred *new);
85503+
85504+void gr_delayed_cred_worker(void)
85505+{
85506+ const struct cred *new = current->delayed_cred;
85507+ struct cred *ncred;
85508+
85509+ current->delayed_cred = NULL;
85510+
85511+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85512+ // from doing get_cred on it when queueing this
85513+ put_cred(new);
85514+ return;
85515+ } else if (new == NULL)
85516+ return;
85517+
85518+ ncred = prepare_creds();
85519+ if (!ncred)
85520+ goto die;
85521+ // uids
85522+ ncred->uid = new->uid;
85523+ ncred->euid = new->euid;
85524+ ncred->suid = new->suid;
85525+ ncred->fsuid = new->fsuid;
85526+ // gids
85527+ ncred->gid = new->gid;
85528+ ncred->egid = new->egid;
85529+ ncred->sgid = new->sgid;
85530+ ncred->fsgid = new->fsgid;
85531+ // groups
85532+ if (set_groups(ncred, new->group_info) < 0) {
85533+ abort_creds(ncred);
85534+ goto die;
85535+ }
85536+ // caps
85537+ ncred->securebits = new->securebits;
85538+ ncred->cap_inheritable = new->cap_inheritable;
85539+ ncred->cap_permitted = new->cap_permitted;
85540+ ncred->cap_effective = new->cap_effective;
85541+ ncred->cap_bset = new->cap_bset;
85542+
85543+ if (set_user(ncred)) {
85544+ abort_creds(ncred);
85545+ goto die;
85546+ }
85547+
85548+ // from doing get_cred on it when queueing this
85549+ put_cred(new);
85550+
85551+ __commit_creds(ncred);
85552+ return;
85553+die:
85554+ // from doing get_cred on it when queueing this
85555+ put_cred(new);
85556+ do_group_exit(SIGKILL);
85557+}
85558+#endif
85559+
85560+int commit_creds(struct cred *new)
85561+{
85562+#ifdef CONFIG_GRKERNSEC_SETXID
85563+ int ret;
85564+ int schedule_it = 0;
85565+ struct task_struct *t;
85566+
85567+ /* we won't get called with tasklist_lock held for writing
85568+ and interrupts disabled as the cred struct in that case is
85569+ init_cred
85570+ */
85571+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85572+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85573+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85574+ schedule_it = 1;
85575+ }
85576+ ret = __commit_creds(new);
85577+ if (schedule_it) {
85578+ rcu_read_lock();
85579+ read_lock(&tasklist_lock);
85580+ for (t = next_thread(current); t != current;
85581+ t = next_thread(t)) {
85582+ if (t->delayed_cred == NULL) {
85583+ t->delayed_cred = get_cred(new);
85584+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85585+ set_tsk_need_resched(t);
85586+ }
85587+ }
85588+ read_unlock(&tasklist_lock);
85589+ rcu_read_unlock();
85590+ }
85591+ return ret;
85592+#else
85593+ return __commit_creds(new);
85594+#endif
85595+}
85596+
85597 EXPORT_SYMBOL(commit_creds);
85598
85599 /**
85600diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85601index 334b398..9145fb1 100644
85602--- a/kernel/debug/debug_core.c
85603+++ b/kernel/debug/debug_core.c
85604@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85605 */
85606 static atomic_t masters_in_kgdb;
85607 static atomic_t slaves_in_kgdb;
85608-static atomic_t kgdb_break_tasklet_var;
85609+static atomic_unchecked_t kgdb_break_tasklet_var;
85610 atomic_t kgdb_setting_breakpoint;
85611
85612 struct task_struct *kgdb_usethread;
85613@@ -133,7 +133,7 @@ int kgdb_single_step;
85614 static pid_t kgdb_sstep_pid;
85615
85616 /* to keep track of the CPU which is doing the single stepping*/
85617-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85618+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85619
85620 /*
85621 * If you are debugging a problem where roundup (the collection of
85622@@ -541,7 +541,7 @@ return_normal:
85623 * kernel will only try for the value of sstep_tries before
85624 * giving up and continuing on.
85625 */
85626- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85627+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85628 (kgdb_info[cpu].task &&
85629 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85630 atomic_set(&kgdb_active, -1);
85631@@ -639,8 +639,8 @@ cpu_master_loop:
85632 }
85633
85634 kgdb_restore:
85635- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85636- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85637+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85638+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85639 if (kgdb_info[sstep_cpu].task)
85640 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85641 else
85642@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85643 static void kgdb_tasklet_bpt(unsigned long ing)
85644 {
85645 kgdb_breakpoint();
85646- atomic_set(&kgdb_break_tasklet_var, 0);
85647+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85648 }
85649
85650 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85651
85652 void kgdb_schedule_breakpoint(void)
85653 {
85654- if (atomic_read(&kgdb_break_tasklet_var) ||
85655+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85656 atomic_read(&kgdb_active) != -1 ||
85657 atomic_read(&kgdb_setting_breakpoint))
85658 return;
85659- atomic_inc(&kgdb_break_tasklet_var);
85660+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85661 tasklet_schedule(&kgdb_tasklet_breakpoint);
85662 }
85663 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85664diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85665index 0b097c8..11dd5c5 100644
85666--- a/kernel/debug/kdb/kdb_main.c
85667+++ b/kernel/debug/kdb/kdb_main.c
85668@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85669 continue;
85670
85671 kdb_printf("%-20s%8u 0x%p ", mod->name,
85672- mod->core_size, (void *)mod);
85673+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85674 #ifdef CONFIG_MODULE_UNLOAD
85675 kdb_printf("%4ld ", module_refcount(mod));
85676 #endif
85677@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85678 kdb_printf(" (Loading)");
85679 else
85680 kdb_printf(" (Live)");
85681- kdb_printf(" 0x%p", mod->module_core);
85682+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85683
85684 #ifdef CONFIG_MODULE_UNLOAD
85685 {
85686diff --git a/kernel/events/core.c b/kernel/events/core.c
85687index fa0b2d4..67a1c7a 100644
85688--- a/kernel/events/core.c
85689+++ b/kernel/events/core.c
85690@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85691 * 0 - disallow raw tracepoint access for unpriv
85692 * 1 - disallow cpu events for unpriv
85693 * 2 - disallow kernel profiling for unpriv
85694+ * 3 - disallow all unpriv perf event use
85695 */
85696-int sysctl_perf_event_paranoid __read_mostly = 1;
85697+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85698+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85699+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85700+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85701+#else
85702+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85703+#endif
85704
85705 /* Minimum for 512 kiB + 1 user control page */
85706 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85707@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85708
85709 tmp *= sysctl_perf_cpu_time_max_percent;
85710 do_div(tmp, 100);
85711- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85712+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85713 }
85714
85715 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85716@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85717 update_perf_cpu_limits();
85718 }
85719
85720-static atomic64_t perf_event_id;
85721+static atomic64_unchecked_t perf_event_id;
85722
85723 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85724 enum event_type_t event_type);
85725@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85726
85727 static inline u64 perf_event_count(struct perf_event *event)
85728 {
85729- return local64_read(&event->count) + atomic64_read(&event->child_count);
85730+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85731 }
85732
85733 static u64 perf_event_read(struct perf_event *event)
85734@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85735 mutex_lock(&event->child_mutex);
85736 total += perf_event_read(event);
85737 *enabled += event->total_time_enabled +
85738- atomic64_read(&event->child_total_time_enabled);
85739+ atomic64_read_unchecked(&event->child_total_time_enabled);
85740 *running += event->total_time_running +
85741- atomic64_read(&event->child_total_time_running);
85742+ atomic64_read_unchecked(&event->child_total_time_running);
85743
85744 list_for_each_entry(child, &event->child_list, child_list) {
85745 total += perf_event_read(child);
85746@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85747 userpg->offset -= local64_read(&event->hw.prev_count);
85748
85749 userpg->time_enabled = enabled +
85750- atomic64_read(&event->child_total_time_enabled);
85751+ atomic64_read_unchecked(&event->child_total_time_enabled);
85752
85753 userpg->time_running = running +
85754- atomic64_read(&event->child_total_time_running);
85755+ atomic64_read_unchecked(&event->child_total_time_running);
85756
85757 arch_perf_update_userpage(userpg, now);
85758
85759@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85760
85761 /* Data. */
85762 sp = perf_user_stack_pointer(regs);
85763- rem = __output_copy_user(handle, (void *) sp, dump_size);
85764+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85765 dyn_size = dump_size - rem;
85766
85767 perf_output_skip(handle, rem);
85768@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85769 values[n++] = perf_event_count(event);
85770 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85771 values[n++] = enabled +
85772- atomic64_read(&event->child_total_time_enabled);
85773+ atomic64_read_unchecked(&event->child_total_time_enabled);
85774 }
85775 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85776 values[n++] = running +
85777- atomic64_read(&event->child_total_time_running);
85778+ atomic64_read_unchecked(&event->child_total_time_running);
85779 }
85780 if (read_format & PERF_FORMAT_ID)
85781 values[n++] = primary_event_id(event);
85782@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85783 event->parent = parent_event;
85784
85785 event->ns = get_pid_ns(task_active_pid_ns(current));
85786- event->id = atomic64_inc_return(&perf_event_id);
85787+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85788
85789 event->state = PERF_EVENT_STATE_INACTIVE;
85790
85791@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85792 if (flags & ~PERF_FLAG_ALL)
85793 return -EINVAL;
85794
85795+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85796+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85797+ return -EACCES;
85798+#endif
85799+
85800 err = perf_copy_attr(attr_uptr, &attr);
85801 if (err)
85802 return err;
85803@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85804 /*
85805 * Add back the child's count to the parent's count:
85806 */
85807- atomic64_add(child_val, &parent_event->child_count);
85808- atomic64_add(child_event->total_time_enabled,
85809+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85810+ atomic64_add_unchecked(child_event->total_time_enabled,
85811 &parent_event->child_total_time_enabled);
85812- atomic64_add(child_event->total_time_running,
85813+ atomic64_add_unchecked(child_event->total_time_running,
85814 &parent_event->child_total_time_running);
85815
85816 /*
85817diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85818index 569b2187..19940d9 100644
85819--- a/kernel/events/internal.h
85820+++ b/kernel/events/internal.h
85821@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85822 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85823 }
85824
85825-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85826+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85827 static inline unsigned long \
85828 func_name(struct perf_output_handle *handle, \
85829- const void *buf, unsigned long len) \
85830+ const void user *buf, unsigned long len) \
85831 { \
85832 unsigned long size, written; \
85833 \
85834@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85835 return 0;
85836 }
85837
85838-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85839+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85840
85841 static inline unsigned long
85842 memcpy_skip(void *dst, const void *src, unsigned long n)
85843@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85844 return 0;
85845 }
85846
85847-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85848+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85849
85850 #ifndef arch_perf_out_copy_user
85851 #define arch_perf_out_copy_user arch_perf_out_copy_user
85852@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85853 }
85854 #endif
85855
85856-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85857+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85858
85859 /* Callchain handling */
85860 extern struct perf_callchain_entry *
85861diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85862index 307d87c..6466cbe 100644
85863--- a/kernel/events/uprobes.c
85864+++ b/kernel/events/uprobes.c
85865@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85866 {
85867 struct page *page;
85868 uprobe_opcode_t opcode;
85869- int result;
85870+ long result;
85871
85872 pagefault_disable();
85873 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85874diff --git a/kernel/exit.c b/kernel/exit.c
85875index 81b3d67..ef189a4 100644
85876--- a/kernel/exit.c
85877+++ b/kernel/exit.c
85878@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85879 struct task_struct *leader;
85880 int zap_leader;
85881 repeat:
85882+#ifdef CONFIG_NET
85883+ gr_del_task_from_ip_table(p);
85884+#endif
85885+
85886 /* don't need to get the RCU readlock here - the process is dead and
85887 * can't be modifying its own credentials. But shut RCU-lockdep up */
85888 rcu_read_lock();
85889@@ -330,7 +334,7 @@ int allow_signal(int sig)
85890 * know it'll be handled, so that they don't get converted to
85891 * SIGKILL or just silently dropped.
85892 */
85893- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85894+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85895 recalc_sigpending();
85896 spin_unlock_irq(&current->sighand->siglock);
85897 return 0;
85898@@ -706,6 +710,8 @@ void do_exit(long code)
85899 struct task_struct *tsk = current;
85900 int group_dead;
85901
85902+ set_fs(USER_DS);
85903+
85904 profile_task_exit(tsk);
85905
85906 WARN_ON(blk_needs_flush_plug(tsk));
85907@@ -722,7 +728,6 @@ void do_exit(long code)
85908 * mm_release()->clear_child_tid() from writing to a user-controlled
85909 * kernel address.
85910 */
85911- set_fs(USER_DS);
85912
85913 ptrace_event(PTRACE_EVENT_EXIT, code);
85914
85915@@ -781,6 +786,9 @@ void do_exit(long code)
85916 tsk->exit_code = code;
85917 taskstats_exit(tsk, group_dead);
85918
85919+ gr_acl_handle_psacct(tsk, code);
85920+ gr_acl_handle_exit();
85921+
85922 exit_mm(tsk);
85923
85924 if (group_dead)
85925@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85926 * Take down every thread in the group. This is called by fatal signals
85927 * as well as by sys_exit_group (below).
85928 */
85929-void
85930+__noreturn void
85931 do_group_exit(int exit_code)
85932 {
85933 struct signal_struct *sig = current->signal;
85934diff --git a/kernel/fork.c b/kernel/fork.c
85935index a17621c..b77fef8 100644
85936--- a/kernel/fork.c
85937+++ b/kernel/fork.c
85938@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85939 *stackend = STACK_END_MAGIC; /* for overflow detection */
85940
85941 #ifdef CONFIG_CC_STACKPROTECTOR
85942- tsk->stack_canary = get_random_int();
85943+ tsk->stack_canary = pax_get_random_long();
85944 #endif
85945
85946 /*
85947@@ -345,12 +345,80 @@ free_tsk:
85948 }
85949
85950 #ifdef CONFIG_MMU
85951-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85952+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85953+{
85954+ struct vm_area_struct *tmp;
85955+ unsigned long charge;
85956+ struct file *file;
85957+ int retval;
85958+
85959+ charge = 0;
85960+ if (mpnt->vm_flags & VM_ACCOUNT) {
85961+ unsigned long len = vma_pages(mpnt);
85962+
85963+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85964+ goto fail_nomem;
85965+ charge = len;
85966+ }
85967+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85968+ if (!tmp)
85969+ goto fail_nomem;
85970+ *tmp = *mpnt;
85971+ tmp->vm_mm = mm;
85972+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
85973+ retval = vma_dup_policy(mpnt, tmp);
85974+ if (retval)
85975+ goto fail_nomem_policy;
85976+ if (anon_vma_fork(tmp, mpnt))
85977+ goto fail_nomem_anon_vma_fork;
85978+ tmp->vm_flags &= ~VM_LOCKED;
85979+ tmp->vm_next = tmp->vm_prev = NULL;
85980+ tmp->vm_mirror = NULL;
85981+ file = tmp->vm_file;
85982+ if (file) {
85983+ struct inode *inode = file_inode(file);
85984+ struct address_space *mapping = file->f_mapping;
85985+
85986+ get_file(file);
85987+ if (tmp->vm_flags & VM_DENYWRITE)
85988+ atomic_dec(&inode->i_writecount);
85989+ mutex_lock(&mapping->i_mmap_mutex);
85990+ if (tmp->vm_flags & VM_SHARED)
85991+ mapping->i_mmap_writable++;
85992+ flush_dcache_mmap_lock(mapping);
85993+ /* insert tmp into the share list, just after mpnt */
85994+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85995+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85996+ else
85997+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85998+ flush_dcache_mmap_unlock(mapping);
85999+ mutex_unlock(&mapping->i_mmap_mutex);
86000+ }
86001+
86002+ /*
86003+ * Clear hugetlb-related page reserves for children. This only
86004+ * affects MAP_PRIVATE mappings. Faults generated by the child
86005+ * are not guaranteed to succeed, even if read-only
86006+ */
86007+ if (is_vm_hugetlb_page(tmp))
86008+ reset_vma_resv_huge_pages(tmp);
86009+
86010+ return tmp;
86011+
86012+fail_nomem_anon_vma_fork:
86013+ mpol_put(vma_policy(tmp));
86014+fail_nomem_policy:
86015+ kmem_cache_free(vm_area_cachep, tmp);
86016+fail_nomem:
86017+ vm_unacct_memory(charge);
86018+ return NULL;
86019+}
86020+
86021+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86022 {
86023 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86024 struct rb_node **rb_link, *rb_parent;
86025 int retval;
86026- unsigned long charge;
86027
86028 uprobe_start_dup_mmap();
86029 down_write(&oldmm->mmap_sem);
86030@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86031
86032 prev = NULL;
86033 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86034- struct file *file;
86035-
86036 if (mpnt->vm_flags & VM_DONTCOPY) {
86037 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86038 -vma_pages(mpnt));
86039 continue;
86040 }
86041- charge = 0;
86042- if (mpnt->vm_flags & VM_ACCOUNT) {
86043- unsigned long len = vma_pages(mpnt);
86044-
86045- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86046- goto fail_nomem;
86047- charge = len;
86048- }
86049- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86050- if (!tmp)
86051- goto fail_nomem;
86052- *tmp = *mpnt;
86053- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86054- retval = vma_dup_policy(mpnt, tmp);
86055- if (retval)
86056- goto fail_nomem_policy;
86057- tmp->vm_mm = mm;
86058- if (anon_vma_fork(tmp, mpnt))
86059- goto fail_nomem_anon_vma_fork;
86060- tmp->vm_flags &= ~VM_LOCKED;
86061- tmp->vm_next = tmp->vm_prev = NULL;
86062- file = tmp->vm_file;
86063- if (file) {
86064- struct inode *inode = file_inode(file);
86065- struct address_space *mapping = file->f_mapping;
86066-
86067- get_file(file);
86068- if (tmp->vm_flags & VM_DENYWRITE)
86069- atomic_dec(&inode->i_writecount);
86070- mutex_lock(&mapping->i_mmap_mutex);
86071- if (tmp->vm_flags & VM_SHARED)
86072- mapping->i_mmap_writable++;
86073- flush_dcache_mmap_lock(mapping);
86074- /* insert tmp into the share list, just after mpnt */
86075- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86076- vma_nonlinear_insert(tmp,
86077- &mapping->i_mmap_nonlinear);
86078- else
86079- vma_interval_tree_insert_after(tmp, mpnt,
86080- &mapping->i_mmap);
86081- flush_dcache_mmap_unlock(mapping);
86082- mutex_unlock(&mapping->i_mmap_mutex);
86083+ tmp = dup_vma(mm, oldmm, mpnt);
86084+ if (!tmp) {
86085+ retval = -ENOMEM;
86086+ goto out;
86087 }
86088
86089 /*
86090@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86091 if (retval)
86092 goto out;
86093 }
86094+
86095+#ifdef CONFIG_PAX_SEGMEXEC
86096+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86097+ struct vm_area_struct *mpnt_m;
86098+
86099+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86100+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86101+
86102+ if (!mpnt->vm_mirror)
86103+ continue;
86104+
86105+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86106+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86107+ mpnt->vm_mirror = mpnt_m;
86108+ } else {
86109+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86110+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86111+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86112+ mpnt->vm_mirror->vm_mirror = mpnt;
86113+ }
86114+ }
86115+ BUG_ON(mpnt_m);
86116+ }
86117+#endif
86118+
86119 /* a new mm has just been created */
86120 arch_dup_mmap(oldmm, mm);
86121 retval = 0;
86122@@ -468,14 +521,6 @@ out:
86123 up_write(&oldmm->mmap_sem);
86124 uprobe_end_dup_mmap();
86125 return retval;
86126-fail_nomem_anon_vma_fork:
86127- mpol_put(vma_policy(tmp));
86128-fail_nomem_policy:
86129- kmem_cache_free(vm_area_cachep, tmp);
86130-fail_nomem:
86131- retval = -ENOMEM;
86132- vm_unacct_memory(charge);
86133- goto out;
86134 }
86135
86136 static inline int mm_alloc_pgd(struct mm_struct *mm)
86137@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86138 return ERR_PTR(err);
86139
86140 mm = get_task_mm(task);
86141- if (mm && mm != current->mm &&
86142- !ptrace_may_access(task, mode)) {
86143+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86144+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86145 mmput(mm);
86146 mm = ERR_PTR(-EACCES);
86147 }
86148@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86149 spin_unlock(&fs->lock);
86150 return -EAGAIN;
86151 }
86152- fs->users++;
86153+ atomic_inc(&fs->users);
86154 spin_unlock(&fs->lock);
86155 return 0;
86156 }
86157 tsk->fs = copy_fs_struct(fs);
86158 if (!tsk->fs)
86159 return -ENOMEM;
86160+ /* Carry through gr_chroot_dentry and is_chrooted instead
86161+ of recomputing it here. Already copied when the task struct
86162+ is duplicated. This allows pivot_root to not be treated as
86163+ a chroot
86164+ */
86165+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86166+
86167 return 0;
86168 }
86169
86170@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86171 * parts of the process environment (as per the clone
86172 * flags). The actual kick-off is left to the caller.
86173 */
86174-static struct task_struct *copy_process(unsigned long clone_flags,
86175+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86176 unsigned long stack_start,
86177 unsigned long stack_size,
86178 int __user *child_tidptr,
86179@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86180 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86181 #endif
86182 retval = -EAGAIN;
86183+
86184+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86185+
86186 if (atomic_read(&p->real_cred->user->processes) >=
86187 task_rlimit(p, RLIMIT_NPROC)) {
86188 if (p->real_cred->user != INIT_USER &&
86189@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86190 goto bad_fork_free_pid;
86191 }
86192
86193+ /* synchronizes with gr_set_acls()
86194+ we need to call this past the point of no return for fork()
86195+ */
86196+ gr_copy_label(p);
86197+
86198 if (likely(p->pid)) {
86199 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86200
86201@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86202 bad_fork_free:
86203 free_task(p);
86204 fork_out:
86205+ gr_log_forkfail(retval);
86206+
86207 return ERR_PTR(retval);
86208 }
86209
86210@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86211
86212 p = copy_process(clone_flags, stack_start, stack_size,
86213 child_tidptr, NULL, trace);
86214+ add_latent_entropy();
86215 /*
86216 * Do this prior waking up the new thread - the thread pointer
86217 * might get invalid after that point, if the thread exits quickly.
86218@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86219 if (clone_flags & CLONE_PARENT_SETTID)
86220 put_user(nr, parent_tidptr);
86221
86222+ gr_handle_brute_check();
86223+
86224 if (clone_flags & CLONE_VFORK) {
86225 p->vfork_done = &vfork;
86226 init_completion(&vfork);
86227@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86228 mm_cachep = kmem_cache_create("mm_struct",
86229 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86230 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86231- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86232+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86233 mmap_init();
86234 nsproxy_cache_init();
86235 }
86236@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86237 return 0;
86238
86239 /* don't need lock here; in the worst case we'll do useless copy */
86240- if (fs->users == 1)
86241+ if (atomic_read(&fs->users) == 1)
86242 return 0;
86243
86244 *new_fsp = copy_fs_struct(fs);
86245@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86246 fs = current->fs;
86247 spin_lock(&fs->lock);
86248 current->fs = new_fs;
86249- if (--fs->users)
86250+ gr_set_chroot_entries(current, &current->fs->root);
86251+ if (atomic_dec_return(&fs->users))
86252 new_fs = NULL;
86253 else
86254 new_fs = fs;
86255diff --git a/kernel/futex.c b/kernel/futex.c
86256index 6801b37..bb6becca 100644
86257--- a/kernel/futex.c
86258+++ b/kernel/futex.c
86259@@ -54,6 +54,7 @@
86260 #include <linux/mount.h>
86261 #include <linux/pagemap.h>
86262 #include <linux/syscalls.h>
86263+#include <linux/ptrace.h>
86264 #include <linux/signal.h>
86265 #include <linux/export.h>
86266 #include <linux/magic.h>
86267@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86268 struct page *page, *page_head;
86269 int err, ro = 0;
86270
86271+#ifdef CONFIG_PAX_SEGMEXEC
86272+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86273+ return -EFAULT;
86274+#endif
86275+
86276 /*
86277 * The futex address must be "naturally" aligned.
86278 */
86279@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86280
86281 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86282 {
86283- int ret;
86284+ unsigned long ret;
86285
86286 pagefault_disable();
86287 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86288@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86289 {
86290 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86291 u32 curval;
86292+ mm_segment_t oldfs;
86293
86294 /*
86295 * This will fail and we want it. Some arch implementations do
86296@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86297 * implementation, the non-functional ones will return
86298 * -ENOSYS.
86299 */
86300+ oldfs = get_fs();
86301+ set_fs(USER_DS);
86302 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86303 futex_cmpxchg_enabled = 1;
86304+ set_fs(oldfs);
86305 #endif
86306 }
86307
86308diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86309index f9f44fd..29885e4 100644
86310--- a/kernel/futex_compat.c
86311+++ b/kernel/futex_compat.c
86312@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86313 return 0;
86314 }
86315
86316-static void __user *futex_uaddr(struct robust_list __user *entry,
86317+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86318 compat_long_t futex_offset)
86319 {
86320 compat_uptr_t base = ptr_to_compat(entry);
86321diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86322index f45b75b..bfac6d5 100644
86323--- a/kernel/gcov/base.c
86324+++ b/kernel/gcov/base.c
86325@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86326 }
86327
86328 #ifdef CONFIG_MODULES
86329-static inline int within(void *addr, void *start, unsigned long size)
86330-{
86331- return ((addr >= start) && (addr < start + size));
86332-}
86333-
86334 /* Update list and generate events when modules are unloaded. */
86335 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86336 void *data)
86337@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86338
86339 /* Remove entries located in module from linked list. */
86340 while ((info = gcov_info_next(info))) {
86341- if (within(info, mod->module_core, mod->core_size)) {
86342+ if (within_module_core_rw((unsigned long)info, mod)) {
86343 gcov_info_unlink(prev, info);
86344 if (gcov_events_enabled)
86345 gcov_event(GCOV_REMOVE, info);
86346diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86347index 0909436..6037d22 100644
86348--- a/kernel/hrtimer.c
86349+++ b/kernel/hrtimer.c
86350@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86351 local_irq_restore(flags);
86352 }
86353
86354-static void run_hrtimer_softirq(struct softirq_action *h)
86355+static __latent_entropy void run_hrtimer_softirq(void)
86356 {
86357 hrtimer_peek_ahead_timers();
86358 }
86359diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86360index 55fcce6..0e4cf34 100644
86361--- a/kernel/irq_work.c
86362+++ b/kernel/irq_work.c
86363@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86364 return NOTIFY_OK;
86365 }
86366
86367-static struct notifier_block cpu_notify;
86368+static struct notifier_block cpu_notify = {
86369+ .notifier_call = irq_work_cpu_notify,
86370+ .priority = 0,
86371+};
86372
86373 static __init int irq_work_init_cpu_notifier(void)
86374 {
86375- cpu_notify.notifier_call = irq_work_cpu_notify;
86376- cpu_notify.priority = 0;
86377 register_cpu_notifier(&cpu_notify);
86378 return 0;
86379 }
86380diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86381index 9019f15..9a3c42e 100644
86382--- a/kernel/jump_label.c
86383+++ b/kernel/jump_label.c
86384@@ -14,6 +14,7 @@
86385 #include <linux/err.h>
86386 #include <linux/static_key.h>
86387 #include <linux/jump_label_ratelimit.h>
86388+#include <linux/mm.h>
86389
86390 #ifdef HAVE_JUMP_LABEL
86391
86392@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86393
86394 size = (((unsigned long)stop - (unsigned long)start)
86395 / sizeof(struct jump_entry));
86396+ pax_open_kernel();
86397 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86398+ pax_close_kernel();
86399 }
86400
86401 static void jump_label_update(struct static_key *key, int enable);
86402@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86403 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86404 struct jump_entry *iter;
86405
86406+ pax_open_kernel();
86407 for (iter = iter_start; iter < iter_stop; iter++) {
86408 if (within_module_init(iter->code, mod))
86409 iter->code = 0;
86410 }
86411+ pax_close_kernel();
86412 }
86413
86414 static int
86415diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86416index 3127ad5..159d880 100644
86417--- a/kernel/kallsyms.c
86418+++ b/kernel/kallsyms.c
86419@@ -11,6 +11,9 @@
86420 * Changed the compression method from stem compression to "table lookup"
86421 * compression (see scripts/kallsyms.c for a more complete description)
86422 */
86423+#ifdef CONFIG_GRKERNSEC_HIDESYM
86424+#define __INCLUDED_BY_HIDESYM 1
86425+#endif
86426 #include <linux/kallsyms.h>
86427 #include <linux/module.h>
86428 #include <linux/init.h>
86429@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86430
86431 static inline int is_kernel_inittext(unsigned long addr)
86432 {
86433+ if (system_state != SYSTEM_BOOTING)
86434+ return 0;
86435+
86436 if (addr >= (unsigned long)_sinittext
86437 && addr <= (unsigned long)_einittext)
86438 return 1;
86439 return 0;
86440 }
86441
86442+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86443+#ifdef CONFIG_MODULES
86444+static inline int is_module_text(unsigned long addr)
86445+{
86446+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86447+ return 1;
86448+
86449+ addr = ktla_ktva(addr);
86450+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86451+}
86452+#else
86453+static inline int is_module_text(unsigned long addr)
86454+{
86455+ return 0;
86456+}
86457+#endif
86458+#endif
86459+
86460 static inline int is_kernel_text(unsigned long addr)
86461 {
86462 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86463@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86464
86465 static inline int is_kernel(unsigned long addr)
86466 {
86467+
86468+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86469+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86470+ return 1;
86471+
86472+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86473+#else
86474 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86475+#endif
86476+
86477 return 1;
86478 return in_gate_area_no_mm(addr);
86479 }
86480
86481 static int is_ksym_addr(unsigned long addr)
86482 {
86483+
86484+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86485+ if (is_module_text(addr))
86486+ return 0;
86487+#endif
86488+
86489 if (all_var)
86490 return is_kernel(addr);
86491
86492@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86493
86494 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86495 {
86496- iter->name[0] = '\0';
86497 iter->nameoff = get_symbol_offset(new_pos);
86498 iter->pos = new_pos;
86499 }
86500@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86501 {
86502 struct kallsym_iter *iter = m->private;
86503
86504+#ifdef CONFIG_GRKERNSEC_HIDESYM
86505+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86506+ return 0;
86507+#endif
86508+
86509 /* Some debugging symbols have no name. Ignore them. */
86510 if (!iter->name[0])
86511 return 0;
86512@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86513 */
86514 type = iter->exported ? toupper(iter->type) :
86515 tolower(iter->type);
86516+
86517 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86518 type, iter->name, iter->module_name);
86519 } else
86520@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86521 struct kallsym_iter *iter;
86522 int ret;
86523
86524- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86525+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86526 if (!iter)
86527 return -ENOMEM;
86528 reset_iter(iter, 0);
86529diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86530index e30ac0f..3528cac 100644
86531--- a/kernel/kcmp.c
86532+++ b/kernel/kcmp.c
86533@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86534 struct task_struct *task1, *task2;
86535 int ret;
86536
86537+#ifdef CONFIG_GRKERNSEC
86538+ return -ENOSYS;
86539+#endif
86540+
86541 rcu_read_lock();
86542
86543 /*
86544diff --git a/kernel/kexec.c b/kernel/kexec.c
86545index 60bafbe..a120f4f 100644
86546--- a/kernel/kexec.c
86547+++ b/kernel/kexec.c
86548@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86549 unsigned long flags)
86550 {
86551 struct compat_kexec_segment in;
86552- struct kexec_segment out, __user *ksegments;
86553+ struct kexec_segment out;
86554+ struct kexec_segment __user *ksegments;
86555 unsigned long i, result;
86556
86557 /* Don't allow clients that don't understand the native
86558diff --git a/kernel/kmod.c b/kernel/kmod.c
86559index 6b375af..eaff670 100644
86560--- a/kernel/kmod.c
86561+++ b/kernel/kmod.c
86562@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86563 kfree(info->argv);
86564 }
86565
86566-static int call_modprobe(char *module_name, int wait)
86567+static int call_modprobe(char *module_name, char *module_param, int wait)
86568 {
86569 struct subprocess_info *info;
86570 static char *envp[] = {
86571@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86572 NULL
86573 };
86574
86575- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86576+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86577 if (!argv)
86578 goto out;
86579
86580@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86581 argv[1] = "-q";
86582 argv[2] = "--";
86583 argv[3] = module_name; /* check free_modprobe_argv() */
86584- argv[4] = NULL;
86585+ argv[4] = module_param;
86586+ argv[5] = NULL;
86587
86588 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86589 NULL, free_modprobe_argv, NULL);
86590@@ -129,9 +130,8 @@ out:
86591 * If module auto-loading support is disabled then this function
86592 * becomes a no-operation.
86593 */
86594-int __request_module(bool wait, const char *fmt, ...)
86595+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86596 {
86597- va_list args;
86598 char module_name[MODULE_NAME_LEN];
86599 unsigned int max_modprobes;
86600 int ret;
86601@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86602 if (!modprobe_path[0])
86603 return 0;
86604
86605- va_start(args, fmt);
86606- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86607- va_end(args);
86608+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86609 if (ret >= MODULE_NAME_LEN)
86610 return -ENAMETOOLONG;
86611
86612@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86613 if (ret)
86614 return ret;
86615
86616+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86617+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86618+ /* hack to workaround consolekit/udisks stupidity */
86619+ read_lock(&tasklist_lock);
86620+ if (!strcmp(current->comm, "mount") &&
86621+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86622+ read_unlock(&tasklist_lock);
86623+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86624+ return -EPERM;
86625+ }
86626+ read_unlock(&tasklist_lock);
86627+ }
86628+#endif
86629+
86630 /* If modprobe needs a service that is in a module, we get a recursive
86631 * loop. Limit the number of running kmod threads to max_threads/2 or
86632 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86633@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86634
86635 trace_module_request(module_name, wait, _RET_IP_);
86636
86637- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86638+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86639
86640 atomic_dec(&kmod_concurrent);
86641 return ret;
86642 }
86643+
86644+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86645+{
86646+ va_list args;
86647+ int ret;
86648+
86649+ va_start(args, fmt);
86650+ ret = ____request_module(wait, module_param, fmt, args);
86651+ va_end(args);
86652+
86653+ return ret;
86654+}
86655+
86656+int __request_module(bool wait, const char *fmt, ...)
86657+{
86658+ va_list args;
86659+ int ret;
86660+
86661+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86662+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86663+ char module_param[MODULE_NAME_LEN];
86664+
86665+ memset(module_param, 0, sizeof(module_param));
86666+
86667+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86668+
86669+ va_start(args, fmt);
86670+ ret = ____request_module(wait, module_param, fmt, args);
86671+ va_end(args);
86672+
86673+ return ret;
86674+ }
86675+#endif
86676+
86677+ va_start(args, fmt);
86678+ ret = ____request_module(wait, NULL, fmt, args);
86679+ va_end(args);
86680+
86681+ return ret;
86682+}
86683+
86684 EXPORT_SYMBOL(__request_module);
86685 #endif /* CONFIG_MODULES */
86686
86687@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86688 */
86689 set_user_nice(current, 0);
86690
86691+#ifdef CONFIG_GRKERNSEC
86692+ /* this is race-free as far as userland is concerned as we copied
86693+ out the path to be used prior to this point and are now operating
86694+ on that copy
86695+ */
86696+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86697+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86698+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86699+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86700+ retval = -EPERM;
86701+ goto fail;
86702+ }
86703+#endif
86704+
86705 retval = -ENOMEM;
86706 new = prepare_kernel_cred(current);
86707 if (!new)
86708@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86709 commit_creds(new);
86710
86711 retval = do_execve(getname_kernel(sub_info->path),
86712- (const char __user *const __user *)sub_info->argv,
86713- (const char __user *const __user *)sub_info->envp);
86714+ (const char __user *const __force_user *)sub_info->argv,
86715+ (const char __user *const __force_user *)sub_info->envp);
86716 if (!retval)
86717 return 0;
86718
86719@@ -260,6 +327,10 @@ static int call_helper(void *data)
86720
86721 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86722 {
86723+#ifdef CONFIG_GRKERNSEC
86724+ kfree(info->path);
86725+ info->path = info->origpath;
86726+#endif
86727 if (info->cleanup)
86728 (*info->cleanup)(info);
86729 kfree(info);
86730@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86731 *
86732 * Thus the __user pointer cast is valid here.
86733 */
86734- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86735+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86736
86737 /*
86738 * If ret is 0, either ____call_usermodehelper failed and the
86739@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86740 goto out;
86741
86742 INIT_WORK(&sub_info->work, __call_usermodehelper);
86743+#ifdef CONFIG_GRKERNSEC
86744+ sub_info->origpath = path;
86745+ sub_info->path = kstrdup(path, gfp_mask);
86746+#else
86747 sub_info->path = path;
86748+#endif
86749 sub_info->argv = argv;
86750 sub_info->envp = envp;
86751
86752@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86753 static int proc_cap_handler(struct ctl_table *table, int write,
86754 void __user *buffer, size_t *lenp, loff_t *ppos)
86755 {
86756- struct ctl_table t;
86757+ ctl_table_no_const t;
86758 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86759 kernel_cap_t new_cap;
86760 int err, i;
86761diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86762index ceeadfc..11c18b6 100644
86763--- a/kernel/kprobes.c
86764+++ b/kernel/kprobes.c
86765@@ -31,6 +31,9 @@
86766 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86767 * <prasanna@in.ibm.com> added function-return probes.
86768 */
86769+#ifdef CONFIG_GRKERNSEC_HIDESYM
86770+#define __INCLUDED_BY_HIDESYM 1
86771+#endif
86772 #include <linux/kprobes.h>
86773 #include <linux/hash.h>
86774 #include <linux/init.h>
86775@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86776
86777 static void *alloc_insn_page(void)
86778 {
86779- return module_alloc(PAGE_SIZE);
86780+ return module_alloc_exec(PAGE_SIZE);
86781 }
86782
86783 static void free_insn_page(void *page)
86784 {
86785- module_free(NULL, page);
86786+ module_free_exec(NULL, page);
86787 }
86788
86789 struct kprobe_insn_cache kprobe_insn_slots = {
86790@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86791 kprobe_type = "k";
86792
86793 if (sym)
86794- seq_printf(pi, "%p %s %s+0x%x %s ",
86795+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86796 p->addr, kprobe_type, sym, offset,
86797 (modname ? modname : " "));
86798 else
86799- seq_printf(pi, "%p %s %p ",
86800+ seq_printf(pi, "%pK %s %pK ",
86801 p->addr, kprobe_type, p->addr);
86802
86803 if (!pp)
86804diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86805index d945a94..0b7f45f 100644
86806--- a/kernel/ksysfs.c
86807+++ b/kernel/ksysfs.c
86808@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86809 {
86810 if (count+1 > UEVENT_HELPER_PATH_LEN)
86811 return -ENOENT;
86812+ if (!capable(CAP_SYS_ADMIN))
86813+ return -EPERM;
86814 memcpy(uevent_helper, buf, count);
86815 uevent_helper[count] = '\0';
86816 if (count && uevent_helper[count-1] == '\n')
86817@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86818 return count;
86819 }
86820
86821-static struct bin_attribute notes_attr = {
86822+static bin_attribute_no_const notes_attr __read_only = {
86823 .attr = {
86824 .name = "notes",
86825 .mode = S_IRUGO,
86826diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86827index eb8a547..321d8e1 100644
86828--- a/kernel/locking/lockdep.c
86829+++ b/kernel/locking/lockdep.c
86830@@ -597,6 +597,10 @@ static int static_obj(void *obj)
86831 end = (unsigned long) &_end,
86832 addr = (unsigned long) obj;
86833
86834+#ifdef CONFIG_PAX_KERNEXEC
86835+ start = ktla_ktva(start);
86836+#endif
86837+
86838 /*
86839 * static variable?
86840 */
86841@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86842 if (!static_obj(lock->key)) {
86843 debug_locks_off();
86844 printk("INFO: trying to register non-static key.\n");
86845+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86846 printk("the code is fine but needs lockdep annotation.\n");
86847 printk("turning off the locking correctness validator.\n");
86848 dump_stack();
86849@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86850 if (!class)
86851 return 0;
86852 }
86853- atomic_inc((atomic_t *)&class->ops);
86854+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86855 if (very_verbose(class)) {
86856 printk("\nacquire class [%p] %s", class->key, class->name);
86857 if (class->name_version > 1)
86858diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86859index ef43ac4..2720dfa 100644
86860--- a/kernel/locking/lockdep_proc.c
86861+++ b/kernel/locking/lockdep_proc.c
86862@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86863 return 0;
86864 }
86865
86866- seq_printf(m, "%p", class->key);
86867+ seq_printf(m, "%pK", class->key);
86868 #ifdef CONFIG_DEBUG_LOCKDEP
86869 seq_printf(m, " OPS:%8ld", class->ops);
86870 #endif
86871@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86872
86873 list_for_each_entry(entry, &class->locks_after, entry) {
86874 if (entry->distance == 1) {
86875- seq_printf(m, " -> [%p] ", entry->class->key);
86876+ seq_printf(m, " -> [%pK] ", entry->class->key);
86877 print_name(m, entry->class);
86878 seq_puts(m, "\n");
86879 }
86880@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86881 if (!class->key)
86882 continue;
86883
86884- seq_printf(m, "[%p] ", class->key);
86885+ seq_printf(m, "[%pK] ", class->key);
86886 print_name(m, class);
86887 seq_puts(m, "\n");
86888 }
86889@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86890 if (!i)
86891 seq_line(m, '-', 40-namelen, namelen);
86892
86893- snprintf(ip, sizeof(ip), "[<%p>]",
86894+ snprintf(ip, sizeof(ip), "[<%pK>]",
86895 (void *)class->contention_point[i]);
86896 seq_printf(m, "%40s %14lu %29s %pS\n",
86897 name, stats->contention_point[i],
86898@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86899 if (!i)
86900 seq_line(m, '-', 40-namelen, namelen);
86901
86902- snprintf(ip, sizeof(ip), "[<%p>]",
86903+ snprintf(ip, sizeof(ip), "[<%pK>]",
86904 (void *)class->contending_point[i]);
86905 seq_printf(m, "%40s %14lu %29s %pS\n",
86906 name, stats->contending_point[i],
86907diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86908index faf6f5b..dc9070a 100644
86909--- a/kernel/locking/mutex-debug.c
86910+++ b/kernel/locking/mutex-debug.c
86911@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86912 }
86913
86914 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86915- struct thread_info *ti)
86916+ struct task_struct *task)
86917 {
86918 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86919
86920 /* Mark the current thread as blocked on the lock: */
86921- ti->task->blocked_on = waiter;
86922+ task->blocked_on = waiter;
86923 }
86924
86925 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86926- struct thread_info *ti)
86927+ struct task_struct *task)
86928 {
86929 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86930- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86931- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86932- ti->task->blocked_on = NULL;
86933+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
86934+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86935+ task->blocked_on = NULL;
86936
86937 list_del_init(&waiter->list);
86938 waiter->task = NULL;
86939diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86940index 0799fd3..d06ae3b 100644
86941--- a/kernel/locking/mutex-debug.h
86942+++ b/kernel/locking/mutex-debug.h
86943@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86944 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86945 extern void debug_mutex_add_waiter(struct mutex *lock,
86946 struct mutex_waiter *waiter,
86947- struct thread_info *ti);
86948+ struct task_struct *task);
86949 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86950- struct thread_info *ti);
86951+ struct task_struct *task);
86952 extern void debug_mutex_unlock(struct mutex *lock);
86953 extern void debug_mutex_init(struct mutex *lock, const char *name,
86954 struct lock_class_key *key);
86955diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86956index 4dd6e4c..df52693 100644
86957--- a/kernel/locking/mutex.c
86958+++ b/kernel/locking/mutex.c
86959@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86960 node->locked = 1;
86961 return;
86962 }
86963- ACCESS_ONCE(prev->next) = node;
86964+ ACCESS_ONCE_RW(prev->next) = node;
86965 smp_wmb();
86966 /* Wait until the lock holder passes the lock down */
86967 while (!ACCESS_ONCE(node->locked))
86968@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86969 while (!(next = ACCESS_ONCE(node->next)))
86970 arch_mutex_cpu_relax();
86971 }
86972- ACCESS_ONCE(next->locked) = 1;
86973+ ACCESS_ONCE_RW(next->locked) = 1;
86974 smp_wmb();
86975 }
86976
86977@@ -520,7 +520,7 @@ slowpath:
86978 goto skip_wait;
86979
86980 debug_mutex_lock_common(lock, &waiter);
86981- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86982+ debug_mutex_add_waiter(lock, &waiter, task);
86983
86984 /* add waiting tasks to the end of the waitqueue (FIFO): */
86985 list_add_tail(&waiter.list, &lock->wait_list);
86986@@ -564,7 +564,7 @@ slowpath:
86987 schedule_preempt_disabled();
86988 spin_lock_mutex(&lock->wait_lock, flags);
86989 }
86990- mutex_remove_waiter(lock, &waiter, current_thread_info());
86991+ mutex_remove_waiter(lock, &waiter, task);
86992 /* set it to 0 if there are no waiters left: */
86993 if (likely(list_empty(&lock->wait_list)))
86994 atomic_set(&lock->count, 0);
86995@@ -601,7 +601,7 @@ skip_wait:
86996 return 0;
86997
86998 err:
86999- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87000+ mutex_remove_waiter(lock, &waiter, task);
87001 spin_unlock_mutex(&lock->wait_lock, flags);
87002 debug_mutex_free_waiter(&waiter);
87003 mutex_release(&lock->dep_map, 1, ip);
87004diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87005index 1d96dd0..994ff19 100644
87006--- a/kernel/locking/rtmutex-tester.c
87007+++ b/kernel/locking/rtmutex-tester.c
87008@@ -22,7 +22,7 @@
87009 #define MAX_RT_TEST_MUTEXES 8
87010
87011 static spinlock_t rttest_lock;
87012-static atomic_t rttest_event;
87013+static atomic_unchecked_t rttest_event;
87014
87015 struct test_thread_data {
87016 int opcode;
87017@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87018
87019 case RTTEST_LOCKCONT:
87020 td->mutexes[td->opdata] = 1;
87021- td->event = atomic_add_return(1, &rttest_event);
87022+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87023 return 0;
87024
87025 case RTTEST_RESET:
87026@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87027 return 0;
87028
87029 case RTTEST_RESETEVENT:
87030- atomic_set(&rttest_event, 0);
87031+ atomic_set_unchecked(&rttest_event, 0);
87032 return 0;
87033
87034 default:
87035@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87036 return ret;
87037
87038 td->mutexes[id] = 1;
87039- td->event = atomic_add_return(1, &rttest_event);
87040+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87041 rt_mutex_lock(&mutexes[id]);
87042- td->event = atomic_add_return(1, &rttest_event);
87043+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87044 td->mutexes[id] = 4;
87045 return 0;
87046
87047@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87048 return ret;
87049
87050 td->mutexes[id] = 1;
87051- td->event = atomic_add_return(1, &rttest_event);
87052+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87053 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87054- td->event = atomic_add_return(1, &rttest_event);
87055+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87056 td->mutexes[id] = ret ? 0 : 4;
87057 return ret ? -EINTR : 0;
87058
87059@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87060 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87061 return ret;
87062
87063- td->event = atomic_add_return(1, &rttest_event);
87064+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87065 rt_mutex_unlock(&mutexes[id]);
87066- td->event = atomic_add_return(1, &rttest_event);
87067+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87068 td->mutexes[id] = 0;
87069 return 0;
87070
87071@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87072 break;
87073
87074 td->mutexes[dat] = 2;
87075- td->event = atomic_add_return(1, &rttest_event);
87076+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87077 break;
87078
87079 default:
87080@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87081 return;
87082
87083 td->mutexes[dat] = 3;
87084- td->event = atomic_add_return(1, &rttest_event);
87085+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87086 break;
87087
87088 case RTTEST_LOCKNOWAIT:
87089@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87090 return;
87091
87092 td->mutexes[dat] = 1;
87093- td->event = atomic_add_return(1, &rttest_event);
87094+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87095 return;
87096
87097 default:
87098diff --git a/kernel/module.c b/kernel/module.c
87099index d24fcf2..2af3fd9 100644
87100--- a/kernel/module.c
87101+++ b/kernel/module.c
87102@@ -61,6 +61,7 @@
87103 #include <linux/pfn.h>
87104 #include <linux/bsearch.h>
87105 #include <linux/fips.h>
87106+#include <linux/grsecurity.h>
87107 #include <uapi/linux/module.h>
87108 #include "module-internal.h"
87109
87110@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87111
87112 /* Bounds of module allocation, for speeding __module_address.
87113 * Protected by module_mutex. */
87114-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87115+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87116+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87117
87118 int register_module_notifier(struct notifier_block * nb)
87119 {
87120@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87121 return true;
87122
87123 list_for_each_entry_rcu(mod, &modules, list) {
87124- struct symsearch arr[] = {
87125+ struct symsearch modarr[] = {
87126 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87127 NOT_GPL_ONLY, false },
87128 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87129@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87130 if (mod->state == MODULE_STATE_UNFORMED)
87131 continue;
87132
87133- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87134+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87135 return true;
87136 }
87137 return false;
87138@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87139 if (!pcpusec->sh_size)
87140 return 0;
87141
87142- if (align > PAGE_SIZE) {
87143+ if (align-1 >= PAGE_SIZE) {
87144 pr_warn("%s: per-cpu alignment %li > %li\n",
87145 mod->name, align, PAGE_SIZE);
87146 align = PAGE_SIZE;
87147@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87148 static ssize_t show_coresize(struct module_attribute *mattr,
87149 struct module_kobject *mk, char *buffer)
87150 {
87151- return sprintf(buffer, "%u\n", mk->mod->core_size);
87152+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87153 }
87154
87155 static struct module_attribute modinfo_coresize =
87156@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87157 static ssize_t show_initsize(struct module_attribute *mattr,
87158 struct module_kobject *mk, char *buffer)
87159 {
87160- return sprintf(buffer, "%u\n", mk->mod->init_size);
87161+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87162 }
87163
87164 static struct module_attribute modinfo_initsize =
87165@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87166 goto bad_version;
87167 }
87168
87169+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87170+ /*
87171+ * avoid potentially printing jibberish on attempted load
87172+ * of a module randomized with a different seed
87173+ */
87174+ pr_warn("no symbol version for %s\n", symname);
87175+#else
87176 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87177+#endif
87178 return 0;
87179
87180 bad_version:
87181+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87182+ /*
87183+ * avoid potentially printing jibberish on attempted load
87184+ * of a module randomized with a different seed
87185+ */
87186+ printk("attempted module disagrees about version of symbol %s\n",
87187+ symname);
87188+#else
87189 printk("%s: disagrees about version of symbol %s\n",
87190 mod->name, symname);
87191+#endif
87192 return 0;
87193 }
87194
87195@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87196 */
87197 #ifdef CONFIG_SYSFS
87198
87199-#ifdef CONFIG_KALLSYMS
87200+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87201 static inline bool sect_empty(const Elf_Shdr *sect)
87202 {
87203 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87204@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87205 {
87206 unsigned int notes, loaded, i;
87207 struct module_notes_attrs *notes_attrs;
87208- struct bin_attribute *nattr;
87209+ bin_attribute_no_const *nattr;
87210
87211 /* failed to create section attributes, so can't create notes */
87212 if (!mod->sect_attrs)
87213@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87214 static int module_add_modinfo_attrs(struct module *mod)
87215 {
87216 struct module_attribute *attr;
87217- struct module_attribute *temp_attr;
87218+ module_attribute_no_const *temp_attr;
87219 int error = 0;
87220 int i;
87221
87222@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87223
87224 static void unset_module_core_ro_nx(struct module *mod)
87225 {
87226- set_page_attributes(mod->module_core + mod->core_text_size,
87227- mod->module_core + mod->core_size,
87228+ set_page_attributes(mod->module_core_rw,
87229+ mod->module_core_rw + mod->core_size_rw,
87230 set_memory_x);
87231- set_page_attributes(mod->module_core,
87232- mod->module_core + mod->core_ro_size,
87233+ set_page_attributes(mod->module_core_rx,
87234+ mod->module_core_rx + mod->core_size_rx,
87235 set_memory_rw);
87236 }
87237
87238 static void unset_module_init_ro_nx(struct module *mod)
87239 {
87240- set_page_attributes(mod->module_init + mod->init_text_size,
87241- mod->module_init + mod->init_size,
87242+ set_page_attributes(mod->module_init_rw,
87243+ mod->module_init_rw + mod->init_size_rw,
87244 set_memory_x);
87245- set_page_attributes(mod->module_init,
87246- mod->module_init + mod->init_ro_size,
87247+ set_page_attributes(mod->module_init_rx,
87248+ mod->module_init_rx + mod->init_size_rx,
87249 set_memory_rw);
87250 }
87251
87252@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87253 list_for_each_entry_rcu(mod, &modules, list) {
87254 if (mod->state == MODULE_STATE_UNFORMED)
87255 continue;
87256- if ((mod->module_core) && (mod->core_text_size)) {
87257- set_page_attributes(mod->module_core,
87258- mod->module_core + mod->core_text_size,
87259+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87260+ set_page_attributes(mod->module_core_rx,
87261+ mod->module_core_rx + mod->core_size_rx,
87262 set_memory_rw);
87263 }
87264- if ((mod->module_init) && (mod->init_text_size)) {
87265- set_page_attributes(mod->module_init,
87266- mod->module_init + mod->init_text_size,
87267+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87268+ set_page_attributes(mod->module_init_rx,
87269+ mod->module_init_rx + mod->init_size_rx,
87270 set_memory_rw);
87271 }
87272 }
87273@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87274 list_for_each_entry_rcu(mod, &modules, list) {
87275 if (mod->state == MODULE_STATE_UNFORMED)
87276 continue;
87277- if ((mod->module_core) && (mod->core_text_size)) {
87278- set_page_attributes(mod->module_core,
87279- mod->module_core + mod->core_text_size,
87280+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87281+ set_page_attributes(mod->module_core_rx,
87282+ mod->module_core_rx + mod->core_size_rx,
87283 set_memory_ro);
87284 }
87285- if ((mod->module_init) && (mod->init_text_size)) {
87286- set_page_attributes(mod->module_init,
87287- mod->module_init + mod->init_text_size,
87288+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87289+ set_page_attributes(mod->module_init_rx,
87290+ mod->module_init_rx + mod->init_size_rx,
87291 set_memory_ro);
87292 }
87293 }
87294@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87295
87296 /* This may be NULL, but that's OK */
87297 unset_module_init_ro_nx(mod);
87298- module_free(mod, mod->module_init);
87299+ module_free(mod, mod->module_init_rw);
87300+ module_free_exec(mod, mod->module_init_rx);
87301 kfree(mod->args);
87302 percpu_modfree(mod);
87303
87304 /* Free lock-classes: */
87305- lockdep_free_key_range(mod->module_core, mod->core_size);
87306+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87307+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87308
87309 /* Finally, free the core (containing the module structure) */
87310 unset_module_core_ro_nx(mod);
87311- module_free(mod, mod->module_core);
87312+ module_free_exec(mod, mod->module_core_rx);
87313+ module_free(mod, mod->module_core_rw);
87314
87315 #ifdef CONFIG_MPU
87316 update_protections(current->mm);
87317@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87318 int ret = 0;
87319 const struct kernel_symbol *ksym;
87320
87321+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87322+ int is_fs_load = 0;
87323+ int register_filesystem_found = 0;
87324+ char *p;
87325+
87326+ p = strstr(mod->args, "grsec_modharden_fs");
87327+ if (p) {
87328+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87329+ /* copy \0 as well */
87330+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87331+ is_fs_load = 1;
87332+ }
87333+#endif
87334+
87335 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87336 const char *name = info->strtab + sym[i].st_name;
87337
87338+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87339+ /* it's a real shame this will never get ripped and copied
87340+ upstream! ;(
87341+ */
87342+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87343+ register_filesystem_found = 1;
87344+#endif
87345+
87346 switch (sym[i].st_shndx) {
87347 case SHN_COMMON:
87348 /* We compiled with -fno-common. These are not
87349@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87350 ksym = resolve_symbol_wait(mod, info, name);
87351 /* Ok if resolved. */
87352 if (ksym && !IS_ERR(ksym)) {
87353+ pax_open_kernel();
87354 sym[i].st_value = ksym->value;
87355+ pax_close_kernel();
87356 break;
87357 }
87358
87359@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87360 secbase = (unsigned long)mod_percpu(mod);
87361 else
87362 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87363+ pax_open_kernel();
87364 sym[i].st_value += secbase;
87365+ pax_close_kernel();
87366 break;
87367 }
87368 }
87369
87370+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87371+ if (is_fs_load && !register_filesystem_found) {
87372+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87373+ ret = -EPERM;
87374+ }
87375+#endif
87376+
87377 return ret;
87378 }
87379
87380@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87381 || s->sh_entsize != ~0UL
87382 || strstarts(sname, ".init"))
87383 continue;
87384- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87385+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87386+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87387+ else
87388+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87389 pr_debug("\t%s\n", sname);
87390 }
87391- switch (m) {
87392- case 0: /* executable */
87393- mod->core_size = debug_align(mod->core_size);
87394- mod->core_text_size = mod->core_size;
87395- break;
87396- case 1: /* RO: text and ro-data */
87397- mod->core_size = debug_align(mod->core_size);
87398- mod->core_ro_size = mod->core_size;
87399- break;
87400- case 3: /* whole core */
87401- mod->core_size = debug_align(mod->core_size);
87402- break;
87403- }
87404 }
87405
87406 pr_debug("Init section allocation order:\n");
87407@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87408 || s->sh_entsize != ~0UL
87409 || !strstarts(sname, ".init"))
87410 continue;
87411- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87412- | INIT_OFFSET_MASK);
87413+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87414+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87415+ else
87416+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87417+ s->sh_entsize |= INIT_OFFSET_MASK;
87418 pr_debug("\t%s\n", sname);
87419 }
87420- switch (m) {
87421- case 0: /* executable */
87422- mod->init_size = debug_align(mod->init_size);
87423- mod->init_text_size = mod->init_size;
87424- break;
87425- case 1: /* RO: text and ro-data */
87426- mod->init_size = debug_align(mod->init_size);
87427- mod->init_ro_size = mod->init_size;
87428- break;
87429- case 3: /* whole init */
87430- mod->init_size = debug_align(mod->init_size);
87431- break;
87432- }
87433 }
87434 }
87435
87436@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87437
87438 /* Put symbol section at end of init part of module. */
87439 symsect->sh_flags |= SHF_ALLOC;
87440- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87441+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87442 info->index.sym) | INIT_OFFSET_MASK;
87443 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87444
87445@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87446 }
87447
87448 /* Append room for core symbols at end of core part. */
87449- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87450- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87451- mod->core_size += strtab_size;
87452+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87453+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87454+ mod->core_size_rx += strtab_size;
87455
87456 /* Put string table section at end of init part of module. */
87457 strsect->sh_flags |= SHF_ALLOC;
87458- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87459+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87460 info->index.str) | INIT_OFFSET_MASK;
87461 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87462 }
87463@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87464 /* Make sure we get permanent strtab: don't use info->strtab. */
87465 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87466
87467+ pax_open_kernel();
87468+
87469 /* Set types up while we still have access to sections. */
87470 for (i = 0; i < mod->num_symtab; i++)
87471 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87472
87473- mod->core_symtab = dst = mod->module_core + info->symoffs;
87474- mod->core_strtab = s = mod->module_core + info->stroffs;
87475+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87476+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87477 src = mod->symtab;
87478 for (ndst = i = 0; i < mod->num_symtab; i++) {
87479 if (i == 0 ||
87480@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87481 }
87482 }
87483 mod->core_num_syms = ndst;
87484+
87485+ pax_close_kernel();
87486 }
87487 #else
87488 static inline void layout_symtab(struct module *mod, struct load_info *info)
87489@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87490 return vmalloc_exec(size);
87491 }
87492
87493-static void *module_alloc_update_bounds(unsigned long size)
87494+static void *module_alloc_update_bounds_rw(unsigned long size)
87495 {
87496 void *ret = module_alloc(size);
87497
87498 if (ret) {
87499 mutex_lock(&module_mutex);
87500 /* Update module bounds. */
87501- if ((unsigned long)ret < module_addr_min)
87502- module_addr_min = (unsigned long)ret;
87503- if ((unsigned long)ret + size > module_addr_max)
87504- module_addr_max = (unsigned long)ret + size;
87505+ if ((unsigned long)ret < module_addr_min_rw)
87506+ module_addr_min_rw = (unsigned long)ret;
87507+ if ((unsigned long)ret + size > module_addr_max_rw)
87508+ module_addr_max_rw = (unsigned long)ret + size;
87509+ mutex_unlock(&module_mutex);
87510+ }
87511+ return ret;
87512+}
87513+
87514+static void *module_alloc_update_bounds_rx(unsigned long size)
87515+{
87516+ void *ret = module_alloc_exec(size);
87517+
87518+ if (ret) {
87519+ mutex_lock(&module_mutex);
87520+ /* Update module bounds. */
87521+ if ((unsigned long)ret < module_addr_min_rx)
87522+ module_addr_min_rx = (unsigned long)ret;
87523+ if ((unsigned long)ret + size > module_addr_max_rx)
87524+ module_addr_max_rx = (unsigned long)ret + size;
87525 mutex_unlock(&module_mutex);
87526 }
87527 return ret;
87528@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87529 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87530
87531 if (info->index.sym == 0) {
87532+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87533+ /*
87534+ * avoid potentially printing jibberish on attempted load
87535+ * of a module randomized with a different seed
87536+ */
87537+ pr_warn("module has no symbols (stripped?)\n");
87538+#else
87539 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87540+#endif
87541 return ERR_PTR(-ENOEXEC);
87542 }
87543
87544@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87545 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87546 {
87547 const char *modmagic = get_modinfo(info, "vermagic");
87548+ const char *license = get_modinfo(info, "license");
87549 int err;
87550
87551+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87552+ if (!license || !license_is_gpl_compatible(license))
87553+ return -ENOEXEC;
87554+#endif
87555+
87556 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87557 modmagic = NULL;
87558
87559@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87560 }
87561
87562 /* Set up license info based on the info section */
87563- set_license(mod, get_modinfo(info, "license"));
87564+ set_license(mod, license);
87565
87566 return 0;
87567 }
87568@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87569 void *ptr;
87570
87571 /* Do the allocs. */
87572- ptr = module_alloc_update_bounds(mod->core_size);
87573+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87574 /*
87575 * The pointer to this block is stored in the module structure
87576 * which is inside the block. Just mark it as not being a
87577@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87578 if (!ptr)
87579 return -ENOMEM;
87580
87581- memset(ptr, 0, mod->core_size);
87582- mod->module_core = ptr;
87583+ memset(ptr, 0, mod->core_size_rw);
87584+ mod->module_core_rw = ptr;
87585
87586- if (mod->init_size) {
87587- ptr = module_alloc_update_bounds(mod->init_size);
87588+ if (mod->init_size_rw) {
87589+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87590 /*
87591 * The pointer to this block is stored in the module structure
87592 * which is inside the block. This block doesn't need to be
87593@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87594 */
87595 kmemleak_ignore(ptr);
87596 if (!ptr) {
87597- module_free(mod, mod->module_core);
87598+ module_free(mod, mod->module_core_rw);
87599 return -ENOMEM;
87600 }
87601- memset(ptr, 0, mod->init_size);
87602- mod->module_init = ptr;
87603+ memset(ptr, 0, mod->init_size_rw);
87604+ mod->module_init_rw = ptr;
87605 } else
87606- mod->module_init = NULL;
87607+ mod->module_init_rw = NULL;
87608+
87609+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87610+ kmemleak_not_leak(ptr);
87611+ if (!ptr) {
87612+ if (mod->module_init_rw)
87613+ module_free(mod, mod->module_init_rw);
87614+ module_free(mod, mod->module_core_rw);
87615+ return -ENOMEM;
87616+ }
87617+
87618+ pax_open_kernel();
87619+ memset(ptr, 0, mod->core_size_rx);
87620+ pax_close_kernel();
87621+ mod->module_core_rx = ptr;
87622+
87623+ if (mod->init_size_rx) {
87624+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87625+ kmemleak_ignore(ptr);
87626+ if (!ptr && mod->init_size_rx) {
87627+ module_free_exec(mod, mod->module_core_rx);
87628+ if (mod->module_init_rw)
87629+ module_free(mod, mod->module_init_rw);
87630+ module_free(mod, mod->module_core_rw);
87631+ return -ENOMEM;
87632+ }
87633+
87634+ pax_open_kernel();
87635+ memset(ptr, 0, mod->init_size_rx);
87636+ pax_close_kernel();
87637+ mod->module_init_rx = ptr;
87638+ } else
87639+ mod->module_init_rx = NULL;
87640
87641 /* Transfer each section which specifies SHF_ALLOC */
87642 pr_debug("final section addresses:\n");
87643@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87644 if (!(shdr->sh_flags & SHF_ALLOC))
87645 continue;
87646
87647- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87648- dest = mod->module_init
87649- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87650- else
87651- dest = mod->module_core + shdr->sh_entsize;
87652+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87653+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87654+ dest = mod->module_init_rw
87655+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87656+ else
87657+ dest = mod->module_init_rx
87658+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87659+ } else {
87660+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87661+ dest = mod->module_core_rw + shdr->sh_entsize;
87662+ else
87663+ dest = mod->module_core_rx + shdr->sh_entsize;
87664+ }
87665+
87666+ if (shdr->sh_type != SHT_NOBITS) {
87667+
87668+#ifdef CONFIG_PAX_KERNEXEC
87669+#ifdef CONFIG_X86_64
87670+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87671+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87672+#endif
87673+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87674+ pax_open_kernel();
87675+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87676+ pax_close_kernel();
87677+ } else
87678+#endif
87679
87680- if (shdr->sh_type != SHT_NOBITS)
87681 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87682+ }
87683 /* Update sh_addr to point to copy in image. */
87684- shdr->sh_addr = (unsigned long)dest;
87685+
87686+#ifdef CONFIG_PAX_KERNEXEC
87687+ if (shdr->sh_flags & SHF_EXECINSTR)
87688+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87689+ else
87690+#endif
87691+
87692+ shdr->sh_addr = (unsigned long)dest;
87693 pr_debug("\t0x%lx %s\n",
87694 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87695 }
87696@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87697 * Do it before processing of module parameters, so the module
87698 * can provide parameter accessor functions of its own.
87699 */
87700- if (mod->module_init)
87701- flush_icache_range((unsigned long)mod->module_init,
87702- (unsigned long)mod->module_init
87703- + mod->init_size);
87704- flush_icache_range((unsigned long)mod->module_core,
87705- (unsigned long)mod->module_core + mod->core_size);
87706+ if (mod->module_init_rx)
87707+ flush_icache_range((unsigned long)mod->module_init_rx,
87708+ (unsigned long)mod->module_init_rx
87709+ + mod->init_size_rx);
87710+ flush_icache_range((unsigned long)mod->module_core_rx,
87711+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87712
87713 set_fs(old_fs);
87714 }
87715@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87716 static void module_deallocate(struct module *mod, struct load_info *info)
87717 {
87718 percpu_modfree(mod);
87719- module_free(mod, mod->module_init);
87720- module_free(mod, mod->module_core);
87721+ module_free_exec(mod, mod->module_init_rx);
87722+ module_free_exec(mod, mod->module_core_rx);
87723+ module_free(mod, mod->module_init_rw);
87724+ module_free(mod, mod->module_core_rw);
87725 }
87726
87727 int __weak module_finalize(const Elf_Ehdr *hdr,
87728@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87729 static int post_relocation(struct module *mod, const struct load_info *info)
87730 {
87731 /* Sort exception table now relocations are done. */
87732+ pax_open_kernel();
87733 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87734+ pax_close_kernel();
87735
87736 /* Copy relocated percpu area over. */
87737 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87738@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87739 MODULE_STATE_COMING, mod);
87740
87741 /* Set RO and NX regions for core */
87742- set_section_ro_nx(mod->module_core,
87743- mod->core_text_size,
87744- mod->core_ro_size,
87745- mod->core_size);
87746+ set_section_ro_nx(mod->module_core_rx,
87747+ mod->core_size_rx,
87748+ mod->core_size_rx,
87749+ mod->core_size_rx);
87750
87751 /* Set RO and NX regions for init */
87752- set_section_ro_nx(mod->module_init,
87753- mod->init_text_size,
87754- mod->init_ro_size,
87755- mod->init_size);
87756+ set_section_ro_nx(mod->module_init_rx,
87757+ mod->init_size_rx,
87758+ mod->init_size_rx,
87759+ mod->init_size_rx);
87760
87761 do_mod_ctors(mod);
87762 /* Start the module */
87763@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87764 mod->strtab = mod->core_strtab;
87765 #endif
87766 unset_module_init_ro_nx(mod);
87767- module_free(mod, mod->module_init);
87768- mod->module_init = NULL;
87769- mod->init_size = 0;
87770- mod->init_ro_size = 0;
87771- mod->init_text_size = 0;
87772+ module_free(mod, mod->module_init_rw);
87773+ module_free_exec(mod, mod->module_init_rx);
87774+ mod->module_init_rw = NULL;
87775+ mod->module_init_rx = NULL;
87776+ mod->init_size_rw = 0;
87777+ mod->init_size_rx = 0;
87778 mutex_unlock(&module_mutex);
87779 wake_up_all(&module_wq);
87780
87781@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87782 if (err)
87783 goto free_unload;
87784
87785+ /* Now copy in args */
87786+ mod->args = strndup_user(uargs, ~0UL >> 1);
87787+ if (IS_ERR(mod->args)) {
87788+ err = PTR_ERR(mod->args);
87789+ goto free_unload;
87790+ }
87791+
87792 /* Set up MODINFO_ATTR fields */
87793 setup_modinfo(mod, info);
87794
87795+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87796+ {
87797+ char *p, *p2;
87798+
87799+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87800+ 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);
87801+ err = -EPERM;
87802+ goto free_modinfo;
87803+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87804+ p += sizeof("grsec_modharden_normal") - 1;
87805+ p2 = strstr(p, "_");
87806+ if (p2) {
87807+ *p2 = '\0';
87808+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87809+ *p2 = '_';
87810+ }
87811+ err = -EPERM;
87812+ goto free_modinfo;
87813+ }
87814+ }
87815+#endif
87816+
87817 /* Fix up syms, so that st_value is a pointer to location. */
87818 err = simplify_symbols(mod, info);
87819 if (err < 0)
87820@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87821
87822 flush_module_icache(mod);
87823
87824- /* Now copy in args */
87825- mod->args = strndup_user(uargs, ~0UL >> 1);
87826- if (IS_ERR(mod->args)) {
87827- err = PTR_ERR(mod->args);
87828- goto free_arch_cleanup;
87829- }
87830-
87831 dynamic_debug_setup(info->debug, info->num_debug);
87832
87833 /* Finally it's fully formed, ready to start executing. */
87834@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87835 ddebug_cleanup:
87836 dynamic_debug_remove(info->debug);
87837 synchronize_sched();
87838- kfree(mod->args);
87839- free_arch_cleanup:
87840 module_arch_cleanup(mod);
87841 free_modinfo:
87842 free_modinfo(mod);
87843+ kfree(mod->args);
87844 free_unload:
87845 module_unload_free(mod);
87846 unlink_mod:
87847@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87848 unsigned long nextval;
87849
87850 /* At worse, next value is at end of module */
87851- if (within_module_init(addr, mod))
87852- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87853+ if (within_module_init_rx(addr, mod))
87854+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87855+ else if (within_module_init_rw(addr, mod))
87856+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87857+ else if (within_module_core_rx(addr, mod))
87858+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87859+ else if (within_module_core_rw(addr, mod))
87860+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87861 else
87862- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87863+ return NULL;
87864
87865 /* Scan for closest preceding symbol, and next symbol. (ELF
87866 starts real symbols at 1). */
87867@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87868 return 0;
87869
87870 seq_printf(m, "%s %u",
87871- mod->name, mod->init_size + mod->core_size);
87872+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87873 print_unload_info(m, mod);
87874
87875 /* Informative for users. */
87876@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87877 mod->state == MODULE_STATE_COMING ? "Loading":
87878 "Live");
87879 /* Used by oprofile and other similar tools. */
87880- seq_printf(m, " 0x%pK", mod->module_core);
87881+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87882
87883 /* Taints info */
87884 if (mod->taints)
87885@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
87886
87887 static int __init proc_modules_init(void)
87888 {
87889+#ifndef CONFIG_GRKERNSEC_HIDESYM
87890+#ifdef CONFIG_GRKERNSEC_PROC_USER
87891+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87892+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87893+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87894+#else
87895 proc_create("modules", 0, NULL, &proc_modules_operations);
87896+#endif
87897+#else
87898+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87899+#endif
87900 return 0;
87901 }
87902 module_init(proc_modules_init);
87903@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
87904 {
87905 struct module *mod;
87906
87907- if (addr < module_addr_min || addr > module_addr_max)
87908+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87909+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
87910 return NULL;
87911
87912 list_for_each_entry_rcu(mod, &modules, list) {
87913 if (mod->state == MODULE_STATE_UNFORMED)
87914 continue;
87915- if (within_module_core(addr, mod)
87916- || within_module_init(addr, mod))
87917+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
87918 return mod;
87919 }
87920 return NULL;
87921@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
87922 */
87923 struct module *__module_text_address(unsigned long addr)
87924 {
87925- struct module *mod = __module_address(addr);
87926+ struct module *mod;
87927+
87928+#ifdef CONFIG_X86_32
87929+ addr = ktla_ktva(addr);
87930+#endif
87931+
87932+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87933+ return NULL;
87934+
87935+ mod = __module_address(addr);
87936+
87937 if (mod) {
87938 /* Make sure it's within the text section. */
87939- if (!within(addr, mod->module_init, mod->init_text_size)
87940- && !within(addr, mod->module_core, mod->core_text_size))
87941+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87942 mod = NULL;
87943 }
87944 return mod;
87945diff --git a/kernel/notifier.c b/kernel/notifier.c
87946index 2d5cc4c..d9ea600 100644
87947--- a/kernel/notifier.c
87948+++ b/kernel/notifier.c
87949@@ -5,6 +5,7 @@
87950 #include <linux/rcupdate.h>
87951 #include <linux/vmalloc.h>
87952 #include <linux/reboot.h>
87953+#include <linux/mm.h>
87954
87955 /*
87956 * Notifier list for kernel code which wants to be called
87957@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87958 while ((*nl) != NULL) {
87959 if (n->priority > (*nl)->priority)
87960 break;
87961- nl = &((*nl)->next);
87962+ nl = (struct notifier_block **)&((*nl)->next);
87963 }
87964- n->next = *nl;
87965+ pax_open_kernel();
87966+ *(const void **)&n->next = *nl;
87967 rcu_assign_pointer(*nl, n);
87968+ pax_close_kernel();
87969 return 0;
87970 }
87971
87972@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87973 return 0;
87974 if (n->priority > (*nl)->priority)
87975 break;
87976- nl = &((*nl)->next);
87977+ nl = (struct notifier_block **)&((*nl)->next);
87978 }
87979- n->next = *nl;
87980+ pax_open_kernel();
87981+ *(const void **)&n->next = *nl;
87982 rcu_assign_pointer(*nl, n);
87983+ pax_close_kernel();
87984 return 0;
87985 }
87986
87987@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87988 {
87989 while ((*nl) != NULL) {
87990 if ((*nl) == n) {
87991+ pax_open_kernel();
87992 rcu_assign_pointer(*nl, n->next);
87993+ pax_close_kernel();
87994 return 0;
87995 }
87996- nl = &((*nl)->next);
87997+ nl = (struct notifier_block **)&((*nl)->next);
87998 }
87999 return -ENOENT;
88000 }
88001diff --git a/kernel/padata.c b/kernel/padata.c
88002index 161402f..598814c 100644
88003--- a/kernel/padata.c
88004+++ b/kernel/padata.c
88005@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88006 * seq_nr mod. number of cpus in use.
88007 */
88008
88009- seq_nr = atomic_inc_return(&pd->seq_nr);
88010+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88011 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88012
88013 return padata_index_to_cpu(pd, cpu_index);
88014@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88015 padata_init_pqueues(pd);
88016 padata_init_squeues(pd);
88017 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88018- atomic_set(&pd->seq_nr, -1);
88019+ atomic_set_unchecked(&pd->seq_nr, -1);
88020 atomic_set(&pd->reorder_objects, 0);
88021 atomic_set(&pd->refcnt, 0);
88022 pd->pinst = pinst;
88023diff --git a/kernel/panic.c b/kernel/panic.c
88024index 6d63003..486a109 100644
88025--- a/kernel/panic.c
88026+++ b/kernel/panic.c
88027@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88028 /*
88029 * Stop ourself in panic -- architecture code may override this
88030 */
88031-void __weak panic_smp_self_stop(void)
88032+void __weak __noreturn panic_smp_self_stop(void)
88033 {
88034 while (1)
88035 cpu_relax();
88036@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88037 disable_trace_on_warning();
88038
88039 pr_warn("------------[ cut here ]------------\n");
88040- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88041+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88042 raw_smp_processor_id(), current->pid, file, line, caller);
88043
88044 if (args)
88045@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88046 */
88047 void __stack_chk_fail(void)
88048 {
88049- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88050+ dump_stack();
88051+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88052 __builtin_return_address(0));
88053 }
88054 EXPORT_SYMBOL(__stack_chk_fail);
88055diff --git a/kernel/pid.c b/kernel/pid.c
88056index 9b9a266..c20ef80 100644
88057--- a/kernel/pid.c
88058+++ b/kernel/pid.c
88059@@ -33,6 +33,7 @@
88060 #include <linux/rculist.h>
88061 #include <linux/bootmem.h>
88062 #include <linux/hash.h>
88063+#include <linux/security.h>
88064 #include <linux/pid_namespace.h>
88065 #include <linux/init_task.h>
88066 #include <linux/syscalls.h>
88067@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88068
88069 int pid_max = PID_MAX_DEFAULT;
88070
88071-#define RESERVED_PIDS 300
88072+#define RESERVED_PIDS 500
88073
88074 int pid_max_min = RESERVED_PIDS + 1;
88075 int pid_max_max = PID_MAX_LIMIT;
88076@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88077 */
88078 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88079 {
88080+ struct task_struct *task;
88081+
88082 rcu_lockdep_assert(rcu_read_lock_held(),
88083 "find_task_by_pid_ns() needs rcu_read_lock()"
88084 " protection");
88085- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88086+
88087+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88088+
88089+ if (gr_pid_is_chrooted(task))
88090+ return NULL;
88091+
88092+ return task;
88093 }
88094
88095 struct task_struct *find_task_by_vpid(pid_t vnr)
88096@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88097 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88098 }
88099
88100+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88101+{
88102+ rcu_lockdep_assert(rcu_read_lock_held(),
88103+ "find_task_by_pid_ns() needs rcu_read_lock()"
88104+ " protection");
88105+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88106+}
88107+
88108 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88109 {
88110 struct pid *pid;
88111diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88112index db95d8e..a0ca23f 100644
88113--- a/kernel/pid_namespace.c
88114+++ b/kernel/pid_namespace.c
88115@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88116 void __user *buffer, size_t *lenp, loff_t *ppos)
88117 {
88118 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88119- struct ctl_table tmp = *table;
88120+ ctl_table_no_const tmp = *table;
88121
88122 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88123 return -EPERM;
88124diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88125index 3b89464..5e38379 100644
88126--- a/kernel/posix-cpu-timers.c
88127+++ b/kernel/posix-cpu-timers.c
88128@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88129
88130 static __init int init_posix_cpu_timers(void)
88131 {
88132- struct k_clock process = {
88133+ static struct k_clock process = {
88134 .clock_getres = process_cpu_clock_getres,
88135 .clock_get = process_cpu_clock_get,
88136 .timer_create = process_cpu_timer_create,
88137 .nsleep = process_cpu_nsleep,
88138 .nsleep_restart = process_cpu_nsleep_restart,
88139 };
88140- struct k_clock thread = {
88141+ static struct k_clock thread = {
88142 .clock_getres = thread_cpu_clock_getres,
88143 .clock_get = thread_cpu_clock_get,
88144 .timer_create = thread_cpu_timer_create,
88145diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88146index 424c2d4..679242f 100644
88147--- a/kernel/posix-timers.c
88148+++ b/kernel/posix-timers.c
88149@@ -43,6 +43,7 @@
88150 #include <linux/hash.h>
88151 #include <linux/posix-clock.h>
88152 #include <linux/posix-timers.h>
88153+#include <linux/grsecurity.h>
88154 #include <linux/syscalls.h>
88155 #include <linux/wait.h>
88156 #include <linux/workqueue.h>
88157@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88158 * which we beg off on and pass to do_sys_settimeofday().
88159 */
88160
88161-static struct k_clock posix_clocks[MAX_CLOCKS];
88162+static struct k_clock *posix_clocks[MAX_CLOCKS];
88163
88164 /*
88165 * These ones are defined below.
88166@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88167 */
88168 static __init int init_posix_timers(void)
88169 {
88170- struct k_clock clock_realtime = {
88171+ static struct k_clock clock_realtime = {
88172 .clock_getres = hrtimer_get_res,
88173 .clock_get = posix_clock_realtime_get,
88174 .clock_set = posix_clock_realtime_set,
88175@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88176 .timer_get = common_timer_get,
88177 .timer_del = common_timer_del,
88178 };
88179- struct k_clock clock_monotonic = {
88180+ static struct k_clock clock_monotonic = {
88181 .clock_getres = hrtimer_get_res,
88182 .clock_get = posix_ktime_get_ts,
88183 .nsleep = common_nsleep,
88184@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88185 .timer_get = common_timer_get,
88186 .timer_del = common_timer_del,
88187 };
88188- struct k_clock clock_monotonic_raw = {
88189+ static struct k_clock clock_monotonic_raw = {
88190 .clock_getres = hrtimer_get_res,
88191 .clock_get = posix_get_monotonic_raw,
88192 };
88193- struct k_clock clock_realtime_coarse = {
88194+ static struct k_clock clock_realtime_coarse = {
88195 .clock_getres = posix_get_coarse_res,
88196 .clock_get = posix_get_realtime_coarse,
88197 };
88198- struct k_clock clock_monotonic_coarse = {
88199+ static struct k_clock clock_monotonic_coarse = {
88200 .clock_getres = posix_get_coarse_res,
88201 .clock_get = posix_get_monotonic_coarse,
88202 };
88203- struct k_clock clock_tai = {
88204+ static struct k_clock clock_tai = {
88205 .clock_getres = hrtimer_get_res,
88206 .clock_get = posix_get_tai,
88207 .nsleep = common_nsleep,
88208@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88209 .timer_get = common_timer_get,
88210 .timer_del = common_timer_del,
88211 };
88212- struct k_clock clock_boottime = {
88213+ static struct k_clock clock_boottime = {
88214 .clock_getres = hrtimer_get_res,
88215 .clock_get = posix_get_boottime,
88216 .nsleep = common_nsleep,
88217@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88218 return;
88219 }
88220
88221- posix_clocks[clock_id] = *new_clock;
88222+ posix_clocks[clock_id] = new_clock;
88223 }
88224 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88225
88226@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88227 return (id & CLOCKFD_MASK) == CLOCKFD ?
88228 &clock_posix_dynamic : &clock_posix_cpu;
88229
88230- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88231+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88232 return NULL;
88233- return &posix_clocks[id];
88234+ return posix_clocks[id];
88235 }
88236
88237 static int common_timer_create(struct k_itimer *new_timer)
88238@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88239 struct k_clock *kc = clockid_to_kclock(which_clock);
88240 struct k_itimer *new_timer;
88241 int error, new_timer_id;
88242- sigevent_t event;
88243+ sigevent_t event = { };
88244 int it_id_set = IT_ID_NOT_SET;
88245
88246 if (!kc)
88247@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88248 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88249 return -EFAULT;
88250
88251+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88252+ have their clock_set fptr set to a nosettime dummy function
88253+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88254+ call common_clock_set, which calls do_sys_settimeofday, which
88255+ we hook
88256+ */
88257+
88258 return kc->clock_set(which_clock, &new_tp);
88259 }
88260
88261diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88262index 2fac9cc..56fef29 100644
88263--- a/kernel/power/Kconfig
88264+++ b/kernel/power/Kconfig
88265@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88266 config HIBERNATION
88267 bool "Hibernation (aka 'suspend to disk')"
88268 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88269+ depends on !GRKERNSEC_KMEM
88270+ depends on !PAX_MEMORY_SANITIZE
88271 select HIBERNATE_CALLBACKS
88272 select LZO_COMPRESS
88273 select LZO_DECOMPRESS
88274diff --git a/kernel/power/process.c b/kernel/power/process.c
88275index 06ec886..9dba35e 100644
88276--- a/kernel/power/process.c
88277+++ b/kernel/power/process.c
88278@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88279 unsigned int elapsed_msecs;
88280 bool wakeup = false;
88281 int sleep_usecs = USEC_PER_MSEC;
88282+ bool timedout = false;
88283
88284 do_gettimeofday(&start);
88285
88286@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88287
88288 while (true) {
88289 todo = 0;
88290+ if (time_after(jiffies, end_time))
88291+ timedout = true;
88292 read_lock(&tasklist_lock);
88293 do_each_thread(g, p) {
88294 if (p == current || !freeze_task(p))
88295 continue;
88296
88297- if (!freezer_should_skip(p))
88298+ if (!freezer_should_skip(p)) {
88299 todo++;
88300+ if (timedout) {
88301+ printk(KERN_ERR "Task refusing to freeze:\n");
88302+ sched_show_task(p);
88303+ }
88304+ }
88305 } while_each_thread(g, p);
88306 read_unlock(&tasklist_lock);
88307
88308@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88309 todo += wq_busy;
88310 }
88311
88312- if (!todo || time_after(jiffies, end_time))
88313+ if (!todo || timedout)
88314 break;
88315
88316 if (pm_wakeup_pending()) {
88317diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88318index 4dae9cb..039ffbb 100644
88319--- a/kernel/printk/printk.c
88320+++ b/kernel/printk/printk.c
88321@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88322 if (from_file && type != SYSLOG_ACTION_OPEN)
88323 return 0;
88324
88325+#ifdef CONFIG_GRKERNSEC_DMESG
88326+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88327+ return -EPERM;
88328+#endif
88329+
88330 if (syslog_action_restricted(type)) {
88331 if (capable(CAP_SYSLOG))
88332 return 0;
88333diff --git a/kernel/profile.c b/kernel/profile.c
88334index ebdd9c1..612ee05 100644
88335--- a/kernel/profile.c
88336+++ b/kernel/profile.c
88337@@ -37,7 +37,7 @@ struct profile_hit {
88338 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88339 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88340
88341-static atomic_t *prof_buffer;
88342+static atomic_unchecked_t *prof_buffer;
88343 static unsigned long prof_len, prof_shift;
88344
88345 int prof_on __read_mostly;
88346@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88347 hits[i].pc = 0;
88348 continue;
88349 }
88350- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88351+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88352 hits[i].hits = hits[i].pc = 0;
88353 }
88354 }
88355@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88356 * Add the current hit(s) and flush the write-queue out
88357 * to the global buffer:
88358 */
88359- atomic_add(nr_hits, &prof_buffer[pc]);
88360+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88361 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88362- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88363+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88364 hits[i].pc = hits[i].hits = 0;
88365 }
88366 out:
88367@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88368 {
88369 unsigned long pc;
88370 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88371- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88372+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88373 }
88374 #endif /* !CONFIG_SMP */
88375
88376@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88377 return -EFAULT;
88378 buf++; p++; count--; read++;
88379 }
88380- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88381+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88382 if (copy_to_user(buf, (void *)pnt, count))
88383 return -EFAULT;
88384 read += count;
88385@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88386 }
88387 #endif
88388 profile_discard_flip_buffers();
88389- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88390+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88391 return count;
88392 }
88393
88394diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88395index 1f4bcb3..99cf7ab 100644
88396--- a/kernel/ptrace.c
88397+++ b/kernel/ptrace.c
88398@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88399 if (seize)
88400 flags |= PT_SEIZED;
88401 rcu_read_lock();
88402- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88403+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88404 flags |= PT_PTRACE_CAP;
88405 rcu_read_unlock();
88406 task->ptrace = flags;
88407@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88408 break;
88409 return -EIO;
88410 }
88411- if (copy_to_user(dst, buf, retval))
88412+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88413 return -EFAULT;
88414 copied += retval;
88415 src += retval;
88416@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88417 bool seized = child->ptrace & PT_SEIZED;
88418 int ret = -EIO;
88419 siginfo_t siginfo, *si;
88420- void __user *datavp = (void __user *) data;
88421+ void __user *datavp = (__force void __user *) data;
88422 unsigned long __user *datalp = datavp;
88423 unsigned long flags;
88424
88425@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88426 goto out;
88427 }
88428
88429+ if (gr_handle_ptrace(child, request)) {
88430+ ret = -EPERM;
88431+ goto out_put_task_struct;
88432+ }
88433+
88434 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88435 ret = ptrace_attach(child, request, addr, data);
88436 /*
88437 * Some architectures need to do book-keeping after
88438 * a ptrace attach.
88439 */
88440- if (!ret)
88441+ if (!ret) {
88442 arch_ptrace_attach(child);
88443+ gr_audit_ptrace(child);
88444+ }
88445 goto out_put_task_struct;
88446 }
88447
88448@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88449 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88450 if (copied != sizeof(tmp))
88451 return -EIO;
88452- return put_user(tmp, (unsigned long __user *)data);
88453+ return put_user(tmp, (__force unsigned long __user *)data);
88454 }
88455
88456 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88457@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88458 }
88459
88460 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88461- compat_long_t addr, compat_long_t data)
88462+ compat_ulong_t addr, compat_ulong_t data)
88463 {
88464 struct task_struct *child;
88465 long ret;
88466@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88467 goto out;
88468 }
88469
88470+ if (gr_handle_ptrace(child, request)) {
88471+ ret = -EPERM;
88472+ goto out_put_task_struct;
88473+ }
88474+
88475 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88476 ret = ptrace_attach(child, request, addr, data);
88477 /*
88478 * Some architectures need to do book-keeping after
88479 * a ptrace attach.
88480 */
88481- if (!ret)
88482+ if (!ret) {
88483 arch_ptrace_attach(child);
88484+ gr_audit_ptrace(child);
88485+ }
88486 goto out_put_task_struct;
88487 }
88488
88489diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88490index 3318d82..1a5b2d1 100644
88491--- a/kernel/rcu/srcu.c
88492+++ b/kernel/rcu/srcu.c
88493@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88494
88495 idx = ACCESS_ONCE(sp->completed) & 0x1;
88496 preempt_disable();
88497- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88498+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88499 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88500- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88501+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88502 preempt_enable();
88503 return idx;
88504 }
88505diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88506index 1254f31..16258dc 100644
88507--- a/kernel/rcu/tiny.c
88508+++ b/kernel/rcu/tiny.c
88509@@ -46,7 +46,7 @@
88510 /* Forward declarations for tiny_plugin.h. */
88511 struct rcu_ctrlblk;
88512 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88513-static void rcu_process_callbacks(struct softirq_action *unused);
88514+static void rcu_process_callbacks(void);
88515 static void __call_rcu(struct rcu_head *head,
88516 void (*func)(struct rcu_head *rcu),
88517 struct rcu_ctrlblk *rcp);
88518@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88519 false));
88520 }
88521
88522-static void rcu_process_callbacks(struct softirq_action *unused)
88523+static __latent_entropy void rcu_process_callbacks(void)
88524 {
88525 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88526 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88527diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88528index 732f8ae..42c1919 100644
88529--- a/kernel/rcu/torture.c
88530+++ b/kernel/rcu/torture.c
88531@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88532 { 0 };
88533 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88534 { 0 };
88535-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88536-static atomic_t n_rcu_torture_alloc;
88537-static atomic_t n_rcu_torture_alloc_fail;
88538-static atomic_t n_rcu_torture_free;
88539-static atomic_t n_rcu_torture_mberror;
88540-static atomic_t n_rcu_torture_error;
88541+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88542+static atomic_unchecked_t n_rcu_torture_alloc;
88543+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88544+static atomic_unchecked_t n_rcu_torture_free;
88545+static atomic_unchecked_t n_rcu_torture_mberror;
88546+static atomic_unchecked_t n_rcu_torture_error;
88547 static long n_rcu_torture_barrier_error;
88548 static long n_rcu_torture_boost_ktrerror;
88549 static long n_rcu_torture_boost_rterror;
88550@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88551
88552 spin_lock_bh(&rcu_torture_lock);
88553 if (list_empty(&rcu_torture_freelist)) {
88554- atomic_inc(&n_rcu_torture_alloc_fail);
88555+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88556 spin_unlock_bh(&rcu_torture_lock);
88557 return NULL;
88558 }
88559- atomic_inc(&n_rcu_torture_alloc);
88560+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88561 p = rcu_torture_freelist.next;
88562 list_del_init(p);
88563 spin_unlock_bh(&rcu_torture_lock);
88564@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88565 static void
88566 rcu_torture_free(struct rcu_torture *p)
88567 {
88568- atomic_inc(&n_rcu_torture_free);
88569+ atomic_inc_unchecked(&n_rcu_torture_free);
88570 spin_lock_bh(&rcu_torture_lock);
88571 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88572 spin_unlock_bh(&rcu_torture_lock);
88573@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88574 i = rp->rtort_pipe_count;
88575 if (i > RCU_TORTURE_PIPE_LEN)
88576 i = RCU_TORTURE_PIPE_LEN;
88577- atomic_inc(&rcu_torture_wcount[i]);
88578+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88579 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88580 rp->rtort_mbtest = 0;
88581 rcu_torture_free(rp);
88582@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88583 i = old_rp->rtort_pipe_count;
88584 if (i > RCU_TORTURE_PIPE_LEN)
88585 i = RCU_TORTURE_PIPE_LEN;
88586- atomic_inc(&rcu_torture_wcount[i]);
88587+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88588 old_rp->rtort_pipe_count++;
88589 if (gp_normal == gp_exp)
88590 exp = !!(rcu_random(&rand) & 0x80);
88591@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88592 i = rp->rtort_pipe_count;
88593 if (i > RCU_TORTURE_PIPE_LEN)
88594 i = RCU_TORTURE_PIPE_LEN;
88595- atomic_inc(&rcu_torture_wcount[i]);
88596+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88597 if (++rp->rtort_pipe_count >=
88598 RCU_TORTURE_PIPE_LEN) {
88599 rp->rtort_mbtest = 0;
88600@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88601 return;
88602 }
88603 if (p->rtort_mbtest == 0)
88604- atomic_inc(&n_rcu_torture_mberror);
88605+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88606 spin_lock(&rand_lock);
88607 cur_ops->read_delay(&rand);
88608 n_rcu_torture_timers++;
88609@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88610 continue;
88611 }
88612 if (p->rtort_mbtest == 0)
88613- atomic_inc(&n_rcu_torture_mberror);
88614+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88615 cur_ops->read_delay(&rand);
88616 preempt_disable();
88617 pipe_count = p->rtort_pipe_count;
88618@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
88619 }
88620 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88621 page += sprintf(page,
88622- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88623+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88624 rcu_torture_current,
88625 rcu_torture_current_version,
88626 list_empty(&rcu_torture_freelist),
88627- atomic_read(&n_rcu_torture_alloc),
88628- atomic_read(&n_rcu_torture_alloc_fail),
88629- atomic_read(&n_rcu_torture_free));
88630+ atomic_read_unchecked(&n_rcu_torture_alloc),
88631+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88632+ atomic_read_unchecked(&n_rcu_torture_free));
88633 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88634- atomic_read(&n_rcu_torture_mberror),
88635+ atomic_read_unchecked(&n_rcu_torture_mberror),
88636 n_rcu_torture_boost_ktrerror,
88637 n_rcu_torture_boost_rterror);
88638 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88639@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88640 n_barrier_attempts,
88641 n_rcu_torture_barrier_error);
88642 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88643- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88644+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88645 n_rcu_torture_barrier_error != 0 ||
88646 n_rcu_torture_boost_ktrerror != 0 ||
88647 n_rcu_torture_boost_rterror != 0 ||
88648 n_rcu_torture_boost_failure != 0 ||
88649 i > 1) {
88650 page += sprintf(page, "!!! ");
88651- atomic_inc(&n_rcu_torture_error);
88652+ atomic_inc_unchecked(&n_rcu_torture_error);
88653 WARN_ON_ONCE(1);
88654 }
88655 page += sprintf(page, "Reader Pipe: ");
88656@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88657 page += sprintf(page, "Free-Block Circulation: ");
88658 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88659 page += sprintf(page, " %d",
88660- atomic_read(&rcu_torture_wcount[i]));
88661+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88662 }
88663 page += sprintf(page, "\n");
88664 if (cur_ops->stats)
88665@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88666
88667 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88668
88669- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88670+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88671 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88672 else if (n_online_successes != n_online_attempts ||
88673 n_offline_successes != n_offline_attempts)
88674@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88675
88676 rcu_torture_current = NULL;
88677 rcu_torture_current_version = 0;
88678- atomic_set(&n_rcu_torture_alloc, 0);
88679- atomic_set(&n_rcu_torture_alloc_fail, 0);
88680- atomic_set(&n_rcu_torture_free, 0);
88681- atomic_set(&n_rcu_torture_mberror, 0);
88682- atomic_set(&n_rcu_torture_error, 0);
88683+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88684+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88685+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88686+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88687+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88688 n_rcu_torture_barrier_error = 0;
88689 n_rcu_torture_boost_ktrerror = 0;
88690 n_rcu_torture_boost_rterror = 0;
88691 n_rcu_torture_boost_failure = 0;
88692 n_rcu_torture_boosts = 0;
88693 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88694- atomic_set(&rcu_torture_wcount[i], 0);
88695+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88696 for_each_possible_cpu(cpu) {
88697 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88698 per_cpu(rcu_torture_count, cpu)[i] = 0;
88699diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88700index b3d116c..ebf6598 100644
88701--- a/kernel/rcu/tree.c
88702+++ b/kernel/rcu/tree.c
88703@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88704 rcu_prepare_for_idle(smp_processor_id());
88705 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88706 smp_mb__before_atomic_inc(); /* See above. */
88707- atomic_inc(&rdtp->dynticks);
88708+ atomic_inc_unchecked(&rdtp->dynticks);
88709 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88710- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88711+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88712
88713 /*
88714 * It is illegal to enter an extended quiescent state while
88715@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88716 int user)
88717 {
88718 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88719- atomic_inc(&rdtp->dynticks);
88720+ atomic_inc_unchecked(&rdtp->dynticks);
88721 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88722 smp_mb__after_atomic_inc(); /* See above. */
88723- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88724+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88725 rcu_cleanup_after_idle(smp_processor_id());
88726 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88727 if (!user && !is_idle_task(current)) {
88728@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88729 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88730
88731 if (rdtp->dynticks_nmi_nesting == 0 &&
88732- (atomic_read(&rdtp->dynticks) & 0x1))
88733+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88734 return;
88735 rdtp->dynticks_nmi_nesting++;
88736 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88737- atomic_inc(&rdtp->dynticks);
88738+ atomic_inc_unchecked(&rdtp->dynticks);
88739 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88740 smp_mb__after_atomic_inc(); /* See above. */
88741- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88742+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88743 }
88744
88745 /**
88746@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88747 return;
88748 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88749 smp_mb__before_atomic_inc(); /* See above. */
88750- atomic_inc(&rdtp->dynticks);
88751+ atomic_inc_unchecked(&rdtp->dynticks);
88752 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88753- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88754+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88755 }
88756
88757 /**
88758@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88759 */
88760 bool notrace __rcu_is_watching(void)
88761 {
88762- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88763+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88764 }
88765
88766 /**
88767@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88768 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88769 bool *isidle, unsigned long *maxj)
88770 {
88771- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88772+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88773 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88774 return (rdp->dynticks_snap & 0x1) == 0;
88775 }
88776@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88777 unsigned int curr;
88778 unsigned int snap;
88779
88780- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88781+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88782 snap = (unsigned int)rdp->dynticks_snap;
88783
88784 /*
88785@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88786 rdp = this_cpu_ptr(rsp->rda);
88787 rcu_preempt_check_blocked_tasks(rnp);
88788 rnp->qsmask = rnp->qsmaskinit;
88789- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88790+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88791 WARN_ON_ONCE(rnp->completed != rsp->completed);
88792- ACCESS_ONCE(rnp->completed) = rsp->completed;
88793+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88794 if (rnp == rdp->mynode)
88795 __note_gp_changes(rsp, rnp, rdp);
88796 rcu_preempt_boost_start_gp(rnp);
88797@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88798 rcu_for_each_node_breadth_first(rsp, rnp) {
88799 raw_spin_lock_irq(&rnp->lock);
88800 smp_mb__after_unlock_lock();
88801- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88802+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88803 rdp = this_cpu_ptr(rsp->rda);
88804 if (rnp == rdp->mynode)
88805 __note_gp_changes(rsp, rnp, rdp);
88806@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88807 rsp->qlen += rdp->qlen;
88808 rdp->n_cbs_orphaned += rdp->qlen;
88809 rdp->qlen_lazy = 0;
88810- ACCESS_ONCE(rdp->qlen) = 0;
88811+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88812 }
88813
88814 /*
88815@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88816 }
88817 smp_mb(); /* List handling before counting for rcu_barrier(). */
88818 rdp->qlen_lazy -= count_lazy;
88819- ACCESS_ONCE(rdp->qlen) -= count;
88820+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88821 rdp->n_cbs_invoked += count;
88822
88823 /* Reinstate batch limit if we have worked down the excess. */
88824@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88825 /*
88826 * Do RCU core processing for the current CPU.
88827 */
88828-static void rcu_process_callbacks(struct softirq_action *unused)
88829+static void rcu_process_callbacks(void)
88830 {
88831 struct rcu_state *rsp;
88832
88833@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88834 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88835 if (debug_rcu_head_queue(head)) {
88836 /* Probable double call_rcu(), so leak the callback. */
88837- ACCESS_ONCE(head->func) = rcu_leak_callback;
88838+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88839 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88840 return;
88841 }
88842@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88843 local_irq_restore(flags);
88844 return;
88845 }
88846- ACCESS_ONCE(rdp->qlen)++;
88847+ ACCESS_ONCE_RW(rdp->qlen)++;
88848 if (lazy)
88849 rdp->qlen_lazy++;
88850 else
88851@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88852 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88853 * course be required on a 64-bit system.
88854 */
88855- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88856+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88857 (ulong)atomic_long_read(&rsp->expedited_done) +
88858 ULONG_MAX / 8)) {
88859 synchronize_sched();
88860- atomic_long_inc(&rsp->expedited_wrap);
88861+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88862 return;
88863 }
88864
88865@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88866 * Take a ticket. Note that atomic_inc_return() implies a
88867 * full memory barrier.
88868 */
88869- snap = atomic_long_inc_return(&rsp->expedited_start);
88870+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88871 firstsnap = snap;
88872 get_online_cpus();
88873 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88874@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88875 synchronize_sched_expedited_cpu_stop,
88876 NULL) == -EAGAIN) {
88877 put_online_cpus();
88878- atomic_long_inc(&rsp->expedited_tryfail);
88879+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88880
88881 /* Check to see if someone else did our work for us. */
88882 s = atomic_long_read(&rsp->expedited_done);
88883 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88884 /* ensure test happens before caller kfree */
88885 smp_mb__before_atomic_inc(); /* ^^^ */
88886- atomic_long_inc(&rsp->expedited_workdone1);
88887+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88888 return;
88889 }
88890
88891@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
88892 udelay(trycount * num_online_cpus());
88893 } else {
88894 wait_rcu_gp(call_rcu_sched);
88895- atomic_long_inc(&rsp->expedited_normal);
88896+ atomic_long_inc_unchecked(&rsp->expedited_normal);
88897 return;
88898 }
88899
88900@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
88901 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88902 /* ensure test happens before caller kfree */
88903 smp_mb__before_atomic_inc(); /* ^^^ */
88904- atomic_long_inc(&rsp->expedited_workdone2);
88905+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88906 return;
88907 }
88908
88909@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
88910 * period works for us.
88911 */
88912 get_online_cpus();
88913- snap = atomic_long_read(&rsp->expedited_start);
88914+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
88915 smp_mb(); /* ensure read is before try_stop_cpus(). */
88916 }
88917- atomic_long_inc(&rsp->expedited_stoppedcpus);
88918+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88919
88920 /*
88921 * Everyone up to our most recent fetch is covered by our grace
88922@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
88923 * than we did already did their update.
88924 */
88925 do {
88926- atomic_long_inc(&rsp->expedited_done_tries);
88927+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88928 s = atomic_long_read(&rsp->expedited_done);
88929 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88930 /* ensure test happens before caller kfree */
88931 smp_mb__before_atomic_inc(); /* ^^^ */
88932- atomic_long_inc(&rsp->expedited_done_lost);
88933+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88934 break;
88935 }
88936 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88937- atomic_long_inc(&rsp->expedited_done_exit);
88938+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88939
88940 put_online_cpus();
88941 }
88942@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88943 * ACCESS_ONCE() to prevent the compiler from speculating
88944 * the increment to precede the early-exit check.
88945 */
88946- ACCESS_ONCE(rsp->n_barrier_done)++;
88947+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88948 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88949 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88950 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88951@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88952
88953 /* Increment ->n_barrier_done to prevent duplicate work. */
88954 smp_mb(); /* Keep increment after above mechanism. */
88955- ACCESS_ONCE(rsp->n_barrier_done)++;
88956+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88957 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88958 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88959 smp_mb(); /* Keep increment before caller's subsequent code. */
88960@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88961 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88962 init_callback_list(rdp);
88963 rdp->qlen_lazy = 0;
88964- ACCESS_ONCE(rdp->qlen) = 0;
88965+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88966 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88967 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88968- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88969+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88970 rdp->cpu = cpu;
88971 rdp->rsp = rsp;
88972 rcu_boot_init_nocb_percpu_data(rdp);
88973@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88974 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88975 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88976 rcu_sysidle_init_percpu_data(rdp->dynticks);
88977- atomic_set(&rdp->dynticks->dynticks,
88978- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88979+ atomic_set_unchecked(&rdp->dynticks->dynticks,
88980+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88981 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88982
88983 /* Add CPU to rcu_node bitmasks. */
88984diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88985index 8c19873..bf83c57 100644
88986--- a/kernel/rcu/tree.h
88987+++ b/kernel/rcu/tree.h
88988@@ -87,11 +87,11 @@ struct rcu_dynticks {
88989 long long dynticks_nesting; /* Track irq/process nesting level. */
88990 /* Process level is worth LLONG_MAX/2. */
88991 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88992- atomic_t dynticks; /* Even value for idle, else odd. */
88993+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88994 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88995 long long dynticks_idle_nesting;
88996 /* irq/process nesting level from idle. */
88997- atomic_t dynticks_idle; /* Even value for idle, else odd. */
88998+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88999 /* "Idle" excludes userspace execution. */
89000 unsigned long dynticks_idle_jiffies;
89001 /* End of last non-NMI non-idle period. */
89002@@ -431,17 +431,17 @@ struct rcu_state {
89003 /* _rcu_barrier(). */
89004 /* End of fields guarded by barrier_mutex. */
89005
89006- atomic_long_t expedited_start; /* Starting ticket. */
89007- atomic_long_t expedited_done; /* Done ticket. */
89008- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89009- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89010- atomic_long_t expedited_workdone1; /* # done by others #1. */
89011- atomic_long_t expedited_workdone2; /* # done by others #2. */
89012- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89013- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89014- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89015- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89016- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89017+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89018+ atomic_long_t expedited_done; /* Done ticket. */
89019+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89020+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89021+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89022+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89023+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89024+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89025+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89026+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89027+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89028
89029 unsigned long jiffies_force_qs; /* Time at which to invoke */
89030 /* force_quiescent_state(). */
89031diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89032index 6e2ef4b..c15df94 100644
89033--- a/kernel/rcu/tree_plugin.h
89034+++ b/kernel/rcu/tree_plugin.h
89035@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89036 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89037 {
89038 return !rcu_preempted_readers_exp(rnp) &&
89039- ACCESS_ONCE(rnp->expmask) == 0;
89040+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89041 }
89042
89043 /*
89044@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89045
89046 /* Clean up and exit. */
89047 smp_mb(); /* ensure expedited GP seen before counter increment. */
89048- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89049+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89050 unlock_mb_ret:
89051 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89052 mb_ret:
89053@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89054 free_cpumask_var(cm);
89055 }
89056
89057-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89058+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89059 .store = &rcu_cpu_kthread_task,
89060 .thread_should_run = rcu_cpu_kthread_should_run,
89061 .thread_fn = rcu_cpu_kthread,
89062@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89063 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89064 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89065 cpu, ticks_value, ticks_title,
89066- atomic_read(&rdtp->dynticks) & 0xfff,
89067+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89068 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89069 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89070 fast_no_hz);
89071@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89072
89073 /* Enqueue the callback on the nocb list and update counts. */
89074 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89075- ACCESS_ONCE(*old_rhpp) = rhp;
89076+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89077 atomic_long_add(rhcount, &rdp->nocb_q_count);
89078 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89079
89080@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89081 * Extract queued callbacks, update counts, and wait
89082 * for a grace period to elapse.
89083 */
89084- ACCESS_ONCE(rdp->nocb_head) = NULL;
89085+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89086 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89087 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89088 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89089- ACCESS_ONCE(rdp->nocb_p_count) += c;
89090- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89091+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89092+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89093 rcu_nocb_wait_gp(rdp);
89094
89095 /* Each pass through the following loop invokes a callback. */
89096@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89097 list = next;
89098 }
89099 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89100- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89101- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89102+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89103+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89104 rdp->n_nocbs_invoked += c;
89105 }
89106 return 0;
89107@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89108 {
89109 if (!rcu_nocb_need_deferred_wakeup(rdp))
89110 return;
89111- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89112+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89113 wake_up(&rdp->nocb_wq);
89114 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89115 }
89116@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89117 t = kthread_run(rcu_nocb_kthread, rdp,
89118 "rcuo%c/%d", rsp->abbr, cpu);
89119 BUG_ON(IS_ERR(t));
89120- ACCESS_ONCE(rdp->nocb_kthread) = t;
89121+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89122 }
89123 }
89124
89125@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89126
89127 /* Record start of fully idle period. */
89128 j = jiffies;
89129- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89130+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89131 smp_mb__before_atomic_inc();
89132- atomic_inc(&rdtp->dynticks_idle);
89133+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89134 smp_mb__after_atomic_inc();
89135- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89136+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89137 }
89138
89139 /*
89140@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89141
89142 /* Record end of idle period. */
89143 smp_mb__before_atomic_inc();
89144- atomic_inc(&rdtp->dynticks_idle);
89145+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89146 smp_mb__after_atomic_inc();
89147- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89148+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89149
89150 /*
89151 * If we are the timekeeping CPU, we are permitted to be non-idle
89152@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89153 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89154
89155 /* Pick up current idle and NMI-nesting counter and check. */
89156- cur = atomic_read(&rdtp->dynticks_idle);
89157+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89158 if (cur & 0x1) {
89159 *isidle = false; /* We are not idle! */
89160 return;
89161@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89162 case RCU_SYSIDLE_NOT:
89163
89164 /* First time all are idle, so note a short idle period. */
89165- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89166+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89167 break;
89168
89169 case RCU_SYSIDLE_SHORT:
89170@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89171 static void rcu_sysidle_cancel(void)
89172 {
89173 smp_mb();
89174- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89175+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89176 }
89177
89178 /*
89179@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89180 smp_mb(); /* grace period precedes setting inuse. */
89181
89182 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89183- ACCESS_ONCE(rshp->inuse) = 0;
89184+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89185 }
89186
89187 /*
89188diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89189index 4def475..8ffddde 100644
89190--- a/kernel/rcu/tree_trace.c
89191+++ b/kernel/rcu/tree_trace.c
89192@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89193 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89194 rdp->passed_quiesce, rdp->qs_pending);
89195 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89196- atomic_read(&rdp->dynticks->dynticks),
89197+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89198 rdp->dynticks->dynticks_nesting,
89199 rdp->dynticks->dynticks_nmi_nesting,
89200 rdp->dynticks_fqs);
89201@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89202 struct rcu_state *rsp = (struct rcu_state *)m->private;
89203
89204 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",
89205- atomic_long_read(&rsp->expedited_start),
89206+ atomic_long_read_unchecked(&rsp->expedited_start),
89207 atomic_long_read(&rsp->expedited_done),
89208- atomic_long_read(&rsp->expedited_wrap),
89209- atomic_long_read(&rsp->expedited_tryfail),
89210- atomic_long_read(&rsp->expedited_workdone1),
89211- atomic_long_read(&rsp->expedited_workdone2),
89212- atomic_long_read(&rsp->expedited_normal),
89213- atomic_long_read(&rsp->expedited_stoppedcpus),
89214- atomic_long_read(&rsp->expedited_done_tries),
89215- atomic_long_read(&rsp->expedited_done_lost),
89216- atomic_long_read(&rsp->expedited_done_exit));
89217+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89218+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89219+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89220+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89221+ atomic_long_read_unchecked(&rsp->expedited_normal),
89222+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89223+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89224+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89225+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89226 return 0;
89227 }
89228
89229diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89230index c54609f..2e8829c 100644
89231--- a/kernel/rcu/update.c
89232+++ b/kernel/rcu/update.c
89233@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89234 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89235 */
89236 if (till_stall_check < 3) {
89237- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89238+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89239 till_stall_check = 3;
89240 } else if (till_stall_check > 300) {
89241- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89242+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89243 till_stall_check = 300;
89244 }
89245 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89246diff --git a/kernel/resource.c b/kernel/resource.c
89247index 3f285dc..5755f62 100644
89248--- a/kernel/resource.c
89249+++ b/kernel/resource.c
89250@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89251
89252 static int __init ioresources_init(void)
89253 {
89254+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89255+#ifdef CONFIG_GRKERNSEC_PROC_USER
89256+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89257+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89258+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89259+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89260+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89261+#endif
89262+#else
89263 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89264 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89265+#endif
89266 return 0;
89267 }
89268 __initcall(ioresources_init);
89269diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89270index 4a07353..66b5291 100644
89271--- a/kernel/sched/auto_group.c
89272+++ b/kernel/sched/auto_group.c
89273@@ -11,7 +11,7 @@
89274
89275 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89276 static struct autogroup autogroup_default;
89277-static atomic_t autogroup_seq_nr;
89278+static atomic_unchecked_t autogroup_seq_nr;
89279
89280 void __init autogroup_init(struct task_struct *init_task)
89281 {
89282@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89283
89284 kref_init(&ag->kref);
89285 init_rwsem(&ag->lock);
89286- ag->id = atomic_inc_return(&autogroup_seq_nr);
89287+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89288 ag->tg = tg;
89289 #ifdef CONFIG_RT_GROUP_SCHED
89290 /*
89291diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89292index a63f4dc..349bbb0 100644
89293--- a/kernel/sched/completion.c
89294+++ b/kernel/sched/completion.c
89295@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89296 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89297 * or number of jiffies left till timeout) if completed.
89298 */
89299-long __sched
89300+long __sched __intentional_overflow(-1)
89301 wait_for_completion_interruptible_timeout(struct completion *x,
89302 unsigned long timeout)
89303 {
89304@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89305 *
89306 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89307 */
89308-int __sched wait_for_completion_killable(struct completion *x)
89309+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89310 {
89311 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89312 if (t == -ERESTARTSYS)
89313@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89314 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89315 * or number of jiffies left till timeout) if completed.
89316 */
89317-long __sched
89318+long __sched __intentional_overflow(-1)
89319 wait_for_completion_killable_timeout(struct completion *x,
89320 unsigned long timeout)
89321 {
89322diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89323index f5c6635..ab9f223 100644
89324--- a/kernel/sched/core.c
89325+++ b/kernel/sched/core.c
89326@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89327 int sysctl_numa_balancing(struct ctl_table *table, int write,
89328 void __user *buffer, size_t *lenp, loff_t *ppos)
89329 {
89330- struct ctl_table t;
89331+ ctl_table_no_const t;
89332 int err;
89333 int state = numabalancing_enabled;
89334
89335@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89336 /* convert nice value [19,-20] to rlimit style value [1,40] */
89337 int nice_rlim = 20 - nice;
89338
89339+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89340+
89341 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89342 capable(CAP_SYS_NICE));
89343 }
89344@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89345 if (nice > 19)
89346 nice = 19;
89347
89348- if (increment < 0 && !can_nice(current, nice))
89349+ if (increment < 0 && (!can_nice(current, nice) ||
89350+ gr_handle_chroot_nice()))
89351 return -EPERM;
89352
89353 retval = security_task_setnice(current, nice);
89354@@ -3332,6 +3335,7 @@ recheck:
89355 if (policy != p->policy && !rlim_rtprio)
89356 return -EPERM;
89357
89358+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89359 /* can't increase priority */
89360 if (attr->sched_priority > p->rt_priority &&
89361 attr->sched_priority > rlim_rtprio)
89362@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89363
89364 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89365
89366-static struct ctl_table sd_ctl_dir[] = {
89367+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89368 {
89369 .procname = "sched_domain",
89370 .mode = 0555,
89371@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89372 {}
89373 };
89374
89375-static struct ctl_table *sd_alloc_ctl_entry(int n)
89376+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89377 {
89378- struct ctl_table *entry =
89379+ ctl_table_no_const *entry =
89380 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89381
89382 return entry;
89383 }
89384
89385-static void sd_free_ctl_entry(struct ctl_table **tablep)
89386+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89387 {
89388- struct ctl_table *entry;
89389+ ctl_table_no_const *entry;
89390
89391 /*
89392 * In the intermediate directories, both the child directory and
89393@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89394 * will always be set. In the lowest directory the names are
89395 * static strings and all have proc handlers.
89396 */
89397- for (entry = *tablep; entry->mode; entry++) {
89398- if (entry->child)
89399- sd_free_ctl_entry(&entry->child);
89400+ for (entry = tablep; entry->mode; entry++) {
89401+ if (entry->child) {
89402+ sd_free_ctl_entry(entry->child);
89403+ pax_open_kernel();
89404+ entry->child = NULL;
89405+ pax_close_kernel();
89406+ }
89407 if (entry->proc_handler == NULL)
89408 kfree(entry->procname);
89409 }
89410
89411- kfree(*tablep);
89412- *tablep = NULL;
89413+ kfree(tablep);
89414 }
89415
89416 static int min_load_idx = 0;
89417 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89418
89419 static void
89420-set_table_entry(struct ctl_table *entry,
89421+set_table_entry(ctl_table_no_const *entry,
89422 const char *procname, void *data, int maxlen,
89423 umode_t mode, proc_handler *proc_handler,
89424 bool load_idx)
89425@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89426 static struct ctl_table *
89427 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89428 {
89429- struct ctl_table *table = sd_alloc_ctl_entry(13);
89430+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89431
89432 if (table == NULL)
89433 return NULL;
89434@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89435 return table;
89436 }
89437
89438-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89439+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89440 {
89441- struct ctl_table *entry, *table;
89442+ ctl_table_no_const *entry, *table;
89443 struct sched_domain *sd;
89444 int domain_num = 0, i;
89445 char buf[32];
89446@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89447 static void register_sched_domain_sysctl(void)
89448 {
89449 int i, cpu_num = num_possible_cpus();
89450- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89451+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89452 char buf[32];
89453
89454 WARN_ON(sd_ctl_dir[0].child);
89455+ pax_open_kernel();
89456 sd_ctl_dir[0].child = entry;
89457+ pax_close_kernel();
89458
89459 if (entry == NULL)
89460 return;
89461@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89462 if (sd_sysctl_header)
89463 unregister_sysctl_table(sd_sysctl_header);
89464 sd_sysctl_header = NULL;
89465- if (sd_ctl_dir[0].child)
89466- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89467+ if (sd_ctl_dir[0].child) {
89468+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89469+ pax_open_kernel();
89470+ sd_ctl_dir[0].child = NULL;
89471+ pax_close_kernel();
89472+ }
89473 }
89474 #else
89475 static void register_sched_domain_sysctl(void)
89476diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89477index 9b4c4f3..665489b 100644
89478--- a/kernel/sched/fair.c
89479+++ b/kernel/sched/fair.c
89480@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89481
89482 static void reset_ptenuma_scan(struct task_struct *p)
89483 {
89484- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89485+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89486 p->mm->numa_scan_offset = 0;
89487 }
89488
89489@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89490 * run_rebalance_domains is triggered when needed from the scheduler tick.
89491 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89492 */
89493-static void run_rebalance_domains(struct softirq_action *h)
89494+static __latent_entropy void run_rebalance_domains(void)
89495 {
89496 struct rq *this_rq = this_rq();
89497 enum cpu_idle_type idle = this_rq->idle_balance ?
89498diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89499index f964add..dcd823d 100644
89500--- a/kernel/sched/sched.h
89501+++ b/kernel/sched/sched.h
89502@@ -1157,7 +1157,7 @@ struct sched_class {
89503 #ifdef CONFIG_FAIR_GROUP_SCHED
89504 void (*task_move_group) (struct task_struct *p, int on_rq);
89505 #endif
89506-};
89507+} __do_const;
89508
89509 #define sched_class_highest (&stop_sched_class)
89510 #define for_each_class(class) \
89511diff --git a/kernel/signal.c b/kernel/signal.c
89512index 52f881d..1e9f941 100644
89513--- a/kernel/signal.c
89514+++ b/kernel/signal.c
89515@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89516
89517 int print_fatal_signals __read_mostly;
89518
89519-static void __user *sig_handler(struct task_struct *t, int sig)
89520+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89521 {
89522 return t->sighand->action[sig - 1].sa.sa_handler;
89523 }
89524
89525-static int sig_handler_ignored(void __user *handler, int sig)
89526+static int sig_handler_ignored(__sighandler_t handler, int sig)
89527 {
89528 /* Is it explicitly or implicitly ignored? */
89529 return handler == SIG_IGN ||
89530@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89531
89532 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89533 {
89534- void __user *handler;
89535+ __sighandler_t handler;
89536
89537 handler = sig_handler(t, sig);
89538
89539@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89540 atomic_inc(&user->sigpending);
89541 rcu_read_unlock();
89542
89543+ if (!override_rlimit)
89544+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89545+
89546 if (override_rlimit ||
89547 atomic_read(&user->sigpending) <=
89548 task_rlimit(t, RLIMIT_SIGPENDING)) {
89549@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89550
89551 int unhandled_signal(struct task_struct *tsk, int sig)
89552 {
89553- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89554+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89555 if (is_global_init(tsk))
89556 return 1;
89557 if (handler != SIG_IGN && handler != SIG_DFL)
89558@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89559 }
89560 }
89561
89562+ /* allow glibc communication via tgkill to other threads in our
89563+ thread group */
89564+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89565+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89566+ && gr_handle_signal(t, sig))
89567+ return -EPERM;
89568+
89569 return security_task_kill(t, info, sig, 0);
89570 }
89571
89572@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89573 return send_signal(sig, info, p, 1);
89574 }
89575
89576-static int
89577+int
89578 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89579 {
89580 return send_signal(sig, info, t, 0);
89581@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89582 unsigned long int flags;
89583 int ret, blocked, ignored;
89584 struct k_sigaction *action;
89585+ int is_unhandled = 0;
89586
89587 spin_lock_irqsave(&t->sighand->siglock, flags);
89588 action = &t->sighand->action[sig-1];
89589@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89590 }
89591 if (action->sa.sa_handler == SIG_DFL)
89592 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89593+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89594+ is_unhandled = 1;
89595 ret = specific_send_sig_info(sig, info, t);
89596 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89597
89598+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89599+ normal operation */
89600+ if (is_unhandled) {
89601+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89602+ gr_handle_crash(t, sig);
89603+ }
89604+
89605 return ret;
89606 }
89607
89608@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89609 ret = check_kill_permission(sig, info, p);
89610 rcu_read_unlock();
89611
89612- if (!ret && sig)
89613+ if (!ret && sig) {
89614 ret = do_send_sig_info(sig, info, p, true);
89615+ if (!ret)
89616+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89617+ }
89618
89619 return ret;
89620 }
89621@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89622 int error = -ESRCH;
89623
89624 rcu_read_lock();
89625- p = find_task_by_vpid(pid);
89626+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89627+ /* allow glibc communication via tgkill to other threads in our
89628+ thread group */
89629+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89630+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89631+ p = find_task_by_vpid_unrestricted(pid);
89632+ else
89633+#endif
89634+ p = find_task_by_vpid(pid);
89635 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89636 error = check_kill_permission(sig, info, p);
89637 /*
89638@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89639 }
89640 seg = get_fs();
89641 set_fs(KERNEL_DS);
89642- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89643- (stack_t __force __user *) &uoss,
89644+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89645+ (stack_t __force_user *) &uoss,
89646 compat_user_stack_pointer());
89647 set_fs(seg);
89648 if (ret >= 0 && uoss_ptr) {
89649diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89650index eb89e18..a4e6792 100644
89651--- a/kernel/smpboot.c
89652+++ b/kernel/smpboot.c
89653@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89654 }
89655 smpboot_unpark_thread(plug_thread, cpu);
89656 }
89657- list_add(&plug_thread->list, &hotplug_threads);
89658+ pax_list_add(&plug_thread->list, &hotplug_threads);
89659 out:
89660 mutex_unlock(&smpboot_threads_lock);
89661 return ret;
89662@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89663 {
89664 get_online_cpus();
89665 mutex_lock(&smpboot_threads_lock);
89666- list_del(&plug_thread->list);
89667+ pax_list_del(&plug_thread->list);
89668 smpboot_destroy_threads(plug_thread);
89669 mutex_unlock(&smpboot_threads_lock);
89670 put_online_cpus();
89671diff --git a/kernel/softirq.c b/kernel/softirq.c
89672index 490fcbb..1e502c6 100644
89673--- a/kernel/softirq.c
89674+++ b/kernel/softirq.c
89675@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89676 EXPORT_SYMBOL(irq_stat);
89677 #endif
89678
89679-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89680+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89681
89682 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89683
89684@@ -267,7 +267,7 @@ restart:
89685 kstat_incr_softirqs_this_cpu(vec_nr);
89686
89687 trace_softirq_entry(vec_nr);
89688- h->action(h);
89689+ h->action();
89690 trace_softirq_exit(vec_nr);
89691 if (unlikely(prev_count != preempt_count())) {
89692 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89693@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89694 or_softirq_pending(1UL << nr);
89695 }
89696
89697-void open_softirq(int nr, void (*action)(struct softirq_action *))
89698+void __init open_softirq(int nr, void (*action)(void))
89699 {
89700 softirq_vec[nr].action = action;
89701 }
89702@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89703 }
89704 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89705
89706-static void tasklet_action(struct softirq_action *a)
89707+static void tasklet_action(void)
89708 {
89709 struct tasklet_struct *list;
89710
89711@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89712 }
89713 }
89714
89715-static void tasklet_hi_action(struct softirq_action *a)
89716+static __latent_entropy void tasklet_hi_action(void)
89717 {
89718 struct tasklet_struct *list;
89719
89720@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89721 .notifier_call = cpu_callback
89722 };
89723
89724-static struct smp_hotplug_thread softirq_threads = {
89725+static struct smp_hotplug_thread softirq_threads __read_only = {
89726 .store = &ksoftirqd,
89727 .thread_should_run = ksoftirqd_should_run,
89728 .thread_fn = run_ksoftirqd,
89729diff --git a/kernel/sys.c b/kernel/sys.c
89730index c0a58be..784c618 100644
89731--- a/kernel/sys.c
89732+++ b/kernel/sys.c
89733@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89734 error = -EACCES;
89735 goto out;
89736 }
89737+
89738+ if (gr_handle_chroot_setpriority(p, niceval)) {
89739+ error = -EACCES;
89740+ goto out;
89741+ }
89742+
89743 no_nice = security_task_setnice(p, niceval);
89744 if (no_nice) {
89745 error = no_nice;
89746@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89747 goto error;
89748 }
89749
89750+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89751+ goto error;
89752+
89753 if (rgid != (gid_t) -1 ||
89754 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89755 new->sgid = new->egid;
89756@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89757 old = current_cred();
89758
89759 retval = -EPERM;
89760+
89761+ if (gr_check_group_change(kgid, kgid, kgid))
89762+ goto error;
89763+
89764 if (ns_capable(old->user_ns, CAP_SETGID))
89765 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89766 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89767@@ -403,7 +416,7 @@ error:
89768 /*
89769 * change the user struct in a credentials set to match the new UID
89770 */
89771-static int set_user(struct cred *new)
89772+int set_user(struct cred *new)
89773 {
89774 struct user_struct *new_user;
89775
89776@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89777 goto error;
89778 }
89779
89780+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89781+ goto error;
89782+
89783 if (!uid_eq(new->uid, old->uid)) {
89784 retval = set_user(new);
89785 if (retval < 0)
89786@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89787 old = current_cred();
89788
89789 retval = -EPERM;
89790+
89791+ if (gr_check_crash_uid(kuid))
89792+ goto error;
89793+ if (gr_check_user_change(kuid, kuid, kuid))
89794+ goto error;
89795+
89796 if (ns_capable(old->user_ns, CAP_SETUID)) {
89797 new->suid = new->uid = kuid;
89798 if (!uid_eq(kuid, old->uid)) {
89799@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89800 goto error;
89801 }
89802
89803+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89804+ goto error;
89805+
89806 if (ruid != (uid_t) -1) {
89807 new->uid = kruid;
89808 if (!uid_eq(kruid, old->uid)) {
89809@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89810 goto error;
89811 }
89812
89813+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89814+ goto error;
89815+
89816 if (rgid != (gid_t) -1)
89817 new->gid = krgid;
89818 if (egid != (gid_t) -1)
89819@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89820 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89821 ns_capable(old->user_ns, CAP_SETUID)) {
89822 if (!uid_eq(kuid, old->fsuid)) {
89823+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89824+ goto error;
89825+
89826 new->fsuid = kuid;
89827 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89828 goto change_okay;
89829 }
89830 }
89831
89832+error:
89833 abort_creds(new);
89834 return old_fsuid;
89835
89836@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89837 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89838 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89839 ns_capable(old->user_ns, CAP_SETGID)) {
89840+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89841+ goto error;
89842+
89843 if (!gid_eq(kgid, old->fsgid)) {
89844 new->fsgid = kgid;
89845 goto change_okay;
89846 }
89847 }
89848
89849+error:
89850 abort_creds(new);
89851 return old_fsgid;
89852
89853@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89854 return -EFAULT;
89855
89856 down_read(&uts_sem);
89857- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89858+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89859 __OLD_UTS_LEN);
89860 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89861- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89862+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89863 __OLD_UTS_LEN);
89864 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89865- error |= __copy_to_user(&name->release, &utsname()->release,
89866+ error |= __copy_to_user(name->release, &utsname()->release,
89867 __OLD_UTS_LEN);
89868 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89869- error |= __copy_to_user(&name->version, &utsname()->version,
89870+ error |= __copy_to_user(name->version, &utsname()->version,
89871 __OLD_UTS_LEN);
89872 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89873- error |= __copy_to_user(&name->machine, &utsname()->machine,
89874+ error |= __copy_to_user(name->machine, &utsname()->machine,
89875 __OLD_UTS_LEN);
89876 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89877 up_read(&uts_sem);
89878@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89879 */
89880 new_rlim->rlim_cur = 1;
89881 }
89882+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89883+ is changed to a lower value. Since tasks can be created by the same
89884+ user in between this limit change and an execve by this task, force
89885+ a recheck only for this task by setting PF_NPROC_EXCEEDED
89886+ */
89887+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89888+ tsk->flags |= PF_NPROC_EXCEEDED;
89889 }
89890 if (!retval) {
89891 if (old_rlim)
89892diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89893index aae21e8..58d8c9a 100644
89894--- a/kernel/sysctl.c
89895+++ b/kernel/sysctl.c
89896@@ -94,7 +94,6 @@
89897
89898
89899 #if defined(CONFIG_SYSCTL)
89900-
89901 /* External variables not in a header file. */
89902 extern int max_threads;
89903 extern int suid_dumpable;
89904@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
89905
89906 /* Constants used for minimum and maximum */
89907 #ifdef CONFIG_LOCKUP_DETECTOR
89908-static int sixty = 60;
89909+static int sixty __read_only = 60;
89910 #endif
89911
89912-static int __maybe_unused neg_one = -1;
89913-
89914-static int zero;
89915-static int __maybe_unused one = 1;
89916-static int __maybe_unused two = 2;
89917-static int __maybe_unused three = 3;
89918-static unsigned long one_ul = 1;
89919-static int one_hundred = 100;
89920+static int __maybe_unused neg_one __read_only = -1;
89921+static int zero __read_only = 0;
89922+static int __maybe_unused one __read_only = 1;
89923+static int __maybe_unused two __read_only = 2;
89924+static int __maybe_unused three __read_only = 3;
89925+static unsigned long one_ul __read_only = 1;
89926+static int one_hundred __read_only = 100;
89927 #ifdef CONFIG_PRINTK
89928-static int ten_thousand = 10000;
89929+static int ten_thousand __read_only = 10000;
89930 #endif
89931
89932 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89933@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
89934 void __user *buffer, size_t *lenp, loff_t *ppos);
89935 #endif
89936
89937-#ifdef CONFIG_PRINTK
89938 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89939 void __user *buffer, size_t *lenp, loff_t *ppos);
89940-#endif
89941
89942 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89943 void __user *buffer, size_t *lenp, loff_t *ppos);
89944@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89945
89946 #endif
89947
89948+extern struct ctl_table grsecurity_table[];
89949+
89950 static struct ctl_table kern_table[];
89951 static struct ctl_table vm_table[];
89952 static struct ctl_table fs_table[];
89953@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
89954 int sysctl_legacy_va_layout;
89955 #endif
89956
89957+#ifdef CONFIG_PAX_SOFTMODE
89958+static ctl_table pax_table[] = {
89959+ {
89960+ .procname = "softmode",
89961+ .data = &pax_softmode,
89962+ .maxlen = sizeof(unsigned int),
89963+ .mode = 0600,
89964+ .proc_handler = &proc_dointvec,
89965+ },
89966+
89967+ { }
89968+};
89969+#endif
89970+
89971 /* The default sysctl tables: */
89972
89973 static struct ctl_table sysctl_base_table[] = {
89974@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
89975 #endif
89976
89977 static struct ctl_table kern_table[] = {
89978+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89979+ {
89980+ .procname = "grsecurity",
89981+ .mode = 0500,
89982+ .child = grsecurity_table,
89983+ },
89984+#endif
89985+
89986+#ifdef CONFIG_PAX_SOFTMODE
89987+ {
89988+ .procname = "pax",
89989+ .mode = 0500,
89990+ .child = pax_table,
89991+ },
89992+#endif
89993+
89994 {
89995 .procname = "sched_child_runs_first",
89996 .data = &sysctl_sched_child_runs_first,
89997@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
89998 .data = &modprobe_path,
89999 .maxlen = KMOD_PATH_LEN,
90000 .mode = 0644,
90001- .proc_handler = proc_dostring,
90002+ .proc_handler = proc_dostring_modpriv,
90003 },
90004 {
90005 .procname = "modules_disabled",
90006@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90007 .extra1 = &zero,
90008 .extra2 = &one,
90009 },
90010+#endif
90011 {
90012 .procname = "kptr_restrict",
90013 .data = &kptr_restrict,
90014 .maxlen = sizeof(int),
90015 .mode = 0644,
90016 .proc_handler = proc_dointvec_minmax_sysadmin,
90017+#ifdef CONFIG_GRKERNSEC_HIDESYM
90018+ .extra1 = &two,
90019+#else
90020 .extra1 = &zero,
90021+#endif
90022 .extra2 = &two,
90023 },
90024-#endif
90025 {
90026 .procname = "ngroups_max",
90027 .data = &ngroups_max,
90028@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90029 */
90030 {
90031 .procname = "perf_event_paranoid",
90032- .data = &sysctl_perf_event_paranoid,
90033- .maxlen = sizeof(sysctl_perf_event_paranoid),
90034+ .data = &sysctl_perf_event_legitimately_concerned,
90035+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90036 .mode = 0644,
90037- .proc_handler = proc_dointvec,
90038+ /* go ahead, be a hero */
90039+ .proc_handler = proc_dointvec_minmax_sysadmin,
90040+ .extra1 = &neg_one,
90041+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90042+ .extra2 = &three,
90043+#else
90044+ .extra2 = &two,
90045+#endif
90046 },
90047 {
90048 .procname = "perf_event_mlock_kb",
90049@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90050 .proc_handler = proc_dointvec_minmax,
90051 .extra1 = &zero,
90052 },
90053+ {
90054+ .procname = "heap_stack_gap",
90055+ .data = &sysctl_heap_stack_gap,
90056+ .maxlen = sizeof(sysctl_heap_stack_gap),
90057+ .mode = 0644,
90058+ .proc_handler = proc_doulongvec_minmax,
90059+ },
90060 #else
90061 {
90062 .procname = "nr_trim_pages",
90063@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90064 buffer, lenp, ppos);
90065 }
90066
90067+int proc_dostring_modpriv(struct ctl_table *table, int write,
90068+ void __user *buffer, size_t *lenp, loff_t *ppos)
90069+{
90070+ if (write && !capable(CAP_SYS_MODULE))
90071+ return -EPERM;
90072+
90073+ return _proc_do_string(table->data, table->maxlen, write,
90074+ buffer, lenp, ppos);
90075+}
90076+
90077 static size_t proc_skip_spaces(char **buf)
90078 {
90079 size_t ret;
90080@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90081 len = strlen(tmp);
90082 if (len > *size)
90083 len = *size;
90084+ if (len > sizeof(tmp))
90085+ len = sizeof(tmp);
90086 if (copy_to_user(*buf, tmp, len))
90087 return -EFAULT;
90088 *size -= len;
90089@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90090 static int proc_taint(struct ctl_table *table, int write,
90091 void __user *buffer, size_t *lenp, loff_t *ppos)
90092 {
90093- struct ctl_table t;
90094+ ctl_table_no_const t;
90095 unsigned long tmptaint = get_taint();
90096 int err;
90097
90098@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90099 return err;
90100 }
90101
90102-#ifdef CONFIG_PRINTK
90103 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90104 void __user *buffer, size_t *lenp, loff_t *ppos)
90105 {
90106@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90107
90108 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90109 }
90110-#endif
90111
90112 struct do_proc_dointvec_minmax_conv_param {
90113 int *min;
90114@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90115 return -ENOSYS;
90116 }
90117
90118+int proc_dostring_modpriv(struct ctl_table *table, int write,
90119+ void __user *buffer, size_t *lenp, loff_t *ppos)
90120+{
90121+ return -ENOSYS;
90122+}
90123+
90124 int proc_dointvec(struct ctl_table *table, int write,
90125 void __user *buffer, size_t *lenp, loff_t *ppos)
90126 {
90127@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90128 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90129 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90130 EXPORT_SYMBOL(proc_dostring);
90131+EXPORT_SYMBOL(proc_dostring_modpriv);
90132 EXPORT_SYMBOL(proc_doulongvec_minmax);
90133 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90134diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90135index 13d2f7c..c93d0b0 100644
90136--- a/kernel/taskstats.c
90137+++ b/kernel/taskstats.c
90138@@ -28,9 +28,12 @@
90139 #include <linux/fs.h>
90140 #include <linux/file.h>
90141 #include <linux/pid_namespace.h>
90142+#include <linux/grsecurity.h>
90143 #include <net/genetlink.h>
90144 #include <linux/atomic.h>
90145
90146+extern int gr_is_taskstats_denied(int pid);
90147+
90148 /*
90149 * Maximum length of a cpumask that can be specified in
90150 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90151@@ -576,6 +579,9 @@ err:
90152
90153 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90154 {
90155+ if (gr_is_taskstats_denied(current->pid))
90156+ return -EACCES;
90157+
90158 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90159 return cmd_attr_register_cpumask(info);
90160 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90161diff --git a/kernel/time.c b/kernel/time.c
90162index 7c7964c..2a0d412 100644
90163--- a/kernel/time.c
90164+++ b/kernel/time.c
90165@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90166 return error;
90167
90168 if (tz) {
90169+ /* we log in do_settimeofday called below, so don't log twice
90170+ */
90171+ if (!tv)
90172+ gr_log_timechange();
90173+
90174 sys_tz = *tz;
90175 update_vsyscall_tz();
90176 if (firsttime) {
90177diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90178index 88c9c65..7497ebc 100644
90179--- a/kernel/time/alarmtimer.c
90180+++ b/kernel/time/alarmtimer.c
90181@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90182 struct platform_device *pdev;
90183 int error = 0;
90184 int i;
90185- struct k_clock alarm_clock = {
90186+ static struct k_clock alarm_clock = {
90187 .clock_getres = alarm_clock_getres,
90188 .clock_get = alarm_clock_get,
90189 .timer_create = alarm_timer_create,
90190diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90191index 5b40279..81e58db 100644
90192--- a/kernel/time/timekeeping.c
90193+++ b/kernel/time/timekeeping.c
90194@@ -15,6 +15,7 @@
90195 #include <linux/init.h>
90196 #include <linux/mm.h>
90197 #include <linux/sched.h>
90198+#include <linux/grsecurity.h>
90199 #include <linux/syscore_ops.h>
90200 #include <linux/clocksource.h>
90201 #include <linux/jiffies.h>
90202@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90203 if (!timespec_valid_strict(tv))
90204 return -EINVAL;
90205
90206+ gr_log_timechange();
90207+
90208 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90209 write_seqcount_begin(&timekeeper_seq);
90210
90211diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90212index 61ed862..3b52c65 100644
90213--- a/kernel/time/timer_list.c
90214+++ b/kernel/time/timer_list.c
90215@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90216
90217 static void print_name_offset(struct seq_file *m, void *sym)
90218 {
90219+#ifdef CONFIG_GRKERNSEC_HIDESYM
90220+ SEQ_printf(m, "<%p>", NULL);
90221+#else
90222 char symname[KSYM_NAME_LEN];
90223
90224 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90225 SEQ_printf(m, "<%pK>", sym);
90226 else
90227 SEQ_printf(m, "%s", symname);
90228+#endif
90229 }
90230
90231 static void
90232@@ -119,7 +123,11 @@ next_one:
90233 static void
90234 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90235 {
90236+#ifdef CONFIG_GRKERNSEC_HIDESYM
90237+ SEQ_printf(m, " .base: %p\n", NULL);
90238+#else
90239 SEQ_printf(m, " .base: %pK\n", base);
90240+#endif
90241 SEQ_printf(m, " .index: %d\n",
90242 base->index);
90243 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90244@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90245 {
90246 struct proc_dir_entry *pe;
90247
90248+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90249+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90250+#else
90251 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90252+#endif
90253 if (!pe)
90254 return -ENOMEM;
90255 return 0;
90256diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90257index 1fb08f2..ca4bb1e 100644
90258--- a/kernel/time/timer_stats.c
90259+++ b/kernel/time/timer_stats.c
90260@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90261 static unsigned long nr_entries;
90262 static struct entry entries[MAX_ENTRIES];
90263
90264-static atomic_t overflow_count;
90265+static atomic_unchecked_t overflow_count;
90266
90267 /*
90268 * The entries are in a hash-table, for fast lookup:
90269@@ -140,7 +140,7 @@ static void reset_entries(void)
90270 nr_entries = 0;
90271 memset(entries, 0, sizeof(entries));
90272 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90273- atomic_set(&overflow_count, 0);
90274+ atomic_set_unchecked(&overflow_count, 0);
90275 }
90276
90277 static struct entry *alloc_entry(void)
90278@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90279 if (likely(entry))
90280 entry->count++;
90281 else
90282- atomic_inc(&overflow_count);
90283+ atomic_inc_unchecked(&overflow_count);
90284
90285 out_unlock:
90286 raw_spin_unlock_irqrestore(lock, flags);
90287@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90288
90289 static void print_name_offset(struct seq_file *m, unsigned long addr)
90290 {
90291+#ifdef CONFIG_GRKERNSEC_HIDESYM
90292+ seq_printf(m, "<%p>", NULL);
90293+#else
90294 char symname[KSYM_NAME_LEN];
90295
90296 if (lookup_symbol_name(addr, symname) < 0)
90297- seq_printf(m, "<%p>", (void *)addr);
90298+ seq_printf(m, "<%pK>", (void *)addr);
90299 else
90300 seq_printf(m, "%s", symname);
90301+#endif
90302 }
90303
90304 static int tstats_show(struct seq_file *m, void *v)
90305@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90306
90307 seq_puts(m, "Timer Stats Version: v0.3\n");
90308 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90309- if (atomic_read(&overflow_count))
90310- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90311+ if (atomic_read_unchecked(&overflow_count))
90312+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90313 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90314
90315 for (i = 0; i < nr_entries; i++) {
90316@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90317 {
90318 struct proc_dir_entry *pe;
90319
90320+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90321+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90322+#else
90323 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90324+#endif
90325 if (!pe)
90326 return -ENOMEM;
90327 return 0;
90328diff --git a/kernel/timer.c b/kernel/timer.c
90329index accfd24..e00f0c0 100644
90330--- a/kernel/timer.c
90331+++ b/kernel/timer.c
90332@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90333 /*
90334 * This function runs timers and the timer-tq in bottom half context.
90335 */
90336-static void run_timer_softirq(struct softirq_action *h)
90337+static __latent_entropy void run_timer_softirq(void)
90338 {
90339 struct tvec_base *base = __this_cpu_read(tvec_bases);
90340
90341@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90342 *
90343 * In all cases the return value is guaranteed to be non-negative.
90344 */
90345-signed long __sched schedule_timeout(signed long timeout)
90346+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90347 {
90348 struct timer_list timer;
90349 unsigned long expire;
90350diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90351index b418cb0..f879a3d 100644
90352--- a/kernel/trace/blktrace.c
90353+++ b/kernel/trace/blktrace.c
90354@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90355 struct blk_trace *bt = filp->private_data;
90356 char buf[16];
90357
90358- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90359+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90360
90361 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90362 }
90363@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90364 return 1;
90365
90366 bt = buf->chan->private_data;
90367- atomic_inc(&bt->dropped);
90368+ atomic_inc_unchecked(&bt->dropped);
90369 return 0;
90370 }
90371
90372@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90373
90374 bt->dir = dir;
90375 bt->dev = dev;
90376- atomic_set(&bt->dropped, 0);
90377+ atomic_set_unchecked(&bt->dropped, 0);
90378 INIT_LIST_HEAD(&bt->running_list);
90379
90380 ret = -EIO;
90381diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90382index cd7f76d..553c805 100644
90383--- a/kernel/trace/ftrace.c
90384+++ b/kernel/trace/ftrace.c
90385@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90386 if (unlikely(ftrace_disabled))
90387 return 0;
90388
90389+ ret = ftrace_arch_code_modify_prepare();
90390+ FTRACE_WARN_ON(ret);
90391+ if (ret)
90392+ return 0;
90393+
90394 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90395+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90396 if (ret) {
90397 ftrace_bug(ret, ip);
90398- return 0;
90399 }
90400- return 1;
90401+ return ret ? 0 : 1;
90402 }
90403
90404 /*
90405@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90406 if (!count)
90407 return 0;
90408
90409+ pax_open_kernel();
90410 sort(start, count, sizeof(*start),
90411 ftrace_cmp_ips, ftrace_swap_ips);
90412+ pax_close_kernel();
90413
90414 start_pg = ftrace_allocate_pages(count);
90415 if (!start_pg)
90416@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90417 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90418
90419 static int ftrace_graph_active;
90420-static struct notifier_block ftrace_suspend_notifier;
90421-
90422 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90423 {
90424 return 0;
90425@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90426 ftrace_graph_entry = ftrace_graph_entry_test;
90427 }
90428
90429+static struct notifier_block ftrace_suspend_notifier = {
90430+ .notifier_call = ftrace_suspend_notifier_call
90431+};
90432+
90433 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90434 trace_func_graph_ent_t entryfunc)
90435 {
90436@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90437 goto out;
90438 }
90439
90440- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90441 register_pm_notifier(&ftrace_suspend_notifier);
90442
90443 ftrace_graph_active++;
90444diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90445index fc4da2d..f3e800b 100644
90446--- a/kernel/trace/ring_buffer.c
90447+++ b/kernel/trace/ring_buffer.c
90448@@ -352,9 +352,9 @@ struct buffer_data_page {
90449 */
90450 struct buffer_page {
90451 struct list_head list; /* list of buffer pages */
90452- local_t write; /* index for next write */
90453+ local_unchecked_t write; /* index for next write */
90454 unsigned read; /* index for next read */
90455- local_t entries; /* entries on this page */
90456+ local_unchecked_t entries; /* entries on this page */
90457 unsigned long real_end; /* real end of data */
90458 struct buffer_data_page *page; /* Actual data page */
90459 };
90460@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90461 unsigned long last_overrun;
90462 local_t entries_bytes;
90463 local_t entries;
90464- local_t overrun;
90465- local_t commit_overrun;
90466+ local_unchecked_t overrun;
90467+ local_unchecked_t commit_overrun;
90468 local_t dropped_events;
90469 local_t committing;
90470 local_t commits;
90471@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90472 *
90473 * We add a counter to the write field to denote this.
90474 */
90475- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90476- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90477+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90478+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90479
90480 /*
90481 * Just make sure we have seen our old_write and synchronize
90482@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90483 * cmpxchg to only update if an interrupt did not already
90484 * do it for us. If the cmpxchg fails, we don't care.
90485 */
90486- (void)local_cmpxchg(&next_page->write, old_write, val);
90487- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90488+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90489+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90490
90491 /*
90492 * No need to worry about races with clearing out the commit.
90493@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90494
90495 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90496 {
90497- return local_read(&bpage->entries) & RB_WRITE_MASK;
90498+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90499 }
90500
90501 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90502 {
90503- return local_read(&bpage->write) & RB_WRITE_MASK;
90504+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90505 }
90506
90507 static int
90508@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90509 * bytes consumed in ring buffer from here.
90510 * Increment overrun to account for the lost events.
90511 */
90512- local_add(page_entries, &cpu_buffer->overrun);
90513+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90514 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90515 }
90516
90517@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90518 * it is our responsibility to update
90519 * the counters.
90520 */
90521- local_add(entries, &cpu_buffer->overrun);
90522+ local_add_unchecked(entries, &cpu_buffer->overrun);
90523 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90524
90525 /*
90526@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90527 if (tail == BUF_PAGE_SIZE)
90528 tail_page->real_end = 0;
90529
90530- local_sub(length, &tail_page->write);
90531+ local_sub_unchecked(length, &tail_page->write);
90532 return;
90533 }
90534
90535@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90536 rb_event_set_padding(event);
90537
90538 /* Set the write back to the previous setting */
90539- local_sub(length, &tail_page->write);
90540+ local_sub_unchecked(length, &tail_page->write);
90541 return;
90542 }
90543
90544@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90545
90546 /* Set write to end of buffer */
90547 length = (tail + length) - BUF_PAGE_SIZE;
90548- local_sub(length, &tail_page->write);
90549+ local_sub_unchecked(length, &tail_page->write);
90550 }
90551
90552 /*
90553@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90554 * about it.
90555 */
90556 if (unlikely(next_page == commit_page)) {
90557- local_inc(&cpu_buffer->commit_overrun);
90558+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90559 goto out_reset;
90560 }
90561
90562@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90563 cpu_buffer->tail_page) &&
90564 (cpu_buffer->commit_page ==
90565 cpu_buffer->reader_page))) {
90566- local_inc(&cpu_buffer->commit_overrun);
90567+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90568 goto out_reset;
90569 }
90570 }
90571@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90572 length += RB_LEN_TIME_EXTEND;
90573
90574 tail_page = cpu_buffer->tail_page;
90575- write = local_add_return(length, &tail_page->write);
90576+ write = local_add_return_unchecked(length, &tail_page->write);
90577
90578 /* set write to only the index of the write */
90579 write &= RB_WRITE_MASK;
90580@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90581 kmemcheck_annotate_bitfield(event, bitfield);
90582 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90583
90584- local_inc(&tail_page->entries);
90585+ local_inc_unchecked(&tail_page->entries);
90586
90587 /*
90588 * If this is the first commit on the page, then update
90589@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90590
90591 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90592 unsigned long write_mask =
90593- local_read(&bpage->write) & ~RB_WRITE_MASK;
90594+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90595 unsigned long event_length = rb_event_length(event);
90596 /*
90597 * This is on the tail page. It is possible that
90598@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90599 */
90600 old_index += write_mask;
90601 new_index += write_mask;
90602- index = local_cmpxchg(&bpage->write, old_index, new_index);
90603+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90604 if (index == old_index) {
90605 /* update counters */
90606 local_sub(event_length, &cpu_buffer->entries_bytes);
90607@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90608
90609 /* Do the likely case first */
90610 if (likely(bpage->page == (void *)addr)) {
90611- local_dec(&bpage->entries);
90612+ local_dec_unchecked(&bpage->entries);
90613 return;
90614 }
90615
90616@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90617 start = bpage;
90618 do {
90619 if (bpage->page == (void *)addr) {
90620- local_dec(&bpage->entries);
90621+ local_dec_unchecked(&bpage->entries);
90622 return;
90623 }
90624 rb_inc_page(cpu_buffer, &bpage);
90625@@ -3146,7 +3146,7 @@ static inline unsigned long
90626 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90627 {
90628 return local_read(&cpu_buffer->entries) -
90629- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90630+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90631 }
90632
90633 /**
90634@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90635 return 0;
90636
90637 cpu_buffer = buffer->buffers[cpu];
90638- ret = local_read(&cpu_buffer->overrun);
90639+ ret = local_read_unchecked(&cpu_buffer->overrun);
90640
90641 return ret;
90642 }
90643@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90644 return 0;
90645
90646 cpu_buffer = buffer->buffers[cpu];
90647- ret = local_read(&cpu_buffer->commit_overrun);
90648+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90649
90650 return ret;
90651 }
90652@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90653 /* if you care about this being correct, lock the buffer */
90654 for_each_buffer_cpu(buffer, cpu) {
90655 cpu_buffer = buffer->buffers[cpu];
90656- overruns += local_read(&cpu_buffer->overrun);
90657+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90658 }
90659
90660 return overruns;
90661@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90662 /*
90663 * Reset the reader page to size zero.
90664 */
90665- local_set(&cpu_buffer->reader_page->write, 0);
90666- local_set(&cpu_buffer->reader_page->entries, 0);
90667+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90668+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90669 local_set(&cpu_buffer->reader_page->page->commit, 0);
90670 cpu_buffer->reader_page->real_end = 0;
90671
90672@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90673 * want to compare with the last_overrun.
90674 */
90675 smp_mb();
90676- overwrite = local_read(&(cpu_buffer->overrun));
90677+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90678
90679 /*
90680 * Here's the tricky part.
90681@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90682
90683 cpu_buffer->head_page
90684 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90685- local_set(&cpu_buffer->head_page->write, 0);
90686- local_set(&cpu_buffer->head_page->entries, 0);
90687+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90688+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90689 local_set(&cpu_buffer->head_page->page->commit, 0);
90690
90691 cpu_buffer->head_page->read = 0;
90692@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90693
90694 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90695 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90696- local_set(&cpu_buffer->reader_page->write, 0);
90697- local_set(&cpu_buffer->reader_page->entries, 0);
90698+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90699+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90700 local_set(&cpu_buffer->reader_page->page->commit, 0);
90701 cpu_buffer->reader_page->read = 0;
90702
90703 local_set(&cpu_buffer->entries_bytes, 0);
90704- local_set(&cpu_buffer->overrun, 0);
90705- local_set(&cpu_buffer->commit_overrun, 0);
90706+ local_set_unchecked(&cpu_buffer->overrun, 0);
90707+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90708 local_set(&cpu_buffer->dropped_events, 0);
90709 local_set(&cpu_buffer->entries, 0);
90710 local_set(&cpu_buffer->committing, 0);
90711@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90712 rb_init_page(bpage);
90713 bpage = reader->page;
90714 reader->page = *data_page;
90715- local_set(&reader->write, 0);
90716- local_set(&reader->entries, 0);
90717+ local_set_unchecked(&reader->write, 0);
90718+ local_set_unchecked(&reader->entries, 0);
90719 reader->read = 0;
90720 *data_page = bpage;
90721
90722diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90723index 24c1f23..781fd73f 100644
90724--- a/kernel/trace/trace.c
90725+++ b/kernel/trace/trace.c
90726@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90727 return 0;
90728 }
90729
90730-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90731+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90732 {
90733 /* do nothing if flag is already set */
90734 if (!!(trace_flags & mask) == !!enabled)
90735diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90736index 02b592f..f971546 100644
90737--- a/kernel/trace/trace.h
90738+++ b/kernel/trace/trace.h
90739@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90740 void trace_printk_init_buffers(void);
90741 void trace_printk_start_comm(void);
90742 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90743-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90744+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90745
90746 /*
90747 * Normal trace_printk() and friends allocates special buffers
90748diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90749index 26dc348..8708ca7 100644
90750--- a/kernel/trace/trace_clock.c
90751+++ b/kernel/trace/trace_clock.c
90752@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90753 return now;
90754 }
90755
90756-static atomic64_t trace_counter;
90757+static atomic64_unchecked_t trace_counter;
90758
90759 /*
90760 * trace_clock_counter(): simply an atomic counter.
90761@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90762 */
90763 u64 notrace trace_clock_counter(void)
90764 {
90765- return atomic64_add_return(1, &trace_counter);
90766+ return atomic64_inc_return_unchecked(&trace_counter);
90767 }
90768diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90769index 7b16d40..1b2875d 100644
90770--- a/kernel/trace/trace_events.c
90771+++ b/kernel/trace/trace_events.c
90772@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90773 return 0;
90774 }
90775
90776-struct ftrace_module_file_ops;
90777 static void __add_event_to_tracers(struct ftrace_event_call *call);
90778
90779 /* Add an additional event_call dynamically */
90780diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90781index 0abd9b8..6a663a2 100644
90782--- a/kernel/trace/trace_mmiotrace.c
90783+++ b/kernel/trace/trace_mmiotrace.c
90784@@ -24,7 +24,7 @@ struct header_iter {
90785 static struct trace_array *mmio_trace_array;
90786 static bool overrun_detected;
90787 static unsigned long prev_overruns;
90788-static atomic_t dropped_count;
90789+static atomic_unchecked_t dropped_count;
90790
90791 static void mmio_reset_data(struct trace_array *tr)
90792 {
90793@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90794
90795 static unsigned long count_overruns(struct trace_iterator *iter)
90796 {
90797- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90798+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90799 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90800
90801 if (over > prev_overruns)
90802@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90803 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90804 sizeof(*entry), 0, pc);
90805 if (!event) {
90806- atomic_inc(&dropped_count);
90807+ atomic_inc_unchecked(&dropped_count);
90808 return;
90809 }
90810 entry = ring_buffer_event_data(event);
90811@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90812 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90813 sizeof(*entry), 0, pc);
90814 if (!event) {
90815- atomic_inc(&dropped_count);
90816+ atomic_inc_unchecked(&dropped_count);
90817 return;
90818 }
90819 entry = ring_buffer_event_data(event);
90820diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90821index ed32284..884d6c3 100644
90822--- a/kernel/trace/trace_output.c
90823+++ b/kernel/trace/trace_output.c
90824@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90825
90826 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90827 if (!IS_ERR(p)) {
90828- p = mangle_path(s->buffer + s->len, p, "\n");
90829+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90830 if (p) {
90831 s->len = p - s->buffer;
90832 return 1;
90833@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90834 goto out;
90835 }
90836
90837+ pax_open_kernel();
90838 if (event->funcs->trace == NULL)
90839- event->funcs->trace = trace_nop_print;
90840+ *(void **)&event->funcs->trace = trace_nop_print;
90841 if (event->funcs->raw == NULL)
90842- event->funcs->raw = trace_nop_print;
90843+ *(void **)&event->funcs->raw = trace_nop_print;
90844 if (event->funcs->hex == NULL)
90845- event->funcs->hex = trace_nop_print;
90846+ *(void **)&event->funcs->hex = trace_nop_print;
90847 if (event->funcs->binary == NULL)
90848- event->funcs->binary = trace_nop_print;
90849+ *(void **)&event->funcs->binary = trace_nop_print;
90850+ pax_close_kernel();
90851
90852 key = event->type & (EVENT_HASHSIZE - 1);
90853
90854diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90855index e6be585..d73ae5e 100644
90856--- a/kernel/trace/trace_stack.c
90857+++ b/kernel/trace/trace_stack.c
90858@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90859 return;
90860
90861 /* we do not handle interrupt stacks yet */
90862- if (!object_is_on_stack(stack))
90863+ if (!object_starts_on_stack(stack))
90864 return;
90865
90866 local_irq_save(flags);
90867diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90868index 80a57af..7f5a7ff 100644
90869--- a/kernel/user_namespace.c
90870+++ b/kernel/user_namespace.c
90871@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90872 !kgid_has_mapping(parent_ns, group))
90873 return -EPERM;
90874
90875+#ifdef CONFIG_GRKERNSEC
90876+ /*
90877+ * This doesn't really inspire confidence:
90878+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90879+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90880+ * Increases kernel attack surface in areas developers
90881+ * previously cared little about ("low importance due
90882+ * to requiring "root" capability")
90883+ * To be removed when this code receives *proper* review
90884+ */
90885+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90886+ !capable(CAP_SETGID))
90887+ return -EPERM;
90888+#endif
90889+
90890 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90891 if (!ns)
90892 return -ENOMEM;
90893@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90894 if (atomic_read(&current->mm->mm_users) > 1)
90895 return -EINVAL;
90896
90897- if (current->fs->users != 1)
90898+ if (atomic_read(&current->fs->users) != 1)
90899 return -EINVAL;
90900
90901 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90902diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90903index 4f69f9a..7c6f8f8 100644
90904--- a/kernel/utsname_sysctl.c
90905+++ b/kernel/utsname_sysctl.c
90906@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90907 static int proc_do_uts_string(ctl_table *table, int write,
90908 void __user *buffer, size_t *lenp, loff_t *ppos)
90909 {
90910- struct ctl_table uts_table;
90911+ ctl_table_no_const uts_table;
90912 int r;
90913 memcpy(&uts_table, table, sizeof(uts_table));
90914 uts_table.data = get_uts(table, write);
90915diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90916index 4431610..4265616 100644
90917--- a/kernel/watchdog.c
90918+++ b/kernel/watchdog.c
90919@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90920 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90921 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90922
90923-static struct smp_hotplug_thread watchdog_threads = {
90924+static struct smp_hotplug_thread watchdog_threads __read_only = {
90925 .store = &softlockup_watchdog,
90926 .thread_should_run = watchdog_should_run,
90927 .thread_fn = watchdog,
90928diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90929index 193e977..26dd63f 100644
90930--- a/kernel/workqueue.c
90931+++ b/kernel/workqueue.c
90932@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90933 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90934 worker_flags |= WORKER_REBOUND;
90935 worker_flags &= ~WORKER_UNBOUND;
90936- ACCESS_ONCE(worker->flags) = worker_flags;
90937+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
90938 }
90939
90940 spin_unlock_irq(&pool->lock);
90941diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90942index a48abea..e108def 100644
90943--- a/lib/Kconfig.debug
90944+++ b/lib/Kconfig.debug
90945@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
90946
90947 config DEBUG_WW_MUTEX_SLOWPATH
90948 bool "Wait/wound mutex debugging: Slowpath testing"
90949- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90950+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90951 select DEBUG_LOCK_ALLOC
90952 select DEBUG_SPINLOCK
90953 select DEBUG_MUTEXES
90954@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90955
90956 config DEBUG_LOCK_ALLOC
90957 bool "Lock debugging: detect incorrect freeing of live locks"
90958- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90959+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90960 select DEBUG_SPINLOCK
90961 select DEBUG_MUTEXES
90962 select LOCKDEP
90963@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
90964
90965 config PROVE_LOCKING
90966 bool "Lock debugging: prove locking correctness"
90967- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90968+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90969 select LOCKDEP
90970 select DEBUG_SPINLOCK
90971 select DEBUG_MUTEXES
90972@@ -932,7 +932,7 @@ config LOCKDEP
90973
90974 config LOCK_STAT
90975 bool "Lock usage statistics"
90976- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90977+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90978 select LOCKDEP
90979 select DEBUG_SPINLOCK
90980 select DEBUG_MUTEXES
90981@@ -1394,6 +1394,7 @@ config LATENCYTOP
90982 depends on DEBUG_KERNEL
90983 depends on STACKTRACE_SUPPORT
90984 depends on PROC_FS
90985+ depends on !GRKERNSEC_HIDESYM
90986 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90987 select KALLSYMS
90988 select KALLSYMS_ALL
90989@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90990 config DEBUG_STRICT_USER_COPY_CHECKS
90991 bool "Strict user copy size checks"
90992 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90993- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90994+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90995 help
90996 Enabling this option turns a certain set of sanity checks for user
90997 copy operations into compile time failures.
90998@@ -1529,7 +1530,7 @@ endmenu # runtime tests
90999
91000 config PROVIDE_OHCI1394_DMA_INIT
91001 bool "Remote debugging over FireWire early on boot"
91002- depends on PCI && X86
91003+ depends on PCI && X86 && !GRKERNSEC
91004 help
91005 If you want to debug problems which hang or crash the kernel early
91006 on boot and the crashing machine has a FireWire port, you can use
91007diff --git a/lib/Makefile b/lib/Makefile
91008index 48140e3..de854e5 100644
91009--- a/lib/Makefile
91010+++ b/lib/Makefile
91011@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91012 obj-$(CONFIG_BTREE) += btree.o
91013 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91014 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91015-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91016+obj-y += list_debug.o
91017 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91018
91019 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91020diff --git a/lib/average.c b/lib/average.c
91021index 114d1be..ab0350c 100644
91022--- a/lib/average.c
91023+++ b/lib/average.c
91024@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91025 {
91026 unsigned long internal = ACCESS_ONCE(avg->internal);
91027
91028- ACCESS_ONCE(avg->internal) = internal ?
91029+ ACCESS_ONCE_RW(avg->internal) = internal ?
91030 (((internal << avg->weight) - internal) +
91031 (val << avg->factor)) >> avg->weight :
91032 (val << avg->factor);
91033diff --git a/lib/bitmap.c b/lib/bitmap.c
91034index 06f7e4f..f3cf2b0 100644
91035--- a/lib/bitmap.c
91036+++ b/lib/bitmap.c
91037@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91038 {
91039 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91040 u32 chunk;
91041- const char __user __force *ubuf = (const char __user __force *)buf;
91042+ const char __user *ubuf = (const char __force_user *)buf;
91043
91044 bitmap_zero(maskp, nmaskbits);
91045
91046@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91047 {
91048 if (!access_ok(VERIFY_READ, ubuf, ulen))
91049 return -EFAULT;
91050- return __bitmap_parse((const char __force *)ubuf,
91051+ return __bitmap_parse((const char __force_kernel *)ubuf,
91052 ulen, 1, maskp, nmaskbits);
91053
91054 }
91055@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91056 {
91057 unsigned a, b;
91058 int c, old_c, totaldigits;
91059- const char __user __force *ubuf = (const char __user __force *)buf;
91060+ const char __user *ubuf = (const char __force_user *)buf;
91061 int exp_digit, in_range;
91062
91063 totaldigits = c = 0;
91064@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91065 {
91066 if (!access_ok(VERIFY_READ, ubuf, ulen))
91067 return -EFAULT;
91068- return __bitmap_parselist((const char __force *)ubuf,
91069+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91070 ulen, 1, maskp, nmaskbits);
91071 }
91072 EXPORT_SYMBOL(bitmap_parselist_user);
91073diff --git a/lib/bug.c b/lib/bug.c
91074index 1686034..a9c00c8 100644
91075--- a/lib/bug.c
91076+++ b/lib/bug.c
91077@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91078 return BUG_TRAP_TYPE_NONE;
91079
91080 bug = find_bug(bugaddr);
91081+ if (!bug)
91082+ return BUG_TRAP_TYPE_NONE;
91083
91084 file = NULL;
91085 line = 0;
91086diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91087index e0731c3..ad66444 100644
91088--- a/lib/debugobjects.c
91089+++ b/lib/debugobjects.c
91090@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91091 if (limit > 4)
91092 return;
91093
91094- is_on_stack = object_is_on_stack(addr);
91095+ is_on_stack = object_starts_on_stack(addr);
91096 if (is_on_stack == onstack)
91097 return;
91098
91099diff --git a/lib/devres.c b/lib/devres.c
91100index 8235331..5881053 100644
91101--- a/lib/devres.c
91102+++ b/lib/devres.c
91103@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91104 void devm_iounmap(struct device *dev, void __iomem *addr)
91105 {
91106 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91107- (void *)addr));
91108+ (void __force *)addr));
91109 iounmap(addr);
91110 }
91111 EXPORT_SYMBOL(devm_iounmap);
91112@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91113 {
91114 ioport_unmap(addr);
91115 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91116- devm_ioport_map_match, (void *)addr));
91117+ devm_ioport_map_match, (void __force *)addr));
91118 }
91119 EXPORT_SYMBOL(devm_ioport_unmap);
91120 #endif /* CONFIG_HAS_IOPORT */
91121diff --git a/lib/div64.c b/lib/div64.c
91122index 4382ad7..08aa558 100644
91123--- a/lib/div64.c
91124+++ b/lib/div64.c
91125@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91126 EXPORT_SYMBOL(__div64_32);
91127
91128 #ifndef div_s64_rem
91129-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91130+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91131 {
91132 u64 quotient;
91133
91134@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91135 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91136 */
91137 #ifndef div64_u64
91138-u64 div64_u64(u64 dividend, u64 divisor)
91139+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91140 {
91141 u32 high = divisor >> 32;
91142 u64 quot;
91143diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91144index 98f2d7e..899da5c 100644
91145--- a/lib/dma-debug.c
91146+++ b/lib/dma-debug.c
91147@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91148
91149 void dma_debug_add_bus(struct bus_type *bus)
91150 {
91151- struct notifier_block *nb;
91152+ notifier_block_no_const *nb;
91153
91154 if (global_disable)
91155 return;
91156@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91157
91158 static void check_for_stack(struct device *dev, void *addr)
91159 {
91160- if (object_is_on_stack(addr))
91161+ if (object_starts_on_stack(addr))
91162 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91163 "stack [addr=%p]\n", addr);
91164 }
91165diff --git a/lib/hash.c b/lib/hash.c
91166index fea973f..386626f 100644
91167--- a/lib/hash.c
91168+++ b/lib/hash.c
91169@@ -14,7 +14,7 @@
91170 #include <linux/hash.h>
91171 #include <linux/cache.h>
91172
91173-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91174+static struct fast_hash_ops arch_hash_ops __read_only = {
91175 .hash = jhash,
91176 .hash2 = jhash2,
91177 };
91178diff --git a/lib/inflate.c b/lib/inflate.c
91179index 013a761..c28f3fc 100644
91180--- a/lib/inflate.c
91181+++ b/lib/inflate.c
91182@@ -269,7 +269,7 @@ static void free(void *where)
91183 malloc_ptr = free_mem_ptr;
91184 }
91185 #else
91186-#define malloc(a) kmalloc(a, GFP_KERNEL)
91187+#define malloc(a) kmalloc((a), GFP_KERNEL)
91188 #define free(a) kfree(a)
91189 #endif
91190
91191diff --git a/lib/ioremap.c b/lib/ioremap.c
91192index 0c9216c..863bd89 100644
91193--- a/lib/ioremap.c
91194+++ b/lib/ioremap.c
91195@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91196 unsigned long next;
91197
91198 phys_addr -= addr;
91199- pmd = pmd_alloc(&init_mm, pud, addr);
91200+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91201 if (!pmd)
91202 return -ENOMEM;
91203 do {
91204@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91205 unsigned long next;
91206
91207 phys_addr -= addr;
91208- pud = pud_alloc(&init_mm, pgd, addr);
91209+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91210 if (!pud)
91211 return -ENOMEM;
91212 do {
91213diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91214index bd2bea9..6b3c95e 100644
91215--- a/lib/is_single_threaded.c
91216+++ b/lib/is_single_threaded.c
91217@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91218 struct task_struct *p, *t;
91219 bool ret;
91220
91221+ if (!mm)
91222+ return true;
91223+
91224 if (atomic_read(&task->signal->live) != 1)
91225 return false;
91226
91227diff --git a/lib/kobject.c b/lib/kobject.c
91228index cb14aea..8c53cdb 100644
91229--- a/lib/kobject.c
91230+++ b/lib/kobject.c
91231@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91232
91233
91234 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91235-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91236+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91237
91238-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91239+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91240 {
91241 enum kobj_ns_type type = ops->type;
91242 int error;
91243diff --git a/lib/list_debug.c b/lib/list_debug.c
91244index c24c2f7..f0296f4 100644
91245--- a/lib/list_debug.c
91246+++ b/lib/list_debug.c
91247@@ -11,7 +11,9 @@
91248 #include <linux/bug.h>
91249 #include <linux/kernel.h>
91250 #include <linux/rculist.h>
91251+#include <linux/mm.h>
91252
91253+#ifdef CONFIG_DEBUG_LIST
91254 /*
91255 * Insert a new entry between two known consecutive entries.
91256 *
91257@@ -19,21 +21,40 @@
91258 * the prev/next entries already!
91259 */
91260
91261+static bool __list_add_debug(struct list_head *new,
91262+ struct list_head *prev,
91263+ struct list_head *next)
91264+{
91265+ if (unlikely(next->prev != prev)) {
91266+ printk(KERN_ERR "list_add corruption. next->prev should be "
91267+ "prev (%p), but was %p. (next=%p).\n",
91268+ prev, next->prev, next);
91269+ BUG();
91270+ return false;
91271+ }
91272+ if (unlikely(prev->next != next)) {
91273+ printk(KERN_ERR "list_add corruption. prev->next should be "
91274+ "next (%p), but was %p. (prev=%p).\n",
91275+ next, prev->next, prev);
91276+ BUG();
91277+ return false;
91278+ }
91279+ if (unlikely(new == prev || new == next)) {
91280+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91281+ new, prev, next);
91282+ BUG();
91283+ return false;
91284+ }
91285+ return true;
91286+}
91287+
91288 void __list_add(struct list_head *new,
91289- struct list_head *prev,
91290- struct list_head *next)
91291+ struct list_head *prev,
91292+ struct list_head *next)
91293 {
91294- WARN(next->prev != prev,
91295- "list_add corruption. next->prev should be "
91296- "prev (%p), but was %p. (next=%p).\n",
91297- prev, next->prev, next);
91298- WARN(prev->next != next,
91299- "list_add corruption. prev->next should be "
91300- "next (%p), but was %p. (prev=%p).\n",
91301- next, prev->next, prev);
91302- WARN(new == prev || new == next,
91303- "list_add double add: new=%p, prev=%p, next=%p.\n",
91304- new, prev, next);
91305+ if (!__list_add_debug(new, prev, next))
91306+ return;
91307+
91308 next->prev = new;
91309 new->next = next;
91310 new->prev = prev;
91311@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91312 }
91313 EXPORT_SYMBOL(__list_add);
91314
91315-void __list_del_entry(struct list_head *entry)
91316+static bool __list_del_entry_debug(struct list_head *entry)
91317 {
91318 struct list_head *prev, *next;
91319
91320 prev = entry->prev;
91321 next = entry->next;
91322
91323- if (WARN(next == LIST_POISON1,
91324- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91325- entry, LIST_POISON1) ||
91326- WARN(prev == LIST_POISON2,
91327- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91328- entry, LIST_POISON2) ||
91329- WARN(prev->next != entry,
91330- "list_del corruption. prev->next should be %p, "
91331- "but was %p\n", entry, prev->next) ||
91332- WARN(next->prev != entry,
91333- "list_del corruption. next->prev should be %p, "
91334- "but was %p\n", entry, next->prev))
91335+ if (unlikely(next == LIST_POISON1)) {
91336+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91337+ entry, LIST_POISON1);
91338+ BUG();
91339+ return false;
91340+ }
91341+ if (unlikely(prev == LIST_POISON2)) {
91342+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91343+ entry, LIST_POISON2);
91344+ BUG();
91345+ return false;
91346+ }
91347+ if (unlikely(entry->prev->next != entry)) {
91348+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91349+ "but was %p\n", entry, prev->next);
91350+ BUG();
91351+ return false;
91352+ }
91353+ if (unlikely(entry->next->prev != entry)) {
91354+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91355+ "but was %p\n", entry, next->prev);
91356+ BUG();
91357+ return false;
91358+ }
91359+ return true;
91360+}
91361+
91362+void __list_del_entry(struct list_head *entry)
91363+{
91364+ if (!__list_del_entry_debug(entry))
91365 return;
91366
91367- __list_del(prev, next);
91368+ __list_del(entry->prev, entry->next);
91369 }
91370 EXPORT_SYMBOL(__list_del_entry);
91371
91372@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91373 void __list_add_rcu(struct list_head *new,
91374 struct list_head *prev, struct list_head *next)
91375 {
91376- WARN(next->prev != prev,
91377- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91378- prev, next->prev, next);
91379- WARN(prev->next != next,
91380- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91381- next, prev->next, prev);
91382+ if (!__list_add_debug(new, prev, next))
91383+ return;
91384+
91385 new->next = next;
91386 new->prev = prev;
91387 rcu_assign_pointer(list_next_rcu(prev), new);
91388 next->prev = new;
91389 }
91390 EXPORT_SYMBOL(__list_add_rcu);
91391+#endif
91392+
91393+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91394+{
91395+#ifdef CONFIG_DEBUG_LIST
91396+ if (!__list_add_debug(new, prev, next))
91397+ return;
91398+#endif
91399+
91400+ pax_open_kernel();
91401+ next->prev = new;
91402+ new->next = next;
91403+ new->prev = prev;
91404+ prev->next = new;
91405+ pax_close_kernel();
91406+}
91407+EXPORT_SYMBOL(__pax_list_add);
91408+
91409+void pax_list_del(struct list_head *entry)
91410+{
91411+#ifdef CONFIG_DEBUG_LIST
91412+ if (!__list_del_entry_debug(entry))
91413+ return;
91414+#endif
91415+
91416+ pax_open_kernel();
91417+ __list_del(entry->prev, entry->next);
91418+ entry->next = LIST_POISON1;
91419+ entry->prev = LIST_POISON2;
91420+ pax_close_kernel();
91421+}
91422+EXPORT_SYMBOL(pax_list_del);
91423+
91424+void pax_list_del_init(struct list_head *entry)
91425+{
91426+ pax_open_kernel();
91427+ __list_del(entry->prev, entry->next);
91428+ INIT_LIST_HEAD(entry);
91429+ pax_close_kernel();
91430+}
91431+EXPORT_SYMBOL(pax_list_del_init);
91432+
91433+void __pax_list_add_rcu(struct list_head *new,
91434+ struct list_head *prev, struct list_head *next)
91435+{
91436+#ifdef CONFIG_DEBUG_LIST
91437+ if (!__list_add_debug(new, prev, next))
91438+ return;
91439+#endif
91440+
91441+ pax_open_kernel();
91442+ new->next = next;
91443+ new->prev = prev;
91444+ rcu_assign_pointer(list_next_rcu(prev), new);
91445+ next->prev = new;
91446+ pax_close_kernel();
91447+}
91448+EXPORT_SYMBOL(__pax_list_add_rcu);
91449+
91450+void pax_list_del_rcu(struct list_head *entry)
91451+{
91452+#ifdef CONFIG_DEBUG_LIST
91453+ if (!__list_del_entry_debug(entry))
91454+ return;
91455+#endif
91456+
91457+ pax_open_kernel();
91458+ __list_del(entry->prev, entry->next);
91459+ entry->next = LIST_POISON1;
91460+ entry->prev = LIST_POISON2;
91461+ pax_close_kernel();
91462+}
91463+EXPORT_SYMBOL(pax_list_del_rcu);
91464diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91465index 963b703..438bc51 100644
91466--- a/lib/percpu-refcount.c
91467+++ b/lib/percpu-refcount.c
91468@@ -29,7 +29,7 @@
91469 * can't hit 0 before we've added up all the percpu refs.
91470 */
91471
91472-#define PCPU_COUNT_BIAS (1U << 31)
91473+#define PCPU_COUNT_BIAS (1U << 30)
91474
91475 /**
91476 * percpu_ref_init - initialize a percpu refcount
91477diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91478index bd4a8df..9e4804f 100644
91479--- a/lib/radix-tree.c
91480+++ b/lib/radix-tree.c
91481@@ -93,7 +93,7 @@ struct radix_tree_preload {
91482 int nr;
91483 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91484 };
91485-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91486+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91487
91488 static inline void *ptr_to_indirect(void *ptr)
91489 {
91490diff --git a/lib/random32.c b/lib/random32.c
91491index 6148967..009bfe8 100644
91492--- a/lib/random32.c
91493+++ b/lib/random32.c
91494@@ -44,7 +44,7 @@
91495 static void __init prandom_state_selftest(void);
91496 #endif
91497
91498-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91499+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91500
91501 /**
91502 * prandom_u32_state - seeded pseudo-random number generator.
91503diff --git a/lib/rbtree.c b/lib/rbtree.c
91504index 65f4eff..2cfa167 100644
91505--- a/lib/rbtree.c
91506+++ b/lib/rbtree.c
91507@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91508 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91509
91510 static const struct rb_augment_callbacks dummy_callbacks = {
91511- dummy_propagate, dummy_copy, dummy_rotate
91512+ .propagate = dummy_propagate,
91513+ .copy = dummy_copy,
91514+ .rotate = dummy_rotate
91515 };
91516
91517 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91518diff --git a/lib/show_mem.c b/lib/show_mem.c
91519index 0922579..9d7adb9 100644
91520--- a/lib/show_mem.c
91521+++ b/lib/show_mem.c
91522@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91523 quicklist_total_size());
91524 #endif
91525 #ifdef CONFIG_MEMORY_FAILURE
91526- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91527+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91528 #endif
91529 }
91530diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91531index bb2b201..46abaf9 100644
91532--- a/lib/strncpy_from_user.c
91533+++ b/lib/strncpy_from_user.c
91534@@ -21,7 +21,7 @@
91535 */
91536 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91537 {
91538- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91539+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91540 long res = 0;
91541
91542 /*
91543diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91544index a28df52..3d55877 100644
91545--- a/lib/strnlen_user.c
91546+++ b/lib/strnlen_user.c
91547@@ -26,7 +26,7 @@
91548 */
91549 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91550 {
91551- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91552+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91553 long align, res = 0;
91554 unsigned long c;
91555
91556diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91557index b604b83..c0547f6 100644
91558--- a/lib/swiotlb.c
91559+++ b/lib/swiotlb.c
91560@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91561
91562 void
91563 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91564- dma_addr_t dev_addr)
91565+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91566 {
91567 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91568
91569diff --git a/lib/usercopy.c b/lib/usercopy.c
91570index 4f5b1dd..7cab418 100644
91571--- a/lib/usercopy.c
91572+++ b/lib/usercopy.c
91573@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91574 WARN(1, "Buffer overflow detected!\n");
91575 }
91576 EXPORT_SYMBOL(copy_from_user_overflow);
91577+
91578+void copy_to_user_overflow(void)
91579+{
91580+ WARN(1, "Buffer overflow detected!\n");
91581+}
91582+EXPORT_SYMBOL(copy_to_user_overflow);
91583diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91584index 185b6d3..823c48c 100644
91585--- a/lib/vsprintf.c
91586+++ b/lib/vsprintf.c
91587@@ -16,6 +16,9 @@
91588 * - scnprintf and vscnprintf
91589 */
91590
91591+#ifdef CONFIG_GRKERNSEC_HIDESYM
91592+#define __INCLUDED_BY_HIDESYM 1
91593+#endif
91594 #include <stdarg.h>
91595 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91596 #include <linux/types.h>
91597@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91598 return number(buf, end, num, spec);
91599 }
91600
91601+#ifdef CONFIG_GRKERNSEC_HIDESYM
91602+int kptr_restrict __read_mostly = 2;
91603+#else
91604 int kptr_restrict __read_mostly;
91605+#endif
91606
91607 /*
91608 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91609@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91610 * - 'f' For simple symbolic function names without offset
91611 * - 'S' For symbolic direct pointers with offset
91612 * - 's' For symbolic direct pointers without offset
91613+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91614 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91615 * - 'B' For backtraced symbolic direct pointers with offset
91616 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91617@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91618
91619 if (!ptr && *fmt != 'K') {
91620 /*
91621- * Print (null) with the same width as a pointer so it makes
91622+ * Print (nil) with the same width as a pointer so it makes
91623 * tabular output look nice.
91624 */
91625 if (spec.field_width == -1)
91626 spec.field_width = default_width;
91627- return string(buf, end, "(null)", spec);
91628+ return string(buf, end, "(nil)", spec);
91629 }
91630
91631 switch (*fmt) {
91632@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91633 /* Fallthrough */
91634 case 'S':
91635 case 's':
91636+#ifdef CONFIG_GRKERNSEC_HIDESYM
91637+ break;
91638+#else
91639+ return symbol_string(buf, end, ptr, spec, fmt);
91640+#endif
91641+ case 'A':
91642 case 'B':
91643 return symbol_string(buf, end, ptr, spec, fmt);
91644 case 'R':
91645@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91646 va_end(va);
91647 return buf;
91648 }
91649+ case 'P':
91650+ break;
91651 case 'K':
91652 /*
91653 * %pK cannot be used in IRQ context because its test
91654@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91655 ((const struct file *)ptr)->f_path.dentry,
91656 spec, fmt);
91657 }
91658+
91659+#ifdef CONFIG_GRKERNSEC_HIDESYM
91660+ /* 'P' = approved pointers to copy to userland,
91661+ as in the /proc/kallsyms case, as we make it display nothing
91662+ for non-root users, and the real contents for root users
91663+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91664+ above
91665+ */
91666+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91667+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91668+ dump_stack();
91669+ ptr = NULL;
91670+ }
91671+#endif
91672+
91673 spec.flags |= SMALL;
91674 if (spec.field_width == -1) {
91675 spec.field_width = default_width;
91676@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91677 typeof(type) value; \
91678 if (sizeof(type) == 8) { \
91679 args = PTR_ALIGN(args, sizeof(u32)); \
91680- *(u32 *)&value = *(u32 *)args; \
91681- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91682+ *(u32 *)&value = *(const u32 *)args; \
91683+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91684 } else { \
91685 args = PTR_ALIGN(args, sizeof(type)); \
91686- value = *(typeof(type) *)args; \
91687+ value = *(const typeof(type) *)args; \
91688 } \
91689 args += sizeof(type); \
91690 value; \
91691@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91692 case FORMAT_TYPE_STR: {
91693 const char *str_arg = args;
91694 args += strlen(str_arg) + 1;
91695- str = string(str, end, (char *)str_arg, spec);
91696+ str = string(str, end, str_arg, spec);
91697 break;
91698 }
91699
91700diff --git a/localversion-grsec b/localversion-grsec
91701new file mode 100644
91702index 0000000..7cd6065
91703--- /dev/null
91704+++ b/localversion-grsec
91705@@ -0,0 +1 @@
91706+-grsec
91707diff --git a/mm/Kconfig b/mm/Kconfig
91708index 2888024..c15a810 100644
91709--- a/mm/Kconfig
91710+++ b/mm/Kconfig
91711@@ -326,10 +326,11 @@ config KSM
91712 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91713
91714 config DEFAULT_MMAP_MIN_ADDR
91715- int "Low address space to protect from user allocation"
91716+ int "Low address space to protect from user allocation"
91717 depends on MMU
91718- default 4096
91719- help
91720+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91721+ default 65536
91722+ help
91723 This is the portion of low virtual memory which should be protected
91724 from userspace allocation. Keeping a user from writing to low pages
91725 can help reduce the impact of kernel NULL pointer bugs.
91726@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91727
91728 config HWPOISON_INJECT
91729 tristate "HWPoison pages injector"
91730- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91731+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91732 select PROC_PAGE_MONITOR
91733
91734 config NOMMU_INITIAL_TRIM_EXCESS
91735diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91736index 09d9591..165bb75 100644
91737--- a/mm/backing-dev.c
91738+++ b/mm/backing-dev.c
91739@@ -12,7 +12,7 @@
91740 #include <linux/device.h>
91741 #include <trace/events/writeback.h>
91742
91743-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91744+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91745
91746 struct backing_dev_info default_backing_dev_info = {
91747 .name = "default",
91748@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91749 return err;
91750
91751 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91752- atomic_long_inc_return(&bdi_seq));
91753+ atomic_long_inc_return_unchecked(&bdi_seq));
91754 if (err) {
91755 bdi_destroy(bdi);
91756 return err;
91757diff --git a/mm/filemap.c b/mm/filemap.c
91758index 7a13f6a..e52e841 100644
91759--- a/mm/filemap.c
91760+++ b/mm/filemap.c
91761@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91762 struct address_space *mapping = file->f_mapping;
91763
91764 if (!mapping->a_ops->readpage)
91765- return -ENOEXEC;
91766+ return -ENODEV;
91767 file_accessed(file);
91768 vma->vm_ops = &generic_file_vm_ops;
91769 return 0;
91770@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91771
91772 while (bytes) {
91773 char __user *buf = iov->iov_base + base;
91774- int copy = min(bytes, iov->iov_len - base);
91775+ size_t copy = min(bytes, iov->iov_len - base);
91776
91777 base = 0;
91778 left = __copy_from_user_inatomic(vaddr, buf, copy);
91779@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91780 BUG_ON(!in_atomic());
91781 kaddr = kmap_atomic(page);
91782 if (likely(i->nr_segs == 1)) {
91783- int left;
91784+ size_t left;
91785 char __user *buf = i->iov->iov_base + i->iov_offset;
91786 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91787 copied = bytes - left;
91788@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91789
91790 kaddr = kmap(page);
91791 if (likely(i->nr_segs == 1)) {
91792- int left;
91793+ size_t left;
91794 char __user *buf = i->iov->iov_base + i->iov_offset;
91795 left = __copy_from_user(kaddr + offset, buf, bytes);
91796 copied = bytes - left;
91797@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91798 * zero-length segments (without overruning the iovec).
91799 */
91800 while (bytes || unlikely(i->count && !iov->iov_len)) {
91801- int copy;
91802+ size_t copy;
91803
91804 copy = min(bytes, iov->iov_len - base);
91805 BUG_ON(!i->count || i->count < copy);
91806@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91807 *pos = i_size_read(inode);
91808
91809 if (limit != RLIM_INFINITY) {
91810+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91811 if (*pos >= limit) {
91812 send_sig(SIGXFSZ, current, 0);
91813 return -EFBIG;
91814diff --git a/mm/fremap.c b/mm/fremap.c
91815index 34feba6..315fe78 100644
91816--- a/mm/fremap.c
91817+++ b/mm/fremap.c
91818@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91819 retry:
91820 vma = find_vma(mm, start);
91821
91822+#ifdef CONFIG_PAX_SEGMEXEC
91823+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91824+ goto out;
91825+#endif
91826+
91827 /*
91828 * Make sure the vma is shared, that it supports prefaulting,
91829 * and that the remapped range is valid and fully within
91830diff --git a/mm/highmem.c b/mm/highmem.c
91831index b32b70c..e512eb0 100644
91832--- a/mm/highmem.c
91833+++ b/mm/highmem.c
91834@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91835 * So no dangers, even with speculative execution.
91836 */
91837 page = pte_page(pkmap_page_table[i]);
91838+ pax_open_kernel();
91839 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91840-
91841+ pax_close_kernel();
91842 set_page_address(page, NULL);
91843 need_flush = 1;
91844 }
91845@@ -198,9 +199,11 @@ start:
91846 }
91847 }
91848 vaddr = PKMAP_ADDR(last_pkmap_nr);
91849+
91850+ pax_open_kernel();
91851 set_pte_at(&init_mm, vaddr,
91852 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91853-
91854+ pax_close_kernel();
91855 pkmap_count[last_pkmap_nr] = 1;
91856 set_page_address(page, (void *)vaddr);
91857
91858diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91859index 2de3c84..4ecaf1b 100644
91860--- a/mm/hugetlb.c
91861+++ b/mm/hugetlb.c
91862@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91863 struct hstate *h = &default_hstate;
91864 unsigned long tmp;
91865 int ret;
91866+ ctl_table_no_const hugetlb_table;
91867
91868 tmp = h->max_huge_pages;
91869
91870 if (write && h->order >= MAX_ORDER)
91871 return -EINVAL;
91872
91873- table->data = &tmp;
91874- table->maxlen = sizeof(unsigned long);
91875- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91876+ hugetlb_table = *table;
91877+ hugetlb_table.data = &tmp;
91878+ hugetlb_table.maxlen = sizeof(unsigned long);
91879+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91880 if (ret)
91881 goto out;
91882
91883@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91884 struct hstate *h = &default_hstate;
91885 unsigned long tmp;
91886 int ret;
91887+ ctl_table_no_const hugetlb_table;
91888
91889 tmp = h->nr_overcommit_huge_pages;
91890
91891 if (write && h->order >= MAX_ORDER)
91892 return -EINVAL;
91893
91894- table->data = &tmp;
91895- table->maxlen = sizeof(unsigned long);
91896- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91897+ hugetlb_table = *table;
91898+ hugetlb_table.data = &tmp;
91899+ hugetlb_table.maxlen = sizeof(unsigned long);
91900+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91901 if (ret)
91902 goto out;
91903
91904@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91905 return 1;
91906 }
91907
91908+#ifdef CONFIG_PAX_SEGMEXEC
91909+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91910+{
91911+ struct mm_struct *mm = vma->vm_mm;
91912+ struct vm_area_struct *vma_m;
91913+ unsigned long address_m;
91914+ pte_t *ptep_m;
91915+
91916+ vma_m = pax_find_mirror_vma(vma);
91917+ if (!vma_m)
91918+ return;
91919+
91920+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91921+ address_m = address + SEGMEXEC_TASK_SIZE;
91922+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91923+ get_page(page_m);
91924+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
91925+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91926+}
91927+#endif
91928+
91929 /*
91930 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91931 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91932@@ -2715,6 +2740,11 @@ retry_avoidcopy:
91933 make_huge_pte(vma, new_page, 1));
91934 page_remove_rmap(old_page);
91935 hugepage_add_new_anon_rmap(new_page, vma, address);
91936+
91937+#ifdef CONFIG_PAX_SEGMEXEC
91938+ pax_mirror_huge_pte(vma, address, new_page);
91939+#endif
91940+
91941 /* Make the old page be freed below */
91942 new_page = old_page;
91943 }
91944@@ -2879,6 +2909,10 @@ retry:
91945 && (vma->vm_flags & VM_SHARED)));
91946 set_huge_pte_at(mm, address, ptep, new_pte);
91947
91948+#ifdef CONFIG_PAX_SEGMEXEC
91949+ pax_mirror_huge_pte(vma, address, page);
91950+#endif
91951+
91952 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91953 /* Optimization, do the COW without a second fault */
91954 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91955@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91956 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91957 struct hstate *h = hstate_vma(vma);
91958
91959+#ifdef CONFIG_PAX_SEGMEXEC
91960+ struct vm_area_struct *vma_m;
91961+#endif
91962+
91963 address &= huge_page_mask(h);
91964
91965 ptep = huge_pte_offset(mm, address);
91966@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91967 VM_FAULT_SET_HINDEX(hstate_index(h));
91968 }
91969
91970+#ifdef CONFIG_PAX_SEGMEXEC
91971+ vma_m = pax_find_mirror_vma(vma);
91972+ if (vma_m) {
91973+ unsigned long address_m;
91974+
91975+ if (vma->vm_start > vma_m->vm_start) {
91976+ address_m = address;
91977+ address -= SEGMEXEC_TASK_SIZE;
91978+ vma = vma_m;
91979+ h = hstate_vma(vma);
91980+ } else
91981+ address_m = address + SEGMEXEC_TASK_SIZE;
91982+
91983+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91984+ return VM_FAULT_OOM;
91985+ address_m &= HPAGE_MASK;
91986+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91987+ }
91988+#endif
91989+
91990 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91991 if (!ptep)
91992 return VM_FAULT_OOM;
91993diff --git a/mm/internal.h b/mm/internal.h
91994index 3e91000..4741a60 100644
91995--- a/mm/internal.h
91996+++ b/mm/internal.h
91997@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91998 * in mm/page_alloc.c
91999 */
92000 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92001+extern void free_compound_page(struct page *page);
92002 extern void prep_compound_page(struct page *page, unsigned long order);
92003 #ifdef CONFIG_MEMORY_FAILURE
92004 extern bool is_free_buddy_page(struct page *page);
92005@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92006
92007 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92008 unsigned long, unsigned long,
92009- unsigned long, unsigned long);
92010+ unsigned long, unsigned long) __intentional_overflow(-1);
92011
92012 extern void set_pageblock_order(void);
92013 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92014diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92015index 31f01c5..7015178 100644
92016--- a/mm/kmemleak.c
92017+++ b/mm/kmemleak.c
92018@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92019
92020 for (i = 0; i < object->trace_len; i++) {
92021 void *ptr = (void *)object->trace[i];
92022- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92023+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92024 }
92025 }
92026
92027@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92028 return -ENOMEM;
92029 }
92030
92031- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92032+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92033 &kmemleak_fops);
92034 if (!dentry)
92035 pr_warning("Failed to create the debugfs kmemleak file\n");
92036diff --git a/mm/maccess.c b/mm/maccess.c
92037index d53adf9..03a24bf 100644
92038--- a/mm/maccess.c
92039+++ b/mm/maccess.c
92040@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92041 set_fs(KERNEL_DS);
92042 pagefault_disable();
92043 ret = __copy_from_user_inatomic(dst,
92044- (__force const void __user *)src, size);
92045+ (const void __force_user *)src, size);
92046 pagefault_enable();
92047 set_fs(old_fs);
92048
92049@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92050
92051 set_fs(KERNEL_DS);
92052 pagefault_disable();
92053- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92054+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92055 pagefault_enable();
92056 set_fs(old_fs);
92057
92058diff --git a/mm/madvise.c b/mm/madvise.c
92059index 539eeb9..e24a987 100644
92060--- a/mm/madvise.c
92061+++ b/mm/madvise.c
92062@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92063 pgoff_t pgoff;
92064 unsigned long new_flags = vma->vm_flags;
92065
92066+#ifdef CONFIG_PAX_SEGMEXEC
92067+ struct vm_area_struct *vma_m;
92068+#endif
92069+
92070 switch (behavior) {
92071 case MADV_NORMAL:
92072 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92073@@ -126,6 +130,13 @@ success:
92074 /*
92075 * vm_flags is protected by the mmap_sem held in write mode.
92076 */
92077+
92078+#ifdef CONFIG_PAX_SEGMEXEC
92079+ vma_m = pax_find_mirror_vma(vma);
92080+ if (vma_m)
92081+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92082+#endif
92083+
92084 vma->vm_flags = new_flags;
92085
92086 out:
92087@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92088 struct vm_area_struct **prev,
92089 unsigned long start, unsigned long end)
92090 {
92091+
92092+#ifdef CONFIG_PAX_SEGMEXEC
92093+ struct vm_area_struct *vma_m;
92094+#endif
92095+
92096 *prev = vma;
92097 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92098 return -EINVAL;
92099@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92100 zap_page_range(vma, start, end - start, &details);
92101 } else
92102 zap_page_range(vma, start, end - start, NULL);
92103+
92104+#ifdef CONFIG_PAX_SEGMEXEC
92105+ vma_m = pax_find_mirror_vma(vma);
92106+ if (vma_m) {
92107+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92108+ struct zap_details details = {
92109+ .nonlinear_vma = vma_m,
92110+ .last_index = ULONG_MAX,
92111+ };
92112+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92113+ } else
92114+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92115+ }
92116+#endif
92117+
92118 return 0;
92119 }
92120
92121@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92122 if (end < start)
92123 return error;
92124
92125+#ifdef CONFIG_PAX_SEGMEXEC
92126+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92127+ if (end > SEGMEXEC_TASK_SIZE)
92128+ return error;
92129+ } else
92130+#endif
92131+
92132+ if (end > TASK_SIZE)
92133+ return error;
92134+
92135 error = 0;
92136 if (end == start)
92137 return error;
92138diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92139index 90002ea..db1452d 100644
92140--- a/mm/memory-failure.c
92141+++ b/mm/memory-failure.c
92142@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92143
92144 int sysctl_memory_failure_recovery __read_mostly = 1;
92145
92146-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92147+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92148
92149 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92150
92151@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92152 pfn, t->comm, t->pid);
92153 si.si_signo = SIGBUS;
92154 si.si_errno = 0;
92155- si.si_addr = (void *)addr;
92156+ si.si_addr = (void __user *)addr;
92157 #ifdef __ARCH_SI_TRAPNO
92158 si.si_trapno = trapno;
92159 #endif
92160@@ -762,7 +762,7 @@ static struct page_state {
92161 unsigned long res;
92162 char *msg;
92163 int (*action)(struct page *p, unsigned long pfn);
92164-} error_states[] = {
92165+} __do_const error_states[] = {
92166 { reserved, reserved, "reserved kernel", me_kernel },
92167 /*
92168 * free pages are specially detected outside this table:
92169@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92170 nr_pages = 1 << compound_order(hpage);
92171 else /* normal page or thp */
92172 nr_pages = 1;
92173- atomic_long_add(nr_pages, &num_poisoned_pages);
92174+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92175
92176 /*
92177 * We need/can do nothing about count=0 pages.
92178@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92179 if (!PageHWPoison(hpage)
92180 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92181 || (p != hpage && TestSetPageHWPoison(hpage))) {
92182- atomic_long_sub(nr_pages, &num_poisoned_pages);
92183+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92184 return 0;
92185 }
92186 set_page_hwpoison_huge_page(hpage);
92187@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92188 }
92189 if (hwpoison_filter(p)) {
92190 if (TestClearPageHWPoison(p))
92191- atomic_long_sub(nr_pages, &num_poisoned_pages);
92192+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92193 unlock_page(hpage);
92194 put_page(hpage);
92195 return 0;
92196@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92197 return 0;
92198 }
92199 if (TestClearPageHWPoison(p))
92200- atomic_long_dec(&num_poisoned_pages);
92201+ atomic_long_dec_unchecked(&num_poisoned_pages);
92202 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92203 return 0;
92204 }
92205@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92206 */
92207 if (TestClearPageHWPoison(page)) {
92208 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92209- atomic_long_sub(nr_pages, &num_poisoned_pages);
92210+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92211 freeit = 1;
92212 if (PageHuge(page))
92213 clear_page_hwpoison_huge_page(page);
92214@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92215 if (PageHuge(page)) {
92216 set_page_hwpoison_huge_page(hpage);
92217 dequeue_hwpoisoned_huge_page(hpage);
92218- atomic_long_add(1 << compound_order(hpage),
92219+ atomic_long_add_unchecked(1 << compound_order(hpage),
92220 &num_poisoned_pages);
92221 } else {
92222 SetPageHWPoison(page);
92223- atomic_long_inc(&num_poisoned_pages);
92224+ atomic_long_inc_unchecked(&num_poisoned_pages);
92225 }
92226 }
92227 return ret;
92228@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92229 put_page(page);
92230 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92231 SetPageHWPoison(page);
92232- atomic_long_inc(&num_poisoned_pages);
92233+ atomic_long_inc_unchecked(&num_poisoned_pages);
92234 return 0;
92235 }
92236
92237@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92238 if (!is_free_buddy_page(page))
92239 pr_info("soft offline: %#lx: page leaked\n",
92240 pfn);
92241- atomic_long_inc(&num_poisoned_pages);
92242+ atomic_long_inc_unchecked(&num_poisoned_pages);
92243 }
92244 } else {
92245 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92246@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92247 if (PageHuge(page)) {
92248 set_page_hwpoison_huge_page(hpage);
92249 dequeue_hwpoisoned_huge_page(hpage);
92250- atomic_long_add(1 << compound_order(hpage),
92251+ atomic_long_add_unchecked(1 << compound_order(hpage),
92252 &num_poisoned_pages);
92253 } else {
92254 SetPageHWPoison(page);
92255- atomic_long_inc(&num_poisoned_pages);
92256+ atomic_long_inc_unchecked(&num_poisoned_pages);
92257 }
92258 }
92259 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92260diff --git a/mm/memory.c b/mm/memory.c
92261index 22dfa61..90d7ec5 100644
92262--- a/mm/memory.c
92263+++ b/mm/memory.c
92264@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92265 free_pte_range(tlb, pmd, addr);
92266 } while (pmd++, addr = next, addr != end);
92267
92268+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92269 start &= PUD_MASK;
92270 if (start < floor)
92271 return;
92272@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92273 pmd = pmd_offset(pud, start);
92274 pud_clear(pud);
92275 pmd_free_tlb(tlb, pmd, start);
92276+#endif
92277+
92278 }
92279
92280 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92281@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92282 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92283 } while (pud++, addr = next, addr != end);
92284
92285+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92286 start &= PGDIR_MASK;
92287 if (start < floor)
92288 return;
92289@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92290 pud = pud_offset(pgd, start);
92291 pgd_clear(pgd);
92292 pud_free_tlb(tlb, pud, start);
92293+#endif
92294+
92295 }
92296
92297 /*
92298@@ -1636,12 +1642,6 @@ no_page_table:
92299 return page;
92300 }
92301
92302-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92303-{
92304- return stack_guard_page_start(vma, addr) ||
92305- stack_guard_page_end(vma, addr+PAGE_SIZE);
92306-}
92307-
92308 /**
92309 * __get_user_pages() - pin user pages in memory
92310 * @tsk: task_struct of target task
92311@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92312
92313 i = 0;
92314
92315- do {
92316+ while (nr_pages) {
92317 struct vm_area_struct *vma;
92318
92319- vma = find_extend_vma(mm, start);
92320+ vma = find_vma(mm, start);
92321 if (!vma && in_gate_area(mm, start)) {
92322 unsigned long pg = start & PAGE_MASK;
92323 pgd_t *pgd;
92324@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92325 goto next_page;
92326 }
92327
92328- if (!vma ||
92329+ if (!vma || start < vma->vm_start ||
92330 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92331 !(vm_flags & vma->vm_flags))
92332 return i ? : -EFAULT;
92333@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92334 int ret;
92335 unsigned int fault_flags = 0;
92336
92337- /* For mlock, just skip the stack guard page. */
92338- if (foll_flags & FOLL_MLOCK) {
92339- if (stack_guard_page(vma, start))
92340- goto next_page;
92341- }
92342 if (foll_flags & FOLL_WRITE)
92343 fault_flags |= FAULT_FLAG_WRITE;
92344 if (nonblocking)
92345@@ -1893,7 +1888,7 @@ next_page:
92346 start += page_increm * PAGE_SIZE;
92347 nr_pages -= page_increm;
92348 } while (nr_pages && start < vma->vm_end);
92349- } while (nr_pages);
92350+ }
92351 return i;
92352 }
92353 EXPORT_SYMBOL(__get_user_pages);
92354@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92355 unsigned long address, unsigned int fault_flags)
92356 {
92357 struct vm_area_struct *vma;
92358+ vm_flags_t vm_flags;
92359 int ret;
92360
92361 vma = find_extend_vma(mm, address);
92362 if (!vma || address < vma->vm_start)
92363 return -EFAULT;
92364
92365+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92366+ if (!(vm_flags & vma->vm_flags))
92367+ return -EFAULT;
92368+
92369 ret = handle_mm_fault(mm, vma, address, fault_flags);
92370 if (ret & VM_FAULT_ERROR) {
92371 if (ret & VM_FAULT_OOM)
92372@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92373 page_add_file_rmap(page);
92374 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92375
92376+#ifdef CONFIG_PAX_SEGMEXEC
92377+ pax_mirror_file_pte(vma, addr, page, ptl);
92378+#endif
92379+
92380 retval = 0;
92381 pte_unmap_unlock(pte, ptl);
92382 return retval;
92383@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92384 if (!page_count(page))
92385 return -EINVAL;
92386 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92387+
92388+#ifdef CONFIG_PAX_SEGMEXEC
92389+ struct vm_area_struct *vma_m;
92390+#endif
92391+
92392 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92393 BUG_ON(vma->vm_flags & VM_PFNMAP);
92394 vma->vm_flags |= VM_MIXEDMAP;
92395+
92396+#ifdef CONFIG_PAX_SEGMEXEC
92397+ vma_m = pax_find_mirror_vma(vma);
92398+ if (vma_m)
92399+ vma_m->vm_flags |= VM_MIXEDMAP;
92400+#endif
92401+
92402 }
92403 return insert_page(vma, addr, page, vma->vm_page_prot);
92404 }
92405@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92406 unsigned long pfn)
92407 {
92408 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92409+ BUG_ON(vma->vm_mirror);
92410
92411 if (addr < vma->vm_start || addr >= vma->vm_end)
92412 return -EFAULT;
92413@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92414
92415 BUG_ON(pud_huge(*pud));
92416
92417- pmd = pmd_alloc(mm, pud, addr);
92418+ pmd = (mm == &init_mm) ?
92419+ pmd_alloc_kernel(mm, pud, addr) :
92420+ pmd_alloc(mm, pud, addr);
92421 if (!pmd)
92422 return -ENOMEM;
92423 do {
92424@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92425 unsigned long next;
92426 int err;
92427
92428- pud = pud_alloc(mm, pgd, addr);
92429+ pud = (mm == &init_mm) ?
92430+ pud_alloc_kernel(mm, pgd, addr) :
92431+ pud_alloc(mm, pgd, addr);
92432 if (!pud)
92433 return -ENOMEM;
92434 do {
92435@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92436 copy_user_highpage(dst, src, va, vma);
92437 }
92438
92439+#ifdef CONFIG_PAX_SEGMEXEC
92440+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92441+{
92442+ struct mm_struct *mm = vma->vm_mm;
92443+ spinlock_t *ptl;
92444+ pte_t *pte, entry;
92445+
92446+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92447+ entry = *pte;
92448+ if (!pte_present(entry)) {
92449+ if (!pte_none(entry)) {
92450+ BUG_ON(pte_file(entry));
92451+ free_swap_and_cache(pte_to_swp_entry(entry));
92452+ pte_clear_not_present_full(mm, address, pte, 0);
92453+ }
92454+ } else {
92455+ struct page *page;
92456+
92457+ flush_cache_page(vma, address, pte_pfn(entry));
92458+ entry = ptep_clear_flush(vma, address, pte);
92459+ BUG_ON(pte_dirty(entry));
92460+ page = vm_normal_page(vma, address, entry);
92461+ if (page) {
92462+ update_hiwater_rss(mm);
92463+ if (PageAnon(page))
92464+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92465+ else
92466+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92467+ page_remove_rmap(page);
92468+ page_cache_release(page);
92469+ }
92470+ }
92471+ pte_unmap_unlock(pte, ptl);
92472+}
92473+
92474+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92475+ *
92476+ * the ptl of the lower mapped page is held on entry and is not released on exit
92477+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92478+ */
92479+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92480+{
92481+ struct mm_struct *mm = vma->vm_mm;
92482+ unsigned long address_m;
92483+ spinlock_t *ptl_m;
92484+ struct vm_area_struct *vma_m;
92485+ pmd_t *pmd_m;
92486+ pte_t *pte_m, entry_m;
92487+
92488+ BUG_ON(!page_m || !PageAnon(page_m));
92489+
92490+ vma_m = pax_find_mirror_vma(vma);
92491+ if (!vma_m)
92492+ return;
92493+
92494+ BUG_ON(!PageLocked(page_m));
92495+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92496+ address_m = address + SEGMEXEC_TASK_SIZE;
92497+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92498+ pte_m = pte_offset_map(pmd_m, address_m);
92499+ ptl_m = pte_lockptr(mm, pmd_m);
92500+ if (ptl != ptl_m) {
92501+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92502+ if (!pte_none(*pte_m))
92503+ goto out;
92504+ }
92505+
92506+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92507+ page_cache_get(page_m);
92508+ page_add_anon_rmap(page_m, vma_m, address_m);
92509+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92510+ set_pte_at(mm, address_m, pte_m, entry_m);
92511+ update_mmu_cache(vma_m, address_m, pte_m);
92512+out:
92513+ if (ptl != ptl_m)
92514+ spin_unlock(ptl_m);
92515+ pte_unmap(pte_m);
92516+ unlock_page(page_m);
92517+}
92518+
92519+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92520+{
92521+ struct mm_struct *mm = vma->vm_mm;
92522+ unsigned long address_m;
92523+ spinlock_t *ptl_m;
92524+ struct vm_area_struct *vma_m;
92525+ pmd_t *pmd_m;
92526+ pte_t *pte_m, entry_m;
92527+
92528+ BUG_ON(!page_m || PageAnon(page_m));
92529+
92530+ vma_m = pax_find_mirror_vma(vma);
92531+ if (!vma_m)
92532+ return;
92533+
92534+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92535+ address_m = address + SEGMEXEC_TASK_SIZE;
92536+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92537+ pte_m = pte_offset_map(pmd_m, address_m);
92538+ ptl_m = pte_lockptr(mm, pmd_m);
92539+ if (ptl != ptl_m) {
92540+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92541+ if (!pte_none(*pte_m))
92542+ goto out;
92543+ }
92544+
92545+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92546+ page_cache_get(page_m);
92547+ page_add_file_rmap(page_m);
92548+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92549+ set_pte_at(mm, address_m, pte_m, entry_m);
92550+ update_mmu_cache(vma_m, address_m, pte_m);
92551+out:
92552+ if (ptl != ptl_m)
92553+ spin_unlock(ptl_m);
92554+ pte_unmap(pte_m);
92555+}
92556+
92557+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92558+{
92559+ struct mm_struct *mm = vma->vm_mm;
92560+ unsigned long address_m;
92561+ spinlock_t *ptl_m;
92562+ struct vm_area_struct *vma_m;
92563+ pmd_t *pmd_m;
92564+ pte_t *pte_m, entry_m;
92565+
92566+ vma_m = pax_find_mirror_vma(vma);
92567+ if (!vma_m)
92568+ return;
92569+
92570+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92571+ address_m = address + SEGMEXEC_TASK_SIZE;
92572+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92573+ pte_m = pte_offset_map(pmd_m, address_m);
92574+ ptl_m = pte_lockptr(mm, pmd_m);
92575+ if (ptl != ptl_m) {
92576+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92577+ if (!pte_none(*pte_m))
92578+ goto out;
92579+ }
92580+
92581+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92582+ set_pte_at(mm, address_m, pte_m, entry_m);
92583+out:
92584+ if (ptl != ptl_m)
92585+ spin_unlock(ptl_m);
92586+ pte_unmap(pte_m);
92587+}
92588+
92589+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92590+{
92591+ struct page *page_m;
92592+ pte_t entry;
92593+
92594+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92595+ goto out;
92596+
92597+ entry = *pte;
92598+ page_m = vm_normal_page(vma, address, entry);
92599+ if (!page_m)
92600+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92601+ else if (PageAnon(page_m)) {
92602+ if (pax_find_mirror_vma(vma)) {
92603+ pte_unmap_unlock(pte, ptl);
92604+ lock_page(page_m);
92605+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92606+ if (pte_same(entry, *pte))
92607+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92608+ else
92609+ unlock_page(page_m);
92610+ }
92611+ } else
92612+ pax_mirror_file_pte(vma, address, page_m, ptl);
92613+
92614+out:
92615+ pte_unmap_unlock(pte, ptl);
92616+}
92617+#endif
92618+
92619 /*
92620 * This routine handles present pages, when users try to write
92621 * to a shared page. It is done by copying the page to a new address
92622@@ -2810,6 +3011,12 @@ gotten:
92623 */
92624 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92625 if (likely(pte_same(*page_table, orig_pte))) {
92626+
92627+#ifdef CONFIG_PAX_SEGMEXEC
92628+ if (pax_find_mirror_vma(vma))
92629+ BUG_ON(!trylock_page(new_page));
92630+#endif
92631+
92632 if (old_page) {
92633 if (!PageAnon(old_page)) {
92634 dec_mm_counter_fast(mm, MM_FILEPAGES);
92635@@ -2861,6 +3068,10 @@ gotten:
92636 page_remove_rmap(old_page);
92637 }
92638
92639+#ifdef CONFIG_PAX_SEGMEXEC
92640+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92641+#endif
92642+
92643 /* Free the old page.. */
92644 new_page = old_page;
92645 ret |= VM_FAULT_WRITE;
92646@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92647 swap_free(entry);
92648 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92649 try_to_free_swap(page);
92650+
92651+#ifdef CONFIG_PAX_SEGMEXEC
92652+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92653+#endif
92654+
92655 unlock_page(page);
92656 if (page != swapcache) {
92657 /*
92658@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92659
92660 /* No need to invalidate - it was non-present before */
92661 update_mmu_cache(vma, address, page_table);
92662+
92663+#ifdef CONFIG_PAX_SEGMEXEC
92664+ pax_mirror_anon_pte(vma, address, page, ptl);
92665+#endif
92666+
92667 unlock:
92668 pte_unmap_unlock(page_table, ptl);
92669 out:
92670@@ -3180,40 +3401,6 @@ out_release:
92671 }
92672
92673 /*
92674- * This is like a special single-page "expand_{down|up}wards()",
92675- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92676- * doesn't hit another vma.
92677- */
92678-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92679-{
92680- address &= PAGE_MASK;
92681- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92682- struct vm_area_struct *prev = vma->vm_prev;
92683-
92684- /*
92685- * Is there a mapping abutting this one below?
92686- *
92687- * That's only ok if it's the same stack mapping
92688- * that has gotten split..
92689- */
92690- if (prev && prev->vm_end == address)
92691- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92692-
92693- expand_downwards(vma, address - PAGE_SIZE);
92694- }
92695- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92696- struct vm_area_struct *next = vma->vm_next;
92697-
92698- /* As VM_GROWSDOWN but s/below/above/ */
92699- if (next && next->vm_start == address + PAGE_SIZE)
92700- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92701-
92702- expand_upwards(vma, address + PAGE_SIZE);
92703- }
92704- return 0;
92705-}
92706-
92707-/*
92708 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92709 * but allow concurrent faults), and pte mapped but not yet locked.
92710 * We return with mmap_sem still held, but pte unmapped and unlocked.
92711@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92712 unsigned long address, pte_t *page_table, pmd_t *pmd,
92713 unsigned int flags)
92714 {
92715- struct page *page;
92716+ struct page *page = NULL;
92717 spinlock_t *ptl;
92718 pte_t entry;
92719
92720- pte_unmap(page_table);
92721-
92722- /* Check if we need to add a guard page to the stack */
92723- if (check_stack_guard_page(vma, address) < 0)
92724- return VM_FAULT_SIGBUS;
92725-
92726- /* Use the zero-page for reads */
92727 if (!(flags & FAULT_FLAG_WRITE)) {
92728 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92729 vma->vm_page_prot));
92730- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92731+ ptl = pte_lockptr(mm, pmd);
92732+ spin_lock(ptl);
92733 if (!pte_none(*page_table))
92734 goto unlock;
92735 goto setpte;
92736 }
92737
92738 /* Allocate our own private page. */
92739+ pte_unmap(page_table);
92740+
92741 if (unlikely(anon_vma_prepare(vma)))
92742 goto oom;
92743 page = alloc_zeroed_user_highpage_movable(vma, address);
92744@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92745 if (!pte_none(*page_table))
92746 goto release;
92747
92748+#ifdef CONFIG_PAX_SEGMEXEC
92749+ if (pax_find_mirror_vma(vma))
92750+ BUG_ON(!trylock_page(page));
92751+#endif
92752+
92753 inc_mm_counter_fast(mm, MM_ANONPAGES);
92754 page_add_new_anon_rmap(page, vma, address);
92755 setpte:
92756@@ -3273,6 +3461,12 @@ setpte:
92757
92758 /* No need to invalidate - it was non-present before */
92759 update_mmu_cache(vma, address, page_table);
92760+
92761+#ifdef CONFIG_PAX_SEGMEXEC
92762+ if (page)
92763+ pax_mirror_anon_pte(vma, address, page, ptl);
92764+#endif
92765+
92766 unlock:
92767 pte_unmap_unlock(page_table, ptl);
92768 return 0;
92769@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92770 */
92771 /* Only go through if we didn't race with anybody else... */
92772 if (likely(pte_same(*page_table, orig_pte))) {
92773+
92774+#ifdef CONFIG_PAX_SEGMEXEC
92775+ if (anon && pax_find_mirror_vma(vma))
92776+ BUG_ON(!trylock_page(page));
92777+#endif
92778+
92779 flush_icache_page(vma, page);
92780 entry = mk_pte(page, vma->vm_page_prot);
92781 if (flags & FAULT_FLAG_WRITE)
92782@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92783
92784 /* no need to invalidate: a not-present page won't be cached */
92785 update_mmu_cache(vma, address, page_table);
92786+
92787+#ifdef CONFIG_PAX_SEGMEXEC
92788+ if (anon)
92789+ pax_mirror_anon_pte(vma, address, page, ptl);
92790+ else
92791+ pax_mirror_file_pte(vma, address, page, ptl);
92792+#endif
92793+
92794 } else {
92795 if (cow_page)
92796 mem_cgroup_uncharge_page(cow_page);
92797@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92798 if (flags & FAULT_FLAG_WRITE)
92799 flush_tlb_fix_spurious_fault(vma, address);
92800 }
92801+
92802+#ifdef CONFIG_PAX_SEGMEXEC
92803+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92804+ return 0;
92805+#endif
92806+
92807 unlock:
92808 pte_unmap_unlock(pte, ptl);
92809 return 0;
92810@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92811 pmd_t *pmd;
92812 pte_t *pte;
92813
92814+#ifdef CONFIG_PAX_SEGMEXEC
92815+ struct vm_area_struct *vma_m;
92816+#endif
92817+
92818 if (unlikely(is_vm_hugetlb_page(vma)))
92819 return hugetlb_fault(mm, vma, address, flags);
92820
92821+#ifdef CONFIG_PAX_SEGMEXEC
92822+ vma_m = pax_find_mirror_vma(vma);
92823+ if (vma_m) {
92824+ unsigned long address_m;
92825+ pgd_t *pgd_m;
92826+ pud_t *pud_m;
92827+ pmd_t *pmd_m;
92828+
92829+ if (vma->vm_start > vma_m->vm_start) {
92830+ address_m = address;
92831+ address -= SEGMEXEC_TASK_SIZE;
92832+ vma = vma_m;
92833+ } else
92834+ address_m = address + SEGMEXEC_TASK_SIZE;
92835+
92836+ pgd_m = pgd_offset(mm, address_m);
92837+ pud_m = pud_alloc(mm, pgd_m, address_m);
92838+ if (!pud_m)
92839+ return VM_FAULT_OOM;
92840+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92841+ if (!pmd_m)
92842+ return VM_FAULT_OOM;
92843+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92844+ return VM_FAULT_OOM;
92845+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92846+ }
92847+#endif
92848+
92849 pgd = pgd_offset(mm, address);
92850 pud = pud_alloc(mm, pgd, address);
92851 if (!pud)
92852@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92853 spin_unlock(&mm->page_table_lock);
92854 return 0;
92855 }
92856+
92857+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92858+{
92859+ pud_t *new = pud_alloc_one(mm, address);
92860+ if (!new)
92861+ return -ENOMEM;
92862+
92863+ smp_wmb(); /* See comment in __pte_alloc */
92864+
92865+ spin_lock(&mm->page_table_lock);
92866+ if (pgd_present(*pgd)) /* Another has populated it */
92867+ pud_free(mm, new);
92868+ else
92869+ pgd_populate_kernel(mm, pgd, new);
92870+ spin_unlock(&mm->page_table_lock);
92871+ return 0;
92872+}
92873 #endif /* __PAGETABLE_PUD_FOLDED */
92874
92875 #ifndef __PAGETABLE_PMD_FOLDED
92876@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92877 spin_unlock(&mm->page_table_lock);
92878 return 0;
92879 }
92880+
92881+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92882+{
92883+ pmd_t *new = pmd_alloc_one(mm, address);
92884+ if (!new)
92885+ return -ENOMEM;
92886+
92887+ smp_wmb(); /* See comment in __pte_alloc */
92888+
92889+ spin_lock(&mm->page_table_lock);
92890+#ifndef __ARCH_HAS_4LEVEL_HACK
92891+ if (pud_present(*pud)) /* Another has populated it */
92892+ pmd_free(mm, new);
92893+ else
92894+ pud_populate_kernel(mm, pud, new);
92895+#else
92896+ if (pgd_present(*pud)) /* Another has populated it */
92897+ pmd_free(mm, new);
92898+ else
92899+ pgd_populate_kernel(mm, pud, new);
92900+#endif /* __ARCH_HAS_4LEVEL_HACK */
92901+ spin_unlock(&mm->page_table_lock);
92902+ return 0;
92903+}
92904 #endif /* __PAGETABLE_PMD_FOLDED */
92905
92906 #if !defined(__HAVE_ARCH_GATE_AREA)
92907@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
92908 gate_vma.vm_start = FIXADDR_USER_START;
92909 gate_vma.vm_end = FIXADDR_USER_END;
92910 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92911- gate_vma.vm_page_prot = __P101;
92912+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92913
92914 return 0;
92915 }
92916@@ -4011,8 +4298,8 @@ out:
92917 return ret;
92918 }
92919
92920-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92921- void *buf, int len, int write)
92922+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92923+ void *buf, size_t len, int write)
92924 {
92925 resource_size_t phys_addr;
92926 unsigned long prot = 0;
92927@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92928 * Access another process' address space as given in mm. If non-NULL, use the
92929 * given task for page fault accounting.
92930 */
92931-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92932- unsigned long addr, void *buf, int len, int write)
92933+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92934+ unsigned long addr, void *buf, size_t len, int write)
92935 {
92936 struct vm_area_struct *vma;
92937 void *old_buf = buf;
92938@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92939 down_read(&mm->mmap_sem);
92940 /* ignore errors, just check how much was successfully transferred */
92941 while (len) {
92942- int bytes, ret, offset;
92943+ ssize_t bytes, ret, offset;
92944 void *maddr;
92945 struct page *page = NULL;
92946
92947@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92948 *
92949 * The caller must hold a reference on @mm.
92950 */
92951-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92952- void *buf, int len, int write)
92953+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92954+ void *buf, size_t len, int write)
92955 {
92956 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92957 }
92958@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92959 * Source/target buffer must be kernel space,
92960 * Do not walk the page table directly, use get_user_pages
92961 */
92962-int access_process_vm(struct task_struct *tsk, unsigned long addr,
92963- void *buf, int len, int write)
92964+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92965+ void *buf, size_t len, int write)
92966 {
92967 struct mm_struct *mm;
92968- int ret;
92969+ ssize_t ret;
92970
92971 mm = get_task_mm(tsk);
92972 if (!mm)
92973diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92974index ae3c8f3..fa4ee8e 100644
92975--- a/mm/mempolicy.c
92976+++ b/mm/mempolicy.c
92977@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92978 unsigned long vmstart;
92979 unsigned long vmend;
92980
92981+#ifdef CONFIG_PAX_SEGMEXEC
92982+ struct vm_area_struct *vma_m;
92983+#endif
92984+
92985 vma = find_vma(mm, start);
92986 if (!vma || vma->vm_start > start)
92987 return -EFAULT;
92988@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92989 err = vma_replace_policy(vma, new_pol);
92990 if (err)
92991 goto out;
92992+
92993+#ifdef CONFIG_PAX_SEGMEXEC
92994+ vma_m = pax_find_mirror_vma(vma);
92995+ if (vma_m) {
92996+ err = vma_replace_policy(vma_m, new_pol);
92997+ if (err)
92998+ goto out;
92999+ }
93000+#endif
93001+
93002 }
93003
93004 out:
93005@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93006
93007 if (end < start)
93008 return -EINVAL;
93009+
93010+#ifdef CONFIG_PAX_SEGMEXEC
93011+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93012+ if (end > SEGMEXEC_TASK_SIZE)
93013+ return -EINVAL;
93014+ } else
93015+#endif
93016+
93017+ if (end > TASK_SIZE)
93018+ return -EINVAL;
93019+
93020 if (end == start)
93021 return 0;
93022
93023@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93024 */
93025 tcred = __task_cred(task);
93026 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93027- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93028- !capable(CAP_SYS_NICE)) {
93029+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93030 rcu_read_unlock();
93031 err = -EPERM;
93032 goto out_put;
93033@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93034 goto out;
93035 }
93036
93037+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93038+ if (mm != current->mm &&
93039+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93040+ mmput(mm);
93041+ err = -EPERM;
93042+ goto out;
93043+ }
93044+#endif
93045+
93046 err = do_migrate_pages(mm, old, new,
93047 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93048
93049diff --git a/mm/migrate.c b/mm/migrate.c
93050index bed4880..a493f67 100644
93051--- a/mm/migrate.c
93052+++ b/mm/migrate.c
93053@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93054 */
93055 tcred = __task_cred(task);
93056 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93057- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93058- !capable(CAP_SYS_NICE)) {
93059+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93060 rcu_read_unlock();
93061 err = -EPERM;
93062 goto out;
93063diff --git a/mm/mlock.c b/mm/mlock.c
93064index b1eb536..091d154 100644
93065--- a/mm/mlock.c
93066+++ b/mm/mlock.c
93067@@ -14,6 +14,7 @@
93068 #include <linux/pagevec.h>
93069 #include <linux/mempolicy.h>
93070 #include <linux/syscalls.h>
93071+#include <linux/security.h>
93072 #include <linux/sched.h>
93073 #include <linux/export.h>
93074 #include <linux/rmap.h>
93075@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93076 {
93077 unsigned long nstart, end, tmp;
93078 struct vm_area_struct * vma, * prev;
93079- int error;
93080+ int error = 0;
93081
93082 VM_BUG_ON(start & ~PAGE_MASK);
93083 VM_BUG_ON(len != PAGE_ALIGN(len));
93084@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93085 return -EINVAL;
93086 if (end == start)
93087 return 0;
93088+ if (end > TASK_SIZE)
93089+ return -EINVAL;
93090+
93091 vma = find_vma(current->mm, start);
93092 if (!vma || vma->vm_start > start)
93093 return -ENOMEM;
93094@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93095 for (nstart = start ; ; ) {
93096 vm_flags_t newflags;
93097
93098+#ifdef CONFIG_PAX_SEGMEXEC
93099+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93100+ break;
93101+#endif
93102+
93103 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93104
93105 newflags = vma->vm_flags & ~VM_LOCKED;
93106@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93107 locked += current->mm->locked_vm;
93108
93109 /* check against resource limits */
93110+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93111 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93112 error = do_mlock(start, len, 1);
93113
93114@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93115 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93116 vm_flags_t newflags;
93117
93118+#ifdef CONFIG_PAX_SEGMEXEC
93119+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93120+ break;
93121+#endif
93122+
93123 newflags = vma->vm_flags & ~VM_LOCKED;
93124 if (flags & MCL_CURRENT)
93125 newflags |= VM_LOCKED;
93126@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93127 lock_limit >>= PAGE_SHIFT;
93128
93129 ret = -ENOMEM;
93130+
93131+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93132+
93133 down_write(&current->mm->mmap_sem);
93134-
93135 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93136 capable(CAP_IPC_LOCK))
93137 ret = do_mlockall(flags);
93138diff --git a/mm/mmap.c b/mm/mmap.c
93139index 20ff0c3..a9eda98 100644
93140--- a/mm/mmap.c
93141+++ b/mm/mmap.c
93142@@ -36,6 +36,7 @@
93143 #include <linux/sched/sysctl.h>
93144 #include <linux/notifier.h>
93145 #include <linux/memory.h>
93146+#include <linux/random.h>
93147
93148 #include <asm/uaccess.h>
93149 #include <asm/cacheflush.h>
93150@@ -52,6 +53,16 @@
93151 #define arch_rebalance_pgtables(addr, len) (addr)
93152 #endif
93153
93154+static inline void verify_mm_writelocked(struct mm_struct *mm)
93155+{
93156+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93157+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93158+ up_read(&mm->mmap_sem);
93159+ BUG();
93160+ }
93161+#endif
93162+}
93163+
93164 static void unmap_region(struct mm_struct *mm,
93165 struct vm_area_struct *vma, struct vm_area_struct *prev,
93166 unsigned long start, unsigned long end);
93167@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93168 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93169 *
93170 */
93171-pgprot_t protection_map[16] = {
93172+pgprot_t protection_map[16] __read_only = {
93173 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93174 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93175 };
93176
93177-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93178+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93179 {
93180- return __pgprot(pgprot_val(protection_map[vm_flags &
93181+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93182 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93183 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93184+
93185+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93186+ if (!(__supported_pte_mask & _PAGE_NX) &&
93187+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93188+ (vm_flags & (VM_READ | VM_WRITE)))
93189+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93190+#endif
93191+
93192+ return prot;
93193 }
93194 EXPORT_SYMBOL(vm_get_page_prot);
93195
93196@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93197 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93198 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93199 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93200+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93201 /*
93202 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93203 * other variables. It can be updated by several CPUs frequently.
93204@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93205 struct vm_area_struct *next = vma->vm_next;
93206
93207 might_sleep();
93208+ BUG_ON(vma->vm_mirror);
93209 if (vma->vm_ops && vma->vm_ops->close)
93210 vma->vm_ops->close(vma);
93211 if (vma->vm_file)
93212@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93213 * not page aligned -Ram Gupta
93214 */
93215 rlim = rlimit(RLIMIT_DATA);
93216+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93217 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93218 (mm->end_data - mm->start_data) > rlim)
93219 goto out;
93220@@ -940,6 +963,12 @@ static int
93221 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93222 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93223 {
93224+
93225+#ifdef CONFIG_PAX_SEGMEXEC
93226+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93227+ return 0;
93228+#endif
93229+
93230 if (is_mergeable_vma(vma, file, vm_flags) &&
93231 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93232 if (vma->vm_pgoff == vm_pgoff)
93233@@ -959,6 +988,12 @@ static int
93234 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93235 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93236 {
93237+
93238+#ifdef CONFIG_PAX_SEGMEXEC
93239+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93240+ return 0;
93241+#endif
93242+
93243 if (is_mergeable_vma(vma, file, vm_flags) &&
93244 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93245 pgoff_t vm_pglen;
93246@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93247 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93248 struct vm_area_struct *prev, unsigned long addr,
93249 unsigned long end, unsigned long vm_flags,
93250- struct anon_vma *anon_vma, struct file *file,
93251+ struct anon_vma *anon_vma, struct file *file,
93252 pgoff_t pgoff, struct mempolicy *policy)
93253 {
93254 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93255 struct vm_area_struct *area, *next;
93256 int err;
93257
93258+#ifdef CONFIG_PAX_SEGMEXEC
93259+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93260+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93261+
93262+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93263+#endif
93264+
93265 /*
93266 * We later require that vma->vm_flags == vm_flags,
93267 * so this tests vma->vm_flags & VM_SPECIAL, too.
93268@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93269 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93270 next = next->vm_next;
93271
93272+#ifdef CONFIG_PAX_SEGMEXEC
93273+ if (prev)
93274+ prev_m = pax_find_mirror_vma(prev);
93275+ if (area)
93276+ area_m = pax_find_mirror_vma(area);
93277+ if (next)
93278+ next_m = pax_find_mirror_vma(next);
93279+#endif
93280+
93281 /*
93282 * Can it merge with the predecessor?
93283 */
93284@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93285 /* cases 1, 6 */
93286 err = vma_adjust(prev, prev->vm_start,
93287 next->vm_end, prev->vm_pgoff, NULL);
93288- } else /* cases 2, 5, 7 */
93289+
93290+#ifdef CONFIG_PAX_SEGMEXEC
93291+ if (!err && prev_m)
93292+ err = vma_adjust(prev_m, prev_m->vm_start,
93293+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93294+#endif
93295+
93296+ } else { /* cases 2, 5, 7 */
93297 err = vma_adjust(prev, prev->vm_start,
93298 end, prev->vm_pgoff, NULL);
93299+
93300+#ifdef CONFIG_PAX_SEGMEXEC
93301+ if (!err && prev_m)
93302+ err = vma_adjust(prev_m, prev_m->vm_start,
93303+ end_m, prev_m->vm_pgoff, NULL);
93304+#endif
93305+
93306+ }
93307 if (err)
93308 return NULL;
93309 khugepaged_enter_vma_merge(prev);
93310@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93311 mpol_equal(policy, vma_policy(next)) &&
93312 can_vma_merge_before(next, vm_flags,
93313 anon_vma, file, pgoff+pglen)) {
93314- if (prev && addr < prev->vm_end) /* case 4 */
93315+ if (prev && addr < prev->vm_end) { /* case 4 */
93316 err = vma_adjust(prev, prev->vm_start,
93317 addr, prev->vm_pgoff, NULL);
93318- else /* cases 3, 8 */
93319+
93320+#ifdef CONFIG_PAX_SEGMEXEC
93321+ if (!err && prev_m)
93322+ err = vma_adjust(prev_m, prev_m->vm_start,
93323+ addr_m, prev_m->vm_pgoff, NULL);
93324+#endif
93325+
93326+ } else { /* cases 3, 8 */
93327 err = vma_adjust(area, addr, next->vm_end,
93328 next->vm_pgoff - pglen, NULL);
93329+
93330+#ifdef CONFIG_PAX_SEGMEXEC
93331+ if (!err && area_m)
93332+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93333+ next_m->vm_pgoff - pglen, NULL);
93334+#endif
93335+
93336+ }
93337 if (err)
93338 return NULL;
93339 khugepaged_enter_vma_merge(area);
93340@@ -1172,8 +1253,10 @@ none:
93341 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93342 struct file *file, long pages)
93343 {
93344- const unsigned long stack_flags
93345- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93346+
93347+#ifdef CONFIG_PAX_RANDMMAP
93348+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93349+#endif
93350
93351 mm->total_vm += pages;
93352
93353@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93354 mm->shared_vm += pages;
93355 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93356 mm->exec_vm += pages;
93357- } else if (flags & stack_flags)
93358+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93359 mm->stack_vm += pages;
93360 }
93361 #endif /* CONFIG_PROC_FS */
93362@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93363 locked += mm->locked_vm;
93364 lock_limit = rlimit(RLIMIT_MEMLOCK);
93365 lock_limit >>= PAGE_SHIFT;
93366+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93367 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93368 return -EAGAIN;
93369 }
93370@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93371 * (the exception is when the underlying filesystem is noexec
93372 * mounted, in which case we dont add PROT_EXEC.)
93373 */
93374- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93375+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93376 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93377 prot |= PROT_EXEC;
93378
93379@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93380 /* Obtain the address to map to. we verify (or select) it and ensure
93381 * that it represents a valid section of the address space.
93382 */
93383- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93384+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93385 if (addr & ~PAGE_MASK)
93386 return addr;
93387
93388@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93389 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93390 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93391
93392+#ifdef CONFIG_PAX_MPROTECT
93393+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93394+
93395+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93396+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93397+ mm->binfmt->handle_mmap)
93398+ mm->binfmt->handle_mmap(file);
93399+#endif
93400+
93401+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93402+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93403+ gr_log_rwxmmap(file);
93404+
93405+#ifdef CONFIG_PAX_EMUPLT
93406+ vm_flags &= ~VM_EXEC;
93407+#else
93408+ return -EPERM;
93409+#endif
93410+
93411+ }
93412+
93413+ if (!(vm_flags & VM_EXEC))
93414+ vm_flags &= ~VM_MAYEXEC;
93415+#else
93416+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93417+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93418+#endif
93419+ else
93420+ vm_flags &= ~VM_MAYWRITE;
93421+ }
93422+#endif
93423+
93424+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93425+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93426+ vm_flags &= ~VM_PAGEEXEC;
93427+#endif
93428+
93429 if (flags & MAP_LOCKED)
93430 if (!can_do_mlock())
93431 return -EPERM;
93432@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93433 vm_flags |= VM_NORESERVE;
93434 }
93435
93436+ if (!gr_acl_handle_mmap(file, prot))
93437+ return -EACCES;
93438+
93439 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93440 if (!IS_ERR_VALUE(addr) &&
93441 ((vm_flags & VM_LOCKED) ||
93442@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93443 vm_flags_t vm_flags = vma->vm_flags;
93444
93445 /* If it was private or non-writable, the write bit is already clear */
93446- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93447+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93448 return 0;
93449
93450 /* The backer wishes to know when pages are first written to? */
93451@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93452 struct rb_node **rb_link, *rb_parent;
93453 unsigned long charged = 0;
93454
93455+#ifdef CONFIG_PAX_SEGMEXEC
93456+ struct vm_area_struct *vma_m = NULL;
93457+#endif
93458+
93459+ /*
93460+ * mm->mmap_sem is required to protect against another thread
93461+ * changing the mappings in case we sleep.
93462+ */
93463+ verify_mm_writelocked(mm);
93464+
93465 /* Check against address space limit. */
93466+
93467+#ifdef CONFIG_PAX_RANDMMAP
93468+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93469+#endif
93470+
93471 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93472 unsigned long nr_pages;
93473
93474@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93475
93476 /* Clear old maps */
93477 error = -ENOMEM;
93478-munmap_back:
93479 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93480 if (do_munmap(mm, addr, len))
93481 return -ENOMEM;
93482- goto munmap_back;
93483+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93484 }
93485
93486 /*
93487@@ -1554,6 +1692,16 @@ munmap_back:
93488 goto unacct_error;
93489 }
93490
93491+#ifdef CONFIG_PAX_SEGMEXEC
93492+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93493+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93494+ if (!vma_m) {
93495+ error = -ENOMEM;
93496+ goto free_vma;
93497+ }
93498+ }
93499+#endif
93500+
93501 vma->vm_mm = mm;
93502 vma->vm_start = addr;
93503 vma->vm_end = addr + len;
93504@@ -1573,6 +1721,13 @@ munmap_back:
93505 if (error)
93506 goto unmap_and_free_vma;
93507
93508+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93509+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93510+ vma->vm_flags |= VM_PAGEEXEC;
93511+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93512+ }
93513+#endif
93514+
93515 /* Can addr have changed??
93516 *
93517 * Answer: Yes, several device drivers can do it in their
93518@@ -1606,6 +1761,12 @@ munmap_back:
93519 }
93520
93521 vma_link(mm, vma, prev, rb_link, rb_parent);
93522+
93523+#ifdef CONFIG_PAX_SEGMEXEC
93524+ if (vma_m)
93525+ BUG_ON(pax_mirror_vma(vma_m, vma));
93526+#endif
93527+
93528 /* Once vma denies write, undo our temporary denial count */
93529 if (vm_flags & VM_DENYWRITE)
93530 allow_write_access(file);
93531@@ -1614,6 +1775,7 @@ out:
93532 perf_event_mmap(vma);
93533
93534 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93535+ track_exec_limit(mm, addr, addr + len, vm_flags);
93536 if (vm_flags & VM_LOCKED) {
93537 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93538 vma == get_gate_vma(current->mm)))
93539@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93540 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93541 charged = 0;
93542 free_vma:
93543+
93544+#ifdef CONFIG_PAX_SEGMEXEC
93545+ if (vma_m)
93546+ kmem_cache_free(vm_area_cachep, vma_m);
93547+#endif
93548+
93549 kmem_cache_free(vm_area_cachep, vma);
93550 unacct_error:
93551 if (charged)
93552@@ -1653,7 +1821,63 @@ unacct_error:
93553 return error;
93554 }
93555
93556-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93557+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93558+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93559+{
93560+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93561+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93562+
93563+ return 0;
93564+}
93565+#endif
93566+
93567+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93568+{
93569+ if (!vma) {
93570+#ifdef CONFIG_STACK_GROWSUP
93571+ if (addr > sysctl_heap_stack_gap)
93572+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93573+ else
93574+ vma = find_vma(current->mm, 0);
93575+ if (vma && (vma->vm_flags & VM_GROWSUP))
93576+ return false;
93577+#endif
93578+ return true;
93579+ }
93580+
93581+ if (addr + len > vma->vm_start)
93582+ return false;
93583+
93584+ if (vma->vm_flags & VM_GROWSDOWN)
93585+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93586+#ifdef CONFIG_STACK_GROWSUP
93587+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93588+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93589+#endif
93590+ else if (offset)
93591+ return offset <= vma->vm_start - addr - len;
93592+
93593+ return true;
93594+}
93595+
93596+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93597+{
93598+ if (vma->vm_start < len)
93599+ return -ENOMEM;
93600+
93601+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93602+ if (offset <= vma->vm_start - len)
93603+ return vma->vm_start - len - offset;
93604+ else
93605+ return -ENOMEM;
93606+ }
93607+
93608+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93609+ return vma->vm_start - len - sysctl_heap_stack_gap;
93610+ return -ENOMEM;
93611+}
93612+
93613+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93614 {
93615 /*
93616 * We implement the search by looking for an rbtree node that
93617@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93618 }
93619 }
93620
93621- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93622+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93623 check_current:
93624 /* Check if current node has a suitable gap */
93625 if (gap_start > high_limit)
93626 return -ENOMEM;
93627+
93628+ if (gap_end - gap_start > info->threadstack_offset)
93629+ gap_start += info->threadstack_offset;
93630+ else
93631+ gap_start = gap_end;
93632+
93633+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93634+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93635+ gap_start += sysctl_heap_stack_gap;
93636+ else
93637+ gap_start = gap_end;
93638+ }
93639+ if (vma->vm_flags & VM_GROWSDOWN) {
93640+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93641+ gap_end -= sysctl_heap_stack_gap;
93642+ else
93643+ gap_end = gap_start;
93644+ }
93645 if (gap_end >= low_limit && gap_end - gap_start >= length)
93646 goto found;
93647
93648@@ -1755,7 +1997,7 @@ found:
93649 return gap_start;
93650 }
93651
93652-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93653+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93654 {
93655 struct mm_struct *mm = current->mm;
93656 struct vm_area_struct *vma;
93657@@ -1809,6 +2051,24 @@ check_current:
93658 gap_end = vma->vm_start;
93659 if (gap_end < low_limit)
93660 return -ENOMEM;
93661+
93662+ if (gap_end - gap_start > info->threadstack_offset)
93663+ gap_end -= info->threadstack_offset;
93664+ else
93665+ gap_end = gap_start;
93666+
93667+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93668+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93669+ gap_start += sysctl_heap_stack_gap;
93670+ else
93671+ gap_start = gap_end;
93672+ }
93673+ if (vma->vm_flags & VM_GROWSDOWN) {
93674+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93675+ gap_end -= sysctl_heap_stack_gap;
93676+ else
93677+ gap_end = gap_start;
93678+ }
93679 if (gap_start <= high_limit && gap_end - gap_start >= length)
93680 goto found;
93681
93682@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93683 struct mm_struct *mm = current->mm;
93684 struct vm_area_struct *vma;
93685 struct vm_unmapped_area_info info;
93686+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93687
93688 if (len > TASK_SIZE - mmap_min_addr)
93689 return -ENOMEM;
93690@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93691 if (flags & MAP_FIXED)
93692 return addr;
93693
93694+#ifdef CONFIG_PAX_RANDMMAP
93695+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93696+#endif
93697+
93698 if (addr) {
93699 addr = PAGE_ALIGN(addr);
93700 vma = find_vma(mm, addr);
93701 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93702- (!vma || addr + len <= vma->vm_start))
93703+ check_heap_stack_gap(vma, addr, len, offset))
93704 return addr;
93705 }
93706
93707@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93708 info.low_limit = mm->mmap_base;
93709 info.high_limit = TASK_SIZE;
93710 info.align_mask = 0;
93711+ info.threadstack_offset = offset;
93712 return vm_unmapped_area(&info);
93713 }
93714 #endif
93715@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93716 struct mm_struct *mm = current->mm;
93717 unsigned long addr = addr0;
93718 struct vm_unmapped_area_info info;
93719+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93720
93721 /* requested length too big for entire address space */
93722 if (len > TASK_SIZE - mmap_min_addr)
93723@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93724 if (flags & MAP_FIXED)
93725 return addr;
93726
93727+#ifdef CONFIG_PAX_RANDMMAP
93728+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93729+#endif
93730+
93731 /* requesting a specific address */
93732 if (addr) {
93733 addr = PAGE_ALIGN(addr);
93734 vma = find_vma(mm, addr);
93735 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93736- (!vma || addr + len <= vma->vm_start))
93737+ check_heap_stack_gap(vma, addr, len, offset))
93738 return addr;
93739 }
93740
93741@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93742 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93743 info.high_limit = mm->mmap_base;
93744 info.align_mask = 0;
93745+ info.threadstack_offset = offset;
93746 addr = vm_unmapped_area(&info);
93747
93748 /*
93749@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93750 VM_BUG_ON(addr != -ENOMEM);
93751 info.flags = 0;
93752 info.low_limit = TASK_UNMAPPED_BASE;
93753+
93754+#ifdef CONFIG_PAX_RANDMMAP
93755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93756+ info.low_limit += mm->delta_mmap;
93757+#endif
93758+
93759 info.high_limit = TASK_SIZE;
93760 addr = vm_unmapped_area(&info);
93761 }
93762@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93763 return vma;
93764 }
93765
93766+#ifdef CONFIG_PAX_SEGMEXEC
93767+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93768+{
93769+ struct vm_area_struct *vma_m;
93770+
93771+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93772+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93773+ BUG_ON(vma->vm_mirror);
93774+ return NULL;
93775+ }
93776+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93777+ vma_m = vma->vm_mirror;
93778+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93779+ BUG_ON(vma->vm_file != vma_m->vm_file);
93780+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93781+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93782+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93783+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93784+ return vma_m;
93785+}
93786+#endif
93787+
93788 /*
93789 * Verify that the stack growth is acceptable and
93790 * update accounting. This is shared with both the
93791@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93792 return -ENOMEM;
93793
93794 /* Stack limit test */
93795+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93796 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93797 return -ENOMEM;
93798
93799@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93800 locked = mm->locked_vm + grow;
93801 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93802 limit >>= PAGE_SHIFT;
93803+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93804 if (locked > limit && !capable(CAP_IPC_LOCK))
93805 return -ENOMEM;
93806 }
93807@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93808 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93809 * vma is the last one with address > vma->vm_end. Have to extend vma.
93810 */
93811+#ifndef CONFIG_IA64
93812+static
93813+#endif
93814 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93815 {
93816 int error;
93817+ bool locknext;
93818
93819 if (!(vma->vm_flags & VM_GROWSUP))
93820 return -EFAULT;
93821
93822+ /* Also guard against wrapping around to address 0. */
93823+ if (address < PAGE_ALIGN(address+1))
93824+ address = PAGE_ALIGN(address+1);
93825+ else
93826+ return -ENOMEM;
93827+
93828 /*
93829 * We must make sure the anon_vma is allocated
93830 * so that the anon_vma locking is not a noop.
93831 */
93832 if (unlikely(anon_vma_prepare(vma)))
93833 return -ENOMEM;
93834+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93835+ if (locknext && anon_vma_prepare(vma->vm_next))
93836+ return -ENOMEM;
93837 vma_lock_anon_vma(vma);
93838+ if (locknext)
93839+ vma_lock_anon_vma(vma->vm_next);
93840
93841 /*
93842 * vma->vm_start/vm_end cannot change under us because the caller
93843 * is required to hold the mmap_sem in read mode. We need the
93844- * anon_vma lock to serialize against concurrent expand_stacks.
93845- * Also guard against wrapping around to address 0.
93846+ * anon_vma locks to serialize against concurrent expand_stacks
93847+ * and expand_upwards.
93848 */
93849- if (address < PAGE_ALIGN(address+4))
93850- address = PAGE_ALIGN(address+4);
93851- else {
93852- vma_unlock_anon_vma(vma);
93853- return -ENOMEM;
93854- }
93855 error = 0;
93856
93857 /* Somebody else might have raced and expanded it already */
93858- if (address > vma->vm_end) {
93859+ 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)
93860+ error = -ENOMEM;
93861+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93862 unsigned long size, grow;
93863
93864 size = address - vma->vm_start;
93865@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93866 }
93867 }
93868 }
93869+ if (locknext)
93870+ vma_unlock_anon_vma(vma->vm_next);
93871 vma_unlock_anon_vma(vma);
93872 khugepaged_enter_vma_merge(vma);
93873 validate_mm(vma->vm_mm);
93874@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93875 unsigned long address)
93876 {
93877 int error;
93878+ bool lockprev = false;
93879+ struct vm_area_struct *prev;
93880
93881 /*
93882 * We must make sure the anon_vma is allocated
93883@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93884 if (error)
93885 return error;
93886
93887+ prev = vma->vm_prev;
93888+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93889+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93890+#endif
93891+ if (lockprev && anon_vma_prepare(prev))
93892+ return -ENOMEM;
93893+ if (lockprev)
93894+ vma_lock_anon_vma(prev);
93895+
93896 vma_lock_anon_vma(vma);
93897
93898 /*
93899@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
93900 */
93901
93902 /* Somebody else might have raced and expanded it already */
93903- if (address < vma->vm_start) {
93904+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93905+ error = -ENOMEM;
93906+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93907 unsigned long size, grow;
93908
93909+#ifdef CONFIG_PAX_SEGMEXEC
93910+ struct vm_area_struct *vma_m;
93911+
93912+ vma_m = pax_find_mirror_vma(vma);
93913+#endif
93914+
93915 size = vma->vm_end - address;
93916 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93917
93918@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
93919 vma->vm_pgoff -= grow;
93920 anon_vma_interval_tree_post_update_vma(vma);
93921 vma_gap_update(vma);
93922+
93923+#ifdef CONFIG_PAX_SEGMEXEC
93924+ if (vma_m) {
93925+ anon_vma_interval_tree_pre_update_vma(vma_m);
93926+ vma_m->vm_start -= grow << PAGE_SHIFT;
93927+ vma_m->vm_pgoff -= grow;
93928+ anon_vma_interval_tree_post_update_vma(vma_m);
93929+ vma_gap_update(vma_m);
93930+ }
93931+#endif
93932+
93933 spin_unlock(&vma->vm_mm->page_table_lock);
93934
93935+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93936 perf_event_mmap(vma);
93937 }
93938 }
93939 }
93940 vma_unlock_anon_vma(vma);
93941+ if (lockprev)
93942+ vma_unlock_anon_vma(prev);
93943 khugepaged_enter_vma_merge(vma);
93944 validate_mm(vma->vm_mm);
93945 return error;
93946@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93947 do {
93948 long nrpages = vma_pages(vma);
93949
93950+#ifdef CONFIG_PAX_SEGMEXEC
93951+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93952+ vma = remove_vma(vma);
93953+ continue;
93954+ }
93955+#endif
93956+
93957 if (vma->vm_flags & VM_ACCOUNT)
93958 nr_accounted += nrpages;
93959 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93960@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93961 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93962 vma->vm_prev = NULL;
93963 do {
93964+
93965+#ifdef CONFIG_PAX_SEGMEXEC
93966+ if (vma->vm_mirror) {
93967+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93968+ vma->vm_mirror->vm_mirror = NULL;
93969+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
93970+ vma->vm_mirror = NULL;
93971+ }
93972+#endif
93973+
93974 vma_rb_erase(vma, &mm->mm_rb);
93975 mm->map_count--;
93976 tail_vma = vma;
93977@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93978 struct vm_area_struct *new;
93979 int err = -ENOMEM;
93980
93981+#ifdef CONFIG_PAX_SEGMEXEC
93982+ struct vm_area_struct *vma_m, *new_m = NULL;
93983+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93984+#endif
93985+
93986 if (is_vm_hugetlb_page(vma) && (addr &
93987 ~(huge_page_mask(hstate_vma(vma)))))
93988 return -EINVAL;
93989
93990+#ifdef CONFIG_PAX_SEGMEXEC
93991+ vma_m = pax_find_mirror_vma(vma);
93992+#endif
93993+
93994 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93995 if (!new)
93996 goto out_err;
93997
93998+#ifdef CONFIG_PAX_SEGMEXEC
93999+ if (vma_m) {
94000+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94001+ if (!new_m) {
94002+ kmem_cache_free(vm_area_cachep, new);
94003+ goto out_err;
94004+ }
94005+ }
94006+#endif
94007+
94008 /* most fields are the same, copy all, and then fixup */
94009 *new = *vma;
94010
94011@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94012 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94013 }
94014
94015+#ifdef CONFIG_PAX_SEGMEXEC
94016+ if (vma_m) {
94017+ *new_m = *vma_m;
94018+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94019+ new_m->vm_mirror = new;
94020+ new->vm_mirror = new_m;
94021+
94022+ if (new_below)
94023+ new_m->vm_end = addr_m;
94024+ else {
94025+ new_m->vm_start = addr_m;
94026+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94027+ }
94028+ }
94029+#endif
94030+
94031 err = vma_dup_policy(vma, new);
94032 if (err)
94033 goto out_free_vma;
94034@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94035 else
94036 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94037
94038+#ifdef CONFIG_PAX_SEGMEXEC
94039+ if (!err && vma_m) {
94040+ struct mempolicy *pol = vma_policy(new);
94041+
94042+ if (anon_vma_clone(new_m, vma_m))
94043+ goto out_free_mpol;
94044+
94045+ mpol_get(pol);
94046+ set_vma_policy(new_m, pol);
94047+
94048+ if (new_m->vm_file)
94049+ get_file(new_m->vm_file);
94050+
94051+ if (new_m->vm_ops && new_m->vm_ops->open)
94052+ new_m->vm_ops->open(new_m);
94053+
94054+ if (new_below)
94055+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94056+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94057+ else
94058+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94059+
94060+ if (err) {
94061+ if (new_m->vm_ops && new_m->vm_ops->close)
94062+ new_m->vm_ops->close(new_m);
94063+ if (new_m->vm_file)
94064+ fput(new_m->vm_file);
94065+ mpol_put(pol);
94066+ }
94067+ }
94068+#endif
94069+
94070 /* Success. */
94071 if (!err)
94072 return 0;
94073@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94074 new->vm_ops->close(new);
94075 if (new->vm_file)
94076 fput(new->vm_file);
94077- unlink_anon_vmas(new);
94078 out_free_mpol:
94079 mpol_put(vma_policy(new));
94080 out_free_vma:
94081+
94082+#ifdef CONFIG_PAX_SEGMEXEC
94083+ if (new_m) {
94084+ unlink_anon_vmas(new_m);
94085+ kmem_cache_free(vm_area_cachep, new_m);
94086+ }
94087+#endif
94088+
94089+ unlink_anon_vmas(new);
94090 kmem_cache_free(vm_area_cachep, new);
94091 out_err:
94092 return err;
94093@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94094 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94095 unsigned long addr, int new_below)
94096 {
94097+
94098+#ifdef CONFIG_PAX_SEGMEXEC
94099+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94100+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94101+ if (mm->map_count >= sysctl_max_map_count-1)
94102+ return -ENOMEM;
94103+ } else
94104+#endif
94105+
94106 if (mm->map_count >= sysctl_max_map_count)
94107 return -ENOMEM;
94108
94109@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94110 * work. This now handles partial unmappings.
94111 * Jeremy Fitzhardinge <jeremy@goop.org>
94112 */
94113+#ifdef CONFIG_PAX_SEGMEXEC
94114 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94115 {
94116+ int ret = __do_munmap(mm, start, len);
94117+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94118+ return ret;
94119+
94120+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94121+}
94122+
94123+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94124+#else
94125+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94126+#endif
94127+{
94128 unsigned long end;
94129 struct vm_area_struct *vma, *prev, *last;
94130
94131+ /*
94132+ * mm->mmap_sem is required to protect against another thread
94133+ * changing the mappings in case we sleep.
94134+ */
94135+ verify_mm_writelocked(mm);
94136+
94137 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94138 return -EINVAL;
94139
94140@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94141 /* Fix up all other VM information */
94142 remove_vma_list(mm, vma);
94143
94144+ track_exec_limit(mm, start, end, 0UL);
94145+
94146 return 0;
94147 }
94148
94149@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94150 int ret;
94151 struct mm_struct *mm = current->mm;
94152
94153+
94154+#ifdef CONFIG_PAX_SEGMEXEC
94155+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94156+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94157+ return -EINVAL;
94158+#endif
94159+
94160 down_write(&mm->mmap_sem);
94161 ret = do_munmap(mm, start, len);
94162 up_write(&mm->mmap_sem);
94163@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94164 return vm_munmap(addr, len);
94165 }
94166
94167-static inline void verify_mm_writelocked(struct mm_struct *mm)
94168-{
94169-#ifdef CONFIG_DEBUG_VM
94170- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94171- WARN_ON(1);
94172- up_read(&mm->mmap_sem);
94173- }
94174-#endif
94175-}
94176-
94177 /*
94178 * this is really a simplified "do_mmap". it only handles
94179 * anonymous maps. eventually we may be able to do some
94180@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94181 struct rb_node ** rb_link, * rb_parent;
94182 pgoff_t pgoff = addr >> PAGE_SHIFT;
94183 int error;
94184+ unsigned long charged;
94185
94186 len = PAGE_ALIGN(len);
94187 if (!len)
94188@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94189
94190 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94191
94192+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94193+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94194+ flags &= ~VM_EXEC;
94195+
94196+#ifdef CONFIG_PAX_MPROTECT
94197+ if (mm->pax_flags & MF_PAX_MPROTECT)
94198+ flags &= ~VM_MAYEXEC;
94199+#endif
94200+
94201+ }
94202+#endif
94203+
94204 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94205 if (error & ~PAGE_MASK)
94206 return error;
94207
94208+ charged = len >> PAGE_SHIFT;
94209+
94210 error = mlock_future_check(mm, mm->def_flags, len);
94211 if (error)
94212 return error;
94213@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94214 /*
94215 * Clear old maps. this also does some error checking for us
94216 */
94217- munmap_back:
94218 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94219 if (do_munmap(mm, addr, len))
94220 return -ENOMEM;
94221- goto munmap_back;
94222+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94223 }
94224
94225 /* Check against address space limits *after* clearing old maps... */
94226- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94227+ if (!may_expand_vm(mm, charged))
94228 return -ENOMEM;
94229
94230 if (mm->map_count > sysctl_max_map_count)
94231 return -ENOMEM;
94232
94233- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94234+ if (security_vm_enough_memory_mm(mm, charged))
94235 return -ENOMEM;
94236
94237 /* Can we just expand an old private anonymous mapping? */
94238@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94239 */
94240 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94241 if (!vma) {
94242- vm_unacct_memory(len >> PAGE_SHIFT);
94243+ vm_unacct_memory(charged);
94244 return -ENOMEM;
94245 }
94246
94247@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94248 vma_link(mm, vma, prev, rb_link, rb_parent);
94249 out:
94250 perf_event_mmap(vma);
94251- mm->total_vm += len >> PAGE_SHIFT;
94252+ mm->total_vm += charged;
94253 if (flags & VM_LOCKED)
94254- mm->locked_vm += (len >> PAGE_SHIFT);
94255+ mm->locked_vm += charged;
94256 vma->vm_flags |= VM_SOFTDIRTY;
94257+ track_exec_limit(mm, addr, addr + len, flags);
94258 return addr;
94259 }
94260
94261@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94262 while (vma) {
94263 if (vma->vm_flags & VM_ACCOUNT)
94264 nr_accounted += vma_pages(vma);
94265+ vma->vm_mirror = NULL;
94266 vma = remove_vma(vma);
94267 }
94268 vm_unacct_memory(nr_accounted);
94269@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94270 struct vm_area_struct *prev;
94271 struct rb_node **rb_link, *rb_parent;
94272
94273+#ifdef CONFIG_PAX_SEGMEXEC
94274+ struct vm_area_struct *vma_m = NULL;
94275+#endif
94276+
94277+ if (security_mmap_addr(vma->vm_start))
94278+ return -EPERM;
94279+
94280 /*
94281 * The vm_pgoff of a purely anonymous vma should be irrelevant
94282 * until its first write fault, when page's anon_vma and index
94283@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94284 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94285 return -ENOMEM;
94286
94287+#ifdef CONFIG_PAX_SEGMEXEC
94288+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94289+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94290+ if (!vma_m)
94291+ return -ENOMEM;
94292+ }
94293+#endif
94294+
94295 vma_link(mm, vma, prev, rb_link, rb_parent);
94296+
94297+#ifdef CONFIG_PAX_SEGMEXEC
94298+ if (vma_m)
94299+ BUG_ON(pax_mirror_vma(vma_m, vma));
94300+#endif
94301+
94302 return 0;
94303 }
94304
94305@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94306 struct rb_node **rb_link, *rb_parent;
94307 bool faulted_in_anon_vma = true;
94308
94309+ BUG_ON(vma->vm_mirror);
94310+
94311 /*
94312 * If anonymous vma has not yet been faulted, update new pgoff
94313 * to match new location, to increase its chance of merging.
94314@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94315 return NULL;
94316 }
94317
94318+#ifdef CONFIG_PAX_SEGMEXEC
94319+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94320+{
94321+ struct vm_area_struct *prev_m;
94322+ struct rb_node **rb_link_m, *rb_parent_m;
94323+ struct mempolicy *pol_m;
94324+
94325+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94326+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94327+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94328+ *vma_m = *vma;
94329+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94330+ if (anon_vma_clone(vma_m, vma))
94331+ return -ENOMEM;
94332+ pol_m = vma_policy(vma_m);
94333+ mpol_get(pol_m);
94334+ set_vma_policy(vma_m, pol_m);
94335+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94336+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94337+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94338+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94339+ if (vma_m->vm_file)
94340+ get_file(vma_m->vm_file);
94341+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94342+ vma_m->vm_ops->open(vma_m);
94343+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94344+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94345+ vma_m->vm_mirror = vma;
94346+ vma->vm_mirror = vma_m;
94347+ return 0;
94348+}
94349+#endif
94350+
94351 /*
94352 * Return true if the calling process may expand its vm space by the passed
94353 * number of pages
94354@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94355
94356 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94357
94358+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94359 if (cur + npages > lim)
94360 return 0;
94361 return 1;
94362@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94363 vma->vm_start = addr;
94364 vma->vm_end = addr + len;
94365
94366+#ifdef CONFIG_PAX_MPROTECT
94367+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94368+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94369+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94370+ return -EPERM;
94371+ if (!(vm_flags & VM_EXEC))
94372+ vm_flags &= ~VM_MAYEXEC;
94373+#else
94374+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94375+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94376+#endif
94377+ else
94378+ vm_flags &= ~VM_MAYWRITE;
94379+ }
94380+#endif
94381+
94382 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94383 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94384
94385diff --git a/mm/mprotect.c b/mm/mprotect.c
94386index 769a67a..414d24f 100644
94387--- a/mm/mprotect.c
94388+++ b/mm/mprotect.c
94389@@ -24,10 +24,18 @@
94390 #include <linux/migrate.h>
94391 #include <linux/perf_event.h>
94392 #include <linux/ksm.h>
94393+#include <linux/sched/sysctl.h>
94394+
94395+#ifdef CONFIG_PAX_MPROTECT
94396+#include <linux/elf.h>
94397+#include <linux/binfmts.h>
94398+#endif
94399+
94400 #include <asm/uaccess.h>
94401 #include <asm/pgtable.h>
94402 #include <asm/cacheflush.h>
94403 #include <asm/tlbflush.h>
94404+#include <asm/mmu_context.h>
94405
94406 #ifndef pgprot_modify
94407 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94408@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94409 return pages;
94410 }
94411
94412+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94413+/* called while holding the mmap semaphor for writing except stack expansion */
94414+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94415+{
94416+ unsigned long oldlimit, newlimit = 0UL;
94417+
94418+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94419+ return;
94420+
94421+ spin_lock(&mm->page_table_lock);
94422+ oldlimit = mm->context.user_cs_limit;
94423+ if ((prot & VM_EXEC) && oldlimit < end)
94424+ /* USER_CS limit moved up */
94425+ newlimit = end;
94426+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94427+ /* USER_CS limit moved down */
94428+ newlimit = start;
94429+
94430+ if (newlimit) {
94431+ mm->context.user_cs_limit = newlimit;
94432+
94433+#ifdef CONFIG_SMP
94434+ wmb();
94435+ cpus_clear(mm->context.cpu_user_cs_mask);
94436+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94437+#endif
94438+
94439+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94440+ }
94441+ spin_unlock(&mm->page_table_lock);
94442+ if (newlimit == end) {
94443+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94444+
94445+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94446+ if (is_vm_hugetlb_page(vma))
94447+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94448+ else
94449+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94450+ }
94451+}
94452+#endif
94453+
94454 int
94455 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94456 unsigned long start, unsigned long end, unsigned long newflags)
94457@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94458 int error;
94459 int dirty_accountable = 0;
94460
94461+#ifdef CONFIG_PAX_SEGMEXEC
94462+ struct vm_area_struct *vma_m = NULL;
94463+ unsigned long start_m, end_m;
94464+
94465+ start_m = start + SEGMEXEC_TASK_SIZE;
94466+ end_m = end + SEGMEXEC_TASK_SIZE;
94467+#endif
94468+
94469 if (newflags == oldflags) {
94470 *pprev = vma;
94471 return 0;
94472 }
94473
94474+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94475+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94476+
94477+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94478+ return -ENOMEM;
94479+
94480+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94481+ return -ENOMEM;
94482+ }
94483+
94484 /*
94485 * If we make a private mapping writable we increase our commit;
94486 * but (without finer accounting) cannot reduce our commit if we
94487@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94488 }
94489 }
94490
94491+#ifdef CONFIG_PAX_SEGMEXEC
94492+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94493+ if (start != vma->vm_start) {
94494+ error = split_vma(mm, vma, start, 1);
94495+ if (error)
94496+ goto fail;
94497+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94498+ *pprev = (*pprev)->vm_next;
94499+ }
94500+
94501+ if (end != vma->vm_end) {
94502+ error = split_vma(mm, vma, end, 0);
94503+ if (error)
94504+ goto fail;
94505+ }
94506+
94507+ if (pax_find_mirror_vma(vma)) {
94508+ error = __do_munmap(mm, start_m, end_m - start_m);
94509+ if (error)
94510+ goto fail;
94511+ } else {
94512+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94513+ if (!vma_m) {
94514+ error = -ENOMEM;
94515+ goto fail;
94516+ }
94517+ vma->vm_flags = newflags;
94518+ error = pax_mirror_vma(vma_m, vma);
94519+ if (error) {
94520+ vma->vm_flags = oldflags;
94521+ goto fail;
94522+ }
94523+ }
94524+ }
94525+#endif
94526+
94527 /*
94528 * First try to merge with previous and/or next vma.
94529 */
94530@@ -277,9 +381,21 @@ success:
94531 * vm_flags and vm_page_prot are protected by the mmap_sem
94532 * held in write mode.
94533 */
94534+
94535+#ifdef CONFIG_PAX_SEGMEXEC
94536+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94537+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94538+#endif
94539+
94540 vma->vm_flags = newflags;
94541+
94542+#ifdef CONFIG_PAX_MPROTECT
94543+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94544+ mm->binfmt->handle_mprotect(vma, newflags);
94545+#endif
94546+
94547 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94548- vm_get_page_prot(newflags));
94549+ vm_get_page_prot(vma->vm_flags));
94550
94551 if (vma_wants_writenotify(vma)) {
94552 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94553@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94554 end = start + len;
94555 if (end <= start)
94556 return -ENOMEM;
94557+
94558+#ifdef CONFIG_PAX_SEGMEXEC
94559+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94560+ if (end > SEGMEXEC_TASK_SIZE)
94561+ return -EINVAL;
94562+ } else
94563+#endif
94564+
94565+ if (end > TASK_SIZE)
94566+ return -EINVAL;
94567+
94568 if (!arch_validate_prot(prot))
94569 return -EINVAL;
94570
94571@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94572 /*
94573 * Does the application expect PROT_READ to imply PROT_EXEC:
94574 */
94575- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94576+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94577 prot |= PROT_EXEC;
94578
94579 vm_flags = calc_vm_prot_bits(prot);
94580@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94581 if (start > vma->vm_start)
94582 prev = vma;
94583
94584+#ifdef CONFIG_PAX_MPROTECT
94585+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94586+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94587+#endif
94588+
94589 for (nstart = start ; ; ) {
94590 unsigned long newflags;
94591
94592@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94593
94594 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94595 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94596+ if (prot & (PROT_WRITE | PROT_EXEC))
94597+ gr_log_rwxmprotect(vma);
94598+
94599+ error = -EACCES;
94600+ goto out;
94601+ }
94602+
94603+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94604 error = -EACCES;
94605 goto out;
94606 }
94607@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94608 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94609 if (error)
94610 goto out;
94611+
94612+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94613+
94614 nstart = tmp;
94615
94616 if (nstart < prev->vm_end)
94617diff --git a/mm/mremap.c b/mm/mremap.c
94618index 0843feb..4f5b2e6 100644
94619--- a/mm/mremap.c
94620+++ b/mm/mremap.c
94621@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94622 continue;
94623 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94624 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94625+
94626+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94627+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94628+ pte = pte_exprotect(pte);
94629+#endif
94630+
94631 pte = move_soft_dirty_pte(pte);
94632 set_pte_at(mm, new_addr, new_pte, pte);
94633 }
94634@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94635 if (is_vm_hugetlb_page(vma))
94636 goto Einval;
94637
94638+#ifdef CONFIG_PAX_SEGMEXEC
94639+ if (pax_find_mirror_vma(vma))
94640+ goto Einval;
94641+#endif
94642+
94643 /* We can't remap across vm area boundaries */
94644 if (old_len > vma->vm_end - addr)
94645 goto Efault;
94646@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94647 unsigned long ret = -EINVAL;
94648 unsigned long charged = 0;
94649 unsigned long map_flags;
94650+ unsigned long pax_task_size = TASK_SIZE;
94651
94652 if (new_addr & ~PAGE_MASK)
94653 goto out;
94654
94655- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94656+#ifdef CONFIG_PAX_SEGMEXEC
94657+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94658+ pax_task_size = SEGMEXEC_TASK_SIZE;
94659+#endif
94660+
94661+ pax_task_size -= PAGE_SIZE;
94662+
94663+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94664 goto out;
94665
94666 /* Check if the location we're moving into overlaps the
94667 * old location at all, and fail if it does.
94668 */
94669- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94670- goto out;
94671-
94672- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94673+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94674 goto out;
94675
94676 ret = do_munmap(mm, new_addr, new_len);
94677@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94678 unsigned long ret = -EINVAL;
94679 unsigned long charged = 0;
94680 bool locked = false;
94681+ unsigned long pax_task_size = TASK_SIZE;
94682
94683 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94684 return ret;
94685@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94686 if (!new_len)
94687 return ret;
94688
94689+#ifdef CONFIG_PAX_SEGMEXEC
94690+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94691+ pax_task_size = SEGMEXEC_TASK_SIZE;
94692+#endif
94693+
94694+ pax_task_size -= PAGE_SIZE;
94695+
94696+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94697+ old_len > pax_task_size || addr > pax_task_size-old_len)
94698+ return ret;
94699+
94700 down_write(&current->mm->mmap_sem);
94701
94702 if (flags & MREMAP_FIXED) {
94703@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94704 new_addr = addr;
94705 }
94706 ret = addr;
94707+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94708 goto out;
94709 }
94710 }
94711@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94712 goto out;
94713 }
94714
94715+ map_flags = vma->vm_flags;
94716 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94717+ if (!(ret & ~PAGE_MASK)) {
94718+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94719+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94720+ }
94721 }
94722 out:
94723 if (ret & ~PAGE_MASK)
94724diff --git a/mm/nommu.c b/mm/nommu.c
94725index 8740213..f87e25b 100644
94726--- a/mm/nommu.c
94727+++ b/mm/nommu.c
94728@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94729 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94730 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94731 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94732-int heap_stack_gap = 0;
94733
94734 atomic_long_t mmap_pages_allocated;
94735
94736@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94737 EXPORT_SYMBOL(find_vma);
94738
94739 /*
94740- * find a VMA
94741- * - we don't extend stack VMAs under NOMMU conditions
94742- */
94743-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94744-{
94745- return find_vma(mm, addr);
94746-}
94747-
94748-/*
94749 * expand a stack to a given address
94750 * - not supported under NOMMU conditions
94751 */
94752@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94753
94754 /* most fields are the same, copy all, and then fixup */
94755 *new = *vma;
94756+ INIT_LIST_HEAD(&new->anon_vma_chain);
94757 *region = *vma->vm_region;
94758 new->vm_region = region;
94759
94760@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94761 }
94762 EXPORT_SYMBOL(generic_file_remap_pages);
94763
94764-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94765- unsigned long addr, void *buf, int len, int write)
94766+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94767+ unsigned long addr, void *buf, size_t len, int write)
94768 {
94769 struct vm_area_struct *vma;
94770
94771@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94772 *
94773 * The caller must hold a reference on @mm.
94774 */
94775-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94776- void *buf, int len, int write)
94777+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94778+ void *buf, size_t len, int write)
94779 {
94780 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94781 }
94782@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94783 * Access another process' address space.
94784 * - source/target buffer must be kernel space
94785 */
94786-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94787+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94788 {
94789 struct mm_struct *mm;
94790
94791diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94792index 7106cb1..0805f48 100644
94793--- a/mm/page-writeback.c
94794+++ b/mm/page-writeback.c
94795@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94796 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94797 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94798 */
94799-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94800+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94801 unsigned long thresh,
94802 unsigned long bg_thresh,
94803 unsigned long dirty,
94804diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94805index 7387a67..3994687 100644
94806--- a/mm/page_alloc.c
94807+++ b/mm/page_alloc.c
94808@@ -61,6 +61,7 @@
94809 #include <linux/page-debug-flags.h>
94810 #include <linux/hugetlb.h>
94811 #include <linux/sched/rt.h>
94812+#include <linux/random.h>
94813
94814 #include <asm/sections.h>
94815 #include <asm/tlbflush.h>
94816@@ -354,7 +355,7 @@ out:
94817 * This usage means that zero-order pages may not be compound.
94818 */
94819
94820-static void free_compound_page(struct page *page)
94821+void free_compound_page(struct page *page)
94822 {
94823 __free_pages_ok(page, compound_order(page));
94824 }
94825@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94826 int i;
94827 int bad = 0;
94828
94829+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94830+ unsigned long index = 1UL << order;
94831+#endif
94832+
94833 trace_mm_page_free(page, order);
94834 kmemcheck_free_shadow(page, order);
94835
94836@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94837 debug_check_no_obj_freed(page_address(page),
94838 PAGE_SIZE << order);
94839 }
94840+
94841+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94842+ for (; index; --index)
94843+ sanitize_highpage(page + index - 1);
94844+#endif
94845+
94846 arch_free_page(page, order);
94847 kernel_map_pages(page, 1 << order, 0);
94848
94849@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94850 local_irq_restore(flags);
94851 }
94852
94853+#ifdef CONFIG_PAX_LATENT_ENTROPY
94854+bool __meminitdata extra_latent_entropy;
94855+
94856+static int __init setup_pax_extra_latent_entropy(char *str)
94857+{
94858+ extra_latent_entropy = true;
94859+ return 0;
94860+}
94861+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94862+
94863+volatile u64 latent_entropy __latent_entropy;
94864+EXPORT_SYMBOL(latent_entropy);
94865+#endif
94866+
94867 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94868 {
94869 unsigned int nr_pages = 1 << order;
94870@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94871 __ClearPageReserved(p);
94872 set_page_count(p, 0);
94873
94874+#ifdef CONFIG_PAX_LATENT_ENTROPY
94875+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94876+ u64 hash = 0;
94877+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94878+ const u64 *data = lowmem_page_address(page);
94879+
94880+ for (index = 0; index < end; index++)
94881+ hash ^= hash + data[index];
94882+ latent_entropy ^= hash;
94883+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94884+ }
94885+#endif
94886+
94887 page_zone(page)->managed_pages += nr_pages;
94888 set_page_refcounted(page);
94889 __free_pages(page, order);
94890@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94891 arch_alloc_page(page, order);
94892 kernel_map_pages(page, 1 << order, 1);
94893
94894+#ifndef CONFIG_PAX_MEMORY_SANITIZE
94895 if (gfp_flags & __GFP_ZERO)
94896 prep_zero_page(page, order, gfp_flags);
94897+#endif
94898
94899 if (order && (gfp_flags & __GFP_COMP))
94900 prep_compound_page(page, order);
94901diff --git a/mm/page_io.c b/mm/page_io.c
94902index 7c59ef6..1358905 100644
94903--- a/mm/page_io.c
94904+++ b/mm/page_io.c
94905@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94906 struct file *swap_file = sis->swap_file;
94907 struct address_space *mapping = swap_file->f_mapping;
94908 struct iovec iov = {
94909- .iov_base = kmap(page),
94910+ .iov_base = (void __force_user *)kmap(page),
94911 .iov_len = PAGE_SIZE,
94912 };
94913
94914diff --git a/mm/percpu.c b/mm/percpu.c
94915index 036cfe0..980d0fa 100644
94916--- a/mm/percpu.c
94917+++ b/mm/percpu.c
94918@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94919 static unsigned int pcpu_high_unit_cpu __read_mostly;
94920
94921 /* the address of the first chunk which starts with the kernel static area */
94922-void *pcpu_base_addr __read_mostly;
94923+void *pcpu_base_addr __read_only;
94924 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94925
94926 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94927diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94928index fd26d04..0cea1b0 100644
94929--- a/mm/process_vm_access.c
94930+++ b/mm/process_vm_access.c
94931@@ -13,6 +13,7 @@
94932 #include <linux/uio.h>
94933 #include <linux/sched.h>
94934 #include <linux/highmem.h>
94935+#include <linux/security.h>
94936 #include <linux/ptrace.h>
94937 #include <linux/slab.h>
94938 #include <linux/syscalls.h>
94939@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94940 size_t iov_l_curr_offset = 0;
94941 ssize_t iov_len;
94942
94943+ return -ENOSYS; // PaX: until properly audited
94944+
94945 /*
94946 * Work out how many pages of struct pages we're going to need
94947 * when eventually calling get_user_pages
94948 */
94949 for (i = 0; i < riovcnt; i++) {
94950 iov_len = rvec[i].iov_len;
94951- if (iov_len > 0) {
94952- nr_pages_iov = ((unsigned long)rvec[i].iov_base
94953- + iov_len)
94954- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94955- / PAGE_SIZE + 1;
94956- nr_pages = max(nr_pages, nr_pages_iov);
94957- }
94958+ if (iov_len <= 0)
94959+ continue;
94960+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94961+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94962+ nr_pages = max(nr_pages, nr_pages_iov);
94963 }
94964
94965 if (nr_pages == 0)
94966@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94967 goto free_proc_pages;
94968 }
94969
94970+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94971+ rc = -EPERM;
94972+ goto put_task_struct;
94973+ }
94974+
94975 mm = mm_access(task, PTRACE_MODE_ATTACH);
94976 if (!mm || IS_ERR(mm)) {
94977 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94978diff --git a/mm/rmap.c b/mm/rmap.c
94979index d3cbac5..0788da4 100644
94980--- a/mm/rmap.c
94981+++ b/mm/rmap.c
94982@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94983 struct anon_vma *anon_vma = vma->anon_vma;
94984 struct anon_vma_chain *avc;
94985
94986+#ifdef CONFIG_PAX_SEGMEXEC
94987+ struct anon_vma_chain *avc_m = NULL;
94988+#endif
94989+
94990 might_sleep();
94991 if (unlikely(!anon_vma)) {
94992 struct mm_struct *mm = vma->vm_mm;
94993@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94994 if (!avc)
94995 goto out_enomem;
94996
94997+#ifdef CONFIG_PAX_SEGMEXEC
94998+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94999+ if (!avc_m)
95000+ goto out_enomem_free_avc;
95001+#endif
95002+
95003 anon_vma = find_mergeable_anon_vma(vma);
95004 allocated = NULL;
95005 if (!anon_vma) {
95006@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95007 /* page_table_lock to protect against threads */
95008 spin_lock(&mm->page_table_lock);
95009 if (likely(!vma->anon_vma)) {
95010+
95011+#ifdef CONFIG_PAX_SEGMEXEC
95012+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95013+
95014+ if (vma_m) {
95015+ BUG_ON(vma_m->anon_vma);
95016+ vma_m->anon_vma = anon_vma;
95017+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95018+ avc_m = NULL;
95019+ }
95020+#endif
95021+
95022 vma->anon_vma = anon_vma;
95023 anon_vma_chain_link(vma, avc, anon_vma);
95024 allocated = NULL;
95025@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95026
95027 if (unlikely(allocated))
95028 put_anon_vma(allocated);
95029+
95030+#ifdef CONFIG_PAX_SEGMEXEC
95031+ if (unlikely(avc_m))
95032+ anon_vma_chain_free(avc_m);
95033+#endif
95034+
95035 if (unlikely(avc))
95036 anon_vma_chain_free(avc);
95037 }
95038 return 0;
95039
95040 out_enomem_free_avc:
95041+
95042+#ifdef CONFIG_PAX_SEGMEXEC
95043+ if (avc_m)
95044+ anon_vma_chain_free(avc_m);
95045+#endif
95046+
95047 anon_vma_chain_free(avc);
95048 out_enomem:
95049 return -ENOMEM;
95050@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95051 * Attach the anon_vmas from src to dst.
95052 * Returns 0 on success, -ENOMEM on failure.
95053 */
95054-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95055+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95056 {
95057 struct anon_vma_chain *avc, *pavc;
95058 struct anon_vma *root = NULL;
95059@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95060 * the corresponding VMA in the parent process is attached to.
95061 * Returns 0 on success, non-zero on failure.
95062 */
95063-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95064+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95065 {
95066 struct anon_vma_chain *avc;
95067 struct anon_vma *anon_vma;
95068@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95069 void __init anon_vma_init(void)
95070 {
95071 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95072- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95073- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95074+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95075+ anon_vma_ctor);
95076+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95077+ SLAB_PANIC|SLAB_NO_SANITIZE);
95078 }
95079
95080 /*
95081diff --git a/mm/shmem.c b/mm/shmem.c
95082index 1f18c9d..3e03d33 100644
95083--- a/mm/shmem.c
95084+++ b/mm/shmem.c
95085@@ -33,7 +33,7 @@
95086 #include <linux/swap.h>
95087 #include <linux/aio.h>
95088
95089-static struct vfsmount *shm_mnt;
95090+struct vfsmount *shm_mnt;
95091
95092 #ifdef CONFIG_SHMEM
95093 /*
95094@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95095 #define BOGO_DIRENT_SIZE 20
95096
95097 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95098-#define SHORT_SYMLINK_LEN 128
95099+#define SHORT_SYMLINK_LEN 64
95100
95101 /*
95102 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95103@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95104 static int shmem_xattr_validate(const char *name)
95105 {
95106 struct { const char *prefix; size_t len; } arr[] = {
95107+
95108+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95109+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95110+#endif
95111+
95112 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95113 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95114 };
95115@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95116 if (err)
95117 return err;
95118
95119+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95120+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95121+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95122+ return -EOPNOTSUPP;
95123+ if (size > 8)
95124+ return -EINVAL;
95125+ }
95126+#endif
95127+
95128 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95129 }
95130
95131@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95132 int err = -ENOMEM;
95133
95134 /* Round up to L1_CACHE_BYTES to resist false sharing */
95135- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95136- L1_CACHE_BYTES), GFP_KERNEL);
95137+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95138 if (!sbinfo)
95139 return -ENOMEM;
95140
95141diff --git a/mm/slab.c b/mm/slab.c
95142index b264214..83872cd 100644
95143--- a/mm/slab.c
95144+++ b/mm/slab.c
95145@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95146 if ((x)->max_freeable < i) \
95147 (x)->max_freeable = i; \
95148 } while (0)
95149-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95150-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95151-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95152-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95153+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95154+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95155+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95156+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95157+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95158+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95159 #else
95160 #define STATS_INC_ACTIVE(x) do { } while (0)
95161 #define STATS_DEC_ACTIVE(x) do { } while (0)
95162@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95163 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95164 #define STATS_INC_FREEHIT(x) do { } while (0)
95165 #define STATS_INC_FREEMISS(x) do { } while (0)
95166+#define STATS_INC_SANITIZED(x) do { } while (0)
95167+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95168 #endif
95169
95170 #if DEBUG
95171@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95172 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95173 */
95174 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95175- const struct page *page, void *obj)
95176+ const struct page *page, const void *obj)
95177 {
95178 u32 offset = (obj - page->s_mem);
95179 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95180@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95181 */
95182
95183 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95184- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95185+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95186
95187 if (INDEX_AC != INDEX_NODE)
95188 kmalloc_caches[INDEX_NODE] =
95189 create_kmalloc_cache("kmalloc-node",
95190- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95191+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95192
95193 slab_early_init = 0;
95194
95195@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95196 struct array_cache *ac = cpu_cache_get(cachep);
95197
95198 check_irq_off();
95199+
95200+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95201+ if (pax_sanitize_slab) {
95202+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95203+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95204+
95205+ if (cachep->ctor)
95206+ cachep->ctor(objp);
95207+
95208+ STATS_INC_SANITIZED(cachep);
95209+ } else
95210+ STATS_INC_NOT_SANITIZED(cachep);
95211+ }
95212+#endif
95213+
95214 kmemleak_free_recursive(objp, cachep->flags);
95215 objp = cache_free_debugcheck(cachep, objp, caller);
95216
95217@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95218
95219 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95220 return;
95221+ VM_BUG_ON(!virt_addr_valid(objp));
95222 local_irq_save(flags);
95223 kfree_debugcheck(objp);
95224 c = virt_to_cache(objp);
95225@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95226 }
95227 /* cpu stats */
95228 {
95229- unsigned long allochit = atomic_read(&cachep->allochit);
95230- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95231- unsigned long freehit = atomic_read(&cachep->freehit);
95232- unsigned long freemiss = atomic_read(&cachep->freemiss);
95233+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95234+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95235+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95236+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95237
95238 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95239 allochit, allocmiss, freehit, freemiss);
95240 }
95241+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95242+ {
95243+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95244+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95245+
95246+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95247+ }
95248+#endif
95249 #endif
95250 }
95251
95252@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95253 static int __init slab_proc_init(void)
95254 {
95255 #ifdef CONFIG_DEBUG_SLAB_LEAK
95256- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95257+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95258 #endif
95259 return 0;
95260 }
95261 module_init(slab_proc_init);
95262 #endif
95263
95264+bool is_usercopy_object(const void *ptr)
95265+{
95266+ struct page *page;
95267+ struct kmem_cache *cachep;
95268+
95269+ if (ZERO_OR_NULL_PTR(ptr))
95270+ return false;
95271+
95272+ if (!slab_is_available())
95273+ return false;
95274+
95275+ if (!virt_addr_valid(ptr))
95276+ return false;
95277+
95278+ page = virt_to_head_page(ptr);
95279+
95280+ if (!PageSlab(page))
95281+ return false;
95282+
95283+ cachep = page->slab_cache;
95284+ return cachep->flags & SLAB_USERCOPY;
95285+}
95286+
95287+#ifdef CONFIG_PAX_USERCOPY
95288+const char *check_heap_object(const void *ptr, unsigned long n)
95289+{
95290+ struct page *page;
95291+ struct kmem_cache *cachep;
95292+ unsigned int objnr;
95293+ unsigned long offset;
95294+
95295+ if (ZERO_OR_NULL_PTR(ptr))
95296+ return "<null>";
95297+
95298+ if (!virt_addr_valid(ptr))
95299+ return NULL;
95300+
95301+ page = virt_to_head_page(ptr);
95302+
95303+ if (!PageSlab(page))
95304+ return NULL;
95305+
95306+ cachep = page->slab_cache;
95307+ if (!(cachep->flags & SLAB_USERCOPY))
95308+ return cachep->name;
95309+
95310+ objnr = obj_to_index(cachep, page, ptr);
95311+ BUG_ON(objnr >= cachep->num);
95312+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95313+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95314+ return NULL;
95315+
95316+ return cachep->name;
95317+}
95318+#endif
95319+
95320 /**
95321 * ksize - get the actual amount of memory allocated for a given object
95322 * @objp: Pointer to the object
95323diff --git a/mm/slab.h b/mm/slab.h
95324index 8184a7c..ab27737 100644
95325--- a/mm/slab.h
95326+++ b/mm/slab.h
95327@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95328 /* The slab cache that manages slab cache information */
95329 extern struct kmem_cache *kmem_cache;
95330
95331+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95332+#ifdef CONFIG_X86_64
95333+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95334+#else
95335+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95336+#endif
95337+extern bool pax_sanitize_slab;
95338+#endif
95339+
95340 unsigned long calculate_alignment(unsigned long flags,
95341 unsigned long align, unsigned long size);
95342
95343@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95344
95345 /* Legal flag mask for kmem_cache_create(), for various configurations */
95346 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95347- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95348+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95349+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95350
95351 #if defined(CONFIG_DEBUG_SLAB)
95352 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95353@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95354 return s;
95355
95356 page = virt_to_head_page(x);
95357+
95358+ BUG_ON(!PageSlab(page));
95359+
95360 cachep = page->slab_cache;
95361 if (slab_equal_or_root(cachep, s))
95362 return cachep;
95363diff --git a/mm/slab_common.c b/mm/slab_common.c
95364index 1ec3c61..2067c11 100644
95365--- a/mm/slab_common.c
95366+++ b/mm/slab_common.c
95367@@ -23,11 +23,22 @@
95368
95369 #include "slab.h"
95370
95371-enum slab_state slab_state;
95372+enum slab_state slab_state __read_only;
95373 LIST_HEAD(slab_caches);
95374 DEFINE_MUTEX(slab_mutex);
95375 struct kmem_cache *kmem_cache;
95376
95377+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95378+bool pax_sanitize_slab __read_only = true;
95379+static int __init pax_sanitize_slab_setup(char *str)
95380+{
95381+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95382+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95383+ return 1;
95384+}
95385+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95386+#endif
95387+
95388 #ifdef CONFIG_DEBUG_VM
95389 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95390 size_t size)
95391@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95392 if (err)
95393 goto out_free_cache;
95394
95395- s->refcount = 1;
95396+ atomic_set(&s->refcount, 1);
95397 list_add(&s->list, &slab_caches);
95398 memcg_register_cache(s);
95399
95400@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95401
95402 get_online_cpus();
95403 mutex_lock(&slab_mutex);
95404- s->refcount--;
95405- if (!s->refcount) {
95406+ if (atomic_dec_and_test(&s->refcount)) {
95407 list_del(&s->list);
95408
95409 if (!__kmem_cache_shutdown(s)) {
95410@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95411 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95412 name, size, err);
95413
95414- s->refcount = -1; /* Exempt from merging for now */
95415+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95416 }
95417
95418 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95419@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95420
95421 create_boot_cache(s, name, size, flags);
95422 list_add(&s->list, &slab_caches);
95423- s->refcount = 1;
95424+ atomic_set(&s->refcount, 1);
95425 return s;
95426 }
95427
95428@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95429 EXPORT_SYMBOL(kmalloc_dma_caches);
95430 #endif
95431
95432+#ifdef CONFIG_PAX_USERCOPY_SLABS
95433+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95434+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95435+#endif
95436+
95437 /*
95438 * Conversion table for small slabs sizes / 8 to the index in the
95439 * kmalloc array. This is necessary for slabs < 192 since we have non power
95440@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95441 return kmalloc_dma_caches[index];
95442
95443 #endif
95444+
95445+#ifdef CONFIG_PAX_USERCOPY_SLABS
95446+ if (unlikely((flags & GFP_USERCOPY)))
95447+ return kmalloc_usercopy_caches[index];
95448+
95449+#endif
95450+
95451 return kmalloc_caches[index];
95452 }
95453
95454@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95455 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95456 if (!kmalloc_caches[i]) {
95457 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95458- 1 << i, flags);
95459+ 1 << i, SLAB_USERCOPY | flags);
95460 }
95461
95462 /*
95463@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95464 * earlier power of two caches
95465 */
95466 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95467- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95468+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95469
95470 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95471- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95472+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95473 }
95474
95475 /* Kmalloc array is now usable */
95476@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95477 }
95478 }
95479 #endif
95480+
95481+#ifdef CONFIG_PAX_USERCOPY_SLABS
95482+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95483+ struct kmem_cache *s = kmalloc_caches[i];
95484+
95485+ if (s) {
95486+ int size = kmalloc_size(i);
95487+ char *n = kasprintf(GFP_NOWAIT,
95488+ "usercopy-kmalloc-%d", size);
95489+
95490+ BUG_ON(!n);
95491+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95492+ size, SLAB_USERCOPY | flags);
95493+ }
95494+ }
95495+#endif
95496+
95497 }
95498 #endif /* !CONFIG_SLOB */
95499
95500@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95501 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95502 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95503 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95504+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95505+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95506+#endif
95507 #endif
95508 seq_putc(m, '\n');
95509 }
95510diff --git a/mm/slob.c b/mm/slob.c
95511index 4bf8809..98a6914 100644
95512--- a/mm/slob.c
95513+++ b/mm/slob.c
95514@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95515 /*
95516 * Return the size of a slob block.
95517 */
95518-static slobidx_t slob_units(slob_t *s)
95519+static slobidx_t slob_units(const slob_t *s)
95520 {
95521 if (s->units > 0)
95522 return s->units;
95523@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95524 /*
95525 * Return the next free slob block pointer after this one.
95526 */
95527-static slob_t *slob_next(slob_t *s)
95528+static slob_t *slob_next(const slob_t *s)
95529 {
95530 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95531 slobidx_t next;
95532@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95533 /*
95534 * Returns true if s is the last free block in its page.
95535 */
95536-static int slob_last(slob_t *s)
95537+static int slob_last(const slob_t *s)
95538 {
95539 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95540 }
95541
95542-static void *slob_new_pages(gfp_t gfp, int order, int node)
95543+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95544 {
95545- void *page;
95546+ struct page *page;
95547
95548 #ifdef CONFIG_NUMA
95549 if (node != NUMA_NO_NODE)
95550@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95551 if (!page)
95552 return NULL;
95553
95554- return page_address(page);
95555+ __SetPageSlab(page);
95556+ return page;
95557 }
95558
95559-static void slob_free_pages(void *b, int order)
95560+static void slob_free_pages(struct page *sp, int order)
95561 {
95562 if (current->reclaim_state)
95563 current->reclaim_state->reclaimed_slab += 1 << order;
95564- free_pages((unsigned long)b, order);
95565+ __ClearPageSlab(sp);
95566+ page_mapcount_reset(sp);
95567+ sp->private = 0;
95568+ __free_pages(sp, order);
95569 }
95570
95571 /*
95572@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95573
95574 /* Not enough space: must allocate a new page */
95575 if (!b) {
95576- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95577- if (!b)
95578+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95579+ if (!sp)
95580 return NULL;
95581- sp = virt_to_page(b);
95582- __SetPageSlab(sp);
95583+ b = page_address(sp);
95584
95585 spin_lock_irqsave(&slob_lock, flags);
95586 sp->units = SLOB_UNITS(PAGE_SIZE);
95587 sp->freelist = b;
95588+ sp->private = 0;
95589 INIT_LIST_HEAD(&sp->list);
95590 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95591 set_slob_page_free(sp, slob_list);
95592@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95593 if (slob_page_free(sp))
95594 clear_slob_page_free(sp);
95595 spin_unlock_irqrestore(&slob_lock, flags);
95596- __ClearPageSlab(sp);
95597- page_mapcount_reset(sp);
95598- slob_free_pages(b, 0);
95599+ slob_free_pages(sp, 0);
95600 return;
95601 }
95602
95603+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95604+ if (pax_sanitize_slab)
95605+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95606+#endif
95607+
95608 if (!slob_page_free(sp)) {
95609 /* This slob page is about to become partially free. Easy! */
95610 sp->units = units;
95611@@ -424,11 +431,10 @@ out:
95612 */
95613
95614 static __always_inline void *
95615-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95616+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95617 {
95618- unsigned int *m;
95619- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95620- void *ret;
95621+ slob_t *m;
95622+ void *ret = NULL;
95623
95624 gfp &= gfp_allowed_mask;
95625
95626@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95627
95628 if (!m)
95629 return NULL;
95630- *m = size;
95631+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95632+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95633+ m[0].units = size;
95634+ m[1].units = align;
95635 ret = (void *)m + align;
95636
95637 trace_kmalloc_node(caller, ret,
95638 size, size + align, gfp, node);
95639 } else {
95640 unsigned int order = get_order(size);
95641+ struct page *page;
95642
95643 if (likely(order))
95644 gfp |= __GFP_COMP;
95645- ret = slob_new_pages(gfp, order, node);
95646+ page = slob_new_pages(gfp, order, node);
95647+ if (page) {
95648+ ret = page_address(page);
95649+ page->private = size;
95650+ }
95651
95652 trace_kmalloc_node(caller, ret,
95653 size, PAGE_SIZE << order, gfp, node);
95654 }
95655
95656- kmemleak_alloc(ret, size, 1, gfp);
95657+ return ret;
95658+}
95659+
95660+static __always_inline void *
95661+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95662+{
95663+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95664+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95665+
95666+ if (!ZERO_OR_NULL_PTR(ret))
95667+ kmemleak_alloc(ret, size, 1, gfp);
95668 return ret;
95669 }
95670
95671@@ -493,34 +517,112 @@ void kfree(const void *block)
95672 return;
95673 kmemleak_free(block);
95674
95675+ VM_BUG_ON(!virt_addr_valid(block));
95676 sp = virt_to_page(block);
95677- if (PageSlab(sp)) {
95678+ VM_BUG_ON(!PageSlab(sp));
95679+ if (!sp->private) {
95680 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95681- unsigned int *m = (unsigned int *)(block - align);
95682- slob_free(m, *m + align);
95683- } else
95684+ slob_t *m = (slob_t *)(block - align);
95685+ slob_free(m, m[0].units + align);
95686+ } else {
95687+ __ClearPageSlab(sp);
95688+ page_mapcount_reset(sp);
95689+ sp->private = 0;
95690 __free_pages(sp, compound_order(sp));
95691+ }
95692 }
95693 EXPORT_SYMBOL(kfree);
95694
95695+bool is_usercopy_object(const void *ptr)
95696+{
95697+ if (!slab_is_available())
95698+ return false;
95699+
95700+ // PAX: TODO
95701+
95702+ return false;
95703+}
95704+
95705+#ifdef CONFIG_PAX_USERCOPY
95706+const char *check_heap_object(const void *ptr, unsigned long n)
95707+{
95708+ struct page *page;
95709+ const slob_t *free;
95710+ const void *base;
95711+ unsigned long flags;
95712+
95713+ if (ZERO_OR_NULL_PTR(ptr))
95714+ return "<null>";
95715+
95716+ if (!virt_addr_valid(ptr))
95717+ return NULL;
95718+
95719+ page = virt_to_head_page(ptr);
95720+ if (!PageSlab(page))
95721+ return NULL;
95722+
95723+ if (page->private) {
95724+ base = page;
95725+ if (base <= ptr && n <= page->private - (ptr - base))
95726+ return NULL;
95727+ return "<slob>";
95728+ }
95729+
95730+ /* some tricky double walking to find the chunk */
95731+ spin_lock_irqsave(&slob_lock, flags);
95732+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95733+ free = page->freelist;
95734+
95735+ while (!slob_last(free) && (void *)free <= ptr) {
95736+ base = free + slob_units(free);
95737+ free = slob_next(free);
95738+ }
95739+
95740+ while (base < (void *)free) {
95741+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95742+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95743+ int offset;
95744+
95745+ if (ptr < base + align)
95746+ break;
95747+
95748+ offset = ptr - base - align;
95749+ if (offset >= m) {
95750+ base += size;
95751+ continue;
95752+ }
95753+
95754+ if (n > m - offset)
95755+ break;
95756+
95757+ spin_unlock_irqrestore(&slob_lock, flags);
95758+ return NULL;
95759+ }
95760+
95761+ spin_unlock_irqrestore(&slob_lock, flags);
95762+ return "<slob>";
95763+}
95764+#endif
95765+
95766 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95767 size_t ksize(const void *block)
95768 {
95769 struct page *sp;
95770 int align;
95771- unsigned int *m;
95772+ slob_t *m;
95773
95774 BUG_ON(!block);
95775 if (unlikely(block == ZERO_SIZE_PTR))
95776 return 0;
95777
95778 sp = virt_to_page(block);
95779- if (unlikely(!PageSlab(sp)))
95780- return PAGE_SIZE << compound_order(sp);
95781+ VM_BUG_ON(!PageSlab(sp));
95782+ if (sp->private)
95783+ return sp->private;
95784
95785 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95786- m = (unsigned int *)(block - align);
95787- return SLOB_UNITS(*m) * SLOB_UNIT;
95788+ m = (slob_t *)(block - align);
95789+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95790 }
95791 EXPORT_SYMBOL(ksize);
95792
95793@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95794
95795 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95796 {
95797- void *b;
95798+ void *b = NULL;
95799
95800 flags &= gfp_allowed_mask;
95801
95802 lockdep_trace_alloc(flags);
95803
95804+#ifdef CONFIG_PAX_USERCOPY_SLABS
95805+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95806+#else
95807 if (c->size < PAGE_SIZE) {
95808 b = slob_alloc(c->size, flags, c->align, node);
95809 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95810 SLOB_UNITS(c->size) * SLOB_UNIT,
95811 flags, node);
95812 } else {
95813- b = slob_new_pages(flags, get_order(c->size), node);
95814+ struct page *sp;
95815+
95816+ sp = slob_new_pages(flags, get_order(c->size), node);
95817+ if (sp) {
95818+ b = page_address(sp);
95819+ sp->private = c->size;
95820+ }
95821 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95822 PAGE_SIZE << get_order(c->size),
95823 flags, node);
95824 }
95825+#endif
95826
95827 if (b && c->ctor)
95828 c->ctor(b);
95829@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95830
95831 static void __kmem_cache_free(void *b, int size)
95832 {
95833- if (size < PAGE_SIZE)
95834+ struct page *sp;
95835+
95836+ sp = virt_to_page(b);
95837+ BUG_ON(!PageSlab(sp));
95838+ if (!sp->private)
95839 slob_free(b, size);
95840 else
95841- slob_free_pages(b, get_order(size));
95842+ slob_free_pages(sp, get_order(size));
95843 }
95844
95845 static void kmem_rcu_free(struct rcu_head *head)
95846@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95847
95848 void kmem_cache_free(struct kmem_cache *c, void *b)
95849 {
95850+ int size = c->size;
95851+
95852+#ifdef CONFIG_PAX_USERCOPY_SLABS
95853+ if (size + c->align < PAGE_SIZE) {
95854+ size += c->align;
95855+ b -= c->align;
95856+ }
95857+#endif
95858+
95859 kmemleak_free_recursive(b, c->flags);
95860 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95861 struct slob_rcu *slob_rcu;
95862- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95863- slob_rcu->size = c->size;
95864+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95865+ slob_rcu->size = size;
95866 call_rcu(&slob_rcu->head, kmem_rcu_free);
95867 } else {
95868- __kmem_cache_free(b, c->size);
95869+ __kmem_cache_free(b, size);
95870 }
95871
95872+#ifdef CONFIG_PAX_USERCOPY_SLABS
95873+ trace_kfree(_RET_IP_, b);
95874+#else
95875 trace_kmem_cache_free(_RET_IP_, b);
95876+#endif
95877+
95878 }
95879 EXPORT_SYMBOL(kmem_cache_free);
95880
95881diff --git a/mm/slub.c b/mm/slub.c
95882index 25f14ad..ff4d0b7 100644
95883--- a/mm/slub.c
95884+++ b/mm/slub.c
95885@@ -207,7 +207,7 @@ struct track {
95886
95887 enum track_item { TRACK_ALLOC, TRACK_FREE };
95888
95889-#ifdef CONFIG_SYSFS
95890+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95891 static int sysfs_slab_add(struct kmem_cache *);
95892 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95893 static void sysfs_slab_remove(struct kmem_cache *);
95894@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
95895 if (!t->addr)
95896 return;
95897
95898- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95899+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95900 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95901 #ifdef CONFIG_STACKTRACE
95902 {
95903@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95904
95905 slab_free_hook(s, x);
95906
95907+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95908+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95909+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95910+ if (s->ctor)
95911+ s->ctor(x);
95912+ }
95913+#endif
95914+
95915 redo:
95916 /*
95917 * Determine the currently cpus per cpu slab.
95918@@ -2733,7 +2741,7 @@ static int slub_min_objects;
95919 * Merge control. If this is set then no merging of slab caches will occur.
95920 * (Could be removed. This was introduced to pacify the merge skeptics.)
95921 */
95922-static int slub_nomerge;
95923+static int slub_nomerge = 1;
95924
95925 /*
95926 * Calculate the order of allocation given an slab object size.
95927@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95928 s->inuse = size;
95929
95930 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95931+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95932+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95933+#endif
95934 s->ctor)) {
95935 /*
95936 * Relocate free pointer after the object if it is not
95937@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95938 EXPORT_SYMBOL(__kmalloc_node);
95939 #endif
95940
95941+bool is_usercopy_object(const void *ptr)
95942+{
95943+ struct page *page;
95944+ struct kmem_cache *s;
95945+
95946+ if (ZERO_OR_NULL_PTR(ptr))
95947+ return false;
95948+
95949+ if (!slab_is_available())
95950+ return false;
95951+
95952+ if (!virt_addr_valid(ptr))
95953+ return false;
95954+
95955+ page = virt_to_head_page(ptr);
95956+
95957+ if (!PageSlab(page))
95958+ return false;
95959+
95960+ s = page->slab_cache;
95961+ return s->flags & SLAB_USERCOPY;
95962+}
95963+
95964+#ifdef CONFIG_PAX_USERCOPY
95965+const char *check_heap_object(const void *ptr, unsigned long n)
95966+{
95967+ struct page *page;
95968+ struct kmem_cache *s;
95969+ unsigned long offset;
95970+
95971+ if (ZERO_OR_NULL_PTR(ptr))
95972+ return "<null>";
95973+
95974+ if (!virt_addr_valid(ptr))
95975+ return NULL;
95976+
95977+ page = virt_to_head_page(ptr);
95978+
95979+ if (!PageSlab(page))
95980+ return NULL;
95981+
95982+ s = page->slab_cache;
95983+ if (!(s->flags & SLAB_USERCOPY))
95984+ return s->name;
95985+
95986+ offset = (ptr - page_address(page)) % s->size;
95987+ if (offset <= s->object_size && n <= s->object_size - offset)
95988+ return NULL;
95989+
95990+ return s->name;
95991+}
95992+#endif
95993+
95994 size_t ksize(const void *object)
95995 {
95996 struct page *page;
95997@@ -3387,6 +3451,7 @@ void kfree(const void *x)
95998 if (unlikely(ZERO_OR_NULL_PTR(x)))
95999 return;
96000
96001+ VM_BUG_ON(!virt_addr_valid(x));
96002 page = virt_to_head_page(x);
96003 if (unlikely(!PageSlab(page))) {
96004 BUG_ON(!PageCompound(page));
96005@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96006 /*
96007 * We may have set a slab to be unmergeable during bootstrap.
96008 */
96009- if (s->refcount < 0)
96010+ if (atomic_read(&s->refcount) < 0)
96011 return 1;
96012
96013 return 0;
96014@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96015
96016 s = find_mergeable(memcg, size, align, flags, name, ctor);
96017 if (s) {
96018- s->refcount++;
96019+ atomic_inc(&s->refcount);
96020 /*
96021 * Adjust the object sizes so that we clear
96022 * the complete object on kzalloc.
96023@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96024 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96025
96026 if (sysfs_slab_alias(s, name)) {
96027- s->refcount--;
96028+ atomic_dec(&s->refcount);
96029 s = NULL;
96030 }
96031 }
96032@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96033 }
96034 #endif
96035
96036-#ifdef CONFIG_SYSFS
96037+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96038 static int count_inuse(struct page *page)
96039 {
96040 return page->inuse;
96041@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
96042 validate_slab_cache(kmalloc_caches[9]);
96043 }
96044 #else
96045-#ifdef CONFIG_SYSFS
96046+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96047 static void resiliency_test(void) {};
96048 #endif
96049 #endif
96050
96051-#ifdef CONFIG_SYSFS
96052+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96053 enum slab_stat_type {
96054 SL_ALL, /* All slabs */
96055 SL_PARTIAL, /* Only partially allocated slabs */
96056@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
96057
96058 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96059 {
96060- return sprintf(buf, "%d\n", s->refcount - 1);
96061+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96062 }
96063 SLAB_ATTR_RO(aliases);
96064
96065@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96066 SLAB_ATTR_RO(cache_dma);
96067 #endif
96068
96069+#ifdef CONFIG_PAX_USERCOPY_SLABS
96070+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96071+{
96072+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96073+}
96074+SLAB_ATTR_RO(usercopy);
96075+#endif
96076+
96077 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96078 {
96079 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96080@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
96081 #ifdef CONFIG_ZONE_DMA
96082 &cache_dma_attr.attr,
96083 #endif
96084+#ifdef CONFIG_PAX_USERCOPY_SLABS
96085+ &usercopy_attr.attr,
96086+#endif
96087 #ifdef CONFIG_NUMA
96088 &remote_node_defrag_ratio_attr.attr,
96089 #endif
96090@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
96091 return name;
96092 }
96093
96094+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96095 static int sysfs_slab_add(struct kmem_cache *s)
96096 {
96097 int err;
96098@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96099 kobject_del(&s->kobj);
96100 kobject_put(&s->kobj);
96101 }
96102+#endif
96103
96104 /*
96105 * Need to buffer aliases during bootup until sysfs becomes
96106@@ -5243,6 +5321,7 @@ struct saved_alias {
96107
96108 static struct saved_alias *alias_list;
96109
96110+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96111 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96112 {
96113 struct saved_alias *al;
96114@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96115 alias_list = al;
96116 return 0;
96117 }
96118+#endif
96119
96120 static int __init slab_sysfs_init(void)
96121 {
96122diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96123index 4cba9c2..b4f9fcc 100644
96124--- a/mm/sparse-vmemmap.c
96125+++ b/mm/sparse-vmemmap.c
96126@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96127 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96128 if (!p)
96129 return NULL;
96130- pud_populate(&init_mm, pud, p);
96131+ pud_populate_kernel(&init_mm, pud, p);
96132 }
96133 return pud;
96134 }
96135@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96136 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96137 if (!p)
96138 return NULL;
96139- pgd_populate(&init_mm, pgd, p);
96140+ pgd_populate_kernel(&init_mm, pgd, p);
96141 }
96142 return pgd;
96143 }
96144diff --git a/mm/sparse.c b/mm/sparse.c
96145index 63c3ea5..95c0858 100644
96146--- a/mm/sparse.c
96147+++ b/mm/sparse.c
96148@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96149
96150 for (i = 0; i < PAGES_PER_SECTION; i++) {
96151 if (PageHWPoison(&memmap[i])) {
96152- atomic_long_sub(1, &num_poisoned_pages);
96153+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96154 ClearPageHWPoison(&memmap[i]);
96155 }
96156 }
96157diff --git a/mm/swap.c b/mm/swap.c
96158index 0092097..33361ff 100644
96159--- a/mm/swap.c
96160+++ b/mm/swap.c
96161@@ -31,6 +31,7 @@
96162 #include <linux/memcontrol.h>
96163 #include <linux/gfp.h>
96164 #include <linux/uio.h>
96165+#include <linux/hugetlb.h>
96166
96167 #include "internal.h"
96168
96169@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96170
96171 __page_cache_release(page);
96172 dtor = get_compound_page_dtor(page);
96173+ if (!PageHuge(page))
96174+ BUG_ON(dtor != free_compound_page);
96175 (*dtor)(page);
96176 }
96177
96178diff --git a/mm/swapfile.c b/mm/swapfile.c
96179index 4a7f7e6..22cddf5 100644
96180--- a/mm/swapfile.c
96181+++ b/mm/swapfile.c
96182@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96183
96184 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96185 /* Activity counter to indicate that a swapon or swapoff has occurred */
96186-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96187+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96188
96189 static inline unsigned char swap_count(unsigned char ent)
96190 {
96191@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96192 spin_unlock(&swap_lock);
96193
96194 err = 0;
96195- atomic_inc(&proc_poll_event);
96196+ atomic_inc_unchecked(&proc_poll_event);
96197 wake_up_interruptible(&proc_poll_wait);
96198
96199 out_dput:
96200@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96201
96202 poll_wait(file, &proc_poll_wait, wait);
96203
96204- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96205- seq->poll_event = atomic_read(&proc_poll_event);
96206+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96207+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96208 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96209 }
96210
96211@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96212 return ret;
96213
96214 seq = file->private_data;
96215- seq->poll_event = atomic_read(&proc_poll_event);
96216+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96217 return 0;
96218 }
96219
96220@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96221 (frontswap_map) ? "FS" : "");
96222
96223 mutex_unlock(&swapon_mutex);
96224- atomic_inc(&proc_poll_event);
96225+ atomic_inc_unchecked(&proc_poll_event);
96226 wake_up_interruptible(&proc_poll_wait);
96227
96228 if (S_ISREG(inode->i_mode))
96229diff --git a/mm/util.c b/mm/util.c
96230index a24aa22..a0d41ae 100644
96231--- a/mm/util.c
96232+++ b/mm/util.c
96233@@ -297,6 +297,12 @@ done:
96234 void arch_pick_mmap_layout(struct mm_struct *mm)
96235 {
96236 mm->mmap_base = TASK_UNMAPPED_BASE;
96237+
96238+#ifdef CONFIG_PAX_RANDMMAP
96239+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96240+ mm->mmap_base += mm->delta_mmap;
96241+#endif
96242+
96243 mm->get_unmapped_area = arch_get_unmapped_area;
96244 }
96245 #endif
96246diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96247index 0fdf968..d6686e8 100644
96248--- a/mm/vmalloc.c
96249+++ b/mm/vmalloc.c
96250@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96251
96252 pte = pte_offset_kernel(pmd, addr);
96253 do {
96254- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96255- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96256+
96257+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96258+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96259+ BUG_ON(!pte_exec(*pte));
96260+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96261+ continue;
96262+ }
96263+#endif
96264+
96265+ {
96266+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96267+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96268+ }
96269 } while (pte++, addr += PAGE_SIZE, addr != end);
96270 }
96271
96272@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96273 pte = pte_alloc_kernel(pmd, addr);
96274 if (!pte)
96275 return -ENOMEM;
96276+
96277+ pax_open_kernel();
96278 do {
96279 struct page *page = pages[*nr];
96280
96281- if (WARN_ON(!pte_none(*pte)))
96282+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96283+ if (pgprot_val(prot) & _PAGE_NX)
96284+#endif
96285+
96286+ if (!pte_none(*pte)) {
96287+ pax_close_kernel();
96288+ WARN_ON(1);
96289 return -EBUSY;
96290- if (WARN_ON(!page))
96291+ }
96292+ if (!page) {
96293+ pax_close_kernel();
96294+ WARN_ON(1);
96295 return -ENOMEM;
96296+ }
96297 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96298 (*nr)++;
96299 } while (pte++, addr += PAGE_SIZE, addr != end);
96300+ pax_close_kernel();
96301 return 0;
96302 }
96303
96304@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96305 pmd_t *pmd;
96306 unsigned long next;
96307
96308- pmd = pmd_alloc(&init_mm, pud, addr);
96309+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96310 if (!pmd)
96311 return -ENOMEM;
96312 do {
96313@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96314 pud_t *pud;
96315 unsigned long next;
96316
96317- pud = pud_alloc(&init_mm, pgd, addr);
96318+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96319 if (!pud)
96320 return -ENOMEM;
96321 do {
96322@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96323 if (addr >= MODULES_VADDR && addr < MODULES_END)
96324 return 1;
96325 #endif
96326+
96327+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96328+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96329+ return 1;
96330+#endif
96331+
96332 return is_vmalloc_addr(x);
96333 }
96334
96335@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96336
96337 if (!pgd_none(*pgd)) {
96338 pud_t *pud = pud_offset(pgd, addr);
96339+#ifdef CONFIG_X86
96340+ if (!pud_large(*pud))
96341+#endif
96342 if (!pud_none(*pud)) {
96343 pmd_t *pmd = pmd_offset(pud, addr);
96344+#ifdef CONFIG_X86
96345+ if (!pmd_large(*pmd))
96346+#endif
96347 if (!pmd_none(*pmd)) {
96348 pte_t *ptep, pte;
96349
96350@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96351 struct vm_struct *area;
96352
96353 BUG_ON(in_interrupt());
96354+
96355+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96356+ if (flags & VM_KERNEXEC) {
96357+ if (start != VMALLOC_START || end != VMALLOC_END)
96358+ return NULL;
96359+ start = (unsigned long)MODULES_EXEC_VADDR;
96360+ end = (unsigned long)MODULES_EXEC_END;
96361+ }
96362+#endif
96363+
96364 if (flags & VM_IOREMAP)
96365 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96366
96367@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96368 if (count > totalram_pages)
96369 return NULL;
96370
96371+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96372+ if (!(pgprot_val(prot) & _PAGE_NX))
96373+ flags |= VM_KERNEXEC;
96374+#endif
96375+
96376 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96377 __builtin_return_address(0));
96378 if (!area)
96379@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96380 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96381 goto fail;
96382
96383+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96384+ if (!(pgprot_val(prot) & _PAGE_NX))
96385+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96386+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96387+ else
96388+#endif
96389+
96390 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96391 start, end, node, gfp_mask, caller);
96392 if (!area)
96393@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96394 * For tight control over page level allocator and protection flags
96395 * use __vmalloc() instead.
96396 */
96397-
96398 void *vmalloc_exec(unsigned long size)
96399 {
96400- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96401+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96402 NUMA_NO_NODE, __builtin_return_address(0));
96403 }
96404
96405@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96406 {
96407 struct vm_struct *area;
96408
96409+ BUG_ON(vma->vm_mirror);
96410+
96411 size = PAGE_ALIGN(size);
96412
96413 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96414@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96415 v->addr, v->addr + v->size, v->size);
96416
96417 if (v->caller)
96418+#ifdef CONFIG_GRKERNSEC_HIDESYM
96419+ seq_printf(m, " %pK", v->caller);
96420+#else
96421 seq_printf(m, " %pS", v->caller);
96422+#endif
96423
96424 if (v->nr_pages)
96425 seq_printf(m, " pages=%d", v->nr_pages);
96426diff --git a/mm/vmstat.c b/mm/vmstat.c
96427index def5dd2..4ce55cec 100644
96428--- a/mm/vmstat.c
96429+++ b/mm/vmstat.c
96430@@ -20,6 +20,7 @@
96431 #include <linux/writeback.h>
96432 #include <linux/compaction.h>
96433 #include <linux/mm_inline.h>
96434+#include <linux/grsecurity.h>
96435
96436 #include "internal.h"
96437
96438@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96439 *
96440 * vm_stat contains the global counters
96441 */
96442-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96443+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96444 EXPORT_SYMBOL(vm_stat);
96445
96446 #ifdef CONFIG_SMP
96447@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96448
96449 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96450 if (diff[i])
96451- atomic_long_add(diff[i], &vm_stat[i]);
96452+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96453 }
96454
96455 /*
96456@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96457 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96458 if (v) {
96459
96460- atomic_long_add(v, &zone->vm_stat[i]);
96461+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96462 global_diff[i] += v;
96463 #ifdef CONFIG_NUMA
96464 /* 3 seconds idle till flush */
96465@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96466
96467 v = p->vm_stat_diff[i];
96468 p->vm_stat_diff[i] = 0;
96469- atomic_long_add(v, &zone->vm_stat[i]);
96470+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96471 global_diff[i] += v;
96472 }
96473 }
96474@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96475 if (pset->vm_stat_diff[i]) {
96476 int v = pset->vm_stat_diff[i];
96477 pset->vm_stat_diff[i] = 0;
96478- atomic_long_add(v, &zone->vm_stat[i]);
96479- atomic_long_add(v, &vm_stat[i]);
96480+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96481+ atomic_long_add_unchecked(v, &vm_stat[i]);
96482 }
96483 }
96484 #endif
96485@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96486 stat_items_size += sizeof(struct vm_event_state);
96487 #endif
96488
96489- v = kmalloc(stat_items_size, GFP_KERNEL);
96490+ v = kzalloc(stat_items_size, GFP_KERNEL);
96491 m->private = v;
96492 if (!v)
96493 return ERR_PTR(-ENOMEM);
96494+
96495+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96496+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96497+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96498+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96499+ && !in_group_p(grsec_proc_gid)
96500+#endif
96501+ )
96502+ return (unsigned long *)m->private + *pos;
96503+#endif
96504+#endif
96505+
96506 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96507 v[i] = global_page_state(i);
96508 v += NR_VM_ZONE_STAT_ITEMS;
96509@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96510 put_online_cpus();
96511 #endif
96512 #ifdef CONFIG_PROC_FS
96513- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96514- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96515- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96516- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96517+ {
96518+ mode_t gr_mode = S_IRUGO;
96519+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96520+ gr_mode = S_IRUSR;
96521+#endif
96522+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96523+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96524+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96525+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96526+ }
96527 #endif
96528 return 0;
96529 }
96530diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96531index 175273f..1c63e05 100644
96532--- a/net/8021q/vlan.c
96533+++ b/net/8021q/vlan.c
96534@@ -474,7 +474,7 @@ out:
96535 return NOTIFY_DONE;
96536 }
96537
96538-static struct notifier_block vlan_notifier_block __read_mostly = {
96539+static struct notifier_block vlan_notifier_block = {
96540 .notifier_call = vlan_device_event,
96541 };
96542
96543@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96544 err = -EPERM;
96545 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96546 break;
96547- if ((args.u.name_type >= 0) &&
96548- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96549+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96550 struct vlan_net *vn;
96551
96552 vn = net_generic(net, vlan_net_id);
96553diff --git a/net/9p/client.c b/net/9p/client.c
96554index 9186550..e604a2f 100644
96555--- a/net/9p/client.c
96556+++ b/net/9p/client.c
96557@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96558 len - inline_len);
96559 } else {
96560 err = copy_from_user(ename + inline_len,
96561- uidata, len - inline_len);
96562+ (char __force_user *)uidata, len - inline_len);
96563 if (err) {
96564 err = -EFAULT;
96565 goto out_err;
96566@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96567 kernel_buf = 1;
96568 indata = data;
96569 } else
96570- indata = (__force char *)udata;
96571+ indata = (__force_kernel char *)udata;
96572 /*
96573 * response header len is 11
96574 * PDU Header(7) + IO Size (4)
96575@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96576 kernel_buf = 1;
96577 odata = data;
96578 } else
96579- odata = (char *)udata;
96580+ odata = (char __force_kernel *)udata;
96581 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96582 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96583 fid->fid, offset, rsize);
96584diff --git a/net/9p/mod.c b/net/9p/mod.c
96585index 6ab36ae..6f1841b 100644
96586--- a/net/9p/mod.c
96587+++ b/net/9p/mod.c
96588@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96589 void v9fs_register_trans(struct p9_trans_module *m)
96590 {
96591 spin_lock(&v9fs_trans_lock);
96592- list_add_tail(&m->list, &v9fs_trans_list);
96593+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96594 spin_unlock(&v9fs_trans_lock);
96595 }
96596 EXPORT_SYMBOL(v9fs_register_trans);
96597@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96598 void v9fs_unregister_trans(struct p9_trans_module *m)
96599 {
96600 spin_lock(&v9fs_trans_lock);
96601- list_del_init(&m->list);
96602+ pax_list_del_init((struct list_head *)&m->list);
96603 spin_unlock(&v9fs_trans_lock);
96604 }
96605 EXPORT_SYMBOL(v9fs_unregister_trans);
96606diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96607index b7bd7f2..2498bf7 100644
96608--- a/net/9p/trans_fd.c
96609+++ b/net/9p/trans_fd.c
96610@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96611 oldfs = get_fs();
96612 set_fs(get_ds());
96613 /* The cast to a user pointer is valid due to the set_fs() */
96614- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96615+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96616 set_fs(oldfs);
96617
96618 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96619diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
96620index af46bc4..f9adfcd 100644
96621--- a/net/appletalk/atalk_proc.c
96622+++ b/net/appletalk/atalk_proc.c
96623@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
96624 struct proc_dir_entry *p;
96625 int rc = -ENOMEM;
96626
96627- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
96628+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
96629 if (!atalk_proc_dir)
96630 goto out;
96631
96632diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96633index 876fbe8..8bbea9f 100644
96634--- a/net/atm/atm_misc.c
96635+++ b/net/atm/atm_misc.c
96636@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96637 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96638 return 1;
96639 atm_return(vcc, truesize);
96640- atomic_inc(&vcc->stats->rx_drop);
96641+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96642 return 0;
96643 }
96644 EXPORT_SYMBOL(atm_charge);
96645@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96646 }
96647 }
96648 atm_return(vcc, guess);
96649- atomic_inc(&vcc->stats->rx_drop);
96650+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96651 return NULL;
96652 }
96653 EXPORT_SYMBOL(atm_alloc_charge);
96654@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96655
96656 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96657 {
96658-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96659+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96660 __SONET_ITEMS
96661 #undef __HANDLE_ITEM
96662 }
96663@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96664
96665 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96666 {
96667-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96668+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96669 __SONET_ITEMS
96670 #undef __HANDLE_ITEM
96671 }
96672diff --git a/net/atm/lec.c b/net/atm/lec.c
96673index 5a2f602..9396143 100644
96674--- a/net/atm/lec.c
96675+++ b/net/atm/lec.c
96676@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96677 }
96678
96679 static struct lane2_ops lane2_ops = {
96680- lane2_resolve, /* resolve, spec 3.1.3 */
96681- lane2_associate_req, /* associate_req, spec 3.1.4 */
96682- NULL /* associate indicator, spec 3.1.5 */
96683+ .resolve = lane2_resolve,
96684+ .associate_req = lane2_associate_req,
96685+ .associate_indicator = NULL
96686 };
96687
96688 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96689diff --git a/net/atm/lec.h b/net/atm/lec.h
96690index 4149db1..f2ab682 100644
96691--- a/net/atm/lec.h
96692+++ b/net/atm/lec.h
96693@@ -48,7 +48,7 @@ struct lane2_ops {
96694 const u8 *tlvs, u32 sizeoftlvs);
96695 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96696 const u8 *tlvs, u32 sizeoftlvs);
96697-};
96698+} __no_const;
96699
96700 /*
96701 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96702diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96703index d1b2d9a..d549f7f 100644
96704--- a/net/atm/mpoa_caches.c
96705+++ b/net/atm/mpoa_caches.c
96706@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96707
96708
96709 static struct in_cache_ops ingress_ops = {
96710- in_cache_add_entry, /* add_entry */
96711- in_cache_get, /* get */
96712- in_cache_get_with_mask, /* get_with_mask */
96713- in_cache_get_by_vcc, /* get_by_vcc */
96714- in_cache_put, /* put */
96715- in_cache_remove_entry, /* remove_entry */
96716- cache_hit, /* cache_hit */
96717- clear_count_and_expired, /* clear_count */
96718- check_resolving_entries, /* check_resolving */
96719- refresh_entries, /* refresh */
96720- in_destroy_cache /* destroy_cache */
96721+ .add_entry = in_cache_add_entry,
96722+ .get = in_cache_get,
96723+ .get_with_mask = in_cache_get_with_mask,
96724+ .get_by_vcc = in_cache_get_by_vcc,
96725+ .put = in_cache_put,
96726+ .remove_entry = in_cache_remove_entry,
96727+ .cache_hit = cache_hit,
96728+ .clear_count = clear_count_and_expired,
96729+ .check_resolving = check_resolving_entries,
96730+ .refresh = refresh_entries,
96731+ .destroy_cache = in_destroy_cache
96732 };
96733
96734 static struct eg_cache_ops egress_ops = {
96735- eg_cache_add_entry, /* add_entry */
96736- eg_cache_get_by_cache_id, /* get_by_cache_id */
96737- eg_cache_get_by_tag, /* get_by_tag */
96738- eg_cache_get_by_vcc, /* get_by_vcc */
96739- eg_cache_get_by_src_ip, /* get_by_src_ip */
96740- eg_cache_put, /* put */
96741- eg_cache_remove_entry, /* remove_entry */
96742- update_eg_cache_entry, /* update */
96743- clear_expired, /* clear_expired */
96744- eg_destroy_cache /* destroy_cache */
96745+ .add_entry = eg_cache_add_entry,
96746+ .get_by_cache_id = eg_cache_get_by_cache_id,
96747+ .get_by_tag = eg_cache_get_by_tag,
96748+ .get_by_vcc = eg_cache_get_by_vcc,
96749+ .get_by_src_ip = eg_cache_get_by_src_ip,
96750+ .put = eg_cache_put,
96751+ .remove_entry = eg_cache_remove_entry,
96752+ .update = update_eg_cache_entry,
96753+ .clear_expired = clear_expired,
96754+ .destroy_cache = eg_destroy_cache
96755 };
96756
96757
96758diff --git a/net/atm/proc.c b/net/atm/proc.c
96759index bbb6461..cf04016 100644
96760--- a/net/atm/proc.c
96761+++ b/net/atm/proc.c
96762@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96763 const struct k_atm_aal_stats *stats)
96764 {
96765 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96766- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96767- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96768- atomic_read(&stats->rx_drop));
96769+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96770+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96771+ atomic_read_unchecked(&stats->rx_drop));
96772 }
96773
96774 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96775diff --git a/net/atm/resources.c b/net/atm/resources.c
96776index 0447d5d..3cf4728 100644
96777--- a/net/atm/resources.c
96778+++ b/net/atm/resources.c
96779@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96780 static void copy_aal_stats(struct k_atm_aal_stats *from,
96781 struct atm_aal_stats *to)
96782 {
96783-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96784+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96785 __AAL_STAT_ITEMS
96786 #undef __HANDLE_ITEM
96787 }
96788@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96789 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96790 struct atm_aal_stats *to)
96791 {
96792-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96793+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96794 __AAL_STAT_ITEMS
96795 #undef __HANDLE_ITEM
96796 }
96797diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96798index 919a5ce..cc6b444 100644
96799--- a/net/ax25/sysctl_net_ax25.c
96800+++ b/net/ax25/sysctl_net_ax25.c
96801@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96802 {
96803 char path[sizeof("net/ax25/") + IFNAMSIZ];
96804 int k;
96805- struct ctl_table *table;
96806+ ctl_table_no_const *table;
96807
96808 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96809 if (!table)
96810diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96811index 8323bce..a03130d 100644
96812--- a/net/batman-adv/bat_iv_ogm.c
96813+++ b/net/batman-adv/bat_iv_ogm.c
96814@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96815
96816 /* randomize initial seqno to avoid collision */
96817 get_random_bytes(&random_seqno, sizeof(random_seqno));
96818- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96819+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96820
96821 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96822 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96823@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96824 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96825
96826 /* change sequence number to network order */
96827- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96828+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96829 batadv_ogm_packet->seqno = htonl(seqno);
96830- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96831+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96832
96833 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96834
96835@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96836 return;
96837
96838 /* could be changed by schedule_own_packet() */
96839- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96840+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96841
96842 if (ogm_packet->flags & BATADV_DIRECTLINK)
96843 has_directlink_flag = true;
96844diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96845index 88df9b1..69cf7c0 100644
96846--- a/net/batman-adv/fragmentation.c
96847+++ b/net/batman-adv/fragmentation.c
96848@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96849 frag_header.packet_type = BATADV_UNICAST_FRAG;
96850 frag_header.version = BATADV_COMPAT_VERSION;
96851 frag_header.ttl = BATADV_TTL;
96852- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96853+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96854 frag_header.reserved = 0;
96855 frag_header.no = 0;
96856 frag_header.total_size = htons(skb->len);
96857diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96858index f82c267..0e56d32 100644
96859--- a/net/batman-adv/soft-interface.c
96860+++ b/net/batman-adv/soft-interface.c
96861@@ -283,7 +283,7 @@ send:
96862 primary_if->net_dev->dev_addr, ETH_ALEN);
96863
96864 /* set broadcast sequence number */
96865- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96866+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96867 bcast_packet->seqno = htonl(seqno);
96868
96869 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96870@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96871 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96872
96873 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96874- atomic_set(&bat_priv->bcast_seqno, 1);
96875+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96876 atomic_set(&bat_priv->tt.vn, 0);
96877 atomic_set(&bat_priv->tt.local_changes, 0);
96878 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96879@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96880
96881 /* randomize initial seqno to avoid collision */
96882 get_random_bytes(&random_seqno, sizeof(random_seqno));
96883- atomic_set(&bat_priv->frag_seqno, random_seqno);
96884+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96885
96886 bat_priv->primary_if = NULL;
96887 bat_priv->num_ifaces = 0;
96888diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96889index 78370ab..1cb3614 100644
96890--- a/net/batman-adv/types.h
96891+++ b/net/batman-adv/types.h
96892@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
96893 struct batadv_hard_iface_bat_iv {
96894 unsigned char *ogm_buff;
96895 int ogm_buff_len;
96896- atomic_t ogm_seqno;
96897+ atomic_unchecked_t ogm_seqno;
96898 };
96899
96900 /**
96901@@ -714,7 +714,7 @@ struct batadv_priv {
96902 atomic_t bonding;
96903 atomic_t fragmentation;
96904 atomic_t packet_size_max;
96905- atomic_t frag_seqno;
96906+ atomic_unchecked_t frag_seqno;
96907 #ifdef CONFIG_BATMAN_ADV_BLA
96908 atomic_t bridge_loop_avoidance;
96909 #endif
96910@@ -730,7 +730,7 @@ struct batadv_priv {
96911 #endif
96912 uint32_t isolation_mark;
96913 uint32_t isolation_mark_mask;
96914- atomic_t bcast_seqno;
96915+ atomic_unchecked_t bcast_seqno;
96916 atomic_t bcast_queue_left;
96917 atomic_t batman_queue_left;
96918 char num_ifaces;
96919diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96920index 7552f9e..074ce29 100644
96921--- a/net/bluetooth/hci_sock.c
96922+++ b/net/bluetooth/hci_sock.c
96923@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96924 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96925 }
96926
96927- len = min_t(unsigned int, len, sizeof(uf));
96928+ len = min((size_t)len, sizeof(uf));
96929 if (copy_from_user(&uf, optval, len)) {
96930 err = -EFAULT;
96931 break;
96932diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96933index b0ad2c7..96f6a5e 100644
96934--- a/net/bluetooth/l2cap_core.c
96935+++ b/net/bluetooth/l2cap_core.c
96936@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96937 break;
96938
96939 case L2CAP_CONF_RFC:
96940- if (olen == sizeof(rfc))
96941- memcpy(&rfc, (void *)val, olen);
96942+ if (olen != sizeof(rfc))
96943+ break;
96944+
96945+ memcpy(&rfc, (void *)val, olen);
96946
96947 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96948 rfc.mode != chan->mode)
96949diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96950index d58f76b..b69600a 100644
96951--- a/net/bluetooth/l2cap_sock.c
96952+++ b/net/bluetooth/l2cap_sock.c
96953@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96954 struct sock *sk = sock->sk;
96955 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96956 struct l2cap_options opts;
96957- int len, err = 0;
96958+ int err = 0;
96959+ size_t len = optlen;
96960 u32 opt;
96961
96962 BT_DBG("sk %p", sk);
96963@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96964 opts.max_tx = chan->max_tx;
96965 opts.txwin_size = chan->tx_win;
96966
96967- len = min_t(unsigned int, sizeof(opts), optlen);
96968+ len = min(sizeof(opts), len);
96969 if (copy_from_user((char *) &opts, optval, len)) {
96970 err = -EFAULT;
96971 break;
96972@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96973 struct bt_security sec;
96974 struct bt_power pwr;
96975 struct l2cap_conn *conn;
96976- int len, err = 0;
96977+ int err = 0;
96978+ size_t len = optlen;
96979 u32 opt;
96980
96981 BT_DBG("sk %p", sk);
96982@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96983
96984 sec.level = BT_SECURITY_LOW;
96985
96986- len = min_t(unsigned int, sizeof(sec), optlen);
96987+ len = min(sizeof(sec), len);
96988 if (copy_from_user((char *) &sec, optval, len)) {
96989 err = -EFAULT;
96990 break;
96991@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96992
96993 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96994
96995- len = min_t(unsigned int, sizeof(pwr), optlen);
96996+ len = min(sizeof(pwr), len);
96997 if (copy_from_user((char *) &pwr, optval, len)) {
96998 err = -EFAULT;
96999 break;
97000diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97001index 3c2d3e4..884855a 100644
97002--- a/net/bluetooth/rfcomm/sock.c
97003+++ b/net/bluetooth/rfcomm/sock.c
97004@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97005 struct sock *sk = sock->sk;
97006 struct bt_security sec;
97007 int err = 0;
97008- size_t len;
97009+ size_t len = optlen;
97010 u32 opt;
97011
97012 BT_DBG("sk %p", sk);
97013@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97014
97015 sec.level = BT_SECURITY_LOW;
97016
97017- len = min_t(unsigned int, sizeof(sec), optlen);
97018+ len = min(sizeof(sec), len);
97019 if (copy_from_user((char *) &sec, optval, len)) {
97020 err = -EFAULT;
97021 break;
97022diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97023index f9c0980a..fcbbfeb 100644
97024--- a/net/bluetooth/rfcomm/tty.c
97025+++ b/net/bluetooth/rfcomm/tty.c
97026@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97027 BT_DBG("tty %p id %d", tty, tty->index);
97028
97029 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97030- dev->channel, dev->port.count);
97031+ dev->channel, atomic_read(&dev->port.count));
97032
97033 err = tty_port_open(&dev->port, tty, filp);
97034 if (err)
97035@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97036 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97037
97038 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97039- dev->port.count);
97040+ atomic_read(&dev->port.count));
97041
97042 tty_port_close(&dev->port, tty, filp);
97043 }
97044diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97045index 0e474b1..fb7109c 100644
97046--- a/net/bridge/netfilter/ebtables.c
97047+++ b/net/bridge/netfilter/ebtables.c
97048@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97049 tmp.valid_hooks = t->table->valid_hooks;
97050 }
97051 mutex_unlock(&ebt_mutex);
97052- if (copy_to_user(user, &tmp, *len) != 0) {
97053+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97054 BUGPRINT("c2u Didn't work\n");
97055 ret = -EFAULT;
97056 break;
97057@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97058 goto out;
97059 tmp.valid_hooks = t->valid_hooks;
97060
97061- if (copy_to_user(user, &tmp, *len) != 0) {
97062+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97063 ret = -EFAULT;
97064 break;
97065 }
97066@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97067 tmp.entries_size = t->table->entries_size;
97068 tmp.valid_hooks = t->table->valid_hooks;
97069
97070- if (copy_to_user(user, &tmp, *len) != 0) {
97071+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97072 ret = -EFAULT;
97073 break;
97074 }
97075diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97076index 0f45522..dab651f 100644
97077--- a/net/caif/cfctrl.c
97078+++ b/net/caif/cfctrl.c
97079@@ -10,6 +10,7 @@
97080 #include <linux/spinlock.h>
97081 #include <linux/slab.h>
97082 #include <linux/pkt_sched.h>
97083+#include <linux/sched.h>
97084 #include <net/caif/caif_layer.h>
97085 #include <net/caif/cfpkt.h>
97086 #include <net/caif/cfctrl.h>
97087@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97088 memset(&dev_info, 0, sizeof(dev_info));
97089 dev_info.id = 0xff;
97090 cfsrvl_init(&this->serv, 0, &dev_info, false);
97091- atomic_set(&this->req_seq_no, 1);
97092- atomic_set(&this->rsp_seq_no, 1);
97093+ atomic_set_unchecked(&this->req_seq_no, 1);
97094+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97095 this->serv.layer.receive = cfctrl_recv;
97096 sprintf(this->serv.layer.name, "ctrl");
97097 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97098@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97099 struct cfctrl_request_info *req)
97100 {
97101 spin_lock_bh(&ctrl->info_list_lock);
97102- atomic_inc(&ctrl->req_seq_no);
97103- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97104+ atomic_inc_unchecked(&ctrl->req_seq_no);
97105+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97106 list_add_tail(&req->list, &ctrl->list);
97107 spin_unlock_bh(&ctrl->info_list_lock);
97108 }
97109@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97110 if (p != first)
97111 pr_warn("Requests are not received in order\n");
97112
97113- atomic_set(&ctrl->rsp_seq_no,
97114+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97115 p->sequence_no);
97116 list_del(&p->list);
97117 goto out;
97118diff --git a/net/can/af_can.c b/net/can/af_can.c
97119index a27f8aa..67174a3 100644
97120--- a/net/can/af_can.c
97121+++ b/net/can/af_can.c
97122@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97123 };
97124
97125 /* notifier block for netdevice event */
97126-static struct notifier_block can_netdev_notifier __read_mostly = {
97127+static struct notifier_block can_netdev_notifier = {
97128 .notifier_call = can_notifier,
97129 };
97130
97131diff --git a/net/can/bcm.c b/net/can/bcm.c
97132index dcb75c0..24b1b43 100644
97133--- a/net/can/bcm.c
97134+++ b/net/can/bcm.c
97135@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97136 }
97137
97138 /* create /proc/net/can-bcm directory */
97139- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97140+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97141 return 0;
97142 }
97143
97144diff --git a/net/can/gw.c b/net/can/gw.c
97145index ac31891..4799c17 100644
97146--- a/net/can/gw.c
97147+++ b/net/can/gw.c
97148@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97149 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97150
97151 static HLIST_HEAD(cgw_list);
97152-static struct notifier_block notifier;
97153
97154 static struct kmem_cache *cgw_cache __read_mostly;
97155
97156@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97157 return err;
97158 }
97159
97160+static struct notifier_block notifier = {
97161+ .notifier_call = cgw_notifier
97162+};
97163+
97164 static __init int cgw_module_init(void)
97165 {
97166 /* sanitize given module parameter */
97167@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97168 return -ENOMEM;
97169
97170 /* set notifier */
97171- notifier.notifier_call = cgw_notifier;
97172 register_netdevice_notifier(&notifier);
97173
97174 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97175diff --git a/net/can/proc.c b/net/can/proc.c
97176index b543470..d2ddae2 100644
97177--- a/net/can/proc.c
97178+++ b/net/can/proc.c
97179@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97180 void can_init_proc(void)
97181 {
97182 /* create /proc/net/can directory */
97183- can_dir = proc_mkdir("can", init_net.proc_net);
97184+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97185
97186 if (!can_dir) {
97187 printk(KERN_INFO "can: failed to create /proc/net/can . "
97188diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97189index 30efc5c..cfa1bbc 100644
97190--- a/net/ceph/messenger.c
97191+++ b/net/ceph/messenger.c
97192@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97193 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97194
97195 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97196-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97197+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97198
97199 static struct page *zero_page; /* used in certain error cases */
97200
97201@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97202 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97203 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97204
97205- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97206+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97207 s = addr_str[i];
97208
97209 switch (ss->ss_family) {
97210diff --git a/net/compat.c b/net/compat.c
97211index f50161f..94fa415 100644
97212--- a/net/compat.c
97213+++ b/net/compat.c
97214@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97215 return -EFAULT;
97216 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97217 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97218- kmsg->msg_name = compat_ptr(tmp1);
97219- kmsg->msg_iov = compat_ptr(tmp2);
97220- kmsg->msg_control = compat_ptr(tmp3);
97221+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97222+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97223+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97224 return 0;
97225 }
97226
97227@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97228
97229 if (kern_msg->msg_namelen) {
97230 if (mode == VERIFY_READ) {
97231- int err = move_addr_to_kernel(kern_msg->msg_name,
97232+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97233 kern_msg->msg_namelen,
97234 kern_address);
97235 if (err < 0)
97236@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97237 kern_msg->msg_name = NULL;
97238
97239 tot_len = iov_from_user_compat_to_kern(kern_iov,
97240- (struct compat_iovec __user *)kern_msg->msg_iov,
97241+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97242 kern_msg->msg_iovlen);
97243 if (tot_len >= 0)
97244 kern_msg->msg_iov = kern_iov;
97245@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97246
97247 #define CMSG_COMPAT_FIRSTHDR(msg) \
97248 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97249- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97250+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97251 (struct compat_cmsghdr __user *)NULL)
97252
97253 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97254 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97255 (ucmlen) <= (unsigned long) \
97256 ((mhdr)->msg_controllen - \
97257- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97258+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97259
97260 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97261 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97262 {
97263 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97264- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97265+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97266 msg->msg_controllen)
97267 return NULL;
97268 return (struct compat_cmsghdr __user *)ptr;
97269@@ -222,7 +222,7 @@ Efault:
97270
97271 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97272 {
97273- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97274+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97275 struct compat_cmsghdr cmhdr;
97276 struct compat_timeval ctv;
97277 struct compat_timespec cts[3];
97278@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97279
97280 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97281 {
97282- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97283+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97284 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97285 int fdnum = scm->fp->count;
97286 struct file **fp = scm->fp->fp;
97287@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97288 return -EFAULT;
97289 old_fs = get_fs();
97290 set_fs(KERNEL_DS);
97291- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97292+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97293 set_fs(old_fs);
97294
97295 return err;
97296@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97297 len = sizeof(ktime);
97298 old_fs = get_fs();
97299 set_fs(KERNEL_DS);
97300- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97301+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97302 set_fs(old_fs);
97303
97304 if (!err) {
97305@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97306 case MCAST_JOIN_GROUP:
97307 case MCAST_LEAVE_GROUP:
97308 {
97309- struct compat_group_req __user *gr32 = (void *)optval;
97310+ struct compat_group_req __user *gr32 = (void __user *)optval;
97311 struct group_req __user *kgr =
97312 compat_alloc_user_space(sizeof(struct group_req));
97313 u32 interface;
97314@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97315 case MCAST_BLOCK_SOURCE:
97316 case MCAST_UNBLOCK_SOURCE:
97317 {
97318- struct compat_group_source_req __user *gsr32 = (void *)optval;
97319+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97320 struct group_source_req __user *kgsr = compat_alloc_user_space(
97321 sizeof(struct group_source_req));
97322 u32 interface;
97323@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97324 }
97325 case MCAST_MSFILTER:
97326 {
97327- struct compat_group_filter __user *gf32 = (void *)optval;
97328+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97329 struct group_filter __user *kgf;
97330 u32 interface, fmode, numsrc;
97331
97332@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97333 char __user *optval, int __user *optlen,
97334 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97335 {
97336- struct compat_group_filter __user *gf32 = (void *)optval;
97337+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97338 struct group_filter __user *kgf;
97339 int __user *koptlen;
97340 u32 interface, fmode, numsrc;
97341@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97342
97343 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97344 return -EINVAL;
97345- if (copy_from_user(a, args, nas[call]))
97346+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97347 return -EFAULT;
97348 a0 = a[0];
97349 a1 = a[1];
97350diff --git a/net/core/datagram.c b/net/core/datagram.c
97351index a16ed7b..eb44d17 100644
97352--- a/net/core/datagram.c
97353+++ b/net/core/datagram.c
97354@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97355 }
97356
97357 kfree_skb(skb);
97358- atomic_inc(&sk->sk_drops);
97359+ atomic_inc_unchecked(&sk->sk_drops);
97360 sk_mem_reclaim_partial(sk);
97361
97362 return err;
97363diff --git a/net/core/dev.c b/net/core/dev.c
97364index 45fa2f1..f3e28ec 100644
97365--- a/net/core/dev.c
97366+++ b/net/core/dev.c
97367@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97368 {
97369 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97370 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97371- atomic_long_inc(&dev->rx_dropped);
97372+ atomic_long_inc_unchecked(&dev->rx_dropped);
97373 kfree_skb(skb);
97374 return NET_RX_DROP;
97375 }
97376 }
97377
97378 if (unlikely(!is_skb_forwardable(dev, skb))) {
97379- atomic_long_inc(&dev->rx_dropped);
97380+ atomic_long_inc_unchecked(&dev->rx_dropped);
97381 kfree_skb(skb);
97382 return NET_RX_DROP;
97383 }
97384@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97385
97386 struct dev_gso_cb {
97387 void (*destructor)(struct sk_buff *skb);
97388-};
97389+} __no_const;
97390
97391 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97392
97393@@ -3227,7 +3227,7 @@ enqueue:
97394
97395 local_irq_restore(flags);
97396
97397- atomic_long_inc(&skb->dev->rx_dropped);
97398+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97399 kfree_skb(skb);
97400 return NET_RX_DROP;
97401 }
97402@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97403 }
97404 EXPORT_SYMBOL(netif_rx_ni);
97405
97406-static void net_tx_action(struct softirq_action *h)
97407+static __latent_entropy void net_tx_action(void)
97408 {
97409 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97410
97411@@ -3645,7 +3645,7 @@ ncls:
97412 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97413 } else {
97414 drop:
97415- atomic_long_inc(&skb->dev->rx_dropped);
97416+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97417 kfree_skb(skb);
97418 /* Jamal, now you will not able to escape explaining
97419 * me how you were going to use this. :-)
97420@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97421 }
97422 EXPORT_SYMBOL(netif_napi_del);
97423
97424-static void net_rx_action(struct softirq_action *h)
97425+static __latent_entropy void net_rx_action(void)
97426 {
97427 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97428 unsigned long time_limit = jiffies + 2;
97429@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97430 } else {
97431 netdev_stats_to_stats64(storage, &dev->stats);
97432 }
97433- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97434+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97435 return storage;
97436 }
97437 EXPORT_SYMBOL(dev_get_stats);
97438diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97439index cf999e0..c59a975 100644
97440--- a/net/core/dev_ioctl.c
97441+++ b/net/core/dev_ioctl.c
97442@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97443 if (no_module && capable(CAP_NET_ADMIN))
97444 no_module = request_module("netdev-%s", name);
97445 if (no_module && capable(CAP_SYS_MODULE)) {
97446+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97447+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97448+#else
97449 if (!request_module("%s", name))
97450 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97451 name);
97452+#endif
97453 }
97454 }
97455 EXPORT_SYMBOL(dev_load);
97456diff --git a/net/core/filter.c b/net/core/filter.c
97457index ad30d62..21c0743 100644
97458--- a/net/core/filter.c
97459+++ b/net/core/filter.c
97460@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97461 void *ptr;
97462 u32 A = 0; /* Accumulator */
97463 u32 X = 0; /* Index Register */
97464- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97465+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97466 u32 tmp;
97467 int k;
97468
97469@@ -292,10 +292,10 @@ load_b:
97470 X = K;
97471 continue;
97472 case BPF_S_LD_MEM:
97473- A = mem[K];
97474+ A = mem[K&15];
97475 continue;
97476 case BPF_S_LDX_MEM:
97477- X = mem[K];
97478+ X = mem[K&15];
97479 continue;
97480 case BPF_S_MISC_TAX:
97481 X = A;
97482@@ -308,10 +308,10 @@ load_b:
97483 case BPF_S_RET_A:
97484 return A;
97485 case BPF_S_ST:
97486- mem[K] = A;
97487+ mem[K&15] = A;
97488 continue;
97489 case BPF_S_STX:
97490- mem[K] = X;
97491+ mem[K&15] = X;
97492 continue;
97493 case BPF_S_ANC_PROTOCOL:
97494 A = ntohs(skb->protocol);
97495@@ -355,6 +355,10 @@ load_b:
97496
97497 if (skb_is_nonlinear(skb))
97498 return 0;
97499+
97500+ if (skb->len < sizeof(struct nlattr))
97501+ return 0;
97502+
97503 if (A > skb->len - sizeof(struct nlattr))
97504 return 0;
97505
97506@@ -371,11 +375,15 @@ load_b:
97507
97508 if (skb_is_nonlinear(skb))
97509 return 0;
97510+
97511+ if (skb->len < sizeof(struct nlattr))
97512+ return 0;
97513+
97514 if (A > skb->len - sizeof(struct nlattr))
97515 return 0;
97516
97517 nla = (struct nlattr *)&skb->data[A];
97518- if (nla->nla_len > A - skb->len)
97519+ if (nla->nla_len > skb->len - A)
97520 return 0;
97521
97522 nla = nla_find_nested(nla, X);
97523@@ -391,9 +399,10 @@ load_b:
97524 continue;
97525 #endif
97526 default:
97527- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97528+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97529 fentry->code, fentry->jt,
97530 fentry->jf, fentry->k);
97531+ BUG();
97532 return 0;
97533 }
97534 }
97535@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97536 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97537 int pc, ret = 0;
97538
97539- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97540+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97541 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97542 if (!masks)
97543 return -ENOMEM;
97544@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97545 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97546 if (!fp)
97547 return -ENOMEM;
97548- memcpy(fp->insns, fprog->filter, fsize);
97549+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97550
97551 atomic_set(&fp->refcnt, 1);
97552 fp->len = fprog->len;
97553diff --git a/net/core/flow.c b/net/core/flow.c
97554index dfa602c..3103d88 100644
97555--- a/net/core/flow.c
97556+++ b/net/core/flow.c
97557@@ -61,7 +61,7 @@ struct flow_cache {
97558 struct timer_list rnd_timer;
97559 };
97560
97561-atomic_t flow_cache_genid = ATOMIC_INIT(0);
97562+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97563 EXPORT_SYMBOL(flow_cache_genid);
97564 static struct flow_cache flow_cache_global;
97565 static struct kmem_cache *flow_cachep __read_mostly;
97566@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97567
97568 static int flow_entry_valid(struct flow_cache_entry *fle)
97569 {
97570- if (atomic_read(&flow_cache_genid) != fle->genid)
97571+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97572 return 0;
97573 if (fle->object && !fle->object->ops->check(fle->object))
97574 return 0;
97575@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97576 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97577 fcp->hash_count++;
97578 }
97579- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97580+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97581 flo = fle->object;
97582 if (!flo)
97583 goto ret_object;
97584@@ -279,7 +279,7 @@ nocache:
97585 }
97586 flo = resolver(net, key, family, dir, flo, ctx);
97587 if (fle) {
97588- fle->genid = atomic_read(&flow_cache_genid);
97589+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97590 if (!IS_ERR(flo))
97591 fle->object = flo;
97592 else
97593diff --git a/net/core/iovec.c b/net/core/iovec.c
97594index b618694..192bbba 100644
97595--- a/net/core/iovec.c
97596+++ b/net/core/iovec.c
97597@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97598 if (m->msg_namelen) {
97599 if (mode == VERIFY_READ) {
97600 void __user *namep;
97601- namep = (void __user __force *) m->msg_name;
97602+ namep = (void __force_user *) m->msg_name;
97603 err = move_addr_to_kernel(namep, m->msg_namelen,
97604 address);
97605 if (err < 0)
97606@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97607 }
97608
97609 size = m->msg_iovlen * sizeof(struct iovec);
97610- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97611+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97612 return -EFAULT;
97613
97614 m->msg_iov = iov;
97615diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97616index e161290..8149aea 100644
97617--- a/net/core/neighbour.c
97618+++ b/net/core/neighbour.c
97619@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97620 void __user *buffer, size_t *lenp, loff_t *ppos)
97621 {
97622 int size, ret;
97623- struct ctl_table tmp = *ctl;
97624+ ctl_table_no_const tmp = *ctl;
97625
97626 tmp.extra1 = &zero;
97627 tmp.extra2 = &unres_qlen_max;
97628@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97629 void __user *buffer,
97630 size_t *lenp, loff_t *ppos)
97631 {
97632- struct ctl_table tmp = *ctl;
97633+ ctl_table_no_const tmp = *ctl;
97634 int ret;
97635
97636 tmp.extra1 = &zero;
97637@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97638 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97639 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97640 } else {
97641+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97642 dev_name_source = "default";
97643- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97644- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97645- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97646- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97647+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97648+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97649+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97650+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97651 }
97652
97653 if (handler) {
97654diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97655index 2bf8329..2eb1423 100644
97656--- a/net/core/net-procfs.c
97657+++ b/net/core/net-procfs.c
97658@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
97659 struct rtnl_link_stats64 temp;
97660 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
97661
97662- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97663+ if (gr_proc_is_restricted())
97664+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97665+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97666+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
97667+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
97668+ else
97669+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
97670 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
97671 dev->name, stats->rx_bytes, stats->rx_packets,
97672 stats->rx_errors,
97673@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
97674 return 0;
97675 }
97676
97677-static const struct seq_operations dev_seq_ops = {
97678+const struct seq_operations dev_seq_ops = {
97679 .start = dev_seq_start,
97680 .next = dev_seq_next,
97681 .stop = dev_seq_stop,
97682@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
97683
97684 static int softnet_seq_open(struct inode *inode, struct file *file)
97685 {
97686- return seq_open(file, &softnet_seq_ops);
97687+ return seq_open_restrict(file, &softnet_seq_ops);
97688 }
97689
97690 static const struct file_operations softnet_seq_fops = {
97691@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97692 else
97693 seq_printf(seq, "%04x", ntohs(pt->type));
97694
97695+#ifdef CONFIG_GRKERNSEC_HIDESYM
97696+ seq_printf(seq, " %-8s %pf\n",
97697+ pt->dev ? pt->dev->name : "", NULL);
97698+#else
97699 seq_printf(seq, " %-8s %pf\n",
97700 pt->dev ? pt->dev->name : "", pt->func);
97701+#endif
97702 }
97703
97704 return 0;
97705diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97706index 81d3a9a..a0bd7a8 100644
97707--- a/net/core/net_namespace.c
97708+++ b/net/core/net_namespace.c
97709@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97710 int error;
97711 LIST_HEAD(net_exit_list);
97712
97713- list_add_tail(&ops->list, list);
97714+ pax_list_add_tail((struct list_head *)&ops->list, list);
97715 if (ops->init || (ops->id && ops->size)) {
97716 for_each_net(net) {
97717 error = ops_init(ops, net);
97718@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97719
97720 out_undo:
97721 /* If I have an error cleanup all namespaces I initialized */
97722- list_del(&ops->list);
97723+ pax_list_del((struct list_head *)&ops->list);
97724 ops_exit_list(ops, &net_exit_list);
97725 ops_free_list(ops, &net_exit_list);
97726 return error;
97727@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97728 struct net *net;
97729 LIST_HEAD(net_exit_list);
97730
97731- list_del(&ops->list);
97732+ pax_list_del((struct list_head *)&ops->list);
97733 for_each_net(net)
97734 list_add_tail(&net->exit_list, &net_exit_list);
97735 ops_exit_list(ops, &net_exit_list);
97736@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97737 mutex_lock(&net_mutex);
97738 error = register_pernet_operations(&pernet_list, ops);
97739 if (!error && (first_device == &pernet_list))
97740- first_device = &ops->list;
97741+ first_device = (struct list_head *)&ops->list;
97742 mutex_unlock(&net_mutex);
97743 return error;
97744 }
97745diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97746index df9e6b1..6e68e4e 100644
97747--- a/net/core/netpoll.c
97748+++ b/net/core/netpoll.c
97749@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97750 struct udphdr *udph;
97751 struct iphdr *iph;
97752 struct ethhdr *eth;
97753- static atomic_t ip_ident;
97754+ static atomic_unchecked_t ip_ident;
97755 struct ipv6hdr *ip6h;
97756
97757 udp_len = len + sizeof(*udph);
97758@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97759 put_unaligned(0x45, (unsigned char *)iph);
97760 iph->tos = 0;
97761 put_unaligned(htons(ip_len), &(iph->tot_len));
97762- iph->id = htons(atomic_inc_return(&ip_ident));
97763+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97764 iph->frag_off = 0;
97765 iph->ttl = 64;
97766 iph->protocol = IPPROTO_UDP;
97767diff --git a/net/core/pktgen.c b/net/core/pktgen.c
97768index fdac61c..e5e5b46 100644
97769--- a/net/core/pktgen.c
97770+++ b/net/core/pktgen.c
97771@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
97772 pn->net = net;
97773 INIT_LIST_HEAD(&pn->pktgen_threads);
97774 pn->pktgen_exiting = false;
97775- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
97776+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
97777 if (!pn->proc_dir) {
97778 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
97779 return -ENODEV;
97780diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97781index 120eecc..cd1ec44 100644
97782--- a/net/core/rtnetlink.c
97783+++ b/net/core/rtnetlink.c
97784@@ -58,7 +58,7 @@ struct rtnl_link {
97785 rtnl_doit_func doit;
97786 rtnl_dumpit_func dumpit;
97787 rtnl_calcit_func calcit;
97788-};
97789+} __no_const;
97790
97791 static DEFINE_MUTEX(rtnl_mutex);
97792
97793@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97794 if (rtnl_link_ops_get(ops->kind))
97795 return -EEXIST;
97796
97797- if (!ops->dellink)
97798- ops->dellink = unregister_netdevice_queue;
97799+ if (!ops->dellink) {
97800+ pax_open_kernel();
97801+ *(void **)&ops->dellink = unregister_netdevice_queue;
97802+ pax_close_kernel();
97803+ }
97804
97805- list_add_tail(&ops->list, &link_ops);
97806+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97807 return 0;
97808 }
97809 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97810@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97811 for_each_net(net) {
97812 __rtnl_kill_links(net, ops);
97813 }
97814- list_del(&ops->list);
97815+ pax_list_del((struct list_head *)&ops->list);
97816 }
97817 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97818
97819diff --git a/net/core/scm.c b/net/core/scm.c
97820index b442e7e..6f5b5a2 100644
97821--- a/net/core/scm.c
97822+++ b/net/core/scm.c
97823@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97824 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97825 {
97826 struct cmsghdr __user *cm
97827- = (__force struct cmsghdr __user *)msg->msg_control;
97828+ = (struct cmsghdr __force_user *)msg->msg_control;
97829 struct cmsghdr cmhdr;
97830 int cmlen = CMSG_LEN(len);
97831 int err;
97832@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97833 err = -EFAULT;
97834 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97835 goto out;
97836- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97837+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97838 goto out;
97839 cmlen = CMSG_SPACE(len);
97840 if (msg->msg_controllen < cmlen)
97841@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97842 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97843 {
97844 struct cmsghdr __user *cm
97845- = (__force struct cmsghdr __user*)msg->msg_control;
97846+ = (struct cmsghdr __force_user *)msg->msg_control;
97847
97848 int fdmax = 0;
97849 int fdnum = scm->fp->count;
97850@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97851 if (fdnum < fdmax)
97852 fdmax = fdnum;
97853
97854- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97855+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97856 i++, cmfptr++)
97857 {
97858 struct socket *sock;
97859diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97860index 90b96a1..cd18f16d 100644
97861--- a/net/core/skbuff.c
97862+++ b/net/core/skbuff.c
97863@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97864 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97865 int len, __wsum csum)
97866 {
97867- const struct skb_checksum_ops ops = {
97868+ static const struct skb_checksum_ops ops = {
97869 .update = csum_partial_ext,
97870 .combine = csum_block_add_ext,
97871 };
97872@@ -3220,13 +3220,15 @@ void __init skb_init(void)
97873 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97874 sizeof(struct sk_buff),
97875 0,
97876- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97877+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97878+ SLAB_NO_SANITIZE,
97879 NULL);
97880 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97881 (2*sizeof(struct sk_buff)) +
97882 sizeof(atomic_t),
97883 0,
97884- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97885+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97886+ SLAB_NO_SANITIZE,
97887 NULL);
97888 }
97889
97890diff --git a/net/core/sock.c b/net/core/sock.c
97891index c0fc6bd..51d8326 100644
97892--- a/net/core/sock.c
97893+++ b/net/core/sock.c
97894@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97895 struct sk_buff_head *list = &sk->sk_receive_queue;
97896
97897 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97898- atomic_inc(&sk->sk_drops);
97899+ atomic_inc_unchecked(&sk->sk_drops);
97900 trace_sock_rcvqueue_full(sk, skb);
97901 return -ENOMEM;
97902 }
97903@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97904 return err;
97905
97906 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97907- atomic_inc(&sk->sk_drops);
97908+ atomic_inc_unchecked(&sk->sk_drops);
97909 return -ENOBUFS;
97910 }
97911
97912@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97913 skb_dst_force(skb);
97914
97915 spin_lock_irqsave(&list->lock, flags);
97916- skb->dropcount = atomic_read(&sk->sk_drops);
97917+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97918 __skb_queue_tail(list, skb);
97919 spin_unlock_irqrestore(&list->lock, flags);
97920
97921@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97922 skb->dev = NULL;
97923
97924 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97925- atomic_inc(&sk->sk_drops);
97926+ atomic_inc_unchecked(&sk->sk_drops);
97927 goto discard_and_relse;
97928 }
97929 if (nested)
97930@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97931 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97932 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97933 bh_unlock_sock(sk);
97934- atomic_inc(&sk->sk_drops);
97935+ atomic_inc_unchecked(&sk->sk_drops);
97936 goto discard_and_relse;
97937 }
97938
97939@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97940 struct timeval tm;
97941 } v;
97942
97943- int lv = sizeof(int);
97944- int len;
97945+ unsigned int lv = sizeof(int);
97946+ unsigned int len;
97947
97948 if (get_user(len, optlen))
97949 return -EFAULT;
97950- if (len < 0)
97951+ if (len > INT_MAX)
97952 return -EINVAL;
97953
97954 memset(&v, 0, sizeof(v));
97955@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97956
97957 case SO_PEERNAME:
97958 {
97959- char address[128];
97960+ char address[_K_SS_MAXSIZE];
97961
97962 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97963 return -ENOTCONN;
97964- if (lv < len)
97965+ if (lv < len || sizeof address < len)
97966 return -EINVAL;
97967 if (copy_to_user(optval, address, len))
97968 return -EFAULT;
97969@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97970
97971 if (len > lv)
97972 len = lv;
97973- if (copy_to_user(optval, &v, len))
97974+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
97975 return -EFAULT;
97976 lenout:
97977 if (put_user(len, optlen))
97978@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97979 */
97980 smp_wmb();
97981 atomic_set(&sk->sk_refcnt, 1);
97982- atomic_set(&sk->sk_drops, 0);
97983+ atomic_set_unchecked(&sk->sk_drops, 0);
97984 }
97985 EXPORT_SYMBOL(sock_init_data);
97986
97987@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97988 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97989 int level, int type)
97990 {
97991+ struct sock_extended_err ee;
97992 struct sock_exterr_skb *serr;
97993 struct sk_buff *skb, *skb2;
97994 int copied, err;
97995@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97996 sock_recv_timestamp(msg, sk, skb);
97997
97998 serr = SKB_EXT_ERR(skb);
97999- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98000+ ee = serr->ee;
98001+ put_cmsg(msg, level, type, sizeof ee, &ee);
98002
98003 msg->msg_flags |= MSG_ERRQUEUE;
98004 err = copied;
98005diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98006index a0e9cf6..ef7f9ed 100644
98007--- a/net/core/sock_diag.c
98008+++ b/net/core/sock_diag.c
98009@@ -9,26 +9,33 @@
98010 #include <linux/inet_diag.h>
98011 #include <linux/sock_diag.h>
98012
98013-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98014+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98015 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98016 static DEFINE_MUTEX(sock_diag_table_mutex);
98017
98018 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98019 {
98020+#ifndef CONFIG_GRKERNSEC_HIDESYM
98021 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98022 cookie[1] != INET_DIAG_NOCOOKIE) &&
98023 ((u32)(unsigned long)sk != cookie[0] ||
98024 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98025 return -ESTALE;
98026 else
98027+#endif
98028 return 0;
98029 }
98030 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98031
98032 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98033 {
98034+#ifdef CONFIG_GRKERNSEC_HIDESYM
98035+ cookie[0] = 0;
98036+ cookie[1] = 0;
98037+#else
98038 cookie[0] = (u32)(unsigned long)sk;
98039 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98040+#endif
98041 }
98042 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98043
98044@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98045 mutex_lock(&sock_diag_table_mutex);
98046 if (sock_diag_handlers[hndl->family])
98047 err = -EBUSY;
98048- else
98049+ else {
98050+ pax_open_kernel();
98051 sock_diag_handlers[hndl->family] = hndl;
98052+ pax_close_kernel();
98053+ }
98054 mutex_unlock(&sock_diag_table_mutex);
98055
98056 return err;
98057@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98058
98059 mutex_lock(&sock_diag_table_mutex);
98060 BUG_ON(sock_diag_handlers[family] != hnld);
98061+ pax_open_kernel();
98062 sock_diag_handlers[family] = NULL;
98063+ pax_close_kernel();
98064 mutex_unlock(&sock_diag_table_mutex);
98065 }
98066 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98067diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98068index cf9cd13..8b56af3 100644
98069--- a/net/core/sysctl_net_core.c
98070+++ b/net/core/sysctl_net_core.c
98071@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98072 {
98073 unsigned int orig_size, size;
98074 int ret, i;
98075- struct ctl_table tmp = {
98076+ ctl_table_no_const tmp = {
98077 .data = &size,
98078 .maxlen = sizeof(size),
98079 .mode = table->mode
98080@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98081 void __user *buffer, size_t *lenp, loff_t *ppos)
98082 {
98083 char id[IFNAMSIZ];
98084- struct ctl_table tbl = {
98085+ ctl_table_no_const tbl = {
98086 .data = id,
98087 .maxlen = IFNAMSIZ,
98088 };
98089@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98090
98091 static __net_init int sysctl_core_net_init(struct net *net)
98092 {
98093- struct ctl_table *tbl;
98094+ ctl_table_no_const *tbl = NULL;
98095
98096 net->core.sysctl_somaxconn = SOMAXCONN;
98097
98098- tbl = netns_core_table;
98099 if (!net_eq(net, &init_net)) {
98100- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98101+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98102 if (tbl == NULL)
98103 goto err_dup;
98104
98105@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98106 if (net->user_ns != &init_user_ns) {
98107 tbl[0].procname = NULL;
98108 }
98109- }
98110-
98111- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98112+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98113+ } else
98114+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98115 if (net->core.sysctl_hdr == NULL)
98116 goto err_reg;
98117
98118 return 0;
98119
98120 err_reg:
98121- if (tbl != netns_core_table)
98122- kfree(tbl);
98123+ kfree(tbl);
98124 err_dup:
98125 return -ENOMEM;
98126 }
98127@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98128 kfree(tbl);
98129 }
98130
98131-static __net_initdata struct pernet_operations sysctl_core_ops = {
98132+static __net_initconst struct pernet_operations sysctl_core_ops = {
98133 .init = sysctl_core_net_init,
98134 .exit = sysctl_core_net_exit,
98135 };
98136diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98137index 4c04848..f575934 100644
98138--- a/net/decnet/af_decnet.c
98139+++ b/net/decnet/af_decnet.c
98140@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98141 .sysctl_rmem = sysctl_decnet_rmem,
98142 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98143 .obj_size = sizeof(struct dn_sock),
98144+ .slab_flags = SLAB_USERCOPY,
98145 };
98146
98147 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98148diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98149index a603823..a36ee0b 100644
98150--- a/net/decnet/dn_dev.c
98151+++ b/net/decnet/dn_dev.c
98152@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98153 .extra1 = &min_t3,
98154 .extra2 = &max_t3
98155 },
98156- {0}
98157+ { }
98158 },
98159 };
98160
98161diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98162index 5325b54..a0d4d69 100644
98163--- a/net/decnet/sysctl_net_decnet.c
98164+++ b/net/decnet/sysctl_net_decnet.c
98165@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98166
98167 if (len > *lenp) len = *lenp;
98168
98169- if (copy_to_user(buffer, addr, len))
98170+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98171 return -EFAULT;
98172
98173 *lenp = len;
98174@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98175
98176 if (len > *lenp) len = *lenp;
98177
98178- if (copy_to_user(buffer, devname, len))
98179+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98180 return -EFAULT;
98181
98182 *lenp = len;
98183diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98184index 1846c1f..96d4a9f 100644
98185--- a/net/ieee802154/dgram.c
98186+++ b/net/ieee802154/dgram.c
98187@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98188 if (saddr) {
98189 saddr->family = AF_IEEE802154;
98190 saddr->addr = mac_cb(skb)->sa;
98191+ }
98192+ if (addr_len)
98193 *addr_len = sizeof(*saddr);
98194- }
98195
98196 if (flags & MSG_TRUNC)
98197 copied = skb->len;
98198diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98199index 19ab78a..bf575c9 100644
98200--- a/net/ipv4/af_inet.c
98201+++ b/net/ipv4/af_inet.c
98202@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98203
98204 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98205
98206- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98207- if (!sysctl_local_reserved_ports)
98208- goto out;
98209-
98210 rc = proto_register(&tcp_prot, 1);
98211 if (rc)
98212- goto out_free_reserved_ports;
98213+ goto out;
98214
98215 rc = proto_register(&udp_prot, 1);
98216 if (rc)
98217@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98218 proto_unregister(&udp_prot);
98219 out_unregister_tcp_proto:
98220 proto_unregister(&tcp_prot);
98221-out_free_reserved_ports:
98222- kfree(sysctl_local_reserved_ports);
98223 goto out;
98224 }
98225
98226diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98227index bdbf68b..deb4759 100644
98228--- a/net/ipv4/devinet.c
98229+++ b/net/ipv4/devinet.c
98230@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98231 idx = 0;
98232 head = &net->dev_index_head[h];
98233 rcu_read_lock();
98234- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98235+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98236 net->dev_base_seq;
98237 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98238 if (idx < s_idx)
98239@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98240 idx = 0;
98241 head = &net->dev_index_head[h];
98242 rcu_read_lock();
98243- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98244+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98245 net->dev_base_seq;
98246 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98247 if (idx < s_idx)
98248@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98249 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98250 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98251
98252-static struct devinet_sysctl_table {
98253+static const struct devinet_sysctl_table {
98254 struct ctl_table_header *sysctl_header;
98255 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98256 } devinet_sysctl = {
98257@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98258 int err;
98259 struct ipv4_devconf *all, *dflt;
98260 #ifdef CONFIG_SYSCTL
98261- struct ctl_table *tbl = ctl_forward_entry;
98262+ ctl_table_no_const *tbl = NULL;
98263 struct ctl_table_header *forw_hdr;
98264 #endif
98265
98266@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98267 goto err_alloc_dflt;
98268
98269 #ifdef CONFIG_SYSCTL
98270- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98271+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98272 if (tbl == NULL)
98273 goto err_alloc_ctl;
98274
98275@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98276 goto err_reg_dflt;
98277
98278 err = -ENOMEM;
98279- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98280+ if (!net_eq(net, &init_net))
98281+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98282+ else
98283+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98284 if (forw_hdr == NULL)
98285 goto err_reg_ctl;
98286 net->ipv4.forw_hdr = forw_hdr;
98287@@ -2272,8 +2275,7 @@ err_reg_ctl:
98288 err_reg_dflt:
98289 __devinet_sysctl_unregister(all);
98290 err_reg_all:
98291- if (tbl != ctl_forward_entry)
98292- kfree(tbl);
98293+ kfree(tbl);
98294 err_alloc_ctl:
98295 #endif
98296 if (dflt != &ipv4_devconf_dflt)
98297diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98298index c7539e2..b455e51 100644
98299--- a/net/ipv4/fib_frontend.c
98300+++ b/net/ipv4/fib_frontend.c
98301@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98302 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98303 fib_sync_up(dev);
98304 #endif
98305- atomic_inc(&net->ipv4.dev_addr_genid);
98306+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98307 rt_cache_flush(dev_net(dev));
98308 break;
98309 case NETDEV_DOWN:
98310 fib_del_ifaddr(ifa, NULL);
98311- atomic_inc(&net->ipv4.dev_addr_genid);
98312+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98313 if (ifa->ifa_dev->ifa_list == NULL) {
98314 /* Last address was deleted from this interface.
98315 * Disable IP.
98316@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98317 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98318 fib_sync_up(dev);
98319 #endif
98320- atomic_inc(&net->ipv4.dev_addr_genid);
98321+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98322 rt_cache_flush(net);
98323 break;
98324 case NETDEV_DOWN:
98325diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98326index b53f0bf..3585b33 100644
98327--- a/net/ipv4/fib_semantics.c
98328+++ b/net/ipv4/fib_semantics.c
98329@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98330 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98331 nh->nh_gw,
98332 nh->nh_parent->fib_scope);
98333- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98334+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98335
98336 return nh->nh_saddr;
98337 }
98338diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98339index 0d1e2cb..4501a2c 100644
98340--- a/net/ipv4/inet_connection_sock.c
98341+++ b/net/ipv4/inet_connection_sock.c
98342@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98343 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98344 #endif
98345
98346-unsigned long *sysctl_local_reserved_ports;
98347+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98348 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98349
98350 void inet_get_local_port_range(struct net *net, int *low, int *high)
98351diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98352index 8b9cf27..0d8d592 100644
98353--- a/net/ipv4/inet_hashtables.c
98354+++ b/net/ipv4/inet_hashtables.c
98355@@ -18,6 +18,7 @@
98356 #include <linux/sched.h>
98357 #include <linux/slab.h>
98358 #include <linux/wait.h>
98359+#include <linux/security.h>
98360
98361 #include <net/inet_connection_sock.h>
98362 #include <net/inet_hashtables.h>
98363@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98364 return inet_ehashfn(net, laddr, lport, faddr, fport);
98365 }
98366
98367+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98368+
98369 /*
98370 * Allocate and initialize a new local port bind bucket.
98371 * The bindhash mutex for snum's hash chain must be held here.
98372@@ -554,6 +557,8 @@ ok:
98373 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98374 spin_unlock(&head->lock);
98375
98376+ gr_update_task_in_ip_table(current, inet_sk(sk));
98377+
98378 if (tw) {
98379 inet_twsk_deschedule(tw, death_row);
98380 while (twrefcnt) {
98381diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98382index 48f4244..f56d83a 100644
98383--- a/net/ipv4/inetpeer.c
98384+++ b/net/ipv4/inetpeer.c
98385@@ -496,8 +496,8 @@ relookup:
98386 if (p) {
98387 p->daddr = *daddr;
98388 atomic_set(&p->refcnt, 1);
98389- atomic_set(&p->rid, 0);
98390- atomic_set(&p->ip_id_count,
98391+ atomic_set_unchecked(&p->rid, 0);
98392+ atomic_set_unchecked(&p->ip_id_count,
98393 (daddr->family == AF_INET) ?
98394 secure_ip_id(daddr->addr.a4) :
98395 secure_ipv6_id(daddr->addr.a6));
98396diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98397index c10a3ce..dd71f84 100644
98398--- a/net/ipv4/ip_fragment.c
98399+++ b/net/ipv4/ip_fragment.c
98400@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98401 return 0;
98402
98403 start = qp->rid;
98404- end = atomic_inc_return(&peer->rid);
98405+ end = atomic_inc_return_unchecked(&peer->rid);
98406 qp->rid = end;
98407
98408 rc = qp->q.fragments && (end - start) > max;
98409@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98410
98411 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98412 {
98413- struct ctl_table *table;
98414+ ctl_table_no_const *table = NULL;
98415 struct ctl_table_header *hdr;
98416
98417- table = ip4_frags_ns_ctl_table;
98418 if (!net_eq(net, &init_net)) {
98419- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98420+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98421 if (table == NULL)
98422 goto err_alloc;
98423
98424@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98425 /* Don't export sysctls to unprivileged users */
98426 if (net->user_ns != &init_user_ns)
98427 table[0].procname = NULL;
98428- }
98429+ hdr = register_net_sysctl(net, "net/ipv4", table);
98430+ } else
98431+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98432
98433- hdr = register_net_sysctl(net, "net/ipv4", table);
98434 if (hdr == NULL)
98435 goto err_reg;
98436
98437@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98438 return 0;
98439
98440 err_reg:
98441- if (!net_eq(net, &init_net))
98442- kfree(table);
98443+ kfree(table);
98444 err_alloc:
98445 return -ENOMEM;
98446 }
98447diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98448index ec4f762..4ce3645 100644
98449--- a/net/ipv4/ip_gre.c
98450+++ b/net/ipv4/ip_gre.c
98451@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98452 module_param(log_ecn_error, bool, 0644);
98453 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98454
98455-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98456+static struct rtnl_link_ops ipgre_link_ops;
98457 static int ipgre_tunnel_init(struct net_device *dev);
98458
98459 static int ipgre_net_id __read_mostly;
98460@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98461 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98462 };
98463
98464-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98465+static struct rtnl_link_ops ipgre_link_ops = {
98466 .kind = "gre",
98467 .maxtype = IFLA_GRE_MAX,
98468 .policy = ipgre_policy,
98469@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98470 .fill_info = ipgre_fill_info,
98471 };
98472
98473-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98474+static struct rtnl_link_ops ipgre_tap_ops = {
98475 .kind = "gretap",
98476 .maxtype = IFLA_GRE_MAX,
98477 .policy = ipgre_policy,
98478diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98479index 580dd96..9fcef7e 100644
98480--- a/net/ipv4/ip_sockglue.c
98481+++ b/net/ipv4/ip_sockglue.c
98482@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98483 len = min_t(unsigned int, len, opt->optlen);
98484 if (put_user(len, optlen))
98485 return -EFAULT;
98486- if (copy_to_user(optval, opt->__data, len))
98487+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98488+ copy_to_user(optval, opt->__data, len))
98489 return -EFAULT;
98490 return 0;
98491 }
98492@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98493 if (sk->sk_type != SOCK_STREAM)
98494 return -ENOPROTOOPT;
98495
98496- msg.msg_control = optval;
98497+ msg.msg_control = (void __force_kernel *)optval;
98498 msg.msg_controllen = len;
98499 msg.msg_flags = flags;
98500
98501diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98502index 48eafae..defff53 100644
98503--- a/net/ipv4/ip_vti.c
98504+++ b/net/ipv4/ip_vti.c
98505@@ -44,7 +44,7 @@
98506 #include <net/net_namespace.h>
98507 #include <net/netns/generic.h>
98508
98509-static struct rtnl_link_ops vti_link_ops __read_mostly;
98510+static struct rtnl_link_ops vti_link_ops;
98511
98512 static int vti_net_id __read_mostly;
98513 static int vti_tunnel_init(struct net_device *dev);
98514@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98515 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98516 };
98517
98518-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98519+static struct rtnl_link_ops vti_link_ops = {
98520 .kind = "vti",
98521 .maxtype = IFLA_VTI_MAX,
98522 .policy = vti_policy,
98523diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98524index b3e86ea..18ce98c 100644
98525--- a/net/ipv4/ipconfig.c
98526+++ b/net/ipv4/ipconfig.c
98527@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98528
98529 mm_segment_t oldfs = get_fs();
98530 set_fs(get_ds());
98531- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98532+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98533 set_fs(oldfs);
98534 return res;
98535 }
98536@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98537
98538 mm_segment_t oldfs = get_fs();
98539 set_fs(get_ds());
98540- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98541+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98542 set_fs(oldfs);
98543 return res;
98544 }
98545@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98546
98547 mm_segment_t oldfs = get_fs();
98548 set_fs(get_ds());
98549- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98550+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98551 set_fs(oldfs);
98552 return res;
98553 }
98554diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98555index 812b183..56cbe9c 100644
98556--- a/net/ipv4/ipip.c
98557+++ b/net/ipv4/ipip.c
98558@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98559 static int ipip_net_id __read_mostly;
98560
98561 static int ipip_tunnel_init(struct net_device *dev);
98562-static struct rtnl_link_ops ipip_link_ops __read_mostly;
98563+static struct rtnl_link_ops ipip_link_ops;
98564
98565 static int ipip_err(struct sk_buff *skb, u32 info)
98566 {
98567@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98568 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98569 };
98570
98571-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98572+static struct rtnl_link_ops ipip_link_ops = {
98573 .kind = "ipip",
98574 .maxtype = IFLA_IPTUN_MAX,
98575 .policy = ipip_policy,
98576diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98577index 59da7cd..e318de1 100644
98578--- a/net/ipv4/netfilter/arp_tables.c
98579+++ b/net/ipv4/netfilter/arp_tables.c
98580@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98581 #endif
98582
98583 static int get_info(struct net *net, void __user *user,
98584- const int *len, int compat)
98585+ int len, int compat)
98586 {
98587 char name[XT_TABLE_MAXNAMELEN];
98588 struct xt_table *t;
98589 int ret;
98590
98591- if (*len != sizeof(struct arpt_getinfo)) {
98592- duprintf("length %u != %Zu\n", *len,
98593+ if (len != sizeof(struct arpt_getinfo)) {
98594+ duprintf("length %u != %Zu\n", len,
98595 sizeof(struct arpt_getinfo));
98596 return -EINVAL;
98597 }
98598@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98599 info.size = private->size;
98600 strcpy(info.name, name);
98601
98602- if (copy_to_user(user, &info, *len) != 0)
98603+ if (copy_to_user(user, &info, len) != 0)
98604 ret = -EFAULT;
98605 else
98606 ret = 0;
98607@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98608
98609 switch (cmd) {
98610 case ARPT_SO_GET_INFO:
98611- ret = get_info(sock_net(sk), user, len, 1);
98612+ ret = get_info(sock_net(sk), user, *len, 1);
98613 break;
98614 case ARPT_SO_GET_ENTRIES:
98615 ret = compat_get_entries(sock_net(sk), user, len);
98616@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98617
98618 switch (cmd) {
98619 case ARPT_SO_GET_INFO:
98620- ret = get_info(sock_net(sk), user, len, 0);
98621+ ret = get_info(sock_net(sk), user, *len, 0);
98622 break;
98623
98624 case ARPT_SO_GET_ENTRIES:
98625diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98626index 718dfbd..cef4152 100644
98627--- a/net/ipv4/netfilter/ip_tables.c
98628+++ b/net/ipv4/netfilter/ip_tables.c
98629@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98630 #endif
98631
98632 static int get_info(struct net *net, void __user *user,
98633- const int *len, int compat)
98634+ int len, int compat)
98635 {
98636 char name[XT_TABLE_MAXNAMELEN];
98637 struct xt_table *t;
98638 int ret;
98639
98640- if (*len != sizeof(struct ipt_getinfo)) {
98641- duprintf("length %u != %zu\n", *len,
98642+ if (len != sizeof(struct ipt_getinfo)) {
98643+ duprintf("length %u != %zu\n", len,
98644 sizeof(struct ipt_getinfo));
98645 return -EINVAL;
98646 }
98647@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98648 info.size = private->size;
98649 strcpy(info.name, name);
98650
98651- if (copy_to_user(user, &info, *len) != 0)
98652+ if (copy_to_user(user, &info, len) != 0)
98653 ret = -EFAULT;
98654 else
98655 ret = 0;
98656@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98657
98658 switch (cmd) {
98659 case IPT_SO_GET_INFO:
98660- ret = get_info(sock_net(sk), user, len, 1);
98661+ ret = get_info(sock_net(sk), user, *len, 1);
98662 break;
98663 case IPT_SO_GET_ENTRIES:
98664 ret = compat_get_entries(sock_net(sk), user, len);
98665@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98666
98667 switch (cmd) {
98668 case IPT_SO_GET_INFO:
98669- ret = get_info(sock_net(sk), user, len, 0);
98670+ ret = get_info(sock_net(sk), user, *len, 0);
98671 break;
98672
98673 case IPT_SO_GET_ENTRIES:
98674diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98675index 2510c02..cfb34fa 100644
98676--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
98677+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
98678@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
98679 spin_lock_init(&cn->lock);
98680
98681 #ifdef CONFIG_PROC_FS
98682- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
98683+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
98684 if (!cn->procdir) {
98685 pr_err("Unable to proc dir entry\n");
98686 return -ENOMEM;
98687diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98688index 2d11c09..3f153f8 100644
98689--- a/net/ipv4/ping.c
98690+++ b/net/ipv4/ping.c
98691@@ -59,7 +59,7 @@ struct ping_table {
98692 };
98693
98694 static struct ping_table ping_table;
98695-struct pingv6_ops pingv6_ops;
98696+struct pingv6_ops *pingv6_ops;
98697 EXPORT_SYMBOL_GPL(pingv6_ops);
98698
98699 static u16 ping_port_rover;
98700@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98701 struct group_info *group_info = get_current_groups();
98702 int i, j, count = group_info->ngroups;
98703 kgid_t low, high;
98704+ int ret = 0;
98705
98706 inet_get_ping_group_range_net(net, &low, &high);
98707 if (gid_lte(low, group) && gid_lte(group, high))
98708- return 0;
98709+ goto out_release_group;
98710
98711 for (i = 0; i < group_info->nblocks; i++) {
98712 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98713 for (j = 0; j < cp_count; j++) {
98714 kgid_t gid = group_info->blocks[i][j];
98715 if (gid_lte(low, gid) && gid_lte(gid, high))
98716- return 0;
98717+ goto out_release_group;
98718 }
98719
98720 count -= cp_count;
98721 }
98722
98723- return -EACCES;
98724+ ret = -EACCES;
98725+
98726+out_release_group:
98727+ put_group_info(group_info);
98728+ return ret;
98729 }
98730 EXPORT_SYMBOL_GPL(ping_init_sock);
98731
98732@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98733 return -ENODEV;
98734 }
98735 }
98736- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98737+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98738 scoped);
98739 rcu_read_unlock();
98740
98741@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98742 }
98743 #if IS_ENABLED(CONFIG_IPV6)
98744 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98745- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98746+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98747 #endif
98748 }
98749
98750@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98751 info, (u8 *)icmph);
98752 #if IS_ENABLED(CONFIG_IPV6)
98753 } else if (family == AF_INET6) {
98754- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98755+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98756 info, (u8 *)icmph);
98757 #endif
98758 }
98759@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98760 {
98761 struct inet_sock *isk = inet_sk(sk);
98762 int family = sk->sk_family;
98763+ struct sockaddr_in *sin;
98764+ struct sockaddr_in6 *sin6;
98765 struct sk_buff *skb;
98766 int copied, err;
98767
98768@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98769 if (flags & MSG_OOB)
98770 goto out;
98771
98772+ if (addr_len) {
98773+ if (family == AF_INET)
98774+ *addr_len = sizeof(*sin);
98775+ else if (family == AF_INET6 && addr_len)
98776+ *addr_len = sizeof(*sin6);
98777+ }
98778+
98779 if (flags & MSG_ERRQUEUE) {
98780 if (family == AF_INET) {
98781 return ip_recv_error(sk, msg, len, addr_len);
98782 #if IS_ENABLED(CONFIG_IPV6)
98783 } else if (family == AF_INET6) {
98784- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98785+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98786 addr_len);
98787 #endif
98788 }
98789@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98790 sin->sin_port = 0 /* skb->h.uh->source */;
98791 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98792 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98793- *addr_len = sizeof(*sin);
98794 }
98795
98796 if (isk->cmsg_flags)
98797@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98798 sin6->sin6_scope_id =
98799 ipv6_iface_scope_id(&sin6->sin6_addr,
98800 IP6CB(skb)->iif);
98801- *addr_len = sizeof(*sin6);
98802 }
98803
98804 if (inet6_sk(sk)->rxopt.all)
98805- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98806+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98807 if (skb->protocol == htons(ETH_P_IPV6) &&
98808 inet6_sk(sk)->rxopt.all)
98809- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98810+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98811 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98812 ip_cmsg_recv(msg, skb);
98813 #endif
98814@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98815 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98816 0, sock_i_ino(sp),
98817 atomic_read(&sp->sk_refcnt), sp,
98818- atomic_read(&sp->sk_drops));
98819+ atomic_read_unchecked(&sp->sk_drops));
98820 }
98821
98822 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98823diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98824index c04518f..824ebe5 100644
98825--- a/net/ipv4/raw.c
98826+++ b/net/ipv4/raw.c
98827@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98828 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98829 {
98830 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98831- atomic_inc(&sk->sk_drops);
98832+ atomic_inc_unchecked(&sk->sk_drops);
98833 kfree_skb(skb);
98834 return NET_RX_DROP;
98835 }
98836@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98837 if (flags & MSG_OOB)
98838 goto out;
98839
98840+ if (addr_len)
98841+ *addr_len = sizeof(*sin);
98842+
98843 if (flags & MSG_ERRQUEUE) {
98844 err = ip_recv_error(sk, msg, len, addr_len);
98845 goto out;
98846@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98847 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98848 sin->sin_port = 0;
98849 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98850- *addr_len = sizeof(*sin);
98851 }
98852 if (inet->cmsg_flags)
98853 ip_cmsg_recv(msg, skb);
98854@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98855
98856 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98857 {
98858+ struct icmp_filter filter;
98859+
98860 if (optlen > sizeof(struct icmp_filter))
98861 optlen = sizeof(struct icmp_filter);
98862- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98863+ if (copy_from_user(&filter, optval, optlen))
98864 return -EFAULT;
98865+ raw_sk(sk)->filter = filter;
98866 return 0;
98867 }
98868
98869 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98870 {
98871 int len, ret = -EFAULT;
98872+ struct icmp_filter filter;
98873
98874 if (get_user(len, optlen))
98875 goto out;
98876@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98877 if (len > sizeof(struct icmp_filter))
98878 len = sizeof(struct icmp_filter);
98879 ret = -EFAULT;
98880- if (put_user(len, optlen) ||
98881- copy_to_user(optval, &raw_sk(sk)->filter, len))
98882+ filter = raw_sk(sk)->filter;
98883+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98884 goto out;
98885 ret = 0;
98886 out: return ret;
98887@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98888 0, 0L, 0,
98889 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98890 0, sock_i_ino(sp),
98891- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98892+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98893 }
98894
98895 static int raw_seq_show(struct seq_file *seq, void *v)
98896diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98897index 4c011ec..8fae66b 100644
98898--- a/net/ipv4/route.c
98899+++ b/net/ipv4/route.c
98900@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
98901
98902 static int rt_cache_seq_open(struct inode *inode, struct file *file)
98903 {
98904- return seq_open(file, &rt_cache_seq_ops);
98905+ return seq_open_restrict(file, &rt_cache_seq_ops);
98906 }
98907
98908 static const struct file_operations rt_cache_seq_fops = {
98909@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
98910
98911 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
98912 {
98913- return seq_open(file, &rt_cpu_seq_ops);
98914+ return seq_open_restrict(file, &rt_cpu_seq_ops);
98915 }
98916
98917 static const struct file_operations rt_cpu_seq_fops = {
98918@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
98919
98920 static int rt_acct_proc_open(struct inode *inode, struct file *file)
98921 {
98922- return single_open(file, rt_acct_proc_show, NULL);
98923+ return single_open_restrict(file, rt_acct_proc_show, NULL);
98924 }
98925
98926 static const struct file_operations rt_acct_proc_fops = {
98927@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98928 .maxlen = sizeof(int),
98929 .mode = 0200,
98930 .proc_handler = ipv4_sysctl_rtcache_flush,
98931+ .extra1 = &init_net,
98932 },
98933 { },
98934 };
98935
98936 static __net_init int sysctl_route_net_init(struct net *net)
98937 {
98938- struct ctl_table *tbl;
98939+ ctl_table_no_const *tbl = NULL;
98940
98941- tbl = ipv4_route_flush_table;
98942 if (!net_eq(net, &init_net)) {
98943- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98944+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98945 if (tbl == NULL)
98946 goto err_dup;
98947
98948 /* Don't export sysctls to unprivileged users */
98949 if (net->user_ns != &init_user_ns)
98950 tbl[0].procname = NULL;
98951- }
98952- tbl[0].extra1 = net;
98953+ tbl[0].extra1 = net;
98954+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98955+ } else
98956+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98957
98958- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98959 if (net->ipv4.route_hdr == NULL)
98960 goto err_reg;
98961 return 0;
98962
98963 err_reg:
98964- if (tbl != ipv4_route_flush_table)
98965- kfree(tbl);
98966+ kfree(tbl);
98967 err_dup:
98968 return -ENOMEM;
98969 }
98970@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98971
98972 static __net_init int rt_genid_init(struct net *net)
98973 {
98974- atomic_set(&net->ipv4.rt_genid, 0);
98975- atomic_set(&net->fnhe_genid, 0);
98976+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98977+ atomic_set_unchecked(&net->fnhe_genid, 0);
98978 get_random_bytes(&net->ipv4.dev_addr_genid,
98979 sizeof(net->ipv4.dev_addr_genid));
98980 return 0;
98981diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98982index 44eba05..b36864b 100644
98983--- a/net/ipv4/sysctl_net_ipv4.c
98984+++ b/net/ipv4/sysctl_net_ipv4.c
98985@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98986 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98987 int ret;
98988 int range[2];
98989- struct ctl_table tmp = {
98990+ ctl_table_no_const tmp = {
98991 .data = &range,
98992 .maxlen = sizeof(range),
98993 .mode = table->mode,
98994@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98995 int ret;
98996 gid_t urange[2];
98997 kgid_t low, high;
98998- struct ctl_table tmp = {
98999+ ctl_table_no_const tmp = {
99000 .data = &urange,
99001 .maxlen = sizeof(urange),
99002 .mode = table->mode,
99003@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99004 void __user *buffer, size_t *lenp, loff_t *ppos)
99005 {
99006 char val[TCP_CA_NAME_MAX];
99007- struct ctl_table tbl = {
99008+ ctl_table_no_const tbl = {
99009 .data = val,
99010 .maxlen = TCP_CA_NAME_MAX,
99011 };
99012@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99013 void __user *buffer, size_t *lenp,
99014 loff_t *ppos)
99015 {
99016- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99017+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99018 int ret;
99019
99020 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99021@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99022 void __user *buffer, size_t *lenp,
99023 loff_t *ppos)
99024 {
99025- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99026+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99027 int ret;
99028
99029 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99030@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99031 void __user *buffer, size_t *lenp,
99032 loff_t *ppos)
99033 {
99034- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99035+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99036 struct tcp_fastopen_context *ctxt;
99037 int ret;
99038 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99039@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99040 },
99041 {
99042 .procname = "ip_local_reserved_ports",
99043- .data = NULL, /* initialized in sysctl_ipv4_init */
99044+ .data = sysctl_local_reserved_ports,
99045 .maxlen = 65536,
99046 .mode = 0644,
99047 .proc_handler = proc_do_large_bitmap,
99048@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99049
99050 static __net_init int ipv4_sysctl_init_net(struct net *net)
99051 {
99052- struct ctl_table *table;
99053+ ctl_table_no_const *table = NULL;
99054
99055- table = ipv4_net_table;
99056 if (!net_eq(net, &init_net)) {
99057 int i;
99058
99059- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99060+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99061 if (table == NULL)
99062 goto err_alloc;
99063
99064@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99065 net->ipv4.sysctl_local_ports.range[0] = 32768;
99066 net->ipv4.sysctl_local_ports.range[1] = 61000;
99067
99068- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99069+ if (!net_eq(net, &init_net))
99070+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99071+ else
99072+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99073 if (net->ipv4.ipv4_hdr == NULL)
99074 goto err_reg;
99075
99076 return 0;
99077
99078 err_reg:
99079- if (!net_eq(net, &init_net))
99080- kfree(table);
99081+ kfree(table);
99082 err_alloc:
99083 return -ENOMEM;
99084 }
99085@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99086 static __init int sysctl_ipv4_init(void)
99087 {
99088 struct ctl_table_header *hdr;
99089- struct ctl_table *i;
99090-
99091- for (i = ipv4_table; i->procname; i++) {
99092- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99093- i->data = sysctl_local_reserved_ports;
99094- break;
99095- }
99096- }
99097- if (!i->procname)
99098- return -EINVAL;
99099
99100 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99101 if (hdr == NULL)
99102diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99103index eeaac39..dc29942 100644
99104--- a/net/ipv4/tcp_input.c
99105+++ b/net/ipv4/tcp_input.c
99106@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99107 * without any lock. We want to make sure compiler wont store
99108 * intermediate values in this location.
99109 */
99110- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99111+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99112 sk->sk_max_pacing_rate);
99113 }
99114
99115@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99116 * simplifies code)
99117 */
99118 static void
99119-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99120+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99121 struct sk_buff *head, struct sk_buff *tail,
99122 u32 start, u32 end)
99123 {
99124@@ -5562,6 +5562,7 @@ discard:
99125 tcp_paws_reject(&tp->rx_opt, 0))
99126 goto discard_and_undo;
99127
99128+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99129 if (th->syn) {
99130 /* We see SYN without ACK. It is attempt of
99131 * simultaneous connect with crossed SYNs.
99132@@ -5612,6 +5613,7 @@ discard:
99133 goto discard;
99134 #endif
99135 }
99136+#endif
99137 /* "fifth, if neither of the SYN or RST bits is set then
99138 * drop the segment and return."
99139 */
99140@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99141 goto discard;
99142
99143 if (th->syn) {
99144- if (th->fin)
99145+ if (th->fin || th->urg || th->psh)
99146 goto discard;
99147 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99148 return 1;
99149diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99150index 1e4eac7..a66fa4a 100644
99151--- a/net/ipv4/tcp_ipv4.c
99152+++ b/net/ipv4/tcp_ipv4.c
99153@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99154 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99155
99156
99157+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99158+extern int grsec_enable_blackhole;
99159+#endif
99160+
99161 #ifdef CONFIG_TCP_MD5SIG
99162 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99163 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99164@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99165 return 0;
99166
99167 reset:
99168+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99169+ if (!grsec_enable_blackhole)
99170+#endif
99171 tcp_v4_send_reset(rsk, skb);
99172 discard:
99173 kfree_skb(skb);
99174@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99175 TCP_SKB_CB(skb)->sacked = 0;
99176
99177 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99178- if (!sk)
99179+ if (!sk) {
99180+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99181+ ret = 1;
99182+#endif
99183 goto no_tcp_socket;
99184-
99185+ }
99186 process:
99187- if (sk->sk_state == TCP_TIME_WAIT)
99188+ if (sk->sk_state == TCP_TIME_WAIT) {
99189+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99190+ ret = 2;
99191+#endif
99192 goto do_time_wait;
99193+ }
99194
99195 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99196 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99197@@ -2033,6 +2047,10 @@ csum_error:
99198 bad_packet:
99199 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99200 } else {
99201+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99202+ if (!grsec_enable_blackhole || (ret == 1 &&
99203+ (skb->dev->flags & IFF_LOOPBACK)))
99204+#endif
99205 tcp_v4_send_reset(NULL, skb);
99206 }
99207
99208diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99209index 7a436c5..1b05c59 100644
99210--- a/net/ipv4/tcp_minisocks.c
99211+++ b/net/ipv4/tcp_minisocks.c
99212@@ -27,6 +27,10 @@
99213 #include <net/inet_common.h>
99214 #include <net/xfrm.h>
99215
99216+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99217+extern int grsec_enable_blackhole;
99218+#endif
99219+
99220 int sysctl_tcp_syncookies __read_mostly = 1;
99221 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99222
99223@@ -709,7 +713,10 @@ embryonic_reset:
99224 * avoid becoming vulnerable to outside attack aiming at
99225 * resetting legit local connections.
99226 */
99227- req->rsk_ops->send_reset(sk, skb);
99228+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99229+ if (!grsec_enable_blackhole)
99230+#endif
99231+ req->rsk_ops->send_reset(sk, skb);
99232 } else if (fastopen) { /* received a valid RST pkt */
99233 reqsk_fastopen_remove(sk, req, true);
99234 tcp_reset(sk);
99235diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99236index 1f2d376..01d18c4 100644
99237--- a/net/ipv4/tcp_probe.c
99238+++ b/net/ipv4/tcp_probe.c
99239@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99240 if (cnt + width >= len)
99241 break;
99242
99243- if (copy_to_user(buf + cnt, tbuf, width))
99244+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99245 return -EFAULT;
99246 cnt += width;
99247 }
99248diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99249index 64f0354..a81b39d 100644
99250--- a/net/ipv4/tcp_timer.c
99251+++ b/net/ipv4/tcp_timer.c
99252@@ -22,6 +22,10 @@
99253 #include <linux/gfp.h>
99254 #include <net/tcp.h>
99255
99256+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99257+extern int grsec_lastack_retries;
99258+#endif
99259+
99260 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99261 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99262 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99263@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99264 }
99265 }
99266
99267+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99268+ if ((sk->sk_state == TCP_LAST_ACK) &&
99269+ (grsec_lastack_retries > 0) &&
99270+ (grsec_lastack_retries < retry_until))
99271+ retry_until = grsec_lastack_retries;
99272+#endif
99273+
99274 if (retransmits_timed_out(sk, retry_until,
99275 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99276 /* Has it gone just too far? */
99277diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99278index 77bd16f..5f7174a 100644
99279--- a/net/ipv4/udp.c
99280+++ b/net/ipv4/udp.c
99281@@ -87,6 +87,7 @@
99282 #include <linux/types.h>
99283 #include <linux/fcntl.h>
99284 #include <linux/module.h>
99285+#include <linux/security.h>
99286 #include <linux/socket.h>
99287 #include <linux/sockios.h>
99288 #include <linux/igmp.h>
99289@@ -113,6 +114,10 @@
99290 #include <net/busy_poll.h>
99291 #include "udp_impl.h"
99292
99293+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99294+extern int grsec_enable_blackhole;
99295+#endif
99296+
99297 struct udp_table udp_table __read_mostly;
99298 EXPORT_SYMBOL(udp_table);
99299
99300@@ -615,6 +620,9 @@ found:
99301 return s;
99302 }
99303
99304+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99305+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99306+
99307 /*
99308 * This routine is called by the ICMP module when it gets some
99309 * sort of error condition. If err < 0 then the socket should
99310@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99311 dport = usin->sin_port;
99312 if (dport == 0)
99313 return -EINVAL;
99314+
99315+ err = gr_search_udp_sendmsg(sk, usin);
99316+ if (err)
99317+ return err;
99318 } else {
99319 if (sk->sk_state != TCP_ESTABLISHED)
99320 return -EDESTADDRREQ;
99321+
99322+ err = gr_search_udp_sendmsg(sk, NULL);
99323+ if (err)
99324+ return err;
99325+
99326 daddr = inet->inet_daddr;
99327 dport = inet->inet_dport;
99328 /* Open fast path for connected socket.
99329@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99330 IS_UDPLITE(sk));
99331 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99332 IS_UDPLITE(sk));
99333- atomic_inc(&sk->sk_drops);
99334+ atomic_inc_unchecked(&sk->sk_drops);
99335 __skb_unlink(skb, rcvq);
99336 __skb_queue_tail(&list_kill, skb);
99337 }
99338@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99339 int is_udplite = IS_UDPLITE(sk);
99340 bool slow;
99341
99342+ /*
99343+ * Check any passed addresses
99344+ */
99345+ if (addr_len)
99346+ *addr_len = sizeof(*sin);
99347+
99348 if (flags & MSG_ERRQUEUE)
99349 return ip_recv_error(sk, msg, len, addr_len);
99350
99351@@ -1243,6 +1266,10 @@ try_again:
99352 if (!skb)
99353 goto out;
99354
99355+ err = gr_search_udp_recvmsg(sk, skb);
99356+ if (err)
99357+ goto out_free;
99358+
99359 ulen = skb->len - sizeof(struct udphdr);
99360 copied = len;
99361 if (copied > ulen)
99362@@ -1276,7 +1303,7 @@ try_again:
99363 if (unlikely(err)) {
99364 trace_kfree_skb(skb, udp_recvmsg);
99365 if (!peeked) {
99366- atomic_inc(&sk->sk_drops);
99367+ atomic_inc_unchecked(&sk->sk_drops);
99368 UDP_INC_STATS_USER(sock_net(sk),
99369 UDP_MIB_INERRORS, is_udplite);
99370 }
99371@@ -1295,7 +1322,6 @@ try_again:
99372 sin->sin_port = udp_hdr(skb)->source;
99373 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99374 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99375- *addr_len = sizeof(*sin);
99376 }
99377 if (inet->cmsg_flags)
99378 ip_cmsg_recv(msg, skb);
99379@@ -1566,7 +1592,7 @@ csum_error:
99380 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99381 drop:
99382 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99383- atomic_inc(&sk->sk_drops);
99384+ atomic_inc_unchecked(&sk->sk_drops);
99385 kfree_skb(skb);
99386 return -1;
99387 }
99388@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99389 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99390
99391 if (!skb1) {
99392- atomic_inc(&sk->sk_drops);
99393+ atomic_inc_unchecked(&sk->sk_drops);
99394 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99395 IS_UDPLITE(sk));
99396 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99397@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99398 goto csum_error;
99399
99400 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99401+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99402+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99403+#endif
99404 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99405
99406 /*
99407@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99408 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99409 0, sock_i_ino(sp),
99410 atomic_read(&sp->sk_refcnt), sp,
99411- atomic_read(&sp->sk_drops));
99412+ atomic_read_unchecked(&sp->sk_drops));
99413 }
99414
99415 int udp4_seq_show(struct seq_file *seq, void *v)
99416diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99417index e1a6393..f634ce5 100644
99418--- a/net/ipv4/xfrm4_policy.c
99419+++ b/net/ipv4/xfrm4_policy.c
99420@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99421 fl4->flowi4_tos = iph->tos;
99422 }
99423
99424-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99425+static int xfrm4_garbage_collect(struct dst_ops *ops)
99426 {
99427 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99428
99429- xfrm4_policy_afinfo.garbage_collect(net);
99430+ xfrm_garbage_collect_deferred(net);
99431 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99432 }
99433
99434@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99435
99436 static int __net_init xfrm4_net_init(struct net *net)
99437 {
99438- struct ctl_table *table;
99439+ ctl_table_no_const *table = NULL;
99440 struct ctl_table_header *hdr;
99441
99442- table = xfrm4_policy_table;
99443 if (!net_eq(net, &init_net)) {
99444- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99445+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99446 if (!table)
99447 goto err_alloc;
99448
99449 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99450- }
99451-
99452- hdr = register_net_sysctl(net, "net/ipv4", table);
99453+ hdr = register_net_sysctl(net, "net/ipv4", table);
99454+ } else
99455+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99456 if (!hdr)
99457 goto err_reg;
99458
99459@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99460 return 0;
99461
99462 err_reg:
99463- if (!net_eq(net, &init_net))
99464- kfree(table);
99465+ kfree(table);
99466 err_alloc:
99467 return -ENOMEM;
99468 }
99469diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99470index 6c7fa08..285086c 100644
99471--- a/net/ipv6/addrconf.c
99472+++ b/net/ipv6/addrconf.c
99473@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99474 idx = 0;
99475 head = &net->dev_index_head[h];
99476 rcu_read_lock();
99477- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99478+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99479 net->dev_base_seq;
99480 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99481 if (idx < s_idx)
99482@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99483 p.iph.ihl = 5;
99484 p.iph.protocol = IPPROTO_IPV6;
99485 p.iph.ttl = 64;
99486- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99487+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99488
99489 if (ops->ndo_do_ioctl) {
99490 mm_segment_t oldfs = get_fs();
99491@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99492 s_ip_idx = ip_idx = cb->args[2];
99493
99494 rcu_read_lock();
99495- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99496+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99497 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99498 idx = 0;
99499 head = &net->dev_index_head[h];
99500@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99501 dst_free(&ifp->rt->dst);
99502 break;
99503 }
99504- atomic_inc(&net->ipv6.dev_addr_genid);
99505+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99506 rt_genid_bump_ipv6(net);
99507 }
99508
99509@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99510 int *valp = ctl->data;
99511 int val = *valp;
99512 loff_t pos = *ppos;
99513- struct ctl_table lctl;
99514+ ctl_table_no_const lctl;
99515 int ret;
99516
99517 /*
99518@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99519 int *valp = ctl->data;
99520 int val = *valp;
99521 loff_t pos = *ppos;
99522- struct ctl_table lctl;
99523+ ctl_table_no_const lctl;
99524 int ret;
99525
99526 /*
99527diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99528index d935889..2f64330 100644
99529--- a/net/ipv6/af_inet6.c
99530+++ b/net/ipv6/af_inet6.c
99531@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99532 net->ipv6.sysctl.bindv6only = 0;
99533 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99534 net->ipv6.sysctl.flowlabel_consistency = 1;
99535- atomic_set(&net->ipv6.rt_genid, 0);
99536+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99537
99538 err = ipv6_init_mibs(net);
99539 if (err)
99540diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99541index c3bf2d2..1f00573 100644
99542--- a/net/ipv6/datagram.c
99543+++ b/net/ipv6/datagram.c
99544@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99545 0,
99546 sock_i_ino(sp),
99547 atomic_read(&sp->sk_refcnt), sp,
99548- atomic_read(&sp->sk_drops));
99549+ atomic_read_unchecked(&sp->sk_drops));
99550 }
99551diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
99552index 7b32652..0bc348b 100644
99553--- a/net/ipv6/icmp.c
99554+++ b/net/ipv6/icmp.c
99555@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
99556
99557 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
99558 {
99559- struct ctl_table *table;
99560+ ctl_table_no_const *table;
99561
99562 table = kmemdup(ipv6_icmp_table_template,
99563 sizeof(ipv6_icmp_table_template),
99564diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
99565index f3ffb43..1172ba7 100644
99566--- a/net/ipv6/ip6_gre.c
99567+++ b/net/ipv6/ip6_gre.c
99568@@ -71,7 +71,7 @@ struct ip6gre_net {
99569 struct net_device *fb_tunnel_dev;
99570 };
99571
99572-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
99573+static struct rtnl_link_ops ip6gre_link_ops;
99574 static int ip6gre_tunnel_init(struct net_device *dev);
99575 static void ip6gre_tunnel_setup(struct net_device *dev);
99576 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
99577@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99578 }
99579
99580
99581-static struct inet6_protocol ip6gre_protocol __read_mostly = {
99582+static struct inet6_protocol ip6gre_protocol = {
99583 .handler = ip6gre_rcv,
99584 .err_handler = ip6gre_err,
99585 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99586@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99587 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99588 };
99589
99590-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99591+static struct rtnl_link_ops ip6gre_link_ops = {
99592 .kind = "ip6gre",
99593 .maxtype = IFLA_GRE_MAX,
99594 .policy = ip6gre_policy,
99595@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99596 .fill_info = ip6gre_fill_info,
99597 };
99598
99599-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99600+static struct rtnl_link_ops ip6gre_tap_ops = {
99601 .kind = "ip6gretap",
99602 .maxtype = IFLA_GRE_MAX,
99603 .policy = ip6gre_policy,
99604diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99605index 5db8d31..4a72c26 100644
99606--- a/net/ipv6/ip6_tunnel.c
99607+++ b/net/ipv6/ip6_tunnel.c
99608@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99609
99610 static int ip6_tnl_dev_init(struct net_device *dev);
99611 static void ip6_tnl_dev_setup(struct net_device *dev);
99612-static struct rtnl_link_ops ip6_link_ops __read_mostly;
99613+static struct rtnl_link_ops ip6_link_ops;
99614
99615 static int ip6_tnl_net_id __read_mostly;
99616 struct ip6_tnl_net {
99617@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99618 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99619 };
99620
99621-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99622+static struct rtnl_link_ops ip6_link_ops = {
99623 .kind = "ip6tnl",
99624 .maxtype = IFLA_IPTUN_MAX,
99625 .policy = ip6_tnl_policy,
99626diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99627index 2d19272..3a46322 100644
99628--- a/net/ipv6/ip6_vti.c
99629+++ b/net/ipv6/ip6_vti.c
99630@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99631
99632 static int vti6_dev_init(struct net_device *dev);
99633 static void vti6_dev_setup(struct net_device *dev);
99634-static struct rtnl_link_ops vti6_link_ops __read_mostly;
99635+static struct rtnl_link_ops vti6_link_ops;
99636
99637 static int vti6_net_id __read_mostly;
99638 struct vti6_net {
99639@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99640 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99641 };
99642
99643-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99644+static struct rtnl_link_ops vti6_link_ops = {
99645 .kind = "vti6",
99646 .maxtype = IFLA_VTI_MAX,
99647 .policy = vti6_policy,
99648diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99649index 0a00f44..bec42b2 100644
99650--- a/net/ipv6/ipv6_sockglue.c
99651+++ b/net/ipv6/ipv6_sockglue.c
99652@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99653 if (sk->sk_type != SOCK_STREAM)
99654 return -ENOPROTOOPT;
99655
99656- msg.msg_control = optval;
99657+ msg.msg_control = (void __force_kernel *)optval;
99658 msg.msg_controllen = len;
99659 msg.msg_flags = flags;
99660
99661diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99662index 710238f..0fd1816 100644
99663--- a/net/ipv6/netfilter/ip6_tables.c
99664+++ b/net/ipv6/netfilter/ip6_tables.c
99665@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99666 #endif
99667
99668 static int get_info(struct net *net, void __user *user,
99669- const int *len, int compat)
99670+ int len, int compat)
99671 {
99672 char name[XT_TABLE_MAXNAMELEN];
99673 struct xt_table *t;
99674 int ret;
99675
99676- if (*len != sizeof(struct ip6t_getinfo)) {
99677- duprintf("length %u != %zu\n", *len,
99678+ if (len != sizeof(struct ip6t_getinfo)) {
99679+ duprintf("length %u != %zu\n", len,
99680 sizeof(struct ip6t_getinfo));
99681 return -EINVAL;
99682 }
99683@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99684 info.size = private->size;
99685 strcpy(info.name, name);
99686
99687- if (copy_to_user(user, &info, *len) != 0)
99688+ if (copy_to_user(user, &info, len) != 0)
99689 ret = -EFAULT;
99690 else
99691 ret = 0;
99692@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99693
99694 switch (cmd) {
99695 case IP6T_SO_GET_INFO:
99696- ret = get_info(sock_net(sk), user, len, 1);
99697+ ret = get_info(sock_net(sk), user, *len, 1);
99698 break;
99699 case IP6T_SO_GET_ENTRIES:
99700 ret = compat_get_entries(sock_net(sk), user, len);
99701@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99702
99703 switch (cmd) {
99704 case IP6T_SO_GET_INFO:
99705- ret = get_info(sock_net(sk), user, len, 0);
99706+ ret = get_info(sock_net(sk), user, *len, 0);
99707 break;
99708
99709 case IP6T_SO_GET_ENTRIES:
99710diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99711index 767ab8d..c5ec70a 100644
99712--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99713+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99714@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99715
99716 static int nf_ct_frag6_sysctl_register(struct net *net)
99717 {
99718- struct ctl_table *table;
99719+ ctl_table_no_const *table = NULL;
99720 struct ctl_table_header *hdr;
99721
99722- table = nf_ct_frag6_sysctl_table;
99723 if (!net_eq(net, &init_net)) {
99724- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99725+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99726 GFP_KERNEL);
99727 if (table == NULL)
99728 goto err_alloc;
99729@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99730 table[0].data = &net->nf_frag.frags.timeout;
99731 table[1].data = &net->nf_frag.frags.low_thresh;
99732 table[2].data = &net->nf_frag.frags.high_thresh;
99733- }
99734-
99735- hdr = register_net_sysctl(net, "net/netfilter", table);
99736+ hdr = register_net_sysctl(net, "net/netfilter", table);
99737+ } else
99738+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99739 if (hdr == NULL)
99740 goto err_reg;
99741
99742@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99743 return 0;
99744
99745 err_reg:
99746- if (!net_eq(net, &init_net))
99747- kfree(table);
99748+ kfree(table);
99749 err_alloc:
99750 return -ENOMEM;
99751 }
99752diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99753index 827f795..7e28e82 100644
99754--- a/net/ipv6/output_core.c
99755+++ b/net/ipv6/output_core.c
99756@@ -9,8 +9,8 @@
99757
99758 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99759 {
99760- static atomic_t ipv6_fragmentation_id;
99761- int old, new;
99762+ static atomic_unchecked_t ipv6_fragmentation_id;
99763+ int id;
99764
99765 #if IS_ENABLED(CONFIG_IPV6)
99766 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99767@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99768 }
99769 }
99770 #endif
99771- do {
99772- old = atomic_read(&ipv6_fragmentation_id);
99773- new = old + 1;
99774- if (!new)
99775- new = 1;
99776- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99777- fhdr->identification = htonl(new);
99778+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99779+ if (!id)
99780+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99781+ fhdr->identification = htonl(id);
99782 }
99783 EXPORT_SYMBOL(ipv6_select_ident);
99784
99785diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99786index bda7429..469b26b 100644
99787--- a/net/ipv6/ping.c
99788+++ b/net/ipv6/ping.c
99789@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99790 };
99791 #endif
99792
99793+static struct pingv6_ops real_pingv6_ops = {
99794+ .ipv6_recv_error = ipv6_recv_error,
99795+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99796+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99797+ .icmpv6_err_convert = icmpv6_err_convert,
99798+ .ipv6_icmp_error = ipv6_icmp_error,
99799+ .ipv6_chk_addr = ipv6_chk_addr,
99800+};
99801+
99802+static struct pingv6_ops dummy_pingv6_ops = {
99803+ .ipv6_recv_error = dummy_ipv6_recv_error,
99804+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99805+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99806+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99807+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99808+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99809+};
99810+
99811 int __init pingv6_init(void)
99812 {
99813 #ifdef CONFIG_PROC_FS
99814@@ -253,13 +271,7 @@ int __init pingv6_init(void)
99815 if (ret)
99816 return ret;
99817 #endif
99818- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99819- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99820- pingv6_ops.ip6_datagram_recv_specific_ctl =
99821- ip6_datagram_recv_specific_ctl;
99822- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99823- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99824- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99825+ pingv6_ops = &real_pingv6_ops;
99826 return inet6_register_protosw(&pingv6_protosw);
99827 }
99828
99829@@ -268,14 +280,9 @@ int __init pingv6_init(void)
99830 */
99831 void pingv6_exit(void)
99832 {
99833- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99834- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99835- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99836- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99837- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99838- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99839 #ifdef CONFIG_PROC_FS
99840 unregister_pernet_subsys(&ping_v6_net_ops);
99841 #endif
99842+ pingv6_ops = &dummy_pingv6_ops;
99843 inet6_unregister_protosw(&pingv6_protosw);
99844 }
99845diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
99846index 091d066..139d410 100644
99847--- a/net/ipv6/proc.c
99848+++ b/net/ipv6/proc.c
99849@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
99850 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
99851 goto proc_snmp6_fail;
99852
99853- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
99854+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
99855 if (!net->mib.proc_net_devsnmp6)
99856 goto proc_dev_snmp6_fail;
99857 return 0;
99858diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99859index 1f29996..46fe0c7 100644
99860--- a/net/ipv6/raw.c
99861+++ b/net/ipv6/raw.c
99862@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99863 {
99864 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99865 skb_checksum_complete(skb)) {
99866- atomic_inc(&sk->sk_drops);
99867+ atomic_inc_unchecked(&sk->sk_drops);
99868 kfree_skb(skb);
99869 return NET_RX_DROP;
99870 }
99871@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99872 struct raw6_sock *rp = raw6_sk(sk);
99873
99874 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99875- atomic_inc(&sk->sk_drops);
99876+ atomic_inc_unchecked(&sk->sk_drops);
99877 kfree_skb(skb);
99878 return NET_RX_DROP;
99879 }
99880@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99881
99882 if (inet->hdrincl) {
99883 if (skb_checksum_complete(skb)) {
99884- atomic_inc(&sk->sk_drops);
99885+ atomic_inc_unchecked(&sk->sk_drops);
99886 kfree_skb(skb);
99887 return NET_RX_DROP;
99888 }
99889@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99890 if (flags & MSG_OOB)
99891 return -EOPNOTSUPP;
99892
99893+ if (addr_len)
99894+ *addr_len=sizeof(*sin6);
99895+
99896 if (flags & MSG_ERRQUEUE)
99897 return ipv6_recv_error(sk, msg, len, addr_len);
99898
99899@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99900 sin6->sin6_flowinfo = 0;
99901 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99902 IP6CB(skb)->iif);
99903- *addr_len = sizeof(*sin6);
99904 }
99905
99906 sock_recv_ts_and_drops(msg, sk, skb);
99907@@ -610,7 +612,7 @@ out:
99908 return err;
99909 }
99910
99911-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99912+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99913 struct flowi6 *fl6, struct dst_entry **dstp,
99914 unsigned int flags)
99915 {
99916@@ -922,12 +924,15 @@ do_confirm:
99917 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99918 char __user *optval, int optlen)
99919 {
99920+ struct icmp6_filter filter;
99921+
99922 switch (optname) {
99923 case ICMPV6_FILTER:
99924 if (optlen > sizeof(struct icmp6_filter))
99925 optlen = sizeof(struct icmp6_filter);
99926- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99927+ if (copy_from_user(&filter, optval, optlen))
99928 return -EFAULT;
99929+ raw6_sk(sk)->filter = filter;
99930 return 0;
99931 default:
99932 return -ENOPROTOOPT;
99933@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99934 char __user *optval, int __user *optlen)
99935 {
99936 int len;
99937+ struct icmp6_filter filter;
99938
99939 switch (optname) {
99940 case ICMPV6_FILTER:
99941@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99942 len = sizeof(struct icmp6_filter);
99943 if (put_user(len, optlen))
99944 return -EFAULT;
99945- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99946+ filter = raw6_sk(sk)->filter;
99947+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
99948 return -EFAULT;
99949 return 0;
99950 default:
99951diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99952index cc85a9b..526a133 100644
99953--- a/net/ipv6/reassembly.c
99954+++ b/net/ipv6/reassembly.c
99955@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99956
99957 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99958 {
99959- struct ctl_table *table;
99960+ ctl_table_no_const *table = NULL;
99961 struct ctl_table_header *hdr;
99962
99963- table = ip6_frags_ns_ctl_table;
99964 if (!net_eq(net, &init_net)) {
99965- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99966+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99967 if (table == NULL)
99968 goto err_alloc;
99969
99970@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99971 /* Don't export sysctls to unprivileged users */
99972 if (net->user_ns != &init_user_ns)
99973 table[0].procname = NULL;
99974- }
99975+ hdr = register_net_sysctl(net, "net/ipv6", table);
99976+ } else
99977+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99978
99979- hdr = register_net_sysctl(net, "net/ipv6", table);
99980 if (hdr == NULL)
99981 goto err_reg;
99982
99983@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99984 return 0;
99985
99986 err_reg:
99987- if (!net_eq(net, &init_net))
99988- kfree(table);
99989+ kfree(table);
99990 err_alloc:
99991 return -ENOMEM;
99992 }
99993diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99994index fba54a4..73e374e 100644
99995--- a/net/ipv6/route.c
99996+++ b/net/ipv6/route.c
99997@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
99998
99999 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100000 {
100001- struct ctl_table *table;
100002+ ctl_table_no_const *table;
100003
100004 table = kmemdup(ipv6_route_table_template,
100005 sizeof(ipv6_route_table_template),
100006diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100007index b4d74c8..b4f3fbe 100644
100008--- a/net/ipv6/sit.c
100009+++ b/net/ipv6/sit.c
100010@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100011 static void ipip6_dev_free(struct net_device *dev);
100012 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100013 __be32 *v4dst);
100014-static struct rtnl_link_ops sit_link_ops __read_mostly;
100015+static struct rtnl_link_ops sit_link_ops;
100016
100017 static int sit_net_id __read_mostly;
100018 struct sit_net {
100019@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100020 unregister_netdevice_queue(dev, head);
100021 }
100022
100023-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100024+static struct rtnl_link_ops sit_link_ops = {
100025 .kind = "sit",
100026 .maxtype = IFLA_IPTUN_MAX,
100027 .policy = ipip6_policy,
100028diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100029index 7f405a1..eabef92 100644
100030--- a/net/ipv6/sysctl_net_ipv6.c
100031+++ b/net/ipv6/sysctl_net_ipv6.c
100032@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100033
100034 static int __net_init ipv6_sysctl_net_init(struct net *net)
100035 {
100036- struct ctl_table *ipv6_table;
100037+ ctl_table_no_const *ipv6_table;
100038 struct ctl_table *ipv6_route_table;
100039 struct ctl_table *ipv6_icmp_table;
100040 int err;
100041diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100042index 889079b..a04512c 100644
100043--- a/net/ipv6/tcp_ipv6.c
100044+++ b/net/ipv6/tcp_ipv6.c
100045@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100046 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100047 }
100048
100049+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100050+extern int grsec_enable_blackhole;
100051+#endif
100052+
100053 static void tcp_v6_hash(struct sock *sk)
100054 {
100055 if (sk->sk_state != TCP_CLOSE) {
100056@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100057 return 0;
100058
100059 reset:
100060+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100061+ if (!grsec_enable_blackhole)
100062+#endif
100063 tcp_v6_send_reset(sk, skb);
100064 discard:
100065 if (opt_skb)
100066@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100067 TCP_SKB_CB(skb)->sacked = 0;
100068
100069 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100070- if (!sk)
100071+ if (!sk) {
100072+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100073+ ret = 1;
100074+#endif
100075 goto no_tcp_socket;
100076+ }
100077
100078 process:
100079- if (sk->sk_state == TCP_TIME_WAIT)
100080+ if (sk->sk_state == TCP_TIME_WAIT) {
100081+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100082+ ret = 2;
100083+#endif
100084 goto do_time_wait;
100085+ }
100086
100087 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100088 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100089@@ -1553,6 +1568,10 @@ csum_error:
100090 bad_packet:
100091 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100092 } else {
100093+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100094+ if (!grsec_enable_blackhole || (ret == 1 &&
100095+ (skb->dev->flags & IFF_LOOPBACK)))
100096+#endif
100097 tcp_v6_send_reset(NULL, skb);
100098 }
100099
100100diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100101index 1e586d9..384a9c9 100644
100102--- a/net/ipv6/udp.c
100103+++ b/net/ipv6/udp.c
100104@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100105 udp_ipv6_hash_secret + net_hash_mix(net));
100106 }
100107
100108+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100109+extern int grsec_enable_blackhole;
100110+#endif
100111+
100112 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100113 {
100114 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100115@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100116 int is_udp4;
100117 bool slow;
100118
100119+ if (addr_len)
100120+ *addr_len = sizeof(struct sockaddr_in6);
100121+
100122 if (flags & MSG_ERRQUEUE)
100123 return ipv6_recv_error(sk, msg, len, addr_len);
100124
100125@@ -435,7 +442,7 @@ try_again:
100126 if (unlikely(err)) {
100127 trace_kfree_skb(skb, udpv6_recvmsg);
100128 if (!peeked) {
100129- atomic_inc(&sk->sk_drops);
100130+ atomic_inc_unchecked(&sk->sk_drops);
100131 if (is_udp4)
100132 UDP_INC_STATS_USER(sock_net(sk),
100133 UDP_MIB_INERRORS,
100134@@ -475,7 +482,7 @@ try_again:
100135 ipv6_iface_scope_id(&sin6->sin6_addr,
100136 IP6CB(skb)->iif);
100137 }
100138- *addr_len = sizeof(*sin6);
100139+
100140 }
100141
100142 if (np->rxopt.all)
100143@@ -690,7 +697,7 @@ csum_error:
100144 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100145 drop:
100146 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100147- atomic_inc(&sk->sk_drops);
100148+ atomic_inc_unchecked(&sk->sk_drops);
100149 kfree_skb(skb);
100150 return -1;
100151 }
100152@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100153 if (likely(skb1 == NULL))
100154 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100155 if (!skb1) {
100156- atomic_inc(&sk->sk_drops);
100157+ atomic_inc_unchecked(&sk->sk_drops);
100158 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100159 IS_UDPLITE(sk));
100160 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100161@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100162 goto csum_error;
100163
100164 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100165+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100166+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100167+#endif
100168 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100169
100170 kfree_skb(skb);
100171diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100172index 5f8e128..865d38e 100644
100173--- a/net/ipv6/xfrm6_policy.c
100174+++ b/net/ipv6/xfrm6_policy.c
100175@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100176 }
100177 }
100178
100179-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100180+static int xfrm6_garbage_collect(struct dst_ops *ops)
100181 {
100182 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100183
100184- xfrm6_policy_afinfo.garbage_collect(net);
100185+ xfrm_garbage_collect_deferred(net);
100186 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100187 }
100188
100189@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100190
100191 static int __net_init xfrm6_net_init(struct net *net)
100192 {
100193- struct ctl_table *table;
100194+ ctl_table_no_const *table = NULL;
100195 struct ctl_table_header *hdr;
100196
100197- table = xfrm6_policy_table;
100198 if (!net_eq(net, &init_net)) {
100199- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100200+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100201 if (!table)
100202 goto err_alloc;
100203
100204 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100205- }
100206+ hdr = register_net_sysctl(net, "net/ipv6", table);
100207+ } else
100208+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100209
100210- hdr = register_net_sysctl(net, "net/ipv6", table);
100211 if (!hdr)
100212 goto err_reg;
100213
100214@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100215 return 0;
100216
100217 err_reg:
100218- if (!net_eq(net, &init_net))
100219- kfree(table);
100220+ kfree(table);
100221 err_alloc:
100222 return -ENOMEM;
100223 }
100224diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100225index e15c16a..7cf07aa 100644
100226--- a/net/ipx/ipx_proc.c
100227+++ b/net/ipx/ipx_proc.c
100228@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100229 struct proc_dir_entry *p;
100230 int rc = -ENOMEM;
100231
100232- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100233+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100234
100235 if (!ipx_proc_dir)
100236 goto out;
100237diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100238index 2ba8b97..6d33010 100644
100239--- a/net/irda/ircomm/ircomm_tty.c
100240+++ b/net/irda/ircomm/ircomm_tty.c
100241@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100242 add_wait_queue(&port->open_wait, &wait);
100243
100244 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100245- __FILE__, __LINE__, tty->driver->name, port->count);
100246+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100247
100248 spin_lock_irqsave(&port->lock, flags);
100249 if (!tty_hung_up_p(filp))
100250- port->count--;
100251+ atomic_dec(&port->count);
100252 port->blocked_open++;
100253 spin_unlock_irqrestore(&port->lock, flags);
100254
100255@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100256 }
100257
100258 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100259- __FILE__, __LINE__, tty->driver->name, port->count);
100260+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100261
100262 schedule();
100263 }
100264@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100265
100266 spin_lock_irqsave(&port->lock, flags);
100267 if (!tty_hung_up_p(filp))
100268- port->count++;
100269+ atomic_inc(&port->count);
100270 port->blocked_open--;
100271 spin_unlock_irqrestore(&port->lock, flags);
100272
100273 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100274- __FILE__, __LINE__, tty->driver->name, port->count);
100275+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100276
100277 if (!retval)
100278 port->flags |= ASYNC_NORMAL_ACTIVE;
100279@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100280
100281 /* ++ is not atomic, so this should be protected - Jean II */
100282 spin_lock_irqsave(&self->port.lock, flags);
100283- self->port.count++;
100284+ atomic_inc(&self->port.count);
100285 spin_unlock_irqrestore(&self->port.lock, flags);
100286 tty_port_tty_set(&self->port, tty);
100287
100288 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100289- self->line, self->port.count);
100290+ self->line, atomic_read(&self->port.count));
100291
100292 /* Not really used by us, but lets do it anyway */
100293 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100294@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100295 tty_kref_put(port->tty);
100296 }
100297 port->tty = NULL;
100298- port->count = 0;
100299+ atomic_set(&port->count, 0);
100300 spin_unlock_irqrestore(&port->lock, flags);
100301
100302 wake_up_interruptible(&port->open_wait);
100303@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100304 seq_putc(m, '\n');
100305
100306 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100307- seq_printf(m, "Open count: %d\n", self->port.count);
100308+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100309 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100310 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100311
100312diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100313index b9ac598..f88cc56 100644
100314--- a/net/irda/irproc.c
100315+++ b/net/irda/irproc.c
100316@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100317 {
100318 int i;
100319
100320- proc_irda = proc_mkdir("irda", init_net.proc_net);
100321+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100322 if (proc_irda == NULL)
100323 return;
100324
100325diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100326index c4b7218..3e83259 100644
100327--- a/net/iucv/af_iucv.c
100328+++ b/net/iucv/af_iucv.c
100329@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100330
100331 write_lock_bh(&iucv_sk_list.lock);
100332
100333- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100334+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100335 while (__iucv_get_sock_by_name(name)) {
100336 sprintf(name, "%08x",
100337- atomic_inc_return(&iucv_sk_list.autobind_name));
100338+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100339 }
100340
100341 write_unlock_bh(&iucv_sk_list.lock);
100342diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100343index cd5b8ec..f205e6b 100644
100344--- a/net/iucv/iucv.c
100345+++ b/net/iucv/iucv.c
100346@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100347 return NOTIFY_OK;
100348 }
100349
100350-static struct notifier_block __refdata iucv_cpu_notifier = {
100351+static struct notifier_block iucv_cpu_notifier = {
100352 .notifier_call = iucv_cpu_notify,
100353 };
100354
100355diff --git a/net/key/af_key.c b/net/key/af_key.c
100356index 7932697..a13d158 100644
100357--- a/net/key/af_key.c
100358+++ b/net/key/af_key.c
100359@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100360 static u32 get_acqseq(void)
100361 {
100362 u32 res;
100363- static atomic_t acqseq;
100364+ static atomic_unchecked_t acqseq;
100365
100366 do {
100367- res = atomic_inc_return(&acqseq);
100368+ res = atomic_inc_return_unchecked(&acqseq);
100369 } while (!res);
100370 return res;
100371 }
100372diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100373index 0b44d85..1a7f88b 100644
100374--- a/net/l2tp/l2tp_ip.c
100375+++ b/net/l2tp/l2tp_ip.c
100376@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100377 if (flags & MSG_OOB)
100378 goto out;
100379
100380+ if (addr_len)
100381+ *addr_len = sizeof(*sin);
100382+
100383 skb = skb_recv_datagram(sk, flags, noblock, &err);
100384 if (!skb)
100385 goto out;
100386@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100387 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100388 sin->sin_port = 0;
100389 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100390- *addr_len = sizeof(*sin);
100391 }
100392 if (inet->cmsg_flags)
100393 ip_cmsg_recv(msg, skb);
100394diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100395index 1a3c7e0..80f8b0c 100644
100396--- a/net/llc/llc_proc.c
100397+++ b/net/llc/llc_proc.c
100398@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100399 int rc = -ENOMEM;
100400 struct proc_dir_entry *p;
100401
100402- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100403+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100404 if (!llc_proc_dir)
100405 goto out;
100406
100407diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100408index 453e974..b3a43a5 100644
100409--- a/net/mac80211/cfg.c
100410+++ b/net/mac80211/cfg.c
100411@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100412 ret = ieee80211_vif_use_channel(sdata, chandef,
100413 IEEE80211_CHANCTX_EXCLUSIVE);
100414 }
100415- } else if (local->open_count == local->monitors) {
100416+ } else if (local_read(&local->open_count) == local->monitors) {
100417 local->_oper_chandef = *chandef;
100418 ieee80211_hw_config(local, 0);
100419 }
100420@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100421 else
100422 local->probe_req_reg--;
100423
100424- if (!local->open_count)
100425+ if (!local_read(&local->open_count))
100426 break;
100427
100428 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100429@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100430 if (chanctx_conf) {
100431 *chandef = chanctx_conf->def;
100432 ret = 0;
100433- } else if (local->open_count > 0 &&
100434- local->open_count == local->monitors &&
100435+ } else if (local_read(&local->open_count) > 0 &&
100436+ local_read(&local->open_count) == local->monitors &&
100437 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100438 if (local->use_chanctx)
100439 *chandef = local->monitor_chandef;
100440diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100441index 5e44e317..3d404a6 100644
100442--- a/net/mac80211/ieee80211_i.h
100443+++ b/net/mac80211/ieee80211_i.h
100444@@ -28,6 +28,7 @@
100445 #include <net/ieee80211_radiotap.h>
100446 #include <net/cfg80211.h>
100447 #include <net/mac80211.h>
100448+#include <asm/local.h>
100449 #include "key.h"
100450 #include "sta_info.h"
100451 #include "debug.h"
100452@@ -994,7 +995,7 @@ struct ieee80211_local {
100453 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100454 spinlock_t queue_stop_reason_lock;
100455
100456- int open_count;
100457+ local_t open_count;
100458 int monitors, cooked_mntrs;
100459 /* number of interfaces with corresponding FIF_ flags */
100460 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100461diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100462index ce1c443..6cd39e1 100644
100463--- a/net/mac80211/iface.c
100464+++ b/net/mac80211/iface.c
100465@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100466 break;
100467 }
100468
100469- if (local->open_count == 0) {
100470+ if (local_read(&local->open_count) == 0) {
100471 res = drv_start(local);
100472 if (res)
100473 goto err_del_bss;
100474@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100475 res = drv_add_interface(local, sdata);
100476 if (res)
100477 goto err_stop;
100478- } else if (local->monitors == 0 && local->open_count == 0) {
100479+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100480 res = ieee80211_add_virtual_monitor(local);
100481 if (res)
100482 goto err_stop;
100483@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100484 atomic_inc(&local->iff_promiscs);
100485
100486 if (coming_up)
100487- local->open_count++;
100488+ local_inc(&local->open_count);
100489
100490 if (hw_reconf_flags)
100491 ieee80211_hw_config(local, hw_reconf_flags);
100492@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100493 err_del_interface:
100494 drv_remove_interface(local, sdata);
100495 err_stop:
100496- if (!local->open_count)
100497+ if (!local_read(&local->open_count))
100498 drv_stop(local);
100499 err_del_bss:
100500 sdata->bss = NULL;
100501@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100502 }
100503
100504 if (going_down)
100505- local->open_count--;
100506+ local_dec(&local->open_count);
100507
100508 switch (sdata->vif.type) {
100509 case NL80211_IFTYPE_AP_VLAN:
100510@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100511 }
100512 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100513
100514- if (local->open_count == 0)
100515+ if (local_read(&local->open_count) == 0)
100516 ieee80211_clear_tx_pending(local);
100517
100518 /*
100519@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100520
100521 ieee80211_recalc_ps(local, -1);
100522
100523- if (local->open_count == 0) {
100524+ if (local_read(&local->open_count) == 0) {
100525 ieee80211_stop_device(local);
100526
100527 /* no reconfiguring after stop! */
100528@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100529 ieee80211_configure_filter(local);
100530 ieee80211_hw_config(local, hw_reconf_flags);
100531
100532- if (local->monitors == local->open_count)
100533+ if (local->monitors == local_read(&local->open_count))
100534 ieee80211_add_virtual_monitor(local);
100535 }
100536
100537diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100538index d767cfb..b4cd07d 100644
100539--- a/net/mac80211/main.c
100540+++ b/net/mac80211/main.c
100541@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100542 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100543 IEEE80211_CONF_CHANGE_POWER);
100544
100545- if (changed && local->open_count) {
100546+ if (changed && local_read(&local->open_count)) {
100547 ret = drv_config(local, changed);
100548 /*
100549 * Goal:
100550diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
100551index af64fb8..366e371 100644
100552--- a/net/mac80211/pm.c
100553+++ b/net/mac80211/pm.c
100554@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100555 struct ieee80211_sub_if_data *sdata;
100556 struct sta_info *sta;
100557
100558- if (!local->open_count)
100559+ if (!local_read(&local->open_count))
100560 goto suspend;
100561
100562 ieee80211_scan_cancel(local);
100563@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100564 cancel_work_sync(&local->dynamic_ps_enable_work);
100565 del_timer_sync(&local->dynamic_ps_timer);
100566
100567- local->wowlan = wowlan && local->open_count;
100568+ local->wowlan = wowlan && local_read(&local->open_count);
100569 if (local->wowlan) {
100570 int err = drv_suspend(local, wowlan);
100571 if (err < 0) {
100572@@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100573 WARN_ON(!list_empty(&local->chanctx_list));
100574
100575 /* stop hardware - this must stop RX */
100576- if (local->open_count)
100577+ if (local_read(&local->open_count))
100578 ieee80211_stop_device(local);
100579
100580 suspend:
100581diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
100582index 22b223f..ab70070 100644
100583--- a/net/mac80211/rate.c
100584+++ b/net/mac80211/rate.c
100585@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
100586
100587 ASSERT_RTNL();
100588
100589- if (local->open_count)
100590+ if (local_read(&local->open_count))
100591 return -EBUSY;
100592
100593 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
100594diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
100595index 6ff1346..936ca9a 100644
100596--- a/net/mac80211/rc80211_pid_debugfs.c
100597+++ b/net/mac80211/rc80211_pid_debugfs.c
100598@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
100599
100600 spin_unlock_irqrestore(&events->lock, status);
100601
100602- if (copy_to_user(buf, pb, p))
100603+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
100604 return -EFAULT;
100605
100606 return p;
100607diff --git a/net/mac80211/util.c b/net/mac80211/util.c
100608index b8700d4..89086d5 100644
100609--- a/net/mac80211/util.c
100610+++ b/net/mac80211/util.c
100611@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100612 }
100613 #endif
100614 /* everything else happens only if HW was up & running */
100615- if (!local->open_count)
100616+ if (!local_read(&local->open_count))
100617 goto wake_up;
100618
100619 /*
100620@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100621 local->in_reconfig = false;
100622 barrier();
100623
100624- if (local->monitors == local->open_count && local->monitors > 0)
100625+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
100626 ieee80211_add_virtual_monitor(local);
100627
100628 /*
100629diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100630index e9410d1..77b6378 100644
100631--- a/net/netfilter/Kconfig
100632+++ b/net/netfilter/Kconfig
100633@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
100634
100635 To compile it as a module, choose M here. If unsure, say N.
100636
100637+config NETFILTER_XT_MATCH_GRADM
100638+ tristate '"gradm" match support'
100639+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100640+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100641+ ---help---
100642+ The gradm match allows to match on grsecurity RBAC being enabled.
100643+ It is useful when iptables rules are applied early on bootup to
100644+ prevent connections to the machine (except from a trusted host)
100645+ while the RBAC system is disabled.
100646+
100647 config NETFILTER_XT_MATCH_HASHLIMIT
100648 tristate '"hashlimit" match support'
100649 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100650diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100651index bffdad7..f9317d1 100644
100652--- a/net/netfilter/Makefile
100653+++ b/net/netfilter/Makefile
100654@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100655 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100656 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100657 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100658+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100659 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100660 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100661 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100662diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100663index de770ec..3fc49d2 100644
100664--- a/net/netfilter/ipset/ip_set_core.c
100665+++ b/net/netfilter/ipset/ip_set_core.c
100666@@ -1922,7 +1922,7 @@ done:
100667 return ret;
100668 }
100669
100670-static struct nf_sockopt_ops so_set __read_mostly = {
100671+static struct nf_sockopt_ops so_set = {
100672 .pf = PF_INET,
100673 .get_optmin = SO_IP_SET,
100674 .get_optmax = SO_IP_SET + 1,
100675diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100676index a8eb0a8..86f2de4 100644
100677--- a/net/netfilter/ipvs/ip_vs_conn.c
100678+++ b/net/netfilter/ipvs/ip_vs_conn.c
100679@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100680 /* Increase the refcnt counter of the dest */
100681 ip_vs_dest_hold(dest);
100682
100683- conn_flags = atomic_read(&dest->conn_flags);
100684+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
100685 if (cp->protocol != IPPROTO_UDP)
100686 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100687 flags = cp->flags;
100688@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100689
100690 cp->control = NULL;
100691 atomic_set(&cp->n_control, 0);
100692- atomic_set(&cp->in_pkts, 0);
100693+ atomic_set_unchecked(&cp->in_pkts, 0);
100694
100695 cp->packet_xmit = NULL;
100696 cp->app = NULL;
100697@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100698
100699 /* Don't drop the entry if its number of incoming packets is not
100700 located in [0, 8] */
100701- i = atomic_read(&cp->in_pkts);
100702+ i = atomic_read_unchecked(&cp->in_pkts);
100703 if (i > 8 || i < 0) return 0;
100704
100705 if (!todrop_rate[i]) return 0;
100706diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100707index 4f26ee4..6a9d7c3 100644
100708--- a/net/netfilter/ipvs/ip_vs_core.c
100709+++ b/net/netfilter/ipvs/ip_vs_core.c
100710@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100711 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100712 /* do not touch skb anymore */
100713
100714- atomic_inc(&cp->in_pkts);
100715+ atomic_inc_unchecked(&cp->in_pkts);
100716 ip_vs_conn_put(cp);
100717 return ret;
100718 }
100719@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100720 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100721 pkts = sysctl_sync_threshold(ipvs);
100722 else
100723- pkts = atomic_add_return(1, &cp->in_pkts);
100724+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100725
100726 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100727 ip_vs_sync_conn(net, cp, pkts);
100728diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100729index 35be035..50f8834 100644
100730--- a/net/netfilter/ipvs/ip_vs_ctl.c
100731+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100732@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100733 */
100734 ip_vs_rs_hash(ipvs, dest);
100735 }
100736- atomic_set(&dest->conn_flags, conn_flags);
100737+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100738
100739 /* bind the service */
100740 old_svc = rcu_dereference_protected(dest->svc, 1);
100741@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100742 * align with netns init in ip_vs_control_net_init()
100743 */
100744
100745-static struct ctl_table vs_vars[] = {
100746+static ctl_table_no_const vs_vars[] __read_only = {
100747 {
100748 .procname = "amemthresh",
100749 .maxlen = sizeof(int),
100750@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100751 " %-7s %-6d %-10d %-10d\n",
100752 &dest->addr.in6,
100753 ntohs(dest->port),
100754- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100755+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100756 atomic_read(&dest->weight),
100757 atomic_read(&dest->activeconns),
100758 atomic_read(&dest->inactconns));
100759@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100760 "%-7s %-6d %-10d %-10d\n",
100761 ntohl(dest->addr.ip),
100762 ntohs(dest->port),
100763- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100764+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100765 atomic_read(&dest->weight),
100766 atomic_read(&dest->activeconns),
100767 atomic_read(&dest->inactconns));
100768@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100769
100770 entry.addr = dest->addr.ip;
100771 entry.port = dest->port;
100772- entry.conn_flags = atomic_read(&dest->conn_flags);
100773+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100774 entry.weight = atomic_read(&dest->weight);
100775 entry.u_threshold = dest->u_threshold;
100776 entry.l_threshold = dest->l_threshold;
100777@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100778 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100779 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100780 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100781- (atomic_read(&dest->conn_flags) &
100782+ (atomic_read_unchecked(&dest->conn_flags) &
100783 IP_VS_CONN_F_FWD_MASK)) ||
100784 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100785 atomic_read(&dest->weight)) ||
100786@@ -3580,7 +3580,7 @@ out:
100787 }
100788
100789
100790-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100791+static const struct genl_ops ip_vs_genl_ops[] = {
100792 {
100793 .cmd = IPVS_CMD_NEW_SERVICE,
100794 .flags = GENL_ADMIN_PERM,
100795@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100796 {
100797 int idx;
100798 struct netns_ipvs *ipvs = net_ipvs(net);
100799- struct ctl_table *tbl;
100800+ ctl_table_no_const *tbl;
100801
100802 atomic_set(&ipvs->dropentry, 0);
100803 spin_lock_init(&ipvs->dropentry_lock);
100804diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100805index ca056a3..9cf01ef 100644
100806--- a/net/netfilter/ipvs/ip_vs_lblc.c
100807+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100808@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100809 * IPVS LBLC sysctl table
100810 */
100811 #ifdef CONFIG_SYSCTL
100812-static struct ctl_table vs_vars_table[] = {
100813+static ctl_table_no_const vs_vars_table[] __read_only = {
100814 {
100815 .procname = "lblc_expiration",
100816 .data = NULL,
100817diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100818index 3f21a2f..a112e85 100644
100819--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100820+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100821@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100822 * IPVS LBLCR sysctl table
100823 */
100824
100825-static struct ctl_table vs_vars_table[] = {
100826+static ctl_table_no_const vs_vars_table[] __read_only = {
100827 {
100828 .procname = "lblcr_expiration",
100829 .data = NULL,
100830diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100831index db80126..ef7110e 100644
100832--- a/net/netfilter/ipvs/ip_vs_sync.c
100833+++ b/net/netfilter/ipvs/ip_vs_sync.c
100834@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100835 cp = cp->control;
100836 if (cp) {
100837 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100838- pkts = atomic_add_return(1, &cp->in_pkts);
100839+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100840 else
100841 pkts = sysctl_sync_threshold(ipvs);
100842 ip_vs_sync_conn(net, cp->control, pkts);
100843@@ -771,7 +771,7 @@ control:
100844 if (!cp)
100845 return;
100846 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100847- pkts = atomic_add_return(1, &cp->in_pkts);
100848+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100849 else
100850 pkts = sysctl_sync_threshold(ipvs);
100851 goto sloop;
100852@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100853
100854 if (opt)
100855 memcpy(&cp->in_seq, opt, sizeof(*opt));
100856- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100857+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100858 cp->state = state;
100859 cp->old_state = cp->state;
100860 /*
100861diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100862index c47444e..b0961c6 100644
100863--- a/net/netfilter/ipvs/ip_vs_xmit.c
100864+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100865@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100866 else
100867 rc = NF_ACCEPT;
100868 /* do not touch skb anymore */
100869- atomic_inc(&cp->in_pkts);
100870+ atomic_inc_unchecked(&cp->in_pkts);
100871 goto out;
100872 }
100873
100874@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100875 else
100876 rc = NF_ACCEPT;
100877 /* do not touch skb anymore */
100878- atomic_inc(&cp->in_pkts);
100879+ atomic_inc_unchecked(&cp->in_pkts);
100880 goto out;
100881 }
100882
100883diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100884index a4b5e2a..13b1de3 100644
100885--- a/net/netfilter/nf_conntrack_acct.c
100886+++ b/net/netfilter/nf_conntrack_acct.c
100887@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100888 #ifdef CONFIG_SYSCTL
100889 static int nf_conntrack_acct_init_sysctl(struct net *net)
100890 {
100891- struct ctl_table *table;
100892+ ctl_table_no_const *table;
100893
100894 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100895 GFP_KERNEL);
100896diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100897index 356bef5..99932cb 100644
100898--- a/net/netfilter/nf_conntrack_core.c
100899+++ b/net/netfilter/nf_conntrack_core.c
100900@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
100901 #define DYING_NULLS_VAL ((1<<30)+1)
100902 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100903
100904+#ifdef CONFIG_GRKERNSEC_HIDESYM
100905+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100906+#endif
100907+
100908 int nf_conntrack_init_net(struct net *net)
100909 {
100910 int ret;
100911@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
100912 goto err_stat;
100913 }
100914
100915+#ifdef CONFIG_GRKERNSEC_HIDESYM
100916+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100917+#else
100918 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100919+#endif
100920 if (!net->ct.slabname) {
100921 ret = -ENOMEM;
100922 goto err_slabname;
100923diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100924index 1df1761..ce8b88a 100644
100925--- a/net/netfilter/nf_conntrack_ecache.c
100926+++ b/net/netfilter/nf_conntrack_ecache.c
100927@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100928 #ifdef CONFIG_SYSCTL
100929 static int nf_conntrack_event_init_sysctl(struct net *net)
100930 {
100931- struct ctl_table *table;
100932+ ctl_table_no_const *table;
100933
100934 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100935 GFP_KERNEL);
100936diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100937index 974a2a4..52cc6ff 100644
100938--- a/net/netfilter/nf_conntrack_helper.c
100939+++ b/net/netfilter/nf_conntrack_helper.c
100940@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100941
100942 static int nf_conntrack_helper_init_sysctl(struct net *net)
100943 {
100944- struct ctl_table *table;
100945+ ctl_table_no_const *table;
100946
100947 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100948 GFP_KERNEL);
100949diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100950index b65d586..beec902 100644
100951--- a/net/netfilter/nf_conntrack_proto.c
100952+++ b/net/netfilter/nf_conntrack_proto.c
100953@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100954
100955 static void
100956 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100957- struct ctl_table **table,
100958+ ctl_table_no_const **table,
100959 unsigned int users)
100960 {
100961 if (users > 0)
100962diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100963index f641751..d3c5b51 100644
100964--- a/net/netfilter/nf_conntrack_standalone.c
100965+++ b/net/netfilter/nf_conntrack_standalone.c
100966@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100967
100968 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100969 {
100970- struct ctl_table *table;
100971+ ctl_table_no_const *table;
100972
100973 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100974 GFP_KERNEL);
100975diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100976index 7a394df..bd91a8a 100644
100977--- a/net/netfilter/nf_conntrack_timestamp.c
100978+++ b/net/netfilter/nf_conntrack_timestamp.c
100979@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100980 #ifdef CONFIG_SYSCTL
100981 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100982 {
100983- struct ctl_table *table;
100984+ ctl_table_no_const *table;
100985
100986 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100987 GFP_KERNEL);
100988diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100989index 85296d4..8becdec 100644
100990--- a/net/netfilter/nf_log.c
100991+++ b/net/netfilter/nf_log.c
100992@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100993
100994 #ifdef CONFIG_SYSCTL
100995 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100996-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100997+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100998
100999 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101000 void __user *buffer, size_t *lenp, loff_t *ppos)
101001@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101002 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101003 mutex_unlock(&nf_log_mutex);
101004 } else {
101005+ ctl_table_no_const nf_log_table = *table;
101006+
101007 mutex_lock(&nf_log_mutex);
101008 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101009 lockdep_is_held(&nf_log_mutex));
101010 if (!logger)
101011- table->data = "NONE";
101012+ nf_log_table.data = "NONE";
101013 else
101014- table->data = logger->name;
101015- r = proc_dostring(table, write, buffer, lenp, ppos);
101016+ nf_log_table.data = logger->name;
101017+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101018 mutex_unlock(&nf_log_mutex);
101019 }
101020
101021diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101022index f042ae5..30ea486 100644
101023--- a/net/netfilter/nf_sockopt.c
101024+++ b/net/netfilter/nf_sockopt.c
101025@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101026 }
101027 }
101028
101029- list_add(&reg->list, &nf_sockopts);
101030+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101031 out:
101032 mutex_unlock(&nf_sockopt_mutex);
101033 return ret;
101034@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101035 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101036 {
101037 mutex_lock(&nf_sockopt_mutex);
101038- list_del(&reg->list);
101039+ pax_list_del((struct list_head *)&reg->list);
101040 mutex_unlock(&nf_sockopt_mutex);
101041 }
101042 EXPORT_SYMBOL(nf_unregister_sockopt);
101043diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101044index adce01e..8d52d50 100644
101045--- a/net/netfilter/nf_tables_api.c
101046+++ b/net/netfilter/nf_tables_api.c
101047@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101048 #ifdef CONFIG_MODULES
101049 if (autoload) {
101050 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101051- request_module("nft-chain-%u-%*.s", afi->family,
101052- nla_len(nla)-1, (const char *)nla_data(nla));
101053+ request_module("nft-chain-%u-%.*s", afi->family,
101054+ nla_len(nla), (const char *)nla_data(nla));
101055 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101056 type = __nf_tables_chain_type_lookup(afi->family, nla);
101057 if (type != NULL)
101058@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101059
101060 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101061 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101062- [NFTA_SET_NAME] = { .type = NLA_STRING },
101063+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101064+ .len = IFNAMSIZ - 1 },
101065 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101066 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101067 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101068diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101069index a155d19..726b0f2 100644
101070--- a/net/netfilter/nfnetlink_log.c
101071+++ b/net/netfilter/nfnetlink_log.c
101072@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101073 struct nfnl_log_net {
101074 spinlock_t instances_lock;
101075 struct hlist_head instance_table[INSTANCE_BUCKETS];
101076- atomic_t global_seq;
101077+ atomic_unchecked_t global_seq;
101078 };
101079
101080 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101081@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101082 /* global sequence number */
101083 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101084 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101085- htonl(atomic_inc_return(&log->global_seq))))
101086+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101087 goto nla_put_failure;
101088
101089 if (data_len) {
101090diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101091index 82cb823..5685dd5 100644
101092--- a/net/netfilter/nft_compat.c
101093+++ b/net/netfilter/nft_compat.c
101094@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101095 /* We want to reuse existing compat_to_user */
101096 old_fs = get_fs();
101097 set_fs(KERNEL_DS);
101098- t->compat_to_user(out, in);
101099+ t->compat_to_user((void __force_user *)out, in);
101100 set_fs(old_fs);
101101 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101102 kfree(out);
101103@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101104 /* We want to reuse existing compat_to_user */
101105 old_fs = get_fs();
101106 set_fs(KERNEL_DS);
101107- m->compat_to_user(out, in);
101108+ m->compat_to_user((void __force_user *)out, in);
101109 set_fs(old_fs);
101110 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101111 kfree(out);
101112diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101113new file mode 100644
101114index 0000000..c566332
101115--- /dev/null
101116+++ b/net/netfilter/xt_gradm.c
101117@@ -0,0 +1,51 @@
101118+/*
101119+ * gradm match for netfilter
101120